From bcbdee21363d9a8fdd2c1741dca74806b8e68976 Mon Sep 17 00:00:00 2001 From: Orestis Floros Date: Wed, 22 May 2024 21:26:34 +0200 Subject: [PATCH] Display help on wayland Additionally, exit with 0 when user asks for help --- i3lock.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/i3lock.c b/i3lock.c index 956f2c1..fc87ad5 100644 --- a/i3lock.c +++ b/i3lock.c @@ -1006,13 +1006,7 @@ int main(int argc, char *argv[]) { {"show-keyboard-layout", no_argument, NULL, 'k'}, {NULL, no_argument, NULL, 0}}; - if ((pw = getpwuid(getuid())) == NULL) - err(EXIT_FAILURE, "getpwuid() failed"); - if ((username = pw->pw_name) == NULL) - errx(EXIT_FAILURE, "pw->pw_name is NULL."); - if (getenv("WAYLAND_DISPLAY") != NULL) - errx(EXIT_FAILURE, "i3lock is a program for X11 and does not work on Wayland. Try https://github.com/swaywm/swaylock instead"); - + int code = EXIT_FAILURE; char *optstring = "hvnbdc:p:ui:teI:fk"; while ((o = getopt_long(argc, argv, optstring, longopts, &longoptind)) != -1) { switch (o) { @@ -1076,12 +1070,25 @@ int main(int argc, char *argv[]) { case 'k': show_keyboard_layout = true; break; + case 'h': + code = EXIT_SUCCESS; + /* fallthrough */ default: - errx(EXIT_FAILURE, "Syntax: i3lock [-v] [-n] [-b] [-d] [-c color] [-u] [-p win|default]" - " [-i image.png] [-t] [-e] [-I timeout] [-f] [-k]"); + errx(code, "Syntax: i3lock [-v] [-n] [-b] [-d] [-c color] [-u] [-p win|default]" + " [-i image.png] [-t] [-e] [-I timeout] [-f] [-k]"); } } + if ((pw = getpwuid(getuid())) == NULL) { + err(EXIT_FAILURE, "getpwuid() failed"); + } + if ((username = pw->pw_name) == NULL) { + errx(EXIT_FAILURE, "pw->pw_name is NULL."); + } + if (getenv("WAYLAND_DISPLAY") != NULL) { + errx(EXIT_FAILURE, "i3lock is a program for X11 and does not work on Wayland. Try https://github.com/swaywm/swaylock instead"); + } + /* We need (relatively) random numbers for highlighting a random part of * the unlock indicator upon keypresses. */ srand(time(NULL));