X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=i3lock.c;h=5a87999f6b4b666b4e5dfa8bd4371e4ba97f48ae;hb=e0213cb1f5be55e101406c2dec67ec2dc178c78c;hp=5d1da0162d3d0b290cffc03f50816fdfcffe9f11;hpb=e84a1203a65fed6d090d492aec6505fc6f250ae9;p=i3%2Fi3lock diff --git a/i3lock.c b/i3lock.c index 5d1da01..5a87999 100644 --- a/i3lock.c +++ b/i3lock.c @@ -172,10 +172,20 @@ static void clear_pam_wrong(EV_P_ ev_timer *w, int revents) { 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); @@ -195,6 +205,7 @@ static void input_done(void) { 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 @@ -242,8 +253,10 @@ static void handle_key_press(xcb_key_press_event_t *event) { 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. */ @@ -255,18 +268,21 @@ static void handle_key_press(xcb_key_press_event_t *event) { 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: @@ -306,7 +322,7 @@ static void handle_key_press(xcb_key_press_event_t *event) { /* 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(); @@ -479,6 +495,8 @@ static void xcb_check_cb(EV_P_ ev_check *w, int revents) { /* In the parent process, we exit */ if (fork() != 0) exit(0); + + ev_loop_fork(EV_DEFAULT); } break; @@ -542,7 +560,7 @@ int main(int argc, char *argv[]) { 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; }