[Xcb-commit] configure.ac ewmh Makefile.am

Arnaud Fontaine arnau at kemper.freedesktop.org
Wed Jul 29 04:08:03 PDT 2009


Rebased ref, commits from common ancestor:
commit 6aaac24d7eaff0d7efcc655a0e4d76f049e384ef
Author: Arnaud Fontaine <arnau at debian.org>
Date:   Mon Jul 13 10:07:16 2009 +0100

    Add EWMH support but not finished yet

diff --git a/Makefile.am b/Makefile.am
index 5a98062..d60d5e4 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,6 +1,6 @@
 
 MAINTAINERCLEANFILES = Makefile.in
 
-SUBDIRS = atom aux event property icccm image keysyms reply renderutil
+SUBDIRS = atom aux event property icccm ewmh image keysyms reply renderutil
 
 EXTRA_DIST=xcb-util-common.h
diff --git a/configure.ac b/configure.ac
index 714b617..5deb5cb 100644
--- a/configure.ac
+++ b/configure.ac
@@ -85,6 +85,8 @@ XCB_PROPERTY_CFLAGS='-I$(top_srcdir)/property'
 XCB_PROPERTY_LIBS='$(top_builddir)/property/libxcb-property.la'
 XCB_ICCCM_CFLAGS='-I$(top_srcdir)/icccm'
 XCB_ICCCM_LIBS='$(top_builddir)/icccm/libxcb-icccm.la'
+XCB_EWMH_CFLAGS='-I$(top_srcdir)/ewmh'
+XCB_EWMH_LIBS='$(top_builddir)/ewmh/libxcb-ewmh.la'
 AC_SUBST(XCB_AUX_CFLAGS)
 AC_SUBST(XCB_AUX_LIBS)
 AC_SUBST(XCB_ATOM_CFLAGS)
@@ -95,6 +97,8 @@ AC_SUBST(XCB_PROPERTY_CFLAGS)
 AC_SUBST(XCB_PROPERTY_LIBS)
 AC_SUBST(XCB_ICCCM_CFLAGS)
 AC_SUBST(XCB_ICCCM_LIBS)
