From 832082c5bcfbe51a479ebae76b22a28ae403d761 Mon Sep 17 00:00:00 2001 From: Roland Winklmeier Date: Fri, 5 Oct 2018 21:50:39 +0200 Subject: [PATCH] Delay creating input devices to when required Every first call to CInputManager::instance() was automatically creating the low level input devices. This was not always desired and therefore creation is now explicit via function. Unit tests do not need the devices created. In contrast, Windows unit tests failed since Windows didn't like the Jenkins service childs to allocate DInput devices. T391 --- src/blackcore/application.cpp | 5 +++++ src/blackcore/inputmanager.cpp | 14 +++++++++----- src/blackcore/inputmanager.h | 3 +++ 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/blackcore/application.cpp b/src/blackcore/application.cpp index 540c00fdb..e3ae331ee 100644 --- a/src/blackcore/application.cpp +++ b/src/blackcore/application.cpp @@ -175,6 +175,11 @@ namespace BlackCore // startup done connect(this, &CApplication::startUpCompleted, this, &CApplication::onStartUpCompleted, Qt::QueuedConnection); connect(this, &CApplication::coreFacadeStarted, this, &CApplication::onCoreFacadeStarted, Qt::QueuedConnection); + + if (!this->getApplicationInfo().isUnitTest()) + { + CInputManager::instance()->createDevices(); + } } } diff --git a/src/blackcore/inputmanager.cpp b/src/blackcore/inputmanager.cpp index 9bcfd3c76..141b829cf 100644 --- a/src/blackcore/inputmanager.cpp +++ b/src/blackcore/inputmanager.cpp @@ -25,12 +25,8 @@ using namespace BlackMisc::Input; namespace BlackCore { CInputManager::CInputManager(QObject *parent) : - QObject(parent), - m_keyboard(IKeyboard::create(this)), - m_joystick(IJoystick::create(this)) + QObject(parent) { - connect(m_keyboard.get(), &IKeyboard::keyCombinationChanged, this, &CInputManager::processKeyCombinationChanged, Qt::QueuedConnection); - connect(m_joystick.get(), &IJoystick::buttonCombinationChanged, this, &CInputManager::processButtonCombinationChanged, Qt::QueuedConnection); reloadHotkeySettings(); } @@ -129,6 +125,14 @@ namespace BlackCore m_lastCombination = combination; } + void CInputManager::createDevices() + { + m_keyboard = IKeyboard::create(this); + m_joystick = IJoystick::create(this); + connect(m_keyboard.get(), &IKeyboard::keyCombinationChanged, this, &CInputManager::processKeyCombinationChanged, Qt::QueuedConnection); + connect(m_joystick.get(), &IJoystick::buttonCombinationChanged, this, &CInputManager::processButtonCombinationChanged, Qt::QueuedConnection); + } + void CInputManager::releaseDevices() { m_keyboard.reset(); diff --git a/src/blackcore/inputmanager.h b/src/blackcore/inputmanager.h index e5a2cd952..f2e06e877 100644 --- a/src/blackcore/inputmanager.h +++ b/src/blackcore/inputmanager.h @@ -87,6 +87,9 @@ namespace BlackCore //! Triggers a key event manually and calls the registered functions. void triggerKey(const BlackMisc::Input::CHotkeyCombination &combination, bool isPressed); + //! Creates low level input devices. Once completed, hotkeys start to be processed. + void createDevices(); + //! Releases all devices void releaseDevices();