1 diff --git a/back.c b/back.c
2 index c1810dc..75416fb 100644
5 @@ -25,7 +25,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
9 -#define CFGFILE "/etc/spnavrc"
11 int get_daemon_pid(void);
12 static int update_cfg(void);
13 @@ -127,7 +126,7 @@ int get_daemon_pid(void)
15 static int update_cfg(void)
17 - if(write_cfg(CFGFILE, &cfg) == -1) {
18 + if(write_cfg(cfg_path(), &cfg) == -1) {
19 fprintf(stderr, "failed to update config file\n");
22 diff --git a/cfgfile.c b/cfgfile.c
23 index 5a9c502..2ea323d 100644
26 @@ -22,12 +22,40 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
31 +#include <sys/types.h>
35 enum {TX, TY, TZ, RX, RY, RZ};
37 static const int def_axmap[] = {0, 2, 1, 3, 5, 4};
38 static const int def_axinv[] = {0, 1, 1, 0, 1, 1};
39 +static char* config_path;
44 + if((buf = getenv("XDG_CONFIG_HOME"))) {
45 + if(config_path == NULL) {
46 + config_path = malloc(strlen(buf) + strlen("/spnavrc") + 1);
47 + if ( config_path != NULL) {
48 + sprintf(config_path, "%s/spnavrc", buf);
53 + if (!(buf = getenv("HOME"))) {
54 + struct passwd *pw = getpwuid(getuid());
57 + config_path = malloc(strlen(buf) + strlen("/.config/spnavrc") + 1);
58 + if ( config_path != NULL) {
59 + sprintf(config_path, "%s/.config/spnavrc", buf);
65 void default_cfg(struct cfg *cfg)
67 diff --git a/cfgfile.h b/cfgfile.h
68 index dfed8c9..5bb1b2c 100644
71 @@ -47,6 +47,7 @@ struct cfg {
72 int devid[MAX_CUSTOM][2]; /* custom USB vendor/product id list */
75 +char* cfg_path(void);
76 void default_cfg(struct cfg *cfg);
77 int read_cfg(const char *fname, struct cfg *cfg);
78 int write_cfg(const char *fname, struct cfg *cfg);
79 diff --git a/front_gtk.c b/front_gtk.c
80 index e4c2cd7..6a800a0 100644
83 @@ -28,8 +28,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
87 -#define CFGFILE "/etc/spnavrc"
89 #define CHK_AXINV_TRANS_X "axinv_trans_x"
90 #define CHK_AXINV_TRANS_Y "axinv_trans_y"
91 #define CHK_AXINV_TRANS_Z "axinv_trans_z"
92 @@ -121,7 +119,7 @@ void frontend(int pfd)
96 - read_cfg(CFGFILE, &cfg);
97 + read_cfg(cfg_path(), &cfg);