Sanity check against duped children

This commit is contained in:
vaxerski 2021-11-24 18:51:34 +01:00
parent 8f172a4e55
commit ad87629d51
3 changed files with 68 additions and 6 deletions

View file

@ -100,6 +100,19 @@ CWindow* Events::remapFloatingWindow(int windowID) {
CWindow* Events::remapWindow(int windowID, bool wasfloating) { CWindow* Events::remapWindow(int windowID, bool wasfloating) {
// Do the setup of the window's params and stuf // Do the setup of the window's params and stuf
// For all floating windows, get their default size
const auto GEOMETRYCOOKIE = xcb_get_geometry(g_pWindowManager->DisplayConnection, windowID);
const auto GEOMETRY = xcb_get_geometry_reply(g_pWindowManager->DisplayConnection, GEOMETRYCOOKIE, 0);
if (GEOMETRY) {
// Check if the window isn't bullshit.
if (GEOMETRY->width < 2 || GEOMETRY->height < 2) {
// Bullshit window. set to floating.
return Events::remapFloatingWindow(windowID);
}
}
CWindow window; CWindow window;
window.setDrawable(windowID); window.setDrawable(windowID);
window.setIsFloating(false); window.setIsFloating(false);
@ -112,10 +125,6 @@ CWindow* Events::remapWindow(int windowID, bool wasfloating) {
window.setWorkspaceID(g_pWindowManager->activeWorkspaces[CURRENTSCREEN]); window.setWorkspaceID(g_pWindowManager->activeWorkspaces[CURRENTSCREEN]);
window.setMonitor(CURRENTSCREEN); window.setMonitor(CURRENTSCREEN);
// For all floating windows, get their default size
const auto GEOMETRYCOOKIE = xcb_get_geometry(g_pWindowManager->DisplayConnection, windowID);
const auto GEOMETRY = xcb_get_geometry_reply(g_pWindowManager->DisplayConnection, GEOMETRYCOOKIE, 0);
if (GEOMETRY) { if (GEOMETRY) {
window.setDefaultPosition(Vector2D(GEOMETRY->x, GEOMETRY->y)); window.setDefaultPosition(Vector2D(GEOMETRY->x, GEOMETRY->y));
window.setDefaultSize(Vector2D(GEOMETRY->width, GEOMETRY->height)); window.setDefaultSize(Vector2D(GEOMETRY->width, GEOMETRY->height));

View file

@ -259,11 +259,14 @@ bool CWindowManager::handleEvent() {
free(ev); free(ev);
} }
// TODO: sanity check on open/closed window.
// refresh and apply the parameters of all dirty windows. // refresh and apply the parameters of all dirty windows.
refreshDirtyWindows(); refreshDirtyWindows();
// Sanity checks
for (const auto active : activeWorkspaces) {
sanityCheckOnWorkspace(active);
}
// remove unused workspaces // remove unused workspaces
cleanupUnusedWorkspaces(); cleanupUnusedWorkspaces();
@ -405,6 +408,55 @@ void CWindowManager::setFocusedWindow(xcb_drawable_t window) {
} }
} }
void CWindowManager::sanityCheckOnWorkspace(int workspaceID) {
for (auto& w : windows) {
if (w.getWorkspaceID() == workspaceID) {
// Check #1: Parent has 2 identical children (happens!)
if (w.getDrawable() < 0) {
const auto CHILDA = w.getChildNodeAID();
const auto CHILDB = w.getChildNodeBID();
if (CHILDA == CHILDB) {
// Fix. Remove this parent, replace with child.
Debug::log(LOG, "Sanity check A triggered for window ID " + std::to_string(w.getDrawable()));
const auto PCHILD = getWindowFromDrawable(CHILDA);
if (!PCHILD)
continue; // Should be cleaned later.
PCHILD->setPosition(w.getPosition());
PCHILD->setSize(w.getSize());
// make the sibling replace the parent
PCHILD->setParentNodeID(w.getParentNodeID());
if (w.getParentNodeID() != 0 && getWindowFromDrawable(w.getParentNodeID())) {
if (getWindowFromDrawable(w.getParentNodeID())->getChildNodeAID() == w.getDrawable()) {
getWindowFromDrawable(w.getParentNodeID())->setChildNodeAID(w.getDrawable());
} else {
getWindowFromDrawable(w.getParentNodeID())->setChildNodeBID(w.getDrawable());
}
}
// Make the sibling eat the closed window
PCHILD->setDirtyRecursive(true);
PCHILD->recalcSizePosRecursive();
// Remove the parent
removeWindowFromVectorSafe(w.getDrawable());
if (findWindowAtCursor())
setFocusedWindow(findWindowAtCursor()->getDrawable()); // Set focus. :)
Debug::log(LOG, "Sanity check A finished successfully.");
}
}
}
}
}
CWindow* CWindowManager::getWindowFromDrawable(int64_t window) { CWindow* CWindowManager::getWindowFromDrawable(int64_t window) {
for(auto& w : windows) { for(auto& w : windows) {
if (w.getDrawable() == window) { if (w.getDrawable() == window) {

View file

@ -86,6 +86,7 @@ public:
void setupRandrMonitors(); void setupRandrMonitors();
void sanityCheckOnWorkspace(int);
CWindow* getNeighborInDir(char dir); CWindow* getNeighborInDir(char dir);
void eatWindow(CWindow* a, CWindow* toEat); void eatWindow(CWindow* a, CWindow* toEat);
bool canEatWindow(CWindow* a, CWindow* toEat); bool canEatWindow(CWindow* a, CWindow* toEat);