mew

desc
git clone https://git.awy.one/mew.git
Log | Files | Refs | README | LICENSE

commit f13bb6ebe5215d970d640f9bbc66f19b087ce0d6
parent af6440da8fe6683cf0b873e0a98c293bf02c3447
Author: awy <awy@awy.one>
Date:   Sat, 19 Jul 2025 18:46:58 +0300

password patch

Diffstat:
Mmew.1 | 5++++-
Mmew.c | 41+++++++++++++++++++++++++++--------------
2 files changed, 31 insertions(+), 15 deletions(-)

diff --git a/mew.1 b/mew.1 @@ -3,7 +3,7 @@ mew \- menu for wayland .SH SYNOPSIS .B mew -.RB [ \-beiv ] +.RB [ \-beivP ] .RB [ \-l .IR lines ] .RB [ \-o @@ -46,6 +46,9 @@ passing focus to the application ran. .B \-i matches menu items case insensitively. .TP +.B \-P +mew will not directly display the keyboard input, but instead replace it with dots. All data from stdin will be ignored. +.TP .BI \-l " lines" lists item vertically, with the given number of lines. .TP diff --git a/mew.c b/mew.c @@ -51,7 +51,7 @@ static struct { static char text[BUFSIZ] = ""; static int bh, mw, mh; -static int inputw = 0, promptw; +static int inputw = 0, promptw, passwd = 0; static int32_t scale = 1; static int lrpad; /* sum of left and right padding */ static size_t cursor; @@ -76,7 +76,7 @@ static Drwl *drw; static BufPool pool; static struct wl_callback *frame_callback; /* default output supplied by compositor */ -static struct wl_output *output = NULL; +static struct wl_output *output = NULL; #include "config.h" @@ -280,6 +280,7 @@ drawmenu(void) unsigned int curpos; struct item *item; int x = 0, y = 0, w; + char *censort; DrwBuf *buf; errno = 0; @@ -297,7 +298,12 @@ drawmenu(void) /* draw input field */ w = (lines > 0 || !matches) ? mw - x : inputw; drwl_setscheme(drw, colors[SchemeNorm]); - drwl_text(drw, x, 0, w, bh, lrpad / 2, text, 0); + if (passwd) { + censort = calloc(1, sizeof(text)); + memset(censort, '*', strlen(text)); + drwl_text(drw, x, 0, w, bh, lrpad / 2, censort, 0); + free(censort); + } else drwl_text(drw, x, 0, w, bh, lrpad / 2, text, 0); curpos = TEXTW(text) - TEXTW(&text[cursor]); if ((curpos += lrpad / 2 - 1) < w) { @@ -685,7 +691,7 @@ keyboard_handle_keymap(void *data, struct wl_keyboard *wl_keyboard, map_shm = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0); if (map_shm == MAP_FAILED) die("mmap:"); - + kbd.xkb_keymap = xkb_keymap_new_from_string(kbd.xkb_context, map_shm, XKB_KEYMAP_FORMAT_TEXT_V1, XKB_KEYMAP_COMPILE_NO_FLAGS); munmap(map_shm, size); @@ -723,7 +729,7 @@ keyboard_handle_key(void *data, struct wl_keyboard *wl_keyboard, kbd.repeat.sym = sym; spec.it_value.tv_sec = kbd.repeat.delay / 1000; spec.it_value.tv_nsec = (kbd.repeat.delay % 1000) * 1000000l; - } + } timerfd_settime(kbd.repeat.timer, 0, &spec, NULL); } @@ -800,7 +806,7 @@ static const struct zwlr_layer_surface_v1_listener layer_surface_listener = { .closed = layer_surface_handle_closed, }; -static void +static void surface_handle_preferred_scale(void *data, struct wl_surface *wl_surface, int32_t factor) { @@ -907,6 +913,10 @@ readstdin(void) char *line = NULL; size_t i, itemsiz = 0, linesiz = 0; ssize_t len; + if(passwd){ + inputw = lines = 0; + return; + } /* read each line from stdin and add it to the item list */ for (i = 0; (len = getline(&line, &linesiz, stdin)) != -1; i++) { @@ -931,13 +941,13 @@ readstdin(void) static void run(void) { - struct pollfd pfds[] = { + struct pollfd pfds[] = { { wl_display_get_fd(display), POLLIN }, { kbd.repeat.timer, POLLIN }, - }; + }; running = 1; - while (running) { + while (running) { wl_display_flush(display); if (poll(pfds, LENGTH(pfds), -1) < 0) @@ -962,7 +972,7 @@ setup(void) wl_registry_add_listener(registry, &registry_listener, NULL); wl_display_roundtrip(display); wl_display_roundtrip(display); /* output & seat listeners */ - + if (!compositor) die("wl_compositor not available"); if (!shm) @@ -990,7 +1000,7 @@ setup(void) layer_surface = zwlr_layer_shell_v1_get_layer_surface(layer_shell, surface, output, ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY, "mew"); zwlr_layer_surface_v1_set_size(layer_surface, 0, mh); - zwlr_layer_surface_v1_set_anchor(layer_surface, + zwlr_layer_surface_v1_set_anchor(layer_surface, (top ? ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP : ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM ) | ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT); zwlr_layer_surface_v1_set_exclusive_zone(layer_surface, -1); @@ -1003,7 +1013,7 @@ setup(void) static void usage(void) { - die("usage: mew [-beiv] [-l lines] [-p prompt] [-f font] [-o output]\n" + die("usage: mew [-beivP] [-l lines] [-p prompt] [-f font] [-o output]\n" " [-nb color] [-nf color] [-sb color] [-sf color]"); } @@ -1021,10 +1031,12 @@ main(int argc, char *argv[]) top = 0; else if (!strcmp(argv[i], "-e")) submit = exec_cmd; - else if (!strcmp(argv[i], "-i")) { + else if (!strcmp(argv[i], "-i")) { fstrncmp = strncasecmp; fstrstr = cistrstr; - } else if (i + 1 == argc) + } else if (!strcmp(argv[i], "-P")) /* is the input a password */ + passwd = 1; + else if (i + 1 == argc) usage(); else if (!strcmp(argv[i], "-l")) lines = atoi(argv[++i]); @@ -1057,3 +1069,4 @@ main(int argc, char *argv[]) return EXIT_SUCCESS; } +