close(fd);
unlink(config_path);
+ int screen;
+ if ((conn = xcb_connect(NULL, &screen)) == NULL ||
+ xcb_connection_has_error(conn))
+ errx(1, "Cannot open display\n");
+
if (socket_path == NULL)
- socket_path = root_atom_contents("I3_SOCKET_PATH");
+ socket_path = root_atom_contents("I3_SOCKET_PATH", conn, screen);
if (socket_path == NULL)
socket_path = "/tmp/i3-ipc.sock";
- int screens;
- if ((conn = xcb_connect(NULL, &screens)) == NULL ||
- xcb_connection_has_error(conn))
- errx(1, "Cannot open display\n");
-
keysyms = xcb_key_symbols_alloc(conn);
xcb_get_modifier_mapping_cookie_t modmap_cookie;
modmap_cookie = xcb_get_modifier_mapping(conn);
#include "atoms.xmacro"
#undef xmacro
- root_screen = xcb_aux_get_screen(conn, screens);
+ root_screen = xcb_aux_get_screen(conn, screen);
root = root_screen->root;
if (!(modmap_reply = xcb_get_modifier_mapping_reply(conn, modmap_cookie, NULL)))
}
}
- char *shmname = root_atom_contents("I3_SHMLOG_PATH");
+ char *shmname = root_atom_contents("I3_SHMLOG_PATH", NULL, 0);
if (shmname == NULL) {
/* Something failed. Let’s invest a little effort to find out what it
* is. This is hugely helpful for users who want to debug i3 but are
fprintf(stderr, "FYI: The DISPLAY environment variable is set to \"%s\".\n", getenv("DISPLAY"));
exit(1);
}
- if (root_atom_contents("I3_CONFIG_PATH") != NULL) {
+ if (root_atom_contents("I3_CONFIG_PATH", conn, screen) != NULL) {
fprintf(stderr, "i3-dump-log: ERROR: i3 is running, but SHM logging is not enabled.\n\n");
if (!is_debug_build()) {
fprintf(stderr, "You seem to be using a release version of i3:\n %s\n\n", I3_VERSION);
printf("using format \"%s\"\n", format);
+ int screen;
+ conn = xcb_connect(NULL, &screen);
+ if (!conn || xcb_connection_has_error(conn))
+ die("Cannot open display\n");
+
if (socket_path == NULL)
- socket_path = root_atom_contents("I3_SOCKET_PATH");
+ socket_path = root_atom_contents("I3_SOCKET_PATH", conn, screen);
if (socket_path == NULL)
socket_path = "/tmp/i3-ipc.sock";
sockfd = ipc_connect(socket_path);
- int screens;
- conn = xcb_connect(NULL, &screens);
- if (!conn || xcb_connection_has_error(conn))
- die("Cannot open display\n");
-
/* Request the current InputFocus to restore when i3-input exits. */
focus_cookie = xcb_get_input_focus(conn);
- root_screen = xcb_aux_get_screen(conn, screens);
+ root_screen = xcb_aux_get_screen(conn, screen);
root = root_screen->root;
symbols = xcb_key_symbols_alloc(conn);
}
if (socket_path == NULL)
- socket_path = root_atom_contents("I3_SOCKET_PATH");
+ socket_path = root_atom_contents("I3_SOCKET_PATH", NULL, 0);
/* Fall back to the default socket path */
if (socket_path == NULL)
/* 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 its 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);
- }
- }
-
+ char *path = root_atom_contents("I3_SOCKET_PATH", xcb_connection, screen);
if (xcb_request_failed(sl_pm_cookie, "Could not allocate statusline-buffer") ||
xcb_request_failed(clear_ctx_cookie, "Could not allocate statusline-buffer-clearcontext") ||
* Try to get the contents of the given atom (for example I3_SOCKET_PATH) from
* the X11 root window and return NULL if it doesn’t work.
*
+ * If the provided XCB connection is NULL, a new connection will be
+ * established.
+ *
* The memory for the contents is dynamically allocated and has to be
* free()d by the caller.
*
*/
-char *root_atom_contents(const char *atomname);
+char *root_atom_contents(const char *atomname, xcb_connection_t *provided_conn, int screen);
/**
* Safe-wrapper around malloc which exits if malloc returns NULL (meaning that
* Try to get the contents of the given atom (for example I3_SOCKET_PATH) from
* the X11 root window and return NULL if it doesn’t work.
*
+ * If the provided XCB connection is NULL, a new connection will be
+ * established.
+ *
* The memory for the contents is dynamically allocated and has to be
* free()d by the caller.
*
*/
-char *root_atom_contents(const char *atomname) {
- xcb_connection_t *conn;
+char *root_atom_contents(const char *atomname, xcb_connection_t *provided_conn, int screen) {
xcb_intern_atom_cookie_t atom_cookie;
xcb_intern_atom_reply_t *atom_reply;
- int screen;
char *content;
+ xcb_connection_t *conn = provided_conn;
- if ((conn = xcb_connect(NULL, &screen)) == NULL ||
- xcb_connection_has_error(conn))
+ if (provided_conn == NULL &&
+ ((conn = xcb_connect(NULL, &screen)) == NULL ||
+ xcb_connection_has_error(conn)))
return NULL;
atom_cookie = xcb_intern_atom(conn, 0, strlen(atomname), atomname);
(char*)xcb_get_property_value(prop_reply)) == -1)
return NULL;
}
- xcb_disconnect(conn);
+ if (provided_conn == NULL)
+ xcb_disconnect(conn);
return content;
}
*
*/
void display_running_version(void) {
- char *socket_path = root_atom_contents("I3_SOCKET_PATH");
+ char *socket_path = root_atom_contents("I3_SOCKET_PATH", conn, conn_screen);
if (socket_path == NULL)
exit(EXIT_SUCCESS);
- char *pid_from_atom = root_atom_contents("I3_PID");
+ char *pid_from_atom = root_atom_contents("I3_PID", conn, conn_screen);
if (pid_from_atom == NULL) {
/* If I3_PID is not set, the running version is older than 4.2-200. */
printf("\nRunning version: < 4.2-200\n");
break;
} else if (strcmp(long_options[option_index].name, "get-socketpath") == 0 ||
strcmp(long_options[option_index].name, "get_socketpath") == 0) {
- char *socket_path = root_atom_contents("I3_SOCKET_PATH");
+ char *socket_path = root_atom_contents("I3_SOCKET_PATH", NULL, 0);
if (socket_path) {
printf("%s\n", socket_path);
exit(EXIT_SUCCESS);
optind++;
}
DLOG("Command is: %s (%zd bytes)\n", payload, strlen(payload));
- char *socket_path = root_atom_contents("I3_SOCKET_PATH");
+ char *socket_path = root_atom_contents("I3_SOCKET_PATH", NULL, 0);
if (!socket_path) {
ELOG("Could not get i3 IPC socket path\n");
return 1;