From e98780109670c48667a122b74e2f10bda46c8d15 Mon Sep 17 00:00:00 2001 From: Torsten Sadowski Date: Tue, 6 Nov 2018 20:55:33 +0100 Subject: [PATCH] Fixed compilation of 3Dconnexion/libspacenav wit Qt4 --- src/Gui/3Dconnexion/GuiNativeEventCommon.h | 1 + src/Gui/3Dconnexion/GuiNativeEventLinux.cpp | 4 +- src/Gui/3Dconnexion/GuiNativeEventLinux.h | 3 +- .../3Dconnexion/GuiNativeEventLinuxX11.cpp | 47 +++++++++++-------- src/Gui/3Dconnexion/GuiNativeEventLinuxX11.h | 2 +- src/Gui/3Dconnexion/GuiNativeEventMac.cpp | 2 + src/Gui/3Dconnexion/GuiNativeEventWin32.cpp | 1 + src/Gui/CMakeLists.txt | 14 ++++++ src/Gui/GuiApplicationNativeEventAware.cpp | 14 ++++++ src/Gui/GuiApplicationNativeEventAware.h | 19 ++------ 10 files changed, 69 insertions(+), 38 deletions(-) diff --git a/src/Gui/3Dconnexion/GuiNativeEventCommon.h b/src/Gui/3Dconnexion/GuiNativeEventCommon.h index 97a8542526..fb17f65e0b 100644 --- a/src/Gui/3Dconnexion/GuiNativeEventCommon.h +++ b/src/Gui/3Dconnexion/GuiNativeEventCommon.h @@ -1,3 +1,4 @@ + Q_OBJECT public: GuiNativeEvent(GUIApplicationNativeEventAware *app); ~GuiNativeEvent(); diff --git a/src/Gui/3Dconnexion/GuiNativeEventLinux.cpp b/src/Gui/3Dconnexion/GuiNativeEventLinux.cpp index c136b5509d..4099928285 100644 --- a/src/Gui/3Dconnexion/GuiNativeEventLinux.cpp +++ b/src/Gui/3Dconnexion/GuiNativeEventLinux.cpp @@ -37,7 +37,7 @@ void Gui::GuiNativeEvent::initSpaceball(QMainWindow *window) } else { Base::Console().Log("Connected to spacenav daemon\n"); QSocketNotifier* SpacenavNotifier = new QSocketNotifier(spnav_fd(), QSocketNotifier::Read, this); - connect(SpacenavNotifier, &QSocketNotifier::activated, this, &GuiNativeEvent::pollSpacenav); + connect(SpacenavNotifier, SIGNAL(activated(int)), this, SLOT(pollSpacenav())); mainApp->setSpaceballPresent(true); } } @@ -68,3 +68,5 @@ void Gui::GuiNativeEvent::pollSpacenav() } } } + +#include "3Dconnexion/moc_GuiNativeEventLinux.cpp" diff --git a/src/Gui/3Dconnexion/GuiNativeEventLinux.h b/src/Gui/3Dconnexion/GuiNativeEventLinux.h index df4a5abb9f..ad5161f9bf 100644 --- a/src/Gui/3Dconnexion/GuiNativeEventLinux.h +++ b/src/Gui/3Dconnexion/GuiNativeEventLinux.h @@ -4,7 +4,6 @@ #include class QMainWindow; -class GUIApplicationNativeEventAware; namespace Gui { @@ -13,7 +12,7 @@ namespace Gui class GuiNativeEvent : public QObject { #include "GuiNativeEventCommon.h" - private: + private slots: void pollSpacenav(); }; } diff --git a/src/Gui/3Dconnexion/GuiNativeEventLinuxX11.cpp b/src/Gui/3Dconnexion/GuiNativeEventLinuxX11.cpp index c714eaf03f..2a38e75252 100644 --- a/src/Gui/3Dconnexion/GuiNativeEventLinuxX11.cpp +++ b/src/Gui/3Dconnexion/GuiNativeEventLinuxX11.cpp @@ -2,19 +2,19 @@ Implementation by Torsten Sadowski 2018 */ +#include "SpaceballEvent.h" +#include + #include "GuiNativeEventLinuxX11.h" #include "GuiApplicationNativeEventAware.h" -#include "SpaceballEvent.h" #include #include -#include #include #include #if QT_VERSION >= 0x050000 - #include #include "GuiRawInputEventFilter.h" #undef Bool #undef CursorShape @@ -57,26 +57,33 @@ void Gui::GuiNativeEvent::initSpaceball(QMainWindow *window) mainApp->setSpaceballPresent(true); #if QT_VERSION >= 0x050000 - static auto evFilter( [](void *msg, long *result){ - Q_UNUSED(result); - auto inst(dynamic_cast(QApplication::instance())); - if (inst) { - return inst->nativeEvent->xcbEventFilter(static_cast(msg)); - } else { - return false; - } - } ); - mainApp->installNativeEventFilter(new Gui::RawInputEventFilter(evFilter)); + //static auto evFilter( [](void *msg, long *result){ + // Q_UNUSED(result); + // auto inst(dynamic_cast(QApplication::instance())); + // if (inst) { + // return inst->nativeEvent->xcbEventFilter(static_cast(msg)); + // } else { + // return false; + // } + // } ); + //mainApp->installNativeEventFilter(new Gui::RawInputEventFilter(evFilter)); + mainApp->installNativeEventFilter(new Gui::RawInputEventFilter(&xcbEventFilter)); #endif // #if QT_VERSION >= 0x050000 } } #if QT_VERSION >= 0x050000 -bool Gui::GuiNativeEvent::xcbEventFilter(const xcb_client_message_event_t *xcb_ev) +bool Gui::GuiNativeEvent::xcbEventFilter(void *xcb_void, long* result) { - spnav_event navEvent; + Q_UNUSED(result); + auto inst(dynamic_cast(QApplication::instance())); + if (!inst) + return false; + spnav_event navEvent; + + const xcb_client_message_event_t* xcb_ev = static_cast(xcb_void); // Qt4 used XEvents in native event filters, but Qt5 changed to XCB. The // SpaceNavigator API only works with XEvent, so we need to construct a // temporary XEvent with just enough information for spnav_x11_event() @@ -110,7 +117,7 @@ bool Gui::GuiNativeEvent::xcbEventFilter(const xcb_client_message_event_t *xcb_e motionDataArray[4] = -navEvent.motion.rz; motionDataArray[5] = -navEvent.motion.ry; - mainApp->postMotionEvent(&motionDataArray[0]); + inst->postMotionEvent(&motionDataArray[0]); return true; } @@ -123,7 +130,7 @@ bool Gui::GuiNativeEvent::xcbEventFilter(const xcb_client_message_event_t *xcb_e } else { buttonEvent->setButtonStatus(Spaceball::BUTTON_RELEASED); } - mainApp->postButtonEvent(navEvent.button.bnum, navEvent.button.press); + inst->postButtonEvent(navEvent.button.bnum, navEvent.button.press); return true; } default: @@ -156,7 +163,7 @@ bool Gui::GuiNativeEvent::x11EventFilter(XEvent *event) nMotionEvents--; if (nMotionEvents == 0) { - mainApp->postMotionEvent(&motionDataArray); + mainApp->postMotionEvent(&motionDataArray[0]); } return true; @@ -236,7 +243,7 @@ bool Gui::GuiNativeEvent::x11EventFilter(XEvent *event) if (navEvent.type == SPNAV_EVENT_BUTTON) { - this->postButtonEvent(navEvent.button.bnum, navEvent.button.press); + mainApp->postButtonEvent(navEvent.button.bnum, navEvent.button.press); return true; } @@ -244,3 +251,5 @@ bool Gui::GuiNativeEvent::x11EventFilter(XEvent *event) return true; } #endif // if/else QT_VERSION >= 0x050000 + +#include "3Dconnexion/moc_GuiNativeEventLinuxX11.cpp" diff --git a/src/Gui/3Dconnexion/GuiNativeEventLinuxX11.h b/src/Gui/3Dconnexion/GuiNativeEventLinuxX11.h index 17bd177217..f6871aad63 100644 --- a/src/Gui/3Dconnexion/GuiNativeEventLinuxX11.h +++ b/src/Gui/3Dconnexion/GuiNativeEventLinuxX11.h @@ -21,7 +21,7 @@ namespace Gui #include "GuiNativeEventCommon.h" public: #if QT_VERSION >= 0x050000 - bool xcbEventFilter(const xcb_client_message_event_t *message); + static bool xcbEventFilter(void *message, long* result); #else bool x11EventFilter(XEvent *event); #endif // if/else QT_VERSION >= 0x050000 diff --git a/src/Gui/3Dconnexion/GuiNativeEventMac.cpp b/src/Gui/3Dconnexion/GuiNativeEventMac.cpp index e72397554c..fd27ecd35e 100644 --- a/src/Gui/3Dconnexion/GuiNativeEventMac.cpp +++ b/src/Gui/3Dconnexion/GuiNativeEventMac.cpp @@ -155,3 +155,5 @@ void Gui::GuiNativeEvent::initSpaceball(QMainWindow *window) Base::Console().Log("3Dconnexion driver initialized. Client ID: %d\n", tdxClientID); mainApp->setSpaceballPresent(true); } + +#include "3Dconnexion/moc_GuiNativeEventMac.cpp" diff --git a/src/Gui/3Dconnexion/GuiNativeEventWin32.cpp b/src/Gui/3Dconnexion/GuiNativeEventWin32.cpp index 94f9198770..468829cb16 100644 --- a/src/Gui/3Dconnexion/GuiNativeEventWin32.cpp +++ b/src/Gui/3Dconnexion/GuiNativeEventWin32.cpp @@ -949,3 +949,4 @@ Error: return processed; } +#include "3Dconnexion/moc_GuiNativeEventWin32.cpp" diff --git a/src/Gui/CMakeLists.txt b/src/Gui/CMakeLists.txt index 8286a47d18..58b1337b4e 100644 --- a/src/Gui/CMakeLists.txt +++ b/src/Gui/CMakeLists.txt @@ -122,9 +122,15 @@ IF(SPNAV_FOUND) SET(FreeCADGui_SDK_SRCS 3Dconnexion/GuiNativeEventLinuxX11.cpp ) + SET(FreeCADGui_SDK_MOC_HDRS + 3Dconnexion/GuiNativeEventLinuxX11.h + ) else(SPNAV_USE_X11) SET(FreeCADGui_SDK_SRCS 3Dconnexion/GuiNativeEventLinux.cpp + ) + SET(FreeCADGui_SDK_MOC_HDRS + 3Dconnexion/GuiNativeEventLinux.h ) endif(SPNAV_USE_X11) SOURCE_GROUP("3D connexion SDK" FILES ${FreeCADGui_SDK_SRCS}) @@ -210,6 +216,9 @@ SET(FreeCADGui_SDK_SRCS 3Dconnexion/GuiNativeEventWin32.cpp ) SOURCE_GROUP("3D connexion SDK" FILES ${FreeCADGui_SDK_SRCS}) +SET(FreeCADGui_SDK_MOC_HDRS + 3Dconnexion/GuiNativeEventWin32.h +) endif(FREECAD_USE_3DCONNEXION AND MSVC) if(FREECAD_USE_3DCONNEXION AND APPLE) @@ -217,6 +226,9 @@ SET(FreeCADGui_SDK_SRCS 3Dconnexion/GuiNativeEventMac.cpp ) SOURCE_GROUP("3D connexion SDK" FILES ${FreeCADGui_SDK_SRCS}) +SET(FreeCADGui_SDK_MOC_HDRS + 3Dconnexion/GuiNativeEventMac.h +) endif(FREECAD_USE_3DCONNEXION AND APPLE) set(Gui_MOC_HDRS @@ -327,6 +339,7 @@ set(Gui_MOC_HDRS TaskView/TaskView.h DAGView/DAGView.h DAGView/DAGModel.h + ${FreeCADGui_SDK_MOC_HDRS} ) fc_wrap_cpp(Gui_MOC_SRCS ${Gui_MOC_HDRS}) @@ -1171,6 +1184,7 @@ SET(FreeCADGui_SRCS ManualAlignment.h TransactionObject.h WinNativeGestureRecognizers.h + ${FreeCADGui_SDK_MOC_HDRS} ) SET(FreeCADGui_SRCS diff --git a/src/Gui/GuiApplicationNativeEventAware.cpp b/src/Gui/GuiApplicationNativeEventAware.cpp index a03ae7793c..35acc17255 100644 --- a/src/Gui/GuiApplicationNativeEventAware.cpp +++ b/src/Gui/GuiApplicationNativeEventAware.cpp @@ -31,6 +31,20 @@ #include "SpaceballEvent.h" #include "Application.h" +#if defined(_USE_3DCONNEXION_SDK) || defined(SPNAV_FOUND) +#if defined(Q_OS_LINUX) + #if defined(SPNAV_USE_X11) + #include "3Dconnexion/GuiNativeEventLinuxX11.h" + #else + #include "3Dconnexion/GuiNativeEventLinux.h" + #endif +#elif defined(Q_OS_WIN) + #include "3Dconnexion/GuiNativeEventWin32.h" +#elif defined(Q_OS_MACX) + #include "3Dconnexion/GuiNativeEventMac.h" +#endif // Platform switch +#endif // Spacemice + Gui::GUIApplicationNativeEventAware::GUIApplicationNativeEventAware(int &argc, char *argv[]) : QApplication (argc, argv) { diff --git a/src/Gui/GuiApplicationNativeEventAware.h b/src/Gui/GuiApplicationNativeEventAware.h index 365ad8e447..d79b18debf 100644 --- a/src/Gui/GuiApplicationNativeEventAware.h +++ b/src/Gui/GuiApplicationNativeEventAware.h @@ -29,22 +29,11 @@ class QMainWindow; -#if defined(_USE_3DCONNEXION_SDK) || defined(SPNAV_FOUND) -#if defined(Q_OS_LINUX) - #if defined(SPNAV_USE_X11) - #include "3Dconnexion/GuiNativeEventLinuxX11.h" - #else - #include "3Dconnexion/GuiNativeEventLinux.h" - #endif -#elif defined(Q_OS_WIN) - #include "3Dconnexion/GuiNativeEventWin32.h" -#elif defined(Q_OS_MACX) - #include "3Dconnexion/GuiNativeEventMac.h" -#endif // Platform switch -#endif // Spacemice - namespace Gui { +#if defined(_USE_3DCONNEXION_SDK) || defined(SPNAV_FOUND) + class GuiNativeEvent; +#endif // Spacemice class GUIApplicationNativeEventAware : public QApplication { Q_OBJECT @@ -63,7 +52,7 @@ namespace Gui float convertPrefToSensitivity(int value); #if defined(_USE_3DCONNEXION_SDK) || defined(SPNAV_FOUND) GuiNativeEvent *nativeEvent; - friend void GuiNativeEvent::initSpaceball(QMainWindow *window); +// friend void GuiNativeEvent::initSpaceball(QMainWindow *window); #endif }; // end class GUIApplicationNativeEventAware } // end namespace Gui