Skip to content

Commit 998500b

Browse files
snap: option to respect gaps
1 parent 81cd526 commit 998500b

File tree

3 files changed

+35
-18
lines changed

3 files changed

+35
-18
lines changed

src/config/ConfigDescriptions.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@ inline static const std::vector<SConfigOptionDescription> CONFIG_OPTIONS = {
128128
.type = CONFIG_OPTION_BOOL,
129129
.data = SConfigOptionDescription::SBoolData{false},
130130
},
131+
SConfigOptionDescription{
132+
.value = "general:snap:respect_gaps",
133+
.description = "if true, snapping will respect gaps between windows",
134+
.type = CONFIG_OPTION_BOOL,
135+
.data = SConfigOptionDescription::SBoolData{false},
136+
},
131137

132138
/*
133139
* decoration:

src/config/ConfigManager.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,7 @@ CConfigManager::CConfigManager() {
456456
registerConfigVar("general:snap:window_gap", Hyprlang::INT{10});
457457
registerConfigVar("general:snap:monitor_gap", Hyprlang::INT{10});
458458
registerConfigVar("general:snap:border_overlap", Hyprlang::INT{0});
459+
registerConfigVar("general:snap:respect_gaps", Hyprlang::INT{0});
459460
registerConfigVar("general:col.active_border", Hyprlang::CConfigCustomValueType{&configHandleGradientSet, configHandleGradientDestroy, "0xffffffff"});
460461
registerConfigVar("general:col.inactive_border", Hyprlang::CConfigCustomValueType{&configHandleGradientSet, configHandleGradientDestroy, "0xff444444"});
461462
registerConfigVar("general:col.nogroup_border", Hyprlang::CConfigCustomValueType{&configHandleGradientSet, configHandleGradientDestroy, "0xffffaaff"});

src/layout/IHyprLayout.cpp

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ static void performSnap(Vector2D& sourcePos, Vector2D& sourceSize, PHLWINDOW DRA
393393
static auto SNAPWINDOWGAP = CConfigValue<Hyprlang::INT>("general:snap:window_gap");
394394
static auto SNAPMONITORGAP = CConfigValue<Hyprlang::INT>("general:snap:monitor_gap");
395395
static auto SNAPBORDEROVERLAP = CConfigValue<Hyprlang::INT>("general:snap:border_overlap");
396+
static auto SNAPRESPECTGAPS = CConfigValue<Hyprlang::INT>("general:snap:respect_gaps");
396397

397398
const SnapFn SNAP = (MODE == MBIND_MOVE) ? snapMove : snapResize;
398399
int snaps = 0;
@@ -420,9 +421,15 @@ static void performSnap(Vector2D& sourcePos, Vector2D& sourceSize, PHLWINDOW DRA
420421
const int OTHERBORDERSIZE = other->getRealBorderSize();
421422
const double BORDERSIZE = OVERLAP ? std::max(DRAGGINGBORDERSIZE, OTHERBORDERSIZE) : (DRAGGINGBORDERSIZE + OTHERBORDERSIZE);
422423

423-
const CBox SURF = other->getWindowMainSurfaceBox();
424-
const SRange SURFBX = {SURF.x - BORDERSIZE, SURF.x + SURF.w + BORDERSIZE};
425-
const SRange SURFBY = {SURF.y - BORDERSIZE, SURF.y + SURF.h + BORDERSIZE};
424+
const CBox SURF = other->getWindowMainSurfaceBox();
425+
double GAP_OFFSET = 0;
426+
if (*SNAPRESPECTGAPS) {
427+
static auto PGAPSINDATA = CConfigValue<Hyprlang::CUSTOMTYPE>("general:gaps_in");
428+
auto* PGAPSINPTR = (CCssGapData*)(PGAPSINDATA.ptr())->getData();
429+
GAP_OFFSET = std::max({PGAPSINPTR->m_left, PGAPSINPTR->m_right, PGAPSINPTR->m_top, PGAPSINPTR->m_bottom});
430+
}
431+
const SRange SURFBX = {SURF.x - BORDERSIZE - GAP_OFFSET, SURF.x + SURF.w + BORDERSIZE + GAP_OFFSET};
432+
const SRange SURFBY = {SURF.y - BORDERSIZE - GAP_OFFSET, SURF.y + SURF.h + BORDERSIZE + GAP_OFFSET};
426433

427434
// only snap windows if their ranges overlap in the opposite axis
428435
if (sourceY.start <= SURFBY.end && SURFBY.start <= sourceY.end) {
@@ -473,32 +480,35 @@ static void performSnap(Vector2D& sourcePos, Vector2D& sourceSize, PHLWINDOW DRA
473480
const double GAPSIZE = *SNAPMONITORGAP;
474481
const double BORDERDIFF = OVERLAP ? DRAGGINGBORDERSIZE : 0;
475482
const auto MON = DRAGGINGWINDOW->m_monitor.lock();
476-
477-
SRange monX = {MON->m_position.x + MON->m_reservedTopLeft.x + DRAGGINGBORDERSIZE, MON->m_position.x + MON->m_size.x - MON->m_reservedBottomRight.x - DRAGGINGBORDERSIZE};
478-
SRange monY = {MON->m_position.y + MON->m_reservedTopLeft.y + DRAGGINGBORDERSIZE, MON->m_position.y + MON->m_size.y - MON->m_reservedBottomRight.y - DRAGGINGBORDERSIZE};
483+
double GAP_OFFSET = 0;
484+
if (*SNAPRESPECTGAPS) {
485+
static auto PGAPSOUTDATA = CConfigValue<Hyprlang::CUSTOMTYPE>("general:gaps_out");
486+
auto* PGAPSOUTPTR = (CCssGapData*)(PGAPSOUTDATA.ptr())->getData();
487+
GAP_OFFSET = std::max({PGAPSOUTPTR->m_left, PGAPSOUTPTR->m_right, PGAPSOUTPTR->m_top, PGAPSOUTPTR->m_bottom});
488+
}
479489

480490
if (CORNER & (CORNER_TOPLEFT | CORNER_BOTTOMLEFT) &&
481-
((MON->m_reservedTopLeft.x > 0 && canSnap(sourceX.start, monX.start, GAPSIZE)) ||
482-
canSnap(sourceX.start, (monX.start -= MON->m_reservedTopLeft.x + BORDERDIFF), GAPSIZE))) {
483-
SNAP(sourceX.start, sourceX.end, monX.start);
491+
((MON->m_reservedTopLeft.x > 0 && canSnap(sourceX.start, MON->m_position.x + MON->m_reservedTopLeft.x + DRAGGINGBORDERSIZE + GAP_OFFSET, GAPSIZE)) ||
492+
canSnap(sourceX.start, MON->m_position.x + MON->m_reservedTopLeft.x - BORDERDIFF + GAP_OFFSET, GAPSIZE))) {
493+
SNAP(sourceX.start, sourceX.end, MON->m_position.x + MON->m_reservedTopLeft.x + DRAGGINGBORDERSIZE + GAP_OFFSET);
484494
snaps |= SNAP_LEFT;
485495
}
486496
if (CORNER & (CORNER_TOPRIGHT | CORNER_BOTTOMRIGHT) &&
487-
((MON->m_reservedBottomRight.x > 0 && canSnap(sourceX.end, monX.end, GAPSIZE)) ||
488-
canSnap(sourceX.end, (monX.end += MON->m_reservedBottomRight.x + BORDERDIFF), GAPSIZE))) {
489-
SNAP(sourceX.end, sourceX.start, monX.end);
497+
((MON->m_reservedBottomRight.x > 0 && canSnap(sourceX.end, MON->m_position.x + MON->m_size.x - MON->m_reservedBottomRight.x - DRAGGINGBORDERSIZE - GAP_OFFSET, GAPSIZE)) ||
498+
canSnap(sourceX.end, MON->m_position.x + MON->m_size.x - MON->m_reservedBottomRight.x + BORDERDIFF - GAP_OFFSET, GAPSIZE))) {
499+
SNAP(sourceX.end, sourceX.start, MON->m_position.x + MON->m_size.x - MON->m_reservedBottomRight.x - DRAGGINGBORDERSIZE - GAP_OFFSET);
490500
snaps |= SNAP_RIGHT;
491501
}
492502
if (CORNER & (CORNER_TOPLEFT | CORNER_TOPRIGHT) &&
493-
((MON->m_reservedTopLeft.y > 0 && canSnap(sourceY.start, monY.start, GAPSIZE)) ||
494-
canSnap(sourceY.start, (monY.start -= MON->m_reservedTopLeft.y + BORDERDIFF), GAPSIZE))) {
495-
SNAP(sourceY.start, sourceY.end, monY.start);
503+
((MON->m_reservedTopLeft.y > 0 && canSnap(sourceY.start, MON->m_position.y + MON->m_reservedTopLeft.y + DRAGGINGBORDERSIZE + GAP_OFFSET, GAPSIZE)) ||
504+
canSnap(sourceY.start, MON->m_position.y + MON->m_reservedTopLeft.y - BORDERDIFF + GAP_OFFSET, GAPSIZE))) {
505+
SNAP(sourceY.start, sourceY.end, MON->m_position.y + MON->m_reservedTopLeft.y + DRAGGINGBORDERSIZE + GAP_OFFSET);
496506
snaps |= SNAP_UP;
497507
}
498508
if (CORNER & (CORNER_BOTTOMLEFT | CORNER_BOTTOMRIGHT) &&
499-
((MON->m_reservedBottomRight.y > 0 && canSnap(sourceY.end, monY.end, GAPSIZE)) ||
500-
canSnap(sourceY.end, (monY.end += MON->m_reservedBottomRight.y + BORDERDIFF), GAPSIZE))) {
501-
SNAP(sourceY.end, sourceY.start, monY.end);
509+
((MON->m_reservedBottomRight.y > 0 && canSnap(sourceY.end, MON->m_position.y + MON->m_size.y - MON->m_reservedBottomRight.y - DRAGGINGBORDERSIZE - GAP_OFFSET, GAPSIZE)) ||
510+
canSnap(sourceY.end, MON->m_position.y + MON->m_size.y - MON->m_reservedBottomRight.y + BORDERDIFF - GAP_OFFSET, GAPSIZE))) {
511+
SNAP(sourceY.end, sourceY.start, MON->m_position.y + MON->m_size.y - MON->m_reservedBottomRight.y - DRAGGINGBORDERSIZE - GAP_OFFSET);
502512
snaps |= SNAP_DOWN;
503513
}
504514
}

0 commit comments

Comments
 (0)