Add cmd option for ring color

pull/197/head
Theo Müller 2018-08-20 19:08:59 +01:00
parent f09bf1176a
commit 8cee298023
3 changed files with 42 additions and 4 deletions

View File

@ -59,6 +59,7 @@ typedef void (*ev_callback_t)(EV_P_ ev_timer *w, int revents);
static void input_done(void);
char color[7] = "ffffff";
char ring_color[7] = "337d00";
uint32_t last_resolution[2];
xcb_window_t win;
static xcb_cursor_t cursor;
@ -875,6 +876,7 @@ int main(int argc, char *argv[]) {
{"help", no_argument, NULL, 'h'},
{"no-unlock-indicator", no_argument, NULL, 'u'},
{"no-text", no_argument, NULL, 's'},
{"ring_color", required_argument, NULL, 'r'},
{"image", required_argument, NULL, 'i'},
{"tiling", no_argument, NULL, 't'},
{"ignore-empty-password", no_argument, NULL, 'e'},
@ -887,7 +889,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:fs";
char *optstring = "hvnbdc:p:ui:teI:fsr:";
while ((o = getopt_long(argc, argv, optstring, longopts, &longoptind)) != -1) {
switch (o) {
case 'v':
@ -917,6 +919,17 @@ int main(int argc, char *argv[]) {
break;
}
case 'r': {
char *arg = optarg;
if (arg[0] == '#')
arg++;
if (strlen(arg) != 6 || sscanf(arg, "%06[0-9a-fA-F]", ring_color) != 1)
errx(EXIT_FAILURE, "color is invalid, it must be given in 3-byte hexadecimal format: rrggbb\n");
break;
}
case 'u':
unlock_indicator = false;
break;
@ -950,7 +963,7 @@ int main(int argc, char *argv[]) {
break;
default:
errx(EXIT_FAILURE, "Syntax: i3lock [-v] [-n] [-b] [-d] [-c color] [-u] [-s] [-p win|default]"
" [-i image.png] [-t] [-e] [-I timeout] [-f]");
" [-r color] [-i image.png] [-t] [-e] [-I timeout] [-f]");
}
}
@ -1037,6 +1050,8 @@ int main(int argc, char *argv[]) {
load_compose_table(locale);
init_colors();
screen = xcb_setup_roots_iterator(xcb_get_setup(conn)).data;
init_dpi();

View File

@ -56,6 +56,8 @@ extern cairo_surface_t *img;
extern bool tile;
/* The background color to use (in hex). */
extern char color[7];
/* The color of the unlock circle */
extern char ring_color[7];
/* Whether to write text on the unlock indicator. */
extern bool write_text;
@ -75,6 +77,9 @@ extern xcb_screen_t *screen;
* Local variables.
******************************************************************************/
static float ring_colorf[3];
static float type_colorf[3];
/* Cache the screens visual, necessary for creating a Cairo context. */
static xcb_visualtype_t *vistype;
@ -83,6 +88,23 @@ static xcb_visualtype_t *vistype;
unlock_state_t unlock_state;
auth_state_t auth_state;
void init_colors(void) {
char strgroups[3][3] = {{ring_color[0], ring_color[1], '\0'},
{ring_color[2], ring_color[3], '\0'},
{ring_color[4], ring_color[5], '\0'}};
ring_colorf[0] = (float) strtol(strgroups[0], NULL, 16) / 255;
ring_colorf[1] = (float) strtol(strgroups[1], NULL, 16) / 255;
ring_colorf[2] = (float) strtol(strgroups[2], NULL, 16) / 255;
double P = sqrt(ring_color[0] * .3 * 256 + ring_color[1] * .6 * 256 + ring_color[2] * .1 * 256) / 255;
printf("%f", P);
type_colorf[0] = (P + (ring_colorf[0] - P) * 0.75) * 1.8;
type_colorf[1] = (P + (ring_colorf[1] - P) * 0.75) * 1.8;
type_colorf[2] = (P + (ring_colorf[2] - P) * 0.75) * 1.8;
}
/*
* Draws global image with fill color onto a pixmap with the given
* resolution and returns it.
@ -181,7 +203,7 @@ xcb_pixmap_t draw_image(uint32_t *resolution) {
break;
}
cairo_set_source_rgb(ctx, 51.0 / 255, 125.0 / 255, 0);
cairo_set_source_rgb(ctx, ring_colorf[0], ring_colorf[1], type_colorf[2]);
break;
}
cairo_stroke(ctx);
@ -280,7 +302,7 @@ xcb_pixmap_t draw_image(uint32_t *resolution) {
highlight_start + (M_PI / 3.0));
if (unlock_state == STATE_KEY_ACTIVE) {
/* For normal keys, we use a lighter green. */
cairo_set_source_rgb(ctx, 51.0 / 255, 219.0 / 255, 0);
cairo_set_source_rgb(ctx, type_colorf[0], type_colorf[1], type_colorf[2]);
} else {
/* For backspace, we use red. */
cairo_set_source_rgb(ctx, 219.0 / 255, 51.0 / 255, 0);

View File

@ -19,6 +19,7 @@ typedef enum {
STATE_I3LOCK_LOCK_FAILED = 4, /* i3lock failed to load */
} auth_state_t;
void init_colors(void);
xcb_pixmap_t draw_image(uint32_t* resolution);
void redraw_screen(void);
void clear_indicator(void);