equal
deleted
inserted
replaced
24 #include <unistd.h> |
24 #include <unistd.h> |
25 |
25 |
26 #include <X11/Xlib.h> |
26 #include <X11/Xlib.h> |
27 #include <spnav.h> |
27 #include <spnav.h> |
28 |
28 |
|
29 /** |
|
30 * The purpose of this hack is to enable 3D mouse in applications that use X11 protocol |
|
31 * while our daemon is providing only domain socket and no X11. |
|
32 * |
|
33 * Usage: |
|
34 * LD_PRELOAD=./spacenav-lib-hack/build/Debug/src/libspnav-lib-hack.so freecad |
|
35 * |
|
36 * This hack: |
|
37 * 1) Pretends that spnav_x11_open() was successful. |
|
38 * 2) Starts a background process (TODO: also terminate it) which reads from the domain socket |
|
39 * and translates spacenav events to X11 events and sends them to the application window. |
|
40 * 3) reimplements spnav_x11_event() which is needed, because Atom variables in original library |
|
41 * were not initialized spnav_x11_open() and thus the library funcion is not working. |
|
42 * |
|
43 * This solution works and allows using e.g. FreeCAD with domain socket instead of X11, but: |
|
44 * - the background process never ends and must be terminated by: killall freecad |
|
45 * - is very hackish and should be reimplemented as a separate process which will work partly |
|
46 * as a libspnav client and partly emulate spacenavd daemon and will bridge the domain socket |
|
47 * and th X11. Other solution is to emulate the hardware and keep spacenavd and libspnav untouched. |
|
48 */ |
|
49 |
29 // from proto_x11.c (spacenavd) |
50 // from proto_x11.c (spacenavd) |
30 static Atom xa_event_motion, xa_event_bpress, xa_event_brelease, xa_event_cmd; |
51 static Atom xa_event_motion, xa_event_bpress, xa_event_brelease, xa_event_cmd; |
31 static float x11_sens = 1.0; |
52 static float x11_sens = 1.0; |
32 |
53 |
33 /** |
54 /** |
73 |
94 |
74 default: |
95 default: |
75 break; |
96 break; |
76 } |
97 } |
77 |
98 |
78 Window xxx; |
99 XSendEvent(dpy, win, False, 0, &xevent); |
79 int zzz; |
100 XFlush(dpy); |
80 int yyy = XGetInputFocus(dpy, &xxx, &zzz); |
|
81 fprintf(stderr, "spnav-lib-hack: XGetInputFocus(%p, %lx, %d) = %d\n", dpy, xxx, zzz, yyy); |
|
82 Status result = XSendEvent(dpy, win, False, 0, &xevent); |
|
83 int xflushResult = XFlush(dpy); |
|
84 fprintf(stderr, "spnav-lib-hack: send_xevent(); XSendEvent() = %d; XFlush() = %d\n", result, xflushResult); |
|
85 } |
101 } |
86 |
102 |
87 static void spacenav_hack_translate_events(Window win) { |
103 static void spacenav_hack_translate_events(Window win) { |
88 spnav_event event; |
104 spnav_event event; |
89 Display* dpy = XOpenDisplay(0); |
105 Display* dpy = XOpenDisplay(0); |