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

@ -7,6 +7,7 @@
struct view;
struct server;
struct cursor_context;
struct action {
struct wl_list link; /*
@ -34,8 +35,16 @@ void action_arg_from_xml_node(struct action *action, const char *nodename, const
bool actions_contain_toggle_keybinds(struct wl_list *action_list);
/**
* actions_run() - Run actions.
* @activator: Target view to apply actions (e.g. Maximize, Focus etc.).
* NULL is allowed, in which case the focused/hovered view is used.
* @ctx: Set for action invocations via mousebindings. Used to get the
* direction of resize or the position of the window menu button for ShowMenu
* action.
*/
void actions_run(struct view *activator, struct server *server,
struct wl_list *actions, uint32_t resize_edges);
struct wl_list *actions, struct cursor_context *ctx);
void action_free(struct action *action);
void action_list_free(struct wl_list *action_list);

View file

@ -129,9 +129,8 @@ struct seat {
struct input_method_relay *input_method_relay;
/**
* pressed view/surface/node will usually be NULL and is only set on
* button press while the mouse is over a view or surface, and reset
* to NULL on button release.
* This is usually zeroed and is only set on button press while the
* mouse is over a view or surface, and zeroed on button release.
* It is used to send cursor motion events to a surface even though
* the cursor has left the surface in the meantime.
*
@ -144,13 +143,7 @@ struct seat {
*
* Both (view && !surface) and (surface && !view) are possible.
*/
struct {
struct view *view;
struct wlr_scene_node *node;
struct wlr_surface *surface;
struct wlr_surface *toplevel;
uint32_t resize_edges;
} pressed;
struct cursor_context pressed;
struct {
bool active;
@ -492,9 +485,7 @@ void seat_focus_surface(struct seat *seat, struct wlr_surface *surface);
void seat_focus_lock_surface(struct seat *seat, struct wlr_surface *surface);
void seat_set_focus_layer(struct seat *seat, struct wlr_layer_surface_v1 *layer);
void seat_set_pressed(struct seat *seat, struct view *view,
struct wlr_scene_node *node, struct wlr_surface *surface,
struct wlr_surface *toplevel, uint32_t resize_edges);
void seat_set_pressed(struct seat *seat, struct cursor_context *ctx);
void seat_reset_pressed(struct seat *seat);
void seat_output_layout_changed(struct seat *seat);

View file

@ -27,6 +27,7 @@ enum ssd_part_type {
LAB_SSD_BUTTON_WINDOW_MENU,
LAB_SSD_BUTTON_SHADE,
LAB_SSD_BUTTON_OMNIPRESENT,
LAB_SSD_BUTTON, /* only for internal use */
LAB_SSD_PART_TITLEBAR,
LAB_SSD_PART_TITLEBAR_CORNER_RIGHT,
LAB_SSD_PART_TITLEBAR_CORNER_LEFT,