mirror of
https://github.com/Raymo111/i3lock-color.git
synced 2024-11-11 13:50:52 -05:00
add a couple options for drawing the line color
This commit is contained in:
parent
986608a1fb
commit
cf522a301f
2 changed files with 69 additions and 16 deletions
46
i3lock.c
46
i3lock.c
|
@ -57,6 +57,8 @@ char linecolor[9] = "000000ff";
|
|||
char textcolor[9] = "000000ff";
|
||||
char keyhlcolor[9] = "33db00ff";
|
||||
char bshlcolor[9] = "db3300ff";
|
||||
/* 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;
|
||||
|
||||
int inactivity_timeout = 30;
|
||||
uint32_t last_resolution[2];
|
||||
|
@ -772,17 +774,19 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
/* options for unlock indicator colors */
|
||||
// defining a lot of different chars here for the options -- TODO find a nicer way for this, maybe not offering single character options at all
|
||||
{"insidevercolor", required_argument, NULL, 0},
|
||||
{"insidewrongcolor", required_argument, NULL, 0},
|
||||
{"insidecolor", required_argument, NULL, 0},
|
||||
{"ringvercolor", required_argument, NULL, 0},
|
||||
{"ringwrongcolor", required_argument, NULL, 0},
|
||||
{"ringcolor", required_argument, NULL, 0},
|
||||
{"linecolor", required_argument, NULL, 0},
|
||||
{"textcolor", required_argument, NULL, 0},
|
||||
{"keyhlcolor", required_argument, NULL, 0},
|
||||
{"bshlcolor", required_argument, NULL, 0},
|
||||
|
||||
{"insidevercolor", required_argument, NULL, 0}, // --i-v
|
||||
{"insidewrongcolor", required_argument, NULL, 0}, // --i-w
|
||||
{"insidecolor", required_argument, NULL, 0}, // --i-c
|
||||
{"ringvercolor", required_argument, NULL, 0}, // --r-v
|
||||
{"ringwrongcolor", required_argument, NULL, 0}, // --r-w
|
||||
{"ringcolor", required_argument, NULL, 0}, // --r-c
|
||||
{"linecolor", required_argument, NULL, 0}, // --l-c
|
||||
{"textcolor", required_argument, NULL, 0}, // --t-c
|
||||
{"keyhlcolor", required_argument, NULL, 0}, // --k-c
|
||||
{"bshlcolor", required_argument, NULL, 0}, // --b-c
|
||||
{"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 */
|
||||
{"ignore-empty-password", no_argument, NULL, 'e'},
|
||||
{"inactivity-timeout", required_argument, NULL, 'I'},
|
||||
{"show-failed-attempts", no_argument, NULL, 'f'},
|
||||
|
@ -793,7 +797,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:f";
|
||||
char *optstring = "hvnbdc:p:ui:teI:frs";
|
||||
while ((o = getopt_long(argc, argv, optstring, longopts, &optind)) != -1) {
|
||||
switch (o) {
|
||||
case 'v':
|
||||
|
@ -847,6 +851,18 @@ int main(int argc, char *argv[]) {
|
|||
case 'e':
|
||||
ignore_empty_password = true;
|
||||
break;
|
||||
case 'r':
|
||||
if (internal_line_source != 0) {
|
||||
errx(EXIT_FAILURE, "i3lock-color: Options line-uses-ring and line-uses-inside conflict.");
|
||||
}
|
||||
internal_line_source = 1; //sets the line drawn inside to use the inside color when drawn
|
||||
break;
|
||||
case 's':
|
||||
if (internal_line_source != 0) {
|
||||
errx(EXIT_FAILURE, "i3lock-color: Options line-uses-ring and line-uses-inside conflict.");
|
||||
}
|
||||
internal_line_source = 2;
|
||||
break;
|
||||
case 0:
|
||||
if (strcmp(longopts[optind].name, "debug") == 0)
|
||||
debug_mode = true;
|
||||
|
@ -955,8 +971,8 @@ int main(int argc, char *argv[]) {
|
|||
show_failed_attempts = true;
|
||||
break;
|
||||
default:
|
||||
errx(EXIT_FAILURE, "Syntax: i3lock [-v] [-n] [-b] [-d] [-c color] [-u] [-p win|default]"
|
||||
" [-i image.png] [-t] [-e] [-I timeout] [-f]");
|
||||
errx(EXIT_FAILURE, "Syntax: i3lock-color [-v] [-n] [-b] [-d] [-c color] [-u] [-p win|default]"
|
||||
" [-i image.png] [-t] [-e] [-I timeout] [-f] [-r|s]");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -965,7 +981,7 @@ int main(int argc, char *argv[]) {
|
|||
srand(time(NULL));
|
||||
|
||||
/* Initialize PAM */
|
||||
if ((ret = pam_start("i3lock", username, &conv, &pam_handle)) != PAM_SUCCESS)
|
||||
if ((ret = pam_start("i3lock-color", username, &conv, &pam_handle)) != PAM_SUCCESS)
|
||||
errx(EXIT_FAILURE, "PAM: %s", pam_strerror(pam_handle, ret));
|
||||
|
||||
if ((ret = pam_set_item(pam_handle, PAM_TTY, getenv("DISPLAY"))) != PAM_SUCCESS)
|
||||
|
|
|
@ -66,6 +66,7 @@ extern char linecolor[9];
|
|||
extern char textcolor[9];
|
||||
extern char keyhlcolor[9];
|
||||
extern char bshlcolor[9];
|
||||
extern int internal_line_source;
|
||||
|
||||
/* Whether the failed attempts should be displayed. */
|
||||
extern bool show_failed_attempts;
|
||||
|
@ -250,12 +251,30 @@ 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);
|
||||
|
@ -263,12 +282,30 @@ xcb_pixmap_t draw_image(uint32_t *resolution) {
|
|||
switch (pam_state) {
|
||||
case STATE_PAM_VERIFY:
|
||||
cairo_set_source_rgba(ctx, (double)ringver16[0]/255, (double)ringver16[1]/255, (double)ringver16[2]/255, (double)ringver16[3]/255);
|
||||
if (internal_line_source == 1) {
|
||||
line16[0] = ringver16[0];
|
||||
line16[1] = ringver16[1];
|
||||
line16[2] = ringver16[2];
|
||||
line16[3] = ringver16[3];
|
||||
}
|
||||
break;
|
||||
case STATE_PAM_WRONG:
|
||||
cairo_set_source_rgba(ctx, (double)ringwrong16[0]/255, (double)ringwrong16[1]/255, (double)ringwrong16[2]/255, (double)ringwrong16[3]/255);
|
||||
if (internal_line_source == 1) {
|
||||
line16[0] = ringwrong16[0];
|
||||
line16[1] = ringwrong16[1];
|
||||
line16[2] = ringwrong16[2];
|
||||
line16[3] = ringwrong16[3];
|
||||
}
|
||||
break;
|
||||
case STATE_PAM_IDLE:
|
||||
cairo_set_source_rgba(ctx, (double)ring16[0]/255, (double)ring16[1]/255, (double)ring16[2]/255, (double)ring16[3]/255);
|
||||
if (internal_line_source == 1) {
|
||||
line16[0] = ring16[0];
|
||||
line16[1] = ring16[1];
|
||||
line16[2] = ring16[2];
|
||||
line16[3] = ring16[3];
|
||||
}
|
||||
break;
|
||||
}
|
||||
cairo_stroke(ctx);
|
||||
|
@ -308,7 +345,7 @@ xcb_pixmap_t draw_image(uint32_t *resolution) {
|
|||
snprintf(buf, sizeof(buf), "%d", failed_attempts);
|
||||
text = buf;
|
||||
}
|
||||
cairo_set_source_rgb(ctx, 1, 0, 0);
|
||||
cairo_set_source_rgba(ctx, (double)text16[0]/255, (double)text16[1]/255, (double)text16[2]/255, (double)text16[3]/255);
|
||||
cairo_set_font_size(ctx, 32.0);
|
||||
}
|
||||
break;
|
||||
|
|
Loading…
Reference in a new issue