summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorknolax <1339802534.kk@gmail.com>2017-07-17 12:15:58 -0400
committerknolax <1339802534.kk@gmail.com>2017-07-17 12:15:58 -0400
commit6fc239fdb0cfc9add7b683d83260dc19b9de3284 (patch)
tree1d59eaa97235ef2133e56427d5f8ec097440d280
parente1a0ee458f32fe5e61ed23fc71fd08af501998b7 (diff)
functional implementation of images for auth indicator state
-rw-r--r--i3lock.c32
-rw-r--r--unlock_indicator.c29
2 files changed, 41 insertions, 20 deletions
diff --git a/i3lock.c b/i3lock.c
index 826d27e..988c32e 100644
--- a/i3lock.c
+++ b/i3lock.c
@@ -86,7 +86,8 @@ static uint8_t xkb_base_event;
static uint8_t xkb_base_error;
cairo_surface_t *img = NULL; // image buffer to background image
-cairo_surface_t **auth_images = NULL; // array of image buffers to background image;
+cairo_surface_t *auth_images[5]; // array of image buffers to background image;
+bool use_auth_images = false;
bool tile = false;
bool ignore_empty_password = false;
bool skip_repeated_empty_password = false;
@@ -836,8 +837,8 @@ int main(int argc, char *argv[]) {
{"help", no_argument, NULL, 'h'},
{"no-unlock-indicator", no_argument, NULL, 'u'},
{"image", required_argument, NULL, 'i'},
- {"auth-image-indicator", required_argument, NULL, 'a'},
- {"keypress-image-indicator", required_argument, NULL, 'k'},
+ {"auth-image-dir", required_argument, NULL, 'a'},
+ {"keypress-image-dir", required_argument, NULL, 'k'},
{"tiling", no_argument, NULL, 't'},
{"ignore-empty-password", no_argument, NULL, 'e'},
{"inactivity-timeout", required_argument, NULL, 'I'},
@@ -849,7 +850,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:a:k:teI:f";
while ((o = getopt_long(argc, argv, optstring, longopts, &optind)) != -1) {
switch (o) {
case 'v':
@@ -915,7 +916,7 @@ int main(int argc, char *argv[]) {
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]");
+ " [-i image.png] [-a auth-image-dir] [-k keypress-image-dir] [-t] [-e] [-I timeout] [-f]");
}
}
@@ -1029,24 +1030,23 @@ int main(int argc, char *argv[]) {
//auth_image_path/{0-4}.png are required, corresponding to their auth_state_t states
//otherwise auth_images is set to null
if (auth_image_path) {
- //allocates 5 cairo_surface_t * to auth_images
- auth_images = calloc(sizeof(cairo_surface_t *) * 5);
+ use_auth_images = true;
int auth_image_counter = 0; // counter to loop through the states
- char * auth_img_path_buffer; // string to store the pathes of each image as it loads
- while (auth_image_counter < STATE_I3LOCK_LOCK_FAILED) {
- //allocates string of exactly 5chars larger tan auth_image_path, since $auth_image_counter.png is 5 chars;
- auth_img_path_buffer = calloc(strlen(auth_image_path) + 5);
- sprintf(auth_img_path_buffer,"%s%d%s",auth_image_path,auth_image_counter,".png");
+ char * auth_image_path_buffer; // string to store the pathes of each image as it loads
+ while (auth_image_counter <= STATE_I3LOCK_LOCK_FAILED) {
+ //allocates string of exactly 5chars larger tan auth_image_path, since /$auth_image_counter.png is 5 chars;
+ auth_image_path_buffer = calloc(strlen(auth_image_path) + 6,sizeof(char));
+ sprintf(auth_image_path_buffer,"%s%s%d%s",auth_image_path,"/",auth_image_counter,".png");
/* Create a pixmap to render on, fill it with the background color */
auth_images[auth_image_counter] = cairo_image_surface_create_from_png(auth_image_path_buffer);
/* In case loading failed, we just pretend no -i was specified. */
- if (cairo_surface_status(img) != CAIRO_STATUS_SUCCESS) {
+ if (cairo_surface_status(auth_images[auth_image_counter]) != CAIRO_STATUS_SUCCESS) {
fprintf(stderr, "Could not load image \"%s\": %s\n",
- image_path_buffer, cairo_status_to_string(cairo_surface_status(auth_images[auth_image_counter])));
- free(auth_images);
- auth_images = NULL;
+ auth_image_path_buffer, cairo_status_to_string(cairo_surface_status(auth_images[auth_image_counter])));
+ use_auth_images = false;
}
free(auth_image_path_buffer);
+ auth_image_counter++;
}
free(auth_image_path);
}
diff --git a/unlock_indicator.c b/unlock_indicator.c
index 4c7d0e9..cf7a391 100644
--- a/unlock_indicator.c
+++ b/unlock_indicator.c
@@ -50,8 +50,12 @@ extern char *modifier_string;
/* A Cairo surface containing the specified image (-i), if any. */
extern cairo_surface_t *img;
-
-/* Whether the image should be tiled. */
+/* array of Cairo surfaces containing the authorization status images (-a), if any. */
+extern cairo_surface_t * auth_images[5];
+extern bool use_auth_images;
+/* Path of directory containing indicator keypress images (-k), if any. */
+extern char * keypress_image_path;
+/*Whether the image should be tiled. */
extern bool tile;
/* The background color to use (in hex). */
extern char color[7];
@@ -139,8 +143,25 @@ xcb_pixmap_t draw_image(uint32_t *resolution) {
cairo_rectangle(xcb_ctx, 0, 0, resolution[0], resolution[1]);
cairo_fill(xcb_ctx);
}
-
- if (unlock_indicator &&
+ //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 (!tile) {
+ cairo_set_source_surface(xcb_ctx, auth_images[auth_state], 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(auth_images[auth_state]);
+ 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)) {
cairo_scale(ctx, scaling_factor(), scaling_factor());
/* Draw a (centered) circle with transparent background. */