aboutsummaryrefslogtreecommitdiff
path: root/menu.h
diff options
context:
space:
mode:
authoradnano <me@adnano.co>2024-02-27 11:23:12 -0500
committeradnano <me@adnano.co>2024-02-27 11:23:12 -0500
commite8782db9c840e42827dafa4ec1ca9849f91b9b59 (patch)
tree0a911c8c81ee7459508633e000beb352e6df2d5a /menu.h
parent1104e8e51b366e7804b94365f8d6a84752693538 (diff)
downloadwmenu-e8782db9c840e42827dafa4ec1ca9849f91b9b59.tar.gz
Move menu and rendering logic into separate files
Diffstat (limited to 'menu.h')
-rw-r--r--menu.h102
1 files changed, 102 insertions, 0 deletions
diff --git a/menu.h b/menu.h
new file mode 100644
index 0000000..334b628
--- /dev/null
+++ b/menu.h
@@ -0,0 +1,102 @@
+#ifndef WMENU_MENU_H
+#define WMENU_MENU_H
+
+#include <xkbcommon/xkbcommon.h>
+
+#include "pool-buffer.h"
+
+// A menu item.
+struct item {
+ char *text;
+ int width;
+ struct item *next; // traverses all items
+ struct item *prev_match; // previous matching item
+ struct item *next_match; // next matching item
+ struct page *page; // the page holding this item
+};
+
+// A page of menu items.
+struct page {
+ struct item *first; // first item in the page
+ struct item *last; // last item in the page
+ struct page *prev; // previous page
+ struct page *next; // next page
+};
+
+// A Wayland output.
+struct output {
+ struct menu *menu;
+ struct wl_output *output;
+ int32_t scale;
+};
+
+// Keyboard state.
+struct keyboard {
+ struct menu *menu;
+
+ struct xkb_context *xkb_context;
+ struct xkb_state *xkb_state;
+
+ int repeat_timer;
+ int repeat_delay;
+ int repeat_period;
+ enum wl_keyboard_key_state repeat_key_state;
+ xkb_keysym_t repeat_sym;
+};
+
+// Menu state.
+struct menu {
+ struct wl_compositor *compositor;
+ struct wl_shm *shm;
+ struct wl_seat *seat;
+ struct wl_data_device_manager *data_device_manager;
+ struct zwlr_layer_shell_v1 *layer_shell;
+
+ struct wl_display *display;
+ struct wl_surface *surface;
+ struct wl_data_offer *offer;
+
+ struct keyboard *keyboard;
+ struct output *output;
+ char *output_name;
+
+ struct pool_buffer buffers[2];
+ struct pool_buffer *current;
+
+ int width;
+ int height;
+ int line_height;
+ int padding;
+ int inputw;
+ int promptw;
+ int left_arrow;
+ int right_arrow;
+
+ bool bottom;
+ int (*strncmp)(const char *, const char *, size_t);
+ char *font;
+ int lines;
+ char *prompt;
+ uint32_t background, foreground;
+ uint32_t promptbg, promptfg;
+ uint32_t selectionbg, selectionfg;
+
+ char input[BUFSIZ];
+ size_t cursor;
+
+ struct item *items; // list of all items
+ struct item *matches; // list of matching items
+ struct item *matches_end; // last matching item
+ struct item *sel; // selected item
+ struct page *pages; // list of pages
+
+ bool exit;
+ bool failure;
+};
+
+void menu_init(struct menu *menu, int argc, char *argv[]);
+void read_menu_items(struct menu *menu);
+void menu_keypress(struct menu *menu, enum wl_keyboard_key_state key_state,
+ xkb_keysym_t sym);
+
+#endif