#include <X11/XKBlib.h>
#include <X11/extensions/XKBfile.h>
#include <xkbcommon/xkbcommon.h>
-
-
-#ifndef NOLIBCAIRO
#include <cairo.h>
#include <cairo/cairo-xcb.h>
-#endif
#include "i3lock.h"
#include "xcb.h"
static struct xkb_context *xkb_context;
static struct xkb_keymap *xkb_keymap;
-#ifndef NOLIBCAIRO
cairo_surface_t *img = NULL;
bool tile = false;
-#endif
/* isutf, u8_dec © 2005 Jeff Bezanson, public domain */
#define isutf(c) (((c) & 0xC0) != 0x80)
clear_pam_wrong_timeout = NULL;
}
-static void input_done(void) {
- if (input_position == 0)
- return;
+static void clear_input(void) {
+ input_position = 0;
+ clear_password_memory();
+ password[input_position] = '\0';
+
+ /* Hide the unlock indicator after a bit if the password buffer is
+ * empty. */
+ start_clear_indicator_timeout();
+ unlock_state = STATE_BACKSPACE_ACTIVE;
+ redraw_screen();
+ unlock_state = STATE_KEY_PRESSED;
+}
+static void input_done(void) {
if (clear_pam_wrong_timeout) {
ev_timer_stop(main_loop, clear_pam_wrong_timeout);
free(clear_pam_wrong_timeout);
fprintf(stderr, "Authentication failure\n");
pam_state = STATE_PAM_WRONG;
+ clear_input();
redraw_screen();
/* Clear this state after 2 seconds (unless the user enters another
xkb_keysym_t ksym;
char buffer[128];
int n;
+ bool ctrl;
ksym = xkb_state_key_get_one_sym(xkb_state, event->detail);
+ ctrl = xkb_state_mod_name_is_active(xkb_state, "Control", XKB_STATE_MODS_DEPRESSED);
xkb_state_update_key(xkb_state, event->detail, XKB_KEY_DOWN);
/* The buffer will be null-terminated, so n >= 2 for 1 actual character. */
switch (ksym) {
case XKB_KEY_Return:
case XKB_KEY_KP_Enter:
+ case XKB_KEY_XF86ScreenSaver:
password[input_position] = '\0';
+ unlock_state = STATE_KEY_PRESSED;
+ redraw_screen();
input_done();
- case XKB_KEY_Escape:
- input_position = 0;
- clear_password_memory();
- password[input_position] = '\0';
+ return;
- /* Hide the unlock indicator after a bit if the password buffer is
- * empty. */
- start_clear_indicator_timeout();
- unlock_state = STATE_BACKSPACE_ACTIVE;
- redraw_screen();
- unlock_state = STATE_KEY_PRESSED;
+ case XKB_KEY_u:
+ if (ctrl) {
+ DEBUG("C-u pressed\n");
+ clear_input();
+ return;
+ }
+ break;
+
+ case XKB_KEY_Escape:
+ clear_input();
return;
case XKB_KEY_BackSpace:
/* store it in the password array as UTF-8 */
memcpy(password+input_position, buffer, n-1);
input_position += n-1;
- DEBUG("current password = %s\n", password);
+ DEBUG("current password = %.*s\n", input_position, password);
unlock_state = STATE_KEY_ACTIVE;
redraw_screen();
free(geom);
-#ifndef NOLIBCAIRO
redraw_screen();
-#endif
uint32_t mask = XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT;
xcb_configure_window(conn, win, mask, last_resolution);
/* In the parent process, we exit */
if (fork() != 0)
exit(0);
+
+ ev_loop_fork(EV_DEFAULT);
}
break;
int main(int argc, char *argv[]) {
char *username;
-#ifndef NOLIBCAIRO
char *image_path = NULL;
-#endif
int ret;
struct pam_conv conv = {conv_callback, NULL};
int curs_choice = CURS_NONE;
{"debug", no_argument, NULL, 0},
{"help", no_argument, NULL, 'h'},
{"no-unlock-indicator", no_argument, NULL, 'u'},
-#ifndef NOLIBCAIRO
{"image", required_argument, NULL, 'i'},
{"tiling", no_argument, NULL, 't'},
-#endif
{NULL, no_argument, NULL, 0}
};
if ((username = getenv("USER")) == NULL)
errx(1, "USER environment variable not set, please set it.\n");
- while ((o = getopt_long(argc, argv, "hvnbdc:p:u"
-#ifndef NOLIBCAIRO
- "i:t"
-#endif
- , longopts, &optind)) != -1) {
+ while ((o = getopt_long(argc, argv, "hvnbdc:p:ui:t", longopts, &optind)) != -1) {
switch (o) {
case 'v':
errx(EXIT_SUCCESS, "version " VERSION " © 2010-2012 Michael Stapelberg");
arg++;
if (strlen(arg) != 6 || sscanf(arg, "%06[0-9a-fA-F]", color) != 1)
- errx(1, "color is invalid, color must be given in 6-byte format: rrggbb\n");
+ errx(1, "color is invalid, it must be given in 3-byte hexadecimal format: rrggbb\n");
break;
}
case 'u':
unlock_indicator = false;
break;
-#ifndef NOLIBCAIRO
case 'i':
image_path = strdup(optarg);
break;
case 't':
tile = true;
break;
-#endif
case 'p':
if (!strcmp(optarg, "win")) {
curs_choice = CURS_WIN;
break;
default:
errx(1, "Syntax: i3lock [-v] [-n] [-b] [-d] [-c color] [-u] [-p win|default]"
-#ifndef NOLIBCAIRO
" [-i image.png] [-t]"
-#else
- " (compiled with NOLIBCAIRO)"
-#endif
);
}
}
xcb_change_window_attributes(conn, screen->root, XCB_CW_EVENT_MASK,
(uint32_t[]){ XCB_EVENT_MASK_STRUCTURE_NOTIFY });
-#ifndef NOLIBCAIRO
if (image_path) {
/* Create a pixmap to render on, fill it with the background color */
img = cairo_image_surface_create_from_png(image_path);
img = NULL;
}
}
-#endif
/* Pixmap on which the image is rendered to (if any) */
xcb_pixmap_t bg_pixmap = draw_image(last_resolution);