]> git.sur5r.net Git - i3/i3/commitdiff
i3bar: request the appropriate _NET_SYSTEM_TRAY atom for the display we are running on
authorMichael Stapelberg <michael@stapelberg.de>
Tue, 16 Aug 2011 22:58:00 +0000 (00:58 +0200)
committerMichael Stapelberg <michael@stapelberg.de>
Tue, 23 Aug 2011 23:18:27 +0000 (01:18 +0200)
i3bar/include/xcb.h
i3bar/include/xcb_atoms.def
i3bar/src/xcb.c

index b70d29ef808ede7dc95c9f4199c2f35521cda91e..0276d3c7b7c04e5029fe00f96b1626efd13dede0 100644 (file)
@@ -12,6 +12,8 @@
 #include <stdint.h>
 //#include "outputs.h"
 
+#define _NET_SYSTEM_TRAY_ORIENTATION_HORZ 0
+#define _NET_SYSTEM_TRAY_ORIENTATION_VERT 1
 #define SYSTEM_TRAY_REQUEST_DOCK    0
 #define SYSTEM_TRAY_BEGIN_MESSAGE   1
 #define SYSTEM_TRAY_CANCEL_MESSAGE  2
index 625fc8a45edcec05e8fa05351bbf8dda1c23d33c..0c0b207ea2d90251237e8307470e9ad75d6b12de 100644 (file)
@@ -2,7 +2,6 @@ ATOM_DO(_NET_WM_WINDOW_TYPE)
 ATOM_DO(_NET_WM_WINDOW_TYPE_DOCK)
 ATOM_DO(_NET_WM_STRUT_PARTIAL)
 ATOM_DO(I3_SOCKET_PATH)
-ATOM_DO(_NET_SYSTEM_TRAY_S0)
 ATOM_DO(MANAGER)
 ATOM_DO(_NET_SYSTEM_TRAY_ORIENTATION)
 ATOM_DO(_NET_SYSTEM_TRAY_VISUAL)
index 81c00ac4367a65139c2d874f4ee5151692c2da79..0cb8bcc87b3d2dd543a7152bfbc78f1828aa3144 100644 (file)
@@ -63,6 +63,7 @@ xcb_atom_t               atoms[NUM_ATOMS];
 
 /* Variables, that are the same for all functions at all times */
 xcb_connection_t *xcb_connection;
+int              screen;
 xcb_screen_t     *xcb_screen;
 xcb_window_t     xcb_root;
 xcb_font_t       xcb_font;
@@ -712,7 +713,7 @@ void xkb_io_cb(struct ev_loop *loop, ev_io *watcher, int revents) {
  */
 char *init_xcb(char *fontname) {
     /* FIXME: xcb_connect leaks Memory */
-    xcb_connection = xcb_connect(NULL, NULL);
+    xcb_connection = xcb_connect(NULL, &screen);
     if (xcb_connection_has_error(xcb_connection)) {
         ELOG("Cannot open display\n");
         exit(EXIT_FAILURE);
@@ -877,7 +878,14 @@ char *init_xcb(char *fontname) {
 }
 
 void init_tray() {
-/* tray support: we need a window to own the selection */
+    /* request the tray manager atom for the X11 display we are running on */
+    char atomname[strlen("_NET_SYSTEM_TRAY_S") + 11];
+    snprintf(atomname, strlen("_NET_SYSTEM_TRAY_S") + 11, "_NET_SYSTEM_TRAY_S%d", screen);
+    xcb_intern_atom_cookie_t tray_cookie;
+    xcb_intern_atom_reply_t *tray_reply;
+    tray_cookie = xcb_intern_atom(xcb_connection, 0, strlen(atomname), atomname);
+
+    /* tray support: we need a window to own the selection */
     xcb_void_cookie_t selwin_cookie;
     xcb_window_t selwin = xcb_generate_id(xcb_connection);
     uint32_t selmask = XCB_CW_OVERRIDE_REDIRECT;
@@ -894,8 +902,6 @@ void init_tray() {
                                               selmask,
                                               selval);
 
-#define _NET_SYSTEM_TRAY_ORIENTATION_HORZ 0
-#define _NET_SYSTEM_TRAY_ORIENTATION_VERT 1
     uint32_t orientation = _NET_SYSTEM_TRAY_ORIENTATION_HORZ;
     /* set the atoms */
     xcb_change_property(xcb_connection,
@@ -907,13 +913,15 @@ void init_tray() {
                         1,
                         &orientation);
 
+    if (!(tray_reply = xcb_intern_atom_reply(xcb_connection, tray_cookie, NULL))) {
+        ELOG("Could not get atom %s\n", atomname);
+        exit(EXIT_FAILURE);
+    }
 
     xcb_set_selection_owner(xcb_connection,
                             selwin,
-                            /* TODO: request this atom separately */
-                            atoms[_NET_SYSTEM_TRAY_S0],
+                            tray_reply->atom,
                             XCB_CURRENT_TIME);
-    /* FIXME: don't use XCB_CURRENT_TIME */
 
     /* TODO: check if we got the selection */
     void *event = calloc(32, 1);
@@ -923,7 +931,7 @@ void init_tray() {
     ev->type = atoms[MANAGER];
     ev->format = 32;
     ev->data.data32[0] = XCB_CURRENT_TIME;
-    ev->data.data32[1] = atoms[_NET_SYSTEM_TRAY_S0];
+    ev->data.data32[1] = tray_reply->atom;
     ev->data.data32[2] = selwin;
     xcb_send_event(xcb_connection,
                    0,
@@ -931,6 +939,7 @@ void init_tray() {
                    XCB_EVENT_MASK_STRUCTURE_NOTIFY,
                    (char*)ev);
     free(event);
+    free(tray_reply);
 }
 
 /*