a bit cleaner version (but still with an infinite loop) v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Fri, 08 Mar 2019 22:48:35 +0100
branchv_0
changeset 3 d8793f61ee43
parent 2 3ba27504be0e
child 4 650e0a578dab
a bit cleaner version (but still with an infinite loop) tested with FreeCAD – test case: - start spacenavd daemon without .Xauthority so it accepts only domain socket connection but not X11 - run freecad - 3D mouse will not work - run LD_PRELOAD=./spacenav-lib-hack/build/Debug/src/libspnav-lib-hack.so freecad - 3D mouse will work
src/spacenav-lib-hack.c
--- a/src/spacenav-lib-hack.c	Fri Mar 08 22:38:58 2019 +0100
+++ b/src/spacenav-lib-hack.c	Fri Mar 08 22:48:35 2019 +0100
@@ -30,28 +30,6 @@
 static Atom xa_event_motion, xa_event_bpress, xa_event_brelease, xa_event_cmd;
 static float x11_sens = 1.0;
 
-/* X11 error handler */
-static int xerr(Display *dpy, XErrorEvent *err) {
-	char buf[512];
-
-	fprintf(stderr, "xerr(%p, %p)\n", (void*) dpy, (void*) err);
-	if (err->error_code == BadWindow) {
-		fprintf(stderr, "BadWindow\n");
-	} else {
-		XGetErrorText(dpy, err->error_code, buf, sizeof buf);
-		fprintf(stderr, "Caught unexpected X error: %s\n", buf);
-	}
-	return 0;
-}
-
-/* X11 I/O error handler
- * This function must not return or xlib will abort.
- */
-static int xioerr(Display *display) {
-	fprintf(stderr, "Lost the X server!\n");
-	return 0;
-}
-
 /**
  * This function is based on proto_x11.c (spacenavd) written by:
  * Copyright (C) 2007-2019 John Tsiombikas <nuclear@member.fsf.org>
@@ -109,30 +87,13 @@
 static void spacenav_hack_translate_events(Window win) {
 	spnav_event event;
 	Display* dpy = XOpenDisplay(0);
-	XSetErrorHandler(xerr);
-	XSetIOErrorHandler(xioerr);
-	fprintf(stderr, "Error handlers were set\n");
-
-	/*
-	xa_event_motion = XInternAtom(dpy, "MotionEvent", False);
-	xa_event_bpress = XInternAtom(dpy, "ButtonPressEvent", False);
-	xa_event_brelease = XInternAtom(dpy, "ButtonReleaseEvent", False);
-	xa_event_cmd = XInternAtom(dpy, "CommandEvent", False);
-	 */
-
-	fprintf(stderr, "spnav-lib-hack: xa_event_motion = %ld\n", xa_event_motion);
-	fprintf(stderr, "spnav-lib-hack: xa_event_bpress = %ld\n", xa_event_bpress);
-	fprintf(stderr, "spnav-lib-hack: xa_event_brelease = %ld\n", xa_event_brelease);
-	fprintf(stderr, "spnav-lib-hack: xa_event_cmd = %ld\n", xa_event_cmd);
 
 	while (1) {
 		if (spnav_wait_event(&event)) {
-			fprintf(stderr, "spnav-lib-hack: got event: PID=%d dpy=%p win=%lx\n", getpid(), dpy, win);
-			//XLockDisplay(dpy);
 			send_xevent(&event, dpy, win);
-			//XUnlockDisplay(dpy);
 		}
 	}
+	// FIXME: this process never ends and must be killed manually
 }
 
 int spnav_x11_open(Display* dpy, Window win) {
@@ -147,8 +108,9 @@
 	if (result == 0) {
 		pid_t pid = fork();
 		fprintf(stderr, "spnav-lib-hack: fork() = %d; PID=%d\n", pid, getpid());
-		if (pid == -1) return 1;
-		if (pid == 0) spacenav_hack_translate_events(win);
+		if (pid == -1) return 1; // error
+		if (pid == 0) spacenav_hack_translate_events(win); // child
+		else; // parent
 	}
 
 	return result;
@@ -198,6 +160,8 @@
 	}
 	return event->type;
 
+	// real_spnav_x11_event() is not working (see comment above):
+
 	/*
 	static int (*real_spnav_x11_event)(const XEvent*, spnav_event*) = NULL;
 	if (!real_spnav_x11_event) real_spnav_x11_event = dlsym(RTLD_NEXT, "spnav_x11_event");
@@ -218,13 +182,6 @@
 }
  */
 
-
-/*
-int spnav_open() {
-	return -1;
-}
- */
-
 /*
 int spnav_open() {
 	static int (*real_spnav_open)() = NULL;