summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRay Strode <rstrode@redhat.com>2014-04-17 14:42:15 -0400
committerRay Strode <rstrode@redhat.com>2014-04-17 15:09:13 -0400
commit7c50a701066b4a4423b4e8c4972c1352aaea03fb (patch)
treec94327e32ec139cd56b2a3969b65ad7b7998b23d
parentca093dca194e88df619bb4397b4ea979686da537 (diff)
xcb_parse_display: support XDG_RUNTIME_DIR/X11-socketxdg-implicitly
If a client doesn't give a display we should just assume they want to connect to a well known name in their runtime directory. This gets rid of one more environment variable in the wild.
-rw-r--r--src/xcb_util.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/xcb_util.c b/src/xcb_util.c
index 9bdfa86..c63648c 100644
--- a/src/xcb_util.c
+++ b/src/xcb_util.c
@@ -83,11 +83,24 @@ static int _xcb_parse_display(const char *name, char **host, char **protocol,
{
int len, display, screen;
char *slash, *colon, *dot, *end;
+ char socket_path[PATH_MAX];
if(!name || !*name)
name = getenv("DISPLAY");
- if(!name)
- return 0;
+
+ if(!name) {
+ const char *runtime_dir = getenv ("XDG_RUNTIME_DIR");
+
+ if(!runtime_dir || runtime_dir[0] != '/')
+ goto error_out;
+
+ snprintf(socket_path, sizeof(socket_path), "%s/X11-socket", runtime_dir);
+
+ if(access(socket_path, F_OK) < 0)
+ goto error_out;
+
+ name = socket_path;
+ }
if(name[0] == '/')
slash = NULL;