i3lock-color

The world's most popular non-default computer lockscreen.
Index Commits Files Refs README LICENSE
commit 2fd65471b282f6a82e2d0f45166ed5b3095c63dc
parent a0af4e1634ad91efeeacac853b7751b3b091f6c0
Author: Cassandra Fox <cass@fox.mom>
Date:   Fri, 20 Sep 2019 17:00:45 -0700

Merge pull request #131 from Raymo111/master

Also pass XF86 Power Off and Power Down keys through when using --pass-media-keys
Diffstat:
Mi3lock.1 | 20+++++++++++++++-----
Mi3lock.c | 93+++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------
2 files changed, 78 insertions(+), 35 deletions(-)
diff --git a/i3lock.1 b/i3lock.1
@@ -138,11 +138,6 @@ Captures the screen and blurs it using the given sigma (radius).
 Images may still be overlaid over the blurred screenshot.
 
 .TP
-.B \-m, \-\-pass-media-keys
-Allow the following keys to be used while the screen is locked by passing them through:
-XF86AudioPlay, XF86AudioPause, XF86AudioStop, XF86AudioPrev, XF86AudioNext, XF86AudioMute, XF86AudioLowerVolume, XF86AudioRaiseVolume,  XF86MonBrightnessUp, XF86MonBrightnessDown.
-
-.TP
 .B \-\-indicator
 Forces the indicator to always be visible, instead of only showing on activity.
 
@@ -170,6 +165,21 @@ Displays the clock. \-\-force\-clock also displays the clock when there's indica
 Some compositors have problems with i3lock trying to render over them, so this argument is disabled by default. However, some will work properly with it, so it's been left enabled.
 
 .TP
+.B \-\-pass-media-keys
+Allow the following keys to be used while the screen is locked by passing them through:
+XF86AudioPlay, XF86AudioPause, XF86AudioStop, XF86AudioPrev, XF86AudioNext, XF86AudioMute, XF86AudioLowerVolume, XF86AudioRaiseVolume.
+
+.TP
+.B \-\-pass-screen-keys
+Allow the following keys to be used while the screen is locked by passing them through:
+XF86MonBrightnessUp, XF86MonBrightnessDown.
+
+.TP
+.B \-\-pass-power-keys
+Allow the following keys to be used while the screen is locked by passing them through:
+XF86PowerDown, XF86PowerOff.
+
+.TP
 .B \-\-insidevercolor=rrggbbaa
 Sets the interior circle color while the password is being verified.
 
diff --git a/i3lock.c b/i3lock.c
@@ -233,6 +233,8 @@ bool tile = false;
 bool ignore_empty_password = false;
 bool skip_repeated_empty_password = false;
 bool pass_media_keys = false;
+bool pass_screen_keys = false;
+bool pass_power_keys = false;
 
 // for the rendering thread, so we can clean it up
 pthread_t draw_thread;
