From 7fb899bcd52a19e81b427d5b8ee4852262482f92 Mon Sep 17 00:00:00 2001 From: Chris Guillott Date: Tue, 9 Feb 2016 09:19:02 -0500 Subject: [PATCH] expose separator color for theming + bug fix I did a double take, apparently he messed up a copy/paste. --- README.md | 7 +++-- i3lock.c | 12 +++++++++ unlock_indicator.c | 67 +++++++++++++++++++++------------------------- 3 files changed, 47 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index 86afb7d..b7cd3f0 100644 --- a/README.md +++ b/README.md @@ -23,10 +23,13 @@ Many little improvements have been made to i3lock over time: - `--ringvercolor=rrggbbaa` -- Outer ring while the password is being verified - `--ringwrongcolor=rrggbbaa` -- Outer ring when a wrong password was entered - `--ringcolor=rrggbbaa` -- Outer ring while typing/idle - - `--linecolor=rrggbbaa` -- Line separating outer ring from inside of the circle and delimiting the highlight segments + - `--linecolor=rrggbbaa` -- Line separating outer ring from inside of the circle + - `--separatorcolor=rrggbbaa` -- Lines delimiting the highlight segments - `--textcolor=rrggbbaa` -- Text ("verifying", "wrong!") - `--keyhlcolor=rrggbbaa` -- Keypress highlight segments - `--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 - 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. @@ -54,7 +57,7 @@ press enter. Example usage for colors: -i3lock --insidevercolor=0000a0bf --insidewrongcolor=ff8000bf --insidecolor=ffffffbf --ringvercolor=0020ffff --ringwrongcolor=4040ffff --ringcolor=404090ff --textcolor=ffffffff --linecolor=aaaaaaff --keyhlcolor=30ccccff --bshlcolor=ff8000ff +i3lock --insidevercolor=0000a0bf --insidewrongcolor=ff8000bf --insidecolor=ffffffbf --ringvercolor=0020ffff --ringwrongcolor=4040ffff --ringcolor=404090ff --textcolor=ffffffff --linecolor=aaaaaaff --keyhlcolor=30ccccff --bshlcolor=ff8000ff -r Upstream diff --git a/i3lock.c b/i3lock.c index d30fdf0..7c83251 100644 --- a/i3lock.c +++ b/i3lock.c @@ -57,6 +57,7 @@ char linecolor[9] = "000000ff"; char textcolor[9] = "000000ff"; char keyhlcolor[9] = "33db00ff"; char bshlcolor[9] = "db3300ff"; +char separatorcolor[9] = "000000ff"; /* 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; @@ -784,6 +785,7 @@ int main(int argc, char *argv[]) { {"textcolor", required_argument, NULL, 0}, // --t-c {"keyhlcolor", required_argument, NULL, 0}, // --k-c {"bshlcolor", required_argument, NULL, 0}, // --b-c + {"separatorcolor", required_argument, NULL, 0}, {"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 */ @@ -966,6 +968,16 @@ int main(int argc, char *argv[]) { if (strlen(arg) != 8 || sscanf(arg, "%08[0-9a-fA-F]", bshlcolor) != 1) errx(1, "bshlcolor is invalid, color must be given in 8-byte format: rrggbb\n"); } + else if (strcmp(longopts[optind].name, "separatorcolor") == 0) { + char *arg = optarg; + + /* Skip # if present */ + if (arg[0] == '#') + arg++; + + if (strlen(arg) != 8 || sscanf(arg, "%08[0-9a-fA-F]", separatorcolor) != 1) + errx(1, "separator is invalid, color must be given in 8-byte format: rrggbb\n"); + } break; case 'f': show_failed_attempts = true; diff --git a/unlock_indicator.c b/unlock_indicator.c index 5d291d6..0b60856 100644 --- a/unlock_indicator.c +++ b/unlock_indicator.c @@ -66,6 +66,7 @@ extern char linecolor[9]; extern char textcolor[9]; extern char keyhlcolor[9]; extern char bshlcolor[9]; +extern char separatorcolor[9]; extern int internal_line_source; /* Whether the failed attempts should be displayed. */ @@ -217,22 +218,30 @@ xcb_pixmap_t draw_image(uint32_t *resolution) { (strtol(strgroupst[1], NULL, 16)), (strtol(strgroupst[2], NULL, 16)), (strtol(strgroupst[3], NULL, 16))}; - char strgroupsk[4][3] = {{keyhlcolor[0], textcolor[1], '\0'}, - {keyhlcolor[2], textcolor[3], '\0'}, - {keyhlcolor[4], textcolor[5], '\0'}, - {keyhlcolor[6], textcolor[7], '\0'}}; + char strgroupsk[4][3] = {{keyhlcolor[0], keyhlcolor[1], '\0'}, + {keyhlcolor[2], keyhlcolor[3], '\0'}, + {keyhlcolor[4], keyhlcolor[5], '\0'}, + {keyhlcolor[6], keyhlcolor[7], '\0'}}; uint32_t keyhl16[4] = {(strtol(strgroupsk[0], NULL, 16)), (strtol(strgroupsk[1], NULL, 16)), (strtol(strgroupsk[2], NULL, 16)), (strtol(strgroupsk[3], NULL, 16))}; - char strgroupsb[4][3] = {{bshlcolor[0], textcolor[1], '\0'}, - {bshlcolor[2], textcolor[3], '\0'}, - {bshlcolor[4], textcolor[5], '\0'}, - {bshlcolor[6], textcolor[7], '\0'}}; + char strgroupsb[4][3] = {{bshlcolor[0], bshlcolor[1], '\0'}, + {bshlcolor[2], bshlcolor[3], '\0'}, + {bshlcolor[4], bshlcolor[5], '\0'}, + {bshlcolor[6], bshlcolor[7], '\0'}}; uint32_t bshl16[4] = {(strtol(strgroupsb[0], NULL, 16)), (strtol(strgroupsb[1], NULL, 16)), (strtol(strgroupsb[2], NULL, 16)), (strtol(strgroupsb[3], NULL, 16))}; + char strgroupss[4][3] = {{separatorcolor[0], separatorcolor[1], '\0'}, + {separatorcolor[2], separatorcolor[3], '\0'}, + {separatorcolor[4], separatorcolor[5], '\0'}, + {separatorcolor[6], separatorcolor[7], '\0'}}; + uint32_t sep16[4] = {(strtol(strgroupss[0], NULL, 16)), + (strtol(strgroupss[1], NULL, 16)), + (strtol(strgroupss[2], NULL, 16)), + (strtol(strgroupss[3], NULL, 16))}; if (unlock_indicator && (unlock_state >= STATE_KEY_PRESSED || pam_state > STATE_PAM_IDLE)) { @@ -251,30 +260,12 @@ xcb_pixmap_t draw_image(uint32_t *resolution) { switch (pam_state) { case STATE_PAM_VERIFY: cairo_set_source_rgba(ctx, (double)insidever16[0]/255, (double)insidever16[1]/255, (double)insidever16[2]/255, (double)insidever16[3]/255); - if (internal_line_source == 2) { - line16[0] = insidever16[0]; - line16[1] = insidever16[1]; - line16[2] = insidever16[2]; - line16[3] = insidever16[3]; - } break; case STATE_PAM_WRONG: cairo_set_source_rgba(ctx, (double)insidewrong16[0]/255, (double)insidewrong16[1]/255, (double)insidewrong16[2]/255, (double)insidewrong16[3]/255); - if (internal_line_source == 2) { - line16[0] = insidewrong16[0]; - line16[1] = insidewrong16[1]; - line16[2] = insidewrong16[2]; - line16[3] = insidewrong16[3]; - } break; default: cairo_set_source_rgba(ctx, (double)inside16[0]/255, (double)inside16[1]/255, (double)inside16[2]/255, (double)inside16[3]/255); - if (internal_line_source == 2) { - line16[0] = inside16[0]; - line16[1] = inside16[1]; - line16[2] = inside16[2]; - line16[3] = inside16[3]; - } break; } cairo_fill_preserve(ctx); @@ -310,16 +301,18 @@ xcb_pixmap_t draw_image(uint32_t *resolution) { } cairo_stroke(ctx); - /* Draw an inner seperator line. */ - cairo_set_source_rgba(ctx, (double)line16[0]/255, (double)line16[1]/255, (double)line16[2]/255, (double)line16[3]/255); - cairo_set_line_width(ctx, 2.0); - cairo_arc(ctx, - BUTTON_CENTER /* x */, - BUTTON_CENTER /* y */, - BUTTON_RADIUS - 5 /* radius */, - 0, - 2 * M_PI); - cairo_stroke(ctx); + /* Draw an inner separator line. */ + if (internal_line_source != 2) { //pretty sure this only needs drawn if it's being drawn over the inside? + cairo_set_source_rgba(ctx, (double)line16[0]/255, (double)line16[1]/255, (double)line16[2]/255, (double)line16[3]/255); + cairo_set_line_width(ctx, 2.0); + cairo_arc(ctx, + BUTTON_CENTER /* x */, + BUTTON_CENTER /* y */, + BUTTON_RADIUS - 5 /* radius */, + 0, + 2 * M_PI); + cairo_stroke(ctx); + } cairo_set_line_width(ctx, 10.0); @@ -403,7 +396,7 @@ xcb_pixmap_t draw_image(uint32_t *resolution) { /* Draw two little separators for the highlighted part of the * unlock indicator. */ - cairo_set_source_rgba(ctx, (double)line16[0]/255, (double)line16[1]/255, (double)line16[2]/255, (double)line16[3]/255); + cairo_set_source_rgba(ctx, (double)sep16[0]/255, (double)sep16[1]/255, (double)sep16[2]/255, (double)sep16[3]/255); cairo_arc(ctx, BUTTON_CENTER /* x */, BUTTON_CENTER /* y */,