mirror of
https://github.com/hyprwm/Hypr.git
synced 2024-11-22 13:35:57 +01:00
Sanity check against duped children
This commit is contained in:
parent
8f172a4e55
commit
ad87629d51
3 changed files with 68 additions and 6 deletions
|
@ -100,6 +100,19 @@ CWindow* Events::remapFloatingWindow(int windowID) {
|
|||
|
||||
CWindow* Events::remapWindow(int windowID, bool wasfloating) {
|
||||
// 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;
|
||||
window.setDrawable(windowID);
|
||||
window.setIsFloating(false);
|
||||
|
@ -112,10 +125,6 @@ CWindow* Events::remapWindow(int windowID, bool wasfloating) {
|
|||
window.setWorkspaceID(g_pWindowManager->activeWorkspaces[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) {
|
||||
window.setDefaultPosition(Vector2D(GEOMETRY->x, GEOMETRY->y));
|
||||
window.setDefaultSize(Vector2D(GEOMETRY->width, GEOMETRY->height));
|
||||
|
|
|
@ -259,11 +259,14 @@ bool CWindowManager::handleEvent() {
|
|||
free(ev);
|
||||
}
|
||||
|
||||
// TODO: sanity check on open/closed window.
|
||||
|
||||
// refresh and apply the parameters of all dirty windows.
|
||||
refreshDirtyWindows();
|
||||
|
||||
// Sanity checks
|
||||
for (const auto active : activeWorkspaces) {
|
||||
sanityCheckOnWorkspace(active);
|
||||
}
|
||||
|
||||
// remove unused workspaces
|
||||
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) {
|
||||
for(auto& w : windows) {
|
||||
if (w.getDrawable() == window) {
|
||||
|
|
|
@ -86,6 +86,7 @@ public:
|
|||
|
||||
void setupRandrMonitors();
|
||||
|
||||
void sanityCheckOnWorkspace(int);
|
||||
CWindow* getNeighborInDir(char dir);
|
||||
void eatWindow(CWindow* a, CWindow* toEat);
|
||||
bool canEatWindow(CWindow* a, CWindow* toEat);
|
||||
|
|
Loading…
Reference in a new issue