Refactor the logic of placing client-menu with ShowMenu action

Before this commit, we assumed `ShowMenu` action is not bound to any
buttons other than window menu button and always place the client-menu
under the window-menu button when atCursor="no". Also, it was going to be
difficult to distinguish whether the action is executed from the window
menu button or the window icon, which will be added soon.

This commit fixes it to open the menu under the actually-clicked button by
passing `cursor_context` to `actions_run()`, with some refactoring:
- `seat->pressed.resize_edges` is removed and it's calculated from the
  cursor position and `seat->pressed.type` just before running Resize
  action. This slightly changes the existing logic to determine the
  resizing edges with Alt-Right + Drag mousebinding, but
  `seat->pressed.type` is still stored on button press so it doesn't bring
  back the issue #543.
- `seat->pressed.toplevel` is removed and `get_toplevel()` in
  `update_pressed_surface()` may be called more often, but its overhead
  will be negligible.
This commit is contained in:
tokyo4j 2024-09-21 01:11:27 +09:00 committed by Johan Malm
parent d29464bac7
commit 25f5cdd3a6
12 changed files with 67 additions and 109 deletions

View file

@ -400,11 +400,8 @@ update_pressed_surface(struct seat *seat, struct cursor_context *ctx)
}
if (seat->pressed.surface && ctx->surface != seat->pressed.surface) {
struct wlr_surface *toplevel = get_toplevel(ctx->surface);
if (toplevel && toplevel == seat->pressed.toplevel) {
/* No need to recompute resize edges here */
seat_set_pressed(seat, ctx->view,
ctx->node, ctx->surface, toplevel,
seat->pressed.resize_edges);
if (toplevel && toplevel == get_toplevel(seat->pressed.surface)) {
seat_set_pressed(seat, ctx);
return true;
}
}
@ -597,9 +594,8 @@ cursor_process_motion(struct server *server, uint32_t time, double *sx, double *
* moving/resizing the wrong view
*/
mousebind->pressed_in_context = false;
actions_run(seat->pressed.view,
server, &mousebind->actions,
seat->pressed.resize_edges);
actions_run(seat->pressed.view, server,
&mousebind->actions, &seat->pressed);
}
}
@ -904,8 +900,7 @@ handle_release_mousebinding(struct server *server,
}
consumed_by_frame_context |= mousebind->context == LAB_SSD_FRAME;
consumed_by_frame_context |= mousebind->context == LAB_SSD_ALL;
actions_run(ctx->view, server, &mousebind->actions,
/*resize_edges*/ 0);
actions_run(ctx->view, server, &mousebind->actions, ctx);
}
}
/*
@ -956,7 +951,7 @@ is_double_click(long double_click_speed, uint32_t button,
static bool
handle_press_mousebinding(struct server *server, struct cursor_context *ctx,
uint32_t button, uint32_t resize_edges)
uint32_t button)
{
if (server->osd_state.cycle_view) {
return false;
@ -1005,7 +1000,7 @@ handle_press_mousebinding(struct server *server, struct cursor_context *ctx,
}
consumed_by_frame_context |= mousebind->context == LAB_SSD_FRAME;
consumed_by_frame_context |= mousebind->context == LAB_SSD_ALL;
actions_run(ctx->view, server, &mousebind->actions, resize_edges);
actions_run(ctx->view, server, &mousebind->actions, ctx);
}
}
return consumed_by_frame_context;
@ -1022,13 +1017,9 @@ cursor_process_button_press(struct seat *seat, uint32_t button, uint32_t time_ms
/* 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);
if (ctx.view || ctx.surface) {
/* Store resize edges for later action processing */
seat_set_pressed(seat, ctx.view, ctx.node, ctx.surface,
get_toplevel(ctx.surface), resize_edges);
/* Store cursor context for later action processing */
seat_set_pressed(seat, &ctx);
}
if (server->input_mode == LAB_INPUT_STATE_MENU) {
@ -1082,7 +1073,7 @@ cursor_process_button_press(struct seat *seat, uint32_t button, uint32_t time_ms
/* Bindings to the Frame context swallow mouse events if activated */
bool consumed_by_frame_context =
handle_press_mousebinding(server, &ctx, button, resize_edges);
handle_press_mousebinding(server, &ctx, button);
if (ctx.surface && !consumed_by_frame_context) {
/* Notify client with pointer focus of button press */
@ -1330,7 +1321,7 @@ handle_cursor_axis(struct server *server, struct cursor_context *ctx,
&& modifiers == mousebind->modifiers
&& mousebind->mouse_event == MOUSE_ACTION_SCROLL) {
handled = true;
actions_run(ctx->view, server, &mousebind->actions, /*resize_edges*/ 0);
actions_run(ctx->view, server, &mousebind->actions, ctx);
}
}

View file

@ -462,7 +462,7 @@ handle_compositor_keybindings(struct keyboard *keyboard,
cur_keybind = NULL;
return true;
}
actions_run(NULL, server, &cur_keybind->actions, 0);
actions_run(NULL, server, &cur_keybind->actions, NULL);
return true;
} else {
return handle_key_release(server, event->keycode);
@ -506,7 +506,7 @@ handle_compositor_keybindings(struct keyboard *keyboard,
*/
key_state_store_pressed_key_as_bound(event->keycode);
if (!cur_keybind->on_release) {
actions_run(NULL, server, &cur_keybind->actions, 0);
actions_run(NULL, server, &cur_keybind->actions, NULL);
}
return true;
}

View file

@ -581,7 +581,7 @@ handle_tablet_tool_button(struct wl_listener *listener, void *data)
&& mousebind->button == button
&& mousebind->context == LAB_SSD_CLIENT) {
actions_run(view, tool->seat->server,
&mousebind->actions, 0);
&mousebind->actions, NULL);
}
}
}

View file

@ -118,7 +118,7 @@ handle_touch_down(struct wl_listener *listener, void *data)
if (mousebind->mouse_event == MOUSE_ACTION_PRESS
&& mousebind->button == BTN_LEFT
&& mousebind->context == LAB_SSD_CLIENT) {
actions_run(view, seat->server, &mousebind->actions, 0);
actions_run(view, seat->server, &mousebind->actions, NULL);
}
}