Esempio n. 1
0
static int
passwd_input_cb(WINDOW *wnd, void *data, int key)
{
  struct input *a = (struct input *) data;
  char ipc_buf[IPC_MQSIZ+1];

  memset(ipc_buf, '\0', IPC_MQSIZ+1);
  switch (key) {
    case UIKEY_ENTER:
      ui_thrd_suspend();
      memset(busy_str, '\0', BSTR_LEN+1);
      ui_ipc_msgsend(MQ_PW, a->input);
      clear_input(wnd, a);
      deactivate_input(pw_input);
      ui_thrd_resume();

      ui_ipc_msgrecv(MQ_IF, ipc_buf, 3);
      show_info_wnd(busywnd, "BUSY", ipc_buf, COLOR_PAIR(5), COLOR_PAIR(5), true, false);
      sleep(3);

      if (ui_ipc_getvalue(SEM_UI) > 0 &&
        ui_ipc_msgrecv(MQ_IF, ipc_buf, 3) > 0)
      {
        show_info_wnd(errwnd, "ERROR", ipc_buf, COLOR_PAIR(4), COLOR_PAIR(4), true, true);
        while (ui_wgetchtest(1500, '\n') != DOUI_KEY) { };
      }

      ui_thrd_suspend();
      set_txtwindow_active(busywnd, false);
      set_txtwindow_active(errwnd, false);
      activate_input(pw_input);
      ui_ipc_msgclear(MQ_IF);
      ui_thrd_resume();
      break;
    case UIKEY_BACKSPACE:
      del_input(wnd, a);
      break;
    case UIKEY_ESC:
      ui_thrd_suspend();
      clear_input(wnd, a);
      deactivate_input(pw_input);
      ui_thrd_resume();
      show_info_wnd(errwnd, "QUIT", "bye bye", COLOR_PAIR(5), COLOR_PAIR(5), true, true);
      sleep(2);
      return DOUI_ERR;
    case UIKEY_DOWN:
    case UIKEY_UP:
    case UIKEY_LEFT:
    case UIKEY_RIGHT:
      break;
    case UIKEY_ACTIVATE:
      break;
    default:
      ui_thrd_suspend();
      add_input(wnd, a, key);
      ui_thrd_resume();
  }
  return DOUI_OK;
}
Esempio n. 2
0
int
input_complex(struct Complex* complex) {
    printf("Enter real part: ");
    while (!scanf("%lf", &(complex->re))) {
        clear_input();
        printf("Input error! Try again: ");
    }
	clear_input();
    printf("Enter imaginary part: ");
    
    while (!scanf("%lf", &(complex->im))) {
        clear_input();
        printf("Input error! Try again: ");
    }
    clear_input();
    return 0;
}
Esempio n. 3
0
struct Complex
input_complex() {
    struct Complex complex;
    
    printf("Enter real part: ");
    while (!scanf("%lf", &complex.re)) {
        clear_input();
        printf("Input error! Try again: ");
    }
    clear_input();

    printf("Enter imaginary part: ");
    
    while (!scanf("%lf", &complex.im)) {
        clear_input();
        printf("Input error! Try again: ");
    }
    clear_input();

    return complex;
}
Esempio n. 4
0
static void input_done(void) {
    if (clear_pam_wrong_timeout) {
        ev_timer_stop(main_loop, clear_pam_wrong_timeout);
        free(clear_pam_wrong_timeout);
        clear_pam_wrong_timeout = NULL;
    }

    pam_state = STATE_PAM_VERIFY;
    redraw_screen();

    if (pam_authenticate(pam_handle, 0) == PAM_SUCCESS) {
        DEBUG("successfully authenticated\n");
        clear_password_memory();
	if (shell_auth_done_command) {
	  system(shell_auth_done_command);
	}
        exit(0);
    }
    else
    {
	if (shell_auth_fail_command) {
	    system(shell_auth_fail_command);
	}
    }

    if (debug_mode)
        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
     * password during that time). */
    ev_now_update(main_loop);
    if ((clear_pam_wrong_timeout = calloc(sizeof(struct ev_timer), 1))) {
        ev_timer_init(clear_pam_wrong_timeout, clear_pam_wrong, 2.0, 0.);
        ev_timer_start(main_loop, clear_pam_wrong_timeout);
    }

    /* Cancel the clear_indicator_timeout, it would hide the unlock indicator
     * too early. */
    stop_clear_indicator_timeout();

    /* beep on authentication failure, if enabled */
    if (beep) {
        xcb_bell(conn, 100);
        xcb_flush(conn);
    }
}
Esempio n. 5
0
static void input_done(void) {
    STOP_TIMER(clear_pam_wrong_timeout);
    pam_state = STATE_PAM_VERIFY;
    redraw_screen();

    if (pam_authenticate(pam_handle, 0) == PAM_SUCCESS) {
        DEBUG("successfully authenticated\n");
        clear_password_memory();
        /* Turn the screen on, as it may have been turned off
         * on release of the 'enter' key. */
        turn_monitors_on();

        /* PAM credentials should be refreshed, this will for example update any kerberos tickets.
         * Related to credentials pam_end() needs to be called to cleanup any temporary
         * credentials like kerberos /tmp/krb5cc_pam_* files which may of been left behind if the
         * refresh of the credentials failed. */
        pam_setcred(pam_handle, PAM_REFRESH_CRED);
        pam_end(pam_handle, PAM_SUCCESS);

        exit(0);
    }

    if (debug_mode)
        fprintf(stderr, "Authentication failure\n");

    pam_state = STATE_PAM_WRONG;
    failed_attempts += 1;
    clear_input();
    if (unlock_indicator)
        redraw_screen();

    /* Clear this state after 2 seconds (unless the user enters another
     * password during that time). */
    ev_now_update(main_loop);
    START_TIMER(clear_pam_wrong_timeout, TSTAMP_N_SECS(2), clear_pam_wrong);

    /* Cancel the clear_indicator_timeout, it would hide the unlock indicator
     * too early. */
    STOP_TIMER(clear_indicator_timeout);

    /* beep on authentication failure, if enabled */
    if (beep) {
        xcb_bell(conn, 100);
        xcb_flush(conn);
    }
}
Esempio n. 6
0
static void input_done(void) {
    STOP_TIMER(clear_pam_wrong_timeout);
    pam_state = STATE_PAM_VERIFY;
    redraw_screen();

    if (pam_authenticate(pam_handle, 0) == PAM_SUCCESS) {
        DEBUG("successfully authenticated\n");
        clear_password_memory();
        /* Turn the screen on, as it may have been turned off
         * on release of the 'enter' key. */
        turn_monitors_on();
        exit(0);
    }

    if (debug_mode)
        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
     * password during that time). */
    ev_now_update(main_loop);
    START_TIMER(clear_pam_wrong_timeout, TSTAMP_N_SECS(2), clear_pam_wrong);

    /* Cancel the clear_indicator_timeout, it would hide the unlock indicator
     * too early. */
    STOP_TIMER(clear_indicator_timeout);

    /* beep on authentication failure, if enabled */
    if (beep) {
        xcb_bell(conn, 100);
        xcb_flush(conn);
    }
}
Esempio n. 7
0
void poll_buttons(void) {
  SDL_Event event;
  while(SDL_PollEvent(&event)) {
    if (event.type == SDL_KEYDOWN) {
      switch (event.key.keysym.sym) {
        case SDLK_DOWN:
        #ifdef PAD_DEBUG
        printf("debug [%d]: DOWN key (down) press detected\n",debug_cnt);
        #endif
        set_input(1);
        break;

        case SDLK_UP:
        #ifdef PAD_DEBUG
        printf("debug [%d]: UP key press (down) detected\n",debug_cnt);
        #endif
        set_input(2);
        break;

        case SDLK_LEFT:
        #ifdef PAD_DEBUG
        printf("debug [%d]: LEFT key press (down) detected\n",debug_cnt);
        #endif
        set_input(3);
        break;

        case SDLK_RIGHT:
        #ifdef PAD_DEBUG
        printf("debug [%d]: RIGHT key press (down) detected\n",debug_cnt);
        #endif
        set_input(4);
        break;

        case SDLK_LCTRL:
        #ifdef PAD_DEBUG
        printf("debug [%d]: LCTRL (NES -> start) key (down) press detected\n",debug_cnt);
        #endif
        set_input(5);
        break;

        case SDLK_LSHIFT:
        #ifdef PAD_DEBUG
        printf("debug [%d]: LSHIFT (NES -> select) key (down) press detected\n",debug_cnt);
        #endif
        set_input(6);
        break;

        case SDLK_p:
        if(pause_emulation) {
          printf("[*] LameNES continue emulation!\n");
          CPU_is_running = 1;
          pause_emulation = 0;
        } else if(!pause_emulation) {
          printf("[*] LameNES paused!\n");
          CPU_is_running = 0;
          pause_emulation = 1;
        }
        break;

        case SDLK_x:
        #ifdef PAD_DEBUG
        printf("debug [%d]: Z (NES -> A) key (down) press detected\n",debug_cnt);
        #endif
        set_input(7);
        break;

        case SDLK_z:
        #ifdef PAD_DEBUG
        printf("debug [%d]: X (NES -> B) key (down) press detected\n",debug_cnt);
        #endif
        set_input(8);
        break;

        case SDLK_q:
        #ifdef PAD_DEBUG
        printf("debug [%d]: Q (quit lamenes) key (down) press detected\n",debug_cnt);
        #endif
        quit_emulation();
        break;

        case SDLK_ESCAPE:
        #ifdef PAD_DEBUG
        printf("debug [%d]: ESC (quit lamenes) key (down) press detected\n",debug_cnt);
        #endif
        quit_emulation();
        break;

        case SDLK_F1:
        /* reset */
        reset_emulation();
        break;

        case SDLK_F3:
        /* load state */
        load_state();
        break;

        case SDLK_F6:
        /* save state */
        save_state();
        break;

        case SDLK_F10:
        if(enable_background == 1) {
          enable_background = 0;
        } else {
          enable_background = 1;
        }
        break;

        case SDLK_F11:
        if(enable_sprites == 1) {
          enable_sprites = 0;
        } else {
          enable_sprites = 1;
        }
        break;

        case SDLK_F12:
        if(startdebugger > 0) {
          disassemble = 1;
          hit_break = 1;
          debugger();
        }
        break;

        default:
        break;
      }
    }

    if(event.type == SDL_KEYUP) {
      switch(event.key.keysym.sym){
        case SDLK_DOWN:
        #ifdef PAD_DEBUG
        printf("debug [%d]: DOWN key (up) press detected\n",debug_cnt);
        #endif
        clear_input(1);
        break;

        case SDLK_UP:
        #ifdef PAD_DEBUG
        printf("debug [%d]: UP key (up) press detected\n",debug_cnt);
        #endif
        clear_input(2);
        break;

        case SDLK_LEFT:
        #ifdef PAD_DEBUG
        printf("debug [%d]: LEFT key (up) press detected\n",debug_cnt);
        #endif
        clear_input(3);
        break;

        case SDLK_RIGHT:
        #ifdef PAD_DEBUG
        printf("debug [%d]: RIGHT key (up) press detected\n",debug_cnt);
        #endif
        clear_input(4);
        break;

        case SDLK_LCTRL:
        #ifdef PAD_DEBUG
        printf("debug [%d]: LCTRL (NES -> start) key (up) press detected\n",debug_cnt);
        #endif
        clear_input(5);
        break;

        case SDLK_LSHIFT:
        #ifdef PAD_DEBUG
        printf("debug [%d]: LSHIFT (NES -> select) key (up) press detected\n",debug_cnt);
        #endif
        clear_input(6);
        break;

        case SDLK_x:
        #ifdef PAD_DEBUG
        printf("debug [%d]: Z (NES -> A) key (up) press detected\n",debug_cnt);
        #endif
        clear_input(7);
        break;

        case SDLK_z:
        #ifdef PAD_DEBUG
        printf("debug [%d]: X (NES -> B) key (up) press detected\n",debug_cnt);
        #endif
        clear_input(8);
        break;

        default:
        break;
      }
    }
  }
}
Esempio n. 8
0
/*
 * Handle key presses. Fixes state, then looks up the key symbol for the
 * given keycode, then looks up the key symbol (as UCS-2), converts it to
 * UTF-8 and stores it in the password array.
 *
 */