@@ -654,6 +656,7 @@ static void handle_key_press(xcb_key_press_event_t *event) {
 #else
     n = xkb_keysym_to_utf8(ksym, buffer, sizeof(buffer));
 #endif
+
     // media keys
     if (pass_media_keys) {
         switch(ksym) {
@@ -665,6 +668,14 @@ static void handle_key_press(xcb_key_press_event_t *event) {
             case XKB_KEY_XF86AudioMute:
             case XKB_KEY_XF86AudioLowerVolume:
             case XKB_KEY_XF86AudioRaiseVolume:
+                xcb_send_event(conn, true, screen->root, XCB_EVENT_MASK_BUTTON_PRESS, (char *)event);
+                return;
+        }
+    }
+
+    // screen keys
+    if (pass_screen_keys) {
+        switch(ksym) {
             case XKB_KEY_XF86MonBrightnessUp:
             case XKB_KEY_XF86MonBrightnessDown:
                 xcb_send_event(conn, true, screen->root, XCB_EVENT_MASK_BUTTON_PRESS, (char *)event);
@@ -672,6 +683,16 @@ static void handle_key_press(xcb_key_press_event_t *event) {
         }
     }
 
+    // power keys
+    if (pass_power_keys) {
+        switch(ksym) {
+            case XKB_KEY_XF86PowerDown:
+            case XKB_KEY_XF86PowerOff:
+                xcb_send_event(conn, true, screen->root, XCB_EVENT_MASK_BUTTON_PRESS, (char *)event);
+                return;
+        }
+    }
+
     // return/enter/etc
     switch (ksym) {
         case XKB_KEY_j:
@@ -1362,7 +1383,7 @@ int main(int argc, char *argv[]) {
         {"inactivity-timeout", required_argument, NULL, 'I'},
         {"show-failed-attempts", no_argument, NULL, 'f'},
 
-        /* options for unlock indicator colors */
+        // options for unlock indicator colors
         {"insidevercolor", required_argument, NULL, 300},
         {"insidewrongcolor", required_argument, NULL, 301},
         {"insidecolor", required_argument, NULL, 302},
@@ -1392,7 +1413,6 @@ int main(int argc, char *argv[]) {
         {"ring-width", required_argument, NULL, 403},
 
         // alignment
-
         {"time-align", required_argument, NULL, 500},
         {"date-align", required_argument, NULL, 501},
         {"verif-align", required_argument, NULL, 502},
@@ -1402,7 +1422,6 @@ int main(int argc, char *argv[]) {
         {"greeter-align", required_argument, NULL, 506},
 
         // string stuff
-
         {"timestr", required_argument, NULL, 510},
         {"datestr", required_argument, NULL, 511},
         {"veriftext", required_argument, NULL, 512},
@@ -1414,7 +1433,6 @@ int main(int argc, char *argv[]) {
         {"greetertext", required_argument, NULL, 518},
 
         // fonts
-
         {"time-font", required_argument, NULL, 520},
         {"date-font", required_argument, NULL, 521},
         {"verif-font", required_argument, NULL, 522},
@@ -1423,7 +1441,6 @@ int main(int argc, char *argv[]) {
         {"greeter-font", required_argument, NULL, 525},
 
         // text size
-
         {"timesize", required_argument, NULL, 530},
         {"datesize", required_argument, NULL, 531},
         {"verifsize", required_argument, NULL, 532},
@@ -1433,7 +1450,6 @@ int main(int argc, char *argv[]) {
         {"greetersize", required_argument, NULL, 536},
 
         // text/indicator positioning
-
         {"timepos", required_argument, NULL, 540},
         {"datepos", required_argument, NULL, 541},
         {"verifpos", required_argument, NULL, 542},
@@ -1444,9 +1460,12 @@ int main(int argc, char *argv[]) {
         {"indpos", required_argument, NULL, 547},
         {"greeterpos", required_argument, NULL, 548},
 
+        // pass keys
+        {"pass-media-keys", no_argument, NULL, 601},
+        {"pass-screen-keys", no_argument, NULL, 602},
+        {"pass-power-keys", no_argument, NULL, 603},
 
         // bar indicator stuff
-
         {"bar-indicator", no_argument, NULL, 700},
         {"bar-direction", required_argument, NULL, 701},
         {"bar-width", required_argument, NULL, 702},
@@ -1459,13 +1478,11 @@ int main(int argc, char *argv[]) {
         {"bar-position", required_argument, NULL, 709},
 
         // misc.
-
         {"redraw-thread", no_argument, NULL, 900},
         {"refresh-rate", required_argument, NULL, 901},
         {"composite", no_argument, NULL, 902},
-        {"pass-media-keys", no_argument, NULL, 'm'},
 
-        /* slideshow options */
+        // slideshow options
         {"slideshow-interval", required_argument, NULL, 903},
         {"slideshow-random-selection", no_argument, NULL, 904},
 
@@ -1534,11 +1551,11 @@ int main(int argc, char *argv[]) {
                 show_failed_attempts = true;
                 break;
             case 'l':
-#if defined(__linux__)
+                #if defined(__linux__)
                 lock_tty_switching = true;
-#else
+                    #else
                 errx(EXIT_FAILURE, "TTY switch locking is only supported on Linux.");
-#endif
+                #endif
                 break;
             case 'r':
                 if (internal_line_source != 0) {
@@ -1563,8 +1580,9 @@ int main(int argc, char *argv[]) {
                 blur = true;
                 blur_sigma = atoi(optarg);
                 break;
-            // begin colors
-#define parse_color(color)\
+
+            // Begin colors
+            #define parse_color(color)\
                 arg = optarg;\
                 if (arg[0] == '#') arg++;\
                 if (strlen(arg) != 8 || sscanf(arg, "%08[0-9a-fA-F]", color) != 1)\
@@ -1617,7 +1635,8 @@ int main(int argc, char *argv[]) {
             case 315:
                 parse_color(greetercolor);
                 break;
-// general indicator opts
+
+            // General indicator opts
             case 400:
                 show_clock = true;
                 always_show_clock = true;
@@ -1627,7 +1646,6 @@ int main(int argc, char *argv[]) {
                 break;
             case 402:
                 arg = optarg;
-
                 if (sscanf(arg, "%lf", &circle_radius) != 1)
                     errx(1, "radius must be a number\n");
                 if (circle_radius < 1) {
@@ -1644,7 +1662,8 @@ int main(int argc, char *argv[]) {
                     ring_width = 7.0;
                 }
                 break;
-// alignment stuff
+
+            // Alignment stuff
             case 500:
                 opt = atoi(optarg);
                 if (opt < 0 || opt > 2) opt = 0;
@@ -1680,7 +1699,8 @@ int main(int argc, char *argv[]) {
                 if (opt < 0 || opt > 2) opt = 0;
                 greeter_align = opt;
                 break;
-// string stuff
+
+            // String stuff
             case 510:
                 if (strlen(optarg) > 31) {
                     errx(1, "time format string can be at most 31 characters\n");
@@ -1717,7 +1737,8 @@ int main(int argc, char *argv[]) {
             case 518:
                 greeter_text = optarg;
                 break;
-// font stuff
+
+            // Font stuff
             case 520:
                 if (strlen(optarg) > 31) {
                     errx(1, "time font string can be at most 31 characters\n");
@@ -1756,7 +1777,8 @@ int main(int argc, char *argv[]) {
                 }
                 strcpy(fonts[GREETER_FONT],optarg);
                 break;
-// text size
+
+            // Text size
             case 530:
                 arg = optarg;
                 if (sscanf(arg, "%lf", &time_size) != 1)
@@ -1814,7 +1836,8 @@ int main(int argc, char *argv[]) {
                     greeter_size = 14.0;
                 }
                 break;
-// Positions
+
+            // Positions
             case 540:
                 //read in to time_x_expr and time_y_expr
                 if (strlen(optarg) > 31) {
@@ -1838,7 +1861,7 @@ int main(int argc, char *argv[]) {
                 }
                 break;
             case 542:
-                //read in to time_x_expr and time_y_expr
+                // read in to time_x_expr and time_y_expr
                 if (strlen(optarg) > 31) {
                     errx(1, "verif position string can be at most 31 characters\n");
                 }
@@ -1905,7 +1928,19 @@ int main(int argc, char *argv[]) {
                     errx(1, "indpos must be of the form x:y\n");
                 }
                 break;
-// bar indicator
+
+            // Pass keys
+            case 601:
+                pass_media_keys = true;
+                break;
+            case 602:
+                pass_screen_keys = true;
+                break;
+            case 603:
+                pass_power_keys = true;
+                break;
+
+            // Bar indicator
             case 700:
                 bar_enabled = true;
                 break;
@@ -1968,7 +2003,8 @@ int main(int argc, char *argv[]) {
                     errx(1, "bar-position must be of the form [pos] with a max length of 31\n");
                 }
                 break;
-// misc
+
+            // Misc
             case 900:
                 redraw_thread = true;
                 break;
@@ -1993,15 +2029,12 @@ int main(int argc, char *argv[]) {
             case 904:
                 slideshow_random_selection = true;
                 break;
-            case 'm':
-                pass_media_keys = true;
+            case 998:
+                image_raw_format = strdup(optarg);
                 break;
             case 999:
                 debug_mode = true;
                 break;
-            case 998:
-                image_raw_format = strdup(optarg);
-                break;
             default:
                 errx(EXIT_FAILURE, "Syntax: i3lock [-v] [-n] [-b] [-d] [-c color] [-u] [-p win|default]"
                                    " [-i image.png] [-t] [-e] [-f] [-l]\n"