labwc/include/action.h
tokyo4j 25f5cdd3a6 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.
2024-09-21 18:07:34 +01:00

52 lines
1.7 KiB
C

/* SPDX-License-Identifier: GPL-2.0-only */
#ifndef LABWC_ACTION_H
#define LABWC_ACTION_H
#include <stdbool.h>
#include <wayland-util.h>
struct view;
struct server;
struct cursor_context;
struct action {
struct wl_list link; /*
* struct keybinding.actions
* struct mousebinding.actions
* struct menuitem.actions
*/
uint32_t type; /* enum action_type */
struct wl_list args; /* struct action_arg.link */
};
struct action *action_create(const char *action_name);
bool action_is_valid(struct action *action);
void action_arg_add_str(struct action *action, const char *key, const char *value);
void action_arg_add_actionlist(struct action *action, const char *key);
void action_arg_add_querylist(struct action *action, const char *key);
struct wl_list *action_get_actionlist(struct action *action, const char *key);
struct wl_list *action_get_querylist(struct action *action, const char *key);
void action_arg_from_xml_node(struct action *action, const char *nodename, const char *content);
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, struct cursor_context *ctx);
void action_free(struct action *action);
void action_list_free(struct wl_list *action_list);
#endif /* LABWC_ACTION_H */