]> git.mdlowis.com Git - proto/labwc.git/commitdiff
mouse: add support for drag mouse event
authorARDiDo <90479315+ARDiDo@users.noreply.github.com>
Thu, 6 Jan 2022 23:30:17 +0000 (18:30 -0500)
committerJohan Malm <johanmalm@users.noreply.github.com>
Fri, 7 Jan 2022 22:05:07 +0000 (22:05 +0000)
docs/labwc-config.5.scd
docs/rc.xml.all
include/config/mousebind.h
src/config/mousebind.c
src/config/rcxml.c
src/cursor.c

index 43312c3d785a24fce8b42ef28000741ecf857f25..6c14e976fca5d2b37ac4907d211ed05d5864f023 100644 (file)
@@ -144,6 +144,7 @@ Configuration must be wrapped in a <labwc_config> root-node.
        - Release: Releasing the specified button in the context.
        - Click: Pressing and then releasing inside of the the context.
        - DoubleClick: Two presses within the doubleClickTime.
+       - Drag: Pressing the button within the contex, then moving the cursor
 
 # LIBINPUT
 
index 0dfb6d41d245ab3c31c834ab962d1d7d704a77bd..8f4fc1a84daf602313c7645913372a993d4a7270 100644 (file)
   <!--
     Multiple <mousebind> can exist within one <context>
     Multiple <actions> can exist within one <mousebind>
-    The following openbox-actions are not supported: "Unshade" and "Drag"
+    Currently, the only openbox-action not supported is "Unshade"
   -->
   <mouse>
 
     <doubleClickTime>500</doubleClickTime>
 
     <context name="Frame">
-      <mousebind button="A-Left" action="Press">
+      <mousebind button="A-Left" action="Drag">
         <action name="Focus"/>
         <action name="Raise"/>
         <action name="Move"/>
       </mousebind>
-      <mousebind button="A-Right" action="Press">
+      <mousebind button="A-Right" action="Drag">
         <action name="Focus"/>
         <action name="Raise"/>
         <action name="Resize"/>
     </context>
 
     <context name="Top">
-      <mousebind button="Left" action="Press">
+      <mousebind button="Left" action="Drag">
         <action name="Resize"/>
       </mousebind>
     </context>
     <context name="Left">
-      <mousebind button="Left" action="Press">
+      <mousebind button="Left" action="Drag">
         <action name="Resize"/>
       </mousebind>
     </context>
     <context name="Right">
-      <mousebind button="Left" action="Press">
+      <mousebind button="Left" action="Drag">
         <action name="Resize"/>
       </mousebind>
     </context>
     <context name="Bottom">
-      <mousebind button="Left" action="Press">
+      <mousebind button="Left" action="Drag">
         <action name="Resize"/>
       </mousebind>
     </context>
     <context name="TRCorner">
-      <mousebind button="Left" action="Press">
+      <mousebind button="Left" action="Drag">
         <action name="Resize"/>
       </mousebind>
     </context>
     <context name="BRCorner">
-      <mousebind button="Left" action="Press">
+      <mousebind button="Left" action="Drag">
         <action name="Resize"/>
       </mousebind>
     </context>
     <context name="TLCorner">
-      <mousebind button="Left" action="Press">
+      <mousebind button="Left" action="Drag">
         <action name="Resize"/>
       </mousebind>
     </context>
     <context name="BLCorner">
-      <mousebind button="Left" action="Press">
+      <mousebind button="Left" action="Drag">
         <action name="Resize"/>
       </mousebind>
     </context>
 
     <context name="TitleBar">
-      <mousebind button="Left" action="Press">
+      <mousebind button="Left" action="Drag">
         <action name="Focus"/>
         <action name="Raise"/>
         <action name="Move"/>
index da43594c7e1c6dcb5b037ba68926bd78194d4475..e2da203c2fab4c321890ac08e4e9a75fd22e6d6d 100644 (file)
@@ -11,6 +11,7 @@ enum mouse_event {
        MOUSE_ACTION_CLICK,
        MOUSE_ACTION_PRESS,
        MOUSE_ACTION_RELEASE,
+       MOUSE_ACTION_DRAG,
 };
 
 struct mousebind {
index 091e582453a02e421a6b02717b0955e2b300d68f..fdbd34d08f2d8655ae9dc4e924b3f7eb360edfc5 100644 (file)
@@ -49,6 +49,8 @@ mousebind_event_from_str(const char *str)
                return MOUSE_ACTION_PRESS;
        } else if (!strcasecmp(str, "release")) {
                return MOUSE_ACTION_RELEASE;
+       } else if (!strcasecmp(str, "drag")) {
+               return MOUSE_ACTION_DRAG;
        }
        wlr_log(WLR_ERROR, "unknown mouse action (%s)", str);
        return MOUSE_ACTION_NONE;
