37 std::wcout << L"calling spnav_close() in ~SpacenavReceiver()" << std::endl; |
37 std::wcout << L"calling spnav_close() in ~SpacenavReceiver()" << std::endl; |
38 spnav_close(); |
38 spnav_close(); |
39 } |
39 } |
40 |
40 |
41 void run() { |
41 void run() { |
42 Display* display; |
|
43 Window window; |
|
44 unsigned long blackPixel; |
|
45 |
|
46 spnav_event event; |
42 spnav_event event; |
47 |
43 |
48 if (!(display = XOpenDisplay(0))) { |
44 // Connect |
49 std::wcout << L"unable to connect to the X server" << std::endl; |
45 if (spnav_open() == 0) { |
50 return; // TODO: throw exception |
46 std::wcout << L"connected through: AF_UNIX socket" << std::endl; |
51 } |
47 } else { |
52 |
48 |
53 blackPixel = BlackPixel(display, DefaultScreen(display)); |
49 Display* display; |
54 window = XCreateSimpleWindow(display, DefaultRootWindow(display), 0, 0, 1, 1, 0, blackPixel, blackPixel); |
50 Window window; |
|
51 unsigned long blackPixel; |
55 |
52 |
56 if (spnav_x11_open(display, window) == -1) { |
|
57 std::wcout << L"unable to connect to the space navigator daemon" << std::endl; |
|
58 return; // TODO: throw exception |
|
59 |
53 |
60 /** |
54 if (!(display = XOpenDisplay(0))) { |
61 * TODO: try also unix socket |
55 std::wcout << L"unable to connect to the X server" << std::endl; |
62 * |
56 return; // TODO: throw exception |
63 * if(spnav_open()==-1) { |
57 } |
64 * fprintf(stderr, "failed to connect to the space navigator daemon\n"); |
58 |
65 * return 1; |
59 blackPixel = BlackPixel(display, DefaultScreen(display)); |
66 * } |
60 window = XCreateSimpleWindow(display, DefaultRootWindow(display), 0, 0, 1, 1, 0, blackPixel, blackPixel); |
67 */ |
61 |
|
62 if (spnav_x11_open(display, window) == 0) { |
|
63 std::wcout << L"connected through: X11" << std::endl; |
|
64 } else { |
|
65 std::wcout << L"unable to connect to the space navigator daemon" << std::endl; |
|
66 return; // TODO: throw exception |
|
67 } |
68 } |
68 } |
69 |
69 |
70 // For stopping this thread by pressing both buttons: |
70 // For stopping this thread by pressing both buttons: |
71 bool pressed0 = false; |
71 bool pressed0 = false; |
72 bool pressed1 = false; |
72 bool pressed1 = false; |
73 |
73 |
|
74 // Process events |
74 while (spnav_wait_event(&event)) { |
75 while (spnav_wait_event(&event)) { |
75 if (event.type == SPNAV_EVENT_MOTION) { |
76 if (event.type == SPNAV_EVENT_MOTION) { |
76 std::wcout << L"motion event: t(" << event.motion.x << L", " << event.motion.y << L", " << event.motion.z << L") "; |
77 std::wcout << L"motion event: t(" << event.motion.x << L", " << event.motion.y << L", " << event.motion.z << L") "; |
77 std::wcout << L"r(" << event.motion.rx << L", " << event.motion.ry << L", " << event.motion.rz << L")" << std::endl; |
78 std::wcout << L"r(" << event.motion.rx << L", " << event.motion.ry << L", " << event.motion.rz << L")" << std::endl; |
78 |
79 |