diff --git a/src/events/events.cpp b/src/events/events.cpp index cf67931..a9104c3 100644 --- a/src/events/events.cpp +++ b/src/events/events.cpp @@ -175,11 +175,6 @@ CWindow* Events::remapFloatingWindow(int windowID, int forcemonitor) { return nullptr; } - if (PWINDOWINARR->getClassName() == "") { - Debug::log(WARN, "remapFloatingWindow with Error, not managing."); - return nullptr; - } - PWINDOWINARR->setIsFloating(true); PWINDOWINARR->setDirty(true); @@ -420,11 +415,6 @@ CWindow* Events::remapWindow(int windowID, bool wasfloating, int forcemonitor) { Debug::log(ERR, "remapWindow called with an invalid window!"); return nullptr; } - - if (PWINDOWINARR->getClassName() == "Error") { - Debug::log(LOG, "Class error -> we wont manage this."); - return nullptr; - } PWINDOWINARR->setIsFloating(false); @@ -622,6 +612,16 @@ void Events::eventMapWindow(xcb_generic_event_t* event) { pNewWindow = g_pWindowManager->getWindowFromDrawable(E->window); } else { + if (g_pWindowManager->getWindowFromDrawable(E->window)) { + Debug::log(LOG, "Window already managed."); + return; + } + + if (!g_pWindowManager->shouldBeManaged(E->window)) { + Debug::log(LOG, "window shouldn't be managed"); + return; + } + CWindow window; window.setDrawable(E->window); g_pWindowManager->addWindowToVectorSafe(window); @@ -635,7 +635,7 @@ void Events::eventMapWindow(xcb_generic_event_t* event) { } } - if (!pNewWindow || pNewWindow->getClassName() == "") { + if (!pNewWindow) { Debug::log(LOG, "Removing, NULL."); g_pWindowManager->removeWindowFromVectorSafe(E->window); return; diff --git a/src/utilities/XCBProps.cpp b/src/utilities/XCBProps.cpp index fe85f54..9aa4be8 100644 --- a/src/utilities/XCBProps.cpp +++ b/src/utilities/XCBProps.cpp @@ -110,4 +110,19 @@ void removeAtom(const int& window, xcb_atom_t prop, xcb_atom_t atom) { free(REPLY); xcb_ungrab_server(DisplayConnection); +} + +uint8_t getWindowState(const int& win) { + uint32_t returns = 0; + + const auto COOKIE = xcb_get_property(DisplayConnection, 0, win, HYPRATOMS["_NET_WM_STATE"], HYPRATOMS["_NET_WM_STATE"], 0L, 2L); + const auto REPLY = xcb_get_property_reply(DisplayConnection, COOKIE, NULL); + if (REPLY) { + if (REPLY->type == HYPRATOMS["_NET_WM_STATE"] && REPLY->format == 32 && REPLY->length == 2) { + returns = *((uint32_t*)xcb_get_property_value(REPLY)); + } + + free(REPLY); + } + return returns; } \ No newline at end of file diff --git a/src/utilities/XCBProps.hpp b/src/utilities/XCBProps.hpp index b6ea488..3f15893 100644 --- a/src/utilities/XCBProps.hpp +++ b/src/utilities/XCBProps.hpp @@ -7,5 +7,6 @@ std::pair getClassName(int64_t window); std::string getRoleName(int64_t window); std::string getWindowName(uint64_t window); +uint8_t getWindowState(const int& win); void removeAtom(const int& window, xcb_atom_t prop, xcb_atom_t atom); \ No newline at end of file diff --git a/src/windowManager.cpp b/src/windowManager.cpp index 4cb64fd..6ef0f68 100644 --- a/src/windowManager.cpp +++ b/src/windowManager.cpp @@ -2277,3 +2277,27 @@ void CWindowManager::dispatchQueuedWarp() { warpCursorTo(QueuedPointerWarp); QueuedPointerWarp = Vector2D(-1,-1); } + +bool CWindowManager::shouldBeManaged(const int& window) { + const auto WINDOWATTRS = xcb_get_window_attributes_reply(DisplayConnection, xcb_get_window_attributes(DisplayConnection, window), NULL); + + if (!WINDOWATTRS) { + Debug::log(LOG, "Skipping: window attributes null"); + return false; + } + + if (WINDOWATTRS->override_redirect) { + Debug::log(LOG, "Skipping: override redirect"); + return false; + } + + const auto GEOMETRY = xcb_get_geometry_reply(DisplayConnection, xcb_get_geometry(DisplayConnection, window), NULL); + if (!GEOMETRY) { + Debug::log(LOG, "Skipping: No geometry"); + return false; + } + + Debug::log(LOG, "shouldBeManaged passed!"); + + return true; +} \ No newline at end of file diff --git a/src/windowManager.hpp b/src/windowManager.hpp index 7afb3db..26080e0 100644 --- a/src/windowManager.hpp +++ b/src/windowManager.hpp @@ -141,6 +141,8 @@ public: void handleClientMessage(xcb_client_message_event_t*); + bool shouldBeManaged(const int&); + private: // Internal WM functions that don't have to be exposed