static void handle_key_press(xcb_key_press_event_t *event) {
    xkb_keysym_t ksym;
    char buffer[128];
    int n;
    bool ctrl;
    bool composed = false;

    ksym = xkb_state_key_get_one_sym(xkb_state, event->detail);
    ctrl = xkb_state_mod_name_is_active(xkb_state, XKB_MOD_NAME_CTRL, XKB_STATE_MODS_DEPRESSED);

    /* The buffer will be null-terminated, so n >= 2 for 1 actual character. */
    memset(buffer, '\0', sizeof(buffer));

    if (xkb_compose_state && xkb_compose_state_feed(xkb_compose_state, ksym) == XKB_COMPOSE_FEED_ACCEPTED) {
        switch (xkb_compose_state_get_status(xkb_compose_state)) {
        case XKB_COMPOSE_NOTHING:
            break;
        case XKB_COMPOSE_COMPOSING:
            return;
        case XKB_COMPOSE_COMPOSED:
            /* xkb_compose_state_get_utf8 doesn't include the terminating byte in the return value
            * as xkb_keysym_to_utf8 does. Adding one makes the variable n consistent. */
            n = xkb_compose_state_get_utf8(xkb_compose_state, buffer, sizeof(buffer)) + 1;
            ksym = xkb_compose_state_get_one_sym(xkb_compose_state);
            composed = true;
            break;
        case XKB_COMPOSE_CANCELLED:
            xkb_compose_state_reset(xkb_compose_state);
            return;
        }
    }

    if (!composed) {
        n = xkb_keysym_to_utf8(ksym, buffer, sizeof(buffer));
    }

    switch (ksym) {
    case XKB_KEY_Return:
    case XKB_KEY_KP_Enter:
    case XKB_KEY_XF86ScreenSaver:
        if (pam_state == STATE_PAM_WRONG)
            return;

        if (skip_without_validation()) {
            clear_input();
            return;
        }
        password[input_position] = '\0';
        unlock_state = STATE_KEY_PRESSED;
        redraw_screen();
        input_done();
        skip_repeated_empty_password = true;
        return;
    default:
        skip_repeated_empty_password = false;
    }

    switch (ksym) {
    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:
        if (input_position == 0)
            return;

        /* decrement input_position to point to the previous glyph */
        u8_dec(password, &input_position);
        password[input_position] = '\0';

        /* Hide the unlock indicator after a bit if the password buffer is
        * empty. */
        START_TIMER(clear_indicator_timeout, 1.0, clear_indicator_cb);
        unlock_state = STATE_BACKSPACE_ACTIVE;
        redraw_screen();
        unlock_state = STATE_KEY_PRESSED;
        return;
    }

    if ((input_position + 8) >= sizeof(password))
        return;

#if 0
    /* FIXME: handle all of these? */
    printf("is_keypad_key = %d\n", xcb_is_keypad_key(sym));
    printf("is_private_keypad_key = %d\n", xcb_is_private_keypad_key(sym));
    printf("xcb_is_cursor_key = %d\n", xcb_is_cursor_key(sym));
    printf("xcb_is_pf_key = %d\n", xcb_is_pf_key(sym));
    printf("xcb_is_function_key = %d\n", xcb_is_function_key(sym));
    printf("xcb_is_misc_function_key = %d\n", xcb_is_misc_function_key(sym));
    printf("xcb_is_modifier_key = %d\n", xcb_is_modifier_key(sym));
#endif

    if (n < 2)
        return;

    /* 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", input_position, password);

    if (unlock_indicator) {
        unlock_state = STATE_KEY_ACTIVE;
        redraw_screen();
        unlock_state = STATE_KEY_PRESSED;

        struct ev_timer *timeout = NULL;
        START_TIMER(timeout, TSTAMP_N_SECS(0.25), redraw_timeout);
        STOP_TIMER(clear_indicator_timeout);
    }

    START_TIMER(discard_passwd_timeout, TSTAMP_N_MINS(3), discard_passwd_cb);
}
Esempio n. 9
0
static void input_done(void) {
    STOP_TIMER(clear_pam_wrong_timeout);
    pam_state = STATE_PAM_VERIFY;
    redraw_screen();

    if (pam_authenticate(pam_handle, 0) == PAM_SUCCESS) {
        DEBUG("successfully authenticated\n");
        clear_password_memory();

        /* PAM credentials should be refreshed, this will for example update any kerberos tickets.
         * Related to credentials pam_end() needs to be called to cleanup any temporary
         * credentials like kerberos /tmp/krb5cc_pam_* files which may of been left behind if the
         * refresh of the credentials failed. */
        pam_setcred(pam_handle, PAM_REFRESH_CRED);
        pam_end(pam_handle, PAM_SUCCESS);

        exit(0);
    }

    if (debug_mode)
        fprintf(stderr, "Authentication failure\n");

    /* Get state of Caps and Num lock modifiers, to be displayed in
     * STATE_PAM_WRONG state */
    xkb_mod_index_t idx, num_mods;
    const char *mod_name;

    num_mods = xkb_keymap_num_mods(xkb_keymap);

    for (idx = 0; idx < num_mods; idx++) {
        if (!xkb_state_mod_index_is_active(xkb_state, idx, XKB_STATE_MODS_EFFECTIVE))
            continue;

        mod_name = xkb_keymap_mod_get_name(xkb_keymap, idx);
        if (mod_name == NULL)
            continue;

        /* Replace certain xkb names with nicer, human-readable ones. */
        if (strcmp(mod_name, XKB_MOD_NAME_CAPS) == 0)
            mod_name = "Caps Lock";
        else if (strcmp(mod_name, XKB_MOD_NAME_ALT) == 0)
            mod_name = "Alt";
        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";

        char *tmp;
        if (modifier_string == NULL) {
            if (asprintf(&tmp, "%s", mod_name) != -1)
                modifier_string = tmp;
        } else if (asprintf(&tmp, "%s, %s", modifier_string, mod_name) != -1) {
            free(modifier_string);
            modifier_string = tmp;
        }
    }

    pam_state = STATE_PAM_WRONG;
    failed_attempts += 1;
    clear_input();
    if (unlock_indicator)
        redraw_screen();

    /* Skip all the events during the pam verification to avoid bad people
     * spamming keys and locking pam in an endless validation loop */
    xcb_generic_event_t *ev = xcb_poll_for_event(conn);
    free(ev);
    while (ev != NULL)
    {
        ev = xcb_poll_for_queued_event(conn);
        free(ev);
    }

    /* Clear this state after 2 seconds (unless the user enters another
     * password during that time). */
    ev_now_update(main_loop);
    START_TIMER(clear_pam_wrong_timeout, TSTAMP_N_SECS(2), clear_pam_wrong);

    /* Cancel the clear_indicator_timeout, it would hide the unlock indicator
     * too early. */
    STOP_TIMER(clear_indicator_timeout);

    /* beep on authentication failure, if enabled */
    if (beep) {
        xcb_bell(conn, 100);
        xcb_flush(conn);
    }
}
Esempio n. 10
0
static void discard_passwd_cb(EV_P_ ev_timer *w, int revents) {
    clear_input();
    STOP_TIMER(discard_passwd_timeout);
}
Esempio n. 11
0
void
wait_user_reaction() {
    printf("Press any key to continue...\n");
    clear_input();
}
Esempio n. 12
0
int main() {
    struct Complex *complex = (struct Complex *) calloc(COMPLEX_SIZE_DEFAULT, sizeof(struct Complex));
    int size = COMPLEX_SIZE_DEFAULT;
    int count_of_elements = COMPLEX_SIZE_DEFAULT;
    
    struct Complex c1, c2, result;

    complex[0].re = COMPLEX1_RE;
    complex[0].im = COMPLEX1_IM;
    complex[1].re = COMPLEX2_RE;
    complex[1].im = COMPLEX2_IM;

    c1.re = COMPLEX1_RE;
    c1.im = COMPLEX1_IM;
    c2.re = COMPLEX2_RE;
    c2.im = COMPLEX2_IM;

    while (1) {
        char ch;
		print_main_menu(c1, c2);
        ch = getchar();
        clear_input();
        switch (ch) {
        case '1':
        {
            int index = 0;
            change_complex_interface(&c1, complex, count_of_elements);
            break;
        }
        case '2':
        {
            int index = 1;
            change_complex_interface(&c2, complex, count_of_elements);
            break;
        }
        case 'a':
        case 'A':
            result = add(c1, c2);
            print_complex(result);
            break;
        case 's':
        case 'S':
            result = sub(c1, c2);
            print_complex(result);
            break;
        case 'm':
        case 'M':
            result = mul(c1, c2);
            print_complex(result);
            break;
        case 'd':
        case 'D':
			{
				int error = 0;
				result = division(c1, c2, &error);
				if (!error)
					print_complex(result);
			break;
			}
        case 'r':
        case 'R':
            complex = read_file_interface(complex, &size, &count_of_elements);
            break;
        case 'w':
        case 'W':
            complex = write_file_interface(complex, &size, &count_of_elements);
            break;
        case 'q':
        case 'Q':
            return 0;
        default:
            printf("Incorrect input, please choose an existing element\n");
        }
    }
    return 0;
}
Esempio n. 13
0
Chip8_Input::Chip8_Input() { clear_input(); }
Esempio n. 14
0
/*
 * Handle key presses. Fixes state, then looks up the key symbol for the
 * given keycode, then looks up the key symbol (as UCS-2), converts it to
 * UTF-8 and stores it in the password array.
 *
 */
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. */
    memset(buffer, '\0', sizeof(buffer));
    n = xkb_keysym_to_utf8(ksym, buffer, sizeof(buffer));

    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();
        return;

    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:
        if (input_position == 0)
            return;

        /* decrement input_position to point to the previous glyph */
        u8_dec(password, &input_position);
        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;
        return;
    }

    if ((input_position + 8) >= sizeof(password))
        return;

