1 Commits

Author SHA1 Message Date
Andrea Chiavazza 7af0b45334 fix some key binding events being passed to clients 2026-01-16 13:23:16 +00:00
4 changed files with 81 additions and 66 deletions
-8
View File
@@ -1,13 +1,5 @@
# dwl - dwm for Wayland # dwl - dwm for Wayland
2025-08-16:
dwl IS CURRENTLY UN-MAINTAINED.
AT THE PRESENT TIME, I (@fauxmight) DO NOT HAVE
THE TIME OR CAPACITY TO KEEP UP WITH [wlroots] CHANGES.
IF YOU ARE INTERESTED IN TAKING ON LEAD DEVELOPER RESPONSIBILITIES,
SEE ISSUE [#1166](https://codeberg.org/dwl/dwl/issues/1166).
---
Join us on our IRC channel: [#dwl on Libera Chat] Join us on our IRC channel: [#dwl on Libera Chat]
Or on the community-maintained [Discord server]. Or on the community-maintained [Discord server].
+11 -4
View File
@@ -291,11 +291,18 @@ client_is_unmanaged(Client *c)
static inline void static inline void
client_notify_enter(struct wlr_surface *s, struct wlr_keyboard *kb) client_notify_enter(struct wlr_surface *s, struct wlr_keyboard *kb)
{ {
if (kb) uint32_t filtered[WLR_KEYBOARD_KEYS_CAP];
wlr_seat_keyboard_notify_enter(seat, s, kb->keycodes, size_t size = 0;
kb->num_keycodes, &kb->modifiers); if (!kb) {
else
wlr_seat_keyboard_notify_enter(seat, s, NULL, 0, NULL); wlr_seat_keyboard_notify_enter(seat, s, NULL, 0, NULL);
return;
}
for (size_t i = 0; i < kb->num_keycodes; i++) {
uint32_t key = kb->keycodes[i];
if (!consumed[key])
filtered[size++] = key;
}
wlr_seat_keyboard_notify_enter(seat, s, filtered, size, &kb->modifiers);
} }
static inline void static inline void
+14 -10
View File
@@ -20,11 +20,12 @@ static const float fullscreen_bg[] = {0.0f, 0.0f, 0.0f, 1.0f}; /* You ca
/* logging */ /* logging */
static int log_level = WLR_ERROR; static int log_level = WLR_ERROR;
/* NOTE: ALWAYS keep a rule declared even if you don't use rules (e.g leave at least one example) */
static const Rule rules[] = { static const Rule rules[] = {
/* app_id title tags mask isfloating monitor */ /* app_id title tags mask isfloating monitor */
/* examples: */
{ "Gimp_EXAMPLE", NULL, 0, 1, -1 }, /* Start on currently visible tags floating, not tiled */ { "Gimp_EXAMPLE", NULL, 0, 1, -1 }, /* Start on currently visible tags floating, not tiled */
{ "firefox_EXAMPLE", NULL, 1 << 8, 0, -1 }, /* Start on ONLY tag "9" */ { "firefox_EXAMPLE", NULL, 1 << 8, 0, -1 }, /* Start on ONLY tag "9" */
/* default/example rule: can be changed but cannot be eliminated; at least one rule must exist */
}; };
/* layout(s) */ /* layout(s) */
@@ -37,14 +38,17 @@ static const Layout layouts[] = {
/* monitors */ /* monitors */
/* (x=-1, y=-1) is reserved as an "autoconfigure" monitor position indicator /* (x=-1, y=-1) is reserved as an "autoconfigure" monitor position indicator
* WARNING: negative values other than (-1, -1) cause problems with Xwayland clients due to * WARNING: negative values other than (-1, -1) cause problems with Xwayland clients
* https://gitlab.freedesktop.org/xorg/xserver/-/issues/899 */ * https://gitlab.freedesktop.org/xorg/xserver/-/issues/899
*/
/* NOTE: ALWAYS add a fallback rule, even if you are completely sure it won't be used */
static const MonitorRule monrules[] = { static const MonitorRule monrules[] = {
/* name mfact nmaster scale layout rotate/reflect x y /* name mfact nmaster scale layout rotate/reflect x y */
* example of a HiDPI laptop monitor: /* example of a HiDPI laptop monitor:
{ "eDP-1", 0.5f, 1, 2, &layouts[0], WL_OUTPUT_TRANSFORM_NORMAL, -1, -1 }, */ { "eDP-1", 0.5f, 1, 2, &layouts[0], WL_OUTPUT_TRANSFORM_NORMAL, -1, -1 },
*/
/* defaults */
{ NULL, 0.55f, 1, 1, &layouts[0], WL_OUTPUT_TRANSFORM_NORMAL, -1, -1 }, { NULL, 0.55f, 1, 1, &layouts[0], WL_OUTPUT_TRANSFORM_NORMAL, -1, -1 },
/* default monitor rule: can be changed but cannot be eliminated; at least one monitor rule must exist */
}; };
/* keyboard */ /* keyboard */
@@ -119,7 +123,7 @@ 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. */ /* Note that Shift changes certain key codes: c -> C, 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} },
@@ -131,7 +135,7 @@ static const Key keys[] = {
{ MODKEY, XKB_KEY_l, setmfact, {.f = +0.05f} }, { MODKEY, XKB_KEY_l, setmfact, {.f = +0.05f} },
{ MODKEY, XKB_KEY_Return, zoom, {0} }, { MODKEY, XKB_KEY_Return, zoom, {0} },
{ MODKEY, XKB_KEY_Tab, view, {0} }, { MODKEY, XKB_KEY_Tab, view, {0} },
{ MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_c, killclient, {0} }, { MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_C, killclient, {0} },
{ MODKEY, XKB_KEY_t, setlayout, {.v = &layouts[0]} }, { MODKEY, XKB_KEY_t, setlayout, {.v = &layouts[0]} },
{ MODKEY, XKB_KEY_f, setlayout, {.v = &layouts[1]} }, { MODKEY, XKB_KEY_f, setlayout, {.v = &layouts[1]} },
{ MODKEY, XKB_KEY_m, setlayout, {.v = &layouts[2]} }, { MODKEY, XKB_KEY_m, setlayout, {.v = &layouts[2]} },
@@ -153,7 +157,7 @@ static const Key keys[] = {
TAGKEYS( XKB_KEY_7, XKB_KEY_ampersand, 6), TAGKEYS( XKB_KEY_7, XKB_KEY_ampersand, 6),
TAGKEYS( XKB_KEY_8, XKB_KEY_asterisk, 7), TAGKEYS( XKB_KEY_8, XKB_KEY_asterisk, 7),
TAGKEYS( XKB_KEY_9, XKB_KEY_parenleft, 8), TAGKEYS( XKB_KEY_9, XKB_KEY_parenleft, 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_Terminate_Server, quit, {0} },
+24 -12
View File
@@ -291,7 +291,7 @@ static void gpureset(struct wl_listener *listener, void *data);
static void handlesig(int signo); static void handlesig(int signo);
static void incnmaster(const Arg *arg); static void incnmaster(const Arg *arg);
static void inputdevice(struct wl_listener *listener, void *data); static void inputdevice(struct wl_listener *listener, void *data);
static int keybinding(uint32_t mods, xkb_keysym_t sym); static const Key * keybinding(uint32_t mods, xkb_keysym_t sym);
static void keypress(struct wl_listener *listener, void *data); static void keypress(struct wl_listener *listener, void *data);
static void keypressmod(struct wl_listener *listener, void *data); static void keypressmod(struct wl_listener *listener, void *data);
static int keyrepeat(void *data); static int keyrepeat(void *data);
@@ -405,6 +405,7 @@ static struct wlr_output_layout *output_layout;
static struct wlr_box sgeom; static struct wlr_box sgeom;
static struct wl_list mons; static struct wl_list mons;
static Monitor *selmon; static Monitor *selmon;
static bool consumed[KEY_MAX + 1];
/* global event handlers */ /* global event handlers */
static struct wl_listener cursor_axis = {.notify = axisnotify}; static struct wl_listener cursor_axis = {.notify = axisnotify};
@@ -1605,7 +1606,7 @@ inputdevice(struct wl_listener *listener, void *data)
wlr_seat_set_capabilities(seat, caps); wlr_seat_set_capabilities(seat, caps);
} }
int const Key *
keybinding(uint32_t mods, xkb_keysym_t sym) keybinding(uint32_t mods, xkb_keysym_t sym)
{ {
/* /*
@@ -1616,13 +1617,10 @@ 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)
&& xkb_keysym_to_lower(sym) == xkb_keysym_to_lower(k->keysym) && sym == k->keysym && k->func)
&& k->func) { return k;
k->func(&k->arg);
return 1;
} }
} return NULL;
return 0;
} }
void void
@@ -1648,8 +1646,14 @@ keypress(struct wl_listener *listener, void *data)
/* 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 (i = 0; i < nsyms; i++) {
handled = keybinding(mods, syms[i]) || handled; const Key *key = keybinding(mods, syms[i]);
if (key) {
consumed[event->keycode] = true;
key->func(&key->arg);
handled = 1;
}
}
} }
if (handled && group->wlr_group->keyboard.repeat_info.delay > 0) { if (handled && group->wlr_group->keyboard.repeat_info.delay > 0) {
@@ -1666,6 +1670,11 @@ keypress(struct wl_listener *listener, void *data)
if (handled) if (handled)
return; return;
if (consumed[event->keycode]) {
if (event->state == WL_KEYBOARD_KEY_STATE_RELEASED)
consumed[event->keycode] = false;
return; // don't pass to the client the release event of a handled key-press
}
wlr_seat_set_keyboard(seat, &group->wlr_group->keyboard); wlr_seat_set_keyboard(seat, &group->wlr_group->keyboard);
/* Pass unhandled keycodes along to the client. */ /* Pass unhandled keycodes along to the client. */
wlr_seat_keyboard_notify_key(seat, event->time_msec, wlr_seat_keyboard_notify_key(seat, event->time_msec,
@@ -1696,8 +1705,11 @@ keyrepeat(void *data)
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 (i = 0; i < group->nsyms; i++) {
keybinding(group->mods, group->keysyms[i]); const Key *key = keybinding(group->mods, group->keysyms[i]);
if (key)
key->func(&key->arg);
}
return 0; return 0;
} }