Scene Menu

This commit is contained in:
Consolatis 2022-02-19 02:05:38 +01:00 committed by Johan Malm
parent f26b61137d
commit f2d40a8d69
8 changed files with 347 additions and 166 deletions

View file

@ -3,19 +3,29 @@
#define __LABWC_MENU_H
#include <wayland-server.h>
#include <wlr/render/wlr_renderer.h>
struct lab_data_buffer;
struct wlr_scene_node;
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 {
struct lab_data_buffer *buffer;
struct wlr_scene_node *text;
struct wlr_scene_node *background;
};
struct menuitem {
struct wl_list actions;
struct menu *submenu;
struct wlr_box box;
struct {
struct wlr_texture *active;
struct wlr_texture *inactive;
int offset_x;
int offset_y;
} texture;
bool selected;
struct menu_scene normal;
struct menu_scene selected;
struct wl_list link; /* menu::menuitems */
};
@ -23,27 +33,62 @@ struct menuitem {
struct menu {
char *id;
char *label;
bool visible;
int item_height;
struct menu *parent;
struct wlr_box box;
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;
};
void menu_init_rootmenu(struct server *server);
void menu_init_windowmenu(struct server *server);
void menu_finish(void);
/* menu_move - move to position (x, y) */
void menu_move(struct menu *menu, int x, int y);
/**
* menu_get_by_id - get menu by id
*
* @id id string defined in menu.xml like "root-menu"
*/
struct menu *menu_get_by_id(const char *id);
/* menu_set_selected - select item at (x, y) */
void menu_set_selected(struct menu *menu, int x, int y);
/**
* menu_open - 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(struct menu *menu, int x, int y);
/* menu_action_selected - select item at (x, y) */
void menu_action_selected(struct server *server, struct menu *menu);
/**
* menu_process_cursor_motion
*
* - handles hover effects
* - may open/close submenus
*/
void menu_process_cursor_motion(struct menu *menu, struct wlr_scene_node *node);
/**
* menu_call_actions - call actions associated with a menu entry
*
* If actions are found, server->menu_current will be closed and set to NULL
* Returns true if handled
*/
bool menu_call_actions(struct menu *menu, struct wlr_scene_node *node);
/* menu_close - close menu */
void menu_close(struct menu *menu);
/* menu_reconfigure - reload theme and content */
void menu_reconfigure(struct server *server, struct menu *menu);
void menu_reconfigure(struct server *server);
#endif /* __LABWC_MENU_H */