documentation v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Fri, 08 Mar 2019 23:05:15 +0100
branchv_0
changeset 4 650e0a578dab
parent 3 d8793f61ee43
child 5 26e9fb705faf
documentation
src/spacenav-lib-hack.c
--- a/src/spacenav-lib-hack.c	Fri Mar 08 22:48:35 2019 +0100
+++ b/src/spacenav-lib-hack.c	Fri Mar 08 23:05:15 2019 +0100
@@ -26,6 +26,27 @@
 #include <X11/Xlib.h>
 #include <spnav.h>
 
+/**
+ * The purpose of this hack is to enable 3D mouse in applications that use X11 protocol
+ * while our daemon is providing only domain socket and no X11.
+ * 
+ * Usage:
+ * LD_PRELOAD=./spacenav-lib-hack/build/Debug/src/libspnav-lib-hack.so freecad
+ * 
+ * This hack:
+ * 1) Pretends that spnav_x11_open() was successful.
+ * 2) Starts a background process (TODO: also terminate it) which reads from the domain socket
+ *    and translates spacenav events to X11 events and sends them to the application window.
+ * 3) reimplements spnav_x11_event() which is needed, because Atom variables in original library
+ *    were not initialized spnav_x11_open() and thus the library funcion is not working.
+ * 
+ * This solution works and allows using e.g. FreeCAD with domain socket instead of X11, but:
+ *	- the background process never ends and must be terminated by: killall freecad
+ *  - is very hackish and should be reimplemented as a separate process which will work partly
+ *    as a libspnav client and partly emulate spacenavd daemon and will bridge the domain socket
+ *    and th X11. Other solution is to emulate the hardware and keep spacenavd and libspnav untouched.
+ */
+
 // from proto_x11.c (spacenavd)
 static Atom xa_event_motion, xa_event_bpress, xa_event_brelease, xa_event_cmd;
 static float x11_sens = 1.0;
@@ -75,13 +96,8 @@
 			break;
 	}
 
-	Window xxx;
-	int zzz;
-	int yyy = XGetInputFocus(dpy, &xxx, &zzz);
-	fprintf(stderr, "spnav-lib-hack: XGetInputFocus(%p, %lx, %d) = %d\n", dpy, xxx, zzz, yyy);
-	Status result = XSendEvent(dpy, win, False, 0, &xevent);
-	int xflushResult = XFlush(dpy);
-	fprintf(stderr, "spnav-lib-hack: send_xevent(); XSendEvent() = %d; XFlush() = %d\n", result, xflushResult);
+	XSendEvent(dpy, win, False, 0, &xevent);
+	XFlush(dpy);
 }
 
 static void spacenav_hack_translate_events(Window win) {