X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=i3lock.c;h=c49cc7668be66cded0f580a4c1fa0cf3621eba0f;hb=b33fd9dc9eb9beeb335436a66385d6c3c717c80a;hp=2bf3901bf82a792a9666653d7c99046b74975e50;hpb=bcbfee0a1777c301cd4b6e423b1212d718092355;p=i3%2Fi3lock diff --git a/i3lock.c b/i3lock.c index 2bf3901..c49cc76 100644 --- a/i3lock.c +++ b/i3lock.c @@ -40,12 +40,18 @@ #endif #include #include +#if defined(__linux__) +#include +#include +#include +#endif #include "i3lock.h" #include "xcb.h" #include "cursors.h" #include "unlock_indicator.h" #include "randr.h" +#include "dpi.h" #define TSTAMP_N_SECS(n) (n * 1.0) #define TSTAMP_N_MINS(n) (60 * TSTAMP_N_SECS(n)) @@ -330,7 +336,7 @@ static void input_done(void) { else if (strcmp(mod_name, XKB_MOD_NAME_NUM) == 0) mod_name = "Num Lock"; else if (strcmp(mod_name, XKB_MOD_NAME_LOGO) == 0) - mod_name = "Win"; + mod_name = "Super"; char *tmp; if (modifier_string == NULL) { @@ -444,6 +450,12 @@ static void handle_key_press(xcb_key_press_event_t *event) { return; default: skip_repeated_empty_password = false; + // A new password is being entered, but a previous one is pending. + // Discard the old one and clear the retry_verification flag. + if (retry_verification) { + retry_verification = false; + clear_input(); + } } switch (ksym) { @@ -655,7 +667,7 @@ static bool verify_png_image(const char *image_path) { // Check PNG header according to the specification, available at: // https://www.w3.org/TR/2003/REC-PNG-20031110/#5PNG-file-signature - static unsigned char PNG_REFERENCE_HEADER[8] = { 137, 80, 78, 71, 13, 10, 26, 10 }; + static unsigned char PNG_REFERENCE_HEADER[8] = {137, 80, 78, 71, 13, 10, 26, 10}; if (memcmp(PNG_REFERENCE_HEADER, png_header, sizeof(png_header)) != 0) { fprintf(stderr, "File \"%s\" does not start with a PNG header. i3lock currently only supports loading PNG files.\n", image_path); return false; @@ -859,6 +871,11 @@ int main(int argc, char *argv[]) { int ret; struct pam_conv conv = {conv_callback, NULL}; #endif +#if defined(__linux__) + bool lock_tty_switching = false; + int term = -1; +#endif + int curs_choice = CURS_NONE; int o; int longoptind = 0; @@ -877,6 +894,7 @@ int main(int argc, char *argv[]) { {"ignore-empty-password", no_argument, NULL, 'e'}, {"inactivity-timeout", required_argument, NULL, 'I'}, {"show-failed-attempts", no_argument, NULL, 'f'}, + {"lock-console", no_argument, NULL, 'l'}, {NULL, no_argument, NULL, 0}}; if ((pw = getpwuid(getuid())) == NULL) @@ -884,7 +902,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:teI:fl"; while ((o = getopt_long(argc, argv, optstring, longopts, &longoptind)) != -1) { switch (o) { case 'v': @@ -942,9 +960,16 @@ int main(int argc, char *argv[]) { case 'f': show_failed_attempts = true; break; + case 'l': +#if defined(__linux__) + lock_tty_switching = true; +#else + errx(EXIT_FAILURE, "TTY switch locking is only supported on Linux."); +#endif + 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] [-t] [-e] [-I timeout] [-f] [-l]"); } } @@ -1033,6 +1058,8 @@ int main(int argc, char *argv[]) { screen = xcb_setup_roots_iterator(xcb_get_setup(conn)).data; + init_dpi(); + randr_init(&randr_base, screen->root); randr_query(screen->root); @@ -1108,6 +1135,21 @@ int main(int argc, char *argv[]) { if (main_loop == NULL) errx(EXIT_FAILURE, "Could not initialize libev. Bad LIBEV_FLAGS?\n"); +#if defined(__linux__) + + /* Lock tty switching */ + if (lock_tty_switching) { + if ((term = open("/dev/console", O_RDWR)) == -1) { + perror("error locking TTY switching: opening console failed"); + } + + if (term != -1 && (ioctl(term, VT_LOCKSWITCH)) == -1) { + perror("error locking TTY switching: locking console failed"); + } + } + +#endif + /* Explicitly call the screen redraw in case "locking…" message was displayed */ auth_state = STATE_AUTH_IDLE; redraw_screen(); @@ -1135,6 +1177,18 @@ int main(int argc, char *argv[]) { return 0; } +#if defined(__linux__) + /* Restore tty switching */ + if (lock_tty_switching) { + if (term != -1 && (ioctl(term, VT_UNLOCKSWITCH)) == -1) { + perror("error unlocking TTY switching: unlocking console failed"); + } + + close(term); + } + +#endif + DEBUG("restoring focus to X11 window 0x%08x\n", stolen_focus); xcb_ungrab_pointer(conn, XCB_CURRENT_TIME); xcb_ungrab_keyboard(conn, XCB_CURRENT_TIME);