diff --git a/i3bar/include/xcb.h b/i3bar/include/xcb.h index 5ace4f0b..0adb29ab 100644 --- a/i3bar/include/xcb.h +++ b/i3bar/include/xcb.h @@ -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 diff --git a/i3bar/include/xcb_atoms.def b/i3bar/include/xcb_atoms.def index 2ac94acb..5d168873 100644 --- a/i3bar/include/xcb_atoms.def +++ b/i3bar/include/xcb_atoms.def @@ -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 diff --git a/i3bar/src/main.c b/i3bar/src/main.c index 8e632b7b..b09a220f 100644 --- a/i3bar/src/main.c +++ b/i3bar/src/main.c @@ -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); diff --git a/i3bar/src/xcb.c b/i3bar/src/xcb.c index 5f4c58f7..f9f3f79a 100644 --- a/i3bar/src/xcb.c +++ b/i3bar/src/xcb.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -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; } /*