aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authoralaricljs <[email protected]>2023-09-12 04:56:20 -0400
committerGitHub <[email protected]>2023-09-12 09:56:20 +0100
commit9192b20b96b56bbc4f8f6cf90e38375052fb4ff0 (patch)
tree97cfe3d12eaa06c3dcca63778f516c4d116d556c
parentb6191cbc76a9d8b598ab6af6bdd224ca35460d7f (diff)
downloadHyprland-9192b20b96b56bbc4f8f6cf90e38375052fb4ff0.tar.gz
Hyprland-9192b20b96b56bbc4f8f6cf90e38375052fb4ff0.zip
windowrules: add on-screen constraint to wrv2 'move' (#3247)
* add on-screen constraint to wrv2 'move' * review changes * std::clamp * more parens --------- Co-authored-by: Leeman <[email protected]>
-rw-r--r--src/events/Windows.cpp21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/events/Windows.cpp b/src/events/Windows.cpp
index 2d428a8a..c90b19fd 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,16 @@ 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));
+
+ 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);
PWINDOW->m_vRealPosition = Vector2D(posX, posY) + PMONITOR->vecPosition;