diff options
author | Samuel Fadel <samuel@nihil.ws> | 2022-12-08 18:25:18 +0100 |
---|---|---|
committer | Samuel Fadel <samuel@nihil.ws> | 2022-12-08 18:25:18 +0100 |
commit | 6f54084c0ee63f4b341f8f92efbc8b82d3dfa224 (patch) | |
tree | 454e8d7cf51aa4cded69535d60ec56a753325034 /schewm.c | |
parent | 6bdaee03c0fd3caac390dffdaaf52d54653b1430 (diff) |
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
Diffstat (limited to 'schewm.c')
-rw-r--r-- | schewm.c | 42 |
1 files changed, 25 insertions, 17 deletions
@@ -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 |