spnavcfg: config file in $XDG_CONFIG_HOME

authored by

sohalt and committed by
Gabriel Ebner
547d8ee0 6172e51f

+103
+100
pkgs/applications/misc/spnavcfg/configure-cfgfile-path.patch
··· 1 + diff --git a/back.c b/back.c 2 + index c1810dc..75416fb 100644 3 + --- a/back.c 4 + +++ b/back.c 5 + @@ -25,7 +25,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. 6 + #include "cfgfile.h" 7 + #include "cmd.h" 8 + 9 + -#define CFGFILE "/etc/spnavrc" 10 + 11 + int get_daemon_pid(void); 12 + static int update_cfg(void); 13 + @@ -127,7 +126,7 @@ int get_daemon_pid(void) 14 + 15 + static int update_cfg(void) 16 + { 17 + - if(write_cfg(CFGFILE, &cfg) == -1) { 18 + + if(write_cfg(cfg_path(), &cfg) == -1) { 19 + fprintf(stderr, "failed to update config file\n"); 20 + return -1; 21 + } 22 + diff --git a/cfgfile.c b/cfgfile.c 23 + index 5a9c502..2ea323d 100644 24 + --- a/cfgfile.c 25 + +++ b/cfgfile.c 26 + @@ -22,12 +22,40 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. 27 + #include <ctype.h> 28 + #include <errno.h> 29 + #include <fcntl.h> 30 + +#include <unistd.h> 31 + +#include <sys/types.h> 32 + +#include <pwd.h> 33 + #include "cfgfile.h" 34 + 35 + enum {TX, TY, TZ, RX, RY, RZ}; 36 + 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; 40 + + 41 + +char* cfg_path() 42 + +{ 43 + + char* buf; 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); 49 + + } 50 + + }; 51 + + return config_path; 52 + + } else { 53 + + if (!(buf = getenv("HOME"))) { 54 + + struct passwd *pw = getpwuid(getuid()); 55 + + buf = pw->pw_dir; 56 + + } 57 + + config_path = malloc(strlen(buf) + strlen("/.config/spnavrc") + 1); 58 + + if ( config_path != NULL) { 59 + + sprintf(config_path, "%s/.config/spnavrc", buf); 60 + + } 61 + + return config_path; 62 + + } 63 + +} 64 + 65 + void default_cfg(struct cfg *cfg) 66 + { 67 + diff --git a/cfgfile.h b/cfgfile.h 68 + index dfed8c9..5bb1b2c 100644 69 + --- a/cfgfile.h 70 + +++ b/cfgfile.h 71 + @@ -47,6 +47,7 @@ struct cfg { 72 + int devid[MAX_CUSTOM][2]; /* custom USB vendor/product id list */ 73 + }; 74 + 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 81 + --- a/front_gtk.c 82 + +++ b/front_gtk.c 83 + @@ -28,8 +28,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. 84 + #include "cmd.h" 85 + #include "ui.h" 86 + 87 + -#define CFGFILE "/etc/spnavrc" 88 + - 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) 93 + 94 + gtk_init(&argc, 0); 95 + 96 + - read_cfg(CFGFILE, &cfg); 97 + + read_cfg(cfg_path(), &cfg); 98 + 99 + create_ui(); 100 +
+3
pkgs/applications/misc/spnavcfg/default.nix
··· 15 15 # Changes the pidfile path from /run/spnavd.pid to $XDG_RUNTIME_DIR/spnavd.pid 16 16 # to allow for a user service 17 17 ./configure-pidfile-path.patch 18 + # Changes the config file path from /etc/spnavrc to $XDG_CONFIG_HOME/spnavrc or $HOME/.config/spnavrc 19 + # to allow for a user service 20 + ./configure-cfgfile-path.patch 18 21 ]; 19 22 20 23 postPatch = ''