From 6f54084c0ee63f4b341f8f92efbc8b82d3dfa224 Mon Sep 17 00:00:00 2001 From: Samuel Fadel Date: Thu, 8 Dec 2022 18:25:18 +0100 Subject: Working example with keybindings done from Scheme. * main.scm: Added utility and keybinding calls * wm.scm: Added necessary bindings to C code * schewm.c: Some utility functions for grabbing keys --- schewm.c | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) (limited to 'schewm.c') diff --git a/schewm.c b/schewm.c index 126ab2f..4a3811a 100644 --- a/schewm.c +++ b/schewm.c @@ -465,6 +465,7 @@ typedef void (*generic_event_handler_t)(xcb_generic_event_t *); static struct { uint32_t cur_workspace, num_workspaces; bool is_running; + uint16_t mod_key; struct Client *focus; struct ClientsMap *clients; struct Workspace *workspaces; @@ -1778,6 +1779,29 @@ wm_fit_client(struct Client *client) { return should_move || should_resize; } +void +wm_set_mod_key(uint16_t mod) { + wm.mod_key = mod; +} + +uint16_t +wm_get_mod_key(bool with_shift) { + if (with_shift) { + return wm.mod_key | MOD_SHIFT; + } + return wm.mod_key; +} + +void +wm_grab_key_with_mod(xcb_keysym_t keysym) { + dpy_grab_key(wm_get_mod_key(false), keysym); +} + +void +wm_grab_key_with_mod_shift(xcb_keysym_t keysym) { + dpy_grab_key(wm_get_mod_key(true), keysym); +} + /* * event handlers which take a generic event and know what to cast it into. */ @@ -1879,8 +1903,7 @@ wm_init() { dpy_update_window_list(wm.clients); wm_set_workspace(wm.cur_workspace); - // grab_keys(); - dpy_grab_key(XCB_MOD_MASK_ANY, XK_q); + wm.mod_key = MOD_META; dpy_flush(); memset(wm.events, 0, sizeof(wm.events)); @@ -1930,21 +1953,6 @@ wm_run() { wm_destroy(); } -static uint16_t mod_key = MOD_META; - -void -wm_set_mod_key(uint16_t mod) { - mod_key = mod; -} - -uint16_t -wm_get_mod_key(bool with_shift) { - if (with_shift) { - return mod_key | MOD_SHIFT; - } - return mod_key; -} - /* * NOTE: * Don't do the thing below. Create hooks for relevant stuff the user -- cgit v1.2.3