kbgwm

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

commit ac39f5d141b39ee9d8a09c8eb6859d6908bd04e0
parent f0eafa4cea296b091bcd1c41c03c9b97ef481abf
Author: Kebigon <git@kebigon.xyz>
Date:   Thu,  2 Jul 2020 20:28:36 +0900

Start messing around with XCB

Diffstat:
Asrc/config.h | 7+++++++
Asrc/kbgwm.c | 100+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 107 insertions(+), 0 deletions(-)

diff --git a/src/config.h b/src/config.h @@ -0,0 +1,7 @@ + +#define MODKEY XCB_MOD_MASK_4 + +Key keys[] = +{ + { MODKEY, XK_Return } +}; diff --git a/src/kbgwm.c b/src/kbgwm.c @@ -0,0 +1,100 @@ +#include <stdio.h> +#include <stdlib.h> +#include <stdbool.h> + +#include <xcb/xcb.h> +#include <xcb/xcb_keysyms.h> +#include <X11/keysym.h> + +#define LENGTH(X) (sizeof X / sizeof X[0]) + +typedef struct { + uint16_t modifiers; + xcb_keysym_t key; +} Key; + +#include "config.h" + +bool quit = false; +xcb_connection_t *c; +xcb_window_t root; + +void setupEvents() +{ + /* + * Get all the key symbols + */ + xcb_key_symbols_t *syms = xcb_key_symbols_alloc(c); + + for (int i = 0; i != LENGTH(keys); i++) + { + xcb_keycode_t *keycode = xcb_key_symbols_get_keycode(syms, keys[i].key); + + xcb_grab_key(c, 1, root, keys[i].modifiers, keycode, + XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC); + + free(keycode); + } + + xcb_key_symbols_free(syms); +} + +void eventLoop() +{ + xcb_generic_event_t *event; + + while (!quit) + { + event = xcb_wait_for_event(c); + + switch (event->response_type & ~0x80) + { + } + + free(event); + } +} + +int main(void) +{ + /* + * displayname = NULL -> use DISPLAY environment variable + */ + int screenp; + c = xcb_connect(NULL, &screenp); + if (xcb_connection_has_error(c)) + { + perror("xcb_connect"); + exit(1); + } + + /* + * Find the screen + */ + xcb_screen_iterator_t iter = xcb_setup_roots_iterator(xcb_get_setup(c)); + for (int i = 0; i < screenp; ++i) + { + xcb_screen_next(&iter); + } + + xcb_screen_t *screen = iter.data; + if (!screen) + { + xcb_disconnect(c); + perror("screen not found"); + exit(1); + } + + root = screen->root; + + xcb_flush(c); + + setupEvents(); + + // Event loop + eventLoop(); + + xcb_disconnect(c); + + return 0; +}