diff --git a/src/applaunchhelper.cpp b/src/applaunchhelper.cpp index ececb08d..e4e1b6d5 100644 --- a/src/applaunchhelper.cpp +++ b/src/applaunchhelper.cpp @@ -163,3 +163,13 @@ void AppLaunchHelper::appQuitPointerPrecision() } #endif + +void AppLaunchHelper::revertMouseThread() +{ + JoyButton::indirectStaticMouseThread(QThread::currentThread()); +} + +void AppLaunchHelper::changeMouseThread(QThread *thread) +{ + JoyButton::setStaticMouseThread(thread); +} diff --git a/src/applaunchhelper.h b/src/applaunchhelper.h index a1ebe732..8425310d 100644 --- a/src/applaunchhelper.h +++ b/src/applaunchhelper.h @@ -20,6 +20,7 @@ #include #include +#include #include "inputdevice.h" #include "joybutton.h" @@ -54,6 +55,9 @@ public slots: void appQuitPointerPrecision(); #endif + void revertMouseThread(); + void changeMouseThread(QThread *thread); + }; #endif // APPLAUNCHHELPER_H diff --git a/src/inputdaemon.cpp b/src/inputdaemon.cpp index cd7fe96e..b47cae00 100644 --- a/src/inputdaemon.cpp +++ b/src/inputdaemon.cpp @@ -398,6 +398,8 @@ void InputDaemon::removeDevice(InputDevice *device) refreshIndexes(); emit deviceRemoved(static_cast(deviceID)); + + device->closeSDLDevice(); device->deleteLater(); } } @@ -1045,3 +1047,9 @@ void InputDaemon::updatePollResetRate(unsigned int tempPollRate) pollResetTimer.start(); } } + +/*void InputDaemon::changeMouseThread(QThread *thread) +{ + JoyButton::indirectStaticMouseThread(thread); +} +*/ diff --git a/src/inputdaemon.h b/src/inputdaemon.h index 011c52e8..bcda9700 100644 --- a/src/inputdaemon.h +++ b/src/inputdaemon.h @@ -102,6 +102,7 @@ public slots: void refreshJoysticks(); void deleteJoysticks(); void startWorker(); + //void changeMouseThread(QThread *thread); #ifdef USE_SDL_2 void refreshMapping(QString mapping, InputDevice *device); diff --git a/src/joybutton.cpp b/src/joybutton.cpp index 853d23e8..9229f163 100644 --- a/src/joybutton.cpp +++ b/src/joybutton.cpp @@ -16,6 +16,7 @@ */ //#include +#include #include #include @@ -5568,6 +5569,12 @@ void JoyButton::setStaticMouseThread(QThread *thread) lastMouseTime.start(); } +void JoyButton::indirectStaticMouseThread(QThread *thread) +{ + QMetaObject::invokeMethod(&mouseHelper, "changeThread", + Q_ARG(QThread*, thread)); +} + bool JoyButton::shouldInvokeMouseEvents() { bool result = false; diff --git a/src/joybutton.h b/src/joybutton.h index 4e6bb757..7559144a 100644 --- a/src/joybutton.h +++ b/src/joybutton.h @@ -216,6 +216,7 @@ public: static void restartLastMouseTime(); static void setStaticMouseThread(QThread *thread); + static void indirectStaticMouseThread(QThread *thread); static bool shouldInvokeMouseEvents(); static void invokeMouseEvents(); diff --git a/src/joybuttonmousehelper.cpp b/src/joybuttonmousehelper.cpp index 3d15969f..44d996da 100644 --- a/src/joybuttonmousehelper.cpp +++ b/src/joybuttonmousehelper.cpp @@ -114,3 +114,8 @@ void JoyButtonMouseHelper::carryMouseRefreshRateUpdate(unsigned int refreshRate) { emit mouseRefreshRateUpdated(refreshRate); } + +void JoyButtonMouseHelper::changeThread(QThread *thread) +{ + JoyButton::setStaticMouseThread(thread); +} diff --git a/src/joybuttonmousehelper.h b/src/joybuttonmousehelper.h index 463c82a3..40cbeac0 100644 --- a/src/joybuttonmousehelper.h +++ b/src/joybuttonmousehelper.h @@ -19,6 +19,7 @@ #define JOYBUTTONMOUSEHELPER_H #include +#include class JoyButtonMouseHelper : public QObject { @@ -44,6 +45,7 @@ public slots: void moveMouseCursor(); void moveSpringMouse(); void mouseEvent(); + void changeThread(QThread *thread); }; #endif // JOYBUTTONMOUSEHELPER_H diff --git a/src/main.cpp b/src/main.cpp index 78c60f78..8af02030 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -682,6 +682,7 @@ int main(int argc, char *argv[]) QObject::connect(a, SIGNAL(aboutToQuit()), localServer, SLOT(close())); QObject::connect(a, SIGNAL(aboutToQuit()), w, SLOT(saveAppConfig())); QObject::connect(a, SIGNAL(aboutToQuit()), w, SLOT(removeJoyTabs())); + QObject::connect(a, SIGNAL(aboutToQuit()), &mainAppHelper, SLOT(revertMouseThread())); QObject::connect(a, SIGNAL(aboutToQuit()), joypad_worker, SLOT(quit())); QObject::connect(a, SIGNAL(aboutToQuit()), joypad_worker, SLOT(deleteJoysticks())); QObject::connect(a, SIGNAL(aboutToQuit()), joypad_worker, SLOT(deleteLater()), Qt::BlockingQueuedConnection); @@ -716,8 +717,10 @@ int main(int argc, char *argv[]) QThread::currentThread()->setPriority(QThread::HighPriority); #endif - JoyButton::setStaticMouseThread(inputEventThread); + //JoyButton::setStaticMouseThread(inputEventThread); + mainAppHelper.changeMouseThread(inputEventThread); + QTimer::singleShot(20, w, SLOT(fillButtons())); QTimer::singleShot(20, w, SLOT(changeWindowStatus())); int app_result = a->exec(); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index b74d7a35..96221aba 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -138,7 +138,7 @@ MainWindow::MainWindow(QMap *joysticks, setEnabled(false); } - fillButtons(joysticks); + //fillButtons(joysticks); if (cmdutility->hasProfile()) { if (cmdutility->hasControllerNumber()) diff --git a/src/sdleventreader.cpp b/src/sdleventreader.cpp index ebc3d232..b7117c68 100644 --- a/src/sdleventreader.cpp +++ b/src/sdleventreader.cpp @@ -99,16 +99,7 @@ void SDLEventReader::closeSDL() SDL_Event event; - if (joysticks) - { - QMapIterator iter(*joysticks); - while (iter.hasNext()) - { - iter.next(); - InputDevice *current = iter.value(); - current->closeSDLDevice(); - } - } + closeDevices(); // Clear any pending events while (SDL_PollEvent(&event) > 0) @@ -276,3 +267,20 @@ void SDLEventReader::quit() joysticks = 0; } } + +void SDLEventReader::closeDevices() +{ + if (sdlIsOpen) + { + if (joysticks) + { + QMapIterator iter(*joysticks); + while (iter.hasNext()) + { + iter.next(); + InputDevice *current = iter.value(); + current->closeSDLDevice(); + } + } + } +} diff --git a/src/sdleventreader.h b/src/sdleventreader.h index f98c2787..77c7eaff 100644 --- a/src/sdleventreader.h +++ b/src/sdleventreader.h @@ -68,6 +68,7 @@ public slots: void updatePollRate(unsigned int tempPollRate); void resetJoystickMap(); void quit(); + void closeDevices(); private slots: void secondaryRefresh();