mirror of
https://codeberg.org/dwl/dwl.git
synced 2026-09-19 13:52:48 +00:00
Revert "use modifier-independent key symbols in keybindings"
This reverts commit f9c644f0b0.
This commit is contained in:
+18
-17
@@ -106,11 +106,11 @@ static const enum libinput_config_tap_button_map button_map = LIBINPUT_CONFIG_TA
|
||||
/* If you want to use the windows key for MODKEY, use WLR_MODIFIER_LOGO */
|
||||
#define MODKEY WLR_MODIFIER_ALT
|
||||
|
||||
#define TAGKEYS(KEY,TAG) \
|
||||
#define TAGKEYS(KEY,SKEY,TAG) \
|
||||
{ MODKEY, KEY, view, {.ui = 1 << TAG} }, \
|
||||
{ MODKEY|WLR_MODIFIER_CTRL, KEY, toggleview, {.ui = 1 << TAG} }, \
|
||||
{ MODKEY|WLR_MODIFIER_SHIFT, KEY, tag, {.ui = 1 << TAG} }, \
|
||||
{ MODKEY|WLR_MODIFIER_CTRL|WLR_MODIFIER_SHIFT,KEY,toggletag, {.ui = 1 << TAG} }
|
||||
{ MODKEY|WLR_MODIFIER_SHIFT, SKEY, tag, {.ui = 1 << TAG} }, \
|
||||
{ MODKEY|WLR_MODIFIER_CTRL|WLR_MODIFIER_SHIFT,SKEY,toggletag, {.ui = 1 << TAG} }
|
||||
|
||||
/* helper for spawning shell commands in the pre dwm-5.0 fashion */
|
||||
#define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } }
|
||||
@@ -120,6 +120,7 @@ static const char *termcmd[] = { "foot", NULL };
|
||||
static const char *menucmd[] = { "wmenu-run", NULL };
|
||||
|
||||
static const Key keys[] = {
|
||||
/* Note that Shift changes certain key codes: 2 -> at, etc. */
|
||||
/* modifier key function argument */
|
||||
{ MODKEY, XKB_KEY_p, spawn, {.v = menucmd} },
|
||||
{ MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_Return, spawn, {.v = termcmd} },
|
||||
@@ -139,28 +140,28 @@ static const Key keys[] = {
|
||||
{ MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_space, togglefloating, {0} },
|
||||
{ MODKEY, XKB_KEY_e, togglefullscreen, {0} },
|
||||
{ MODKEY, XKB_KEY_0, view, {.ui = ~0} },
|
||||
{ MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_0, tag, {.ui = ~0} },
|
||||
{ MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_parenright, tag, {.ui = ~0} },
|
||||
{ MODKEY, XKB_KEY_comma, focusmon, {.i = WLR_DIRECTION_LEFT} },
|
||||
{ MODKEY, XKB_KEY_period, focusmon, {.i = WLR_DIRECTION_RIGHT} },
|
||||
{ MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_comma, tagmon, {.i = WLR_DIRECTION_LEFT} },
|
||||
{ MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_period, tagmon, {.i = WLR_DIRECTION_RIGHT} },
|
||||
TAGKEYS( XKB_KEY_1, 0),
|
||||
TAGKEYS( XKB_KEY_2, 1),
|
||||
TAGKEYS( XKB_KEY_3, 2),
|
||||
TAGKEYS( XKB_KEY_4, 3),
|
||||
TAGKEYS( XKB_KEY_5, 4),
|
||||
TAGKEYS( XKB_KEY_6, 5),
|
||||
TAGKEYS( XKB_KEY_7, 6),
|
||||
TAGKEYS( XKB_KEY_8, 7),
|
||||
TAGKEYS( XKB_KEY_9, 8),
|
||||
{ MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_less, tagmon, {.i = WLR_DIRECTION_LEFT} },
|
||||
{ MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_greater, tagmon, {.i = WLR_DIRECTION_RIGHT} },
|
||||
TAGKEYS( XKB_KEY_1, XKB_KEY_exclam, 0),
|
||||
TAGKEYS( XKB_KEY_2, XKB_KEY_at, 1),
|
||||
TAGKEYS( XKB_KEY_3, XKB_KEY_numbersign, 2),
|
||||
TAGKEYS( XKB_KEY_4, XKB_KEY_dollar, 3),
|
||||
TAGKEYS( XKB_KEY_5, XKB_KEY_percent, 4),
|
||||
TAGKEYS( XKB_KEY_6, XKB_KEY_asciicircum, 5),
|
||||
TAGKEYS( XKB_KEY_7, XKB_KEY_ampersand, 6),
|
||||
TAGKEYS( XKB_KEY_8, XKB_KEY_asterisk, 7),
|
||||
TAGKEYS( XKB_KEY_9, XKB_KEY_parenleft, 8),
|
||||
{ MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_q, quit, {0} },
|
||||
|
||||
/* Ctrl-Alt-Backspace and Ctrl-Alt-Fx used to be handled by X server */
|
||||
{ WLR_MODIFIER_CTRL|WLR_MODIFIER_ALT,XKB_KEY_BackSpace, quit, {0} },
|
||||
{ WLR_MODIFIER_CTRL|WLR_MODIFIER_ALT,XKB_KEY_Terminate_Server, quit, {0} },
|
||||
/* Ctrl-Alt-Fx is used to switch to another VT, if you don't know what a VT is
|
||||
* do not remove them.
|
||||
*/
|
||||
#define CHVT(n) { WLR_MODIFIER_CTRL|WLR_MODIFIER_ALT,XKB_KEY_F##n, chvt, {.ui = (n)} }
|
||||
#define CHVT(n) { WLR_MODIFIER_CTRL|WLR_MODIFIER_ALT,XKB_KEY_XF86Switch_VT_##n, chvt, {.ui = (n)} }
|
||||
CHVT(1), CHVT(2), CHVT(3), CHVT(4), CHVT(5), CHVT(6),
|
||||
CHVT(7), CHVT(8), CHVT(9), CHVT(10), CHVT(11), CHVT(12),
|
||||
};
|
||||
|
||||
@@ -170,8 +170,9 @@ typedef struct {
|
||||
struct wlr_keyboard_group *wlr_group;
|
||||
struct wlr_keyboard *virtual_keyboard;
|
||||
|
||||
xkb_keysym_t keysyms[2];
|
||||
uint32_t mods;
|
||||
int nsyms;
|
||||
const xkb_keysym_t *keysyms; /* invalid if nsyms == 0 */
|
||||
uint32_t mods; /* invalid if nsyms == 0 */
|
||||
struct wl_event_source *key_repeat_source;
|
||||
|
||||
struct wl_listener modifiers;
|
||||
@@ -1710,39 +1711,40 @@ keybinding(uint32_t mods, xkb_keysym_t sym)
|
||||
*/
|
||||
const Key *k;
|
||||
for (k = keys; k < END(keys); k++) {
|
||||
if (CLEANMASK(mods) == CLEANMASK(k->mod) && sym == k->keysym && k->func)
|
||||
if (CLEANMASK(mods) == CLEANMASK(k->mod)
|
||||
&& xkb_keysym_to_lower(sym) == xkb_keysym_to_lower(k->keysym)
|
||||
&& k->func) {
|
||||
return k;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
keypress(struct wl_listener *listener, void *data)
|
||||
{
|
||||
int i;
|
||||
/* This event is raised when a key is pressed or released. */
|
||||
KeyboardGroup *group = wl_container_of(listener, group, key);
|
||||
struct wlr_keyboard_key_event *event = data;
|
||||
|
||||
/* Translate libinput keycode -> xkbcommon */
|
||||
uint32_t keycode = event->keycode + 8;
|
||||
struct wlr_keyboard *kb = &group->wlr_group->keyboard;
|
||||
xkb_layout_index_t layout = xkb_state_key_get_layout(kb->xkb_state, keycode);
|
||||
int handled = 0;
|
||||
/* Get a list of keysyms based on the keymap for this keyboard */
|
||||
const xkb_keysym_t *syms;
|
||||
int nsyms = xkb_state_key_get_syms(
|
||||
group->wlr_group->keyboard.xkb_state, keycode, &syms);
|
||||
|
||||
// Get the keysyms for level 0 (normal) and level 1 (shifted)
|
||||
// Only one keysym for each level:
|
||||
// multiple keysyms per keycode don't really exist in the real world
|
||||
for (int i = 0; i < 2; i++)
|
||||
group->keysyms[i] = keymap_get_one_sym_by_level(kb->keymap, keycode, layout, i);
|
||||
group->mods = wlr_keyboard_get_modifiers(&group->wlr_group->keyboard);
|
||||
int handled = 0;
|
||||
uint32_t mods = wlr_keyboard_get_modifiers(&group->wlr_group->keyboard);
|
||||
|
||||
wlr_idle_notifier_v1_notify_activity(idle_notifier, seat);
|
||||
|
||||
/* On _press_ if there is no active screen locker,
|
||||
* attempt to process a compositor keybinding. */
|
||||
if (!locked && event->state == WL_KEYBOARD_KEY_STATE_PRESSED) {
|
||||
for (int i = 0; i < 2; i++) {
|
||||
const Key *key = keybinding(group->mods, group->keysyms[i]);
|
||||
for (i = 0; i < nsyms; i++) {
|
||||
const Key *key = keybinding(mods, syms[i]);
|
||||
if (key) {
|
||||
consumed[event->keycode] = 1;
|
||||
key->func(&key->arg);
|
||||
@@ -1751,11 +1753,16 @@ keypress(struct wl_listener *listener, void *data)
|
||||
}
|
||||
}
|
||||
|
||||
if (handled && group->wlr_group->keyboard.repeat_info.delay > 0)
|
||||
if (handled && group->wlr_group->keyboard.repeat_info.delay > 0) {
|
||||
group->mods = mods;
|
||||
group->keysyms = syms;
|
||||
group->nsyms = nsyms;
|
||||
wl_event_source_timer_update(group->key_repeat_source,
|
||||
group->wlr_group->keyboard.repeat_info.delay);
|
||||
else
|
||||
} else {
|
||||
group->nsyms = 0;
|
||||
wl_event_source_timer_update(group->key_repeat_source, 0);
|
||||
}
|
||||
|
||||
if (handled || input_method_keyboard_grab_forward_key(group, event))
|
||||
return;
|
||||
@@ -1791,13 +1798,14 @@ int
|
||||
keyrepeat(void *data)
|
||||
{
|
||||
KeyboardGroup *group = data;
|
||||
if (group->wlr_group->keyboard.repeat_info.rate <= 0)
|
||||
int i;
|
||||
if (!group->nsyms || group->wlr_group->keyboard.repeat_info.rate <= 0)
|
||||
return 0;
|
||||
|
||||
wl_event_source_timer_update(group->key_repeat_source,
|
||||
1000 / group->wlr_group->keyboard.repeat_info.rate);
|
||||
|
||||
for (int i = 0; i < 2; i++) {
|
||||
for (i = 0; i < group->nsyms; i++) {
|
||||
const Key *key = keybinding(group->mods, group->keysyms[i]);
|
||||
if (key)
|
||||
key->func(&key->arg);
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <xkbcommon/xkbcommon.h>
|
||||
|
||||
#define MAX(A, B) ((A) > (B) ? (A) : (B))
|
||||
#define MIN(A, B) ((A) < (B) ? (A) : (B))
|
||||
@@ -14,8 +13,6 @@
|
||||
static void die(const char *fmt, ...);
|
||||
static void *ecalloc(size_t nmemb, size_t size);
|
||||
static int fd_set_nonblock(int fd);
|
||||
xkb_keysym_t keymap_get_one_sym_by_level(struct xkb_keymap *keymap,
|
||||
xkb_keycode_t key, xkb_layout_index_t layout, xkb_level_index_t level);
|
||||
|
||||
void
|
||||
die(const char *fmt, ...) {
|
||||
@@ -59,12 +56,3 @@ fd_set_nonblock(int fd) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
xkb_keysym_t
|
||||
keymap_get_one_sym_by_level(struct xkb_keymap *keymap, xkb_keycode_t key,
|
||||
xkb_layout_index_t layout, xkb_level_index_t level)
|
||||
{
|
||||
const xkb_keysym_t *syms;
|
||||
int count = xkb_keymap_key_get_syms_by_level(keymap, key, layout, level, &syms);
|
||||
return count ? syms[0] : XKB_KEY_NoSymbol;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user