From cbadf3e3f31ab5ad5d192daac5f2ca930d08b8fb Mon Sep 17 00:00:00 2001 From: MightyPlaza <123664421+MightyPlaza@users.noreply.github.com> Date: Sun, 4 Feb 2024 15:40:20 +0000 Subject: [PATCH] input: focus window on mouse down on decoration (#4514) Also unifies vectorToWindow funcs --- src/Compositor.cpp | 159 ++++++++-------------------- src/Compositor.hpp | 5 +- src/SharedDefs.hpp | 7 +- src/Window.cpp | 32 ++---- src/Window.hpp | 12 ++- src/helpers/Monitor.cpp | 2 +- src/helpers/Vector2D.cpp | 4 + src/helpers/Vector2D.hpp | 2 + src/layout/DwindleLayout.cpp | 4 +- src/layout/IHyprLayout.cpp | 9 +- src/managers/KeybindManager.cpp | 9 +- src/managers/input/InputManager.cpp | 22 ++-- 12 files changed, 105 insertions(+), 162 deletions(-) diff --git a/src/Compositor.cpp b/src/Compositor.cpp index db2e5f4a..cefd9652 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -685,27 +685,7 @@ bool CCompositor::windowExists(CWindow* pWindow) { return false; } -CWindow* CCompositor::vectorToWindowTiled(const Vector2D& pos) { - const auto PMONITOR = getMonitorFromVector(pos); - - if (PMONITOR->specialWorkspaceID) { - for (auto& w : m_vWindows) { - CBox box = {w->m_vPosition.x, w->m_vPosition.y, w->m_vSize.x, w->m_vSize.y}; - if (w->m_iWorkspaceID == PMONITOR->specialWorkspaceID && box.containsPoint(pos) && !w->m_bIsFloating && !w->isHidden() && !w->m_bNoFocus) - return w.get(); - } - } - - for (auto& w : m_vWindows) { - CBox box = {w->m_vPosition.x, w->m_vPosition.y, w->m_vSize.x, w->m_vSize.y}; - if (w->m_bIsMapped && box.containsPoint(pos) && w->m_iWorkspaceID == PMONITOR->activeWorkspace && !w->m_bIsFloating && !w->isHidden() && !w->m_bNoFocus) - return w.get(); - } - - return nullptr; -} - -CWindow* CCompositor::vectorToWindowIdeal(const Vector2D& pos, CWindow* pIgnoreWindow) { +CWindow* CCompositor::vectorToWindowUnified(const Vector2D& pos, uint8_t properties, CWindow* pIgnoreWindow) { const auto PMONITOR = getMonitorFromVector(pos); static auto* const PRESIZEONBORDER = &g_pConfigManager->getConfigValuePtr("general:resize_on_border")->intValue; static auto* const PBORDERSIZE = &g_pConfigManager->getConfigValuePtr("general:border_size")->intValue; @@ -714,44 +694,13 @@ CWindow* CCompositor::vectorToWindowIdeal(const Vector2D& pos, CWindow* pIgnoreW const auto BORDER_GRAB_AREA = *PRESIZEONBORDER ? *PBORDERSIZE + *PBORDERGRABEXTEND : 0; // pinned windows on top of floating regardless - for (auto& w : m_vWindows | std::views::reverse) { - const auto BB = w->getWindowInputBox(); - CBox box = {BB.x - BORDER_GRAB_AREA, BB.y - BORDER_GRAB_AREA, BB.width + 2 * BORDER_GRAB_AREA, BB.height + 2 * BORDER_GRAB_AREA}; - if (w->m_bIsFloating && w->m_bIsMapped && !w->isHidden() && !w->m_bX11ShouldntFocus && w->m_bPinned && !w->m_bNoFocus && w.get() != pIgnoreWindow) { - if (box.containsPoint({m_sWLRCursor->x, m_sWLRCursor->y})) - return w.get(); - - if (!w->m_bIsX11) { - if (w->hasPopupAt(pos)) - return w.get(); - } - } - } - - auto windowForWorkspace = [&](bool special) -> CWindow* { - // first loop over floating cuz they're above, m_lWindows should be sorted bottom->top, for tiled it doesn't matter. + if (properties & ALLOW_FLOATING) { for (auto& w : m_vWindows | std::views::reverse) { - - if (special && !isWorkspaceSpecial(w->m_iWorkspaceID)) // because special floating may creep up into regular - continue; - - const auto BB = w->getWindowInputBox(); + const auto BB = w->getWindowBoxUnified(properties); CBox box = {BB.x - BORDER_GRAB_AREA, BB.y - BORDER_GRAB_AREA, BB.width + 2 * BORDER_GRAB_AREA, BB.height + 2 * BORDER_GRAB_AREA}; - if (w->m_bIsFloating && w->m_bIsMapped && isWorkspaceVisible(w->m_iWorkspaceID) && !w->isHidden() && !w->m_bPinned && !w->m_bNoFocus && w.get() != pIgnoreWindow) { - // OR windows should add focus to parent - if (w->m_bX11ShouldntFocus && w->m_iX11Type != 2) - continue; - - if (box.containsPoint({m_sWLRCursor->x, m_sWLRCursor->y})) { - - if (w->m_bIsX11 && w->m_iX11Type == 2 && !wlr_xwayland_or_surface_wants_focus(w->m_uSurface.xwayland)) { - // Override Redirect - return g_pCompositor->m_pLastWindow; // we kinda trick everything here. - // TODO: this is wrong, we should focus the parent, but idk how to get it considering it's nullptr in most cases. - } - + if (w->m_bIsFloating && w->m_bIsMapped && !w->isHidden() && !w->m_bX11ShouldntFocus && w->m_bPinned && !w->m_bNoFocus && w.get() != pIgnoreWindow) { + if (box.containsPoint({m_sWLRCursor->x, m_sWLRCursor->y})) return w.get(); - } if (!w->m_bIsX11) { if (w->hasPopupAt(pos)) @@ -759,6 +708,44 @@ CWindow* CCompositor::vectorToWindowIdeal(const Vector2D& pos, CWindow* pIgnoreW } } } + } + + auto windowForWorkspace = [&](bool special) -> CWindow* { + if (properties & ALLOW_FLOATING) { + // first loop over floating cuz they're above, m_lWindows should be sorted bottom->top, for tiled it doesn't matter. + for (auto& w : m_vWindows | std::views::reverse) { + + if (special && !isWorkspaceSpecial(w->m_iWorkspaceID)) // because special floating may creep up into regular + continue; + + const auto BB = w->getWindowBoxUnified(properties); + CBox box = {BB.x - BORDER_GRAB_AREA, BB.y - BORDER_GRAB_AREA, BB.width + 2 * BORDER_GRAB_AREA, BB.height + 2 * BORDER_GRAB_AREA}; + if (w->m_bIsFloating && w->m_bIsMapped && isWorkspaceVisible(w->m_iWorkspaceID) && !w->isHidden() && !w->m_bPinned && !w->m_bNoFocus && w.get() != pIgnoreWindow) { + // OR windows should add focus to parent + if (w->m_bX11ShouldntFocus && w->m_iX11Type != 2) + continue; + + if (box.containsPoint({m_sWLRCursor->x, m_sWLRCursor->y})) { + + if (w->m_bIsX11 && w->m_iX11Type == 2 && !wlr_xwayland_or_surface_wants_focus(w->m_uSurface.xwayland)) { + // Override Redirect + return g_pCompositor->m_pLastWindow; // we kinda trick everything here. + // TODO: this is wrong, we should focus the parent, but idk how to get it considering it's nullptr in most cases. + } + + return w.get(); + } + + if (!w->m_bIsX11) { + if (w->hasPopupAt(pos)) + return w.get(); + } + } + } + } + + if (properties & FLOATING_ONLY) + return nullptr; const int64_t WORKSPACEID = special ? PMONITOR->specialWorkspaceID : PMONITOR->activeWorkspace; const auto PWORKSPACE = getWorkspaceByID(WORKSPACEID); @@ -782,7 +769,7 @@ CWindow* CCompositor::vectorToWindowIdeal(const Vector2D& pos, CWindow* pIgnoreW if (special != isWorkspaceSpecial(w->m_iWorkspaceID)) continue; - CBox box = {w->m_vPosition, w->m_vSize}; + CBox box = (properties & USE_PROP_TILED) ? w->getWindowBoxUnified(properties) : CBox{w->m_vPosition, w->m_vSize}; if (!w->m_bIsFloating && w->m_bIsMapped && box.containsPoint(pos) && w->m_iWorkspaceID == WORKSPACEID && !w->isHidden() && !w->m_bX11ShouldntFocus && !w->m_bNoFocus && w.get() != pIgnoreWindow) return w.get(); @@ -805,64 +792,6 @@ CWindow* CCompositor::vectorToWindowIdeal(const Vector2D& pos, CWindow* pIgnoreW return windowForWorkspace(false); } -CWindow* CCompositor::windowFromCursor() { - const auto PMONITOR = getMonitorFromCursor(); - - if (PMONITOR->specialWorkspaceID) { - for (auto& w : m_vWindows | std::views::reverse) { - CBox box = {w->m_vRealPosition.vec().x, w->m_vRealPosition.vec().y, w->m_vRealSize.vec().x, w->m_vRealSize.vec().y}; - if (w->m_bIsFloating && w->m_iWorkspaceID == PMONITOR->specialWorkspaceID && w->m_bIsMapped && box.containsPoint({m_sWLRCursor->x, m_sWLRCursor->y}) && - !w->isHidden() && !w->m_bNoFocus) - return w.get(); - } - - for (auto& w : m_vWindows) { - CBox box = {w->m_vPosition.x, w->m_vPosition.y, w->m_vSize.x, w->m_vSize.y}; - if (w->m_iWorkspaceID == PMONITOR->specialWorkspaceID && box.containsPoint({m_sWLRCursor->x, m_sWLRCursor->y}) && w->m_bIsMapped && !w->m_bNoFocus) - return w.get(); - } - } - - // pinned - for (auto& w : m_vWindows | std::views::reverse) { - CBox box = {w->m_vRealPosition.vec().x, w->m_vRealPosition.vec().y, w->m_vRealSize.vec().x, w->m_vRealSize.vec().y}; - if (box.containsPoint({m_sWLRCursor->x, m_sWLRCursor->y}) && w->m_bIsMapped && w->m_bIsFloating && w->m_bPinned && !w->m_bNoFocus) - return w.get(); - } - - // first loop over floating cuz they're above, m_lWindows should be sorted bottom->top, for tiled it doesn't matter. - for (auto& w : m_vWindows | std::views::reverse) { - CBox box = {w->m_vRealPosition.vec().x, w->m_vRealPosition.vec().y, w->m_vRealSize.vec().x, w->m_vRealSize.vec().y}; - if (box.containsPoint({m_sWLRCursor->x, m_sWLRCursor->y}) && w->m_bIsMapped && w->m_bIsFloating && isWorkspaceVisible(w->m_iWorkspaceID) && !w->m_bPinned && !w->m_bNoFocus) - return w.get(); - } - - for (auto& w : m_vWindows) { - CBox box = {w->m_vPosition.x, w->m_vPosition.y, w->m_vSize.x, w->m_vSize.y}; - if (box.containsPoint({m_sWLRCursor->x, m_sWLRCursor->y}) && w->m_bIsMapped && w->m_iWorkspaceID == PMONITOR->activeWorkspace && !w->m_bNoFocus) - return w.get(); - } - - return nullptr; -} - -CWindow* CCompositor::windowFloatingFromCursor() { - for (auto& w : m_vWindows | std::views::reverse) { - CBox box = {w->m_vRealPosition.vec().x, w->m_vRealPosition.vec().y, w->m_vRealSize.vec().x, w->m_vRealSize.vec().y}; - if (box.containsPoint({m_sWLRCursor->x, m_sWLRCursor->y}) && w->m_bIsMapped && w->m_bIsFloating && !w->isHidden() && w->m_bPinned && !w->m_bNoFocus) - return w.get(); - } - - for (auto& w : m_vWindows | std::views::reverse) { - CBox box = {w->m_vRealPosition.vec().x, w->m_vRealPosition.vec().y, w->m_vRealSize.vec().x, w->m_vRealSize.vec().y}; - if (box.containsPoint({m_sWLRCursor->x, m_sWLRCursor->y}) && w->m_bIsMapped && w->m_bIsFloating && isWorkspaceVisible(w->m_iWorkspaceID) && !w->isHidden() && - !w->m_bPinned && !w->m_bNoFocus) - return w.get(); - } - - return nullptr; -} - wlr_surface* CCompositor::vectorWindowToSurface(const Vector2D& pos, CWindow* pWindow, Vector2D& sl) { if (!windowValidMapped(pWindow)) diff --git a/src/Compositor.hpp b/src/Compositor.hpp index 9372839a..3fe5a730 100644 --- a/src/Compositor.hpp +++ b/src/Compositor.hpp @@ -135,14 +135,11 @@ class CCompositor { void focusSurface(wlr_surface*, CWindow* pWindowOwner = nullptr); bool windowExists(CWindow*); bool windowValidMapped(CWindow*); - CWindow* vectorToWindowIdeal(const Vector2D&, CWindow* pIgnoreWindow = nullptr); // used only for finding a window to focus on, basically a "findFocusableWindow" - CWindow* vectorToWindowTiled(const Vector2D&); + CWindow* vectorToWindowUnified(const Vector2D&, uint8_t properties, CWindow* pIgnoreWindow = nullptr); wlr_surface* vectorToLayerSurface(const Vector2D&, std::vector>*, Vector2D*, SLayerSurface**); SIMEPopup* vectorToIMEPopup(const Vector2D& pos, std::list& popups); wlr_surface* vectorWindowToSurface(const Vector2D&, CWindow*, Vector2D& sl); Vector2D vectorToSurfaceLocal(const Vector2D&, CWindow*, wlr_surface*); - CWindow* windowFromCursor(); - CWindow* windowFloatingFromCursor(); CMonitor* getMonitorFromOutput(wlr_output*); CWindow* getWindowForPopup(wlr_xdg_popup*); CWindow* getWindowFromSurface(wlr_surface*); diff --git a/src/SharedDefs.hpp b/src/SharedDefs.hpp index da7f6938..3dfb272a 100644 --- a/src/SharedDefs.hpp +++ b/src/SharedDefs.hpp @@ -52,4 +52,9 @@ struct SWindowDecorationExtents { bool operator==(const SWindowDecorationExtents& other) const { return topLeft == other.topLeft && bottomRight == other.bottomRight; } -}; \ No newline at end of file + + void addExtents(const SWindowDecorationExtents& other) { + topLeft = topLeft.getComponentMax(other.topLeft); + bottomRight = bottomRight.getComponentMax(other.bottomRight); + } +}; diff --git a/src/Window.cpp b/src/Window.cpp index d821b1b9..1a7b9de9 100644 --- a/src/Window.cpp +++ b/src/Window.cpp @@ -139,35 +139,25 @@ CBox CWindow::getWindowIdealBoundingBoxIgnoreReserved() { return CBox{(int)POS.x, (int)POS.y, (int)SIZE.x, (int)SIZE.y}; } -CBox CWindow::getWindowInputBox() { - const int BORDERSIZE = getRealBorderSize(); +CBox CWindow::getWindowBoxUnified(uint64_t properties) { if (m_sAdditionalConfigData.dimAround) { const auto PMONITOR = g_pCompositor->getMonitorFromID(m_iMonitorID); return {PMONITOR->vecPosition.x, PMONITOR->vecPosition.y, PMONITOR->vecSize.x, PMONITOR->vecSize.y}; } - SWindowDecorationExtents maxExtents = {{BORDERSIZE + 2, BORDERSIZE + 2}, {BORDERSIZE + 2, BORDERSIZE + 2}}; + SWindowDecorationExtents EXTENTS = {{0, 0}, {0, 0}}; + if (properties & RESERVED_EXTENTS) + EXTENTS.addExtents(g_pDecorationPositioner->getWindowDecorationReserved(this)); + if (properties & INPUT_EXTENTS) + EXTENTS.addExtents(g_pDecorationPositioner->getWindowDecorationExtents(this, true)); + if (properties & FULL_EXTENTS) + EXTENTS.addExtents(g_pDecorationPositioner->getWindowDecorationExtents(this, false)); - const auto EXTENTS = g_pDecorationPositioner->getWindowDecorationExtents(this, true); + CBox box = {m_vRealPosition.vec().x, m_vRealPosition.vec().y, m_vRealSize.vec().x, m_vRealSize.vec().y}; + box.addExtents(EXTENTS); - if (EXTENTS.topLeft.x > maxExtents.topLeft.x) - maxExtents.topLeft.x = EXTENTS.topLeft.x; - - if (EXTENTS.topLeft.y > maxExtents.topLeft.y) - maxExtents.topLeft.y = EXTENTS.topLeft.y; - - if (EXTENTS.bottomRight.x > maxExtents.bottomRight.x) - maxExtents.bottomRight.x = EXTENTS.bottomRight.x; - - if (EXTENTS.bottomRight.y > maxExtents.bottomRight.y) - maxExtents.bottomRight.y = EXTENTS.bottomRight.y; - - // Add extents to the real base BB and return - CBox finalBox = {m_vRealPosition.vec().x - maxExtents.topLeft.x, m_vRealPosition.vec().y - maxExtents.topLeft.y, - m_vRealSize.vec().x + maxExtents.topLeft.x + maxExtents.bottomRight.x, m_vRealSize.vec().y + maxExtents.topLeft.y + maxExtents.bottomRight.y}; - - return finalBox; + return box; } CBox CWindow::getWindowMainSurfaceBox() { diff --git a/src/Window.hpp b/src/Window.hpp index bbe7dc07..b0689b61 100644 --- a/src/Window.hpp +++ b/src/Window.hpp @@ -30,6 +30,16 @@ enum eGroupRules { GROUP_OVERRIDE = 1 << 6, // Override other rules }; +enum eGetWindowProperties { + WINDOW_ONLY = 0, + RESERVED_EXTENTS = 1 << 0, + INPUT_EXTENTS = 1 << 1, + FULL_EXTENTS = 1 << 2, + FLOATING_ONLY = 1 << 3, + ALLOW_FLOATING = 1 << 4, + USE_PROP_TILED = 1 << 5 +}; + class IWindowTransformer; template @@ -342,7 +352,7 @@ class CWindow { // methods CBox getFullWindowBoundingBox(); SWindowDecorationExtents getFullWindowExtents(); - CBox getWindowInputBox(); + CBox getWindowBoxUnified(uint64_t props); CBox getWindowMainSurfaceBox(); CBox getWindowIdealBoundingBoxIgnoreReserved(); void addWindowDeco(std::unique_ptr deco); diff --git a/src/helpers/Monitor.cpp b/src/helpers/Monitor.cpp index f9cc5472..f084d3c0 100644 --- a/src/helpers/Monitor.cpp +++ b/src/helpers/Monitor.cpp @@ -541,7 +541,7 @@ void CMonitor::changeWorkspace(CWorkspace* const pWorkspace, bool internal, bool if (!pWindow) { if (*PFOLLOWMOUSE == 1) - pWindow = g_pCompositor->vectorToWindowIdeal(g_pInputManager->getMouseCoordsInternal()); + pWindow = g_pCompositor->vectorToWindowUnified(g_pInputManager->getMouseCoordsInternal(), RESERVED_EXTENTS | INPUT_EXTENTS | ALLOW_FLOATING); if (!pWindow) pWindow = g_pCompositor->getTopLeftWindowOnWorkspace(pWorkspace->m_iID); diff --git a/src/helpers/Vector2D.cpp b/src/helpers/Vector2D.cpp index fb432936..4cd3476b 100644 --- a/src/helpers/Vector2D.cpp +++ b/src/helpers/Vector2D.cpp @@ -45,3 +45,7 @@ double Vector2D::distance(const Vector2D& other) const { double Vector2D::size() const { return std::sqrt(x * x + y * y); } + +Vector2D Vector2D::getComponentMax(const Vector2D& other) const { + return Vector2D(std::max(this->x, other.x), std::max(this->y, other.y)); +} diff --git a/src/helpers/Vector2D.hpp b/src/helpers/Vector2D.hpp index 16f18793..c56e8a04 100644 --- a/src/helpers/Vector2D.hpp +++ b/src/helpers/Vector2D.hpp @@ -92,6 +92,8 @@ class Vector2D { Vector2D floor() const; Vector2D round() const; + + Vector2D getComponentMax(const Vector2D& other) const; }; /** diff --git a/src/layout/DwindleLayout.cpp b/src/layout/DwindleLayout.cpp index 4058121f..819d7b3e 100644 --- a/src/layout/DwindleLayout.cpp +++ b/src/layout/DwindleLayout.cpp @@ -272,7 +272,7 @@ void CHyprDwindleLayout::onWindowCreatedTiling(CWindow* pWindow, eDirection dire if (PMONITOR->ID == MONFROMCURSOR->ID && (PNODE->workspaceID == PMONITOR->activeWorkspace || (g_pCompositor->isWorkspaceSpecial(PNODE->workspaceID) && PMONITOR->specialWorkspaceID)) && !*PUSEACTIVE) { - OPENINGON = getNodeFromWindow(g_pCompositor->vectorToWindowTiled(MOUSECOORDS)); + OPENINGON = getNodeFromWindow(g_pCompositor->vectorToWindowUnified(MOUSECOORDS, RESERVED_EXTENTS | INPUT_EXTENTS)); if (!OPENINGON && g_pCompositor->isPointOnReservedArea(MOUSECOORDS, PMONITOR)) OPENINGON = getClosestNodeOnWorkspace(PNODE->workspaceID, MOUSECOORDS); @@ -282,7 +282,7 @@ void CHyprDwindleLayout::onWindowCreatedTiling(CWindow* pWindow, eDirection dire g_pCompositor->m_pLastWindow->m_iWorkspaceID == pWindow->m_iWorkspaceID && g_pCompositor->m_pLastWindow->m_bIsMapped) { OPENINGON = getNodeFromWindow(g_pCompositor->m_pLastWindow); } else { - OPENINGON = getNodeFromWindow(g_pCompositor->vectorToWindowTiled(MOUSECOORDS)); + OPENINGON = getNodeFromWindow(g_pCompositor->vectorToWindowUnified(MOUSECOORDS, RESERVED_EXTENTS | INPUT_EXTENTS)); } if (!OPENINGON && g_pCompositor->isPointOnReservedArea(MOUSECOORDS, PMONITOR)) diff --git a/src/layout/IHyprLayout.cpp b/src/layout/IHyprLayout.cpp index 705f48cf..cf3cf405 100644 --- a/src/layout/IHyprLayout.cpp +++ b/src/layout/IHyprLayout.cpp @@ -268,9 +268,9 @@ void IHyprLayout::onEndDragWindow() { } else if (g_pInputManager->dragMode == MBIND_MOVE) { g_pHyprRenderer->damageWindow(DRAGGINGWINDOW); const auto MOUSECOORDS = g_pInputManager->getMouseCoordsInternal(); - CWindow* pWindow = g_pCompositor->vectorToWindowIdeal(MOUSECOORDS, DRAGGINGWINDOW); + CWindow* pWindow = g_pCompositor->vectorToWindowUnified(MOUSECOORDS, RESERVED_EXTENTS | INPUT_EXTENTS | ALLOW_FLOATING | FLOATING_ONLY, DRAGGINGWINDOW); - if (pWindow && pWindow->m_bIsFloating) { + if (pWindow) { if (pWindow->checkInputOnDecos(INPUT_TYPE_DRAG_END, MOUSECOORDS, DRAGGINGWINDOW)) return; @@ -543,7 +543,8 @@ CWindow* IHyprLayout::getNextWindowCandidate(CWindow* pWindow) { return m_pLastTiledWindow; // if we don't, let's try to find any window that is in the middle - if (const auto PWINDOWCANDIDATE = g_pCompositor->vectorToWindowIdeal(pWindow->middle()); PWINDOWCANDIDATE && PWINDOWCANDIDATE != pWindow) + if (const auto PWINDOWCANDIDATE = g_pCompositor->vectorToWindowUnified(pWindow->middle(), RESERVED_EXTENTS | INPUT_EXTENTS | ALLOW_FLOATING); + PWINDOWCANDIDATE && PWINDOWCANDIDATE != pWindow) return PWINDOWCANDIDATE; // if not, floating window @@ -558,7 +559,7 @@ CWindow* IHyprLayout::getNextWindowCandidate(CWindow* pWindow) { } // if it was a tiled window, we first try to find the window that will replace it. - auto pWindowCandidate = g_pCompositor->vectorToWindowIdeal(pWindow->middle()); + auto pWindowCandidate = g_pCompositor->vectorToWindowUnified(pWindow->middle(), RESERVED_EXTENTS | INPUT_EXTENTS | ALLOW_FLOATING); if (!pWindowCandidate) pWindowCandidate = g_pCompositor->getTopLeftWindowOnWorkspace(pWindow->m_iWorkspaceID); diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index eae86d39..7f6c06ae 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -1067,7 +1067,7 @@ void CKeybindManager::moveActiveToWorkspaceSilent(std::string args) { } if (PWINDOW == g_pCompositor->m_pLastWindow) { - if (const auto PATCOORDS = g_pCompositor->vectorToWindowIdeal(OLDMIDDLE, PWINDOW); PATCOORDS) + if (const auto PATCOORDS = g_pCompositor->vectorToWindowUnified(OLDMIDDLE, RESERVED_EXTENTS | INPUT_EXTENTS | ALLOW_FLOATING, PWINDOW); PATCOORDS) g_pCompositor->focusWindow(PATCOORDS); else g_pInputManager->refocus(); @@ -1939,7 +1939,7 @@ void CKeybindManager::pinActive(std::string args) { const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(PWINDOW->m_iWorkspaceID); - PWORKSPACE->m_pLastFocusedWindow = g_pCompositor->vectorToWindowTiled(g_pInputManager->getMouseCoordsInternal()); + PWORKSPACE->m_pLastFocusedWindow = g_pCompositor->vectorToWindowUnified(g_pInputManager->getMouseCoordsInternal(), RESERVED_EXTENTS | INPUT_EXTENTS); } void CKeybindManager::mouse(std::string args) { @@ -1951,7 +1951,7 @@ void CKeybindManager::mouse(std::string args) { g_pKeybindManager->m_bIsMouseBindActive = true; const auto mouseCoords = g_pInputManager->getMouseCoordsInternal(); - CWindow* pWindow = g_pCompositor->vectorToWindowIdeal(mouseCoords); + CWindow* pWindow = g_pCompositor->vectorToWindowUnified(mouseCoords, RESERVED_EXTENTS | INPUT_EXTENTS | ALLOW_FLOATING); if (pWindow && !pWindow->m_bIsFullscreen) pWindow->checkInputOnDecos(INPUT_TYPE_DRAG_START, mouseCoords); @@ -1974,7 +1974,8 @@ void CKeybindManager::mouse(std::string args) { if (PRESSED) { g_pKeybindManager->m_bIsMouseBindActive = true; - g_pInputManager->currentlyDraggedWindow = g_pCompositor->vectorToWindowIdeal(g_pInputManager->getMouseCoordsInternal()); + g_pInputManager->currentlyDraggedWindow = + g_pCompositor->vectorToWindowUnified(g_pInputManager->getMouseCoordsInternal(), RESERVED_EXTENTS | INPUT_EXTENTS | ALLOW_FLOATING); try { switch (std::stoi(ARGS[1])) { diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index 2c46cf85..d0bc402c 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -261,7 +261,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { return; } - const auto PWINDOWIDEAL = g_pCompositor->vectorToWindowIdeal(mouseCoords); + const auto PWINDOWIDEAL = g_pCompositor->vectorToWindowUnified(mouseCoords, RESERVED_EXTENTS | INPUT_EXTENTS | ALLOW_FLOATING); if (PWINDOWIDEAL && ((PWINDOWIDEAL->m_bIsFloating && PWINDOWIDEAL->m_bCreatedOverFullscreen) /* floating over fullscreen */ @@ -282,19 +282,19 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { if (PWORKSPACE->m_bHasFullscreenWindow && PWORKSPACE->m_efFullscreenMode == FULLSCREEN_MAXIMIZED) { if (PMONITOR->specialWorkspaceID) { - pFoundWindow = g_pCompositor->vectorToWindowIdeal(mouseCoords); + pFoundWindow = g_pCompositor->vectorToWindowUnified(mouseCoords, RESERVED_EXTENTS | INPUT_EXTENTS | ALLOW_FLOATING); if (pFoundWindow && !g_pCompositor->isWorkspaceSpecial(pFoundWindow->m_iWorkspaceID)) { pFoundWindow = g_pCompositor->getFullscreenWindowOnWorkspace(PWORKSPACE->m_iID); } } else { - pFoundWindow = g_pCompositor->vectorToWindowIdeal(mouseCoords); + pFoundWindow = g_pCompositor->vectorToWindowUnified(mouseCoords, RESERVED_EXTENTS | INPUT_EXTENTS | ALLOW_FLOATING); if (!(pFoundWindow && pFoundWindow->m_bIsFloating && pFoundWindow->m_bCreatedOverFullscreen)) pFoundWindow = g_pCompositor->getFullscreenWindowOnWorkspace(PWORKSPACE->m_iID); } } else { - pFoundWindow = g_pCompositor->vectorToWindowIdeal(mouseCoords); + pFoundWindow = g_pCompositor->vectorToWindowUnified(mouseCoords, RESERVED_EXTENTS | INPUT_EXTENTS | ALLOW_FLOATING); } if (pFoundWindow) { @@ -599,10 +599,14 @@ void CInputManager::processMouseDownNormal(wlr_pointer_button_event* e) { return; const auto mouseCoords = g_pInputManager->getMouseCoordsInternal(); - const auto w = g_pCompositor->vectorToWindowIdeal(mouseCoords); + const auto w = g_pCompositor->vectorToWindowUnified(mouseCoords, ALLOW_FLOATING | RESERVED_EXTENTS | INPUT_EXTENTS); - if (w && !m_bLastFocusOnLS && w->checkInputOnDecos(INPUT_TYPE_BUTTON, mouseCoords, e)) - return; + if (w && !m_bLastFocusOnLS) { + if (g_pCompositor->m_pLastWindow != w && *PFOLLOWMOUSE != 3) + g_pCompositor->focusWindow(w); + if (w->checkInputOnDecos(INPUT_TYPE_BUTTON, mouseCoords, e)) + return; + } // clicking on border triggers resize // TODO detect click on LS properly @@ -653,7 +657,7 @@ void CInputManager::processMouseDownNormal(wlr_pointer_button_event* e) { void CInputManager::processMouseDownKill(wlr_pointer_button_event* e) { switch (e->state) { case WLR_BUTTON_PRESSED: { - const auto PWINDOW = g_pCompositor->vectorToWindowIdeal(getMouseCoordsInternal()); + const auto PWINDOW = g_pCompositor->vectorToWindowUnified(getMouseCoordsInternal(), RESERVED_EXTENTS | INPUT_EXTENTS | ALLOW_FLOATING); if (!PWINDOW) { Debug::log(ERR, "Cannot kill invalid window!"); @@ -689,7 +693,7 @@ void CInputManager::onMouseWheel(wlr_pointer_axis_event* e) { if (!m_bLastFocusOnLS) { const auto MOUSECOORDS = g_pInputManager->getMouseCoordsInternal(); - const auto PWINDOW = g_pCompositor->vectorToWindowIdeal(MOUSECOORDS); + const auto PWINDOW = g_pCompositor->vectorToWindowUnified(MOUSECOORDS, RESERVED_EXTENTS | INPUT_EXTENTS | ALLOW_FLOATING); if (PWINDOW && PWINDOW->checkInputOnDecos(INPUT_TYPE_AXIS, MOUSECOORDS, e)) return;