1diff --git a/spnav.c b/spnav.c
2index f9e10f8..27149f7 100644
3--- a/spnav.c
4+++ b/spnav.c
5@@ -36,7 +36,7 @@ OF SUCH DAMAGE.
6 #include <sys/select.h>
7 #include "spnav.h"
8
9-#define SPNAV_SOCK_PATH "/var/run/spnav.sock"
10+#define DEFAULT_SPNAV_SOCK_PATH "/run/spnav.sock"
11
12 #ifdef USE_X11
13 #include <X11/Xlib.h>
14@@ -70,6 +70,24 @@ static struct event_node *ev_queue, *ev_queue_tail;
15 /* AF_UNIX socket used for alternative communication with daemon */
16 static int sock = -1;
17
18+static char *spath = NULL;
19+
20+static char *socket_path()
21+{
22+ char *xdg_runtime_dir;
23+ if((xdg_runtime_dir = getenv("XDG_RUNTIME_DIR"))) {
24+ if ( spath == NULL ) {
25+ spath = malloc(strlen(xdg_runtime_dir) + strlen("/spnav.sock") + 1);
26+ if ( spath != NULL ) {
27+ sprintf(spath, "%s/spnav.sock", xdg_runtime_dir);
28+ }
29+ }
30+ if(access(spath, F_OK) != -1){
31+ return spath;
32+ }
33+ }
34+ return DEFAULT_SPNAV_SOCK_PATH;
35+}
36
37 int spnav_open(void)
38 {
39@@ -92,7 +110,7 @@ int spnav_open(void)
40
41 memset(&addr, 0, sizeof addr);
42 addr.sun_family = AF_UNIX;
43- strncpy(addr.sun_path, SPNAV_SOCK_PATH, sizeof(addr.sun_path));
44+ strncpy(addr.sun_path, socket_path(), sizeof(addr.sun_path));
45
46
47 if(connect(s, (struct sockaddr*)&addr, sizeof addr) == -1) {