Fix kblayout

This commit is contained in:
Nikita Ivanov 2024-06-01 02:35:35 +02:00
parent d400a432ad
commit 5c86e65aa0
No known key found for this signature in database
GPG Key ID: 6E656AC5B97B5133
2 changed files with 38 additions and 26 deletions

View File

@ -21,7 +21,7 @@ implementation happens to share some code. If you don't need
any of these features, just disable it in `config.h`. any of these features, just disable it in `config.h`.
### Download ### Download
- [2024-05-17](https://codeberg.org/dwl/dwl-patches/raw/branch/main/patches/kblayout/kblayout.patch) - [2024-06-01](https://codeberg.org/dwl/dwl-patches/raw/branch/main/patches/kblayout/kblayout.patch)
### Authors ### Authors
- [ForzCross](https://codeberg.org/ForzCross) - [ForzCross](https://codeberg.org/ForzCross)

View File

@ -1,8 +1,12 @@
commit dc72dae11b1ae4d76b70881e8c5bd62055234e60 From 9e70c5145981d9ae91cf9907b485bb4fdfc1ab04 Mon Sep 17 00:00:00 2001
Author: Nikita Ivanov <nikita.vyach.ivanov@gmail.com> From: Nikita Ivanov <nikita.vyach.ivanov@gmail.com>
Date: Sun Apr 7 22:03:49 2024 +0200 Date: Sun, 7 Apr 2024 22:03:49 +0200
Subject: [PATCH] Add per client keyboard layout and status bar info
Add per client keyboard layout and status bar info ---
config.def.h | 3 +++
dwl.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 72 insertions(+), 1 deletion(-)
diff --git a/config.def.h b/config.def.h diff --git a/config.def.h b/config.def.h
index 8f498d2..484e522 100644 index 8f498d2..484e522 100644
@ -19,10 +23,18 @@ index 8f498d2..484e522 100644
/* tagging - TAGCOUNT must be no greater than 31 */ /* tagging - TAGCOUNT must be no greater than 31 */
#define TAGCOUNT (9) #define TAGCOUNT (9)
diff --git a/dwl.c b/dwl.c diff --git a/dwl.c b/dwl.c
index bf763df..c8da00e 100644 index bf763df..1aad21e 100644
--- a/dwl.c --- a/dwl.c
+++ b/dwl.c +++ b/dwl.c
@@ -139,6 +139,7 @@ typedef struct { @@ -13,6 +13,7 @@
#include <wayland-server-core.h>
#include <wlr/backend.h>
#include <wlr/backend/libinput.h>
+#include <wlr/interfaces/wlr_keyboard.h>
#include <wlr/render/allocator.h>
#include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_compositor.h>
@@ -139,6 +140,7 @@ typedef struct {
uint32_t tags; uint32_t tags;
int isfloating, isurgent, isfullscreen; int isfloating, isurgent, isfullscreen;
uint32_t resize; /* configure serial of a pending resize */ uint32_t resize; /* configure serial of a pending resize */
@ -30,7 +42,7 @@ index bf763df..c8da00e 100644
} Client; } Client;
typedef struct { typedef struct {
@@ -286,6 +287,7 @@ static void fullscreennotify(struct wl_listener *listener, void *data); @@ -286,6 +288,7 @@ static void fullscreennotify(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);
@ -38,7 +50,7 @@ index bf763df..c8da00e 100644
static int keybinding(uint32_t mods, xkb_keysym_t sym); static int 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);
@@ -405,6 +407,8 @@ static struct wlr_box sgeom; @@ -405,6 +408,8 @@ static struct wlr_box sgeom;
static struct wl_list mons; static struct wl_list mons;
static Monitor *selmon; static Monitor *selmon;
@ -47,7 +59,7 @@ index bf763df..c8da00e 100644
#ifdef XWAYLAND #ifdef XWAYLAND
static void activatex11(struct wl_listener *listener, void *data); static void activatex11(struct wl_listener *listener, void *data);
static void associatex11(struct wl_listener *listener, void *data); static void associatex11(struct wl_listener *listener, void *data);
@@ -795,6 +799,8 @@ createkeyboard(struct wlr_keyboard *keyboard) @@ -795,6 +800,8 @@ createkeyboard(struct wlr_keyboard *keyboard)
/* Add the new keyboard to the group */ /* Add the new keyboard to the group */
wlr_keyboard_group_add_keyboard(kb_group.wlr_group, keyboard); wlr_keyboard_group_add_keyboard(kb_group.wlr_group, keyboard);
@ -56,7 +68,7 @@ index bf763df..c8da00e 100644
} }
void void
@@ -951,6 +957,7 @@ createnotify(struct wl_listener *listener, void *data) @@ -951,6 +958,7 @@ createnotify(struct wl_listener *listener, void *data)
struct wlr_xdg_surface *xdg_surface = data; struct wlr_xdg_surface *xdg_surface = data;
Client *c = NULL; Client *c = NULL;
LayerSurface *l = NULL; LayerSurface *l = NULL;
@ -64,7 +76,7 @@ index bf763df..c8da00e 100644
if (xdg_surface->role == WLR_XDG_SURFACE_ROLE_POPUP) { if (xdg_surface->role == WLR_XDG_SURFACE_ROLE_POPUP) {
struct wlr_xdg_popup *popup = xdg_surface->popup; struct wlr_xdg_popup *popup = xdg_surface->popup;
@@ -973,6 +980,7 @@ createnotify(struct wl_listener *listener, void *data) @@ -973,6 +981,7 @@ createnotify(struct wl_listener *listener, void *data)
c = xdg_surface->data = ecalloc(1, sizeof(*c)); c = xdg_surface->data = ecalloc(1, sizeof(*c));
c->surface.xdg = xdg_surface; c->surface.xdg = xdg_surface;
c->bw = borderpx; c->bw = borderpx;
@ -72,7 +84,7 @@ index bf763df..c8da00e 100644
wlr_xdg_toplevel_set_wm_capabilities(xdg_surface->toplevel, wlr_xdg_toplevel_set_wm_capabilities(xdg_surface->toplevel,
WLR_XDG_TOPLEVEL_WM_CAPABILITIES_FULLSCREEN); WLR_XDG_TOPLEVEL_WM_CAPABILITIES_FULLSCREEN);
@@ -1236,10 +1244,26 @@ dirtomon(enum wlr_direction dir) @@ -1236,10 +1245,24 @@ dirtomon(enum wlr_direction dir)
void void
focusclient(Client *c, int lift) focusclient(Client *c, int lift)
{ {
@ -91,15 +103,13 @@ index bf763df..c8da00e 100644
int unused_lx, unused_ly, old_client_type; int unused_lx, unused_ly, old_client_type;
Client *old_c = NULL; Client *old_c = NULL;
LayerSurface *old_l = NULL; LayerSurface *old_l = NULL;
+ xkb_mod_mask_t mdepr, mlatc, mlock;
+ xkb_layout_index_t ldepr, llatc, llock;
+ struct keyboard_group_device *device; + struct keyboard_group_device *device;
+ struct wlr_keyboard *kb = wlr_seat_get_keyboard(seat); + struct wlr_keyboard *kb = wlr_seat_get_keyboard(seat);
+ struct wlr_keyboard_group *group = kb ? wlr_keyboard_group_from_wlr_keyboard(kb) : NULL; + struct wlr_keyboard_group *group = kb ? wlr_keyboard_group_from_wlr_keyboard(kb) : NULL;
if (locked) if (locked)
return; return;
@@ -1292,6 +1316,20 @@ focusclient(Client *c, int lift) @@ -1292,6 +1315,19 @@ focusclient(Client *c, int lift)
} }
printstatus(); printstatus();
@ -108,19 +118,18 @@ index bf763df..c8da00e 100644
+ // Update the first real device, because kb or group->kb is not a real + // Update the first real device, because kb or group->kb is not a real
+ // keyboard and its effective layout gets overwritten + // keyboard and its effective layout gets overwritten
+ device = wl_container_of(group->devices.next, device, link); + device = wl_container_of(group->devices.next, device, link);
+ mdepr = xkb_state_serialize_mods(device->keyboard->xkb_state, XKB_STATE_MODS_DEPRESSED); + wlr_keyboard_notify_modifiers(device->keyboard,
+ mlatc = xkb_state_serialize_mods(device->keyboard->xkb_state, XKB_STATE_MODS_LATCHED); + device->keyboard->modifiers.depressed,
+ mlock = xkb_state_serialize_mods(device->keyboard->xkb_state, XKB_STATE_MODS_LOCKED); + device->keyboard->modifiers.latched,
+ ldepr = xkb_state_serialize_layout(device->keyboard->xkb_state, XKB_STATE_LAYOUT_DEPRESSED); + device->keyboard->modifiers.locked,
+ llatc = xkb_state_serialize_layout(device->keyboard->xkb_state, XKB_STATE_LAYOUT_LATCHED); + c ? c->kblayout_idx : 0
+ llock = c ? c->kblayout_idx : 0; + );
+ xkb_state_update_mask(device->keyboard->xkb_state, mdepr, mlatc, mlock, ldepr, llatc, llock);
+ } + }
+ +
if (!c) { if (!c) {
/* With no client, all we have left is to clear focus */ /* With no client, all we have left is to clear focus */
wlr_seat_keyboard_notify_clear_focus(seat); wlr_seat_keyboard_notify_clear_focus(seat);
@@ -1302,7 +1340,7 @@ focusclient(Client *c, int lift) @@ -1302,7 +1338,7 @@ focusclient(Client *c, int lift)
motionnotify(0, NULL, 0, 0, 0, 0); motionnotify(0, NULL, 0, 0, 0, 0);
/* Have a client, so focus its top-level wlr_surface */ /* Have a client, so focus its top-level wlr_surface */
@ -129,7 +138,7 @@ index bf763df..c8da00e 100644
/* Activate the new client */ /* Activate the new client */
client_activate_surface(client_surface(c), 1); client_activate_surface(client_surface(c), 1);
@@ -1427,6 +1465,36 @@ inputdevice(struct wl_listener *listener, void *data) @@ -1427,6 +1463,36 @@ inputdevice(struct wl_listener *listener, void *data)
wlr_seat_set_capabilities(seat, caps); wlr_seat_set_capabilities(seat, caps);
} }
@ -166,7 +175,7 @@ index bf763df..c8da00e 100644
int int
keybinding(uint32_t mods, xkb_keysym_t sym) keybinding(uint32_t mods, xkb_keysym_t sym)
{ {
@@ -1504,6 +1572,8 @@ keypressmod(struct wl_listener *listener, void *data) @@ -1504,6 +1570,8 @@ keypressmod(struct wl_listener *listener, void *data)
/* Send modifiers to the client. */ /* Send modifiers to the client. */
wlr_seat_keyboard_notify_modifiers(seat, wlr_seat_keyboard_notify_modifiers(seat,
&group->wlr_group->keyboard.modifiers); &group->wlr_group->keyboard.modifiers);
@ -175,3 +184,6 @@ index bf763df..c8da00e 100644
} }
int int
--
2.45.1