summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorknolax <1339802534.kk@gmail.com>2017-07-17 11:42:40 -0400
committerknolax <1339802534.kk@gmail.com>2017-07-17 11:42:40 -0400
commite1a0ee458f32fe5e61ed23fc71fd08af501998b7 (patch)
tree9005bfdf44c812b4d1e84e11e3c2751a58c7dadd
parent3009ab422d136b8aefda080f585e51cd8d93b7fd (diff)
added image keypress and auth state indicator options, as well as loading of auth state indicator option images to auth_images
-rw-r--r--i3lock.c41
1 files changed, 40 insertions, 1 deletions
diff --git a/i3lock.c b/i3lock.c
index 87a77b1..826d27e 100644
--- a/i3lock.c
+++ b/i3lock.c
@@ -85,7 +85,8 @@ static struct xkb_compose_state *xkb_compose_state;
static uint8_t xkb_base_event;
static uint8_t xkb_base_error;
-cairo_surface_t *img = NULL;
+cairo_surface_t *img = NULL; // image buffer to background image
+cairo_surface_t **auth_images = NULL; // array of image buffers to background image;
bool tile = false;
bool ignore_empty_password = false;
bool skip_repeated_empty_password = false;
@@ -813,6 +814,10 @@ int main(int argc, char *argv[]) {
struct passwd *pw;
char *username;
char *image_path = NULL;
+ char * auth_image_path = NULL; // path to images to display as auth state indicator
+ //unlock_successs unlock fail etc...
+ char * keypress_image_path = NULL; // path to images to display on keypress
+ //goes through $keypress_image_path/0.png $keypress_image_path/1.png etc..
#ifndef __OpenBSD__
int ret;
struct pam_conv conv = {conv_callback, NULL};
@@ -831,6 +836,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'},
{"tiling", no_argument, NULL, 't'},
{"ignore-empty-password", no_argument, NULL, 'e'},
{"inactivity-timeout", required_argument, NULL, 'I'},
@@ -878,6 +885,12 @@ int main(int argc, char *argv[]) {
case 'i':
image_path = strdup(optarg);
break;
+ case 'a':
+ auth_image_path = strdup(optarg);
+ break;
+ case 'k':
+ keypress_image_path = strdup(optarg);
+ break;
case 't':
tile = true;
break;
@@ -1000,6 +1013,7 @@ int main(int argc, char *argv[]) {
xcb_change_window_attributes(conn, screen->root, XCB_CW_EVENT_MASK,
(uint32_t[]){XCB_EVENT_MASK_STRUCTURE_NOTIFY});
+ //loads background image for (-i)
if (image_path) {
/* Create a pixmap to render on, fill it with the background color */
img = cairo_image_surface_create_from_png(image_path);
@@ -1011,6 +1025,31 @@ int main(int argc, char *argv[]) {
}
free(image_path);
}
+ //loads images to use for authentification indicator states
+ //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);
+ 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");
+ /* 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) {
+ 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;
+ }
+ free(auth_image_path_buffer);
+ }
+ free(auth_image_path);
+ }
/* Pixmap on which the image is rendered to (if any) */
xcb_pixmap_t bg_pixmap = draw_image(last_resolution);