#if 0
    /* FIXME: handle all of these? */
    printf("is_keypad_key = %d\n", xcb_is_keypad_key(sym));
    printf("is_private_keypad_key = %d\n", xcb_is_private_keypad_key(sym));
    printf("xcb_is_cursor_key = %d\n", xcb_is_cursor_key(sym));
    printf("xcb_is_pf_key = %d\n", xcb_is_pf_key(sym));
    printf("xcb_is_function_key = %d\n", xcb_is_function_key(sym));
    printf("xcb_is_misc_function_key = %d\n", xcb_is_misc_function_key(sym));
    printf("xcb_is_modifier_key = %d\n", xcb_is_modifier_key(sym));
#endif

    if (n < 2)
        return;

    /* 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", input_position, password);

    unlock_state = STATE_KEY_ACTIVE;
    redraw_screen();
    unlock_state = STATE_KEY_PRESSED;

    struct ev_timer *timeout = calloc(sizeof(struct ev_timer), 1);
    if (timeout) {
        ev_timer_init(timeout, redraw_timeout, 0.25, 0.);
        ev_timer_start(main_loop, timeout);
    }

    stop_clear_indicator_timeout();
}
Esempio n. 15
0
/*
 * Handle key presses. Fixes state, then looks up the key symbol for the
 * given keycode, then looks up the key symbol (as UCS-2), converts it to
 * UTF-8 and stores it in the password array.
 *
 */
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);

    /* The buffer will be null-terminated, so n >= 2 for 1 actual character. */
    memset(buffer, '\0', sizeof(buffer));
    n = xkb_keysym_to_utf8(ksym, buffer, sizeof(buffer));

    switch (ksym) {
    case XKB_KEY_Return:
    case XKB_KEY_KP_Enter:
    case XKB_KEY_XF86ScreenSaver:
        if (skip_without_validation()) {
            clear_input();
            return;
        }
        password[input_position] = '\0';
        unlock_state = STATE_KEY_PRESSED;
        redraw_screen();
        input_done();
        skip_repeated_empty_password = true;
        return;
    default:
        skip_repeated_empty_password = false;
    }

    switch (ksym) {
    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:
        if (input_position == 0)
            return;

        /* decrement input_position to point to the previous glyph */
        u8_dec(password, &input_position);
        password[input_position] = '\0';

        /* Hide the unlock indicator after a bit if the password buffer is
         * empty. */
        START_TIMER(clear_indicator_timeout, 1.0, clear_indicator_cb);
        unlock_state = STATE_BACKSPACE_ACTIVE;
        redraw_screen();
        unlock_state = STATE_KEY_PRESSED;
        return;
    }

    if ((input_position + 8) >= sizeof(password))
        return;

#if 0
    /* FIXME: handle all of these? */
    printf("is_keypad_key = %d\n", xcb_is_keypad_key(sym));
    printf("is_private_keypad_key = %d\n", xcb_is_private_keypad_key(sym));
    printf("xcb_is_cursor_key = %d\n", xcb_is_cursor_key(sym));
    printf("xcb_is_pf_key = %d\n", xcb_is_pf_key(sym));
    printf("xcb_is_function_key = %d\n", xcb_is_function_key(sym));
    printf("xcb_is_misc_function_key = %d\n", xcb_is_misc_function_key(sym));
    printf("xcb_is_modifier_key = %d\n", xcb_is_modifier_key(sym));
#endif

    if (n < 2)
        return;

    /* 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", input_position, password);

    unlock_state = STATE_KEY_ACTIVE;
    redraw_screen();
    unlock_state = STATE_KEY_PRESSED;

    struct ev_timer *timeout = NULL;
    START_TIMER(timeout, TSTAMP_N_SECS(0.25), redraw_timeout);
    STOP_TIMER(clear_indicator_timeout);
    START_TIMER(discard_passwd_timeout, TSTAMP_N_MINS(3), discard_passwd_cb);
}