make i3bar use libi3’s root_atom_contents()

This removes code duplication, which will be useful for a subsequent
commit.

Furthermore, we now don’t open X11 connections unnecessarily in some
corner cases.
This commit is contained in:
Michael Stapelberg
2013-11-22 15:48:45 +01:00
parent ca39289e3e
commit d3beff2339
9 changed files with 36 additions and 48 deletions

View File

@ -68,11 +68,11 @@ static yajl_callbacks version_callbacks = {
*
*/
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");

View File

@ -352,7 +352,7 @@ int main(int argc, char *argv[]) {
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);
@ -442,7 +442,7 @@ int main(int argc, char *argv[]) {
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;