From c417daa0a075164e1216bc5a6ee9b5cde990dff7 Mon Sep 17 00:00:00 2001 From: finbargiusti Date: Tue, 8 Jul 2025 19:36:19 +0100 Subject: [PATCH] add center flag --- menu.c | 9 ++++++--- menu.h | 10 +++++++++- wayland.c | 17 +++++++++++++---- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/menu.c b/menu.c index 207d71c..b4385a7 100644 --- a/menu.c +++ b/menu.c @@ -85,14 +85,17 @@ static bool parse_color(const char *color, uint32_t *result) { // Parse menu options from command line arguments. void menu_getopts(struct menu *menu, int argc, char *argv[]) { const char *usage = - "Usage: wmenu [-biPv] [-f font] [-l lines] [-o output] [-p prompt]\n" + "Usage: wmenu [-bciPv] [-f font] [-l lines] [-o output] [-p prompt]\n" "\t[-N color] [-n color] [-M color] [-m color] [-S color] [-s color]\n"; int opt; - while ((opt = getopt(argc, argv, "bhiPvf:l:o:p:N:n:M:m:S:s:")) != -1) { + while ((opt = getopt(argc, argv, "bchiPvf:l:o:p:N:n:M:m:S:s:")) != -1) { switch (opt) { case 'b': - menu->bottom = true; + menu->position = POSITION_BOTTOM; + break; + case 'c': + menu->position = POSITION_CENTER; break; case 'i': menu->strncmp = strncasecmp; diff --git a/menu.h b/menu.h index fdd9ad2..d1691a0 100644 --- a/menu.h +++ b/menu.h @@ -27,10 +27,18 @@ struct page { struct page *next; // next page }; +enum e_position { + POSITION_TOP, + POSITION_BOTTOM, + POSITION_CENTER, +}; + +typedef enum e_position POSITION; + // Menu state. struct menu { // Whether the menu appears at the bottom of the screen - bool bottom; + POSITION position; // The function used to match menu items int (*strncmp)(const char *, const char *, size_t); // Whether the input is a password diff --git a/wayland.c b/wayland.c index 823ced1..5db52f4 100644 --- a/wayland.c +++ b/wayland.c @@ -448,10 +448,19 @@ int menu_run(struct menu *menu) { uint32_t anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT; - if (menu->bottom) { - anchor |= ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM; - } else { - anchor |= ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP; + + switch (menu->position) { + + case POSITION_BOTTOM: + anchor |= ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM; + break; + case POSITION_TOP: + anchor |= ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP; + break; + case POSITION_CENTER: + anchor |= ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP | ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM; + // we will handle this in rendering. + break; } zwlr_layer_surface_v1_set_anchor(layer_surface, anchor);