diff --git a/src/input/InputCEC.cpp b/src/input/InputCEC.cpp index 1a379100a..50e99b43b 100644 --- a/src/input/InputCEC.cpp +++ b/src/input/InputCEC.cpp @@ -67,6 +67,12 @@ bool InputCEC::initInput() return retVal; } +////////////////////////////////////////////////////////////////////////////////////////////////// +void InputCEC::activateSource() +{ + QMetaObject::invokeMethod(m_cecWorker, "activateSource", Qt::QueuedConnection); +} + ///////////////////////////////////////////////////////////////////////////////////////// InputCEC::~InputCEC() { @@ -118,6 +124,9 @@ bool InputCECWorker::init() // check for attached adapters checkAdapter(); + // if necessary, wake device(s) + activateSource(); + // Start a timer to keep track of attached/removed adapters m_timer = new QTimer(nullptr); m_timer->setInterval(10 * 1000); @@ -184,7 +193,7 @@ void InputCECWorker::closeAdapter() void InputCECWorker::checkAdapter() { if (m_adapterPort.isEmpty()) - { + { if (m_adapter) m_adapter->Close(); @@ -192,6 +201,20 @@ void InputCECWorker::checkAdapter() } } +/////////////////////////////////////////////////////////////////////////////////////////////////// +void InputCECWorker::activateSource() +{ + if (!SettingsComponent::Get().value(SETTINGS_SECTION_CEC, "activatesource").toBool()) + { + return; + } + + // Check if a tv has powered on + QLOG_INFO() << "CEC activateSource changing input"; + m_adapter->SetActiveSource(); + +} + /////////////////////////////////////////////////////////////////////////////////////////////////// void InputCECWorker::sendReceivedInput(const QString &source, const QString &keycode, InputBase::InputkeyState keyState) { diff --git a/src/input/InputCEC.h b/src/input/InputCEC.h index 25158db44..ebe395cef 100644 --- a/src/input/InputCEC.h +++ b/src/input/InputCEC.h @@ -17,6 +17,8 @@ class InputCECWorker; /////////////////////////////////////////////////////////////////////////////////////////////////// class InputCEC : public InputBase { + Q_OBJECT + public: explicit InputCEC(QObject* parent); ~InputCEC(); @@ -24,6 +26,8 @@ class InputCEC : public InputBase const char* inputName() override { return CEC_INPUT_NAME; } bool initInput() override; +public slots: + void activateSource(); private: QThread* m_cecThread; @@ -42,6 +46,7 @@ Q_OBJECT Q_SLOT bool init(); Q_SIGNAL void receivedInput(const QString& source, const QString& keycode, InputBase::InputkeyState keyState); Q_SLOT void closeCec(); + Q_SLOT void activateSource(); public slots: void checkAdapter(); diff --git a/src/input/InputComponent.cpp b/src/input/InputComponent.cpp index fc47ec139..53cb0c241 100644 --- a/src/input/InputComponent.cpp +++ b/src/input/InputComponent.cpp @@ -99,7 +99,12 @@ bool InputComponent::componentInitialize() #endif #ifdef HAVE_CEC if (SettingsComponent::Get().value(SETTINGS_SECTION_CEC, "enable").toBool()) - addInput(new InputCEC(this)); + { + InputCEC* cec = new InputCEC(this); + addInput(cec); + connect(&InputKeyboard::Get(), &InputKeyboard::receivedInput, + cec, &InputCEC::activateSource); + } #endif return true;