gimp but for windows: a wayland compositor
git clone https://github.com/m-col/wimp
Files | Refs | Readme

Commit 5517e33716b4e0a49c0f7a7c0b800f89538dfe90
Parent: f46a74c68fb081dd3b6cd04fdcc782a914e75d5b
Author: mcol <mcol@posteo.net>
Date: 2021-01-27 22:40:20 +0000
Committer: mcol <mcol@posteo.net>
Committed: 2021-01-27 22:40:20 +0000

Use shift level 0 key syms for custom key bindings

fixes #1

wimp.conf Modified

@@ -51,10 +51,10 @@
 bind		f		toggle_fullscreen
 
 # These give the focussed window half of the screen
-bind	Shift	J		halfimize down
-bind	Shift	K		halfimize up
-bind	Shift	H		halfimize left
-bind	Shift	L		halfimize right
+bind	Shift	j		halfimize down
+bind	Shift	k		halfimize up
+bind	Shift	h		halfimize left
+bind	Shift	l		halfimize right
 
 # And these act on desks
 bind		Tab		next_desk

src/keyboard.c Modified

@@ -40,21 +40,18 @@
 
 
 static void on_key(struct wl_listener *listener, void *data) {
-    struct keyboard *keyboard = wl_container_of(listener, keyboard, key_listener);
     struct wlr_event_keyboard_key *event = data;
-    struct wlr_seat *seat = wimp.seat;
-
-    const xkb_keysym_t *syms;
-    int nsyms = xkb_state_key_get_syms(
-	keyboard->device->keyboard->xkb_state,
-	event->keycode + 8,
-	&syms
-    );
 
     if (event->state == WLR_KEY_PRESSED) {
+	const xkb_keysym_t *syms;
+	xkb_keycode_t keycode = event->keycode + 8;
+	struct keyboard *keyboard = wl_container_of(listener, keyboard, key_listener);
+	struct wlr_keyboard *wlr_kb = keyboard->device->keyboard;
+
 	if (wimp.mark_waiting) {
-	    wimp.mark_waiting = false;
 	    struct mark *mark;
+	    wimp.mark_waiting = false;
+	    xkb_state_key_get_syms(wlr_kb->xkb_state, keycode, &syms);
 	    mark = wl_container_of(wimp.marks.next, mark, link);
 	    if (mark->key == 0) {
 		actually_set_mark(syms[0]);
@@ -67,6 +64,11 @@
 	uint32_t modifiers = wlr_keyboard_get_modifiers(keyboard->device->keyboard);
 	struct binding *kb;
 	if ((modifiers & wimp.mod)) {
+	    xkb_layout_index_t layout_index = xkb_state_key_get_layout(wlr_kb->xkb_state, keycode);
+	    int nsyms = xkb_keymap_key_get_syms_by_level(
+		wlr_kb->keymap, keycode, layout_index, 0, &syms
+	    );
+
 	    modifiers &= ~wimp.mod;
 	    for (int i = 0; i < nsyms; i++) {
 		wl_list_for_each(kb, &wimp.key_bindings, link) {
@@ -81,7 +83,7 @@
 
     // forward to client
     wlr_seat_keyboard_notify_key(
-	seat, event->time_msec, event->keycode, event->state
+	wimp.seat, event->time_msec, event->keycode, event->state
     );
 }