2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
9 #include "AppInboundProtocol.h"
11 #include "ServiceBroker.h"
12 #include "application/Application.h"
13 #include "application/ApplicationComponents.h"
14 #include "application/ApplicationPowerHandling.h"
15 #include "guilib/GUIComponent.h"
16 #include "guilib/GUIWindowManager.h"
17 #include "input/InputManager.h"
18 #include "input/actions/Action.h"
19 #include "input/actions/ActionIDs.h"
20 #include "messaging/ApplicationMessenger.h"
21 #include "settings/AdvancedSettings.h"
22 #include "settings/DisplaySettings.h"
23 #include "settings/Settings.h"
24 #include "settings/SettingsComponent.h"
25 #include "threads/SingleLock.h"
27 CAppInboundProtocol::CAppInboundProtocol(CApplication
&app
) : m_pApp(app
)
31 bool CAppInboundProtocol::OnEvent(const XBMC_Event
& newEvent
)
33 std::unique_lock
<CCriticalSection
> lock(m_portSection
);
36 m_portEvents
.push_back(newEvent
);
40 void CAppInboundProtocol::Close()
42 std::unique_lock
<CCriticalSection
> lock(m_portSection
);
46 void CAppInboundProtocol::SetRenderGUI(bool renderGUI
)
48 auto& components
= CServiceBroker::GetAppComponents();
49 const auto appPower
= components
.GetComponent
<CApplicationPowerHandling
>();
50 appPower
->SetRenderGUI(renderGUI
);
53 void CAppInboundProtocol::HandleEvents()
55 std::unique_lock
<CCriticalSection
> lock(m_portSection
);
56 while (!m_portEvents
.empty())
58 auto newEvent
= m_portEvents
.front();
59 m_portEvents
.pop_front();
60 CSingleExit
lock(m_portSection
);
61 switch (newEvent
.type
)
65 CServiceBroker::GetAppMessenger()->PostMsg(TMSG_QUIT
);
67 case XBMC_VIDEORESIZE
:
68 if (CServiceBroker::GetGUI()->GetWindowManager().Initialized())
70 if (!CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_fullScreen
)
72 CServiceBroker::GetWinSystem()->GetGfxContext().ApplyWindowResize(newEvent
.resize
.w
,
75 const auto settings
= CServiceBroker::GetSettingsComponent()->GetSettings();
76 settings
->SetInt(CSettings::SETTING_WINDOW_WIDTH
, newEvent
.resize
.w
);
77 settings
->SetInt(CSettings::SETTING_WINDOW_HEIGHT
, newEvent
.resize
.h
);
82 const auto& res_info
= CDisplaySettings::GetInstance().GetResolutionInfo(RES_DESKTOP
);
83 CServiceBroker::GetWinSystem()->ForceFullScreen(res_info
);
89 CServiceBroker::GetWinSystem()->OnMove(newEvent
.move
.x
, newEvent
.move
.y
);
93 CServiceBroker::GetWinSystem()->GetGfxContext().ApplyModeChange(newEvent
.mode
.res
);
95 case XBMC_SCREENCHANGE
:
96 CServiceBroker::GetWinSystem()->OnChangeScreen(newEvent
.screen
.screenIdx
);
99 CServiceBroker::GetAppMessenger()->PostMsg(static_cast<uint32_t>(newEvent
.user
.code
));
103 // Reset the screensaver
104 const auto appPower
= m_pApp
.GetComponent
<CApplicationPowerHandling
>();
105 appPower
->ResetScreenSaver();
106 appPower
->WakeUpScreenSaverAndDPMS();
107 // Send a mouse motion event with no dx,dy for getting the current guiitem selected
108 m_pApp
.OnAction(CAction(ACTION_MOUSE_MOVE
, 0, static_cast<float>(newEvent
.focus
.x
),
109 static_cast<float>(newEvent
.focus
.y
), 0, 0));
113 CServiceBroker::GetInputManager().OnEvent(newEvent
);