EWMH desktop support

This commit is contained in:
vaxerski 2021-12-21 09:41:55 +01:00
parent c679f327d6
commit 627d53ed7c
3 changed files with 49 additions and 1 deletions

View File

@ -65,3 +65,43 @@ void EWMH::setFrameExtents(xcb_window_t w) {
uint32_t extents[4] = {BORDERSIZE,BORDERSIZE,BORDERSIZE,BORDERSIZE};
xcb_change_property(g_pWindowManager->DisplayConnection, XCB_PROP_MODE_REPLACE, w, HYPRATOMS["_NET_FRAME_EXTENTS"], XCB_ATOM_CARDINAL, 32, 4, &extents);
}
void EWMH::updateDesktops() {
if (!g_pWindowManager->getMonitorFromCursor()) {
Debug::log(ERR, "Monitor was null! (updateDesktops EWMH)");
return;
}
const auto ACTIVEWORKSPACE = g_pWindowManager->activeWorkspaces[g_pWindowManager->getMonitorFromCursor()->ID];
if (DesktopInfo::lastid != ACTIVEWORKSPACE) {
// Update the current workspace
DesktopInfo::lastid = ACTIVEWORKSPACE;
xcb_change_property(g_pWindowManager->DisplayConnection, XCB_PROP_MODE_REPLACE, g_pWindowManager->Screen->root, HYPRATOMS["_NET_CURRENT_DESKTOP"], XCB_ATOM_CARDINAL, 32, 1, &ACTIVEWORKSPACE);
// Update all desktops
const auto ALLDESKTOPS = g_pWindowManager->workspaces.size();
xcb_change_property(g_pWindowManager->DisplayConnection, XCB_PROP_MODE_REPLACE, g_pWindowManager->Screen->root, HYPRATOMS["_NET_NUMBER_OF_DESKTOPS"], XCB_ATOM_CARDINAL, 32, 1, &ALLDESKTOPS);
// Update desktop names, create a sorted workspaces vec
auto workspacesVec = g_pWindowManager->workspaces;
std::sort(workspacesVec.begin(), workspacesVec.end(), [](CWorkspace& a, CWorkspace& b) { return a.getID() < b.getID(); });
int msglen = 0;
for (auto& work : workspacesVec) {
msglen += strlen(std::to_string(work.getID()).c_str()) + 1;
}
char names[msglen];
int curpos = 0;
for (auto& work : workspacesVec) {
for (int i = 0; i < strlen(std::to_string(work.getID()).c_str()) + 1; ++i) {
names[curpos] = std::to_string(work.getID())[i];
++curpos;
}
}
xcb_change_property(g_pWindowManager->DisplayConnection, XCB_PROP_MODE_REPLACE, g_pWindowManager->Screen->root, HYPRATOMS["_NET_DESKTOP_NAMES"], HYPRATOMS["UTF8_STRING"], 8, msglen, names);
}
}

View File

@ -7,7 +7,12 @@ namespace EWMH {
void updateCurrentWindow(xcb_window_t);
void updateClientList();
void setFrameExtents(xcb_window_t);
void refreshAllExtents();
void refreshAllExtents();
void updateDesktops();
namespace DesktopInfo {
inline int lastid = 0;
};
inline xcb_window_t EWMHwindow = XCB_WINDOW_NONE;
};

View File

@ -219,6 +219,9 @@ bool CWindowManager::handleEvent() {
// Update the bar with the freshest stuff
updateBarInfo();
// Update EWMH workspace info
EWMH::updateDesktops();
xcb_flush(DisplayConnection);
// Restore thread state