From 88546490ea4fb8d94baf754ba061ad20b70ffbe5 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Mon, 13 Dec 2021 20:21:54 +0100 Subject: [PATCH] Added some EWMH --- src/events/events.cpp | 11 +++++++++- src/ewmh/ewmh.cpp | 22 ++++++++++++++++++++ src/ewmh/ewmh.hpp | 2 ++ src/windowManager.cpp | 47 +++++-------------------------------------- 4 files changed, 39 insertions(+), 43 deletions(-) diff --git a/src/events/events.cpp b/src/events/events.cpp index 9c84539..7eaf324 100644 --- a/src/events/events.cpp +++ b/src/events/events.cpp @@ -107,6 +107,9 @@ void Events::eventDestroy(xcb_generic_event_t* event) { // refocus on new window g_pWindowManager->refocusWindowOnClosed(); + + // EWMH + EWMH::updateClientList(); } void Events::eventUnmapWindow(xcb_generic_event_t* event) { @@ -130,6 +133,9 @@ void Events::eventUnmapWindow(xcb_generic_event_t* event) { // refocus on new window g_pWindowManager->refocusWindowOnClosed(); + + // EWMH + EWMH::updateClientList(); } CWindow* Events::remapFloatingWindow(int windowID, int forcemonitor) { @@ -187,7 +193,7 @@ CWindow* Events::remapFloatingWindow(int windowID, int forcemonitor) { const auto wm_type_cookiereply = xcb_get_property_reply(g_pWindowManager->DisplayConnection, wm_type_cookie, NULL); xcb_atom_t TYPEATOM = NULL; if (wm_type_cookiereply == NULL || xcb_get_property_value_length(wm_type_cookiereply) < 1) { - Debug::log(LOG, "No preferred type found."); + Debug::log(LOG, "No preferred type found. (RemapFloatingWindow)"); } else { const auto ATOMS = (xcb_atom_t*)xcb_get_property_value(wm_type_cookiereply); if (!ATOMS) { @@ -405,6 +411,9 @@ void Events::eventMapWindow(xcb_generic_event_t* event) { // Set not under pNewWindow->setUnderFullscreen(false); pNewWindow->setDirty(true); + + // EWMH + EWMH::updateClientList(); } void Events::eventButtonPress(xcb_generic_event_t* event) { diff --git a/src/ewmh/ewmh.cpp b/src/ewmh/ewmh.cpp index 241b30e..83a45a6 100644 --- a/src/ewmh/ewmh.cpp +++ b/src/ewmh/ewmh.cpp @@ -29,5 +29,27 @@ void EWMH::setupInitEWMH() { xcb_change_property(g_pWindowManager->DisplayConnection, XCB_PROP_MODE_REPLACE, g_pWindowManager->Screen->root, HYPRATOMS["_NET_SUPPORTED"], XCB_ATOM_ATOM, 32, sizeof(supportedAtoms) / sizeof(xcb_atom_t), supportedAtoms); + // delete workarea + xcb_delete_property(g_pWindowManager->DisplayConnection, g_pWindowManager->Screen->root, HYPRATOMS["_NET_WORKAREA"]); + Debug::log(LOG, "EWMH init done."); +} + +void EWMH::updateCurrentWindow(xcb_window_t w) { + xcb_change_property(g_pWindowManager->DisplayConnection, XCB_PROP_MODE_REPLACE, g_pWindowManager->Screen->root, HYPRATOMS["_NET_ACTIVE_WINDOW"], XCB_ATOM_WINDOW, 32, 1, &w); +} + +void EWMH::updateClientList() { + std::vector windowsList; + for (auto& w : g_pWindowManager->windows) + if (w.getDrawable() > 0) + windowsList.push_back(w.getDrawable()); + for (auto& w : g_pWindowManager->unmappedWindows) + windowsList.push_back(w.getDrawable()); + + // hack + xcb_window_t* ArrWindowList = &windowsList[0]; + + xcb_change_property(g_pWindowManager->DisplayConnection, XCB_PROP_MODE_REPLACE, g_pWindowManager->Screen->root, HYPRATOMS["_NET_CLIENT_LIST"], XCB_ATOM_WINDOW, + 32, windowsList.size(), ArrWindowList); } \ No newline at end of file diff --git a/src/ewmh/ewmh.hpp b/src/ewmh/ewmh.hpp index 96d9ad7..4d5f3fb 100644 --- a/src/ewmh/ewmh.hpp +++ b/src/ewmh/ewmh.hpp @@ -4,6 +4,8 @@ namespace EWMH { void setupInitEWMH(); + void updateCurrentWindow(xcb_window_t); + void updateClientList(); inline xcb_window_t EWMHwindow = 0; }; \ No newline at end of file diff --git a/src/windowManager.cpp b/src/windowManager.cpp index 4804636..5146c64 100644 --- a/src/windowManager.cpp +++ b/src/windowManager.cpp @@ -447,6 +447,9 @@ void CWindowManager::setFocusedWindow(xcb_drawable_t window) { // set focus in X11 xcb_set_input_focus(DisplayConnection, XCB_INPUT_FOCUS_POINTER_ROOT, window, XCB_CURRENT_TIME); + + // EWMH + EWMH::updateCurrentWindow(LastWindow); } } @@ -526,46 +529,6 @@ void CWindowManager::sanityCheckOnWorkspace(int workspaceID) { Debug::log(ERR, "Malformed node ID " + std::to_string(w.getDrawable()) + " with 2 children but one or both are nullptr."); } } - - // Check #3: Check if the window exists with xcb - // Some windows do not report they are dead for w/e reason - if (w.getDrawable() > 0) { - const auto GEOMETRYCOOKIE = xcb_get_geometry(g_pWindowManager->DisplayConnection, w.getDrawable()); - const auto GEOMETRY = xcb_get_geometry_reply(g_pWindowManager->DisplayConnection, GEOMETRYCOOKIE, 0); - - if (!GEOMETRY || (GEOMETRY->width < 1 || GEOMETRY->height < 1)) { - Debug::log(LOG, "Found a dead window, ID: " + std::to_string(w.getDrawable()) + ", removing it."); - - closeWindowAllChecks(w.getDrawable()); - continue; - } - - // Type 2: is hidden. - const auto window = w.getDrawable(); - PROP(wm_type_cookie, HYPRATOMS["_NET_WM_WINDOW_TYPE"], UINT32_MAX); - - if (wm_type_cookiereply == NULL || xcb_get_property_value_length(wm_type_cookiereply) < 1) { - Debug::log(LOG, "No preferred type found."); - } else { - const auto ATOMS = (xcb_atom_t*)xcb_get_property_value(wm_type_cookiereply); - if (!ATOMS) { - Debug::log(ERR, "Atoms not found in preferred type!"); - } else { - if (xcbContainsAtom(wm_type_cookiereply, HYPRATOMS["_NET_WM_STATE_HIDDEN"])) { - // delete it - // NOTE: this is NOT the cause of windows in tray not being able - // to open. - free(wm_type_cookiereply); - - Debug::log(LOG, "Found a dead window, ID: " + std::to_string(w.getDrawable()) + ", removing it."); - - closeWindowAllChecks(w.getDrawable()); - continue; - } - } - } - free(wm_type_cookiereply); - } } } } @@ -1591,7 +1554,7 @@ bool CWindowManager::shouldBeFloatedOnInit(int64_t window) { xcb_atom_t TYPEATOM = NULL; if (wm_type_cookiereply == NULL || xcb_get_property_value_length(wm_type_cookiereply) < 1) { - Debug::log(LOG, "No preferred type found."); + Debug::log(LOG, "No preferred type found. (shouldBeFloatedOnInit)"); } else { const auto ATOMS = (xcb_atom_t*)xcb_get_property_value(wm_type_cookiereply); if (!ATOMS) { @@ -1642,7 +1605,7 @@ void CWindowManager::doPostCreationChecks(CWindow* pWindow) { PROP(wm_type_cookie, HYPRATOMS["_NET_WM_WINDOW_TYPE"], UINT32_MAX); if (wm_type_cookiereply == NULL || xcb_get_property_value_length(wm_type_cookiereply) < 1) { - Debug::log(LOG, "No preferred type found."); + Debug::log(LOG, "No preferred type found. (doPostCreationChecks)"); } else { const auto ATOMS = (xcb_atom_t*)xcb_get_property_value(wm_type_cookiereply); if (!ATOMS) {