]> git.mdlowis.com Git - proto/labwc.git/commitdiff
Improve expandibility
authorARDiDo <90479315+ARDiDo@users.noreply.github.com>
Sun, 24 Oct 2021 02:31:39 +0000 (22:31 -0400)
committerJohan Malm <johanmalm@users.noreply.github.com>
Tue, 26 Oct 2021 20:15:13 +0000 (21:15 +0100)
include/config/rcxml.h
include/labwc.h
src/config/rcxml.c
src/cursor.c
src/meson.build
src/strength.c [new file with mode: 0644]
src/view.c

index 630085835b026d3e5f6b87d16bdd09af35b6e572..7ed21d63320ea9381a77b54b91493de9c20b71df 100644 (file)
@@ -14,7 +14,7 @@ struct rcxml {
        bool xdg_shell_server_side_deco;
        int gap;
        bool adaptive_sync;
-       int strength;
+       int screen_edge_strength;
 
        /* focus */
        bool focus_follow_mouse;
index 2f32ed7ca4bfe581955b07ea3225392664a03a0e..1790f52be2a43d3c69f2fb74b871e253bcd120f2 100644 (file)
@@ -345,6 +345,8 @@ void view_child_finish(struct view_child *child);
 void subsurface_create(struct view *view, struct wlr_subsurface *wlr_subsurface);
 
 void view_set_activated(struct view *view, bool activated);
+void move_resistance(struct view *view, double *x, double *y, bool screen_edge);
+struct border view_border(struct view *view);
 void view_move_resize(struct view *view, struct wlr_box geo);
 void view_move(struct view *view, double x, double y);
 void view_minimize(struct view *view, bool minimized);
index 99bf2a25749a6e038057e6c704c12279fcb6151a..91a5fe73d0aa8d0738e8f3cf0df9bcb992155e45 100644 (file)
@@ -323,7 +323,7 @@ entry(xmlNode *node, char *nodename, char *content)
        } else if (!strcasecmp(nodename, "repeatDelay.keyboard")) {
                rc.repeat_delay = atoi(content);
        } else if (!strcasecmp(nodename, "screenEdgeStrength.core")) {
-               rc.strength = atoi(content);
+               rc.screen_edge_strength = atoi(content);
        }
 }
 
@@ -419,7 +419,7 @@ rcxml_init()
        rc.doubleclick_time = 500;
        rc.repeat_rate = 25;
        rc.repeat_delay = 600;
-       rc.strength = 0;
+       rc.screen_edge_strength = 0;
 }
 
 static struct {
index 653c5227acd5c6f5ff81771fa217f31c4d874317..b0d9b4462d18d38ea42c02490f90b81444fee4cc 100644 (file)
@@ -79,7 +79,10 @@ process_cursor_move(struct server *server, uint32_t time)
        struct view *view = server->grabbed_view;
 
        /* Move the grabbed view to the new position. */
-       view_move(view, server->grab_box.x + dx, server->grab_box.y + dy);
+       dx += server->grab_box.x;
+       dy += server->grab_box.y;
+       move_resistance(view, &dx, &dy, true);
+       view_move(view, dx, dy);
 }
 
 static void
