[plasma/kwin] src: Remove snapping logic in checkWorkspacePosition()

Vlad Zahorodnii <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 2793b44003e20c8c81a57b02751078203d977ee9 by Vlad Zahorodnii.
Committed on 10/08/2026 at 12:47.
Pushed by vladz into branch 'master'.

Remove snapping logic in checkWorkspacePosition()

It's been working unreliably, sometimes it works, sometimes it doesn't.
Overall, the net gain from this feature is minor.

M  +0    -146  src/window.cpp
M  +0    -18   src/workspace.cpp
M  +0    -2    src/workspace.h

https://invent.kde.org/plasma/kwin/-/commit/2793b44003e20c8c81a57b02751078203d977ee9

diff --git a/src/window.cpp b/src/window.cpp
index a934b783e2a..ecc6940a61a 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -4020,9 +4020,6 @@ void Window::checkWorkspacePosition(RectF oldGeometry, LogicalOutput *oldOutput)
         oldOutput = moveResizeOutput();
     }
 
-    // If the window was touching an edge before but not now move it so it is again.
-    // Old and new maximums have different starting values so windows on the screen
-    // edge will move when a new strut is placed on the edge.
     RectF oldScreenArea;
     RectF screenArea;
     if (workspace()->inRearrange()) {
@@ -4050,149 +4047,6 @@ void Window::checkWorkspacePosition(RectF oldGeometry, LogicalOutput *oldOutput)
         return;
     }
 
-    const RectF oldGeomTall = RectF(QPointF(oldGeometry.left(), oldScreenArea.top()), QPointF(oldGeometry.right(), oldScreenArea.bottom())); // Full screen height
-    const RectF oldGeomWide = RectF(QPointF(oldScreenArea.left(), oldGeometry.top()), QPointF(oldScreenArea.right(), oldGeometry.bottom())); // Full screen width
-    qreal oldTopMax = oldScreenArea.top();
-    qreal oldRightMax = oldScreenArea.right();
-    qreal oldBottomMax = oldScreenArea.bottom();
-    qreal oldLeftMax = oldScreenArea.left();
-    qreal topMax = screenArea.top();
-    qreal rightMax = screenArea.right();
-    qreal bottomMax = screenArea.bottom();
-    qreal leftMax = screenArea.left();
-    const RectF newGeomTall(QPointF(newGeom.left(), screenArea.top()), QPointF(newGeom.right(), screenArea.bottom())); // Full screen height
-    const RectF newGeomWide(QPointF(screenArea.left(), newGeom.top()), QPointF(screenArea.right(), newGeom.bottom())); // Full screen width
-    // Get the max strut point for each side where the window is (E.g. Highest point for
-    // the bottom struts bounded by the window's left and right sides).
-
-    // These 4 compute old bounds ...
-    auto moveAreaFunc = workspace()->inRearrange() ? &Workspace::previousRestrictedMoveArea : //... the restricted areas changed
-        &Workspace::restrictedMoveArea; //... when e.g. active desktop or screen changes
-
-    const auto oldStrutsTop = (workspace()->*moveAreaFunc)(StrutAreaTop);
-    for (const RectF &r : oldStrutsTop) {
-        RectF rect = r & oldGeomTall;
-        if (!rect.isEmpty()) {
-            oldTopMax = std::max(oldTopMax, rect.bottom());
-        }
-    }
-    const auto oldStrutsRight = (workspace()->*moveAreaFunc)(StrutAreaRight);
-    for (const RectF &r : oldStrutsRight) {
-        RectF rect = r & oldGeomWide;
-        if (!rect.isEmpty()) {
-            oldRightMax = std::min(oldRightMax, rect.left());
-        }
-    }
-    const auto oldStrutsBottom = (workspace()->*moveAreaFunc)(StrutAreaBottom);
-    for (const RectF &r : oldStrutsBottom) {
-        RectF rect = r & oldGeomTall;
-        if (!rect.isEmpty()) {
-            oldBottomMax = std::min(oldBottomMax, rect.top());
-        }
-    }
-    const auto oldStrutsLeft = (workspace()->*moveAreaFunc)(StrutAreaLeft);
-    for (const RectF &r : oldStrutsLeft) {
-        RectF rect = r & oldGeomWide;
-        if (!rect.isEmpty()) {
-            oldLeftMax = std::max(oldLeftMax, rect.right());
-        }
-    }
-
-    // These 4 compute new bounds
-    const auto newStrutsTop = workspace()->restrictedMoveArea(StrutAreaTop);
-    for (const RectF &r : newStrutsTop) {
-        RectF rect = r & newGeomTall;
-        if (!rect.isEmpty()) {
-            topMax = std::max(topMax, rect.bottom());
-        }
-    }
-    const auto newStrutsRight = workspace()->restrictedMoveArea(StrutAreaRight);
-    for (const RectF &r : newStrutsRight) {
-        RectF rect = r & newGeomWide;
-        if (!rect.isEmpty()) {
-            rightMax = std::min(rightMax, rect.left());
-        }
-    }
-    const auto newStrutsBottom = workspace()->restrictedMoveArea(StrutAreaBottom);
-    for (const RectF &r : newStrutsBottom) {
-        RectF rect = r & newGeomTall;
-        if (!rect.isEmpty()) {
-            bottomMax = std::min(bottomMax, rect.top());
-        }
-    }
-    const auto newStrutsLeft = workspace()->restrictedMoveArea(StrutAreaLeft);
-    for (const RectF &r : newStrutsLeft) {
-        RectF rect = r & newGeomWide;
-        if (!rect.isEmpty()) {
-            leftMax = std::max(leftMax, rect.right());
-        }
-    }
-
-    // Check if the sides were inside or touching but are no longer
-    enum {
-        Left = 0,
-        Top,
-        Right,
-        Bottom,
-    };
-    bool keep[4] = {false, false, false, false};
-    bool save[4] = {false, false, false, false};
-    if (oldGeometry.x() >= oldLeftMax) {
-        save[Left] = newGeom.x() < leftMax;
-    }
-    if (oldGeometry.x() == oldLeftMax) {
-        keep[Left] = newGeom.x() != leftMax;
-    }
-
-    if (oldGeometry.y() >= oldTopMax) {
-        save[Top] = newGeom.y() < topMax;
-    }
-    if (oldGeometry.y() == oldTopMax) {
-        keep[Top] = newGeom.y() != topMax;
-    }
-
-    if (oldGeometry.right() <= oldRightMax) {
-        save[Right] = newGeom.right() > rightMax;
-    }
-    if (oldGeometry.right() == oldRightMax) {
-        keep[Right] = newGeom.right() != rightMax;
-    }
-
-    if (oldGeometry.bottom() <= oldBottomMax) {
-        save[Bottom] = newGeom.bottom() > bottomMax;
-    }
-    if (oldGeometry.bottom() == oldBottomMax) {
-        keep[Bottom] = newGeom.bottom() != bottomMax;
-    }
-
-    // if randomly touches opposing edges, do not favor either
-    if (keep[Left] && keep[Right]) {
-        keep[Left] = keep[Right] = false;
-    }
-    if (keep[Top] && keep[Bottom]) {
-        keep[Top] = keep[Bottom] = false;
-    }
-
-    if (save[Left] || keep[Left]) {
-        newGeom.moveLeft(std::max(leftMax, screenArea.x()));
-    }
-    if (save[Top] || keep[Top]) {
-        newGeom.moveTop(std::max(topMax, screenArea.y()));
-    }
-    if (save[Right] || keep[Right]) {
-        newGeom.moveRight(std::min(rightMax, screenArea.right()));
-    }
-    if (save[Bottom] || keep[Bottom]) {
-        newGeom.moveBottom(std::min(bottomMax, screenArea.bottom()));
-    }
-
-    if (oldGeometry.x() >= oldLeftMax && newGeom.x() < leftMax) {
-        newGeom.setLeft(std::max(leftMax, screenArea.left()));
-    }
-    if (oldGeometry.y() >= oldTopMax && newGeom.y() < topMax) {
-        newGeom.setTop(std::max(topMax, screenArea.top()));
-    }
-
     checkOffscreenPosition(&newGeom, screenArea);
     // Obey size hints. TODO: We really should make sure it stays in the right place
     newGeom.setSize(constrainFrameSize(newGeom.size()));
