diff options
author | alaricljs <[email protected]> | 2023-09-21 17:18:26 -0400 |
---|---|---|
committer | GitHub <[email protected]> | 2023-09-21 22:18:26 +0100 |
commit | e4ddfcfa0c944d0851feb9a359e6a224641060f7 (patch) | |
tree | 34933ec0377bced94a2924ff40c5f54dfd4a246f | |
parent | d41a91e050b242e53e7590e7b9267527f039b9f4 (diff) | |
download | Hyprland-e4ddfcfa0c944d0851feb9a359e6a224641060f7.tar.gz Hyprland-e4ddfcfa0c944d0851feb9a359e6a224641060f7.zip |
keybinds: implement pushactivetobottom dispacher (#3217)
Co-authored-by: Leeman <[email protected]>
-rw-r--r-- | src/Compositor.cpp | 57 | ||||
-rw-r--r-- | src/Compositor.hpp | 5 | ||||
-rw-r--r-- | src/events/Windows.cpp | 10 | ||||
-rw-r--r-- | src/layout/DwindleLayout.cpp | 2 | ||||
-rw-r--r-- | src/layout/IHyprLayout.cpp | 6 | ||||
-rw-r--r-- | src/layout/MasterLayout.cpp | 2 | ||||
-rw-r--r-- | src/managers/KeybindManager.cpp | 28 | ||||
-rw-r--r-- | src/managers/KeybindManager.hpp | 1 | ||||
-rw-r--r-- | src/managers/input/InputManager.cpp | 2 |
9 files changed, 78 insertions, 35 deletions
diff --git a/src/Compositor.cpp b/src/Compositor.cpp index 99e62a46..7e5a6c26 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -1240,15 +1240,24 @@ bool CCompositor::isWindowActive(CWindow* pWindow) { return PSURFACE == m_pLastFocus || pWindow == m_pLastWindow; } -void CCompositor::moveWindowToTop(CWindow* pWindow) { +void CCompositor::changeWindowZOrder(CWindow* pWindow, bool top) { if (!windowValidMapped(pWindow)) return; - auto moveToTop = [&](CWindow* pw) -> void { - for (auto it = m_vWindows.begin(); it != m_vWindows.end(); ++it) { - if (it->get() == pw) { - std::rotate(it, it + 1, m_vWindows.end()); - break; + auto moveToZ = [&](CWindow* pw, bool top) -> void { + if (top) { + for (auto it = m_vWindows.begin(); it != m_vWindows.end(); ++it) { + if (it->get() == pw) { + std::rotate(it, it + 1, m_vWindows.end()); + break; + } + } + } else { + for (auto it = m_vWindows.rbegin(); it != m_vWindows.rend(); ++it) { + if (it->get() == pw) { + std::rotate(it, it + 1, m_vWindows.rend()); + break; + } } } @@ -1256,27 +1265,35 @@ void CCompositor::moveWindowToTop(CWindow* pWindow) { g_pHyprRenderer->damageMonitor(getMonitorFromID(pw->m_iMonitorID)); }; - moveToTop(pWindow); + if (top) + pWindow->m_bCreatedOverFullscreen = true; - pWindow->m_bCreatedOverFullscreen = true; - - if (!pWindow->m_bIsX11) + if (!pWindow->m_bIsX11) { + moveToZ(pWindow, top); return; + } else { + // move X11 window stack - // move all children + std::deque<CWindow*> toMove; - std::deque<CWindow*> toMove; + auto x11Stack = [&](CWindow* pw, bool top, auto&& x11Stack) -> void { + if (top) + toMove.emplace_back(pw); + else + toMove.emplace_front(pw); - for (auto& w : m_vWindows) { - if (w->m_bIsMapped && w->m_bMappedX11 && !w->isHidden() && w->m_bIsX11 && w->X11TransientFor() == pWindow) { - toMove.emplace_back(w.get()); - } - } + for (auto& w : m_vWindows) { + if (w->m_bIsMapped && w->m_bMappedX11 && !w->isHidden() && w->m_bIsX11 && w->X11TransientFor() == pw) { + x11Stack(w.get(), top, x11Stack); + } + } + }; - for (auto& pw : toMove) { - moveToTop(pw); + x11Stack(pWindow, top, x11Stack); - moveWindowToTop(pw); + for (auto it : toMove) { + moveToZ(it, top); + } } } diff --git a/src/Compositor.hpp b/src/Compositor.hpp index 2661af27..9102bac4 100644 --- a/src/Compositor.hpp +++ b/src/Compositor.hpp @@ -28,8 +28,7 @@ #include "hyprerror/HyprError.hpp" #include "plugins/PluginSystem.hpp" -enum eManagersInitStage -{ +enum eManagersInitStage { STAGE_PRIORITY = 0, STAGE_LATE }; @@ -160,7 +159,7 @@ class CCompositor { CWindow* getFullscreenWindowOnWorkspace(const int&); bool doesSeatAcceptInput(wlr_surface*); bool isWindowActive(CWindow*); - void moveWindowToTop(CWindow*); + void changeWindowZOrder(CWindow*, bool); void cleanupFadingOut(const int& monid); CWindow* getWindowInDirection(CWindow*, char); CWindow* getNextWindowOnWorkspace(CWindow*, bool focusableOnly = false); diff --git a/src/events/Windows.cpp b/src/events/Windows.cpp index 36646eed..41c19ab4 100644 --- a/src/events/Windows.cpp +++ b/src/events/Windows.cpp @@ -406,7 +406,7 @@ void Events::listener_mapWindow(void* owner, void* data) { // because the windows are animated on RealSize PWINDOW->m_vPseudoSize = PWINDOW->m_vRealSize.goalv(); - g_pCompositor->moveWindowToTop(PWINDOW); + g_pCompositor->changeWindowZOrder(PWINDOW, true); } else { g_pLayoutManager->getCurrentLayout()->onWindowCreated(PWINDOW); @@ -903,7 +903,7 @@ void Events::listener_activateXDG(wl_listener* listener, void* data) { return; if (PWINDOW->m_bIsFloating) - g_pCompositor->moveWindowToTop(PWINDOW); + g_pCompositor->changeWindowZOrder(PWINDOW, true); g_pCompositor->focusWindow(PWINDOW); g_pCompositor->warpCursorTo(PWINDOW->middle()); @@ -937,7 +937,7 @@ void Events::listener_activateX11(void* owner, void* data) { return; if (PWINDOW->m_bIsFloating) - g_pCompositor->moveWindowToTop(PWINDOW); + g_pCompositor->changeWindowZOrder(PWINDOW, true); g_pCompositor->focusWindow(PWINDOW); g_pCompositor->warpCursorTo(PWINDOW->middle()); @@ -985,7 +985,7 @@ void Events::listener_configureX11(void* owner, void* data) { PWINDOW->m_iWorkspaceID = g_pCompositor->getMonitorFromVector(PWINDOW->m_vRealPosition.vec() + PWINDOW->m_vRealSize.vec() / 2.f)->activeWorkspace; - g_pCompositor->moveWindowToTop(PWINDOW); + g_pCompositor->changeWindowZOrder(PWINDOW, true); PWINDOW->m_bCreatedOverFullscreen = true; @@ -1042,7 +1042,7 @@ void Events::listener_unmanagedSetGeometry(void* owner, void* data) { PWINDOW->m_iWorkspaceID = g_pCompositor->getMonitorFromVector(PWINDOW->m_vRealPosition.vec() + PWINDOW->m_vRealSize.vec() / 2.f)->activeWorkspace; - g_pCompositor->moveWindowToTop(PWINDOW); + g_pCompositor->changeWindowZOrder(PWINDOW, true); PWINDOW->updateWindowDecos(); g_pHyprRenderer->damageWindow(PWINDOW); } diff --git a/src/layout/DwindleLayout.cpp b/src/layout/DwindleLayout.cpp index 010cd6b4..1688b417 100644 --- a/src/layout/DwindleLayout.cpp +++ b/src/layout/DwindleLayout.cpp @@ -851,7 +851,7 @@ void CHyprDwindleLayout::fullscreenRequestForWindow(CWindow* pWindow, eFullscree g_pXWaylandManager->setWindowSize(pWindow, pWindow->m_vRealSize.goalv()); - g_pCompositor->moveWindowToTop(pWindow); + g_pCompositor->changeWindowZOrder(pWindow, true); recalculateMonitor(PMONITOR->ID); } diff --git a/src/layout/IHyprLayout.cpp b/src/layout/IHyprLayout.cpp index 46883570..637eeb2a 100644 --- a/src/layout/IHyprLayout.cpp +++ b/src/layout/IHyprLayout.cpp @@ -161,7 +161,7 @@ void IHyprLayout::onWindowCreatedFloating(CWindow* pWindow) { if (pWindow->m_iX11Type != 2) { g_pXWaylandManager->setWindowSize(pWindow, pWindow->m_vRealSize.goalv()); - g_pCompositor->moveWindowToTop(pWindow); + g_pCompositor->changeWindowZOrder(pWindow, true); } } @@ -237,7 +237,7 @@ void IHyprLayout::onBeginDragWindow() { g_pKeybindManager->shadowKeybinds(); g_pCompositor->focusWindow(DRAGGINGWINDOW); - g_pCompositor->moveWindowToTop(DRAGGINGWINDOW); + g_pCompositor->changeWindowZOrder(DRAGGINGWINDOW, true); } void IHyprLayout::onEndDragWindow() { @@ -436,7 +436,7 @@ void IHyprLayout::changeWindowFloatingMode(CWindow* pWindow) { } else { onWindowRemovedTiling(pWindow); - g_pCompositor->moveWindowToTop(pWindow); + g_pCompositor->changeWindowZOrder(pWindow, true); if (DELTALESSTHAN(pWindow->m_vRealSize.vec().x, pWindow->m_vLastFloatingSize.x, 10) && DELTALESSTHAN(pWindow->m_vRealSize.vec().y, pWindow->m_vLastFloatingSize.y, 10)) { pWindow->m_vRealPosition = pWindow->m_vRealPosition.goalv() + (pWindow->m_vRealSize.goalv() - pWindow->m_vLastFloatingSize) / 2.f + Vector2D{10, 10}; diff --git a/src/layout/MasterLayout.cpp b/src/layout/MasterLayout.cpp index 576397f6..5b5d0122 100644 --- a/src/layout/MasterLayout.cpp +++ b/src/layout/MasterLayout.cpp @@ -868,7 +868,7 @@ void CHyprMasterLayout::fullscreenRequestForWindow(CWindow* pWindow, eFullscreen g_pXWaylandManager->setWindowSize(pWindow, pWindow->m_vRealSize.goalv()); - g_pCompositor->moveWindowToTop(pWindow); + g_pCompositor->changeWindowZOrder(pWindow, true); recalculateMonitor(PMONITOR->ID); } diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 992e15b3..0703ba2e 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -63,6 +63,7 @@ CKeybindManager::CKeybindManager() { m_mDispatchers["pin"] = pinActive; m_mDispatchers["mouse"] = mouse; m_mDispatchers["bringactivetotop"] = bringActiveToTop; + m_mDispatchers["alterzorder"] = alterZOrder; m_mDispatchers["focusurgentorlast"] = focusUrgentOrLast; m_mDispatchers["focuscurrentorlast"] = focusCurrentOrLast; m_mDispatchers["lockgroups"] = lockGroups; @@ -1910,7 +1911,32 @@ void CKeybindManager::mouse(std::string args) { void CKeybindManager::bringActiveToTop(std::string args) { if (g_pCompositor->m_pLastWindow && g_pCompositor->m_pLastWindow->m_bIsFloating) - g_pCompositor->moveWindowToTop(g_pCompositor->m_pLastWindow); + g_pCompositor->changeWindowZOrder(g_pCompositor->m_pLastWindow, true); +} + +void CKeybindManager::alterZOrder(std::string args) { + const auto WINDOWREGEX = args.substr(args.find_first_of(',') + 1); + const auto POSITION = args.substr(0, args.find_first_of(',')); + auto PWINDOW = g_pCompositor->getWindowByRegex(WINDOWREGEX); + + if (!PWINDOW && g_pCompositor->m_pLastWindow && g_pCompositor->m_pLastWindow->m_bIsFloating) + PWINDOW = g_pCompositor->m_pLastWindow; + + if (!PWINDOW) { + Debug::log(ERR, "alterZOrder: no window"); + return; + } + + if (POSITION == "top") + g_pCompositor->changeWindowZOrder(PWINDOW, 1); + else if (POSITION == "bottom") + g_pCompositor->changeWindowZOrder(PWINDOW, 0); + else { + Debug::log(ERR, "alterZOrder: bad position: %s", POSITION); + return; + } + + g_pInputManager->simulateMouseMovement(); } void CKeybindManager::fakeFullscreenActive(std::string args) { diff --git a/src/managers/KeybindManager.hpp b/src/managers/KeybindManager.hpp index f0d39192..4a4ebeab 100644 --- a/src/managers/KeybindManager.hpp +++ b/src/managers/KeybindManager.hpp @@ -143,6 +143,7 @@ class CKeybindManager { static void pinActive(std::string); static void mouse(std::string); static void bringActiveToTop(std::string); + static void alterZOrder(std::string); static void lockGroups(std::string); static void lockActiveGroup(std::string); static void moveIntoGroup(std::string); diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index a44e4c51..3567c974 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -600,7 +600,7 @@ void CInputManager::processMouseDownNormal(wlr_pointer_button_event* e) { // if clicked on a floating window make it top if (g_pCompositor->m_pLastWindow && g_pCompositor->m_pLastWindow->m_bIsFloating) - g_pCompositor->moveWindowToTop(g_pCompositor->m_pLastWindow); + g_pCompositor->changeWindowZOrder(g_pCompositor->m_pLastWindow, true); break; case WLR_BUTTON_RELEASED: break; |