diff --git a/xbmc/application/AppInboundProtocol.cpp b/xbmc/application/AppInboundProtocol.cpp index 7a1c80dad8b1f..ce6e7f40dee0f 100644 --- a/xbmc/application/AppInboundProtocol.cpp +++ b/xbmc/application/AppInboundProtocol.cpp @@ -12,15 +12,35 @@ #include "application/Application.h" #include "application/ApplicationComponents.h" #include "application/ApplicationPowerHandling.h" +#include "guilib/GUIComponent.h" +#include "guilib/GUIWindowManager.h" +#include "input/InputManager.h" +#include "input/actions/Action.h" +#include "input/actions/ActionIDs.h" +#include "messaging/ApplicationMessenger.h" +#include "settings/AdvancedSettings.h" +#include "settings/DisplaySettings.h" +#include "settings/Settings.h" +#include "settings/SettingsComponent.h" +#include "threads/SingleLock.h" CAppInboundProtocol::CAppInboundProtocol(CApplication &app) : m_pApp(app) { +} +bool CAppInboundProtocol::OnEvent(const XBMC_Event& newEvent) +{ + std::unique_lock lock(m_portSection); + if (m_closed) + return false; + m_portEvents.push_back(newEvent); + return true; } -bool CAppInboundProtocol::OnEvent(XBMC_Event &event) +void CAppInboundProtocol::Close() { - return m_pApp.OnEvent(event); + std::unique_lock lock(m_portSection); + m_closed = true; } void CAppInboundProtocol::SetRenderGUI(bool renderGUI) @@ -29,3 +49,68 @@ void CAppInboundProtocol::SetRenderGUI(bool renderGUI) const auto appPower = components.GetComponent(); appPower->SetRenderGUI(renderGUI); } + +void CAppInboundProtocol::HandleEvents() +{ + std::unique_lock lock(m_portSection); + while (!m_portEvents.empty()) + { + auto newEvent = m_portEvents.front(); + m_portEvents.pop_front(); + CSingleExit lock(m_portSection); + switch (newEvent.type) + { + case XBMC_QUIT: + if (!m_pApp.m_bStop) + CServiceBroker::GetAppMessenger()->PostMsg(TMSG_QUIT); + break; + case XBMC_VIDEORESIZE: + if (CServiceBroker::GetGUI()->GetWindowManager().Initialized()) + { + if (!CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_fullScreen) + { + CServiceBroker::GetWinSystem()->GetGfxContext().ApplyWindowResize(newEvent.resize.w, + newEvent.resize.h); + + const auto settings = CServiceBroker::GetSettingsComponent()->GetSettings(); + settings->SetInt(CSettings::SETTING_WINDOW_WIDTH, newEvent.resize.w); + settings->SetInt(CSettings::SETTING_WINDOW_HEIGHT, newEvent.resize.h); + settings->Save(); + } + else + { + const auto& res_info = CDisplaySettings::GetInstance().GetResolutionInfo(RES_DESKTOP); + CServiceBroker::GetWinSystem()->ForceFullScreen(res_info); + } + } + break; + case XBMC_VIDEOMOVE: + { + CServiceBroker::GetWinSystem()->OnMove(newEvent.move.x, newEvent.move.y); + } + break; + case XBMC_MODECHANGE: + CServiceBroker::GetWinSystem()->GetGfxContext().ApplyModeChange(newEvent.mode.res); + break; + case XBMC_SCREENCHANGE: + CServiceBroker::GetWinSystem()->OnChangeScreen(newEvent.screen.screenIdx); + break; + case XBMC_USEREVENT: + CServiceBroker::GetAppMessenger()->PostMsg(static_cast(newEvent.user.code)); + break; + case XBMC_SETFOCUS: + { + // Reset the screensaver + const auto appPower = m_pApp.GetComponent(); + appPower->ResetScreenSaver(); + appPower->WakeUpScreenSaverAndDPMS(); + // Send a mouse motion event with no dx,dy for getting the current guiitem selected + m_pApp.OnAction(CAction(ACTION_MOUSE_MOVE, 0, static_cast(newEvent.focus.x), + static_cast(newEvent.focus.y), 0, 0)); + break; + } + default: + CServiceBroker::GetInputManager().OnEvent(newEvent); + } + } +} diff --git a/xbmc/application/AppInboundProtocol.h b/xbmc/application/AppInboundProtocol.h index b0489e5b5d327..5944172bf3d78 100644 --- a/xbmc/application/AppInboundProtocol.h +++ b/xbmc/application/AppInboundProtocol.h @@ -8,17 +8,28 @@ #pragma once +#include "threads/CriticalSection.h" #include "windowing/XBMC_events.h" +#include + class CApplication; class CAppInboundProtocol { + friend class CApplication; + public: - CAppInboundProtocol(CApplication &app); - bool OnEvent(XBMC_Event &event); + CAppInboundProtocol(CApplication& app); + bool OnEvent(const XBMC_Event& newEvent); void SetRenderGUI(bool renderGUI); + void Close(); protected: + void HandleEvents(); + + bool m_closed = false; CApplication &m_pApp; + std::deque m_portEvents; + CCriticalSection m_portSection; }; diff --git a/xbmc/application/Application.cpp b/xbmc/application/Application.cpp index 3309927de025f..cf45deafb529a 100644 --- a/xbmc/application/Application.cpp +++ b/xbmc/application/Application.cpp @@ -244,76 +244,6 @@ CApplication::~CApplication(void) DeregisterComponent(typeid(CApplicationActionListeners)); } -bool CApplication::OnEvent(XBMC_Event& newEvent) -{ - std::unique_lock lock(m_portSection); - m_portEvents.push_back(newEvent); - return true; -} - -void CApplication::HandlePortEvents() -{ - std::unique_lock lock(m_portSection); - while (!m_portEvents.empty()) - { - auto newEvent = m_portEvents.front(); - m_portEvents.pop_front(); - CSingleExit lock(m_portSection); - switch(newEvent.type) - { - case XBMC_QUIT: - if (!m_bStop) - CServiceBroker::GetAppMessenger()->PostMsg(TMSG_QUIT); - break; - case XBMC_VIDEORESIZE: - if (CServiceBroker::GetGUI()->GetWindowManager().Initialized()) - { - if (!CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_fullScreen) - { - CServiceBroker::GetWinSystem()->GetGfxContext().ApplyWindowResize(newEvent.resize.w, newEvent.resize.h); - - const std::shared_ptr settings = CServiceBroker::GetSettingsComponent()->GetSettings(); - settings->SetInt(CSettings::SETTING_WINDOW_WIDTH, newEvent.resize.w); - settings->SetInt(CSettings::SETTING_WINDOW_HEIGHT, newEvent.resize.h); - settings->Save(); - } - else - { - const auto& res_info = CDisplaySettings::GetInstance().GetResolutionInfo(RES_DESKTOP); - CServiceBroker::GetWinSystem()->ForceFullScreen(res_info); - } - } - break; - case XBMC_VIDEOMOVE: - { - CServiceBroker::GetWinSystem()->OnMove(newEvent.move.x, newEvent.move.y); - } - break; - case XBMC_MODECHANGE: - CServiceBroker::GetWinSystem()->GetGfxContext().ApplyModeChange(newEvent.mode.res); - break; - case XBMC_SCREENCHANGE: - CServiceBroker::GetWinSystem()->OnChangeScreen(newEvent.screen.screenIdx); - break; - case XBMC_USEREVENT: - CServiceBroker::GetAppMessenger()->PostMsg(static_cast(newEvent.user.code)); - break; - case XBMC_SETFOCUS: - { - // Reset the screensaver - const auto appPower = GetComponent(); - appPower->ResetScreenSaver(); - appPower->WakeUpScreenSaverAndDPMS(); - // Send a mouse motion event with no dx,dy for getting the current guiitem selected - OnAction(CAction(ACTION_MOUSE_MOVE, 0, static_cast(newEvent.focus.x), static_cast(newEvent.focus.y), 0, 0)); - break; - } - default: - CServiceBroker::GetInputManager().OnEvent(newEvent); - } - } -} - extern "C" void __stdcall init_emu_environ(); extern "C" void __stdcall update_emu_environ(); extern "C" void __stdcall cleanup_emu_environ(); @@ -1586,7 +1516,7 @@ void CApplication::OnApplicationMessage(ThreadMessage* pMsg) newEvent.type = XBMC_VIDEORESIZE; newEvent.resize.w = pMsg->param1; newEvent.resize.h = pMsg->param2; - OnEvent(newEvent); + m_pAppPort->OnEvent(newEvent); CServiceBroker::GetGUI()->GetWindowManager().MarkDirty(); } break; @@ -1745,7 +1675,7 @@ void CApplication::OnApplicationMessage(ThreadMessage* pMsg) if (pMsg->lpVoid) { XBMC_Event* event = static_cast(pMsg->lpVoid); - OnEvent(*event); + m_pAppPort->OnEvent(*event); delete event; } } @@ -1823,7 +1753,7 @@ void CApplication::FrameMove(bool processEvents, bool processGUI) } } - HandlePortEvents(); + m_pAppPort->HandleEvents(); CServiceBroker::GetInputManager().Process(CServiceBroker::GetGUI()->GetWindowManager().GetActiveWindowOrDialog(), frameTime); if (processGUI && renderGUI) @@ -2093,7 +2023,7 @@ bool CApplication::Stop(int exitCode) break; } } - m_pAppPort.reset(); + m_pAppPort->Close(); } try diff --git a/xbmc/application/Application.h b/xbmc/application/Application.h index 397506e5dc325..e06df1cc26bf5 100644 --- a/xbmc/application/Application.h +++ b/xbmc/application/Application.h @@ -20,11 +20,9 @@ #include "utils/GlobalsHandling.h" #include "utils/Stopwatch.h" #include "windowing/Resolution.h" -#include "windowing/XBMC_events.h" #include #include -#include #include #include #include @@ -88,8 +86,6 @@ class CApplication : public IWindowManagerCallback, public CApplicationPlayerCallback, public CApplicationSettingsHandling { -friend class CAppInboundProtocol; - public: // If playback time of current item is greater than this value, ACTION_PREV_ITEM will seek to start @@ -200,16 +196,11 @@ friend class CAppInboundProtocol; bool OnSettingsSaving() const override; void PlaybackCleanup(); - // inbound protocol - bool OnEvent(XBMC_Event& newEvent); - std::shared_ptr m_pAnnouncementManager; std::unique_ptr m_pGUI; std::unique_ptr m_pWinSystem; std::unique_ptr m_pActiveAE; std::shared_ptr m_pAppPort; - std::deque m_portEvents; - CCriticalSection m_portSection; // timer information CStopWatch m_restartPlayerTimer; @@ -229,8 +220,6 @@ friend class CAppInboundProtocol; bool PlayStack(CFileItem& item, bool bRestart); - void HandlePortEvents(); - std::unique_ptr m_pInertialScrollingHandler; std::vector>