File: menu.h

package info (click to toggle)
labwc 0.9.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,980 kB
  • sloc: ansic: 34,416; perl: 5,836; xml: 875; sh: 162; python: 131; makefile: 12
file content (116 lines) | stat: -rw-r--r-- 2,866 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/* 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 *text;
	char *icon_name;
	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 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;
	char *icon_name;
	char *execute;
	struct menu *parent;
	struct menu_pipe_context *pipe_ctx;

	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_child;
	bool align_left;
	bool has_icons;

	/* 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 will 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_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 will 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);

#endif /* LABWC_MENU_H */