Merge master into staging-next

This commit is contained in:
github-actions[bot]
2021-05-22 12:27:09 +00:00
committed by GitHub
22 changed files with 550 additions and 26 deletions
+3 -5
View File
@@ -6,7 +6,6 @@
, x11Support ? true
, ConfigArgParse
, pyxdg
, rofi
, wl-clipboard
, wtype
@@ -16,18 +15,18 @@
buildPythonApplication rec {
pname = "rofimoji";
version = "4.3.0";
version = "5.1.0";
src = fetchFromGitHub {
owner = "fdw";
repo = "rofimoji";
rev = version;
sha256 = "08ayndpifr04njpijc5n5ii5nvibfpab39p6ngyyj0pb43792a8j";
sha256 = "sha256-bLV0hYDjVH11euvNHUHZFcCVywuceRljkCqyX4aANVs=";
};
# `rofi` and the `waylandSupport` and `x11Support` dependencies
# contain binaries needed at runtime.
propagatedBuildInputs = with lib; [ ConfigArgParse pyxdg rofi ]
propagatedBuildInputs = with lib; [ ConfigArgParse rofi ]
++ optionals waylandSupport [ wl-clipboard wtype ]
++ optionals x11Support [ xdotool xsel ];
@@ -35,7 +34,6 @@ buildPythonApplication rec {
# and has additional dependencies.
postPatch = ''
rm -rf extractors
substituteInPlace setup.py --replace 'pyxdg==0.26' 'pyxdg'
'';
# no tests executed
@@ -0,0 +1,100 @@
diff --git a/back.c b/back.c
index c1810dc..75416fb 100644
--- a/back.c
+++ b/back.c
@@ -25,7 +25,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "cfgfile.h"
#include "cmd.h"
-#define CFGFILE "/etc/spnavrc"
int get_daemon_pid(void);
static int update_cfg(void);
@@ -127,7 +126,7 @@ int get_daemon_pid(void)
static int update_cfg(void)
{
- if(write_cfg(CFGFILE, &cfg) == -1) {
+ if(write_cfg(cfg_path(), &cfg) == -1) {
fprintf(stderr, "failed to update config file\n");
return -1;
}
diff --git a/cfgfile.c b/cfgfile.c
index 5a9c502..2ea323d 100644
--- a/cfgfile.c
+++ b/cfgfile.c
@@ -22,12 +22,40 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <pwd.h>
#include "cfgfile.h"
enum {TX, TY, TZ, RX, RY, RZ};
static const int def_axmap[] = {0, 2, 1, 3, 5, 4};
static const int def_axinv[] = {0, 1, 1, 0, 1, 1};
+static char* config_path;
+
+char* cfg_path()
+{
+ char* buf;
+ if((buf = getenv("XDG_CONFIG_HOME"))) {
+ if(config_path == NULL) {
+ config_path = malloc(strlen(buf) + strlen("/spnavrc") + 1);
+ if ( config_path != NULL) {
+ sprintf(config_path, "%s/spnavrc", buf);
+ }
+ };
+ return config_path;
+ } else {
+ if (!(buf = getenv("HOME"))) {
+ struct passwd *pw = getpwuid(getuid());
+ buf = pw->pw_dir;
+ }
+ config_path = malloc(strlen(buf) + strlen("/.config/spnavrc") + 1);
+ if ( config_path != NULL) {
+ sprintf(config_path, "%s/.config/spnavrc", buf);
+ }
+ return config_path;
+ }
+}
void default_cfg(struct cfg *cfg)
{
diff --git a/cfgfile.h b/cfgfile.h
index dfed8c9..5bb1b2c 100644
--- a/cfgfile.h
+++ b/cfgfile.h
@@ -47,6 +47,7 @@ struct cfg {
int devid[MAX_CUSTOM][2]; /* custom USB vendor/product id list */
};
+char* cfg_path(void);
void default_cfg(struct cfg *cfg);
int read_cfg(const char *fname, struct cfg *cfg);
int write_cfg(const char *fname, struct cfg *cfg);
diff --git a/front_gtk.c b/front_gtk.c
index e4c2cd7..6a800a0 100644
--- a/front_gtk.c
+++ b/front_gtk.c
@@ -28,8 +28,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "cmd.h"
#include "ui.h"
-#define CFGFILE "/etc/spnavrc"
-
#define CHK_AXINV_TRANS_X "axinv_trans_x"
#define CHK_AXINV_TRANS_Y "axinv_trans_y"
#define CHK_AXINV_TRANS_Z "axinv_trans_z"
@@ -121,7 +119,7 @@ void frontend(int pfd)
gtk_init(&argc, 0);
- read_cfg(CFGFILE, &cfg);
+ read_cfg(cfg_path(), &cfg);
create_ui();
@@ -0,0 +1,40 @@
diff --git a/back.c b/back.c
index f364e31..c1810dc 100644
--- a/back.c
+++ b/back.c
@@ -26,7 +26,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "cmd.h"
#define CFGFILE "/etc/spnavrc"
-#define PIDFILE "/var/run/spnavd.pid"
int get_daemon_pid(void);
static int update_cfg(void);
@@ -97,11 +96,26 @@ int get_daemon_pid(void)
{
FILE *fp;
char buf[64];
+ char* xdg_runtime_dir;
+ char* pidfile;
- if(!(fp = fopen(PIDFILE, "r"))) {
+ if(!(xdg_runtime_dir = getenv("XDG_RUNTIME_DIR"))){
+ fprintf(stderr, "XDG_RUNTIME_DIR not set, can't find spacenav pid file\n");
+ return -1;
+ }
+ pidfile = malloc(strlen(xdg_runtime_dir) + strlen("/spnavd.pid") + 1);
+ if (pidfile == NULL) {
+ fprintf(stderr, "failed to allocate memory\n");
+ return -1;
+ }
+ sprintf(pidfile, "%s/spnavd.pid", xdg_runtime_dir);
+
+ if(!(fp = fopen(pidfile, "r"))) {
fprintf(stderr, "no spacenav pid file, can't find daemon\n");
+ free(pidfile);
return -1;
}
+ free(pidfile);
if(!fgets(buf, sizeof buf, fp) || !isdigit(buf[0])) {
fprintf(stderr, "corrupted pidfile, can't find the daemon\n");
fclose(fp);
@@ -11,6 +11,15 @@ stdenv.mkDerivation rec {
sha256 = "180mkdis15gxs79rr3f7hpwa1p6v81bybw37pzzdjnmqwqrc08a0";
};
patches = [
# Changes the pidfile path from /run/spnavd.pid to $XDG_RUNTIME_DIR/spnavd.pid
# to allow for a user service
./configure-pidfile-path.patch
# Changes the config file path from /etc/spnavrc to $XDG_CONFIG_HOME/spnavrc or $HOME/.config/spnavrc
# to allow for a user service
./configure-cfgfile-path.patch
];
postPatch = ''
sed -i s/4775/775/ Makefile.in
'';