From ed326ee463d7c01dc3930001cc0a748e83b930dd Mon Sep 17 00:00:00 2001 From: Chris Guillott Date: Wed, 17 Feb 2016 07:51:04 -0500 Subject: [PATCH] add option for single-display unlock indicator --- README.md | 1 + i3lock.c | 8 +++++++- todo.md | 1 + unlock_indicator.c | 23 +++++++++++++++++------ 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index c3aab34..a5e4997 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ Many little improvements have been made to i3lock over time: - `--bshlcolor=rrggbbaa` -- Backspace highlight segments - `--line-uses-ring`, `-r` -- the line between the inside and outer ring uses the ring color for its color - `--line-uses-inside`, `-s` -- the line between the inside and outer ring uses the inside color for its color + - `-S, --screen` -- specifies which display to draw the unlock indicator on - All the colors have an alpha channel now. Please keep in mind that this was not intended when the program was originally written, so making things transparent that weren't before can make it look strange. - You can specify whether i3lock should bell upon a wrong password. diff --git a/i3lock.c b/i3lock.c index 7c83251..8f0eb11 100644 --- a/i3lock.c +++ b/i3lock.c @@ -58,6 +58,8 @@ char textcolor[9] = "000000ff"; char keyhlcolor[9] = "33db00ff"; char bshlcolor[9] = "db3300ff"; char separatorcolor[9] = "000000ff"; + +int screen_number = -1; /* default is to use the supplied line color, 1 will be ring color, 2 will be to use the inside color for ver/wrong/etc */ int internal_line_source = 0; @@ -789,6 +791,7 @@ int main(int argc, char *argv[]) { {"line-uses-ring", no_argument, NULL, 'r'}, {"line-uses-inside", no_argument, NULL, 's'}, /* s for in_s_ide; ideally I'd use -I but that's used for timeout, which should use -T, but compatibility argh */ + {"screen", required_argument, NULL, 'S'}, {"ignore-empty-password", no_argument, NULL, 'e'}, {"inactivity-timeout", required_argument, NULL, 'I'}, {"show-failed-attempts", no_argument, NULL, 'f'}, @@ -799,7 +802,7 @@ int main(int argc, char *argv[]) { if ((username = pw->pw_name) == NULL) errx(EXIT_FAILURE, "pw->pw_name is NULL.\n"); - char *optstring = "hvnbdc:p:ui:teI:frs"; + char *optstring = "hvnbdc:p:ui:teI:frsS:"; while ((o = getopt_long(argc, argv, optstring, longopts, &optind)) != -1) { switch (o) { case 'v': @@ -865,6 +868,9 @@ int main(int argc, char *argv[]) { } internal_line_source = 2; break; + case 'S': + screen_number = atoi(optarg); + break; case 0: if (strcmp(longopts[optind].name, "debug") == 0) debug_mode = true; diff --git a/todo.md b/todo.md index 9f8d4c2..940f035 100644 --- a/todo.md +++ b/todo.md @@ -4,3 +4,4 @@ st for i3lock with colors * Make the arguments less chunky / more concise * Let the user specify 3 colors and have it generate shades based off them * Rainbow mode / random color mode? +* fix up the man page diff --git a/unlock_indicator.c b/unlock_indicator.c index 0b60856..59ab3a8 100644 --- a/unlock_indicator.c +++ b/unlock_indicator.c @@ -69,6 +69,8 @@ extern char bshlcolor[9]; extern char separatorcolor[9]; extern int internal_line_source; +extern int screen_number; + /* Whether the failed attempts should be displayed. */ extern bool show_failed_attempts; /* Number of failed unlock attempts. */ @@ -416,12 +418,21 @@ xcb_pixmap_t draw_image(uint32_t *resolution) { if (xr_screens > 0) { /* Composite the unlock indicator in the middle of each screen. */ - for (int screen = 0; screen < xr_screens; screen++) { - int x = (xr_resolutions[screen].x + ((xr_resolutions[screen].width / 2) - (button_diameter_physical / 2))); - int y = (xr_resolutions[screen].y + ((xr_resolutions[screen].height / 2) - (button_diameter_physical / 2))); - cairo_set_source_surface(xcb_ctx, output, x, y); - cairo_rectangle(xcb_ctx, x, y, button_diameter_physical, button_diameter_physical); - cairo_fill(xcb_ctx); + // excuse me, just gonna hack something in right here + if (screen_number != -1 && screen_number < xr_screens) { + int x = (xr_resolutions[screen_number].x + ((xr_resolutions[screen_number].width / 2) - (button_diameter_physical / 2))); + int y = (xr_resolutions[screen_number].y + ((xr_resolutions[screen_number].height / 2) - (button_diameter_physical / 2))); + cairo_set_source_surface(xcb_ctx, output, x, y); + cairo_rectangle(xcb_ctx, x, y, button_diameter_physical, button_diameter_physical); + cairo_fill(xcb_ctx); } + else { + for (int screen = 0; screen < xr_screens; screen++) { + int x = (xr_resolutions[screen].x + ((xr_resolutions[screen].width / 2) - (button_diameter_physical / 2))); + int y = (xr_resolutions[screen].y + ((xr_resolutions[screen].height / 2) - (button_diameter_physical / 2))); + cairo_set_source_surface(xcb_ctx, output, x, y); + cairo_rectangle(xcb_ctx, x, y, button_diameter_physical, button_diameter_physical); + cairo_fill(xcb_ctx); + } } } else { /* We have no information about the screen sizes/positions, so we just