kbgwm

sucklessy floating window manager
git clone https://git.neuralcrash.com/kbgwm.git
Log | Files | Refs | README | LICENSE

commit f4a993933941b89c42524547c9d0d6185a77133a
parent 0eb7e85e23b872b0d43b3dc00d7c9a5f8d1fd422
Author: Kebigon <git@kebigon.xyz>
Date:   Sun, 19 Jul 2020 15:18:14 +0900

Ignore numlock and shift modifiers
Diffstat:
Mkbgwm.c | 46++++++++++++++++++++++++++++++++++++++++++----
Mxcbutils.c | 20++++++++++----------
2 files changed, 52 insertions(+), 14 deletions(-)

diff --git a/kbgwm.c b/kbgwm.c @@ -10,8 +10,7 @@ #include <inttypes.h> #include "xcbutils.h" -#define IGNORE_LOCK(modifier) (modifier & ~(XCB_MOD_MASK_LOCK)) -#define MATCH_MODIFIERS(expected, actual) ((actual & expected) == expected) +#define CLEANMASK(mask) (mask & ~(numlockmask|XCB_MOD_MASK_LOCK)) static void start(const Arg* arg); static void mousemove(const Arg* arg); @@ -59,6 +58,7 @@ xcb_window_t root; xcb_screen_t* screen; uint_least16_t previous_x; uint_least16_t previous_y; +uint16_t numlockmask = 0; #define focused_client workspaces[current_workspace] uint_fast8_t current_workspace = 0; @@ -437,7 +437,7 @@ void handle_button_press(xcb_button_press_event_t* event) for (uint_fast8_t i = 0; i < LENGTH(buttons); i++) { - if (event->detail == buttons[i].keysym && MATCH_MODIFIERS(buttons[i].modifiers, event->state)) + if (event->detail == buttons[i].keysym && CLEANMASK(buttons[i].modifiers) == CLEANMASK(event->state)) { previous_x = event->root_x; previous_y = event->root_y; @@ -478,7 +478,7 @@ void handle_key_press(xcb_key_press_event_t* event) for (uint_fast8_t i = 0; i < LENGTH(keys); i++) { - if (keysym == keys[i].keysym && MATCH_MODIFIERS(keys[i].modifiers, event->state)) + if (keysym == keys[i].keysym && CLEANMASK(keys[i].modifiers) == CLEANMASK(event->state)) { keys[i].func(&keys[i].arg); break; @@ -553,6 +553,43 @@ void handle_unmap_notify(xcb_unmap_notify_event_t* event) * Setup */ +// Retrieve the numlock keycode +void setup_keyboard() +{ + xcb_get_modifier_mapping_reply_t* reply = xcb_get_modifier_mapping_reply(c, xcb_get_modifier_mapping_unchecked(c), NULL); + if (!reply) + { + printf("Unable to retrieve midifier mapping"); + exit(-1); + } + + xcb_keycode_t* modmap = xcb_get_modifier_mapping_keycodes(reply); + if (!modmap) + { + printf("Unable to retrieve midifier mapping keycodes"); + exit(-1); + } + + xcb_keycode_t* numlock = xcb_get_keycodes(XK_Num_Lock); + + // Not sure why 8, I looked at both dwm and 2bwm, and they both do the same + for (uint_fast8_t i = 0; i < 8; i++) + { + for (uint_fast8_t j = 0; j < reply->keycodes_per_modifier; j++) + { + xcb_keycode_t keycode = modmap[i * reply->keycodes_per_modifier + j]; + + if (keycode == *numlock) + { + numlockmask = (1 << i); + printf("numlock is %d", keycode); + } + } + } + + free(reply); +} + void setup_events() { uint32_t values[] = { XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT | XCB_EVENT_MASK_STRUCTURE_NOTIFY @@ -712,6 +749,7 @@ int main(void) for (uint_fast8_t i = 0; i != NB_WORKSPACES; i++) workspaces[i] = NULL; + setup_keyboard(); setup_screen(); setup_events(); diff --git a/xcbutils.c b/xcbutils.c @@ -5,6 +5,7 @@ extern xcb_connection_t* c; extern xcb_window_t root; +extern uint16_t numlockmask; void* emalloc(size_t size) { @@ -25,23 +26,20 @@ void* emalloc(size_t size) * */ -// TODO: understand why XCB_MOD_MASK_2 is always present -#define IGNORED_MODIFIERS XCB_MOD_MASK_2 - void xcb_register_key_events(Key key) { xcb_keycode_t* keycodes; xcb_keycode_t keycode; - printf("Registering key press event for key %d / key %d\n", key.modifiers, - key.keysym); + printf("Registering key press event for key %d / key %d\n", key.modifiers, key.keysym); keycodes = xcb_get_keycodes(key.keysym); + uint16_t modifiers[] = { 0, numlockmask, XCB_MOD_MASK_LOCK, numlockmask | XCB_MOD_MASK_LOCK }; for (int i = 0; (keycode = keycodes[i]) != XCB_NO_SYMBOL; i++) { - xcb_grab_key(c, 1, root, key.modifiers | IGNORED_MODIFIERS, keycode, - XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC); + for (int j = 0; j != LENGTH(modifiers); j++) + xcb_grab_key(c, 1, root, key.modifiers | modifiers[j], keycode, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC); } free(keycodes); @@ -49,9 +47,11 @@ void xcb_register_key_events(Key key) void xcb_register_button_events(Button button) { - xcb_grab_button(c, 0, root, - BUTTON_EVENT_MASK, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC, root, - XCB_NONE, button.keysym, button.modifiers | IGNORED_MODIFIERS); + uint16_t modifiers[] = { 0, numlockmask, XCB_MOD_MASK_LOCK, numlockmask | XCB_MOD_MASK_LOCK }; + + for (int i = 0; i != LENGTH(modifiers); i++) + xcb_grab_button(c, 0, root, BUTTON_EVENT_MASK, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC, root, XCB_NONE, button.keysym, + button.modifiers | modifiers[i]); } /*