index 8cb843126760b812ecd1e1df2ee5af50ce69ffd3..fd1ec15c15d8ed33e02d80de757cc4d74ae04bfb 100644 (file)
@@ -520,23 +520,23 @@ load_default_key_bindings(void)
 static struct {
        const char *context, *button, *event, *action, *command;
 } mouse_combos[] = {
-       { "Left", "Left", "Press", "Resize", NULL},
-       { "Top", "Left", "Press", "Resize", NULL},
-       { "Bottom", "Left", "Press", "Resize", NULL},
-       { "Right", "Left", "Press", "Resize", NULL},
-       { "TLCorner", "Left", "Press", "Resize", NULL},
-       { "TRCorner", "Left", "Press", "Resize", NULL},
-       { "BRCorner", "Left", "Press", "Resize", NULL},
-       { "BLCorner", "Left", "Press", "Resize", NULL},
-       { "Frame", "A-Left", "Press", "Focus", NULL},
-       { "Frame", "A-Left", "Press", "Raise", NULL},
-       { "Frame", "A-Left", "Press", "Move", NULL},
-       { "Frame", "A-Right", "Press", "Focus", NULL},
-       { "Frame", "A-Right", "Press", "Raise", NULL},
-       { "Frame", "A-Right", "Press", "Resize", NULL},
-       { "Titlebar", "Left", "Press", "Focus", NULL},
-       { "Titlebar", "Left", "Press", "Raise", NULL},
-       { "TitleBar", "Left", "Press", "Move", NULL },
+       { "Left", "Left", "Drag", "Resize", NULL},
+       { "Top", "Left", "Drag", "Resize", NULL},
+       { "Bottom", "Left", "Drag", "Resize", NULL},
+       { "Right", "Left", "Drag", "Resize", NULL},
+       { "TLCorner", "Left", "Drag", "Resize", NULL},
+       { "TRCorner", "Left", "Drag", "Resize", NULL},
+       { "BRCorner", "Left", "Drag", "Resize", NULL},
+       { "BLCorner", "Left", "Drag", "Resize", NULL},
+       { "Frame", "A-Left", "Drag", "Focus", NULL},
+       { "Frame", "A-Left", "Drag", "Raise", NULL},
+       { "Frame", "A-Left", "Drag", "Move", NULL},
+       { "Frame", "A-Right", "Drag", "Focus", NULL},
+       { "Frame", "A-Right", "Drag", "Raise", NULL},
+       { "Frame", "A-Right", "Drag", "Resize", NULL},
+       { "Titlebar", "Left", "Drag", "Focus", NULL},
+       { "Titlebar", "Left", "Drag", "Raise", NULL},
+       { "TitleBar", "Left", "Drag", "Move", NULL },
        { "TitleBar", "Left", "DoubleClick", "ToggleMaximize", NULL },
        { "Close", "Left", "Click", "Close", NULL },
        { "Iconify", "Left", "Click", "Iconify", NULL},
index 032087366e436b0882a83f4aba58e1bcb361559f..1253a6f64f59d95b445370178a657d922b36edc8 100644 (file)
@@ -198,13 +198,14 @@ process_cursor_motion(struct server *server, uint32_t time)
                server->seat.cursor->x, server->seat.cursor->y, &surface,
                &sx, &sy, &view_area);
 
+       /* resize handles */
+       uint32_t resize_edges = ssd_resize_edges(view_area);
+
        /* Set cursor */
        if (!view) {
                /* root, etc. */
                cursor_set(&server->seat, XCURSOR_DEFAULT);
        } else {
-               /* resize handles */
-               uint32_t resize_edges = ssd_resize_edges(view_area);
                if (resize_edges) {
                        cursor_name_set_by_server = true;
                        cursor_set(&server->seat,
@@ -228,6 +229,25 @@ process_cursor_motion(struct server *server, uint32_t time)
                }
        }
 
+       struct mousebind *mousebind;
+       wl_list_for_each(mousebind, &rc.mousebinds, link) {
+               if (mousebind->mouse_event == MOUSE_ACTION_DRAG
+                               && mousebind->pressed_in_context) {
+                       /* Find closest resize edges in case action is Resize */
+                       if (view) {
+                               resize_edges |= server->seat.cursor->x
+                                       < view->x + view->w / 2 ? WLR_EDGE_LEFT
+                                       : WLR_EDGE_RIGHT;
+                               resize_edges |= server->seat.cursor->y
+                                       < view->y + view->h / 2 ? WLR_EDGE_TOP
+                                       : WLR_EDGE_BOTTOM;
+                       }
+
+                       mousebind->pressed_in_context = false;
+                       action(NULL, server, &mousebind->actions, resize_edges);
+               }
+       }
+
        /* Required for iconify/maximize/close button mouse-over deco */
        damage_all_outputs(server);
 
@@ -473,6 +493,8 @@ handle_release_mousebinding(struct view *view, struct server *server,
                        activated_any_frame |= mousebind->context == LAB_SSD_FRAME;
                        action(view, server, &mousebind->actions, resize_edges);
                }
+               /* For the drag events */
+               mousebind->pressed_in_context = false;
        }
        return activated_any && activated_any_frame;
 }
@@ -518,6 +540,7 @@ handle_press_mousebinding(struct view *view, struct server *server,
                                && mousebind->button == button
                                && modifiers == mousebind->modifiers) {
                        switch (mousebind->mouse_event) {
+                       case MOUSE_ACTION_DRAG: /* FALLTHROUGH */
                        case MOUSE_ACTION_CLICK:
                                mousebind->pressed_in_context = true;
                                continue;