1 diff --git a/spnav.c b/spnav.c
2 index f9e10f8..27149f7 100644
5 @@ -36,7 +36,7 @@ OF SUCH DAMAGE.
6 #include <sys/select.h>
9 -#define SPNAV_SOCK_PATH "/var/run/spnav.sock"
10 +#define DEFAULT_SPNAV_SOCK_PATH "/run/spnav.sock"
14 @@ -70,6 +70,24 @@ static struct event_node *ev_queue, *ev_queue_tail;
15 /* AF_UNIX socket used for alternative communication with daemon */
18 +static char *spath = NULL;
20 +static char *socket_path()
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);
30 + if(access(spath, F_OK) != -1){
34 + return DEFAULT_SPNAV_SOCK_PATH;
39 @@ -92,7 +110,7 @@ int spnav_open(void)
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));
47 if(connect(s, (struct sockaddr*)&addr, sizeof addr) == -1) {