mirror of
https://github.com/labwc/labwc.git
synced 2025-11-02 09:01:47 -05:00
This commit delegates the calculation for menu position into wlroots utilities for xdg_positioner. Notable functional changes are: - Slide the menu to fit in the output when it's opened out of the output (e.g. top-left window menu is opened when the window is overflowing to the left), rather than not updating the menu at all. - The horizontal alignment of menus is now determined based on the size of each (sub)menu alone rather than the total width of entire menu tree. This means submenus can now overlap with is parents, but this is no longer a problem since we recently added support for menu borders. - Fixed that pipemenus always follow the alignment of its parent even when it overflows from the output.
129 lines
3.3 KiB
C
129 lines
3.3 KiB
C
/* SPDX-License-Identifier: GPL-2.0-only */
|
|
#ifndef LABWC_MENU_H
|
|
#define LABWC_MENU_H
|
|
|
|
#include <wayland-server.h>
|
|
|
|
/* forward declare arguments */
|
|
struct view;
|
|
struct server;
|
|
struct wl_list;
|
|
struct wlr_scene_tree;
|
|
struct wlr_scene_node;
|
|
struct scaled_font_buffer;
|
|
|
|
enum menuitem_type {
|
|
LAB_MENU_ITEM = 0,
|
|
LAB_MENU_SEPARATOR_LINE,
|
|
LAB_MENU_TITLE,
|
|
};
|
|
|
|
struct menuitem {
|
|
struct wl_list actions;
|
|
char *execute;
|
|
char *id; /* needed for pipemenus */
|
|
char *text;
|
|
const char *arrow;
|
|
struct menu *parent;
|
|
struct menu *submenu;
|
|
bool selectable;
|
|
enum menuitem_type type;
|
|
int native_width;
|
|
struct wlr_scene_tree *tree;
|
|
struct wlr_scene_tree *normal_tree;
|
|
struct wlr_scene_tree *selected_tree;
|
|
struct menu_pipe_context *pipe_ctx;
|
|
struct view *client_list_view; /* used by internal client-list */
|
|
struct wl_list link; /* menu.menuitems */
|
|
};
|
|
|
|
/* This could be the root-menu or a submenu */
|
|
struct menu {
|
|
char *id;
|
|
char *label;
|
|
struct menu *parent;
|
|
|
|
struct {
|
|
int width;
|
|
int height;
|
|
} size;
|
|
struct wl_list menuitems;
|
|
struct server *server;
|
|
struct {
|
|
struct menu *menu;
|
|
struct menuitem *item;
|
|
} selection;
|
|
struct wlr_scene_tree *scene_tree;
|
|
bool is_pipemenu;
|
|
bool align_left;
|
|
|
|
/* Used to match a window-menu to the view that triggered it. */
|
|
struct view *triggered_by_view; /* may be NULL */
|
|
struct wl_list link; /* server.menus */
|
|
};
|
|
|
|
/* 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);
|
|
|
|
void menu_init(struct server *server);
|
|
void menu_finish(struct server *server);
|
|
void menu_on_view_destroy(struct view *view);
|
|
|
|
/**
|
|
* menu_get_by_id - get menu by id
|
|
*
|
|
* @id id string defined in menu.xml like "root-menu"
|
|
*/
|
|
struct menu *menu_get_by_id(struct server *server, const char *id);
|
|
|
|
/**
|
|
* menu_open_root - open menu on position (x, y)
|
|
*
|
|
* 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.
|
|
*/
|
|
void menu_open_root(struct menu *menu, int x, int y);
|
|
|
|
/**
|
|
* menu_process_cursor_motion
|
|
*
|
|
* - handles hover effects
|
|
* - may open/close submenus
|
|
*/
|
|
void menu_process_cursor_motion(struct wlr_scene_node *node);
|
|
|
|
/**
|
|
* 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
|
|
*
|
|
* Returns true if actions have actually been executed
|
|
*/
|
|
bool menu_call_actions(struct wlr_scene_node *node);
|
|
|
|
/**
|
|
* 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);
|
|
|
|
/* menu_reconfigure - reload theme and content */
|
|
void menu_reconfigure(struct server *server);
|
|
|
|
void update_client_list_combined_menu(struct server *server);
|
|
void update_client_send_to_menu(struct server *server);
|
|
|
|
#endif /* LABWC_MENU_H */
|