menu.h - wmenu - [fork] efficient dynamic menu for wayland
 (HTM) git clone https://git.drkhsh.at/wmenu.git
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
       menu.h (2480B)
       ---
            1 #ifndef WMENU_MENU_H
            2 #define WMENU_MENU_H
            3 
            4 #include <cairo/cairo.h>
            5 #include <stdbool.h>
            6 #include <sys/types.h>
            7 #include <xkbcommon/xkbcommon.h>
            8 #include <wayland-client.h>
            9 
           10 struct menu;
           11 typedef void (*menu_callback)(struct menu *menu, char *text, bool exit);
           12 
           13 // A menu item.
           14 struct item {
           15         char *text;
           16         int width;
           17         struct item *prev_match; // previous matching item
           18         struct item *next_match; // next matching item
           19         struct page *page;       // the page holding this item
           20 };
           21 
           22 // A page of menu items.
           23 struct page {
           24         struct item *first; // first item in the page
           25         struct item *last;  // last item in the page
           26         struct page *prev;  // previous page
           27         struct page *next;  // next page
           28 };
           29 
           30 // Menu state.
           31 struct menu {
           32         // Whether the menu appears at the bottom of the screen
           33         bool bottom;
           34         // The function used to match menu items
           35         int (*strncmp)(const char *, const char *, size_t);
           36         // Whether the input is a password
           37         bool passwd;
           38         // The font used to display the menu
           39         char *font;
           40         // The number of lines to list items vertically
           41         int lines;
           42         // The name of the output to display on
           43         char *output_name;
           44         // The prompt displayed to the left of the input field
           45         char *prompt;
           46         // Normal colors
           47         uint32_t normalbg, normalfg;
           48         // Prompt colors
           49         uint32_t promptbg, promptfg;
           50         // Selection colors
           51         uint32_t selectionbg, selectionfg;
           52 
           53         struct wl_context *context;
           54 
           55         // 1x1 surface used estimate text sizes with pango
           56         cairo_surface_t *test_surface;
           57         cairo_t *test_cairo;
           58 
           59         int width;
           60         int height;
           61         int customwidth;
           62         int line_height;
           63         int padding;
           64         int inputw;
           65         int promptw;
           66         int left_arrow;
           67         int right_arrow;
           68         bool rendered;
           69 
           70         char input[BUFSIZ];
           71         size_t cursor;
           72 
           73         struct item *items;       // array of all items
           74         size_t item_count;
           75         struct item *matches;     // list of matching items
           76         struct item *matches_end; // last matching item
           77         struct item *sel;         // selected item
           78         struct page *pages;       // list of pages
           79 
           80         menu_callback callback;
           81         bool exit;
           82         bool failure;
           83 };
           84 
           85 struct menu *menu_create(menu_callback callback);
           86 void menu_destroy(struct menu *menu);
           87 void menu_getopts(struct menu *menu, int argc, char *argv[]);
           88 void menu_add_item(struct menu *menu, char *text);
           89 void menu_sort_and_deduplicate(struct menu *menu);
           90 void menu_invalidate(struct menu *menu);
           91 void menu_render_items(struct menu *menu);
           92 void menu_paste(struct menu *menu, const char *text, ssize_t len);
           93 void menu_keypress(struct menu *menu, enum wl_keyboard_key_state key_state,
           94                 xkb_keysym_t sym);
           95 
           96 #endif