From: Andy Spencer Date: Fri, 17 Apr 2015 05:01:26 +0000 (+0000) Subject: Start adding support for atoms X-Git-Url: http://pileus.org/git/?p=wmpus;a=commitdiff_plain;h=84fdb5249282e858b32f59f49a877a07350a48eb Start adding support for atoms --- diff --git a/makefile b/makefile index 1e64c67..400ce7a 100644 --- a/makefile +++ b/makefile @@ -13,7 +13,7 @@ MANPREFIX ?= ${PREFIX}/share/man ifeq ($(SYS),xcb) GCC ?= gcc PROG ?= wmpus -LDFLAGS += -lxcb -lxcb-keysyms -lxcb-util -lxcb-xinerama +LDFLAGS += -lxcb -lxcb-keysyms -lxcb-util -lxcb-ewmh -lxcb-xinerama endif ifeq ($(SYS),xlib) diff --git a/sys-xcb.c b/sys-xcb.c index af650cd..dc8088a 100644 --- a/sys-xcb.c +++ b/sys-xcb.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include "util.h" @@ -36,9 +37,17 @@ static int stack = 25; static int no_capture = 0; /* Internal structures */ +typedef struct { + int left; + int right; + int top; + int bottom; +} strut_t; + struct win_sys { xcb_window_t xcb; // xcb window id xcb_event_mask_t events; // currently watch events + strut_t strut; // toolbar struts int managed; // window is managed by wm }; @@ -50,15 +59,16 @@ typedef enum { } color_t; /* Global data */ -static xcb_connection_t *conn; -static xcb_key_symbols_t *keysyms; -static xcb_colormap_t colormap; -static xcb_window_t root; -static xcb_event_mask_t events; -static list_t *screens; -static void *cache; -static xcb_pixmap_t colors[NCOLORS]; -static unsigned int grabbed; +static xcb_connection_t *conn; +static xcb_ewmh_connection_t ewmh; +static xcb_key_symbols_t *keysyms; +static xcb_colormap_t colormap; +static xcb_window_t root; +static xcb_event_mask_t events; +static list_t *screens; +static void *cache; +static xcb_pixmap_t colors[NCOLORS]; +static unsigned int grabbed; /************************ * Conversion functions * @@ -320,6 +330,41 @@ static int do_get_input_focus(void) return reply->focus; } +static int do_ewmh_init_atoms(void) +{ + xcb_intern_atom_cookie_t *cookies = + xcb_ewmh_init_atoms(conn, &ewmh); + if (!cookies) + return warn("do_ewmh_init_atoms: no cookies"); + + int status = + xcb_ewmh_init_atoms_replies(&ewmh, cookies, NULL); + if (!status) + return warn("do_ewmh_init_atoms: no status"); + return status; +} + +static int do_get_strut(xcb_window_t win, strut_t *strut) +{ + xcb_get_property_cookie_t cookie = + xcb_ewmh_get_wm_strut(&ewmh, win); + if (!cookie.sequence) + return warn("do_get_strut: bad cookie"); + + xcb_ewmh_get_extents_reply_t ext = {}; + int status = + xcb_ewmh_get_wm_strut_reply(&ewmh, cookie, &ext, NULL); + if (!status) + return warn("do_get_strut: no status"); + + strut->left = ext.left; + strut->right = ext.right; + strut->top = ext.top; + strut->bottom = ext.bottom; + + return ext.left || ext.right || ext.top || ext.bottom; +} + static xcb_pixmap_t do_alloc_color(uint32_t rgb) { uint16_t r = (rgb & 0xFF0000) >> 8; @@ -590,6 +635,11 @@ static void on_map_request(xcb_map_request_event_t *event) event->window, win); if (!win) return; + if (do_get_strut(win->sys->xcb, &win->sys->strut)) + printf("Map: Got a strut!\n"); + else + printf("Map: No struts here!\n"); + send_state(win, ST_SHOW); xcb_map_window(conn, win->sys->xcb); sys_move(win, win->x, win->y, win->w, win->h); @@ -915,6 +965,10 @@ void sys_init(void) root = iter.data->root; colormap = iter.data->default_colormap; + /* Setup EWMH connection */ + if (!do_ewmh_init_atoms()) + error("ewmh setup failed"); + /* Setup for for ST_CLOSE */ xcb_set_close_down_mode(conn, XCB_CLOSE_DOWN_DESTROY_ALL);