index dc183ef10c48b3131b3c66e908e3e3cec87910a7..08bfbfdba599e540f80dd578e17f4cea129ea2a6 100644 (file)
@@ -13,6 +13,7 @@ labwc_sources = files(
   'seat.c',
   'server.c',
   'ssd.c',
+  'strength.c',
   'subsurface.c',
   'theme.c',
   'view.c',
diff --git a/src/strength.c b/src/strength.c
new file mode 100644 (file)
index 0000000..ca21400
--- /dev/null
@@ -0,0 +1,56 @@
+#include "labwc.h"
+#include "config/rcxml.h"
+
+/* These functions could be extended to strength in the future. */
+void
+move_resistance(struct view *view, double *x, double *y, bool screen_edge)
+{
+       struct server *server = view->server;
+       struct wlr_box mgeom;
+       struct output *output;
+       struct border border = view_border(view);
+       int l, r, t, b; /* The edges of the current view */
+       int tl, tr, tt, tb; /* The desired edges */
+       int ml, mr, mt, mb; /* The edges of the monitor/other view */
+
+       l = view->x - border.left - rc.gap;
+       t = view->y - border.top - rc.gap;
+       r = view->x + view->w + border.right + rc.gap;
+       b = view->y + view->h + border.bottom + rc.gap;
+
+       tl = *x - border.left - rc.gap;
+       tt = *y - border.top - rc.gap;
+       tr = *x + view->w + border.right + rc.gap;
+       tb = *y + view->h + border.bottom + rc.gap;
+
+       if (screen_edge) {
+               if (!rc.screen_edge_strength) {
+                       return;
+               }
+
+               wl_list_for_each(output, &server->outputs, link) {
+                       mgeom = output_usable_area_in_layout_coords(output);
+       
+                       ml = mgeom.x;
+                       mt = mgeom.y;
+                       mr = mgeom.x + mgeom.width;
+                       mb = mgeom.y + mgeom.height;
+       
+                       if (l >= ml && tl < ml && tl >= ml
+                                       - rc.screen_edge_strength) {
+                               *x = ml + border.left + rc.gap;
+                       } else if (r <= mr && tr > mr && tr <= mr
+                                       + rc.screen_edge_strength) {
+                               *x = mr - view->w - border.right - rc.gap;
+                       }
+
+                       if (t >= mt && tt < mt && tt >= mt
+                                       - rc.screen_edge_strength) {
+                               *y = mt + border.top + rc.gap;
+                       } else if (b <= mb && tb > mb && tb <= mb
+                                       + rc.screen_edge_strength) {
+                               *y = mb - view->h - border.bottom - rc.gap;
+                       }
+               }
+       }
+}
index 7515c68e968b3a070e930e3f843b186c68e6aa23..b330b900a1d398cc881c200d056bdec77a144708 100644 (file)
@@ -16,8 +16,6 @@ view_set_activated(struct view *view, bool activated)
        }
 }
 
-static void view_move_resistance(struct view *view, double *x, double *y);
-
 void
 view_move_resize(struct view *view, struct wlr_box geo)
 {
@@ -31,7 +29,6 @@ void
 view_move(struct view *view, double x, double y)
 {
        if (view->impl->move) {
-               view_move_resistance(view, &x, &y);
                view->impl->move(view, x, y);
        }
 }
@@ -255,7 +252,7 @@ view_for_each_popup_surface(struct view *view,
        }
 }
 
-static struct border
+struct border
 view_border(struct view *view)
 {
        struct border border = {
@@ -426,55 +423,6 @@ view_snap_to_edge(struct view *view, const char *direction)
        view_move_resize(view, dst);
 }
 
-static void
-view_move_resistance(struct view *view, double *x, double *y)
-{
-       struct wlr_box mgeom;
-       struct output *output;
-       struct border border = view_border(view);
-       int l, r, t, b; /* The edges of the current view */
-       int tl, tr, tt, tb; /* The desired edges */
-       int ml, mr, mt, mb; /* The edges of the Monitor */
-
-       if (!rc.strength) {
-               return;
-       }
-
-       output = view_output(view);
-       if (!output) {
-               return;
-       }
-
-       l = view->x - border.left - rc.gap;
-       t = view->y - border.top - rc.gap;
-       r = view->x + view->w + border.right + rc.gap;
-       b = view->y + view->h + border.bottom + rc.gap;
-
-       tl = *x - border.left - rc.gap;
-       tt = *y - border.top - rc.gap;
-       tr = *x + view->w + border.right + rc.gap;
-       tb = *y + view->h + border.bottom + rc.gap;
-
-       mgeom = output_usable_area_in_layout_coords(output);
-
-       ml = mgeom.x;
-       mt = mgeom.y;
-       mr = mgeom.x + mgeom.width;
-       mb = mgeom.y + mgeom.height;
-
-       if (l >= ml && tl < ml && tl >= ml - rc.strength) {
-               *x = ml + border.left + rc.gap;
-       } else if (r <= mr && tr > mr && tr <= mr + rc.strength) {
-               *x = mr - view->w - border.right - rc.gap;
-       }
-
-       if (t >= mt && tt < mt && tt >= mt - rc.strength) {
-               *y = mt + border.top + rc.gap;
-       } else if (b <= mb && tb > mb && tb <= mb + rc.strength) {
-               *y = mb - view->h - border.bottom - rc.gap;
-       }
-}
-
 const char *
 view_get_string_prop(struct view *view, const char *prop)
 {