From 91ac5bda93c235c182c56388c9a103f3830e4fff Mon Sep 17 00:00:00 2001 From: Leeman Date: Sun, 10 Sep 2023 13:22:23 -0400 Subject: [PATCH 1/4] add on-screen constraint to wrv2 'move' --- src/events/Windows.cpp | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/src/events/Windows.cpp b/src/events/Windows.cpp index 9089567a5e2..c5508872f5f 100644 --- a/src/events/Windows.cpp +++ b/src/events/Windows.cpp @@ -322,6 +322,11 @@ void Events::listener_mapWindow(void* owner, void* data) { try { auto value = r.szRule.substr(r.szRule.find(' ') + 1); + const bool ONSCREEN = value.find("onscreen") == 0; + + if (ONSCREEN) + value = value.substr(value.find_first_of(' ') + 1); + const bool CURSOR = value.find("cursor") == 0; if (CURSOR) @@ -334,8 +339,7 @@ void Events::listener_mapWindow(void* owner, void* data) { int posY = 0; if (POSXSTR.find("100%-") == 0) { - const auto PMONITOR = g_pCompositor->getMonitorFromID(PWINDOW->m_iMonitorID); - const auto POSXRAW = POSXSTR.substr(5); + const auto POSXRAW = POSXSTR.substr(5); posX = PMONITOR->vecSize.x - (!POSXRAW.contains('%') ? std::stoi(POSXRAW) : std::stof(POSXRAW.substr(0, POSXRAW.length() - 1)) * 0.01 * PMONITOR->vecSize.x); @@ -354,8 +358,7 @@ void Events::listener_mapWindow(void* owner, void* data) { } if (POSYSTR.find("100%-") == 0) { - const auto PMONITOR = g_pCompositor->getMonitorFromID(PWINDOW->m_iMonitorID); - const auto POSYRAW = POSYSTR.substr(5); + const auto POSYRAW = POSYSTR.substr(5); posY = PMONITOR->vecSize.y - (!POSYRAW.contains('%') ? std::stoi(POSYRAW) : std::stof(POSYRAW.substr(0, POSYRAW.length() - 1)) * 0.01 * PMONITOR->vecSize.y); @@ -373,6 +376,27 @@ void Events::listener_mapWindow(void* owner, void* data) { } } + if (ONSCREEN) { + static auto* const PBORDERSIZE = &g_pConfigManager->getConfigValuePtr("general:border_size")->intValue; + int borderSize = PWINDOW->m_sSpecialRenderData.borderSize.toUnderlying() == -1 ? *PBORDERSIZE : PWINDOW->m_sSpecialRenderData.borderSize.toUnderlying(); + if (PWINDOW->m_sAdditionalConfigData.borderSize.toUnderlying() != -1) + borderSize = PWINDOW->m_sAdditionalConfigData.borderSize.toUnderlying(); + + // left + if (posX < PMONITOR->vecReservedTopLeft.x + borderSize) + posX = PMONITOR->vecReservedTopLeft.x + borderSize; + // right + if (posX > PMONITOR->vecSize.x - PMONITOR->vecReservedBottomRight.x - PWINDOW->m_vRealSize.goalv().x - borderSize) + posX = PMONITOR->vecSize.x - PMONITOR->vecReservedBottomRight.x - PWINDOW->m_vRealSize.goalv().x - borderSize; + + // top + if (posY < PMONITOR->vecReservedTopLeft.y + borderSize) + posY = PMONITOR->vecReservedTopLeft.y + borderSize; + // bottom + if (posY > PMONITOR->vecSize.y - PMONITOR->vecReservedBottomRight.y - PWINDOW->m_vRealSize.goalv().y - borderSize) + posY = PMONITOR->vecSize.y - PMONITOR->vecReservedBottomRight.y - PWINDOW->m_vRealSize.goalv().y - borderSize; + } + Debug::log(LOG, "Rule move, applying to window {:x}", (uintptr_t)PWINDOW); PWINDOW->m_vRealPosition = Vector2D(posX, posY) + PMONITOR->vecPosition; From 9a2c42924d7c472b9e388e90a8a90793962e57eb Mon Sep 17 00:00:00 2001 From: Leeman Date: Sun, 10 Sep 2023 19:48:05 -0400 Subject: [PATCH 2/4] review changes --- src/events/Windows.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/events/Windows.cpp b/src/events/Windows.cpp index c5508872f5f..0c4d798c31e 100644 --- a/src/events/Windows.cpp +++ b/src/events/Windows.cpp @@ -377,10 +377,7 @@ void Events::listener_mapWindow(void* owner, void* data) { } if (ONSCREEN) { - static auto* const PBORDERSIZE = &g_pConfigManager->getConfigValuePtr("general:border_size")->intValue; - int borderSize = PWINDOW->m_sSpecialRenderData.borderSize.toUnderlying() == -1 ? *PBORDERSIZE : PWINDOW->m_sSpecialRenderData.borderSize.toUnderlying(); - if (PWINDOW->m_sAdditionalConfigData.borderSize.toUnderlying() != -1) - borderSize = PWINDOW->m_sAdditionalConfigData.borderSize.toUnderlying(); + int borderSize = PWINDOW->getRealBorderSize(); // left if (posX < PMONITOR->vecReservedTopLeft.x + borderSize) From 61857a6d871592968d0e9ef01681255be14903bb Mon Sep 17 00:00:00 2001 From: Leeman Date: Mon, 11 Sep 2023 18:43:47 -0400 Subject: [PATCH 3/4] std::clamp --- src/events/Windows.cpp | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/src/events/Windows.cpp b/src/events/Windows.cpp index 0c4d798c31e..0359880a169 100644 --- a/src/events/Windows.cpp +++ b/src/events/Windows.cpp @@ -379,19 +379,11 @@ void Events::listener_mapWindow(void* owner, void* data) { if (ONSCREEN) { int borderSize = PWINDOW->getRealBorderSize(); - // left - if (posX < PMONITOR->vecReservedTopLeft.x + borderSize) - posX = PMONITOR->vecReservedTopLeft.x + borderSize; - // right - if (posX > PMONITOR->vecSize.x - PMONITOR->vecReservedBottomRight.x - PWINDOW->m_vRealSize.goalv().x - borderSize) - posX = PMONITOR->vecSize.x - PMONITOR->vecReservedBottomRight.x - PWINDOW->m_vRealSize.goalv().x - borderSize; - - // top - if (posY < PMONITOR->vecReservedTopLeft.y + borderSize) - posY = PMONITOR->vecReservedTopLeft.y + borderSize; - // bottom - if (posY > PMONITOR->vecSize.y - PMONITOR->vecReservedBottomRight.y - PWINDOW->m_vRealSize.goalv().y - borderSize) - posY = PMONITOR->vecSize.y - PMONITOR->vecReservedBottomRight.y - PWINDOW->m_vRealSize.goalv().y - borderSize; + posX = std::clamp(posX, int(PMONITOR->vecReservedTopLeft.x + borderSize), + int(PMONITOR->vecSize.x - PMONITOR->vecReservedBottomRight.x - PWINDOW->m_vRealSize.goalv().x - borderSize)); + + posY = std::clamp(posY, int(PMONITOR->vecReservedTopLeft.y + borderSize), + int(PMONITOR->vecSize.y - PMONITOR->vecReservedBottomRight.y - PWINDOW->m_vRealSize.goalv().y - borderSize)); } Debug::log(LOG, "Rule move, applying to window {:x}", (uintptr_t)PWINDOW); From d1c9e902d41cd34ea59b84ba9c057be857170332 Mon Sep 17 00:00:00 2001 From: Leeman Date: Mon, 11 Sep 2023 18:47:07 -0400 Subject: [PATCH 4/4] more parens --- src/events/Windows.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/events/Windows.cpp b/src/events/Windows.cpp index 0359880a169..75f33d742b0 100644 --- a/src/events/Windows.cpp +++ b/src/events/Windows.cpp @@ -379,11 +379,11 @@ void Events::listener_mapWindow(void* owner, void* data) { if (ONSCREEN) { int borderSize = PWINDOW->getRealBorderSize(); - posX = std::clamp(posX, int(PMONITOR->vecReservedTopLeft.x + borderSize), - int(PMONITOR->vecSize.x - PMONITOR->vecReservedBottomRight.x - PWINDOW->m_vRealSize.goalv().x - borderSize)); + posX = std::clamp(posX, (int)(PMONITOR->vecReservedTopLeft.x + borderSize), + (int)(PMONITOR->vecSize.x - PMONITOR->vecReservedBottomRight.x - PWINDOW->m_vRealSize.goalv().x - borderSize)); - posY = std::clamp(posY, int(PMONITOR->vecReservedTopLeft.y + borderSize), - int(PMONITOR->vecSize.y - PMONITOR->vecReservedBottomRight.y - PWINDOW->m_vRealSize.goalv().y - borderSize)); + posY = std::clamp(posY, (int)(PMONITOR->vecReservedTopLeft.y + borderSize), + (int)(PMONITOR->vecSize.y - PMONITOR->vecReservedBottomRight.y - PWINDOW->m_vRealSize.goalv().y - borderSize)); } Debug::log(LOG, "Rule move, applying to window {:x}", (uintptr_t)PWINDOW);