diff options
Diffstat (limited to 'unlock_indicator.c')
-rw-r--r-- | unlock_indicator.c | 47 |
1 files changed, 42 insertions, 5 deletions
diff --git a/unlock_indicator.c b/unlock_indicator.c index cf7a391..bf0c31d 100644 --- a/unlock_indicator.c +++ b/unlock_indicator.c @@ -52,9 +52,12 @@ extern char *modifier_string; extern cairo_surface_t *img; /* array of Cairo surfaces containing the authorization status images (-a), if any. */ extern cairo_surface_t * auth_images[5]; +/*Switch on whether to use said images*/ extern bool use_auth_images; -/* Path of directory containing indicator keypress images (-k), if any. */ -extern char * keypress_image_path; +/* array of Cairo surfaces containing the keypress images (-k), if any. */ +extern cairo_surface_t * * keypress_images; +/*number of images, 0 if this option is turned off (-K)*/ +extern long num_keypress_images; /*Whether the image should be tiled. */ extern bool tile; /* The background color to use (in hex). */ @@ -83,7 +86,8 @@ static xcb_visualtype_t *vistype; * indicator. */ unlock_state_t unlock_state; auth_state_t auth_state; - +/*maintains which keypress image to use*/ +long keypress_image = 0; /* * Returns the scaling factor of the current screen. E.g., on a 227 DPI MacBook * Pro 13" Retina screen, the scaling factor is 227/96 = 2.36. @@ -143,9 +147,26 @@ xcb_pixmap_t draw_image(uint32_t *resolution) { cairo_rectangle(xcb_ctx, 0, 0, resolution[0], resolution[1]); cairo_fill(xcb_ctx); } + //increment and decrement the keypress_image used + if((num_keypress_images > 0)&&(unlock_state == STATE_KEY_ACTIVE)) { + keypress_image++; + if (keypress_image >= num_keypress_images) { + keypress_image = num_keypress_images - 1; + } + } + if((num_keypress_images > 0)&&(unlock_state == STATE_BACKSPACE_ACTIVE)) { + keypress_image--; + if (keypress_image < 0) { + keypress_image = 0; + } + } + //if an attempt failed. reset keypress_image + if (auth_state == STATE_AUTH_WRONG) { + keypress_image = 0; + } + //if auth images are used just draw the corresponding image - if (use_auth_images && unlock_indicator && - (unlock_state >= STATE_KEY_PRESSED || auth_state > STATE_AUTH_IDLE)) { + if (use_auth_images && unlock_indicator) { if (!tile) { cairo_set_source_surface(xcb_ctx, auth_images[auth_state], 0, 0); cairo_paint(xcb_ctx); @@ -160,6 +181,22 @@ xcb_pixmap_t draw_image(uint32_t *resolution) { cairo_pattern_destroy(pattern); } } + //if keypress images are used just draw the corresponding image + if ((num_keypress_images > 0) &&(unlock_state >= STATE_KEY_PRESSED)) { + if (!tile) { + cairo_set_source_surface(xcb_ctx, keypress_images[keypress_image], 0, 0); + cairo_paint(xcb_ctx); + } else { + /* create a pattern and fill a rectangle as big as the screen */ + cairo_pattern_t *pattern; + pattern = cairo_pattern_create_for_surface(keypress_images[keypress_image]); + cairo_set_source(xcb_ctx, pattern); + cairo_pattern_set_extend(pattern, CAIRO_EXTEND_REPEAT); + cairo_rectangle(xcb_ctx, 0, 0, resolution[0], resolution[1]); + cairo_fill(xcb_ctx); + cairo_pattern_destroy(pattern); + } + } //otherwise draw the circle indicator if ((!use_auth_images) && unlock_indicator && (unlock_state >= STATE_KEY_PRESSED || auth_state > STATE_AUTH_IDLE)) { |