Drop wmenu -x option

This commit is contained in:
adnano 2024-05-02 14:44:09 -04:00
parent e4c4627eeb
commit 6a39269d2e
5 changed files with 4 additions and 61 deletions

View file

@ -27,7 +27,7 @@ See wmenu(1)
To use wmenu with Sway, you can add the following to your configuration file: 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 bindsym $mod+d exec $menu
``` ```

View file

@ -6,7 +6,7 @@ wmenu - dynamic menu for Wayland
# SYNOPSIS # SYNOPSIS
*wmenu* [-biPvx] \ *wmenu* [-biPv] \
[-f _font_] \ [-f _font_] \
[-l _lines_] \ [-l _lines_] \
[-o _output_] \ [-o _output_] \
@ -37,9 +37,6 @@ to those matching the tokens in the input.
*-v* *-v*
prints version information to stdout, then exits. prints version information to stdout, then exits.
*-x*
wmenu will execute the selected item.
*-f* _font_ *-f* _font_
defines the font used. For more information, see defines the font used. For more information, see
https://docs.gtk.org/Pango/type_func.FontDescription.from_string.html https://docs.gtk.org/Pango/type_func.FontDescription.from_string.html

54
menu.c
View file

@ -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"; "\t[-N color] [-n color] [-M color] [-m color] [-S color] [-s color]\n";
int opt; 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) { switch (opt) {
case 'b': case 'b':
menu->bottom = true; menu->bottom = true;
@ -108,9 +108,6 @@ void menu_getopts(struct menu *menu, int argc, char *argv[]) {
case 'v': case 'v':
puts("wmenu " VERSION); puts("wmenu " VERSION);
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
case 'x':
menu->exec = true;
break;
case 'f': case 'f':
menu->font = optarg; menu->font = optarg;
break; 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. // Handle a keypress.
void menu_keypress(struct menu *menu, enum wl_keyboard_key_state key_state, void menu_keypress(struct menu *menu, enum wl_keyboard_key_state key_state,
xkb_keysym_t sym) { xkb_keysym_t sym) {
@ -639,8 +589,6 @@ void menu_keypress(struct menu *menu, enum wl_keyboard_key_state key_state,
puts(menu->input); puts(menu->input);
fflush(stdout); fflush(stdout);
menu->exit = true; menu->exit = true;
} else if (menu->exec) {
menu_exec(menu);
} else { } else {
char *text = menu->sel ? menu->sel->text : menu->input; char *text = menu->sel ? menu->sel->text : menu->input;
puts(text); puts(text);

2
menu.h
View file

@ -56,8 +56,6 @@ struct menu {
int (*strncmp)(const char *, const char *, size_t); int (*strncmp)(const char *, const char *, size_t);
// Whether the input is a password // Whether the input is a password
bool passwd; bool passwd;
// Whether to execute the selected item
bool exec;
// The font used to display the menu // The font used to display the menu
char *font; char *font;
// The number of lines to list items vertically // The number of lines to list items vertically

View file

@ -32,4 +32,4 @@ path() {
fi fi
} }
path | wmenu -x "$@" path | wmenu "$@" | ${SHELL:-"/bin/sh"} &