add forgotten alt modifier, cleanup repeat vars in kbd
This commit is contained in:
parent
da22980093
commit
7440258aa0
1 changed files with 50 additions and 26 deletions
76
mew.c
76
mew.c
|
@ -38,14 +38,15 @@ static struct {
|
||||||
struct xkb_keymap *xkb_keymap;
|
struct xkb_keymap *xkb_keymap;
|
||||||
struct xkb_state *xkb_state;
|
struct xkb_state *xkb_state;
|
||||||
|
|
||||||
int repeat_delay;
|
struct {
|
||||||
int repeat_period;
|
int delay;
|
||||||
int repeat_timer;
|
int period;
|
||||||
enum wl_keyboard_key_state repeat_key_state;
|
int timer;
|
||||||
xkb_keysym_t repeat_sym;
|
enum wl_keyboard_key_state key_state;
|
||||||
|
xkb_keysym_t sym;
|
||||||
|
} repeat;
|
||||||
|
|
||||||
int ctrl;
|
int ctrl, shift, alt;
|
||||||
int shift;
|
|
||||||
} kbd;
|
} kbd;
|
||||||
|
|
||||||
static char text[BUFSIZ] = "";
|
static char text[BUFSIZ] = "";
|
||||||
|
@ -481,14 +482,14 @@ paste(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
keyboard_keypress(enum wl_keyboard_key_state state, xkb_keysym_t sym, int ctrl, int shift)
|
keyboard_keypress(enum wl_keyboard_key_state state, xkb_keysym_t sym)
|
||||||
{
|
{
|
||||||
char buf[8];
|
char buf[8];
|
||||||
|
|
||||||
if (state != WL_KEYBOARD_KEY_STATE_PRESSED)
|
if (state != WL_KEYBOARD_KEY_STATE_PRESSED)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (ctrl) {
|
if (kbd.ctrl) {
|
||||||
switch (xkb_keysym_to_lower(sym)) {
|
switch (xkb_keysym_to_lower(sym)) {
|
||||||
case XKB_KEY_a: sym = XKB_KEY_Home; break;
|
case XKB_KEY_a: sym = XKB_KEY_Home; break;
|
||||||
case XKB_KEY_b: sym = XKB_KEY_Left; break;
|
case XKB_KEY_b: sym = XKB_KEY_Left; break;
|
||||||
|
@ -537,8 +538,28 @@ keyboard_keypress(enum wl_keyboard_key_state state, xkb_keysym_t sym, int ctrl,
|
||||||
case XKB_KEY_bracketleft:
|
case XKB_KEY_bracketleft:
|
||||||
cleanup();
|
cleanup();
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else if (kbd.alt) {
|
||||||
|
switch(sym) {
|
||||||
|
case XKB_KEY_b:
|
||||||
|
movewordedge(-1);
|
||||||
|
goto draw;
|
||||||
|
case XKB_KEY_f:
|
||||||
|
movewordedge(+1);
|
||||||
|
goto draw;
|
||||||
|
case XKB_KEY_g: sym = XKB_KEY_Home; break;
|
||||||
|
case XKB_KEY_G: sym = XKB_KEY_End; break;
|
||||||
|
case XKB_KEY_h: sym = XKB_KEY_Up; break;
|
||||||
|
case XKB_KEY_j: sym = XKB_KEY_Next; break;
|
||||||
|
case XKB_KEY_k: sym = XKB_KEY_Prior; break;
|
||||||
|
case XKB_KEY_l: sym = XKB_KEY_Down; break;
|
||||||
|
default:
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (sym) {
|
switch (sym) {
|
||||||
case XKB_KEY_Delete:
|
case XKB_KEY_Delete:
|
||||||
case XKB_KEY_KP_Delete:
|
case XKB_KEY_KP_Delete:
|
||||||
|
@ -612,8 +633,8 @@ keyboard_keypress(enum wl_keyboard_key_state state, xkb_keysym_t sym, int ctrl,
|
||||||
break;
|
break;
|
||||||
case XKB_KEY_Return:
|
case XKB_KEY_Return:
|
||||||
case XKB_KEY_KP_Enter:
|
case XKB_KEY_KP_Enter:
|
||||||
submit((sel && !shift) ? sel->text : text);
|
submit((sel && !kbd.shift) ? sel->text : text);
|
||||||
if (!ctrl && submit != exec_cmd) {
|
if (!kbd.ctrl && submit != exec_cmd) {
|
||||||
running = 0;
|
running = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -681,15 +702,15 @@ keyboard_handle_key(void *data, struct wl_keyboard *wl_keyboard,
|
||||||
enum wl_keyboard_key_state key_state = _key_state;
|
enum wl_keyboard_key_state key_state = _key_state;
|
||||||
xkb_keysym_t sym = xkb_state_key_get_one_sym(kbd.xkb_state, key + 8);
|
xkb_keysym_t sym = xkb_state_key_get_one_sym(kbd.xkb_state, key + 8);
|
||||||
|
|
||||||
keyboard_keypress(key_state, sym, kbd.ctrl, kbd.shift);
|
keyboard_keypress(key_state, sym);
|
||||||
|
|
||||||
if (key_state == WL_KEYBOARD_KEY_STATE_PRESSED && kbd.repeat_period >= 0) {
|
if (key_state == WL_KEYBOARD_KEY_STATE_PRESSED && kbd.repeat.period >= 0) {
|
||||||
kbd.repeat_key_state = key_state;
|
kbd.repeat.key_state = key_state;
|
||||||
kbd.repeat_sym = sym;
|
kbd.repeat.sym = sym;
|
||||||
spec.it_value.tv_sec = kbd.repeat_delay / 1000;
|
spec.it_value.tv_sec = kbd.repeat.delay / 1000;
|
||||||
spec.it_value.tv_nsec = (kbd.repeat_delay % 1000) * 1000000l;
|
spec.it_value.tv_nsec = (kbd.repeat.delay % 1000) * 1000000l;
|
||||||
}
|
}
|
||||||
timerfd_settime(kbd.repeat_timer, 0, &spec, NULL);
|
timerfd_settime(kbd.repeat.timer, 0, &spec, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -705,6 +726,9 @@ keyboard_handle_modifiers(void *data, struct wl_keyboard *wl_keyboard,
|
||||||
kbd.shift = xkb_state_mod_name_is_active(kbd.xkb_state,
|
kbd.shift = xkb_state_mod_name_is_active(kbd.xkb_state,
|
||||||
XKB_MOD_NAME_SHIFT,
|
XKB_MOD_NAME_SHIFT,
|
||||||
XKB_STATE_MODS_DEPRESSED | XKB_STATE_MODS_LATCHED);
|
XKB_STATE_MODS_DEPRESSED | XKB_STATE_MODS_LATCHED);
|
||||||
|
kbd.alt = xkb_state_mod_name_is_active(kbd.xkb_state,
|
||||||
|
XKB_MOD_NAME_ALT,
|
||||||
|
XKB_STATE_MODS_DEPRESSED | XKB_STATE_MODS_LATCHED);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -712,19 +736,19 @@ keyboard_repeat(void)
|
||||||
{
|
{
|
||||||
struct itimerspec spec = { 0 };
|
struct itimerspec spec = { 0 };
|
||||||
|
|
||||||
keyboard_keypress(kbd.repeat_key_state, kbd.repeat_sym, kbd.ctrl, kbd.shift);
|
keyboard_keypress(kbd.repeat.key_state, kbd.repeat.sym);
|
||||||
|
|
||||||
spec.it_value.tv_sec = kbd.repeat_period / 1000;
|
spec.it_value.tv_sec = kbd.repeat.period / 1000;
|
||||||
spec.it_value.tv_nsec = (kbd.repeat_period % 1000) * 1000000l;
|
spec.it_value.tv_nsec = (kbd.repeat.period % 1000) * 1000000l;
|
||||||
timerfd_settime(kbd.repeat_timer, 0, &spec, NULL);
|
timerfd_settime(kbd.repeat.timer, 0, &spec, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
keyboard_handle_repeat_info(void *data, struct wl_keyboard *wl_keyboard,
|
keyboard_handle_repeat_info(void *data, struct wl_keyboard *wl_keyboard,
|
||||||
int32_t rate, int32_t delay)
|
int32_t rate, int32_t delay)
|
||||||
{
|
{
|
||||||
kbd.repeat_delay = delay;
|
kbd.repeat.delay = delay;
|
||||||
kbd.repeat_period = rate >= 0 ? 1000 / rate : -1;
|
kbd.repeat.period = rate >= 0 ? 1000 / rate : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct wl_keyboard_listener keyboard_listener = {
|
static const struct wl_keyboard_listener keyboard_listener = {
|
||||||
|
@ -814,7 +838,7 @@ seat_handle_capabilities(void *data, struct wl_seat *wl_seat, enum wl_seat_capab
|
||||||
kbd.wl_keyboard = wl_seat_get_keyboard(seat);
|
kbd.wl_keyboard = wl_seat_get_keyboard(seat);
|
||||||
if (!(kbd.xkb_context = xkb_context_new(XKB_CONTEXT_NO_FLAGS)))
|
if (!(kbd.xkb_context = xkb_context_new(XKB_CONTEXT_NO_FLAGS)))
|
||||||
die("xkb_context_new failed");
|
die("xkb_context_new failed");
|
||||||
if ((kbd.repeat_timer = timerfd_create(CLOCK_MONOTONIC, 0)) < 0)
|
if ((kbd.repeat.timer = timerfd_create(CLOCK_MONOTONIC, 0)) < 0)
|
||||||
die("timerfd_create:");
|
die("timerfd_create:");
|
||||||
wl_keyboard_add_listener(kbd.wl_keyboard, &keyboard_listener, NULL);
|
wl_keyboard_add_listener(kbd.wl_keyboard, &keyboard_listener, NULL);
|
||||||
}
|
}
|
||||||
|
@ -887,7 +911,7 @@ run(void)
|
||||||
{
|
{
|
||||||
struct pollfd pfds[] = {
|
struct pollfd pfds[] = {
|
||||||
{ wl_display_get_fd(display), POLLIN },
|
{ wl_display_get_fd(display), POLLIN },
|
||||||
{ kbd.repeat_timer, POLLIN },
|
{ kbd.repeat.timer, POLLIN },
|
||||||
};
|
};
|
||||||
|
|
||||||
match();
|
match();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue