]> git.sur5r.net Git - i3/i3/commitdiff
Add support for I3_SOCKET_PATH-atom
authorAxel Wagner <mail@merovius.de>
Sat, 19 Mar 2011 21:06:08 +0000 (22:06 +0100)
committerAxel Wagner <mail@merovius.de>
Sat, 19 Mar 2011 21:06:08 +0000 (22:06 +0100)
i3bar/include/xcb.h
i3bar/include/xcb_atoms.def
i3bar/src/main.c
i3bar/src/xcb.c

index 5ace4f0b665d4ffeea20df8fd43dbf4f3909c2e7..0adb29ab1d966aa03ffba5108a4da9c9a75b024d 100644 (file)
@@ -29,7 +29,7 @@ typedef struct xcb_colors_t xcb_colors_t;
  * Initialize xcb and use the specified fontname for text-rendering
  *
  */
-void init_xcb();
+char *init_xcb();
 
 /*
  * Initialize the colors
index 2ac94acb81beedc74592bf85bcd45a28b6dd6d17..5d1688731659a38240ed84b40075e0dd10197e25 100644 (file)
@@ -1,4 +1,5 @@
 ATOM_DO(_NET_WM_WINDOW_TYPE)
 ATOM_DO(_NET_WM_WINDOW_TYPE_DOCK)
 ATOM_DO(_NET_WM_STRUT_PARTIAL)
+ATOM_DO(I3_SOCKET_PATH)
 #undef ATOM_DO
index 8e632b7b2bb07dfedfa4bb2780feec45eb6838ed..b09a220f683f01b90c31d001af0d4570360bce8b 100644 (file)
@@ -218,11 +218,6 @@ int main(int argc, char **argv) {
         fontname = "-misc-fixed-medium-r-semicondensed--12-110-75-75-c-60-iso10646-1";
     }
 
-    if (socket_path == NULL) {
-        ELOG("No Socket Path Specified, default to %s\n", i3_default_sock_path);
-        socket_path = expand_path(i3_default_sock_path);
-    }
-
     if (config.dockpos != DOCKPOS_NONE) {
         if (config.hide_on_modifier) {
             ELOG("--dock and --hide are mutually exclusive!\n");
@@ -235,7 +230,16 @@ int main(int argc, char **argv) {
     main_loop = ev_default_loop(0);
 
     init_colors(&colors);
-    init_xcb(fontname);
+    char *atom_sock_path = init_xcb(fontname);
+
+    if (socket_path == NULL) {
+        socket_path = atom_sock_path;
+    }
+
+    if (socket_path == NULL) {
+        ELOG("No Socket Path Specified, default to %s\n", i3_default_sock_path);
+        socket_path = expand_path(i3_default_sock_path);
+    }
 
     free_colors(&colors);
 
index 5f4c58f72624bd04a58853ac422b9d6883fd5608..f9f3f79afab172997ffc5242bcfcb49b2f9b7cf8 100644 (file)
@@ -19,6 +19,7 @@
 #include <i3/ipc.h>
 #include <ev.h>
 #include <errno.h>
+#include <limits.h>
 
 #include <X11/Xlib.h>
 #include <X11/XKBlib.h>
@@ -445,7 +446,7 @@ void xkb_io_cb(struct ev_loop *loop, ev_io *watcher, int revents) {
  * Initialize xcb and use the specified fontname for text-rendering
  *
  */
-void init_xcb(char *fontname) {
+char *init_xcb(char *fontname) {
     /* FIXME: xcb_connect leaks Memory */
     xcb_connection = xcb_connect(NULL, NULL);
     if (xcb_connection_has_error(xcb_connection)) {
@@ -555,6 +556,26 @@ void init_xcb(char *fontname) {
     /* Now we get the atoms and save them in a nice data-structure */
     get_atoms();
 
+    xcb_get_property_cookie_t path_cookie;
+    path_cookie = xcb_get_property_unchecked(xcb_connection,
+                                   0,
+                                   xcb_root,
+                                   atoms[I3_SOCKET_PATH],
+                                   XCB_GET_PROPERTY_TYPE_ANY,
+                                   0, PATH_MAX);
+
+    /* We check, if i3 set it's socket-path */
+    xcb_get_property_reply_t *path_reply = xcb_get_property_reply(xcb_connection,
+                                                                  path_cookie,
+                                                                  NULL);
+    char *path = NULL;
+    if (path_reply) {
+        int len = xcb_get_property_value_length(path_reply);
+        if (len != 0) {
+            path = strndup(xcb_get_property_value(path_reply), len);
+        }
+    }
+
     /* Now we save the font-infos */
     font_info = xcb_query_font_reply(xcb_connection,
                                      query_font_cookie,
@@ -577,6 +598,8 @@ void init_xcb(char *fontname) {
     if (xcb_request_failed(sl_ctx_cookie, "Could not create context for statusline")) {
         exit(EXIT_FAILURE);
     }
+
+    return path;
 }
 
 /*