From 34b0ce66b3727d5061a3cec2ac96124470b748da Mon Sep 17 00:00:00 2001 From: dranull <150595692+dranull@users.noreply.github.com> Date: Tue, 26 Dec 2023 16:24:31 +0000 Subject: [PATCH] dwindle: Use window->middle() when cursor is on reserved area (#4253) --- src/Compositor.cpp | 20 +++++++++----------- src/Compositor.hpp | 2 +- src/layout/DwindleLayout.cpp | 15 ++++++++------- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/Compositor.cpp b/src/Compositor.cpp index a2b11727..38304f33 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -1723,6 +1723,15 @@ bool CCompositor::isPointOnAnyMonitor(const Vector2D& point) { return false; } +bool CCompositor::isPointOnReservedArea(const Vector2D& point, const CMonitor* pMonitor) { + const auto PMONITOR = pMonitor ? pMonitor : getMonitorFromVector(point); + + const auto XY1 = PMONITOR->vecPosition + PMONITOR->vecReservedTopLeft; + const auto XY2 = PMONITOR->vecPosition + PMONITOR->vecSize - PMONITOR->vecReservedBottomRight; + + return !VECINRECT(point, XY1.x, XY1.y, XY2.x, XY2.y); +} + void checkFocusSurfaceIter(wlr_surface* pSurface, int x, int y, void* data) { auto pair = (std::pair*)data; pair->second = pair->second || pSurface == pair->first; @@ -2528,17 +2537,6 @@ void CCompositor::forceReportSizesToWindowsOnWorkspace(const int& wid) { } } -bool CCompositor::cursorOnReservedArea() { - const auto PMONITOR = getMonitorFromCursor(); - - const auto XY1 = PMONITOR->vecPosition + PMONITOR->vecReservedTopLeft; - const auto XY2 = PMONITOR->vecPosition + PMONITOR->vecSize - PMONITOR->vecReservedBottomRight; - - const auto CURSORPOS = g_pInputManager->getMouseCoordsInternal(); - - return !VECINRECT(CURSORPOS, XY1.x, XY1.y, XY2.x, XY2.y); -} - CWorkspace* CCompositor::createNewWorkspace(const int& id, const int& monid, const std::string& name) { const auto NAME = name == "" ? std::to_string(id) : name; auto monID = monid; diff --git a/src/Compositor.hpp b/src/Compositor.hpp index ae2d4638..f954526c 100644 --- a/src/Compositor.hpp +++ b/src/Compositor.hpp @@ -169,6 +169,7 @@ class CCompositor { CWindow* getPrevWindowOnWorkspace(CWindow*, bool focusableOnly = false, std::optional floating = {}); int getNextAvailableNamedWorkspace(); bool isPointOnAnyMonitor(const Vector2D&); + bool isPointOnReservedArea(const Vector2D& point, const CMonitor* monitor = nullptr); CWindow* getConstraintWindow(SMouse*); CMonitor* getMonitorInDirection(const char&); void updateAllWindowsAnimatedDecorationValues(); @@ -192,7 +193,6 @@ class CCompositor { void closeWindow(CWindow*); Vector2D parseWindowVectorArgsRelative(const std::string&, const Vector2D&); void forceReportSizesToWindowsOnWorkspace(const int&); - bool cursorOnReservedArea(); CWorkspace* createNewWorkspace(const int&, const int&, const std::string& name = ""); // will be deleted next frame if left empty and unfocused! void renameWorkspace(const int&, const std::string& name = ""); void setActiveMonitor(CMonitor*); diff --git a/src/layout/DwindleLayout.cpp b/src/layout/DwindleLayout.cpp index b30d0fb6..63c2fec2 100644 --- a/src/layout/DwindleLayout.cpp +++ b/src/layout/DwindleLayout.cpp @@ -254,10 +254,11 @@ void CHyprDwindleLayout::onWindowCreatedTiling(CWindow* pWindow, eDirection dire const auto MOUSECOORDS = m_vOverrideFocalPoint.value_or(g_pInputManager->getMouseCoordsInternal()); const auto MONFROMCURSOR = g_pCompositor->getMonitorFromVector(MOUSECOORDS); + const auto TARGETCOORDS = PMONITOR->ID == MONFROMCURSOR->ID && g_pCompositor->isPointOnReservedArea(MOUSECOORDS, PMONITOR) ? pWindow->middle() : MOUSECOORDS; 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->vectorToWindowTiled(TARGETCOORDS)); // happens on reserved area if (!OPENINGON && g_pCompositor->getWindowsOnWorkspace(PNODE->workspaceID) > 0) @@ -268,7 +269,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->vectorToWindowTiled(TARGETCOORDS)); } if (!OPENINGON && g_pCompositor->getWindowsOnWorkspace(PNODE->workspaceID) > 0) @@ -399,15 +400,15 @@ void CHyprDwindleLayout::onWindowCreatedTiling(CWindow* pWindow, eDirection dire const auto br = NEWPARENT->box.pos() + NEWPARENT->box.size(); const auto cc = NEWPARENT->box.pos() + NEWPARENT->box.size() / 2; - if (MOUSECOORDS.inTriangle(tl, tr, cc)) { + if (TARGETCOORDS.inTriangle(tl, tr, cc)) { NEWPARENT->splitTop = true; NEWPARENT->children[0] = PNODE; NEWPARENT->children[1] = OPENINGON; - } else if (MOUSECOORDS.inTriangle(tr, cc, br)) { + } else if (TARGETCOORDS.inTriangle(tr, cc, br)) { NEWPARENT->splitTop = false; NEWPARENT->children[0] = OPENINGON; NEWPARENT->children[1] = PNODE; - } else if (MOUSECOORDS.inTriangle(br, bl, cc)) { + } else if (TARGETCOORDS.inTriangle(br, bl, cc)) { NEWPARENT->splitTop = true; NEWPARENT->children[0] = OPENINGON; NEWPARENT->children[1] = PNODE; @@ -418,9 +419,9 @@ void CHyprDwindleLayout::onWindowCreatedTiling(CWindow* pWindow, eDirection dire } } else if (*PFORCESPLIT == 0 || !pWindow->m_bFirstMap) { if ((SIDEBYSIDE && - VECINRECT(MOUSECOORDS, NEWPARENT->box.x, NEWPARENT->box.y / *PWIDTHMULTIPLIER, NEWPARENT->box.x + NEWPARENT->box.w / 2.f, NEWPARENT->box.y + NEWPARENT->box.h)) || + VECINRECT(TARGETCOORDS, NEWPARENT->box.x, NEWPARENT->box.y / *PWIDTHMULTIPLIER, NEWPARENT->box.x + NEWPARENT->box.w / 2.f, NEWPARENT->box.y + NEWPARENT->box.h)) || (!SIDEBYSIDE && - VECINRECT(MOUSECOORDS, NEWPARENT->box.x, NEWPARENT->box.y / *PWIDTHMULTIPLIER, NEWPARENT->box.x + NEWPARENT->box.w, NEWPARENT->box.y + NEWPARENT->box.h / 2.f))) { + VECINRECT(TARGETCOORDS, NEWPARENT->box.x, NEWPARENT->box.y / *PWIDTHMULTIPLIER, NEWPARENT->box.x + NEWPARENT->box.w, NEWPARENT->box.y + NEWPARENT->box.h / 2.f))) { // we are hovering over the first node, make PNODE first. NEWPARENT->children[1] = OPENINGON; NEWPARENT->children[0] = PNODE;