2021-11-02 18:31:19 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2023-05-13 16:10:33 +03:00
|
|
|
#ifndef LABWC_MENU_H
|
|
|
|
|
#define LABWC_MENU_H
|
2020-10-19 22:14:17 +01:00
|
|
|
|
|
|
|
|
#include <wayland-server.h>
|
2022-02-19 02:05:38 +01:00
|
|
|
|
2022-06-09 17:10:36 +02:00
|
|
|
/* forward declare arguments */
|
|
|
|
|
struct view;
|
|
|
|
|
struct server;
|
|
|
|
|
struct wl_list;
|
|
|
|
|
struct wlr_scene_tree;
|
2022-02-19 02:05:38 +01:00
|
|
|
struct wlr_scene_node;
|
2022-06-12 21:22:01 +02:00
|
|
|
struct scaled_font_buffer;
|
2022-02-19 02:05:38 +01:00
|
|
|
|
|
|
|
|
enum menu_align {
|
|
|
|
|
LAB_MENU_OPEN_AUTO = 0,
|
|
|
|
|
LAB_MENU_OPEN_LEFT = 1 << 0,
|
|
|
|
|
LAB_MENU_OPEN_RIGHT = 1 << 1,
|
|
|
|
|
LAB_MENU_OPEN_TOP = 1 << 2,
|
|
|
|
|
LAB_MENU_OPEN_BOTTOM = 1 << 3,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct menu_scene {
|
2022-06-05 14:42:06 +02:00
|
|
|
struct wlr_scene_tree *tree;
|
2022-02-19 02:05:38 +01:00
|
|
|
struct wlr_scene_node *text;
|
|
|
|
|
struct wlr_scene_node *background;
|
2022-06-12 21:22:01 +02:00
|
|
|
struct scaled_font_buffer *buffer;
|
2022-02-19 02:05:38 +01:00
|
|
|
};
|
2020-10-19 22:14:17 +01:00
|
|
|
|
2024-05-09 21:20:15 +01:00
|
|
|
enum menuitem_type {
|
|
|
|
|
LAB_MENU_ITEM = 0,
|
|
|
|
|
LAB_MENU_SEPARATOR_LINE,
|
|
|
|
|
LAB_MENU_TITLE,
|
|
|
|
|
};
|
|
|
|
|
|
2020-10-19 22:14:17 +01:00
|
|
|
struct menuitem {
|
2022-01-05 09:11:24 +01:00
|
|
|
struct wl_list actions;
|
2023-10-31 21:36:45 +00:00
|
|
|
char *execute;
|
|
|
|
|
char *id; /* needed for pipemenus */
|
2022-03-03 04:33:33 +01:00
|
|
|
struct menu *parent;
|
2021-11-02 18:31:19 +00:00
|
|
|
struct menu *submenu;
|
2022-06-22 21:07:25 +01:00
|
|
|
bool selectable;
|
2024-05-09 21:20:15 +01:00
|
|
|
enum menuitem_type type;
|
2022-06-22 21:07:25 +01:00
|
|
|
int height;
|
2022-12-05 14:38:16 +01:00
|
|
|
int native_width;
|
2022-06-05 14:42:06 +02:00
|
|
|
struct wlr_scene_tree *tree;
|
2022-02-19 02:05:38 +01:00
|
|
|
struct menu_scene normal;
|
|
|
|
|
struct menu_scene selected;
|
2024-08-20 18:09:17 +02:00
|
|
|
struct menu_pipe_context *pipe_ctx;
|
2024-09-17 06:52:10 -05:00
|
|
|
struct view *client_list_view; /* used by internal client-list */
|
2023-10-02 19:47:59 +01:00
|
|
|
struct wl_list link; /* menu.menuitems */
|
2020-10-19 22:14:17 +01:00
|
|
|
};
|
|
|
|
|
|
2021-11-02 18:31:19 +00:00
|
|
|
/* This could be the root-menu or a submenu */
|
2020-10-19 22:14:17 +01:00
|
|
|
struct menu {
|
2021-11-02 18:31:19 +00:00
|
|
|
char *id;
|
|
|
|
|
char *label;
|
2021-11-08 17:20:37 +00:00
|
|
|
struct menu *parent;
|
2023-10-31 21:36:45 +00:00
|
|
|
|
2022-02-19 02:05:38 +01:00
|
|
|
struct {
|
|
|
|
|
int width;
|
|
|
|
|
int height;
|
|
|
|
|
} size;
|
2020-10-19 22:14:17 +01:00
|
|
|
struct wl_list menuitems;
|
2021-11-02 18:31:19 +00:00
|
|
|
struct server *server;
|
2022-02-19 02:05:38 +01:00
|
|
|
struct {
|
|
|
|
|
struct menu *menu;
|
|
|
|
|
struct menuitem *item;
|
|
|
|
|
} selection;
|
|
|
|
|
struct wlr_scene_tree *scene_tree;
|
2023-10-31 21:36:45 +00:00
|
|
|
bool is_pipemenu;
|
|
|
|
|
enum menu_align align;
|
2022-06-09 17:10:36 +02:00
|
|
|
|
|
|
|
|
/* Used to match a window-menu to the view that triggered it. */
|
|
|
|
|
struct view *triggered_by_view; /* may be NULL */
|
2023-10-09 20:59:04 +01:00
|
|
|
struct wl_list link; /* server.menus */
|
2020-10-19 22:14:17 +01:00
|
|
|
};
|
|
|
|
|
|
2023-08-30 11:20:46 +02:00
|
|
|
/* For keyboard support */
|
|
|
|
|
void menu_item_select_next(struct server *server);
|
|
|
|
|
void menu_item_select_previous(struct server *server);
|
|
|
|
|
void menu_submenu_enter(struct server *server);
|
|
|
|
|
void menu_submenu_leave(struct server *server);
|
|
|
|
|
bool menu_call_selected_actions(struct server *server);
|
|
|
|
|
|
2022-12-06 11:54:55 +01:00
|
|
|
void menu_init(struct server *server);
|
2023-10-09 20:59:04 +01:00
|
|
|
void menu_finish(struct server *server);
|
2024-10-23 20:47:50 +01:00
|
|
|
void menu_on_view_destroy(struct view *view);
|
2020-10-19 22:14:17 +01:00
|
|
|
|
2022-02-19 02:05:38 +01:00
|
|
|
/**
|
|
|
|
|
* menu_get_by_id - get menu by id
|
|
|
|
|
*
|
|
|
|
|
* @id id string defined in menu.xml like "root-menu"
|
|
|
|
|
*/
|
2023-10-09 20:59:04 +01:00
|
|
|
struct menu *menu_get_by_id(struct server *server, const char *id);
|
2022-02-19 02:05:38 +01:00
|
|
|
|
|
|
|
|
/**
|
2023-10-31 21:08:04 +00:00
|
|
|
* menu_open_root - open menu on position (x, y)
|
2022-02-19 02:05:38 +01:00
|
|
|
*
|
|
|
|
|
* This function will close server->menu_current, open the
|
|
|
|
|
* new menu and assign @menu to server->menu_current.
|
|
|
|
|
*
|
|
|
|
|
* Additionally, server->input_mode wil be set to LAB_INPUT_STATE_MENU.
|
|
|
|
|
*/
|
2023-10-31 21:08:04 +00:00
|
|
|
void menu_open_root(struct menu *menu, int x, int y);
|
2022-02-19 02:05:38 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* menu_process_cursor_motion
|
|
|
|
|
*
|
|
|
|
|
* - handles hover effects
|
|
|
|
|
* - may open/close submenus
|
|
|
|
|
*/
|
2022-03-03 04:33:33 +01:00
|
|
|
void menu_process_cursor_motion(struct wlr_scene_node *node);
|
2020-10-19 22:14:17 +01:00
|
|
|
|
2022-02-19 02:05:38 +01:00
|
|
|
/**
|
2022-03-03 04:33:33 +01:00
|
|
|
* menu_call_actions - call actions associated with a menu node
|
|
|
|
|
*
|
|
|
|
|
* If menuitem connected to @node does not just open a submenu:
|
|
|
|
|
* - associated actions will be called
|
|
|
|
|
* - server->menu_current will be closed
|
|
|
|
|
* - server->menu_current will be set to NULL
|
2022-02-19 02:05:38 +01:00
|
|
|
*
|
2022-03-03 04:33:33 +01:00
|
|
|
* Returns true if actions have actually been executed
|
2022-02-19 02:05:38 +01:00
|
|
|
*/
|
2022-03-03 04:33:33 +01:00
|
|
|
bool menu_call_actions(struct wlr_scene_node *node);
|
2020-10-19 22:14:17 +01:00
|
|
|
|
2022-06-09 17:10:36 +02:00
|
|
|
/**
|
|
|
|
|
* menu_close_root- close root menu
|
|
|
|
|
*
|
|
|
|
|
* This function will close server->menu_current and set it to NULL.
|
|
|
|
|
* Asserts that server->input_mode is set to LAB_INPUT_STATE_MENU.
|
|
|
|
|
*
|
|
|
|
|
* Additionally, server->input_mode wil be set to LAB_INPUT_STATE_PASSTHROUGH.
|
|
|
|
|
*/
|
|
|
|
|
void menu_close_root(struct server *server);
|
2020-10-19 22:14:17 +01:00
|
|
|
|
2021-02-19 23:05:14 +00:00
|
|
|
/* menu_reconfigure - reload theme and content */
|
2022-02-19 02:05:38 +01:00
|
|
|
void menu_reconfigure(struct server *server);
|
2021-02-19 23:05:14 +00:00
|
|
|
|
2024-09-17 06:52:10 -05:00
|
|
|
void update_client_list_combined_menu(struct server *server);
|
2024-09-18 19:01:28 -05:00
|
|
|
void update_client_send_to_menu(struct server *server);
|
2024-09-17 06:52:10 -05:00
|
|
|
|
2023-05-13 16:10:33 +03:00
|
|
|
#endif /* LABWC_MENU_H */
|