| 
									
										
										
										
											2024-02-27 11:23:12 -05:00
										 |  |  | #ifndef WMENU_MENU_H
 | 
					
						
							|  |  |  | #define WMENU_MENU_H
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-02 18:45:49 -04:00
										 |  |  | #include <stdbool.h>
 | 
					
						
							|  |  |  | #include <sys/types.h>
 | 
					
						
							| 
									
										
										
										
											2024-02-27 11:23:12 -05:00
										 |  |  | #include <xkbcommon/xkbcommon.h>
 | 
					
						
							| 
									
										
										
										
											2024-05-02 18:45:49 -04:00
										 |  |  | #include <wayland-client.h>
 | 
					
						
							| 
									
										
										
										
											2024-02-27 11:23:12 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | // 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
 | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Menu state.
 | 
					
						
							|  |  |  | struct menu { | 
					
						
							| 
									
										
										
										
											2024-03-02 11:31:13 -05:00
										 |  |  | 	// Whether the menu appears at the bottom of the screen
 | 
					
						
							|  |  |  | 	bool bottom; | 
					
						
							|  |  |  | 	// The function used to match menu items
 | 
					
						
							|  |  |  | 	int (*strncmp)(const char *, const char *, size_t); | 
					
						
							| 
									
										
										
										
											2024-03-10 18:00:48 +03:00
										 |  |  | 	// Whether the input is a password
 | 
					
						
							|  |  |  | 	bool passwd; | 
					
						
							| 
									
										
										
										
											2024-03-02 11:31:13 -05:00
										 |  |  | 	// The font used to display the menu
 | 
					
						
							|  |  |  | 	char *font; | 
					
						
							|  |  |  | 	// The number of lines to list items vertically
 | 
					
						
							|  |  |  | 	int lines; | 
					
						
							|  |  |  | 	// The name of the output to display on
 | 
					
						
							|  |  |  | 	char *output_name; | 
					
						
							|  |  |  | 	// The prompt displayed to the left of the input field
 | 
					
						
							|  |  |  | 	char *prompt; | 
					
						
							|  |  |  | 	// Normal colors
 | 
					
						
							|  |  |  | 	uint32_t normalbg, normalfg; | 
					
						
							|  |  |  | 	// Prompt colors
 | 
					
						
							|  |  |  | 	uint32_t promptbg, promptfg; | 
					
						
							|  |  |  | 	// Selection colors
 | 
					
						
							|  |  |  | 	uint32_t selectionbg, selectionfg; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-02 17:03:07 -04:00
										 |  |  | 	struct wl_context *context; | 
					
						
							| 
									
										
										
										
											2024-02-27 11:23:12 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	int width; | 
					
						
							|  |  |  | 	int height; | 
					
						
							|  |  |  | 	int line_height; | 
					
						
							|  |  |  | 	int padding; | 
					
						
							|  |  |  | 	int inputw; | 
					
						
							|  |  |  | 	int promptw; | 
					
						
							|  |  |  | 	int left_arrow; | 
					
						
							|  |  |  | 	int right_arrow; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	char input[BUFSIZ]; | 
					
						
							|  |  |  | 	size_t cursor; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	struct item *items;       // list of all items
 | 
					
						
							| 
									
										
										
										
											2024-05-02 17:03:07 -04:00
										 |  |  | 	struct item *lastitem;    // last item in the list
 | 
					
						
							| 
									
										
										
										
											2024-02-27 11:23:12 -05:00
										 |  |  | 	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
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-02 21:39:54 -04:00
										 |  |  | 	void (*callback)(struct menu *menu); | 
					
						
							| 
									
										
										
										
											2024-02-27 11:23:12 -05:00
										 |  |  | 	bool exit; | 
					
						
							|  |  |  | 	bool failure; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-02 11:31:13 -05:00
										 |  |  | struct menu *menu_create(); | 
					
						
							|  |  |  | void menu_getopts(struct menu *menu, int argc, char *argv[]); | 
					
						
							| 
									
										
										
										
											2024-05-02 17:03:07 -04:00
										 |  |  | void menu_add_item(struct menu *menu, char *text); | 
					
						
							| 
									
										
										
										
											2024-05-02 18:45:49 -04:00
										 |  |  | void menu_render_items(struct menu *menu); | 
					
						
							| 
									
										
										
										
											2024-05-02 17:03:07 -04:00
										 |  |  | void menu_paste(struct menu *menu, const char *text, ssize_t len); | 
					
						
							| 
									
										
										
										
											2024-02-27 11:23:12 -05:00
										 |  |  | void menu_keypress(struct menu *menu, enum wl_keyboard_key_state key_state, | 
					
						
							|  |  |  | 		xkb_keysym_t sym); | 
					
						
							| 
									
										
										
										
											2024-03-02 11:31:13 -05:00
										 |  |  | void menu_destroy(struct menu *menu); | 
					
						
							| 
									
										
										
										
											2024-02-27 11:23:12 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | #endif
 |