summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.clang-format11
-rw-r--r--ci/Dockerfile (renamed from travis/Dockerfile)2
-rw-r--r--dpi.c5
-rw-r--r--i3lock.c165
-rwxr-xr-xmeson/meson-dist-script3
-rw-r--r--randr.c6
-rw-r--r--unlock_indicator.c12
-rw-r--r--xcb.c3
8 files changed, 132 insertions, 75 deletions
diff --git a/.clang-format b/.clang-format
index 6e49d83..2b8e0b3 100644
--- a/.clang-format
+++ b/.clang-format
@@ -1,11 +1,12 @@
1BasedOnStyle: google 1AllowShortBlocksOnASingleLine: false
2AllowShortFunctionsOnASingleLine: None
2AllowShortIfStatementsOnASingleLine: false 3AllowShortIfStatementsOnASingleLine: false
3AllowShortLoopsOnASingleLine: false 4AllowShortLoopsOnASingleLine: false
4AllowShortFunctionsOnASingleLine: None
5AllowShortBlocksOnASingleLine: false
6AlwaysBreakBeforeMultilineStrings: false 5AlwaysBreakBeforeMultilineStrings: false
6BasedOnStyle: google
7ColumnLimit: 0
7IndentWidth: 4 8IndentWidth: 4
9InsertBraces: true
8PointerBindsToType: false 10PointerBindsToType: false
9ColumnLimit: 0
10SpaceBeforeParens: ControlStatements
11SortIncludes: false 11SortIncludes: false
12SpaceBeforeParens: ControlStatements
diff --git a/travis/Dockerfile b/ci/Dockerfile
index 9dc8137..17dd297 100644
--- a/travis/Dockerfile
+++ b/ci/Dockerfile
@@ -11,7 +11,7 @@ RUN echo 'APT::Acquire::Retries "5";' > /etc/apt/apt.conf.d/80retry
11# (3608 kB/s)). Hence, let’s stick with httpredir.debian.org (default) for now. 11# (3608 kB/s)). Hence, let’s stick with httpredir.debian.org (default) for now.
12 12
13# Install mk-build-deps (for installing the i3 build dependencies), 13# Install mk-build-deps (for installing the i3 build dependencies),
14# clang and clang-format-9 (for checking formatting and building with clang), 14# clang (for building),
15# lintian (for checking spelling errors), 15# lintian (for checking spelling errors),
16# test suite dependencies (for running tests) 16# test suite dependencies (for running tests)
17RUN apt-get update && \ 17RUN apt-get update && \
diff --git a/dpi.c b/dpi.c
index 3cb08ee..0fdf88a 100644
--- a/dpi.c
+++ b/dpi.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * vim:ts=4:sw=4:expandtab 2 * vim:ts=4:sw=4:expandtab
3 * 3 *
4 * i3 - an improved dynamic tiling window manager 4 * i3 - an improved tiling window manager
5 * © 2009 Michael Stapelberg and contributors (see also: LICENSE) 5 * © 2009 Michael Stapelberg and contributors (see also: LICENSE)
6 * 6 *
7 */ 7 */
@@ -103,7 +103,8 @@ int logical_px(const int logical) {
103 * systems to 96 dpi in order to get the behavior they expect/are used to, 103 * systems to 96 dpi in order to get the behavior they expect/are used to,
104 * but since we can easily detect this case in code, let’s do it for them. 104 * but since we can easily detect this case in code, let’s do it for them.
105 */ 105 */
106 if ((dpi / 96.0) < 1.25) 106 if ((dpi / 96.0) < 1.25) {
107 return logical; 107 return logical;
108 }
108 return ceil((dpi / 96.0) * logical); 109 return ceil((dpi / 96.0) * logical);
109} 110}
diff --git a/i3lock.c b/i3lock.c
index 3f8eb77..44a30f2 100644
--- a/i3lock.c
+++ b/i3lock.c
@@ -236,12 +236,13 @@ static void clear_password_memory(void) {
236 /* A volatile pointer to the password buffer to prevent the compiler from 236 /* A volatile pointer to the password buffer to prevent the compiler from
237 * optimizing this out. */ 237 * optimizing this out. */
238 volatile char *vpassword = password; 238 volatile char *vpassword = password;
239 for (size_t c = 0; c < sizeof(password); c++) 239 for (size_t c = 0; c < sizeof(password); c++) {
240 /* We store a non-random pattern which consists of the (irrelevant) 240 /* We store a non-random pattern which consists of the (irrelevant)
241 * index plus (!) the value of the beep variable. This prevents the 241 * index plus (!) the value of the beep variable. This prevents the
242 * compiler from optimizing the calls away, since the value of 'beep' 242 * compiler from optimizing the calls away, since the value of 'beep'
243 * is not known at compile-time. */ 243 * is not known at compile-time. */
244 vpassword[c] = c + (int)beep; 244 vpassword[c] = c + (int)beep;
245 }
245#endif 246#endif
246} 247}
247 248
@@ -253,7 +254,7 @@ ev_timer *start_timer(ev_timer *timer_obj, ev_tstamp timeout, ev_callback_t call
253 } else { 254 } else {
254 /* When there is no memory, we just don’t have a timeout. We cannot 255 /* When there is no memory, we just don’t have a timeout. We cannot
255 * exit() here, since that would effectively unlock the screen. */ 256 * exit() here, since that would effectively unlock the screen. */
256 timer_obj = calloc(sizeof(struct ev_timer), 1); 257 timer_obj = calloc(1, sizeof(struct ev_timer));
257 if (timer_obj) { 258 if (timer_obj) {
258 ev_timer_init(timer_obj, callback, timeout, 0.); 259 ev_timer_init(timer_obj, callback, timeout, 0.);
259 ev_timer_start(main_loop, timer_obj); 260 ev_timer_start(main_loop, timer_obj);
@@ -332,8 +333,9 @@ static void input_done(void) {
332#ifdef __OpenBSD__ 333#ifdef __OpenBSD__
333 struct passwd *pw; 334 struct passwd *pw;
334 335
335 if (!(pw = getpwuid(getuid()))) 336 if (!(pw = getpwuid(getuid()))) {
336 errx(1, "unknown uid %u.", getuid()); 337 errx(1, "unknown uid %u.", getuid());
338 }
337 339
338 if (auth_userokay(pw->pw_name, NULL, NULL, password) != 0) { 340 if (auth_userokay(pw->pw_name, NULL, NULL, password) != 0) {
339 DEBUG("successfully authenticated\n"); 341 DEBUG("successfully authenticated\n");
@@ -362,14 +364,16 @@ static void input_done(void) {
362 /* reset the time elapsed counter */ 364 /* reset the time elapsed counter */
363 i3lock_elapsed_time.start_time = time(NULL); 365 i3lock_elapsed_time.start_time = time(NULL);
364#endif 366#endif
365 if (debug_mode) 367 if (debug_mode) {
366 fprintf(stderr, "Authentication failure\n"); 368 fprintf(stderr, "Authentication failure\n");
369 }
367 370
368 auth_state = STATE_AUTH_WRONG; 371 auth_state = STATE_AUTH_WRONG;
369 failed_attempts += 1; 372 failed_attempts += 1;
370 clear_input(); 373 clear_input();
371 if (unlock_indicator) 374 if (unlock_indicator) {
372 redraw_screen(); 375 redraw_screen();
376 }
373 377
374 /* Clear this state after 2 seconds (unless the user enters another 378 /* Clear this state after 2 seconds (unless the user enters another
375 * password during that time). */ 379 * password during that time). */
@@ -393,11 +397,13 @@ static void redraw_timeout(EV_P_ ev_timer *w, int revents) {
393} 397}
394 398
395static bool skip_without_validation(void) { 399static bool skip_without_validation(void) {
396 if (input_position != 0) 400 if (input_position != 0) {
397 return false; 401 return false;
402 }
398 403
399 if (skip_repeated_empty_password || ignore_empty_password) 404 if (skip_repeated_empty_password || ignore_empty_password) {
400 return true; 405 return true;
406 }
401 407
402 return false; 408 return false;
403} 409}
@@ -450,8 +456,9 @@ static void handle_key_press(xcb_key_press_event_t *event) {
450 case XKB_KEY_Return: 456 case XKB_KEY_Return:
451 case XKB_KEY_KP_Enter: 457 case XKB_KEY_KP_Enter:
452 case XKB_KEY_XF86ScreenSaver: 458 case XKB_KEY_XF86ScreenSaver:
453 if ((ksym == XKB_KEY_j || ksym == XKB_KEY_m) && !ctrl) 459 if ((ksym == XKB_KEY_j || ksym == XKB_KEY_m) && !ctrl) {
454 break; 460 break;
461 }
455 462
456 if (auth_state == STATE_AUTH_WRONG) { 463 if (auth_state == STATE_AUTH_WRONG) {
457 retry_verification = true; 464 retry_verification = true;
@@ -483,8 +490,9 @@ static void handle_key_press(xcb_key_press_event_t *event) {
483 DEBUG("C-u pressed\n"); 490 DEBUG("C-u pressed\n");
484 clear_input(); 491 clear_input();
485 /* Also hide the unlock indicator */ 492 /* Also hide the unlock indicator */
486 if (unlock_indicator) 493 if (unlock_indicator) {
487 clear_indicator(); 494 clear_indicator();
495 }
488 return; 496 return;
489 } 497 }
490 break; 498 break;
@@ -499,8 +507,9 @@ static void handle_key_press(xcb_key_press_event_t *event) {
499 507
500 case XKB_KEY_h: 508 case XKB_KEY_h:
501 case XKB_KEY_BackSpace: 509 case XKB_KEY_BackSpace:
502 if (ksym == XKB_KEY_h && !ctrl) 510 if (ksym == XKB_KEY_h && !ctrl) {
503 break; 511 break;
512 }
504 513
505 if (input_position == 0) { 514 if (input_position == 0) {
506 START_TIMER(clear_indicator_timeout, 1.0, clear_indicator_cb); 515 START_TIMER(clear_indicator_timeout, 1.0, clear_indicator_cb);
@@ -522,8 +531,9 @@ static void handle_key_press(xcb_key_press_event_t *event) {
522 return; 531 return;
523 } 532 }
524 533
525 if ((input_position + 8) >= (int)sizeof(password)) 534 if ((input_position + 8) >= (int)sizeof(password)) {
526 return; 535 return;
536 }
527 537
528#if 0 538#if 0
529 /* FIXME: handle all of these? */ 539 /* FIXME: handle all of these? */
@@ -536,8 +546,9 @@ static void handle_key_press(xcb_key_press_event_t *event) {
536 printf("xcb_is_modifier_key = %d\n", xcb_is_modifier_key(sym)); 546 printf("xcb_is_modifier_key = %d\n", xcb_is_modifier_key(sym));
537#endif 547#endif
538 548
539 if (n < 2) 549 if (n < 2) {
540 return; 550 return;
551 }
541 552
542 /* store it in the password array as UTF-8 */ 553 /* store it in the password array as UTF-8 */
543 memcpy(password + input_position, buffer, n - 1); 554 memcpy(password + input_position, buffer, n - 1);
@@ -598,8 +609,9 @@ static void process_xkb_event(xcb_generic_event_t *gevent) {
598 609
599 DEBUG("process_xkb_event for device %d\n", event->any.deviceID); 610 DEBUG("process_xkb_event for device %d\n", event->any.deviceID);
600 611
601 if (event->any.deviceID != xkb_x11_get_core_keyboard_device_id(conn)) 612 if (event->any.deviceID != xkb_x11_get_core_keyboard_device_id(conn)) {
602 return; 613 return;
614 }
603 615
604 /* 616 /*
605 * XkbNewKkdNotify and XkbMapNotify together capture all sorts of keymap 617 * XkbNewKkdNotify and XkbMapNotify together capture all sorts of keymap
@@ -608,8 +620,9 @@ static void process_xkb_event(xcb_generic_event_t *gevent) {
608 */ 620 */
609 switch (event->any.xkbType) { 621 switch (event->any.xkbType) {
610 case XCB_XKB_NEW_KEYBOARD_NOTIFY: 622 case XCB_XKB_NEW_KEYBOARD_NOTIFY:
611 if (event->new_keyboard_notify.changed & XCB_XKB_NKN_DETAIL_KEYCODES) 623 if (event->new_keyboard_notify.changed & XCB_XKB_NKN_DETAIL_KEYCODES) {
612 (void)load_keymap(); 624 (void)load_keymap();
625 }
613 break; 626 break;
614 627
615 case XCB_XKB_MAP_NOTIFY: 628 case XCB_XKB_MAP_NOTIFY:
@@ -638,8 +651,9 @@ static void handle_screen_resize(void) {
638 xcb_get_geometry_cookie_t geomc; 651 xcb_get_geometry_cookie_t geomc;
639 xcb_get_geometry_reply_t *geom; 652 xcb_get_geometry_reply_t *geom;
640 geomc = xcb_get_geometry(conn, screen->root); 653 geomc = xcb_get_geometry(conn, screen->root);
641 if ((geom = xcb_get_geometry_reply(conn, geomc, 0)) == NULL) 654 if ((geom = xcb_get_geometry_reply(conn, geomc, 0)) == NULL) {
642 return; 655 return;
656 }
643 657
644 if (last_resolution[0] == geom->width && 658 if (last_resolution[0] == geom->width &&
645 last_resolution[1] == geom->height) { 659 last_resolution[1] == geom->height) {
@@ -667,8 +681,9 @@ static ssize_t read_raw_image_native(uint32_t *dest, FILE *src, size_t width, si
667 for (size_t y = 0; y < height; y++) { 681 for (size_t y = 0; y < height; y++) {
668 size_t n = fread(&dest[y * pixstride], 1, width * 4, src); 682 size_t n = fread(&dest[y * pixstride], 1, width * 4, src);
669 count += n; 683 count += n;
670 if (n < (size_t)(width * 4)) 684 if (n < (size_t)(width * 4)) {
671 break; 685 break;
686 }
672 } 687 }
673 688
674 return count; 689 return count;
@@ -684,15 +699,17 @@ struct raw_pixel_format {
684static ssize_t read_raw_image_fmt(uint32_t *dest, FILE *src, size_t width, size_t height, int pixstride, 699static ssize_t read_raw_image_fmt(uint32_t *dest, FILE *src, size_t width, size_t height, int pixstride,
685 struct raw_pixel_format fmt) { 700 struct raw_pixel_format fmt) {
686 unsigned char *buf = malloc(width * fmt.bpp); 701 unsigned char *buf = malloc(width * fmt.bpp);
687 if (buf == NULL) 702 if (buf == NULL) {
688 return -1; 703 return -1;
704 }
689 705
690 ssize_t count = 0; 706 ssize_t count = 0;
691 for (size_t y = 0; y < height; y++) { 707 for (size_t y = 0; y < height; y++) {
692 size_t n = fread(buf, 1, width * fmt.bpp, src); 708 size_t n = fread(buf, 1, width * fmt.bpp, src);
693 count += n; 709 count += n;
694 if (n < (size_t)(width * fmt.bpp)) 710 if (n < (size_t)(width * fmt.bpp)) {
695 break; 711 break;
712 }
696 713
697 for (size_t x = 0; x < width; ++x) { 714 for (size_t x = 0; x < width; ++x) {
698 int idx = x * fmt.bpp; 715 int idx = x * fmt.bpp;
@@ -763,18 +780,19 @@ static cairo_surface_t *read_raw_image(const char *image_path, const char *image
763 } else { 780 } else {
764 const struct raw_pixel_format *fmt = NULL; 781 const struct raw_pixel_format *fmt = NULL;
765 782
766 if (strcmp(pixfmt, "rgb") == 0) 783 if (strcmp(pixfmt, "rgb") == 0) {
767 fmt = &raw_fmt_rgb; 784 fmt = &raw_fmt_rgb;
768 else if (strcmp(pixfmt, "rgbx") == 0) 785 } else if (strcmp(pixfmt, "rgbx") == 0) {
769 fmt = &raw_fmt_rgbx; 786 fmt = &raw_fmt_rgbx;
770 else if (strcmp(pixfmt, "xrgb") == 0) 787 } else if (strcmp(pixfmt, "xrgb") == 0) {
771 fmt = &raw_fmt_xrgb; 788 fmt = &raw_fmt_xrgb;
772 else if (strcmp(pixfmt, "bgr") == 0) 789 } else if (strcmp(pixfmt, "bgr") == 0) {
773 fmt = &raw_fmt_bgr; 790 fmt = &raw_fmt_bgr;
774 else if (strcmp(pixfmt, "bgrx") == 0) 791 } else if (strcmp(pixfmt, "bgrx") == 0) {
775 fmt = &raw_fmt_bgrx; 792 fmt = &raw_fmt_bgrx;
776 else if (strcmp(pixfmt, "xbgr") == 0) 793 } else if (strcmp(pixfmt, "xbgr") == 0) {
777 fmt = &raw_fmt_xbgr; 794 fmt = &raw_fmt_xbgr;
795 }
778 796
779 if (fmt == NULL) { 797 if (fmt == NULL) {
780 fprintf(stderr, "Unknown raw pixel format: %s\n", pixfmt); 798 fprintf(stderr, "Unknown raw pixel format: %s\n", pixfmt);
@@ -845,8 +863,9 @@ static bool verify_png_image(const char *image_path) {
845 */ 863 */
846static int conv_callback(int num_msg, const struct pam_message **msg, 864static int conv_callback(int num_msg, const struct pam_message **msg,
847 struct pam_response **resp, void *appdata_ptr) { 865 struct pam_response **resp, void *appdata_ptr) {
848 if (num_msg == 0) 866 if (num_msg == 0) {
849 return 1; 867 return 1;
868 }
850 869
851 /* PAM expects an array of responses, one for each message */ 870 /* PAM expects an array of responses, one for each message */
852 if ((*resp = calloc(num_msg, sizeof(struct pam_response))) == NULL) { 871 if ((*resp = calloc(num_msg, sizeof(struct pam_response))) == NULL) {
@@ -856,8 +875,9 @@ static int conv_callback(int num_msg, const struct pam_message **msg,
856 875
857 for (int c = 0; c < num_msg; c++) { 876 for (int c = 0; c < num_msg; c++) {
858 if (msg[c]->msg_style != PAM_PROMPT_ECHO_OFF && 877 if (msg[c]->msg_style != PAM_PROMPT_ECHO_OFF &&
859 msg[c]->msg_style != PAM_PROMPT_ECHO_ON) 878 msg[c]->msg_style != PAM_PROMPT_ECHO_ON) {
860 continue; 879 continue;
880 }
861 881
862 /* return code is currently not used but should be set to zero */ 882 /* return code is currently not used but should be set to zero */
863 resp[c]->resp_retcode = 0; 883 resp[c]->resp_retcode = 0;
@@ -912,15 +932,17 @@ static void maybe_close_sleep_lock_fd(void) {
912static void xcb_check_cb(EV_P_ ev_check *w, int revents) { 932static void xcb_check_cb(EV_P_ ev_check *w, int revents) {
913 xcb_generic_event_t *event; 933 xcb_generic_event_t *event;
914 934
915 if (xcb_connection_has_error(conn)) 935 if (xcb_connection_has_error(conn)) {
916 errx(EXIT_FAILURE, "X11 connection broke, did your server terminate?"); 936 errx(EXIT_FAILURE, "X11 connection broke, did your server terminate?");
937 }
917 938
918 while ((event = xcb_poll_for_event(conn)) != NULL) { 939 while ((event = xcb_poll_for_event(conn)) != NULL) {
919 if (event->response_type == 0) { 940 if (event->response_type == 0) {
920 xcb_generic_error_t *error = (xcb_generic_error_t *)event; 941 xcb_generic_error_t *error = (xcb_generic_error_t *)event;
921 if (debug_mode) 942 if (debug_mode) {
922 fprintf(stderr, "X11 Error received! sequence 0x%x, error_code = %d\n", 943 fprintf(stderr, "X11 Error received! sequence 0x%x, error_code = %d\n",
923 error->sequence, error->error_code); 944 error->sequence, error->error_code);
945 }
924 free(event); 946 free(event);
925 continue; 947 continue;
926 } 948 }
@@ -945,8 +967,9 @@ static void xcb_check_cb(EV_P_ ev_check *w, int revents) {
945 dont_fork = true; 967 dont_fork = true;
946 968
947 /* In the parent process, we exit */ 969 /* In the parent process, we exit */
948 if (fork() != 0) 970 if (fork() != 0) {
949 exit(0); 971 exit(0);
972 }
950 973
951 ev_loop_fork(EV_DEFAULT); 974 ev_loop_fork(EV_DEFAULT);
952 } 975 }
@@ -983,8 +1006,9 @@ static void raise_loop(xcb_window_t window) {
983 xcb_generic_event_t *event; 1006 xcb_generic_event_t *event;
984 int screens; 1007 int screens;
985 1008
986 if (xcb_connection_has_error((conn = xcb_connect(NULL, &screens))) > 0) 1009 if (xcb_connection_has_error((conn = xcb_connect(NULL, &screens))) > 0) {
987 errx(EXIT_FAILURE, "Cannot open display"); 1010 errx(EXIT_FAILURE, "Cannot open display");
1011 }
988 1012
989 /* We need to know about the window being obscured or getting destroyed. */ 1013 /* We need to know about the window being obscured or getting destroyed. */
990 xcb_change_window_attributes(conn, window, XCB_CW_EVENT_MASK, 1014 xcb_change_window_attributes(conn, window, XCB_CW_EVENT_MASK,
@@ -1011,13 +1035,15 @@ static void raise_loop(xcb_window_t window) {
1011 break; 1035 break;
1012 case XCB_UNMAP_NOTIFY: 1036 case XCB_UNMAP_NOTIFY:
1013 DEBUG("UnmapNotify for 0x%08x\n", (((xcb_unmap_notify_event_t *)event)->window)); 1037 DEBUG("UnmapNotify for 0x%08x\n", (((xcb_unmap_notify_event_t *)event)->window));
1014 if (((xcb_unmap_notify_event_t *)event)->window == window) 1038 if (((xcb_unmap_notify_event_t *)event)->window == window) {
1015 exit(EXIT_SUCCESS); 1039 exit(EXIT_SUCCESS);
1040 }
1016 break; 1041 break;
1017 case XCB_DESTROY_NOTIFY: 1042 case XCB_DESTROY_NOTIFY:
1018 DEBUG("DestroyNotify for 0x%08x\n", (((xcb_destroy_notify_event_t *)event)->window)); 1043 DEBUG("DestroyNotify for 0x%08x\n", (((xcb_destroy_notify_event_t *)event)->window));
1019 if (((xcb_destroy_notify_event_t *)event)->window == window) 1044 if (((xcb_destroy_notify_event_t *)event)->window == window) {
1020 exit(EXIT_SUCCESS); 1045 exit(EXIT_SUCCESS);
1046 }
1021 break; 1047 break;
1022 default: 1048 default:
1023 DEBUG("Unhandled event type %d\n", type); 1049 DEBUG("Unhandled event type %d\n", type);
@@ -1088,12 +1114,7 @@ int main(int argc, char *argv[]) {
1088 {"show-keyboard-layout", no_argument, NULL, 'k'}, 1114 {"show-keyboard-layout", no_argument, NULL, 'k'},
1089 {NULL, no_argument, NULL, 0}}; 1115 {NULL, no_argument, NULL, 0}};
1090 1116
1091 if ((pw = getpwuid(getuid())) == NULL) 1117 int code = EXIT_FAILURE;
1092 err(EXIT_FAILURE, "getpwuid() failed");
1093 if ((username = pw->pw_name) == NULL)
1094 errx(EXIT_FAILURE, "pw->pw_name is NULL.");
1095 if (getenv("WAYLAND_DISPLAY") != NULL)
1096 errx(EXIT_FAILURE, "i3lock is a program for X11 and does not work on Wayland. Try https://github.com/swaywm/swaylock instead");
1097 1118
1098#ifdef EXTRAS 1119#ifdef EXTRAS
1099 char *optstring = "hvnbDdELC:c:B:G:F:J:O:R:r:S:T:W:X:x:Y:y:Z:p:ui:teI:fk"; 1120 char *optstring = "hvnbDdELC:c:B:G:F:J:O:R:r:S:T:W:X:x:Y:y:Z:p:ui:teI:fk";
@@ -1121,11 +1142,13 @@ int main(int argc, char *argv[]) {
1121 char *arg = optarg; 1142 char *arg = optarg;
1122 1143
1123 /* Skip # if present */ 1144 /* Skip # if present */
1124 if (arg[0] == '#') 1145 if (arg[0] == '#') {
1125 arg++; 1146 arg++;
1147 }
1126 1148
1127 if (strlen(arg) != 6 || sscanf(arg, "%06[0-9a-fA-F]", color) != 1) 1149 if (strlen(arg) != 6 || sscanf(arg, "%06[0-9a-fA-F]", color) != 1) {
1128 errx(EXIT_FAILURE, "color is invalid, it must be given in 3-byte hexadecimal format: rrggbb"); 1150 errx(EXIT_FAILURE, "color is invalid, it must be given in 3-byte hexadecimal format: rrggbb");
1151 }
1129 1152
1130 break; 1153 break;
1131 } 1154 }
@@ -1332,10 +1355,11 @@ int main(int argc, char *argv[]) {
1332 ignore_empty_password = true; 1355 ignore_empty_password = true;
1333 break; 1356 break;
1334 case 0: 1357 case 0:
1335 if (strcmp(longopts[longoptind].name, "debug") == 0) 1358 if (strcmp(longopts[longoptind].name, "debug") == 0) {
1336 debug_mode = true; 1359 debug_mode = true;
1337 else if (strcmp(longopts[longoptind].name, "raw") == 0) 1360 } else if (strcmp(longopts[longoptind].name, "raw") == 0) {
1338 image_raw_format = strdup(optarg); 1361 image_raw_format = strdup(optarg);
1362 }
1339 break; 1363 break;
1340 case 'f': 1364 case 'f':
1341 show_failed_attempts = true; 1365 show_failed_attempts = true;
@@ -1343,10 +1367,13 @@ int main(int argc, char *argv[]) {
1343 case 'k': 1367 case 'k':
1344 show_keyboard_layout = true; 1368 show_keyboard_layout = true;
1345 break; 1369 break;
1370 case 'h':
1371 code = EXIT_SUCCESS;
1372 /* fallthrough */
1346 default: 1373 default:
1347#ifdef EXTRAS 1374#ifdef EXTRAS
1348 errx( 1375 errx(
1349 EXIT_FAILURE, 1376 code,
1350 "Syntax: i3lock-extended [-B color] [-b] [-C seconds] " 1377 "Syntax: i3lock-extended [-B color] [-b] [-C seconds] "
1351 "[-c color] [-D] [-d] [-E] [-e] [-F color] [-f] [-k]" 1378 "[-c color] [-D] [-d] [-E] [-e] [-F color] [-f] [-k]"
1352 "[-G color] [-h] [-I timeout] [-i image.png] [-J text] " 1379 "[-G color] [-h] [-I timeout] [-i image.png] [-J text] "
@@ -1356,12 +1383,22 @@ int main(int argc, char *argv[]) {
1356 "[-x horizontal-alignment] [-Y vertical-alignment] " 1383 "[-x horizontal-alignment] [-Y vertical-alignment] "
1357 "[-y vertical-alignment] [-Z vertical-alignment]"); 1384 "[-y vertical-alignment] [-Z vertical-alignment]");
1358#else 1385#else
1359 errx(EXIT_FAILURE, "Syntax: i3lock [-v] [-n] [-b] [-d] [-c color] [-u] [-p win|default]" 1386 errx(code, "Syntax: i3lock [-v] [-n] [-b] [-d] [-c color] [-u] [-p win|default]"
1360 " [-i image.png] [-t] [-e] [-I timeout] [-f] [-k]"); 1387 " [-i image.png] [-t] [-e] [-I timeout] [-f] [-k]");
1361#endif 1388#endif
1362 } 1389 }
1363 } 1390 }
1364 1391
1392 if ((pw = getpwuid(getuid())) == NULL) {
1393 err(EXIT_FAILURE, "getpwuid() failed");
1394 }
1395 if ((username = pw->pw_name) == NULL) {
1396 errx(EXIT_FAILURE, "pw->pw_name is NULL.");
1397 }
1398 if (getenv("WAYLAND_DISPLAY") != NULL) {
1399 errx(EXIT_FAILURE, "i3lock is a program for X11 and does not work on Wayland. Try https://github.com/swaywm/swaylock instead");
1400 }
1401
1365 /* We need (relatively) random numbers for highlighting a random part of 1402 /* We need (relatively) random numbers for highlighting a random part of
1366 * the unlock indicator upon keypresses. */ 1403 * the unlock indicator upon keypresses. */
1367 srand(time(NULL)); 1404 srand(time(NULL));
@@ -1369,14 +1406,16 @@ int main(int argc, char *argv[]) {
1369#ifndef __OpenBSD__ 1406#ifndef __OpenBSD__
1370 /* Initialize PAM */ 1407 /* Initialize PAM */
1371#ifdef EXTRAS 1408#ifdef EXTRAS
1372 if ((ret = pam_start("i3lock-extended", username, &conv, &pam_handle)) != PAM_SUCCESS) 1409 if ((ret = pam_start("i3lock-extended", username, &conv, &pam_handle)) != PAM_SUCCESS) {
1373#else 1410#else
1374 if ((ret = pam_start("i3lock", username, &conv, &pam_handle)) != PAM_SUCCESS) 1411 if ((ret = pam_start("i3lock", username, &conv, &pam_handle)) != PAM_SUCCESS) {
1375#endif 1412#endif
1376 errx(EXIT_FAILURE, "PAM: %s", pam_strerror(pam_handle, ret)); 1413 errx(EXIT_FAILURE, "PAM: %s", pam_strerror(pam_handle, ret));
1414 }
1377 1415
1378 if ((ret = pam_set_item(pam_handle, PAM_TTY, getenv("DISPLAY"))) != PAM_SUCCESS) 1416 if ((ret = pam_set_item(pam_handle, PAM_TTY, getenv("DISPLAY"))) != PAM_SUCCESS) {
1379 errx(EXIT_FAILURE, "PAM: %s", pam_strerror(pam_handle, ret)); 1417 errx(EXIT_FAILURE, "PAM: %s", pam_strerror(pam_handle, ret));
1418 }
1380#endif 1419#endif
1381 1420
1382/* Using mlock() as non-super-user seems only possible in Linux. 1421/* Using mlock() as non-super-user seems only possible in Linux.
@@ -1388,15 +1427,17 @@ int main(int argc, char *argv[]) {
1388 /* Lock the area where we store the password in memory, we don’t want it to 1427 /* Lock the area where we store the password in memory, we don’t want it to
1389 * be swapped to disk. Since Linux 2.6.9, this does not require any 1428 * be swapped to disk. Since Linux 2.6.9, this does not require any
1390 * privileges, just enough bytes in the RLIMIT_MEMLOCK limit. */ 1429 * privileges, just enough bytes in the RLIMIT_MEMLOCK limit. */
1391 if (mlock(password, sizeof(password)) != 0) 1430 if (mlock(password, sizeof(password)) != 0) {
1392 err(EXIT_FAILURE, "Could not lock page in memory, check RLIMIT_MEMLOCK"); 1431 err(EXIT_FAILURE, "Could not lock page in memory, check RLIMIT_MEMLOCK");
1432 }
1393#endif 1433#endif
1394 1434
1395 /* Double checking that connection is good and operatable with xcb */ 1435 /* Double checking that connection is good and operatable with xcb */
1396 int screennr; 1436 int screennr;
1397 if ((conn = xcb_connect(NULL, &screennr)) == NULL || 1437 if ((conn = xcb_connect(NULL, &screennr)) == NULL ||
1398 xcb_connection_has_error(conn)) 1438 xcb_connection_has_error(conn)) {
1399 errx(EXIT_FAILURE, "Could not connect to X11, maybe you need to set DISPLAY?"); 1439 errx(EXIT_FAILURE, "Could not connect to X11, maybe you need to set DISPLAY?");
1440 }
1400 1441
1401 if (xkb_x11_setup_xkb_extension(conn, 1442 if (xkb_x11_setup_xkb_extension(conn,
1402 XKB_X11_MIN_MAJOR_XKB_VERSION, 1443 XKB_X11_MIN_MAJOR_XKB_VERSION,
@@ -1405,8 +1446,9 @@ int main(int argc, char *argv[]) {
1405 NULL, 1446 NULL,
1406 NULL, 1447 NULL,
1407 &xkb_base_event, 1448 &xkb_base_event,
1408 &xkb_base_error) != 1) 1449 &xkb_base_error) != 1) {
1409 errx(EXIT_FAILURE, "Could not setup XKB extension."); 1450 errx(EXIT_FAILURE, "Could not setup XKB extension.");
1451 }
1410 1452
1411 static const xcb_xkb_map_part_t required_map_parts = 1453 static const xcb_xkb_map_part_t required_map_parts =
1412 (XCB_XKB_MAP_PART_KEY_TYPES | 1454 (XCB_XKB_MAP_PART_KEY_TYPES |
@@ -1433,17 +1475,21 @@ int main(int argc, char *argv[]) {
1433 0); 1475 0);
1434 1476
1435 /* When we cannot initially load the keymap, we better exit */ 1477 /* When we cannot initially load the keymap, we better exit */
1436 if (!load_keymap()) 1478 if (!load_keymap()) {
1437 errx(EXIT_FAILURE, "Could not load keymap"); 1479 errx(EXIT_FAILURE, "Could not load keymap");
1480 }
1438 1481
1439 const char *locale = getenv("LC_ALL"); 1482 const char *locale = getenv("LC_ALL");
1440 if (!locale || !*locale) 1483 if (!locale || !*locale) {
1441 locale = getenv("LC_CTYPE"); 1484 locale = getenv("LC_CTYPE");
1442 if (!locale || !*locale) 1485 }
1486 if (!locale || !*locale) {
1443 locale = getenv("LANG"); 1487 locale = getenv("LANG");
1488 }
1444 if (!locale || !*locale) { 1489 if (!locale || !*locale) {
1445 if (debug_mode) 1490 if (debug_mode) {
1446 fprintf(stderr, "Can't detect your locale, fallback to C\n"); 1491 fprintf(stderr, "Can't detect your locale, fallback to C\n");
1492 }
1447 locale = "C"; 1493 locale = "C";
1448 } 1494 }
1449 1495
@@ -1532,16 +1578,17 @@ int main(int argc, char *argv[]) {
1532 1578
1533 /* Initialize the libev event loop. */ 1579 /* Initialize the libev event loop. */
1534 main_loop = EV_DEFAULT; 1580 main_loop = EV_DEFAULT;
1535 if (main_loop == NULL) 1581 if (main_loop == NULL) {
1536 errx(EXIT_FAILURE, "Could not initialize libev. Bad LIBEV_FLAGS?"); 1582 errx(EXIT_FAILURE, "Could not initialize libev. Bad LIBEV_FLAGS?");
1583 }
1537 1584
1538 /* Explicitly call the screen redraw in case "locking…" message was displayed */ 1585 /* Explicitly call the screen redraw in case "locking…" message was displayed */
1539 auth_state = STATE_AUTH_IDLE; 1586 auth_state = STATE_AUTH_IDLE;
1540 redraw_screen(); 1587 redraw_screen();
1541 1588
1542 struct ev_io *xcb_watcher = calloc(sizeof(struct ev_io), 1); 1589 struct ev_io *xcb_watcher = calloc(1, sizeof(struct ev_io));
1543 struct ev_check *xcb_check = calloc(sizeof(struct ev_check), 1); 1590 struct ev_check *xcb_check = calloc(1, sizeof(struct ev_check));
1544 struct ev_prepare *xcb_prepare = calloc(sizeof(struct ev_prepare), 1); 1591 struct ev_prepare *xcb_prepare = calloc(1, sizeof(struct ev_prepare));
1545 1592
1546 ev_io_init(xcb_watcher, xcb_got_event, xcb_get_file_descriptor(conn), EV_READ); 1593 ev_io_init(xcb_watcher, xcb_got_event, xcb_get_file_descriptor(conn), EV_READ);
1547 ev_io_start(main_loop, xcb_watcher); 1594 ev_io_start(main_loop, xcb_watcher);
diff --git a/meson/meson-dist-script b/meson/meson-dist-script
index b112d2f..a6a1151 100755
--- a/meson/meson-dist-script
+++ b/meson/meson-dist-script
@@ -8,4 +8,5 @@ cd "${MESON_DIST_ROOT}"
8rm -rf \ 8rm -rf \
9 .clang-format \ 9 .clang-format \
10 .editorconfig \ 10 .editorconfig \
11 travis 11 ci \
12 .github
diff --git a/randr.c b/randr.c
index 4b1ea97..ef84c49 100644
--- a/randr.c
+++ b/randr.c
@@ -58,8 +58,9 @@ void randr_init(int *event_base, xcb_window_t root) {
58 58
59 free(randr_version); 59 free(randr_version);
60 60
61 if (event_base != NULL) 61 if (event_base != NULL) {
62 *event_base = extreply->first_event; 62 *event_base = extreply->first_event;
63 }
63 64
64 xcb_randr_select_input(conn, root, 65 xcb_randr_select_input(conn, root,
65 XCB_RANDR_NOTIFY_MASK_SCREEN_CHANGE | 66 XCB_RANDR_NOTIFY_MASK_SCREEN_CHANGE |
@@ -81,8 +82,9 @@ void _xinerama_init(void) {
81 82
82 cookie = xcb_xinerama_is_active(conn); 83 cookie = xcb_xinerama_is_active(conn);
83 reply = xcb_xinerama_is_active_reply(conn, cookie, NULL); 84 reply = xcb_xinerama_is_active_reply(conn, cookie, NULL);
84 if (!reply) 85 if (!reply) {
85 return; 86 return;
87 }
86 88
87 if (!reply->state) { 89 if (!reply->state) {
88 free(reply); 90 free(reply);
diff --git a/unlock_indicator.c b/unlock_indicator.c
index 7d620fd..33b9406 100644
--- a/unlock_indicator.c
+++ b/unlock_indicator.c
@@ -186,12 +186,14 @@ static void check_modifier_keys(void) {
186 num_mods = xkb_keymap_num_mods(xkb_keymap); 186 num_mods = xkb_keymap_num_mods(xkb_keymap);
187 187
188 for (idx = 0; idx < num_mods; idx++) { 188 for (idx = 0; idx < num_mods; idx++) {
189 if (!xkb_state_mod_index_is_active(xkb_state, idx, XKB_STATE_MODS_EFFECTIVE)) 189 if (!xkb_state_mod_index_is_active(xkb_state, idx, XKB_STATE_MODS_EFFECTIVE)) {
190 continue; 190 continue;
191 }
191 192
192 mod_name = xkb_keymap_mod_get_name(xkb_keymap, idx); 193 mod_name = xkb_keymap_mod_get_name(xkb_keymap, idx);
193 if (mod_name == NULL) 194 if (mod_name == NULL) {
194 continue; 195 continue;
196 }
195 197
196 /* Replace certain xkb names with nicer, human-readable ones. */ 198 /* Replace certain xkb names with nicer, human-readable ones. */
197 if (strcmp(mod_name, XKB_MOD_NAME_CAPS) == 0) { 199 if (strcmp(mod_name, XKB_MOD_NAME_CAPS) == 0) {
@@ -218,8 +220,9 @@ void draw_image(xcb_pixmap_t bg_pixmap, uint32_t *resolution) {
218 DEBUG("scaling_factor is %.f, physical diameter is %d px\n", 220 DEBUG("scaling_factor is %.f, physical diameter is %d px\n",
219 scaling_factor, button_diameter_physical); 221 scaling_factor, button_diameter_physical);
220 222
221 if (!vistype) 223 if (!vistype) {
222 vistype = get_root_visual_type(screen); 224 vistype = get_root_visual_type(screen);
225 }
223 226
224 /* Initialize cairo: Create one in-memory surface to render the unlock 227 /* Initialize cairo: Create one in-memory surface to render the unlock
225 * indicator on, create one XCB surface to actually draw (one or more, 228 * indicator on, create one XCB surface to actually draw (one or more,
@@ -534,7 +537,8 @@ void redraw_screen(void) {
534void clear_indicator(void) { 537void clear_indicator(void) {
535 if (input_position == 0) { 538 if (input_position == 0) {
536 unlock_state = STATE_STARTED; 539 unlock_state = STATE_STARTED;
537 } else 540 } else {
538 unlock_state = STATE_KEY_PRESSED; 541 unlock_state = STATE_KEY_PRESSED;
542 }
539 redraw_screen(); 543 redraw_screen();
540} 544}
diff --git a/xcb.c b/xcb.c
index 2867a47..f0a784f 100644
--- a/xcb.c
+++ b/xcb.c
@@ -95,8 +95,9 @@ xcb_visualtype_t *get_root_visual_type(xcb_screen_t *screen) {
95 for (visual_iter = xcb_depth_visuals_iterator(depth_iter.data); 95 for (visual_iter = xcb_depth_visuals_iterator(depth_iter.data);
96 visual_iter.rem; 96 visual_iter.rem;
97 xcb_visualtype_next(&visual_iter)) { 97 xcb_visualtype_next(&visual_iter)) {
98 if (screen->root_visual != visual_iter.data->visual_id) 98 if (screen->root_visual != visual_iter.data->visual_id) {
99 continue; 99 continue;
100 }
100 101
101 visual_type = visual_iter.data; 102 visual_type = visual_iter.data;
102 return visual_type; 103 return visual_type;