Merge pull request #2121 from martinetd/swaylock-ctrl-u

swaylock: implement ^U to clear buffer
This commit is contained in:
emersion 2018-06-08 16:03:50 +01:00 committed by GitHub
commit c65c84444e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 57 deletions

View file

@ -2,36 +2,12 @@
#define _SWAYLOCK_SEAT_H #define _SWAYLOCK_SEAT_H
#include <xkbcommon/xkbcommon.h> #include <xkbcommon/xkbcommon.h>
enum mod_bit {
MOD_SHIFT = 1<<0,
MOD_CAPS = 1<<1,
MOD_CTRL = 1<<2,
MOD_ALT = 1<<3,
MOD_MOD2 = 1<<4,
MOD_MOD3 = 1<<5,
MOD_LOGO = 1<<6,
MOD_MOD5 = 1<<7,
};
enum mask {
MASK_SHIFT,
MASK_CAPS,
MASK_CTRL,
MASK_ALT,
MASK_MOD2,
MASK_MOD3,
MASK_LOGO,
MASK_MOD5,
MASK_LAST
};
struct swaylock_xkb { struct swaylock_xkb {
uint32_t modifiers;
bool caps_lock; bool caps_lock;
bool control;
struct xkb_state *state; struct xkb_state *state;
struct xkb_context *context; struct xkb_context *context;
struct xkb_keymap *keymap; struct xkb_keymap *keymap;
xkb_mod_mask_t masks[MASK_LAST];
}; };
extern const struct wl_seat_listener seat_listener; extern const struct wl_seat_listener seat_listener;

View file

@ -139,6 +139,14 @@ void swaylock_handle_key(struct swaylock_state *state,
state->auth_state = AUTH_STATE_INPUT_NOP; state->auth_state = AUTH_STATE_INPUT_NOP;
damage_state(state); damage_state(state);
break; break;
case XKB_KEY_u:
if (state->xkb.control) {
clear_password_buffer(&state->password);
state->auth_state = AUTH_STATE_CLEAR;
damage_state(state);
break;
}
// fallthrough
default: default:
if (codepoint) { if (codepoint) {
append_ch(&state->password, codepoint); append_ch(&state->password, codepoint);

View file

@ -7,28 +7,6 @@
#include "swaylock/swaylock.h" #include "swaylock/swaylock.h"
#include "swaylock/seat.h" #include "swaylock/seat.h"
const char *XKB_MASK_NAMES[MASK_LAST] = {
XKB_MOD_NAME_SHIFT,
XKB_MOD_NAME_CAPS,
XKB_MOD_NAME_CTRL,
XKB_MOD_NAME_ALT,
"Mod2",
"Mod3",
XKB_MOD_NAME_LOGO,
"Mod5",
};
const enum mod_bit XKB_MODS[MASK_LAST] = {
MOD_SHIFT,
MOD_CAPS,
MOD_CTRL,
MOD_ALT,
MOD_MOD2,
MOD_MOD3,
MOD_LOGO,
MOD_MOD5
};
static void keyboard_keymap(void *data, struct wl_keyboard *wl_keyboard, static void keyboard_keymap(void *data, struct wl_keyboard *wl_keyboard,
uint32_t format, int32_t fd, uint32_t size) { uint32_t format, int32_t fd, uint32_t size) {
struct swaylock_state *state = data; struct swaylock_state *state = data;
@ -84,16 +62,13 @@ static void keyboard_modifiers(void *data, struct wl_keyboard *wl_keyboard,
uint32_t mods_locked, uint32_t group) { uint32_t mods_locked, uint32_t group) {
struct swaylock_state *state = data; struct swaylock_state *state = data;
xkb_state_update_mask(state->xkb.state, xkb_state_update_mask(state->xkb.state,
mods_depressed, mods_latched, mods_locked, 0, 0, group); mods_depressed, mods_latched, mods_locked, 0, 0, group);
xkb_mod_mask_t mask = xkb_state_serialize_mods(state->xkb.state, state->xkb.caps_lock = xkb_state_mod_name_is_active(state->xkb.state,
XKB_STATE_MODS_DEPRESSED | XKB_STATE_MODS_LATCHED); XKB_MOD_NAME_CAPS, XKB_STATE_MODS_LOCKED);
state->xkb.modifiers = 0; state->xkb.control = xkb_state_mod_name_is_active(state->xkb.state,
state->xkb.caps_lock = xkb_state_mod_name_is_active(state->xkb.state, XKB_MOD_NAME_CAPS, XKB_STATE_MODS_LOCKED); XKB_MOD_NAME_CTRL,
for (uint32_t i = 0; i < MASK_LAST; ++i) { XKB_STATE_MODS_DEPRESSED | XKB_STATE_MODS_LATCHED);
if (mask & state->xkb.masks[i]) {
state->xkb.modifiers |= XKB_MODS[i];
}
}
} }
static void keyboard_repeat_info(void *data, struct wl_keyboard *wl_keyboard, static void keyboard_repeat_info(void *data, struct wl_keyboard *wl_keyboard,