]> git.mdlowis.com Git - proto/labwc.git/commitdiff
resistance: support negative strengths to indicate attractive snapping
authorAndrew J. Hesford <ajh@sideband.org>
Sun, 21 Jan 2024 17:56:37 +0000 (12:56 -0500)
committerAndrew J. Hesford <48421688+ahesford@users.noreply.github.com>
Sun, 21 Jan 2024 21:10:50 +0000 (16:10 -0500)
docs/labwc-config.5.scd
src/resistance.c

index a685542569113b830596084a4dc999ed1e78fec7..f1f996d38a6600e9081f88caa0463094c92d7e76 100644 (file)
@@ -196,15 +196,26 @@ this is for compatibility with Openbox.
 
 ## RESISTANCE
 
-*<resistance><screenEdgeStrength>*
-       Screen-edge strength is the distance, in pixels, past the edge of a
-       screen the cursor must move before an interactive move or resize of a
-       window will continue past the edge. Default is 20 pixels.
-
+*<resistance><screenEdgeStrength>*++
 *<resistance><windowEdgeStrength>*
-       Window-edge strength is the distance, in pixels, past the edge of any
-       other window the cursor must move before an interactive move or resize
-       of a window will continue past the edge. Default is 20 pixels.
+       Resist interactive moves and resizes of a window across screen edges or
+       the edges of any other window, respectively.
+
+       When an edge strength is positive, it indicates a distance, in pixels,
+       that the cursor must move past any relevant encountered edge before an
+       interactive move or resize operation will continue across that edge.
+
+       When the strength is negative, any interactive move or resize operation
+       that brings the cursor within the absolute value of the specified
+       distance, in pixels, from any relevant edge will snap the operation to
+       that edge. Thus, as a move or resize approaches an edge, it will
+       "attract" the cursor to that edge within the specified distance. As the
+       move or resize continues past the edge, it will provide resistance until
+       the cursor has moved beyond the distance.
+
+       A strength of zero disables the corresponding resistance effect.
+
+       The default value for both parameters is 20 pixels.
 
 ## FOCUS
 
index 7fe3f3b59ea1a3e3ac767c576034a8857422eb8c..acb1dfe4473917b89cfad6f0f66b0c5e17b2312b 100644 (file)
@@ -12,20 +12,28 @@ static void
 is_within_resistance_range(struct border view, struct border target,
                struct border other, struct border *flags, int strength)
 {
-       if (view.left >= other.left && target.left < other.left
-                       && target.left >= other.left - strength) {
-               flags->left = 1;
-       } else if (view.right <= other.right && target.right > other.right
-                       && target.right <= other.right + strength) {
-               flags->right = 1;
+       if (view.left >= other.left) {
+               const int lo = other.left - abs(strength);
+               const int hi = other.left - MIN(strength, 0);
+               flags->left = target.left >= lo && target.left < hi;
        }
 
-       if (view.top >= other.top && target.top < other.top
-                       && target.top >= other.top - strength) {
-               flags->top = 1;
-       } else if (view.bottom <= other.bottom && target.bottom > other.bottom
-                       && target.bottom <= other.bottom + strength) {
-               flags->bottom = 1;
+       if (!flags->left && view.right <= other.right) {
+               const int lo = other.right + MIN(strength, 0);
+               const int hi = other.right + abs(strength);
+               flags->right = target.right > lo && target.right <= hi;
+       }
+
+       if (view.top >= other.top) {
+               const int lo = other.top - abs(strength);
+               const int hi = other.top - MIN(strength, 0);
+               flags->top = target.top >= lo && target.top < hi;
+       }
+
+       if (!flags->top && view.bottom <= other.bottom) {
+               const int lo = other.bottom + MIN(strength, 0);
+               const int hi = other.bottom + abs(strength);
+               flags->bottom = target.bottom > lo && target.bottom <= hi;
        }
 }
 
@@ -75,7 +83,7 @@ static void
 find_neighbor_edges(struct view *view, struct wlr_box new_geom,
                struct border *next_edges, bool move)
 {
-       if (rc.window_edge_strength <= 0) {
+       if (rc.window_edge_strength == 0) {
                return;
        }
 
@@ -118,7 +126,7 @@ static void
 find_screen_edges(struct view *view, struct wlr_box new_geom,
                struct border *next_edges, bool move)
 {
-       if (rc.screen_edge_strength <= 0) {
+       if (rc.screen_edge_strength == 0) {
                return;
        }