Skip to content

Commit b5c0d0b

Browse files
keybinds: add an option to respect gaps out for floating to movewindow (#9360)
1 parent b1d0a72 commit b5c0d0b

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

src/config/ConfigDescriptions.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ inline static const std::vector<SConfigOptionDescription> CONFIG_OPTIONS = {
3232
.type = CONFIG_OPTION_STRING_SHORT,
3333
.data = SConfigOptionDescription::SStringData{"20"},
3434
},
35+
SConfigOptionDescription{
36+
.value = "general:float_gaps",
37+
.description = "gaps between windows and monitor edges for floating windows\n\nsupports css style gaps (top, right, bottom, left -> 5 10 15 20). \n-1 means default "
38+
"gaps_in/gaps_out\n0 means no gaps",
39+
.type = CONFIG_OPTION_STRING_SHORT,
40+
.data = SConfigOptionDescription::SStringData{"0"},
41+
},
3542
SConfigOptionDescription{
3643
.value = "general:gaps_workspaces",
3744
.description = "gaps between workspaces. Stacks with gaps_out.",

src/config/ConfigManager.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ CConfigManager::CConfigManager() {
444444
registerConfigVar("general:no_border_on_floating", Hyprlang::INT{0});
445445
registerConfigVar("general:gaps_in", Hyprlang::CConfigCustomValueType{configHandleGapSet, configHandleGapDestroy, "5"});
446446
registerConfigVar("general:gaps_out", Hyprlang::CConfigCustomValueType{configHandleGapSet, configHandleGapDestroy, "20"});
447+
registerConfigVar("general:float_gaps", Hyprlang::CConfigCustomValueType{configHandleGapSet, configHandleGapDestroy, "0"});
447448
registerConfigVar("general:gaps_workspaces", Hyprlang::INT{0});
448449
registerConfigVar("general:no_focus_fallback", Hyprlang::INT{0});
449450
registerConfigVar("general:resize_on_border", Hyprlang::INT{0});
@@ -1318,6 +1319,8 @@ SWorkspaceRule CConfigManager::mergeWorkspaceRules(const SWorkspaceRule& rule1,
13181319
mergedRule.gapsIn = rule2.gapsIn;
13191320
if (rule2.gapsOut.has_value())
13201321
mergedRule.gapsOut = rule2.gapsOut;
1322+
if (rule2.floatGaps)
1323+
mergedRule.floatGaps = rule2.floatGaps;
13211324
if (rule2.borderSize.has_value())
13221325
mergedRule.borderSize = rule2.borderSize;
13231326
if (rule2.noBorder.has_value())

src/config/ConfigManager.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ struct SWorkspaceRule {
3636
bool isPersistent = false;
3737
std::optional<CCssGapData> gapsIn;
3838
std::optional<CCssGapData> gapsOut;
39+
std::optional<CCssGapData> floatGaps = gapsOut;
3940
std::optional<int64_t> borderSize;
4041
std::optional<bool> decorate;
4142
std::optional<bool> noRounding;

src/managers/KeybindManager.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1682,16 +1682,25 @@ SDispatchResult CKeybindManager::moveActiveTo(std::string args) {
16821682

16831683
if (PLASTWINDOW->m_isFloating) {
16841684
std::optional<float> vPosx, vPosy;
1685-
const auto PMONITOR = PLASTWINDOW->m_monitor.lock();
1686-
const auto BORDERSIZE = PLASTWINDOW->getRealBorderSize();
1685+
const auto PMONITOR = PLASTWINDOW->m_monitor.lock();
1686+
const auto BORDERSIZE = PLASTWINDOW->getRealBorderSize();
1687+
static auto PGAPSCUSTOMDATA = CConfigValue<Hyprlang::CUSTOMTYPE>("general:float_gaps");
1688+
static auto PGAPSOUTDATA = CConfigValue<Hyprlang::CUSTOMTYPE>("general:gaps_out");
1689+
auto* PGAPSOUT = (CCssGapData*)PGAPSCUSTOMDATA.ptr()->getData();
1690+
if (PGAPSOUT->m_left < 0 || PGAPSOUT->m_right < 0 || PGAPSOUT->m_top < 0 || PGAPSOUT->m_bottom < 0)
1691+
PGAPSOUT = (CCssGapData*)PGAPSOUTDATA.ptr()->getData();
16871692

16881693
switch (arg) {
1689-
case 'l': vPosx = PMONITOR->m_reservedTopLeft.x + BORDERSIZE + PMONITOR->m_position.x; break;
1690-
case 'r': vPosx = PMONITOR->m_size.x - PMONITOR->m_reservedBottomRight.x - PLASTWINDOW->m_realSize->goal().x - BORDERSIZE + PMONITOR->m_position.x; break;
1694+
case 'l': vPosx = PMONITOR->m_reservedTopLeft.x + BORDERSIZE + PMONITOR->m_position.x + PGAPSOUT->m_left; break;
1695+
case 'r':
1696+
vPosx = PMONITOR->m_size.x - PMONITOR->m_reservedBottomRight.x - PLASTWINDOW->m_realSize->goal().x - BORDERSIZE + PMONITOR->m_position.x - PGAPSOUT->m_right;
1697+
break;
16911698
case 't':
1692-
case 'u': vPosy = PMONITOR->m_reservedTopLeft.y + BORDERSIZE + PMONITOR->m_position.y; break;
1699+
case 'u': vPosy = PMONITOR->m_reservedTopLeft.y + BORDERSIZE + PMONITOR->m_position.y + PGAPSOUT->m_top; break;
16931700
case 'b':
1694-
case 'd': vPosy = PMONITOR->m_size.y - PMONITOR->m_reservedBottomRight.y - PLASTWINDOW->m_realSize->goal().y - BORDERSIZE + PMONITOR->m_position.y; break;
1701+
case 'd':
1702+
vPosy = PMONITOR->m_size.y - PMONITOR->m_reservedBottomRight.y - PLASTWINDOW->m_realSize->goal().y - BORDERSIZE + PMONITOR->m_position.y - PGAPSOUT->m_bottom;
1703+
break;
16951704
}
16961705

16971706
*PLASTWINDOW->m_realPosition = Vector2D(vPosx.value_or(PLASTWINDOW->m_realPosition->goal().x), vPosy.value_or(PLASTWINDOW->m_realPosition->goal().y));

0 commit comments

Comments
 (0)