From 213a03c4fd14b82924923f2d50c8e1b74e7d1627 Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Mon, 10 Feb 2025 15:09:12 +0800 Subject: [PATCH] seperate gap values for float --- 9360.patch | 171 ++++++++++++++++++++++++++++++ snap-gap.patch | 64 +++++++++++ src/config/ConfigDescriptions.hpp | 12 +++ src/config/ConfigManager.cpp | 2 + src/config/ConfigManager.hpp | 2 + src/managers/KeybindManager.cpp | 2 +- subprojects/hyprland-protocols | 2 +- subprojects/tracy | 2 +- 8 files changed, 254 insertions(+), 3 deletions(-) create mode 100644 9360.patch create mode 100644 snap-gap.patch diff --git a/9360.patch b/9360.patch new file mode 100644 index 00000000000..78bedd30cc4 --- /dev/null +++ b/9360.patch @@ -0,0 +1,171 @@ +From a7244473463fa8e693ccffc63af960004a986327 Mon Sep 17 00:00:00 2001 +From: littleblack111 +Date: Fri, 7 Feb 2025 11:00:53 +0800 +Subject: [PATCH 1/4] keybinds: movewindow respect gaps out for floating + windows + +--- + src/managers/KeybindManager.cpp | 19 +++++++++++++------ + 1 file changed, 13 insertions(+), 6 deletions(-) + +diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp +index 8daa6838791..c700f8041a3 100644 +--- a/src/managers/KeybindManager.cpp ++++ b/src/managers/KeybindManager.cpp +@@ -1603,6 +1603,7 @@ SDispatchResult CKeybindManager::swapActive(std::string args) { + } + + SDispatchResult CKeybindManager::moveActiveTo(std::string args) { ++ + char arg = args[0]; + bool silent = args.ends_with(" silent"); + if (silent) +@@ -1636,16 +1637,22 @@ SDispatchResult CKeybindManager::moveActiveTo(std::string args) { + + if (PLASTWINDOW->m_bIsFloating) { + std::optional vPosx, vPosy; +- const auto PMONITOR = PLASTWINDOW->m_pMonitor.lock(); +- const auto BORDERSIZE = PLASTWINDOW->getRealBorderSize(); ++ const auto PMONITOR = PLASTWINDOW->m_pMonitor.lock(); ++ const auto BORDERSIZE = PLASTWINDOW->getRealBorderSize(); ++ static auto PGAPSOUTDATA = CConfigValue("general:gaps_out"); ++ auto* const PGAPSOUT = (CCssGapData*)(PGAPSOUTDATA.ptr())->getData(); + + switch (arg) { +- case 'l': vPosx = PMONITOR->vecReservedTopLeft.x + BORDERSIZE + PMONITOR->vecPosition.x; break; +- case 'r': vPosx = PMONITOR->vecSize.x - PMONITOR->vecReservedBottomRight.x - PLASTWINDOW->m_vRealSize->goal().x - BORDERSIZE + PMONITOR->vecPosition.x; break; ++ case 'l': vPosx = PMONITOR->vecReservedTopLeft.x + BORDERSIZE + PMONITOR->vecPosition.x + PGAPSOUT->left; break; ++ case 'r': ++ vPosx = PMONITOR->vecSize.x - PMONITOR->vecReservedBottomRight.x - PLASTWINDOW->m_vRealSize->goal().x - BORDERSIZE + PMONITOR->vecPosition.x - PGAPSOUT->right; ++ break; + case 't': +- case 'u': vPosy = PMONITOR->vecReservedTopLeft.y + BORDERSIZE + PMONITOR->vecPosition.y; break; ++ case 'u': vPosy = PMONITOR->vecReservedTopLeft.y + BORDERSIZE + PMONITOR->vecPosition.y + PGAPSOUT->top; break; + case 'b': +- case 'd': vPosy = PMONITOR->vecSize.y - PMONITOR->vecReservedBottomRight.y - PLASTWINDOW->m_vRealSize->goal().y - BORDERSIZE + PMONITOR->vecPosition.y; break; ++ case 'd': ++ vPosy = PMONITOR->vecSize.y - PMONITOR->vecReservedBottomRight.y - PLASTWINDOW->m_vRealSize->goal().y - BORDERSIZE + PMONITOR->vecPosition.y - PGAPSOUT->bottom; ++ break; + } + + *PLASTWINDOW->m_vRealPosition = Vector2D(vPosx.value_or(PLASTWINDOW->m_vRealPosition->goal().x), vPosy.value_or(PLASTWINDOW->m_vRealPosition->goal().y)); + +From 18d97a46043b7e75301b6f8da591c1682cfa2ec1 Mon Sep 17 00:00:00 2001 +From: littleblack111 +Date: Fri, 7 Feb 2025 11:05:39 +0800 +Subject: [PATCH 2/4] fixup! random space + +--- + src/managers/KeybindManager.cpp | 1 - + 1 file changed, 1 deletion(-) + +diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp +index c700f8041a3..7b143d286a0 100644 +--- a/src/managers/KeybindManager.cpp ++++ b/src/managers/KeybindManager.cpp +@@ -1603,7 +1603,6 @@ SDispatchResult CKeybindManager::swapActive(std::string args) { + } + + SDispatchResult CKeybindManager::moveActiveTo(std::string args) { +- + char arg = args[0]; + bool silent = args.ends_with(" silent"); + if (silent) + +From 210c64cffe1901024fb66f9fa787a0a4fe60e746 Mon Sep 17 00:00:00 2001 +From: littleblack111 +Date: Mon, 10 Feb 2025 15:09:12 +0800 +Subject: [PATCH 3/4] seperate gap values for float + +--- + src/config/ConfigDescriptions.hpp | 12 ++++++++++++ + src/config/ConfigManager.cpp | 2 ++ + src/config/ConfigManager.hpp | 2 ++ + src/managers/KeybindManager.cpp | 2 +- + 4 files changed, 17 insertions(+), 1 deletion(-) + +diff --git a/src/config/ConfigDescriptions.hpp b/src/config/ConfigDescriptions.hpp +index 8d1b73c4e0e..9dd47c0177e 100644 +--- a/src/config/ConfigDescriptions.hpp ++++ b/src/config/ConfigDescriptions.hpp +@@ -32,6 +32,18 @@ inline static const std::vector CONFIG_OPTIONS = { + .type = CONFIG_OPTION_STRING_SHORT, + .data = SConfigOptionDescription::SStringData{"20"}, + }, ++ SConfigOptionDescription{ ++ .value = "general:float_gaps_in", ++ .description = "gaps between windows for floating windows\n\nsupports css style gaps (top, right, bottom, left -> 5 10 15 20)", ++ .type = CONFIG_OPTION_STRING_SHORT, ++ .data = SConfigOptionDescription::SStringData{"5"}, ++ }, ++ SConfigOptionDescription{ ++ .value = "general:float_gaps_out", ++ .description = "gaps between windows and monitor edges for floating windows\n\nsupports css style gaps (top, right, bottom, left -> 5 10 15 20)", ++ .type = CONFIG_OPTION_STRING_SHORT, ++ .data = SConfigOptionDescription::SStringData{"20"}, ++ }, + SConfigOptionDescription{ + .value = "general:gaps_workspaces", + .description = "gaps between workspaces. Stacks with gaps_out.", +diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp +index f87a5e6b1ab..b524a1c7f3b 100644 +--- a/src/config/ConfigManager.cpp ++++ b/src/config/ConfigManager.cpp +@@ -384,6 +384,8 @@ CConfigManager::CConfigManager() { + m_pConfig->addConfigValue("general:border_part_of_window", Hyprlang::INT{1}); + m_pConfig->addConfigValue("general:gaps_in", Hyprlang::CConfigCustomValueType{configHandleGapSet, configHandleGapDestroy, "5"}); + m_pConfig->addConfigValue("general:gaps_out", Hyprlang::CConfigCustomValueType{configHandleGapSet, configHandleGapDestroy, "20"}); ++ m_pConfig->addConfigValue("general:float_gaps_in", Hyprlang::CConfigCustomValueType{configHandleGapSet, configHandleGapDestroy, "5"}); ++ m_pConfig->addConfigValue("general:float_gaps_out", Hyprlang::CConfigCustomValueType{configHandleGapSet, configHandleGapDestroy, "20"}); + m_pConfig->addConfigValue("general:gaps_workspaces", Hyprlang::INT{0}); + m_pConfig->addConfigValue("general:no_focus_fallback", Hyprlang::INT{0}); + m_pConfig->addConfigValue("general:resize_on_border", Hyprlang::INT{0}); +diff --git a/src/config/ConfigManager.hpp b/src/config/ConfigManager.hpp +index f069688277a..98e4e37c08f 100644 +--- a/src/config/ConfigManager.hpp ++++ b/src/config/ConfigManager.hpp +@@ -36,6 +36,8 @@ struct SWorkspaceRule { + bool isPersistent = false; + std::optional gapsIn; + std::optional gapsOut; ++ std::optional float_gapsIn = gapsIn; ++ std::optional float_gapsOut = gapsOut; + std::optional borderSize; + std::optional decorate; + std::optional noRounding; +diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp +index 7b143d286a0..02cbca8b605 100644 +--- a/src/managers/KeybindManager.cpp ++++ b/src/managers/KeybindManager.cpp +@@ -1638,7 +1638,7 @@ SDispatchResult CKeybindManager::moveActiveTo(std::string args) { + std::optional vPosx, vPosy; + const auto PMONITOR = PLASTWINDOW->m_pMonitor.lock(); + const auto BORDERSIZE = PLASTWINDOW->getRealBorderSize(); +- static auto PGAPSOUTDATA = CConfigValue("general:gaps_out"); ++ static auto PGAPSOUTDATA = CConfigValue("general:float_gaps_out"); + auto* const PGAPSOUT = (CCssGapData*)(PGAPSOUTDATA.ptr())->getData(); + + switch (arg) { + +From d38db1e927c64392f4c899f622a25ee4fc72bfd6 Mon Sep 17 00:00:00 2001 +From: littleblack111 +Date: Mon, 10 Feb 2025 16:29:13 +0800 +Subject: [PATCH 4/4] fixup! seperate gap values for float + +--- + src/config/ConfigManager.hpp | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/config/ConfigManager.hpp b/src/config/ConfigManager.hpp +index 98e4e37c08f..27ba36af7a6 100644 +--- a/src/config/ConfigManager.hpp ++++ b/src/config/ConfigManager.hpp +@@ -36,7 +36,7 @@ struct SWorkspaceRule { + bool isPersistent = false; + std::optional gapsIn; + std::optional gapsOut; +- std::optional float_gapsIn = gapsIn; ++ std::optional float_gapsIn = gapsIn; + std::optional float_gapsOut = gapsOut; + std::optional borderSize; + std::optional decorate; diff --git a/snap-gap.patch b/snap-gap.patch new file mode 100644 index 00000000000..9e930aec729 --- /dev/null +++ b/snap-gap.patch @@ -0,0 +1,64 @@ +diff --git a/src/layout/IHyprLayout.cpp b/src/layout/IHyprLayout.cpp +index e84ffb21..5e66e823 100644 +--- a/src/layout/IHyprLayout.cpp ++++ b/src/layout/IHyprLayout.cpp +@@ -121,16 +121,23 @@ void IHyprLayout::onWindowCreatedFloating(PHLWINDOW pWindow) { + if (pWindow->m_vRealSize->goal().x <= 5 || pWindow->m_vRealSize->goal().y <= 5) + *pWindow->m_vRealSize = PMONITOR->vecSize / 2.f; + +- if (pWindow->m_bIsX11 && pWindow->isX11OverrideRedirect()) { ++ static auto PGAPSOUTDATA = CConfigValue("general:float_gaps_out"); ++ auto* const PGAPSOUT = (CCssGapData*)(PGAPSOUTDATA.ptr())->getData(); + ++ if (pWindow->m_bIsX11 && pWindow->isX11OverrideRedirect()) { + if (pWindow->m_pXWaylandSurface->geometry.x != 0 && pWindow->m_pXWaylandSurface->geometry.y != 0) + *pWindow->m_vRealPosition = g_pXWaylandManager->xwaylandToWaylandCoords(pWindow->m_pXWaylandSurface->geometry.pos()); +- else +- *pWindow->m_vRealPosition = Vector2D(PMONITOR->vecPosition.x + (PMONITOR->vecSize.x - pWindow->m_vRealSize->goal().x) / 2.f, +- PMONITOR->vecPosition.y + (PMONITOR->vecSize.y - pWindow->m_vRealSize->goal().y) / 2.f); ++ else { ++ const auto WORKAREA = Vector2D(PMONITOR->vecSize.x - PGAPSOUT->left - PGAPSOUT->right, ++ PMONITOR->vecSize.y - PGAPSOUT->top - PGAPSOUT->bottom); ++ *pWindow->m_vRealPosition = Vector2D(PMONITOR->vecPosition.x + PGAPSOUT->left + (WORKAREA.x - pWindow->m_vRealSize->goal().x) / 2.f, ++ PMONITOR->vecPosition.y + PGAPSOUT->top + (WORKAREA.y - pWindow->m_vRealSize->goal().y) / 2.f); ++ } + } else { +- *pWindow->m_vRealPosition = Vector2D(PMONITOR->vecPosition.x + (PMONITOR->vecSize.x - pWindow->m_vRealSize->goal().x) / 2.f, +- PMONITOR->vecPosition.y + (PMONITOR->vecSize.y - pWindow->m_vRealSize->goal().y) / 2.f); ++ const auto WORKAREA = Vector2D(PMONITOR->vecSize.x - PGAPSOUT->left - PGAPSOUT->right, ++ PMONITOR->vecSize.y - PGAPSOUT->top - PGAPSOUT->bottom); ++ *pWindow->m_vRealPosition = Vector2D(PMONITOR->vecPosition.x + PGAPSOUT->left + (WORKAREA.x - pWindow->m_vRealSize->goal().x) / 2.f, ++ PMONITOR->vecPosition.y + PGAPSOUT->top + (WORKAREA.y - pWindow->m_vRealSize->goal().y) / 2.f); + } + } else { + // we respect the size. +@@ -160,11 +167,27 @@ void IHyprLayout::onWindowCreatedFloating(PHLWINDOW pWindow) { + } else { + // if it is, we respect where it wants to put itself, but apply monitor offset if outside + // most of these are popups ++ static auto PGAPSOUTDATA = CConfigValue("general:float_gaps_out"); ++ auto* const PGAPSOUT = (CCssGapData*)(PGAPSOUTDATA.ptr())->getData(); ++ ++ // Make a function that ensures the window respects gaps ++ auto ensureWithinGaps = [&](const Vector2D& pos) -> Vector2D { ++ Vector2D result = pos; ++ const auto WORKAREA_START = Vector2D(PMONITOR->vecPosition.x + PGAPSOUT->left, ++ PMONITOR->vecPosition.y + PGAPSOUT->top); ++ const auto WORKAREA_END = Vector2D(PMONITOR->vecPosition.x + PMONITOR->vecSize.x - PGAPSOUT->right, ++ PMONITOR->vecPosition.y + PMONITOR->vecSize.y - PGAPSOUT->bottom); ++ ++ // Clamp the position to respect gaps ++ result.x = std::clamp(result.x, WORKAREA_START.x, WORKAREA_END.x - pWindow->m_vRealSize->goal().x); ++ result.y = std::clamp(result.y, WORKAREA_START.y, WORKAREA_END.y - pWindow->m_vRealSize->goal().y); ++ return result; ++ }; + + if (const auto POPENMON = g_pCompositor->getMonitorFromVector(middlePoint); POPENMON->ID != PMONITOR->ID) +- *pWindow->m_vRealPosition = Vector2D(desiredGeometry.x, desiredGeometry.y) - POPENMON->vecPosition + PMONITOR->vecPosition; ++ *pWindow->m_vRealPosition = ensureWithinGaps(Vector2D(desiredGeometry.x, desiredGeometry.y) - POPENMON->vecPosition + PMONITOR->vecPosition); + else +- *pWindow->m_vRealPosition = Vector2D(desiredGeometry.x, desiredGeometry.y); ++ *pWindow->m_vRealPosition = ensureWithinGaps(Vector2D(desiredGeometry.x, desiredGeometry.y)); + } + } + diff --git a/src/config/ConfigDescriptions.hpp b/src/config/ConfigDescriptions.hpp index 73579af09c9..ae44dfbdc1f 100644 --- a/src/config/ConfigDescriptions.hpp +++ b/src/config/ConfigDescriptions.hpp @@ -32,6 +32,18 @@ inline static const std::vector CONFIG_OPTIONS = { .type = CONFIG_OPTION_STRING_SHORT, .data = SConfigOptionDescription::SStringData{"20"}, }, + SConfigOptionDescription{ + .value = "general:float_gaps_in", + .description = "gaps between windows for floating windows\n\nsupports css style gaps (top, right, bottom, left -> 5 10 15 20)", + .type = CONFIG_OPTION_STRING_SHORT, + .data = SConfigOptionDescription::SStringData{"5"}, + }, + SConfigOptionDescription{ + .value = "general:float_gaps_out", + .description = "gaps between windows and monitor edges for floating windows\n\nsupports css style gaps (top, right, bottom, left -> 5 10 15 20)", + .type = CONFIG_OPTION_STRING_SHORT, + .data = SConfigOptionDescription::SStringData{"20"}, + }, SConfigOptionDescription{ .value = "general:gaps_workspaces", .description = "gaps between workspaces. Stacks with gaps_out.", diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 2f57a37f19b..59c8953cf1c 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -408,6 +408,8 @@ CConfigManager::CConfigManager() { registerConfigVar("general:no_border_on_floating", Hyprlang::INT{0}); registerConfigVar("general:gaps_in", Hyprlang::CConfigCustomValueType{configHandleGapSet, configHandleGapDestroy, "5"}); registerConfigVar("general:gaps_out", Hyprlang::CConfigCustomValueType{configHandleGapSet, configHandleGapDestroy, "20"}); + registerConfigVar("general:float_gaps_in", Hyprlang::CConfigCustomValueType{configHandleGapSet, configHandleGapDestroy, "5"}); + registerConfigVar("general:float_gaps_out", Hyprlang::CConfigCustomValueType{configHandleGapSet, configHandleGapDestroy, "20"}); registerConfigVar("general:gaps_workspaces", Hyprlang::INT{0}); registerConfigVar("general:no_focus_fallback", Hyprlang::INT{0}); registerConfigVar("general:resize_on_border", Hyprlang::INT{0}); diff --git a/src/config/ConfigManager.hpp b/src/config/ConfigManager.hpp index 440b6602ef2..bd9848de29b 100644 --- a/src/config/ConfigManager.hpp +++ b/src/config/ConfigManager.hpp @@ -36,6 +36,8 @@ struct SWorkspaceRule { bool isPersistent = false; std::optional gapsIn; std::optional gapsOut; + std::optional float_gapsIn = gapsIn; + std::optional float_gapsOut = gapsOut; std::optional borderSize; std::optional decorate; std::optional noRounding; diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 90a30b94e87..dd5e0902db6 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -1646,7 +1646,7 @@ SDispatchResult CKeybindManager::moveActiveTo(std::string args) { std::optional vPosx, vPosy; const auto PMONITOR = PLASTWINDOW->m_pMonitor.lock(); const auto BORDERSIZE = PLASTWINDOW->getRealBorderSize(); - static auto PGAPSOUTDATA = CConfigValue("general:gaps_out"); + static auto PGAPSOUTDATA = CConfigValue("general:float_gaps_out"); auto* const PGAPSOUT = (CCssGapData*)(PGAPSOUTDATA.ptr())->getData(); switch (arg) { diff --git a/subprojects/hyprland-protocols b/subprojects/hyprland-protocols index 755aef8dab4..5341ab4d644 160000 --- a/subprojects/hyprland-protocols +++ b/subprojects/hyprland-protocols @@ -1 +1 @@ -Subproject commit 755aef8dab49d0fc4663c715fa4ad221b2aedaed +Subproject commit 5341ab4d644daf092a97ec1935ac72315a3aa19b diff --git a/subprojects/tracy b/subprojects/tracy index 37aff70dfa5..277555af2ad 160000 --- a/subprojects/tracy +++ b/subprojects/tracy @@ -1 +1 @@ -Subproject commit 37aff70dfa50cf6307b3fee6074d627dc2929143 +Subproject commit 277555af2adf864b4c47aca53401bad7e94643b0