# HG changeset patch # User František Kučera # Date 1551910750 -3600 # Node ID 6baa91ac319918d790c52b32be76b160831623fa # Parent 21b0b2b0547e0e8485390c36f1fe4db77a63042f support both: AF_UNIX and X11 connections diff -r 21b0b2b0547e -r 6baa91ac3199 src/SpacenavReceiver.h --- a/src/SpacenavReceiver.h Wed Mar 06 21:08:34 2019 +0100 +++ b/src/SpacenavReceiver.h Wed Mar 06 23:19:10 2019 +0100 @@ -39,38 +39,39 @@ } void run() { - Display* display; - Window window; - unsigned long blackPixel; - spnav_event event; - if (!(display = XOpenDisplay(0))) { - std::wcout << L"unable to connect to the X server" << std::endl; - return; // TODO: throw exception - } + // Connect + if (spnav_open() == 0) { + std::wcout << L"connected through: AF_UNIX socket" << std::endl; + } else { - blackPixel = BlackPixel(display, DefaultScreen(display)); - window = XCreateSimpleWindow(display, DefaultRootWindow(display), 0, 0, 1, 1, 0, blackPixel, blackPixel); + Display* display; + Window window; + unsigned long blackPixel; + - if (spnav_x11_open(display, window) == -1) { - std::wcout << L"unable to connect to the space navigator daemon" << std::endl; - return; // TODO: throw exception + if (!(display = XOpenDisplay(0))) { + std::wcout << L"unable to connect to the X server" << std::endl; + return; // TODO: throw exception + } - /** - * TODO: try also unix socket - * - * if(spnav_open()==-1) { - * fprintf(stderr, "failed to connect to the space navigator daemon\n"); - * return 1; - * } - */ + blackPixel = BlackPixel(display, DefaultScreen(display)); + window = XCreateSimpleWindow(display, DefaultRootWindow(display), 0, 0, 1, 1, 0, blackPixel, blackPixel); + + if (spnav_x11_open(display, window) == 0) { + std::wcout << L"connected through: X11" << std::endl; + } else { + std::wcout << L"unable to connect to the space navigator daemon" << std::endl; + return; // TODO: throw exception + } } // For stopping this thread by pressing both buttons: bool pressed0 = false; bool pressed1 = false; + // Process events while (spnav_wait_event(&event)) { if (event.type == SPNAV_EVENT_MOTION) { std::wcout << L"motion event: t(" << event.motion.x << L", " << event.motion.y << L", " << event.motion.z << L") ";