Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Also pass XF86 Power Off and Power Down keys through when using --pass-media-keys #131

Merged
merged 4 commits into from
Sep 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions i3lock.1
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,6 @@ Note that this number is zero indexed. The ordering is dependent on libxinerama.
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.
Expand Down Expand Up @@ -169,6 +164,21 @@ Displays the clock. \-\-force\-clock also displays the clock when there's indica
.B \-\-composite
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.
Expand Down
93 changes: 63 additions & 30 deletions i3lock.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -665,13 +668,31 @@ 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);
return;
}
}

// 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:
Expand Down Expand Up @@ -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},
Expand Down Expand Up @@ -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},
Expand All @@ -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},
Expand All @@ -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},
Expand All @@ -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},
Expand All @@ -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},
Expand All @@ -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},
Expand All @@ -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},

Expand Down Expand Up @@ -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) {
Expand All @@ -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)\
Expand Down Expand Up @@ -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;
Expand All @@ -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) {
Expand All @@ -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;
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand All @@ -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");
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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"
Expand Down