diff --git a/src/workspace.cpp b/src/workspace.cpp
index 17fe718b2f0..b585f809f69 100644
--- a/src/workspace.cpp
+++ b/src/workspace.cpp
@@ -2462,7 +2462,6 @@ void Workspace::rearrange(const QHash<Window *, LogicalOutput *> &oldOutputs)
         m_screenAreas = screenAreas;
 
         m_inRearrange = true;
-        m_oldRestrictedArea = m_restrictedArea;
         m_restrictedArea = restrictedArea;
 
 #if KWIN_BUILD_X11
@@ -2480,7 +2479,6 @@ void Workspace::rearrange(const QHash<Window *, LogicalOutput *> &oldOutputs)
             }
         }
 
-        m_oldRestrictedArea.clear(); // reset, no longer valid or needed
         m_inRearrange = false;
     }
 }
@@ -2554,22 +2552,6 @@ bool Workspace::inRearrange() const
     return m_inRearrange;
 }
 
-StrutRects Workspace::previousRestrictedMoveArea(StrutAreas areas) const
-{
-    if (areas == StrutAreaAll) {
-        return m_oldRestrictedArea;
-    }
-
-    StrutRects ret;
-    ret.reserve(m_oldRestrictedArea.size());
-    for (const StrutRect &rect : m_oldRestrictedArea) {
-        if (rect.area() & areas) {
-            ret.append(rect);
-        }
-    }
-    return ret;
-}
-
 QHash<const LogicalOutput *, Rect> Workspace::previousScreenSizes() const
 {
     return m_oldScreenGeometries;
diff --git a/src/workspace.h b/src/workspace.h
index 31bc016b014..3afc31f8873 100644
--- a/src/workspace.h
+++ b/src/workspace.h
@@ -237,7 +237,6 @@ public:
     // Unsorted
 
 public:
-    StrutRects previousRestrictedMoveArea(StrutAreas areas = StrutAreaAll) const;
     QHash<const LogicalOutput *, Rect> previousScreenSizes() const;
 
     /**
@@ -709,7 +708,6 @@ private:
     Rect m_geometry;
 
     QHash<const LogicalOutput *, Rect> m_oldScreenGeometries;
-    StrutRects m_oldRestrictedArea;
     QTimer m_rearrangeTimer;
     bool m_inRearrange = false;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.