mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-15 08:45:59 +01:00
layout: window snapping cleanup + fixes
way better now heh fixes #8259 fixes #8267
This commit is contained in:
parent
5d4b54b012
commit
b1120ec433
1 changed files with 50 additions and 44 deletions
|
@ -415,7 +415,7 @@ static void snapResizeRight(double& pos, double& len, const double p) {
|
||||||
|
|
||||||
typedef std::function<void(double&, double&, const double)> SnapFn;
|
typedef std::function<void(double&, double&, const double)> SnapFn;
|
||||||
|
|
||||||
static void performSnap(Vector2D& pos, Vector2D& size, PHLWINDOW DRAGGINGWINDOW, const eMouseBindMode mode, const int corner, const Vector2D& beginSize) {
|
static void performSnap(Vector2D& sourcePos, Vector2D& sourceSize, PHLWINDOW DRAGGINGWINDOW, const eMouseBindMode mode, const int corner, const Vector2D& beginSize) {
|
||||||
static auto SNAPWINDOWGAP = CConfigValue<Hyprlang::INT>("general:snap:window_gap");
|
static auto SNAPWINDOWGAP = CConfigValue<Hyprlang::INT>("general:snap:window_gap");
|
||||||
static auto SNAPMONITORGAP = CConfigValue<Hyprlang::INT>("general:snap:monitor_gap");
|
static auto SNAPMONITORGAP = CConfigValue<Hyprlang::INT>("general:snap:monitor_gap");
|
||||||
|
|
||||||
|
@ -425,59 +425,59 @@ static void performSnap(Vector2D& pos, Vector2D& size, PHLWINDOW DRAGGINGWINDOW,
|
||||||
const SnapFn snapUp = snapLeft;
|
const SnapFn snapUp = snapLeft;
|
||||||
int snaps = 0;
|
int snaps = 0;
|
||||||
|
|
||||||
|
const int DRAGGINGBORDERSIZE = DRAGGINGWINDOW->getRealBorderSize();
|
||||||
|
CBox sourceBox = CBox{sourcePos, sourceSize}.expand(DRAGGINGBORDERSIZE);
|
||||||
|
|
||||||
if (*SNAPWINDOWGAP) {
|
if (*SNAPWINDOWGAP) {
|
||||||
const auto PID = DRAGGINGWINDOW->getPID();
|
const auto PID = DRAGGINGWINDOW->getPID();
|
||||||
const auto WSID = DRAGGINGWINDOW->workspaceID();
|
const auto WSID = DRAGGINGWINDOW->workspaceID();
|
||||||
const int BORD = DRAGGINGWINDOW->getRealBorderSize();
|
|
||||||
|
|
||||||
for (auto& other : g_pCompositor->m_vWindows) {
|
for (auto& other : g_pCompositor->m_vWindows) {
|
||||||
if (other->workspaceID() != WSID || other->getPID() == PID || !other->m_bIsMapped || other->m_bFadingOut || other->isX11OverrideRedirect())
|
if (other->workspaceID() != WSID || other->getPID() == PID || !other->m_bIsMapped || other->m_bFadingOut || other->isX11OverrideRedirect())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
const int bord = std::max(BORD, other->getRealBorderSize());
|
const int BORDERSIZE = other->getRealBorderSize();
|
||||||
const double gap = *SNAPWINDOWGAP + bord;
|
const double GAPSIZE = *SNAPWINDOWGAP + BORDERSIZE;
|
||||||
|
|
||||||
const CBox box = other->getWindowMainSurfaceBox();
|
const CBox SURFBB = other->getWindowMainSurfaceBox().expand(BORDERSIZE);
|
||||||
const CBox ob = {box.x, box.y, box.x + box.w, box.y + box.h};
|
const Vector2D end = sourceBox.pos() + sourceBox.size();
|
||||||
const CBox bb = {ob.x - bord, ob.y - bord, ob.w + bord, ob.h + bord};
|
|
||||||
const Vector2D end = {pos.x + size.x, pos.y + size.y};
|
|
||||||
|
|
||||||
// only snap windows if their ranges intersect in the opposite axis
|
// only snap windows if their ranges intersect in the opposite axis
|
||||||
if (pos.y <= bb.h && bb.y <= end.y) {
|
if (sourceBox.y <= SURFBB.y + SURFBB.h && SURFBB.y <= end.y) {
|
||||||
if (corner & (CORNER_TOPLEFT | CORNER_BOTTOMLEFT) && canSnap(pos.x, bb.w, gap)) {
|
if (corner & (CORNER_TOPLEFT | CORNER_BOTTOMLEFT) && canSnap(sourceBox.x, SURFBB.x + SURFBB.w, GAPSIZE)) {
|
||||||
snapLeft(pos.x, size.x, bb.w);
|
snapLeft(sourceBox.x, sourceBox.w, SURFBB.x + SURFBB.w);
|
||||||
snaps |= SNAP_LEFT;
|
snaps |= SNAP_LEFT;
|
||||||
} else if (corner & (CORNER_TOPRIGHT | CORNER_BOTTOMRIGHT) && canSnap(end.x, bb.x, gap)) {
|
} else if (corner & (CORNER_TOPRIGHT | CORNER_BOTTOMRIGHT) && canSnap(end.x, SURFBB.x, GAPSIZE)) {
|
||||||
snapRight(pos.x, size.x, bb.x);
|
snapRight(sourceBox.x, sourceBox.w, SURFBB.x);
|
||||||
snaps |= SNAP_RIGHT;
|
snaps |= SNAP_RIGHT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (pos.x <= bb.w && bb.x <= end.x) {
|
if (sourceBox.x <= SURFBB.x + SURFBB.w && SURFBB.x <= end.x) {
|
||||||
if (corner & (CORNER_TOPLEFT | CORNER_TOPRIGHT) && canSnap(pos.y, bb.h, gap)) {
|
if (corner & (CORNER_TOPLEFT | CORNER_TOPRIGHT) && canSnap(sourceBox.y, SURFBB.y + SURFBB.h, GAPSIZE)) {
|
||||||
snapUp(pos.y, size.y, bb.h);
|
snapUp(sourceBox.y, sourceBox.h, SURFBB.y + SURFBB.h);
|
||||||
snaps |= SNAP_UP;
|
snaps |= SNAP_UP;
|
||||||
} else if (corner & (CORNER_BOTTOMLEFT | CORNER_BOTTOMRIGHT) && canSnap(end.y, bb.y, gap)) {
|
} else if (corner & (CORNER_BOTTOMLEFT | CORNER_BOTTOMRIGHT) && canSnap(end.y, SURFBB.y, GAPSIZE)) {
|
||||||
snapDown(pos.y, size.y, bb.y);
|
snapDown(sourceBox.y, sourceBox.h, SURFBB.y);
|
||||||
snaps |= SNAP_DOWN;
|
snaps |= SNAP_DOWN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// corner snapping
|
// corner snapping
|
||||||
if (pos.x == bb.w || bb.x == pos.x + size.x) {
|
if (sourceBox.x == SURFBB.x + SURFBB.w || SURFBB.x == sourceBox.x + sourceBox.w) {
|
||||||
if (corner & (CORNER_TOPLEFT | CORNER_TOPRIGHT) && canSnap(pos.y, ob.y, gap)) {
|
if (corner & (CORNER_TOPLEFT | CORNER_TOPRIGHT) && canSnap(sourceBox.y, SURFBB.y, GAPSIZE)) {
|
||||||
snapUp(pos.y, size.y, ob.y);
|
snapUp(sourceBox.y, sourceBox.w, SURFBB.y);
|
||||||
snaps |= SNAP_UP;
|
snaps |= SNAP_UP;
|
||||||
} else if (corner & (CORNER_BOTTOMLEFT | CORNER_BOTTOMRIGHT) && canSnap(end.y, ob.h, gap)) {
|
} else if (corner & (CORNER_BOTTOMLEFT | CORNER_BOTTOMRIGHT) && canSnap(end.y, SURFBB.y + SURFBB.h, GAPSIZE)) {
|
||||||
snapDown(pos.y, size.y, ob.h);
|
snapDown(sourceBox.y, sourceBox.h, SURFBB.y + SURFBB.h);
|
||||||
snaps |= SNAP_DOWN;
|
snaps |= SNAP_DOWN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (pos.y == bb.h || bb.y == pos.y + size.y) {
|
if (sourceBox.y == SURFBB.y + SURFBB.h || SURFBB.y == sourceBox.y + sourceBox.w) {
|
||||||
if (corner & (CORNER_TOPLEFT | CORNER_BOTTOMLEFT) && canSnap(pos.x, ob.x, gap)) {
|
if (corner & (CORNER_TOPLEFT | CORNER_BOTTOMLEFT) && canSnap(sourceBox.x, SURFBB.x, GAPSIZE)) {
|
||||||
snapLeft(pos.x, size.x, ob.x);
|
snapLeft(sourceBox.x, sourceBox.w, SURFBB.x);
|
||||||
snaps |= SNAP_LEFT;
|
snaps |= SNAP_LEFT;
|
||||||
} else if (corner & (CORNER_TOPRIGHT | CORNER_BOTTOMRIGHT) && canSnap(end.x, ob.w, gap)) {
|
} else if (corner & (CORNER_TOPRIGHT | CORNER_BOTTOMRIGHT) && canSnap(end.x, SURFBB.x + SURFBB.w, GAPSIZE)) {
|
||||||
snapRight(pos.x, size.x, ob.w);
|
snapRight(sourceBox.x, sourceBox.w, SURFBB.x + SURFBB.w);
|
||||||
snaps |= SNAP_RIGHT;
|
snaps |= SNAP_RIGHT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -485,24 +485,26 @@ static void performSnap(Vector2D& pos, Vector2D& size, PHLWINDOW DRAGGINGWINDOW,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*SNAPMONITORGAP) {
|
if (*SNAPMONITORGAP) {
|
||||||
const auto MON = DRAGGINGWINDOW->m_pMonitor.lock();
|
const auto MON = DRAGGINGWINDOW->m_pMonitor.lock();
|
||||||
const CBox mon = {MON->vecPosition.x, MON->vecPosition.y, MON->vecPosition.x + MON->vecSize.x, MON->vecPosition.y + MON->vecSize.y};
|
const CBox mon =
|
||||||
|
CBox{MON->vecPosition.x + MON->vecReservedTopLeft.x, MON->vecPosition.y + MON->vecReservedTopLeft.y,
|
||||||
|
MON->vecSize.x - MON->vecReservedTopLeft.x - MON->vecReservedBottomRight.x, MON->vecSize.y - MON->vecReservedBottomRight.y - MON->vecReservedTopLeft.y};
|
||||||
const double gap = *SNAPMONITORGAP;
|
const double gap = *SNAPMONITORGAP;
|
||||||
|
|
||||||
if (canSnap(pos.x, mon.x, gap)) {
|
if (canSnap(sourceBox.x, mon.x, gap)) {
|
||||||
snapLeft(pos.x, size.x, mon.x);
|
snapLeft(sourceBox.x, sourceBox.w, mon.x);
|
||||||
snaps |= SNAP_LEFT;
|
snaps |= SNAP_LEFT;
|
||||||
}
|
}
|
||||||
if (canSnap(pos.x + size.x, mon.w, gap)) {
|
if (canSnap(sourceBox.x + sourceBox.w, mon.x + mon.w, gap)) {
|
||||||
snapRight(pos.x, size.x, mon.w);
|
snapRight(sourceBox.x, sourceBox.w, mon.w + mon.x);
|
||||||
snaps |= SNAP_RIGHT;
|
snaps |= SNAP_RIGHT;
|
||||||
}
|
}
|
||||||
if (canSnap(pos.y, mon.y, gap)) {
|
if (canSnap(sourceBox.y, mon.y, gap)) {
|
||||||
snapUp(pos.y, size.y, mon.y);
|
snapUp(sourceBox.y, sourceBox.h, mon.y);
|
||||||
snaps |= SNAP_UP;
|
snaps |= SNAP_UP;
|
||||||
}
|
}
|
||||||
if (canSnap(pos.y + size.y, mon.h, gap)) {
|
if (canSnap(sourceBox.y + sourceBox.h, mon.y + mon.h, gap)) {
|
||||||
snapDown(pos.y, size.y, mon.h);
|
snapDown(sourceBox.y, sourceBox.h, mon.h + mon.y);
|
||||||
snaps |= SNAP_DOWN;
|
snaps |= SNAP_DOWN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -511,17 +513,21 @@ static void performSnap(Vector2D& pos, Vector2D& size, PHLWINDOW DRAGGINGWINDOW,
|
||||||
const double RATIO = beginSize.y / beginSize.x;
|
const double RATIO = beginSize.y / beginSize.x;
|
||||||
|
|
||||||
if ((corner & (CORNER_TOPLEFT | CORNER_BOTTOMLEFT) && snaps & SNAP_LEFT) || (corner & (CORNER_TOPRIGHT | CORNER_BOTTOMRIGHT) && snaps & SNAP_RIGHT)) {
|
if ((corner & (CORNER_TOPLEFT | CORNER_BOTTOMLEFT) && snaps & SNAP_LEFT) || (corner & (CORNER_TOPRIGHT | CORNER_BOTTOMRIGHT) && snaps & SNAP_RIGHT)) {
|
||||||
const double sizeY = size.x * RATIO;
|
const double sizeY = sourceBox.h * RATIO;
|
||||||
if (corner & (CORNER_TOPLEFT | CORNER_TOPRIGHT))
|
if (corner & (CORNER_TOPLEFT | CORNER_TOPRIGHT))
|
||||||
pos.y += size.y - sizeY;
|
sourceBox.y += sourceBox.h - sizeY;
|
||||||
size.y = sizeY;
|
sourceBox.h = sizeY;
|
||||||
} else if ((corner & (CORNER_TOPLEFT | CORNER_TOPRIGHT) && snaps & SNAP_UP) || (corner & (CORNER_BOTTOMLEFT | CORNER_BOTTOMRIGHT) && snaps & SNAP_DOWN)) {
|
} else if ((corner & (CORNER_TOPLEFT | CORNER_TOPRIGHT) && snaps & SNAP_UP) || (corner & (CORNER_BOTTOMLEFT | CORNER_BOTTOMRIGHT) && snaps & SNAP_DOWN)) {
|
||||||
const double sizeX = size.y / RATIO;
|
const double sizeX = sourceBox.h / RATIO;
|
||||||
if (corner & (CORNER_TOPLEFT | CORNER_BOTTOMLEFT))
|
if (corner & (CORNER_TOPLEFT | CORNER_BOTTOMLEFT))
|
||||||
pos.x += size.x - sizeX;
|
sourceBox.x += sourceBox.w - sizeX;
|
||||||
size.x = sizeX;
|
sourceBox.w = sizeX;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sourceBox.expand(-DRAGGINGBORDERSIZE).round();
|
||||||
|
sourcePos = sourceBox.pos();
|
||||||
|
sourceSize = sourceBox.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
void IHyprLayout::onMouseMove(const Vector2D& mousePos) {
|
void IHyprLayout::onMouseMove(const Vector2D& mousePos) {
|
||||||
|
|
Loading…
Reference in a new issue