diff --git a/docs/labwc-config.5.scd b/docs/labwc-config.5.scd index acc59ada..d86634a8 100644 --- a/docs/labwc-config.5.scd +++ b/docs/labwc-config.5.scd @@ -891,6 +891,24 @@ situation. can be caused by ** settings or exclusive layer-shell clients such as panels. +## MENU + +``` + + 250 + +``` + +** + 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 ``. Default is 250 ms. + ## ENVIRONMENT VARIABLES *XCURSOR_THEME* and *XCURSOR_SIZE* are supported to set cursor theme diff --git a/docs/rc.xml.all b/docs/rc.xml.all index 2044ecd7..cc507dc8 100644 --- a/docs/rc.xml.all +++ b/docs/rc.xml.all @@ -586,4 +586,7 @@ --> + + 250 + diff --git a/include/config/rcxml.h b/include/config/rcxml.h index 60081db0..210d92f2 100644 --- a/include/config/rcxml.h +++ b/include/config/rcxml.h @@ -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; diff --git a/src/config/rcxml.c b/src/config/rcxml.c index 0d844119..1e268f47 100644 --- a/src/config/rcxml.c +++ b/src/config/rcxml.c @@ -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 diff --git a/src/input/cursor.c b/src/input/cursor.c index df03dcf2..6e0e81aa 100644 --- a/src/input/cursor.c +++ b/src/input/cursor.c @@ -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; }