--- a/src/SpacenavReceiver.h Thu Mar 07 17:56:38 2019 +0100
+++ b/src/SpacenavReceiver.h Thu Mar 07 18:33:22 2019 +0100
@@ -24,6 +24,7 @@
Q_DECLARE_METATYPE(SpacenavWrapper::Event::MotionEvent)
Q_DECLARE_METATYPE(SpacenavWrapper::Event::ButtonEvent)
+Q_DECLARE_METATYPE(SpacenavWrapper::ConnectionStatus)
class SpacenavReceiver : public QThread {
Q_OBJECT
@@ -36,6 +37,7 @@
}
void run() {
+ emit spacenavConnectionStatus(spnav.getConnectionStatus());
while (true) {
SpacenavWrapper::Event e = spnav.waitEvent();
if (e.type == SpacenavWrapper::Event::Type::MOTION) emit spacenavMotionEvent(e.motion);
@@ -46,4 +48,5 @@
signals:
void spacenavMotionEvent(SpacenavWrapper::Event::MotionEvent e);
void spacenavButtonEvent(SpacenavWrapper::Event::ButtonEvent e);
+ void spacenavConnectionStatus(SpacenavWrapper::ConnectionStatus s);
};
\ No newline at end of file
--- a/src/SpacenavWindow.cpp Thu Mar 07 17:56:38 2019 +0100
+++ b/src/SpacenavWindow.cpp Thu Mar 07 18:33:22 2019 +0100
@@ -65,3 +65,9 @@
if (e.number == 0) widget.button0->setChecked(e.pressed);
if (e.number == 1) widget.button1->setChecked(e.pressed);
}
+
+void SpacenavWindow::spacenavConnectionStatus(SpacenavWrapper::ConnectionStatus s) {
+ if (s == SpacenavWrapper::ConnectionStatus::DOMAIN_SOCKET) widget.connection->setText("connected through: domain socket");
+ if (s == SpacenavWrapper::ConnectionStatus::X11) widget.connection->setText("connected through: X11");
+}
+
--- a/src/SpacenavWindow.h Thu Mar 07 17:56:38 2019 +0100
+++ b/src/SpacenavWindow.h Thu Mar 07 18:33:22 2019 +0100
@@ -28,6 +28,7 @@
public slots:
void spacenavMotionEvent(SpacenavWrapper::Event::MotionEvent e);
void spacenavButtonEvent(SpacenavWrapper::Event::ButtonEvent e);
+ void spacenavConnectionStatus(SpacenavWrapper::ConnectionStatus s);
private:
Ui::SpacenavWindow widget;
};
--- a/src/SpacenavWindow.ui Thu Mar 07 17:56:38 2019 +0100
+++ b/src/SpacenavWindow.ui Thu Mar 07 18:33:22 2019 +0100
@@ -165,6 +165,23 @@
</property>
</widget>
</item>
+ <item row="16" column="0">
+ <widget class="QLabel" name="connectionLabel">
+ <property name="text">
+ <string>status</string>
+ </property>
+ </widget>
+ </item>
+ <item row="16" column="1">
+ <widget class="QLineEdit" name="connection">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="text">
+ <string>not connected</string>
+ </property>
+ </widget>
+ </item>
</layout>
</widget>
<widget class="QMenuBar" name="menubar">
--- a/src/SpacenavWrapper.cpp Thu Mar 07 17:56:38 2019 +0100
+++ b/src/SpacenavWrapper.cpp Thu Mar 07 18:33:22 2019 +0100
@@ -20,31 +20,27 @@
#include "SpacenavWrapper.h"
SpacenavWrapper::SpacenavWrapper() {
- // TODO: remove logging
if (spnav_open() == 0) {
- std::wcout << L"connected through: AF_UNIX socket" << std::endl;
+ connectionStatus = SpacenavWrapper::ConnectionStatus::DOMAIN_SOCKET;
+ return;
} else {
-
Display* display;
Window window;
unsigned long blackPixel;
+ if (display = XOpenDisplay(0)) {
- if (!(display = XOpenDisplay(0))) {
- std::wcout << L"unable to connect to the X server" << std::endl;
- return; // TODO: throw exception
- }
+ blackPixel = BlackPixel(display, DefaultScreen(display));
+ window = XCreateSimpleWindow(display, DefaultRootWindow(display), 0, 0, 1, 1, 0, blackPixel, blackPixel);
- 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
+ if (spnav_x11_open(display, window) == 0) {
+ connectionStatus = SpacenavWrapper::ConnectionStatus::X11;
+ return;
+ }
}
}
+
+ connectionStatus = SpacenavWrapper::ConnectionStatus::NONE;
}
SpacenavWrapper::~SpacenavWrapper() {
@@ -53,6 +49,10 @@
spnav_close();
}
+SpacenavWrapper::ConnectionStatus SpacenavWrapper::getConnectionStatus() {
+ return connectionStatus;
+}
+
SpacenavWrapper::Event SpacenavWrapper::waitEvent() {
SpacenavWrapper::Event e;
spnav_event event;
--- a/src/SpacenavWrapper.h Thu Mar 07 17:56:38 2019 +0100
+++ b/src/SpacenavWrapper.h Thu Mar 07 18:33:22 2019 +0100
@@ -60,11 +60,19 @@
};
+ enum class ConnectionStatus {
+ NONE,
+ DOMAIN_SOCKET,
+ X11
+ };
+
SpacenavWrapper();
virtual ~SpacenavWrapper();
+ ConnectionStatus getConnectionStatus();
Event waitEvent();
-
+private:
+ ConnectionStatus connectionStatus;
};
\ No newline at end of file
--- a/src/spacenav-demo-qt.cpp Thu Mar 07 17:56:38 2019 +0100
+++ b/src/spacenav-demo-qt.cpp Thu Mar 07 18:33:22 2019 +0100
@@ -34,6 +34,7 @@
QObject::connect(&t, &SpacenavReceiver::spacenavMotionEvent, &w, &SpacenavWindow::spacenavMotionEvent, Qt::ConnectionType::QueuedConnection);
QObject::connect(&t, &SpacenavReceiver::spacenavButtonEvent, &w, &SpacenavWindow::spacenavButtonEvent, Qt::ConnectionType::QueuedConnection);
+ QObject::connect(&t, &SpacenavReceiver::spacenavConnectionStatus, &w, &SpacenavWindow::spacenavConnectionStatus, Qt::ConnectionType::QueuedConnection);
t.start();
int qtResultCode = app.exec();