]> git.mdlowis.com Git - proto/labwc.git/commitdiff
cursor: implement <menu><ignoreButtonReleasePeriod>
authortokyo4j <hrak1529@gmail.com>
Fri, 26 Apr 2024 00:03:17 +0000 (09:03 +0900)
committerHiroaki Yamamoto <hrak1529@gmail.com>
Wed, 1 May 2024 10:08:07 +0000 (19:08 +0900)
Addresses UX degradation introduced by commit 1d3ed457.

This prevents clicks with small movement with the intention of opening
the menu from unexpectedly closing the menu or selecting a menu item.

docs/labwc-config.5.scd
docs/rc.xml.all
include/config/rcxml.h
src/config/rcxml.c
src/input/cursor.c

index acc59ada93254f4c824b46f2fdc3178992e12bc9..d86634a879ad2c80173e7d5b8a61027b2c07000f 100644 (file)
@@ -891,6 +891,24 @@ situation.
        can be caused by *<margin>* settings or exclusive layer-shell clients
        such as panels.
 
+## MENU
+
+```
+<menu>
+  <ignoreButtonReleasePeriod>250</ignoreButtonReleasePeriod>
+</menu>
+```
+
+*<menu><ignoreButtonReleasePeriod>*
+       How long (in milliseconds) the initial button release event is ignored
+       for. The reason for this logic and behaviour is to avoid a fast
+       press-move-release sequence indended to just open the menu resulting in
+       the closure of the menu or the selection of (typically the first) menu
+       item. This behaviour only affects the first button-release. It is not
+       anticipated that most users will want to change this, but the config
+       option has been exposed for unusual use-cases. It is equivalent to
+       Openbox's `<hideDelay>`. Default is 250 ms.
+
 ## ENVIRONMENT VARIABLES
 
 *XCURSOR_THEME* and *XCURSOR_SIZE* are supported to set cursor theme
index 2044ecd71dac29d17f1418fc1c36a58ed3449636..cc507dc830d81933af0be68daba92dd63634b8f4 100644 (file)
     </windowRules>
   -->
 
+  <menu>
+    <ignoreButtonReleasePeriod>250</ignoreButtonReleasePeriod>
+  </menu>
 </labwc_config>
index 60081db03859f4bc42ea8e20f657061db4459130..210d92f2c75c183c9048f40c16dd8c163eecc23a 100644 (file)
@@ -137,6 +137,9 @@ struct rcxml {
        } window_switcher;
 
        struct wl_list window_rules; /* struct window_rule.link */
+
+       /* Menu */
+       unsigned int menu_ignore_button_release_period;
 };
 
 extern struct rcxml rc;
index 0d844119638b056bb068c16f7cf9702db95c6ffe..1e268f474a2421148ab34a61c49d8ff91407bfe8 100644 (file)
@@ -1034,6 +1034,8 @@ entry(xmlNode *node, char *nodename, char *content)
                } else {
                        wlr_log(WLR_ERROR, "Missing 'button' argument for tablet button mapping");
                }
+       } else if (!strcasecmp(nodename, "ignoreButtonReleasePeriod.menu")) {
+               rc.menu_ignore_button_release_period = atoi(content);
        }
 }
 
@@ -1238,6 +1240,8 @@ rcxml_init(void)
 
        rc.workspace_config.popuptime = INT_MIN;
        rc.workspace_config.min_nr_workspaces = 1;
+
+       rc.menu_ignore_button_release_period = 250;
 }
 
 static void
index df03dcf2052a7b7647bc08db5395ac4776b381e7..6e0e81aa33c3fbffacb36507a411941a0892da2f 100644 (file)
@@ -929,6 +929,8 @@ handle_press_mousebinding(struct server *server, struct cursor_context *ctx,
        return consumed_by_frame_context;
 }
 
+static uint32_t press_msec;
+
 static void
 cursor_button_press(struct seat *seat, uint32_t button,
                enum wlr_button_state button_state, uint32_t time_msec)
@@ -936,6 +938,9 @@ cursor_button_press(struct seat *seat, uint32_t button,
        struct server *server = seat->server;
        struct cursor_context ctx = get_cursor_context(server);
 
+       /* Used on next button release to check if it can close menu or select menu item */
+       press_msec = time_msec;
+
        /* Determine closest resize edges in case action is Resize */
        uint32_t resize_edges = cursor_get_resize_edges(seat->cursor, &ctx);
 
@@ -946,6 +951,11 @@ cursor_button_press(struct seat *seat, uint32_t button,
        }
 
        if (server->input_mode == LAB_INPUT_STATE_MENU) {
+               /*
+                * If menu was already opened on press, set a very small value
+                * so subsequent release always closes menu or selects menu item.
+                */
+               press_msec = 0;
                return;
        }
 
@@ -1011,12 +1021,15 @@ cursor_button_release(struct seat *seat, uint32_t button,
        seat_reset_pressed(seat);
 
        if (server->input_mode == LAB_INPUT_STATE_MENU) {
-               if (ctx.type == LAB_SSD_MENU) {
-                       menu_call_selected_actions(server);
-               } else {
-                       menu_close_root(server);
-                       cursor_update_common(server, &ctx, time_msec,
-                               /*cursor_has_moved*/ false);
+               /* TODO: take into account overflow of time_msec */
+               if (time_msec - press_msec > rc.menu_ignore_button_release_period) {
+                       if (ctx.type == LAB_SSD_MENU) {
+                               menu_call_selected_actions(server);
+                       } else {
+                               menu_close_root(server);
+                               cursor_update_common(server, &ctx, time_msec,
+                                       /*cursor_has_moved*/ false);
+                       }
                }
                return;
        }