about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/libraries/libspnav
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/pkgs/development/libraries/libspnav')
-rw-r--r--nixpkgs/pkgs/development/libraries/libspnav/configure-socket-path.patch47
-rw-r--r--nixpkgs/pkgs/development/libraries/libspnav/default.nix41
2 files changed, 88 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/development/libraries/libspnav/configure-socket-path.patch b/nixpkgs/pkgs/development/libraries/libspnav/configure-socket-path.patch
new file mode 100644
index 000000000000..9a8ef0d49811
--- /dev/null
+++ b/nixpkgs/pkgs/development/libraries/libspnav/configure-socket-path.patch
@@ -0,0 +1,47 @@
+diff --git a/spnav.c b/spnav.c
+index f9e10f8..27149f7 100644
+--- a/spnav.c
++++ b/spnav.c
+@@ -36,7 +36,7 @@ OF SUCH DAMAGE.
+ #include <sys/select.h>
+ #include "spnav.h"
+ 
+-#define SPNAV_SOCK_PATH "/var/run/spnav.sock"
++#define DEFAULT_SPNAV_SOCK_PATH "/run/spnav.sock"
+ 
+ #ifdef USE_X11
+ #include <X11/Xlib.h>
+@@ -70,6 +70,24 @@ static struct event_node *ev_queue, *ev_queue_tail;
+ /* AF_UNIX socket used for alternative communication with daemon */
+ static int sock = -1;
+ 
++static char *spath = NULL;
++
++static char *socket_path()
++{
++	char *xdg_runtime_dir;
++	if((xdg_runtime_dir = getenv("XDG_RUNTIME_DIR"))) {
++		if ( spath == NULL ) {
++			spath = malloc(strlen(xdg_runtime_dir) + strlen("/spnav.sock") + 1);
++			if ( spath != NULL ) {
++				sprintf(spath, "%s/spnav.sock", xdg_runtime_dir);
++			}
++		}
++		if(access(spath, F_OK) != -1){
++			return spath;
++		}
++	}
++	return DEFAULT_SPNAV_SOCK_PATH;
++}
+ 
+ int spnav_open(void)
+ {
+@@ -92,7 +110,7 @@ int spnav_open(void)
+ 
+ 	memset(&addr, 0, sizeof addr);
+ 	addr.sun_family = AF_UNIX;
+-	strncpy(addr.sun_path, SPNAV_SOCK_PATH, sizeof(addr.sun_path));
++	strncpy(addr.sun_path, socket_path(), sizeof(addr.sun_path));
+ 
+ 
+ 	if(connect(s, (struct sockaddr*)&addr, sizeof addr) == -1) {
diff --git a/nixpkgs/pkgs/development/libraries/libspnav/default.nix b/nixpkgs/pkgs/development/libraries/libspnav/default.nix
new file mode 100644
index 000000000000..f6908aa3314f
--- /dev/null
+++ b/nixpkgs/pkgs/development/libraries/libspnav/default.nix
@@ -0,0 +1,41 @@
+{ stdenv, lib, fetchFromGitHub, libX11, fixDarwinDylibNames }:
+
+stdenv.mkDerivation rec {
+  version = "0.2.3";
+  pname = "libspnav";
+
+  src = fetchFromGitHub {
+    owner = "FreeSpacenav";
+    repo = "libspnav";
+    rev = "${pname}-${version}";
+    sha256 = "098h1jhlj87axpza5zgy58prp0zn94wyrbch6x0s7q4mzh7dc8ba";
+  };
+
+  nativeBuildInputs = lib.optional stdenv.isDarwin fixDarwinDylibNames;
+  buildInputs = [ libX11 ];
+
+  patches = [
+    # Changes the socket path from /run/spnav.sock to $XDG_RUNTIME_DIR/spnav.sock
+    # to allow for a user service
+    ./configure-socket-path.patch
+  ];
+
+  configureFlags = [ "--disable-debug"];
+  makeFlags = [
+    "CC=${stdenv.cc.targetPrefix}cc"
+    "AR=${stdenv.cc.targetPrefix}ar"
+  ];
+
+  preInstall = ''
+    mkdir -p $out/{lib,include}
+  '';
+
+  meta = with lib; {
+    homepage = "http://spacenav.sourceforge.net/";
+    description = "Device driver and SDK for 3Dconnexion 3D input devices";
+    longDescription = "A free, compatible alternative, to the proprietary 3Dconnexion device driver and SDK, for their 3D input devices (called 'space navigator', 'space pilot', 'space traveller', etc)";
+    license = licenses.bsd3;
+    platforms = platforms.unix;
+    maintainers = with maintainers; [ sohalt ];
+  };
+}