+AC_SUBST(XCB_EWMH_CFLAGS)
+AC_SUBST(XCB_EWMH_LIBS)
 
 AC_OUTPUT([Makefile
 	aux/Makefile aux/xcb-aux.pc
@@ -105,6 +109,7 @@ AC_OUTPUT([Makefile
 	keysyms/Makefile keysyms/xcb-keysyms.pc
 	property/Makefile property/xcb-property.pc
 	icccm/Makefile icccm/xcb-icccm.pc
+	ewmh/Makefile ewmh/xcb-ewmh.pc
 	renderutil/Makefile renderutil/xcb-renderutil.pc
 	xcb_util_intro
 	])
diff --git a/ewmh/Makefile.am b/ewmh/Makefile.am
new file mode 100644
index 0000000..3e5f739
--- /dev/null
+++ b/ewmh/Makefile.am
@@ -0,0 +1,25 @@
+MAINTAINERCLEANFILES = Makefile.in
+
+lib_LTLIBRARIES = libxcb-ewmh.la
+
+xcbinclude_HEADERS = xcb_ewmh.h
+
+AM_CFLAGS = $(CWARNFLAGS)
+
+libxcb_ewmh_la_SOURCES = ewmh.c ewmh.c.m4 atomlist.m4 xcb_ewmh.h.m4
+libxcb_ewmh_la_CPPFLAGS = $(XCB_CFLAGS) $(XCB_ATOM_CFLAGS) $(XCB_AUX_CFLAGS)
+libxcb_ewmh_la_LIBADD = $(XCB_LIBS) $(XCB_ATOM_LIBS) $(XCB_AUX_LIBS)
+libxcb_ewmh_la_LDFLAGS = -version-info 1:0:0
+
+pkgconfig_DATA = xcb-ewmh.pc
+
+EXTRA_DIST = xcb-ewmh.pc.in
+
+BUILT_SOURCES = ewmh.c xcb_ewmh.h
+CLEANFILES = $(BUILT_SOURCES)
+
+ewmh.c: ewmh.c.m4 atomlist.m4
+	$(M4) -I$(srcdir) $< >$@
+
+xcb_ewmh.h: xcb_ewmh.h.m4 atomlist.m4
+	$(M4) -I$(srcdir) $< >$@
diff --git a/ewmh/atomlist.m4 b/ewmh/atomlist.m4
new file mode 100644
index 0000000..f70d87b
--- /dev/null
+++ b/ewmh/atomlist.m4
@@ -0,0 +1,82 @@
+DO(
+_NET_SUPPORTED,
+_NET_CLIENT_LIST,
+_NET_NUMBER_OF_DESKTOPS,
+_NET_DESKTOP_GEOMETRY,
+_NET_DESKTOP_VIEWPORT,
+_NET_CURRENT_DESKTOP,
+_NET_DESKTOP_NAMES,
+_NET_ACTIVE_WINDOW,
+_NET_WORKAREA,
+_NET_SUPPORTING_WM_CHECK,
+_NET_VIRTUAL_ROOTS,
+_NET_DESKTOP_LAYOUT,
+_NET_SHOWING_DESKTOP,
+_NET_CLOSE_WINDOW,
+_NET_MOVERESIZE_WINDOW,
+_NET_WM_MOVERESIZE,
+_NET_RESTACK_WINDOW,
+_NET_REQUEST_FRAME_EXTENTS,
+_NET_WM_NAME,
+_NET_WM_VISIBLE_NAME,
+_NET_WM_ICON_NAME,
+_NET_WM_VISIBLE_ICON_NAME,
+_NET_WM_DESKTOP,
+_NET_WM_WINDOW_TYPE,
+_NET_WM_STATE,
+_NET_WM_ALLOWED_ACTIONS,
+_NET_WM_STRUT,
+_NET_WM_STRUT_PARTIAL,
+_NET_WM_ICON_GEOMETRY,
+_NET_WM_ICON,
+_NET_WM_PID,
+_NET_WM_HANDLED_ICONS,
+_NET_WM_USER_TIME,
+_NET_WM_USER_TIME_WINDOW,
+_NET_FRAME_EXTENTS,
+_NET_WM_PING,
+_NET_WM_SYNC_REQUEST,
+_NET_WM_FULLSCREEN_MONITORS,
+_NET_WM_FULL_PLACEMENT,
+UTF8_STRING,
+WM_PROTOCOLS,
+MANAGER,
+_NET_WM_CM_Sn,
+_NET_WM_WINDOW_TYPE_DESKTOP,
+_NET_WM_WINDOW_TYPE_DOCK,
+_NET_WM_WINDOW_TYPE_TOOLBAR,
+_NET_WM_WINDOW_TYPE_MENU,
+_NET_WM_WINDOW_TYPE_UTILITY,
+_NET_WM_WINDOW_TYPE_SPLASH,
+_NET_WM_WINDOW_TYPE_DIALOG,
+_NET_WM_WINDOW_TYPE_DROPDOWN_MENU,
+_NET_WM_WINDOW_TYPE_POPUP_MENU,
+_NET_WM_WINDOW_TYPE_TOOLTIP,
+_NET_WM_WINDOW_TYPE_NOTIFICATION,
+_NET_WM_WINDOW_TYPE_COMBO,
+_NET_WM_WINDOW_TYPE_DND,
+_NET_WM_WINDOW_TYPE_NORMAL,
+_NET_WM_STATE_MODAL,
+_NET_WM_STATE_STICKY,
+_NET_WM_STATE_MAXIMIZED_VERT,
+_NET_WM_STATE_MAXIMIZED_HORZ,
+_NET_WM_STATE_SHADED,
+_NET_WM_STATE_SKIP_TASKBAR,
+_NET_WM_STATE_SKIP_PAGER,
+_NET_WM_STATE_HIDDEN,
+_NET_WM_STATE_FULLSCREEN,
+_NET_WM_STATE_ABOVE,
+_NET_WM_STATE_BELOW,
+_NET_WM_STATE_DEMANDS_ATTENTION,
+_NET_WM_ACTION_MOVE,
+_NET_WM_ACTION_RESIZE,
+_NET_WM_ACTION_MINIMIZE,
+_NET_WM_ACTION_SHADE,
+_NET_WM_ACTION_STICK,
+_NET_WM_ACTION_MAXIMIZE_HORZ,
+_NET_WM_ACTION_MAXIMIZE_VERT,
+_NET_WM_ACTION_FULLSCREEN,
+_NET_WM_ACTION_CHANGE_DESKTOP,
+_NET_WM_ACTION_CLOSE,
+_NET_WM_ACTION_ABOVE,
+_NET_WM_ACTION_BELOW)
diff --git a/ewmh/ewmh.c.m4 b/ewmh/ewmh.c.m4
new file mode 100644
index 0000000..806d768
--- /dev/null
+++ b/ewmh/ewmh.c.m4
@@ -0,0 +1,1430 @@
+/*
+ * Copyright © 2009 Arnaud Fontaine <arnau at debian.org>
+ *
+ * Permission  is  hereby  granted,  free  of charge,  to  any  person
+ * obtaining  a copy  of  this software  and associated  documentation
+ * files   (the  "Software"),   to  deal   in  the   Software  without
+ * restriction, including without limitation  the rights to use, copy,
+ * modify, merge, publish,  distribute, sublicense, and/or sell copies
+ * of  the Software, and  to permit  persons to  whom the  Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The  above copyright  notice and  this permission  notice  shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE  IS PROVIDED  "AS IS", WITHOUT  WARRANTY OF  ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT  NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY,   FITNESS    FOR   A   PARTICULAR    PURPOSE   AND
+ * NONINFRINGEMENT. IN  NO EVENT SHALL  THE AUTHORS BE LIABLE  FOR ANY
+ * CLAIM,  DAMAGES  OR  OTHER  LIABILITY,  WHETHER  IN  AN  ACTION  OF
+ * CONTRACT, TORT OR OTHERWISE, ARISING  FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Except as  contained in  this notice, the  names of the  authors or
+ * their institutions shall not be used in advertising or otherwise to
+ * promote the  sale, use or  other dealings in this  Software without
+ * prior written authorization from the authors.
+ */
+
+#include <string.h>
+#include <limits.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <assert.h>
+
+#include "xcb_ewmh.h"
+#include "xcb_atom.h"
+#include "xcb_aux.h"
+#include "../xcb-util-common.h"
+
+static xcb_window_t root_window;
+
+#define ROOT_WINDOW_MESSAGE_EVENT_MASK (XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY |\
+					XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT)
+
+typedef struct {
+  xcb_atom_t *value;
+  xcb_intern_atom_cookie_t cookie;
+  uint8_t name_len;
+  char *name;
+} ewmh_atom_t;
+
+define(`DO', `ifelse(`$1', , , `xcb_atom_t $1;
+DO(shift($@))')')dnl
+include(atomlist.m4)dnl
+
+define(`DO_ENTRY', `
+  { &$1, { 0 }, sizeof("$1") - 1, "$1" }ifelse(`$2', , , `,')')dnl
+
+define(`DO', `DO_ENTRY(`$1', `$2')ifelse(`$2', , , `DO(shift($@))')')dnl
+
+static ewmh_atom_t ewmh_atoms_list[] = {dnl
+  include(atomlist.m4)dnl
+};
+
+#define NB_EWMH_ATOMS countof(ewmh_atoms_list)
+
+/**
+ * Common functions and macro
+ */
+
+#define DO_GET_PROPERTY(atom, name, request_type, length)		\
+  xcb_get_property_cookie_t						\
+  xcb_ewmh_get_##name(xcb_connection_t *c,				\
+		      xcb_window_t window)				\
+  {									\
+    return xcb_get_property(c, 0, window, atom, request_type, 0,	\
+			    length);					\
+  }									\
+									\
+  xcb_get_property_cookie_t						\
+  xcb_ewmh_get_##name##_unchecked(xcb_connection_t *c,			\
+				  xcb_window_t window)			\
+  {									\
+    return xcb_get_property_unchecked(c, 0, window, atom,		\
+				      request_type, 0, length);		\
+  }
+
+/**
+ * Generic  function for  EWMH atoms  with  a single  value which  may
+ * actually be either WINDOW or CARDINAL
+ *
+ * _NET_NUMBER_OF_DESKTOPS, CARDINAL/32
+ * _NET_CURRENT_DESKTOP desktop, CARDINAL/32
+ * _NET_ACTIVE_WINDOW, WINDOW/32
+ * _NET_SUPPORTING_WM_CHECK, WINDOW/32
+ * _NET_SHOWING_DESKTOP desktop, CARDINAL/32
+ * _NET_WM_DESKTOP desktop, CARDINAL/32
+ * _NET_WM_PID CARDINAL/32
+ * _NET_WM_USER_TIME CARDINAL/32
+ * _NET_WM_USER_TIME_WINDOW WINDOW/32
+ */
+
+/**
+ * Macro defining function for set_property and get_property functions
+ */
+#define DO_SET_SINGLE_VALUE_PROPERTY(atom, name, name_type, request_type) \
+  void									\
+  xcb_ewmh_set_##name##_checked(xcb_connection_t *c,			\
+                                xcb_window_t window,			\
+				name_type value)			\
+  {									\
+    xcb_change_property_checked(c, XCB_PROP_MODE_REPLACE, window, atom,	\
+				request_type, 32, 1, &value);		\
+  }									\
+									\
+  void									\
+  xcb_ewmh_set_##name(xcb_connection_t *c,				\
+		      xcb_window_t window,				\
+		      name_type value)					\
+  {									\
+    xcb_change_property(c, XCB_PROP_MODE_REPLACE, window, atom,		\
+			request_type, 32, 1, &value);			\
+  }
+
+/**
+ * Macro  defining a generic  function for  reply containing  a single
+ * value
+ */
+#define DO_REPLY_SINGLE_VALUE_ATOM(name, name_type, reply_type)		\
+  static uint8_t							\
+  get_single_##name##_from_reply(name_type *atom_value,			\
+				 xcb_get_property_reply_t *r)		\
+  {									\
+    if(!r || r->type != reply_type || r->format != 32 ||		\
+       xcb_get_property_value_length(r) != 4)		\
+      return 0;								\
+									\
+    *atom_value = *((name_type *) xcb_get_property_value(r));		\
+    return 1;								\
+  }									\
+									\
+  static uint8_t							\
+  get_single_##name##_reply(xcb_connection_t *c,			\
+			    xcb_get_property_cookie_t cookie,		\
+			    name_type *atom_value,			\
+			    xcb_generic_error_t **e)			\
+  {									\
+    xcb_get_property_reply_t *r = xcb_get_property_reply(c, cookie, e);	\
+    const uint8_t ret = get_single_##name##_from_reply(atom_value, r);	\
+    free(r);								\
+    return ret;								\
+  }
+
+DO_REPLY_SINGLE_VALUE_ATOM(window, xcb_window_t, WINDOW)
+DO_REPLY_SINGLE_VALUE_ATOM(cardinal, uint32_t, CARDINAL)
+
+#define DO_ACCESSORS_SINGLE_VALUE_ATOM(atom, name, reply_type, out_type, func_reply) \
+  DO_GET_PROPERTY(atom, name, reply_type, 1L)				\
+  DO_SET_SINGLE_VALUE_PROPERTY(atom, name, out_type, reply_type)	\
+									\
+  uint8_t								\
+  xcb_ewmh_get_##name##_from_reply(out_type *out,			\
+				   xcb_get_property_reply_t *r)		\
+  {									\
+    return get_single_##func_reply##_from_reply(out, r);		\
+  }									\
+									\
+  uint8_t								\
+  xcb_ewmh_get_##name##_reply(xcb_connection_t *c,			\
+			      xcb_get_property_cookie_t cookie,		\
+			      out_type *out,				\
+			      xcb_generic_error_t **e)			\
+  {									\
+    return get_single_##func_reply##_reply(c, cookie, out, e);		\
+  }
+
+/**
+ * Generic function for EWMH atoms with  a list of values which may be
+ * actually WINDOW or ATOM.
+ *
+ * _NET_SUPPORTED, ATOM[]/32
+ * _NET_CLIENT_LIST, WINDOW[]/32
+ * _NET_CLIENT_LIST_STACKING, WINDOW[]/32
+ * _NET_VIRTUAL_ROOTS, WINDOW[]/32
+ * _NET_WM_WINDOW_TYPE, ATOM[]/32
+ * _NET_WM_ALLOWED_ACTIONS, ATOM[]
+ */
+
+#define DO_SET_LIST_VALUES_PROPERTY(atom, name, name_type, request_type, len_shift) \
+  void									\
+  xcb_ewmh_set_##name##_checked(xcb_connection_t *c,			\
+				xcb_window_t window,			\
+				uint32_t list_len,			\
+				name_type *list)			\
+  {									\
+    xcb_change_property_checked(c, XCB_PROP_MODE_REPLACE, window,	\
+				atom, request_type, 32,			\
+				list_len << len_shift, list);		\
+  }									\
+									\
+  void									\
+  xcb_ewmh_set_##name(xcb_connection_t *c,				\
+		      xcb_window_t window,				\
+		      uint32_t list_len,				\
+		      name_type *list)					\
+  {									\
+    xcb_change_property(c, XCB_PROP_MODE_REPLACE, window, atom,		\
+			request_type, 32, list_len << len_shift,	\
+			list);						\
+  }
+
+/**
+ * Macro defining  a generic function  for reply containing a  list of
+ * values and also defines a function to wipe the reply.
+ *
+ * The length is right-shifted by  (len_shift + 2) respectively to get
+ * the actual length of a list  values from a value made from multiple
+ * component  (such as  coordinates), and  divide by  (r->format  / 8)
+ * where r->format always equals to 32 in this case.
+ *
+ * TODO: _len proper value?
+ */
+#define DO_REPLY_LIST_VALUES_ATOM(visibility, name, name_type, reply_type, len_shift) \
+  visibility uint8_t							\
+  xcb_ewmh_get_##name##_from_reply(xcb_ewmh_get_##name##_reply_t *data, \
+				   xcb_get_property_reply_t *r)		\
+  {									\
+    if(!r || r->type != reply_type || r->format != 32)                  \
+      return 0;								\
+									\
+    data->_reply = r;							\
+    data->name##_len = xcb_get_property_value_length(data->_reply) >> (len_shift + 2); \
+    data->name = (name_type *) xcb_get_property_value(data->_reply);	\
+    return 1;								\
+  }									\
+									\
+  visibility uint8_t							\
+  xcb_ewmh_get_##name##_reply(xcb_connection_t *c,			\
+			      xcb_get_property_cookie_t cookie,		\
+			      xcb_ewmh_get_##name##_reply_t *data,	\
+			      xcb_generic_error_t **e)			\
+  {									\
+    xcb_get_property_reply_t *r = xcb_get_property_reply(c, cookie, e);	\
+    const uint8_t ret = xcb_ewmh_get_##name##_from_reply(data, r);	\
+									\
+    /* If the  last call  was not successful  (ret equals to  0), then	\
+       just free the reply as the data value is not consistent */	\
+    if(!ret)								\
+      free(r);								\
+									\
+    return ret;								\
+  }									\
+									\
+  void									\
+  xcb_ewmh_get_##name##_reply_wipe(xcb_ewmh_get_##name##_reply_t *data)	\
+  {									\
+    free(data->_reply);							\
+  }
+
+DO_REPLY_LIST_VALUES_ATOM(static, windows, xcb_window_t, WINDOW, 0)
+DO_REPLY_LIST_VALUES_ATOM(static, atoms, xcb_atom_t, ATOM, 0)
+
+/**
+ * UTF8_STRING handling
+ */
+
+static uint8_t
+get_utf8_from_reply(xcb_ewmh_get_utf8_string_reply_t *data,
+		    xcb_get_property_reply_t *r)
+{
+  if(!r || r->type != UTF8_STRING || r->format != 8)
+    return 0;
+
+  data->_reply = r;
+  data->string_len = xcb_get_property_value_length(data->_reply);
+  data->string = (char *) xcb_get_property_value(data->_reply);
+
+  return 1;
+}
+
+static uint8_t
+get_utf8_reply(xcb_connection_t *c,
+	       xcb_get_property_cookie_t cookie,
+	       xcb_ewmh_get_utf8_string_reply_t *data,
+	       xcb_generic_error_t **e)
+{
+  xcb_get_property_reply_t *r = xcb_get_property_reply(c, cookie, e);
+  const uint8_t ret = get_utf8_from_reply(data, r);
+
+  /* If the last call was not  successful (ret equals to 0), then just
+     free the reply as the data value is not consistent */
+  if(!ret)
+    free(r);
+
+  return ret;
+}
+
+void
+xcb_ewmh_get_utf8_string_reply_wipe(xcb_ewmh_get_utf8_string_reply_t *data)
+{
+  free(data->_reply);
+}
+
+#define DO_ACCESSORS_UTF8_STRING(atom, name)				\
+  DO_GET_PROPERTY(atom, name, 0, UINT_MAX)				\
+									\
+  void									\
+  xcb_ewmh_set_##name(xcb_connection_t *c,				\
+		      xcb_window_t window,				\
+		      uint32_t string_len,				\
+		      const char *string)				\
+  {									\
+    xcb_change_property(c, XCB_PROP_MODE_REPLACE, window, atom,		\
+			UTF8_STRING, 8,	string_len, string);		\
+  }									\
+									\
+  void									\
+  xcb_ewmh_set_##name##_checked(xcb_connection_t *c,			\
+				xcb_window_t window,			\
+				uint32_t string_len,			\
+				const char *string)			\
+  {									\
+    xcb_change_property_checked(c, XCB_PROP_MODE_REPLACE, window, atom,	\
+				UTF8_STRING, 8,	string_len, string);	\
+  }									\
+									\
+  uint8_t								\
+  xcb_ewmh_get_##name##_from_reply(xcb_ewmh_get_utf8_string_reply_t *data, \
+				   xcb_get_property_reply_t *r)		\
+  {									\
+    return get_utf8_from_reply(data, r);				\
+  }									\
+  									\
+  uint8_t								\
+  xcb_ewmh_get_##name##_reply(xcb_connection_t *c,			\
+			      xcb_get_property_cookie_t cookie,		\
+			      xcb_ewmh_get_utf8_string_reply_t *data,	\
+			      xcb_generic_error_t **e)			\
+  {									\
+    return get_utf8_reply(c, cookie, data, e);				\
+  }
+
+/**
+ * ClientMessage generic function
+ */
+void
+send_client_message(xcb_connection_t *c,
+		    xcb_window_t window,
+		    xcb_window_t dest,
+		    xcb_atom_t atom,
+		    uint32_t data_len,
+		    const uint32_t *data)
+{
+  xcb_client_message_event_t ev;
+  memset(&ev, 0, sizeof(xcb_client_message_event_t));
+
+  ev.response_type = XCB_CLIENT_MESSAGE;
+  ev.window = window;
+  ev.format = 32;
+  ev.type = atom;
+
+  for(; data_len != 0; data_len--)
+    ev.data.data32[0] = data[1];
+    
+  xcb_send_event(c, 0, dest, ROOT_WINDOW_MESSAGE_EVENT_MASK,
+		 (char *) &ev);
+}
+
+/**
+ * Atoms initialisation
+ */
+
+void
+xcb_ewmh_init_atoms_list(xcb_connection_t *c,
+			 const int screen_nbr)
+{
+  xcb_screen_t *screen = xcb_aux_get_screen(c, screen_nbr);
+  if(!screen)
+    return;
+
+  /* Compute _NET_WM_CM_Sn according to the screen number 'n' */
+  char wm_cm_sn[32];
+  const int wm_cm_sn_len = snprintf(wm_cm_sn, 32, "_NET_WM_CM_S%d",
+				    screen_nbr);
+
+  assert(wm_cm_sn_len > 0 && wm_cm_sn_len < 32);
+
+  root_window = screen->root;
+
+  uint8_t i;
+  for(i = 0; i < NB_EWMH_ATOMS; i++)
+  {
+    if(ewmh_atoms_list[i].value == &_NET_WM_CM_Sn)
+      ewmh_atoms_list[i].cookie = xcb_intern_atom(c, 0,
+						  wm_cm_sn_len,
+						  wm_cm_sn);
+    else
+      ewmh_atoms_list[i].cookie = xcb_intern_atom(c, 0,
+						  ewmh_atoms_list[i].name_len,
+						  ewmh_atoms_list[i].name);
+  }
+}
+
+uint8_t
+xcb_ewmh_init_atoms_list_replies(xcb_connection_t *c,
+				 xcb_generic_error_t **e)
+{
+  uint8_t i;
+  xcb_intern_atom_reply_t *reply;
+  for(i = 0; i < NB_EWMH_ATOMS; i++)
+  {
+    if((reply = xcb_intern_atom_reply(c, ewmh_atoms_list[i].cookie, e)) == NULL)
+      return 0;
+
+    *(ewmh_atoms_list[i].value) = reply->atom;
+    free(reply);
+  }
+
+  return 1;
+}
+
+/**
+ * _NET_SUPPORTED
+ */
+
+DO_GET_PROPERTY(_NET_SUPPORTED, supported, ATOM, UINT_MAX)
+DO_SET_LIST_VALUES_PROPERTY(_NET_SUPPORTED, supported, xcb_atom_t, ATOM, 0)
+
+uint8_t
+xcb_ewmh_get_supported_from_reply(xcb_ewmh_get_atoms_reply_t *supported,
+				  xcb_get_property_reply_t *r)
+{
+  return xcb_ewmh_get_atoms_from_reply(supported, r);
+}
+
+uint8_t
+xcb_ewmh_get_supported_reply(xcb_connection_t *c,
+			     xcb_get_property_cookie_t cookie,
+			     xcb_ewmh_get_atoms_reply_t *supported,
+			     xcb_generic_error_t **e)
+{
+  return xcb_ewmh_get_atoms_reply(c, cookie, supported, e);
+}
+
+/**
+ * _NET_CLIENT_LIST
+ * _NET_CLIENT_LIST_STACKING
+ */
+
+DO_GET_PROPERTY(_NET_CLIENT_LIST, client_list, WINDOW, UINT_MAX)
+DO_SET_LIST_VALUES_PROPERTY(_NET_CLIENT_LIST, client_list, xcb_window_t, WINDOW, 0)
+
+uint8_t
+xcb_ewmh_get_client_list_from_reply(xcb_ewmh_get_windows_reply_t *clients,
+				    xcb_get_property_reply_t *r)
+{
+  return xcb_ewmh_get_windows_from_reply(clients, r);
+}
+
+uint8_t
+xcb_ewmh_get_client_list_reply(xcb_connection_t *c,
+			       xcb_get_property_cookie_t cookie,
+			       xcb_ewmh_get_windows_reply_t *clients,
+			       xcb_generic_error_t **e)
+{
+  return xcb_ewmh_get_windows_reply(c, cookie, clients, e);
+}
+
+/**
+ * _NET_NUMBER_OF_DESKTOPS
+ */
+
+DO_ACCESSORS_SINGLE_VALUE_ATOM(_NET_NUMBER_OF_DESKTOPS, number_of_desktops,
+			       CARDINAL, uint32_t, cardinal)
+
+void
+xcb_ewmh_request_change_number_of_desktops(xcb_connection_t *c,
+					   uint32_t new_number_of_desktops)
+{
+  send_client_message(c, XCB_NONE, root_window, _NET_NUMBER_OF_DESKTOPS, 1,
+		      &new_number_of_desktops);
+}
+
+/**
+ * _NET_DESKTOP_GEOMETRY
+ */
+
+DO_GET_PROPERTY(_NET_DESKTOP_GEOMETRY, desktop_geometry, CARDINAL, 2L)
+
+void
+xcb_ewmh_set_desktop_geometry(xcb_connection_t *c,
+			      uint32_t new_width, uint32_t new_height)
+{
+  const uint32_t data[] = { new_width, new_height };
+  xcb_change_property(c, XCB_PROP_MODE_REPLACE, root_window,
+		      _NET_DESKTOP_GEOMETRY, CARDINAL, 32, 2, data);
+}
+
+void
+xcb_ewmh_set_desktop_geometry_checked(xcb_connection_t *c,
+				      uint32_t new_width, uint32_t new_height)
+{
+  const uint32_t data[] = { new_width, new_height };
+  xcb_change_property_checked(c, XCB_PROP_MODE_REPLACE, root_window,
+			      _NET_DESKTOP_GEOMETRY, CARDINAL, 32, 2, data);
+}
+
+void
+xcb_ewmh_request_change_desktop_geometry(xcb_connection_t *c,
+					 uint32_t new_width, uint32_t new_height)
+{
+  const uint32_t data[] = { new_width, new_height };
+  send_client_message(c, XCB_NONE, root_window, _NET_DESKTOP_GEOMETRY, 2, data);
+}
+
+uint8_t
+xcb_ewmh_get_desktop_geometry_from_reply(uint32_t *width, uint32_t *height,
+					 xcb_get_property_reply_t *r)
+{
+  if(!r || r->type != CARDINAL || r->format != 32 ||
+     xcb_get_property_value_length(r) != 8)
+    return 0;
+
+  uint32_t *value = (uint32_t *) xcb_get_property_value(r);
+
+  *width = value[0];
+  *height = value[1];
+
+  return 1;
+}
+
+uint8_t
+xcb_ewmh_get_desktop_geometry_reply(xcb_connection_t *c,
+				    xcb_get_property_cookie_t cookie,
+				    uint32_t *width, uint32_t *height,
+				    xcb_generic_error_t **e)
+{
+  xcb_get_property_reply_t *r = xcb_get_property_reply(c, cookie, e);
+  const uint8_t ret = xcb_ewmh_get_desktop_geometry_from_reply(width, height, r);
+  free(r);
+  return ret;
+}
+
+/**
+ * _NET_DESKTOP_VIEWPORT
+ */
+
+DO_GET_PROPERTY(_NET_DESKTOP_VIEWPORT, desktop_viewport, CARDINAL, UINT_MAX)
+DO_SET_LIST_VALUES_PROPERTY(_NET_DESKTOP_VIEWPORT, desktop_viewport,
+			    xcb_ewmh_coordinates_t, CARDINAL, 1)
+
+void
+xcb_ewmh_request_change_desktop_viewport(xcb_connection_t *c,
+					 uint32_t x, uint32_t y)
+{
+  const uint32_t data[] = { x, y };
+  send_client_message(c, XCB_NONE, root_window, _NET_DESKTOP_VIEWPORT, 2, data);
+}
+
+DO_REPLY_LIST_VALUES_ATOM(extern, desktop_viewport, xcb_ewmh_coordinates_t, CARDINAL, 1)
+
+/**
+ * _NET_CURRENT_DESKTOP
+ */
+
+DO_ACCESSORS_SINGLE_VALUE_ATOM(_NET_CURRENT_DESKTOP, current_desktop, CARDINAL, uint32_t, cardinal)
+
+void
+xcb_ewmh_request_change_current_desktop(xcb_connection_t *c,
+					uint32_t new_desktop,
+					xcb_timestamp_t timestamp)
+{
+  const uint32_t data[] = { new_desktop, timestamp };
+  send_client_message(c, XCB_NONE, root_window, _NET_CURRENT_DESKTOP, 2, data);
+}
+
+/**
+ * _NET_DESKTOP_NAMES
+ * TODO: (char **) instead of (char *) (more convenient?)
+ */
+DO_ACCESSORS_UTF8_STRING(_NET_DESKTOP_NAMES, desktop_names)
+
+/**
+ * _NET_ACTIVE_WINDOW
+ */
+
+DO_ACCESSORS_SINGLE_VALUE_ATOM(_NET_ACTIVE_WINDOW, active_window, WINDOW, xcb_window_t, window)
+
+void
+xcb_ewmh_request_change_active_window(xcb_connection_t *c,
+				      xcb_window_t window_to_activate,
+				      xcb_ewmh_client_source_type_t source_indication,
+				      xcb_timestamp_t timestamp,
+				      xcb_window_t current_active_window)
+{
+  const uint32_t data[] = { source_indication, timestamp, current_active_window };
+  send_client_message(c, window_to_activate, root_window, _NET_ACTIVE_WINDOW, 3,
+		      data);
+}
+ 
+/**
+ * _NET_WORKAREA
+ */
+ 
+DO_GET_PROPERTY(_NET_WORKAREA, workarea, CARDINAL, UINT_MAX)
+DO_SET_LIST_VALUES_PROPERTY(_NET_WORKAREA, workarea, xcb_ewmh_geometry_t, CARDINAL, 2)
+DO_REPLY_LIST_VALUES_ATOM(extern, workarea, xcb_ewmh_geometry_t, CARDINAL, 2)
+
+/**
+ * _NET_SUPPORTING_WM_CHECK
+ */
+
+DO_ACCESSORS_SINGLE_VALUE_ATOM(_NET_SUPPORTING_WM_CHECK, supporting_wm_check, WINDOW,
+			       xcb_window_t, window)
+
+/**
+ * _NET_VIRTUAL_ROOTS
+ */
+
+DO_GET_PROPERTY(_NET_VIRTUAL_ROOTS, virtual_roots, WINDOW, UINT_MAX)
+DO_SET_LIST_VALUES_PROPERTY(_NET_VIRTUAL_ROOTS, virtual_roots, xcb_window_t, WINDOW, 0)
+
+uint8_t
+xcb_ewmh_get_virtual_roots_from_reply(xcb_ewmh_get_windows_reply_t *virtual_roots,
+				      xcb_get_property_reply_t *r)
+{
+  return xcb_ewmh_get_windows_from_reply(virtual_roots, r);
+}
+
+uint8_t
+xcb_ewmh_get_virtual_roots_reply(xcb_connection_t *c,
+				 xcb_get_property_cookie_t cookie,
+				 xcb_ewmh_get_windows_reply_t *virtual_roots,
+				 xcb_generic_error_t **e)
+{
+  return xcb_ewmh_get_windows_reply(c, cookie, virtual_roots, e);
+}
+
+/**
+ * _NET_DESKTOP_LAYOUT
+ */
+
+DO_GET_PROPERTY(_NET_DESKTOP_LAYOUT, desktop_layout, CARDINAL, 4)
+
+void
+xcb_ewmh_set_desktop_layout(xcb_connection_t *c,
+			    xcb_ewmh_desktop_layout_orientation_t orientation,
+			    uint32_t columns, uint32_t rows,
+			    xcb_ewmh_desktop_layout_starting_corner_t starting_corner)
+{
+  const uint32_t data[] = { orientation, columns, rows, starting_corner };
+  xcb_change_property(c, XCB_PROP_MODE_REPLACE, root_window,
+		      _NET_DESKTOP_LAYOUT, CARDINAL, 32, 2, data);
+}
+
+void
+xcb_ewmh_set_desktop_layout_checked(xcb_connection_t *c,
+				    xcb_ewmh_desktop_layout_orientation_t orientation,
+				    uint32_t columns, uint32_t rows,
+				    xcb_ewmh_desktop_layout_starting_corner_t starting_corner)
+{
+  const uint32_t data[] = { orientation, columns, rows, starting_corner };
+  xcb_change_property_checked(c, XCB_PROP_MODE_REPLACE, root_window,
+			      _NET_DESKTOP_LAYOUT, CARDINAL, 32, 2, data);
+}
+
+uint8_t
+xcb_ewmh_get_desktop_layout_from_reply(xcb_ewmh_get_desktop_layout_reply_t *desktop_layout,
+				       xcb_get_property_reply_t *r)
+{
+  if(!r || r->type != CARDINAL || r->format != 32 ||
+     (xcb_get_property_value_length(r) >> 2) != 4)
+    return 0;
+
+  memcpy(desktop_layout, xcb_get_property_value(r),
+	 xcb_get_property_value_length(r));
+
+  return 1;
+}
+
+uint8_t
+xcb_ewmh_get_desktop_layout_reply(xcb_connection_t *c,
+				  xcb_get_property_cookie_t cookie,
+				  xcb_ewmh_get_desktop_layout_reply_t *desktop_layout,
+				  xcb_generic_error_t **e)
+{
+  xcb_get_property_reply_t *r = xcb_get_property_reply(c, cookie, e);
+  const uint8_t ret = xcb_ewmh_get_desktop_layout_from_reply(desktop_layout, r);
+  free(r);
+  return ret;
+}
+
+/**
+ * _NET_SHOWING_DESKTOP
+ */
+
+DO_ACCESSORS_SINGLE_VALUE_ATOM(_NET_SHOWING_DESKTOP, showing_desktop, CARDINAL,
+			       uint32_t, cardinal)
+
+void
+xcb_ewmh_request_change_showing_desktop(xcb_connection_t *c,
+					uint32_t enter)
+{
+  send_client_message(c, XCB_NONE, root_window, _NET_SHOWING_DESKTOP, 1,
+		      &enter);
+}
+
+/**
+ * _NET_CLOSE_WINDOW
+ */
+
+void
+xcb_ewmh_request_close_window(xcb_connection_t *c,
+			      xcb_window_t window_to_close,
+			      xcb_timestamp_t timestamp,
+			      xcb_ewmh_client_source_type_t source_indication)
+{
+  const uint32_t data[] = { timestamp, source_indication };
+  send_client_message(c, window_to_close, root_window, _NET_CLOSE_WINDOW, 2,
+		      data);
+}
+
+/**
+ * _NET_MOVERESIZE_WINDOW
+ */
+
+/* x, y, width, height may be equal to -1 */
+void
+xcb_ewmh_request_moveresize_window(xcb_connection_t *c,
+				   xcb_window_t moveresize_window,
+				   xcb_gravity_t gravity,
+				   xcb_ewmh_client_source_type_t source_indication,
+				   xcb_ewmh_moveresize_window_opt_flags_t flags,
+				   uint32_t x, uint32_t y,
+				   uint32_t width, uint32_t height)
+{
+  const uint32_t data[] = { (gravity | flags | (source_indication << 12)),
+			    x, y, width, height };
+
+  send_client_message(c, moveresize_window, root_window, _NET_MOVERESIZE_WINDOW,
+		      5, data);
+}
+
+/**
+ * _NET_WM_MOVERESIZE
+ */	   
+
+void
+xcb_ewmh_request_wm_moveresize(xcb_connection_t *c,
+			       xcb_window_t moveresize_window,
+			       uint32_t x_root, uint32_t y_root,
+			       xcb_ewmh_moveresize_direction_t direction,
+			       xcb_button_index_t button,
+			       xcb_ewmh_client_source_type_t source_indication)
+{
+  const uint32_t data[] = { x_root, y_root, direction, button, source_indication };
+
+  send_client_message(c, moveresize_window, root_window, _NET_WM_MOVERESIZE, 5,
+		      data);
+}
+
+/**
+ * _NET_RESTACK_WINDOW
+ */
+
+void
+xcb_ewmh_request_restack_window(xcb_connection_t *c,
+				xcb_window_t window_to_restack,
+				xcb_window_t sibling_window,
+				xcb_stack_mode_t detail)
+{
+  const uint32_t data[] = { XCB_EWMH_CLIENT_SOURCE_TYPE_OTHER, sibling_window,
+			    detail };
+
+  send_client_message(c, window_to_restack, root_window, _NET_RESTACK_WINDOW, 3,
+		      data);
+}				
+				
+void
+xcb_ewmh_request_frame_extents(xcb_connection_t *c,
+			       xcb_window_t client_window)
+{
+  send_client_message(c, client_window, root_window, _NET_REQUEST_FRAME_EXTENTS,
+		      0, NULL);
+}
+
+/**
+ * _NET_WM_NAME
+ */
+
+DO_ACCESSORS_UTF8_STRING(_NET_WM_NAME, wm_name)
+
+/**
+ * _NET_WM_VISIBLE_NAME
+ */
+
+DO_ACCESSORS_UTF8_STRING(_NET_WM_VISIBLE_NAME, wm_visible_name)
+
+/**
+ * _NET_WM_ICON_NAME
+ */
+
+DO_ACCESSORS_UTF8_STRING(_NET_WM_ICON_NAME, wm_icon_name)
+
+/**
+ * _NET_WM_VISIBLE_ICON_NAME
+ */
+
+DO_ACCESSORS_UTF8_STRING(_NET_WM_VISIBLE_ICON_NAME, wm_visible_icon_name)
+
+/**
+ * _NET_WM_DESKTOP
+ */
+
+DO_ACCESSORS_SINGLE_VALUE_ATOM(_NET_WM_DESKTOP, wm_desktop, CARDINAL, uint32_t, cardinal)
+
+void
+xcb_ewmh_request_change_wm_desktop(xcb_connection_t *c,
+				   xcb_window_t client_window,
+				   uint32_t new_desktop,
+				   xcb_ewmh_client_source_type_t source_indication)
+{
+  const uint32_t data[] = { new_desktop, source_indication };
+
+  send_client_message(c, client_window, root_window, _NET_WM_DESKTOP, 2, data);
+}
+
+/**
+ * _NET_WM_WINDOW_TYPE
+ *
+ * TODO: check possible atoms?
+ */
+
+DO_GET_PROPERTY(_NET_WM_WINDOW_TYPE, wm_window_type, ATOM, UINT_MAX)
+DO_SET_LIST_VALUES_PROPERTY(_NET_WM_WINDOW_TYPE, wm_window_type, xcb_atom_t, ATOM, 0)
+
+uint8_t
+xcb_ewmh_get_wm_window_type_from_reply(xcb_ewmh_get_atoms_reply_t *window_types,
+				       xcb_get_property_reply_t *r)
+{
+  return xcb_ewmh_get_atoms_from_reply(window_types, r);
+}
+
+uint8_t
+xcb_ewmh_get_wm_window_type_reply(xcb_connection_t *c,
+				  xcb_get_property_cookie_t cookie,
+				  xcb_ewmh_get_atoms_reply_t *window_types,
+				  xcb_generic_error_t **e)
+{
+  return xcb_ewmh_get_atoms_reply(c, cookie, window_types, e);
+}
+
+/**
+ * _NET_WM_STATE
+ *
+ * TODO: check possible atoms?
+ */
+
+DO_GET_PROPERTY(_NET_WM_STATE, wm_state, ATOM, UINT_MAX)
+DO_SET_LIST_VALUES_PROPERTY(_NET_WM_STATE, wm_state, xcb_atom_t, ATOM, 0)
+
+void
+xcb_ewmh_request_change_wm_state(xcb_connection_t *c,
+				 xcb_window_t client_window,
+				 xcb_ewmh_wm_state_action_t action,
+				 xcb_atom_t first_property,
+				 xcb_atom_t second_property,
+				 xcb_ewmh_client_source_type_t source_indication)
+{
+  const uint32_t data[] = { action, first_property, second_property, source_indication };
+
+  send_client_message(c, client_window, root_window, _NET_WM_STATE, 4, data);
+}
+
+uint8_t
+xcb_ewmh_get_wm_state_from_reply(xcb_ewmh_get_atoms_reply_t *wm_states,
+				 xcb_get_property_reply_t *r)
+{
+  return xcb_ewmh_get_atoms_from_reply(wm_states, r);
+}
+
+uint8_t
+xcb_ewmh_get_wm_state_reply(xcb_connection_t *c,
+			    xcb_get_property_cookie_t cookie,
+			    xcb_ewmh_get_atoms_reply_t *wm_states,
+			    xcb_generic_error_t **e)
+{
+  return xcb_ewmh_get_atoms_reply(c, cookie, wm_states, e);
+}
+
+/**
+ * _NET_WM_ALLOWED_ACTIONS
+ *
+ * TODO: check possible atoms?
+ */
+
+DO_GET_PROPERTY(_NET_WM_ALLOWED_ACTIONS, wm_allowed_actions, ATOM, UINT_MAX)
+DO_SET_LIST_VALUES_PROPERTY(_NET_WM_ALLOWED_ACTIONS, wm_allowed_actions, xcb_atom_t, ATOM, 0)
+
+uint8_t
+xcb_ewmh_get_wm_allowed_actions_from_reply(xcb_ewmh_get_atoms_reply_t *wm_allowed_actions,
+					   xcb_get_property_reply_t *r)
+{
+  return xcb_ewmh_get_atoms_from_reply(wm_allowed_actions, r);
+}
+
+uint8_t
+xcb_ewmh_get_wm_allowed_actions_reply(xcb_connection_t *c,
+				      xcb_get_property_cookie_t cookie,
+				      xcb_ewmh_get_atoms_reply_t *wm_allowed_actions,
+				      xcb_generic_error_t **e)
+{
+  return xcb_ewmh_get_atoms_reply(c, cookie, wm_allowed_actions, e);
+}
+
+/**
+ * _NET_WM_STRUT
+ * _NET_WM_STRUT_PARTIAL
+ */
+
+DO_GET_PROPERTY(_NET_WM_STRUT, wm_strut, CARDINAL, 12)
+
+void
+xcb_ewmh_set_wm_strut_checked(xcb_connection_t *c,
+			      xcb_window_t window,
+			      xcb_ewmh_wm_strut_t wm_strut)
+{
+  xcb_change_property_checked(c, XCB_PROP_MODE_REPLACE, window, _NET_WM_STRUT,
+			      CARDINAL, 32, 12, &wm_strut);
+}
+
+void
+xcb_ewmh_set_wm_strut(xcb_connection_t *c,
+		      xcb_window_t window,
+		      xcb_ewmh_wm_strut_t wm_strut)
+{
+  xcb_change_property(c, XCB_PROP_MODE_REPLACE, window, _NET_WM_STRUT, CARDINAL,
+		      32, 12, &wm_strut);
+}
+
+uint8_t
+xcb_ewmh_get_wm_strut_from_reply(xcb_ewmh_wm_strut_t *wm_strut,
+				 xcb_get_property_reply_t *r)
+{
+  if(!r || r->type != CARDINAL || r->format != 32 ||
+     (xcb_get_property_value_length(r) >> 2) != 12)
+    return 0;
+
+  memset(wm_strut, 0, sizeof(wm_strut));
+
+  memcpy(wm_strut, xcb_get_property_value(r),
+	 xcb_get_property_value_length(r));
+
+  return 1;
+}
+
+uint8_t
+xcb_ewmh_get_wm_strut_reply(xcb_connection_t *c,
+			    xcb_get_property_cookie_t cookie,
+			    xcb_ewmh_wm_strut_t *wm_strut,
+			    xcb_generic_error_t **e)
+{
+  xcb_get_property_reply_t *r = xcb_get_property_reply(c, cookie, e);
+  const uint8_t ret = xcb_ewmh_get_wm_strut_from_reply(wm_strut, r);
+  free(r);
+  return ret;
+}
+
+/**
+ * _NET_WM_ICON_GEOMETRY
+ */
+
+DO_GET_PROPERTY(_NET_WM_ICON_GEOMETRY, wm_icon_geometry, CARDINAL, 4)
+
+void
+xcb_ewmh_set_wm_icon_geometry_checked(xcb_connection_t *c,
+				      xcb_window_t window,
+				      uint32_t left, uint32_t right,
+				      uint32_t top, uint32_t bottom)
+{
+  const uint32_t data[] = { left, right, top, bottom };
+
+  xcb_change_property_checked(c, XCB_PROP_MODE_REPLACE, window,
+			      _NET_WM_ICON_GEOMETRY, CARDINAL, 32, 4, data);
+}
+
+void
+xcb_ewmh_set_wm_icon_geometry(xcb_connection_t *c,
+			      xcb_window_t window,
+			      uint32_t left, uint32_t right,
+			      uint32_t top, uint32_t bottom)
+{
+  const uint32_t data[] = { left, right, top, bottom };
+
+  xcb_change_property(c, XCB_PROP_MODE_REPLACE, window, _NET_WM_ICON_GEOMETRY,
+		      CARDINAL, 32, 4, data);
+}
+
+uint8_t
+xcb_ewmh_get_wm_icon_geometry_from_reply(xcb_ewmh_geometry_t *wm_icon_geometry,
+					 xcb_get_property_reply_t *r)
+{
+  if(!r || r->type != CARDINAL || r->format != 32 ||
+     (xcb_get_property_value_length(r) >> 2) != 4)
+    return 0;
+
+  memcpy(wm_icon_geometry, xcb_get_property_value(r),
+	 xcb_get_property_value_length(r));
+
+  return 1;
+}
+
+uint8_t
+xcb_ewmh_get_wm_icon_geometry_reply(xcb_connection_t *c,
+				    xcb_get_property_cookie_t cookie,
+				    xcb_ewmh_geometry_t *wm_icon_geometry,
+				    xcb_generic_error_t **e)
+{
+  xcb_get_property_reply_t *r = xcb_get_property_reply(c, cookie, e);
+  const uint8_t ret = xcb_ewmh_get_wm_icon_geometry_from_reply(wm_icon_geometry, r);
+  free(r);
+  return ret;
+}
+
+/**
+ * _NET_WM_ICON
+ */
+
+DO_GET_PROPERTY(_NET_WM_ICON, wm_icon, CARDINAL, UINT_MAX)
+
+static inline void
+set_wm_icon_data(uint32_t data[], uint32_t width, uint32_t height,
+		 uint32_t img_len, uint32_t *img)
+{
+  data[0] = width;
+  data[1] = height;
+
+  memcpy(data + 2, img, img_len);
+}
+
+void
+xcb_ewmh_set_wm_icon_checked(xcb_connection_t *c,
+			     xcb_window_t window,
+			     uint32_t width, uint32_t height,
+			     uint32_t img_len, uint32_t *img)
+{
+  const uint32_t data_len = img_len + 2;
+  uint32_t data[data_len];
+
+  set_wm_icon_data(data, width, height, img_len, img);
+
+  xcb_change_property_checked(c, XCB_PROP_MODE_REPLACE, window, _NET_WM_ICON,
+			      CARDINAL, 32, data_len, data);
+}
+
+void
+xcb_ewmh_set_wm_icon(xcb_connection_t *c,
+		     xcb_window_t window,
+		     uint32_t width, uint32_t height,
+		     uint32_t img_len, uint32_t *img)
+{
+  const uint32_t data_len = img_len + 2;
+  uint32_t data[data_len];
+
+  set_wm_icon_data(data, width, height, img_len, img);
+
+  xcb_change_property(c, XCB_PROP_MODE_REPLACE, window, _NET_WM_ICON, CARDINAL,
+		      32, data_len, data);
+}
+
+uint8_t
+xcb_ewmh_get_wm_icon_from_reply(xcb_ewmh_get_wm_icon_reply_t *wm_icon,
+				xcb_get_property_reply_t *r)
+{
+  if(!r || r->type != CARDINAL || r->format != 32 ||
+     (xcb_get_property_value_length(r) >> 2) <= 2)
+    return 0;
+
+  wm_icon->_reply = r;
+  uint32_t *r_value = (uint32_t *) xcb_get_property_value(wm_icon->_reply);
+
+  wm_icon->width = r_value[0];
+  wm_icon->height = r_value[1];
+  wm_icon->data = r_value + 2;
+
+  return 1;
+}
+
+uint8_t
+xcb_ewmh_get_wm_icon_reply(xcb_connection_t *c,
+			   xcb_get_property_cookie_t cookie,
+			   xcb_ewmh_get_wm_icon_reply_t *wm_icon,
+			   xcb_generic_error_t **e)
+{
+  xcb_get_property_reply_t *r = xcb_get_property_reply(c, cookie, e);
+  const uint8_t ret = xcb_ewmh_get_wm_icon_from_reply(wm_icon, r);
+  if(!ret)
+    free(r);
+
+  return ret;
+}
+
+void
+xcb_ewmh_get_wm_icon_reply_wipe(xcb_ewmh_get_wm_icon_reply_t *wm_icon)
+{
+  free(wm_icon->_reply);
+}
+
+/**
+ * _NET_WM_PID
+ */
+
+DO_ACCESSORS_SINGLE_VALUE_ATOM(_NET_WM_PID, wm_pid, CARDINAL, uint32_t,
+			       cardinal)
+
+/**
+ * _NET_WM_USER_TIME
+ */
+
+DO_ACCESSORS_SINGLE_VALUE_ATOM(_NET_WM_USER_TIME, wm_user_time, CARDINAL,
+			       uint32_t, cardinal)
+
+/**
+ * _NET_WM_USER_TIME_WINDOW
+ */
+
+DO_ACCESSORS_SINGLE_VALUE_ATOM(_NET_WM_USER_TIME_WINDOW, wm_user_time_window,
+			       CARDINAL, uint32_t, cardinal)
+
+/**
+ * _NET_FRAME_EXTENTS
+ */
+
+DO_GET_PROPERTY(_NET_FRAME_EXTENTS, frame_extents, CARDINAL, 4)
+
+void
+xcb_ewmh_set_frame_extents(xcb_connection_t *c,
+			   xcb_window_t window,
+			   uint32_t left, uint32_t right,
+			   uint32_t top, uint32_t bottom)
+{
+  const uint32_t data[] = { left, right, top, bottom };
+
+  xcb_change_property(c, XCB_PROP_MODE_REPLACE, window, _NET_FRAME_EXTENTS,
+		      CARDINAL, 32, 4, data);
+}
+
+void
+xcb_ewmh_set_frame_extents_checked(xcb_connection_t *c,
+				   xcb_window_t window,
+				   uint32_t left, uint32_t right,
+				   uint32_t top, uint32_t bottom)
+{
+  const uint32_t data[] = { left, right, top, bottom };
+
+  xcb_change_property_checked(c, XCB_PROP_MODE_REPLACE, window,
+			      _NET_FRAME_EXTENTS, CARDINAL, 32, 4, data);
+}
+
+uint8_t
+xcb_ewmh_get_frame_extents_from_reply(xcb_ewmh_get_frame_extents_reply_t *frame_extents,
+				      xcb_get_property_reply_t *r)
+{
+  if(!r || r->type != CARDINAL || r->format != 32 ||
+     (xcb_get_property_value_length(r) >> 2) != 4)
+    return 0;
+
+  memcpy(frame_extents, xcb_get_property_value(r),
+	 xcb_get_property_value_length(r));
+
+  return 1;
+}
+
+uint8_t
+xcb_ewmh_get_frame_extents_reply(xcb_connection_t *c,
+				 xcb_get_property_cookie_t cookie,
+				 xcb_ewmh_get_frame_extents_reply_t *frame_extents,
+				 xcb_generic_error_t **e)
+{
+  xcb_get_property_reply_t *r = xcb_get_property_reply(c, cookie, e);
+  const uint8_t ret = xcb_ewmh_get_frame_extents_from_reply(frame_extents, r);
+  free(r);
+  return ret;
+}
+
+/**
+ * _NET_WM_PING
+ *
+ * TODO: client resend function?
+ */
+
+void
+xcb_ewmh_send_wm_ping(xcb_connection_t *c,
+		      xcb_window_t window,
+		      xcb_timestamp_t timestamp)
+{
+  const uint32_t data[] = { _NET_WM_PING, timestamp, window };
+
+  send_client_message(c, window, window, WM_PROTOCOLS, 3, data);
+}
+
+/**
+ * _NET_WM_SYNC_REQUES
+ * _NET_WM_SYNC_REQUEST_COUNTER
+ */
+
+DO_GET_PROPERTY(_NET_WM_SYNC_REQUEST, wm_sync_request_counter, CARDINAL, 2)
+
+void
+xcb_ewmh_set_wm_sync_request_counter(xcb_connection_t *c,
+				     xcb_window_t window,
+				     xcb_atom_t wm_sync_request_counter_atom,
+				     uint32_t low, uint32_t high)
+{
+  const uint32_t data[] = { low, high };
+
+  xcb_change_property(c, XCB_PROP_MODE_REPLACE, window, _NET_WM_SYNC_REQUEST,
+		      CARDINAL, 32, 2, data);
+}
+
+void
+xcb_ewmh_set_wm_sync_request_counter_checked(xcb_connection_t *c,
+					     xcb_window_t window,
+					     xcb_atom_t wm_sync_request_counter_atom,
+					     uint32_t low, uint32_t high)
+{
+  const uint32_t data[] = { low, high };
+
+  xcb_change_property_checked(c, XCB_PROP_MODE_REPLACE, window,
+			      _NET_WM_SYNC_REQUEST, CARDINAL, 32, 2, data);
+}
+
+void
+xcb_ewmh_send_wm_sync_request(xcb_connection_t *c,
+			      xcb_window_t window,
+			      xcb_atom_t wm_protocols_atom,
+			      xcb_atom_t wm_sync_request_atom,
+			      xcb_timestamp_t timestamp,
+			      uint64_t counter)
+{
+  const uint32_t data[] = { _NET_WM_SYNC_REQUEST, timestamp, counter,
+			    counter >> 32 };
+
+  send_client_message(c, window, window, WM_PROTOCOLS, 4, data);
+}
+
+uint8_t
+xcb_ewmh_get_wm_sync_request_counter_from_reply(uint64_t *counter,
+						xcb_get_property_reply_t *r)
+{
+  /* 2 cardinals? */
+  if(!r || r->type != CARDINAL || r->format != 32 ||
+     (xcb_get_property_value_length(r) >> 2) != 2)
+    return 0;
+
+  uint32_t *r_value = (uint32_t *) xcb_get_property_value(r);
+  *counter = (r_value[0] | (r_value[1] << 8));
+
+  return 1;
+}
+
+uint8_t
+xcb_ewmh_get_wm_sync_request_counter_reply(xcb_connection_t *c,
+					   xcb_get_property_cookie_t cookie,
+					   uint64_t *counter,
+					   xcb_generic_error_t **e)
+{
+  xcb_get_property_reply_t *r = xcb_get_property_reply(c, cookie, e);
+  const uint8_t ret = xcb_ewmh_get_wm_sync_request_counter_from_reply(counter, r);
+  free(r);
+  return ret;
+}
+
+/**
+ * _NET_WM_FULLSCREEN_MONITORS
+ */
+
+DO_GET_PROPERTY(_NET_WM_FULLSCREEN_MONITORS, wm_fullscreen_monitors, CARDINAL, 4)
+
+void
+xcb_ewmh_set_wm_fullscreen_monitors(xcb_connection_t *c,
+				    xcb_window_t window,
+				    uint32_t top, uint32_t bottom,
+				    uint32_t left, uint32_t right)
+{
+  const uint32_t data[] = { top, bottom, left, right };
+
+  xcb_change_property(c, XCB_PROP_MODE_REPLACE, window,
+		      _NET_WM_FULLSCREEN_MONITORS, CARDINAL, 32, 4, data);
+}
+
+void
+xcb_ewmh_set_wm_fullscreen_monitors_checked(xcb_connection_t *c,
+					    xcb_window_t window,
+					    uint32_t top, uint32_t bottom,
+					    uint32_t left, uint32_t right)
+{
+  const uint32_t data[] = { top, bottom, left, right };
+
+  xcb_change_property_checked(c, XCB_PROP_MODE_REPLACE, window,
+			      _NET_WM_FULLSCREEN_MONITORS, CARDINAL, 32, 4,
+			      data);
+}
+
+void
+xcb_ewmh_request_change_wm_fullscreen_monitors(xcb_connection_t *c,
+					       xcb_window_t window,
+					       uint32_t top, uint32_t bottom,
+					       uint32_t left, uint32_t right,
+					       xcb_ewmh_client_source_type_t source_indication)
+{
+  const uint32_t data[] = { top, bottom, left, right, source_indication };
+
+  send_client_message(c, window, root_window, _NET_WM_FULLSCREEN_MONITORS, 5,
+		      data);
+}
+
+uint8_t
+xcb_ewmh_get_wm_fullscreen_monitors_from_reply(xcb_ewmh_get_wm_fullscreen_monitors_reply_t *wm_fullscreen_monitors,
+					       xcb_get_property_reply_t *r)
+{
+  if(!r || r->type != CARDINAL || r->format != 32 ||
+     (xcb_get_property_value_length(r) >> 2) != 4)
+    return 0;
+
+  memcpy(wm_fullscreen_monitors, xcb_get_property_value(r),
+	 xcb_get_property_value_length(r));
+
+  return 1;
+}
+
+uint8_t
+xcb_ewmh_get_wm_fullscreen_monitors_reply(xcb_connection_t *c,
+					  xcb_get_property_cookie_t cookie,
+					  xcb_ewmh_get_wm_fullscreen_monitors_reply_t *wm_fullscreen_monitors,
+					  xcb_generic_error_t **e)
+{
+  xcb_get_property_reply_t *r = xcb_get_property_reply(c, cookie, e);
+  const uint8_t ret = xcb_ewmh_get_wm_fullscreen_monitors_from_reply(wm_fullscreen_monitors, r);
+  free(r);
+  return ret;
+}
+
+/**
+ * _NET_WM_FULL_PLACEMENT
+ */
+
+/**
+ * _NET_WM_CM_Sn
+ */
+
+xcb_get_selection_owner_cookie_t
+xcb_ewmh_get_wm_cm_owner(xcb_connection_t *c)
+{
+  return xcb_get_selection_owner(c, _NET_WM_CM_Sn);
+}
+
+xcb_get_selection_owner_cookie_t
+xcb_ewmh_get_wm_cm_owner_unchecked(xcb_connection_t *c)
+{
+  return xcb_get_selection_owner_unchecked(c, _NET_WM_CM_Sn);
+}
+
+uint8_t
+xcb_ewmh_get_wm_cm_owner_reply(xcb_connection_t *c,
+			       xcb_get_selection_owner_cookie_t cookie,
+			       xcb_window_t *owner,
+			       xcb_generic_error_t **e)
+{
+  xcb_get_selection_owner_reply_t *r = xcb_get_selection_owner_reply(c, cookie, e);
+
+  if(!r || r->length != 4)
+  {
+    free(r);
+    return 0;
+  }
+
+  *owner = r->owner;
+  free(r);
+
+  return 1;
+}
+
+/* TODO: section 2.1, 2.2 */
+static void
+set_wm_cm_owner_client_message(xcb_connection_t *c,
+			       xcb_window_t owner,
+			       xcb_timestamp_t timestamp,
+			       uint32_t selection_data1,
+			       uint32_t selection_data2)
+{
+  xcb_client_message_event_t ev;
+  memset(&ev, 0, sizeof(xcb_client_message_event_t));
+
+  ev.response_type = XCB_CLIENT_MESSAGE;
+  ev.format = 32;
+  ev.type = MANAGER;
+  ev.data.data32[0] = timestamp;
+  ev.data.data32[1] = _NET_WM_CM_Sn;
+  ev.data.data32[2] = owner;
+  ev.data.data32[3] = selection_data1;
+  ev.data.data32[4] = selection_data2;
+
+  xcb_send_event(c, 0, root_window, XCB_EVENT_MASK_STRUCTURE_NOTIFY,
+		 (char *) &ev);
+}
+
+void
+xcb_ewmh_set_wm_cm_owner(xcb_connection_t *c,
+			 xcb_window_t owner,
+			 xcb_timestamp_t timestamp,
+			 uint32_t selection_data1,
+			 uint32_t selection_data2)
+{
+  xcb_set_selection_owner(c, owner, _NET_WM_CM_Sn, 0);
+  set_wm_cm_owner_client_message(c, owner, timestamp,
+				 selection_data1, selection_data2);
+}
+
+void
+xcb_ewmh_set_wm_cm_owner_checked(xcb_connection_t *c,
+				 xcb_window_t owner,
+				 xcb_timestamp_t timestamp,
+				 uint32_t selection_data1,
+				 uint32_t selection_data2)
+{
+  xcb_set_selection_owner_checked(c, owner, _NET_WM_CM_Sn, 0);
+  set_wm_cm_owner_client_message(c, owner, timestamp,
+				 selection_data1, selection_data2);
+}
diff --git a/ewmh/xcb-ewmh.pc.in b/ewmh/xcb-ewmh.pc.in
new file mode 100644
index 0000000..7f44214
--- /dev/null
+++ b/ewmh/xcb-ewmh.pc.in
@@ -0,0 +1,11 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+
+Name: XCB EWMH library
+Description: XCB EWMH binding
+Version: @PACKAGE_VERSION@
+Requires: xcb xcb-atom xcb-property
+Libs: -L${libdir} -lxcb-ewmh @LIBS@
+Cflags: -I${includedir}
diff --git a/ewmh/xcb_ewmh.h.m4 b/ewmh/xcb_ewmh.h.m4
new file mode 100644
index 0000000..b30cb63
--- /dev/null
+++ b/ewmh/xcb_ewmh.h.m4
@@ -0,0 +1,221 @@
+#ifndef __XCB_EWMH_H__
+#define __XCB_EWMH_H__
+
+/*
+ * Copyright (C) 2009 Arnaud Fontaine <arnau at debian.org>
+ *
+ * Permission  is  hereby  granted,  free  of charge,  to  any  person
+ * obtaining  a copy  of  this software  and associated  documentation
+ * files   (the  "Software"),   to  deal   in  the   Software  without
+ * restriction, including without limitation  the rights to use, copy,
+ * modify, merge, publish,  distribute, sublicense, and/or sell copies
+ * of  the Software, and  to permit  persons to  whom the  Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The  above copyright  notice and  this permission  notice  shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE  IS PROVIDED  "AS IS", WITHOUT  WARRANTY OF  ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT  NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY,   FITNESS    FOR   A   PARTICULAR    PURPOSE   AND
+ * NONINFRINGEMENT. IN  NO EVENT SHALL  THE AUTHORS BE LIABLE  FOR ANY
+ * CLAIM,  DAMAGES  OR  OTHER  LIABILITY,  WHETHER  IN  AN  ACTION  OF
+ * CONTRACT, TORT OR OTHERWISE, ARISING  FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Except as  contained in  this notice, the  names of the  authors or
+ * their institutions shall not be used in advertising or otherwise to
+ * promote the  sale, use or  other dealings in this  Software without
+ * prior written authorization from the authors.
+ */
+
+/**
+ * @defgroup xcb__icccm_t XCB EWMH Functions
+ *
+ * These functions  allow easy handling  of the protocol  described in
+ * the Extended Window Manager Hints specification.
+ *
+ * @{
+ */
+
+#include <xcb/xcb.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+define(`DO', `ifelse(`$1', , , `extern xcb_atom_t $1;
+DO(shift($@))')')dnl
+include(atomlist.m4)dnl
+
+typedef struct {
+  uint32_t atoms_len;
+  xcb_atom_t *atoms;
+  xcb_get_property_reply_t *_reply;
+} xcb_ewmh_get_atoms_reply_t;
+
+typedef struct {
+  uint32_t windows_len;
+  xcb_atom_t *windows;
+  xcb_get_property_reply_t *_reply;
+} xcb_ewmh_get_windows_reply_t;
+
+typedef struct {
+  uint32_t string_len;
+  char *string;
+  xcb_get_property_reply_t *_reply;
+} xcb_ewmh_get_utf8_string_reply_t;
+
+typedef struct {
+  uint32_t x;
+  uint32_t y;
+} xcb_ewmh_coordinates_t;
+
+typedef struct {
+  uint32_t desktop_viewport_len;
+  xcb_ewmh_coordinates_t *desktop_viewport;
+  xcb_get_property_reply_t *_reply;
+} xcb_ewmh_get_desktop_viewport_reply_t;
+
+typedef struct {
+  uint32_t x;
+  uint32_t y;
+  uint32_t width;
+  uint32_t height;
+} xcb_ewmh_geometry_t;
+
+typedef struct {
+  uint32_t workarea_len;
+  xcb_ewmh_geometry_t *workarea;
+  xcb_get_property_reply_t *_reply;
+} xcb_ewmh_get_workarea_reply_t;
+
+/** Source indication in requests */
+typedef enum {
+  /** No source at all (for clients supporting an older version of
+      EWMH specification) */
+  XCB_EWMH_CLIENT_SOURCE_TYPE_NONE = 0,
+  /** Normal application */
+  XCB_EWMH_CLIENT_SOURCE_TYPE_NORMAL = 1,
+  /** Pagers and other clients that represent direct user actions */
+  XCB_EWMH_CLIENT_SOURCE_TYPE_OTHER = 2
+} xcb_ewmh_client_source_type_t;
+
+typedef enum {
+  XCB_EWMH_WM_ORIENTATION_HORZ = 0,
+  XCB_EWMH_WM_ORIENTATION_VERT = 1
+} xcb_ewmh_desktop_layout_orientation_t;
+
+typedef enum {
+  XCB_EWMH_WM_TOPLEFT = 0,
+  XCB_EWMH_WM_TOPRIGHT = 1,
+  XCB_EWMH_WM_BOTTOMRIGHT = 2,
+  XCB_EWMH_WM_BOTTOMLEFT = 3
+} xcb_ewmh_desktop_layout_starting_corner_t;
+
+typedef struct {
+  uint32_t orientation;
+  uint32_t columns;
+  uint32_t rows;
+  uint32_t starting_corner;
+} xcb_ewmh_get_desktop_layout_reply_t;
+
+typedef enum {
+  XCB_EWMH_MOVERESIZE_WINDOW_X = (1 << 8),
+  XCB_EWMH_MOVERESIZE_WINDOW_Y = (1 << 9),
+  XCB_EWMH_MOVERESIZE_WINDOW_WIDTH = (1 << 10),
+  XCB_EWMH_MOVERESIZE_WINDOW_HEIGHT = (1 << 11)
+} xcb_ewmh_moveresize_window_opt_flags_t;
+
+typedef enum {
+  XCB_EWMH_WM_MOVERESIZE_SIZE_TOPLEFT = 0,
+  XCB_EWMH_WM_MOVERESIZE_SIZE_TOP = 1,
+  XCB_EWMH_WM_MOVERESIZE_SIZE_TOPRIGHT = 2,
+  XCB_EWMH_WM_MOVERESIZE_SIZE_RIGHT = 3,
+  XCB_EWMH_WM_MOVERESIZE_SIZE_BOTTOMRIGHT = 4,
+  XCB_EWMH_WM_MOVERESIZE_SIZE_BOTTOM = 5,
+  XCB_EWMH_WM_MOVERESIZE_SIZE_BOTTOMLEFT = 6,
+  XCB_EWMH_WM_MOVERESIZE_SIZE_LEFT = 7,
+  /* movement only */
+  XCB_EWMH_WM_MOVERESIZE_MOVE = 8,
+  /* size via keyboard */
+  XCB_EWMH_WM_MOVERESIZE_SIZE_KEYBOARD = 9,
+  /* move via keyboard */
+  XCB_EWMH_WM_MOVERESIZE_MOVE_KEYBOARD = 10,
+  /* cancel operation */
+  XCB_EWMH_WM_MOVERESIZE_CANCEL = 11
+} xcb_ewmh_moveresize_direction_t;
+
+typedef enum {
+  /* remove/unset property */
+  XCB_EWMH_WM_STATE_REMOVE = 0,
+  /* add/set property */
+  XCB_EWMH_WM_STATE_ADD = 1,
+  /* toggle property  */
+  XCB_EWMH_WM_STATE_TOGGLE = 2
+} xcb_ewmh_wm_state_action_t;
+
+typedef struct {
+  uint32_t left;
+  uint32_t right;
+  uint32_t top;
+  uint32_t bottom;
+  uint32_t left_start_y;
+  uint32_t left_end_y;
+  uint32_t right_start_y;
+  uint32_t right_end_y;
+  uint32_t top_start_x;
+  uint32_t top_end_x;
+  uint32_t bottom_start_x;
+  uint32_t bottom_end_x;
+} xcb_ewmh_wm_strut_t;
+
+typedef struct {
+  uint32_t width;
+  uint32_t height;
+  uint32_t *data;
+  xcb_get_property_reply_t *_reply;
+} xcb_ewmh_get_wm_icon_reply_t;
+
+typedef struct {
+  uint32_t left;
+  uint32_t right;
+  uint32_t top;
+  uint32_t bottom;
+} xcb_ewmh_get_frame_extents_reply_t;
+
+typedef struct {
+  uint32_t top;
+  uint32_t bottom;
+  uint32_t left;
+  uint32_t right;
+} xcb_ewmh_get_wm_fullscreen_monitors_reply_t;
+
+void xcb_ewmh_init_atoms_list(xcb_connection_t *c,
+				 const int screen_nbr);
+
+uint8_t xcb_ewmh_init_atoms_list_replies(xcb_connection_t *c,
+				         xcb_generic_error_t **e);
+
+xcb_get_selection_owner_cookie_t xcb_ewmh_get_wm_cm_owner_unchecked(xcb_connection_t *c);
+
+uint8_t xcb_ewmh_get_wm_cm_owner_reply(xcb_connection_t *c,
+				       xcb_get_selection_owner_cookie_t cookie,
+				       xcb_window_t *owner,
+				       xcb_generic_error_t **e);
+
+void xcb_ewmh_set_wm_cm_owner(xcb_connection_t *c,
+			      xcb_window_t owner,
+			      xcb_timestamp_t timestamp,
+			      uint32_t selection_data1,
+			      uint32_t selection_data2);
+
+#ifdef __cplusplus
+}
+#endif
+
+/**
+ * @}
+ */
+
+#endif /* __XCB_EWMH_H__ */


More information about the xcb-commit mailing list