From 6a39269d2e73273de324ed156eba71e5bdcd9602 Mon Sep 17 00:00:00 2001 From: adnano Date: Thu, 2 May 2024 14:44:09 -0400 Subject: Drop wmenu -x option --- README.md | 2 +- docs/wmenu.1.scd | 5 +---- menu.c | 54 +----------------------------------------------------- menu.h | 2 -- wmenu_run | 2 +- 5 files changed, 4 insertions(+), 61 deletions(-) diff --git a/README.md b/README.md index 099f036..d0e62c4 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ See wmenu(1) To use wmenu with Sway, you can add the following to your configuration file: ``` -set $menu wmenu_run +set $menu dmenu_path | wmenu | xargs swaymsg exec -- bindsym $mod+d exec $menu ``` diff --git a/docs/wmenu.1.scd b/docs/wmenu.1.scd index cfcbd84..407da9f 100644 --- a/docs/wmenu.1.scd +++ b/docs/wmenu.1.scd @@ -6,7 +6,7 @@ wmenu - dynamic menu for Wayland # SYNOPSIS -*wmenu* [-biPvx] \ +*wmenu* [-biPv] \ [-f _font_] \ [-l _lines_] \ [-o _output_] \ @@ -37,9 +37,6 @@ to those matching the tokens in the input. *-v* prints version information to stdout, then exits. -*-x* - wmenu will execute the selected item. - *-f* _font_ defines the font used. For more information, see https://docs.gtk.org/Pango/type_func.FontDescription.from_string.html diff --git a/menu.c b/menu.c index 549b730..72d903f 100644 --- a/menu.c +++ b/menu.c @@ -94,7 +94,7 @@ void menu_getopts(struct menu *menu, int argc, char *argv[]) { "\t[-N color] [-n color] [-M color] [-m color] [-S color] [-s color]\n"; int opt; - while ((opt = getopt(argc, argv, "bhiPvxf:l:o:p:N:n:M:m:S:s:")) != -1) { + while ((opt = getopt(argc, argv, "bhiPvf:l:o:p:N:n:M:m:S:s:")) != -1) { switch (opt) { case 'b': menu->bottom = true; @@ -108,9 +108,6 @@ void menu_getopts(struct menu *menu, int argc, char *argv[]) { case 'v': puts("wmenu " VERSION); exit(EXIT_SUCCESS); - case 'x': - menu->exec = true; - break; case 'f': menu->font = optarg; break; @@ -413,53 +410,6 @@ static void movewordedge(struct menu *menu, int dir) { } } -// Information needed to execute an item. -struct executable { - struct menu *menu; - char *name; -}; - -// Executes an item with an activation token. -static void execute(struct executable *exe, const char *token) { - menu_destroy(exe->menu); - - setenv("XDG_ACTIVATION_TOKEN", token, true); - execlp(exe->name, exe->name, NULL); - - // Handle execution failure - fprintf(stderr, "Failed to execute selection: %s\n", strerror(errno)); - free(exe->name); - free(exe); - exit(EXIT_FAILURE); -} - -static void activation_token_done(void *data, struct xdg_activation_token_v1 *activation_token, - const char *token) { - struct executable *exe = data; - xdg_activation_token_v1_destroy(activation_token); - execute(exe, token); -} - -static const struct xdg_activation_token_v1_listener activation_token_listener = { - .done = activation_token_done, -}; - -// Executes the selected item. -static void menu_exec(struct menu *menu) { - if (!menu->sel) { - return; - } - - struct executable *exe = calloc(1, sizeof(struct executable)); - exe->menu = menu; - exe->name = strdup(menu->sel->text); - - struct xdg_activation_token_v1 *activation_token = xdg_activation_v1_get_activation_token(menu->activation); - xdg_activation_token_v1_set_surface(activation_token, menu->surface); - xdg_activation_token_v1_add_listener(activation_token, &activation_token_listener, exe); - xdg_activation_token_v1_commit(activation_token); -} - // Handle a keypress. void menu_keypress(struct menu *menu, enum wl_keyboard_key_state key_state, xkb_keysym_t sym) { @@ -639,8 +589,6 @@ void menu_keypress(struct menu *menu, enum wl_keyboard_key_state key_state, puts(menu->input); fflush(stdout); menu->exit = true; - } else if (menu->exec) { - menu_exec(menu); } else { char *text = menu->sel ? menu->sel->text : menu->input; puts(text); diff --git a/menu.h b/menu.h index 762dfc8..0143405 100644 --- a/menu.h +++ b/menu.h @@ -56,8 +56,6 @@ struct menu { int (*strncmp)(const char *, const char *, size_t); // Whether the input is a password bool passwd; - // Whether to execute the selected item - bool exec; // The font used to display the menu char *font; // The number of lines to list items vertically diff --git a/wmenu_run b/wmenu_run index afe96e2..b243b38 100755 --- a/wmenu_run +++ b/wmenu_run @@ -32,4 +32,4 @@ path() { fi } -path | wmenu -x "$@" +path | wmenu "$@" | ${SHELL:-"/bin/sh"} & -- cgit v1.2.3