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