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 "GUIWindowScreensaver.h"
11 #include "GUIPassword.h"
12 #include "GUIUserMessages.h"
13 #include "ServiceBroker.h"
14 #include "addons/AddonManager.h"
15 #include "addons/ScreenSaver.h"
16 #include "addons/addoninfo/AddonType.h"
17 #include "application/ApplicationComponents.h"
18 #include "application/ApplicationPowerHandling.h"
19 #include "guilib/GUIComponent.h"
20 #include "guilib/GUIWindowManager.h"
21 #include "settings/Settings.h"
22 #include "settings/SettingsComponent.h"
26 CGUIWindowScreensaver::CGUIWindowScreensaver()
27 : CGUIDialog(WINDOW_SCREENSAVER
, "", DialogModalityType::MODELESS
)
29 m_renderOrder
= RENDER_ORDER_WINDOW_SCREENSAVER
;
32 void CGUIWindowScreensaver::Process(unsigned int currentTime
, CDirtyRegionList
& regions
)
35 CGUIWindow::Process(currentTime
, regions
);
36 const auto& context
= CServiceBroker::GetWinSystem()->GetGfxContext();
37 m_renderRegion
.SetRect(0, 0, static_cast<float>(context
.GetWidth()),
38 static_cast<float>(context
.GetHeight()));
41 void CGUIWindowScreensaver::Render()
45 auto& context
= CServiceBroker::GetWinSystem()->GetGfxContext();
47 context
.CaptureStateBlock();
49 context
.ApplyStateBlock();
56 void CGUIWindowScreensaver::OnInitWindow()
58 CGUIDialog::OnInitWindow();
62 void CGUIWindowScreensaver::UpdateVisibility()
64 auto& components
= CServiceBroker::GetAppComponents();
65 const auto appPower
= components
.GetComponent
<CApplicationPowerHandling
>();
66 if (!appPower
->IsInScreenSaver() && m_visible
)
73 bool CGUIWindowScreensaver::OnMessage(CGUIMessage
& message
)
75 switch (message
.GetMessage())
77 case GUI_MSG_WINDOW_DEINIT
:
85 CServiceBroker::GetWinSystem()->GetGfxContext().ApplyStateBlock();
89 case GUI_MSG_WINDOW_INIT
:
91 CGUIWindow::OnMessage(message
);
93 CServiceBroker::GetWinSystem()->GetGfxContext().CaptureStateBlock();
95 const std::string addon
= CServiceBroker::GetSettingsComponent()->GetSettings()->GetString(
96 CSettings::SETTING_SCREENSAVER_MODE
);
97 const ADDON::AddonInfoPtr addonBase
=
98 CServiceBroker::GetAddonMgr().GetAddonInfo(addon
, ADDON::AddonType::SCREENSAVER
);
101 m_addon
= std::make_unique
<KODI::ADDONS::CScreenSaver
>(addonBase
);
102 return m_addon
->Start();
105 case GUI_MSG_CHECK_LOCK
:
107 auto& components
= CServiceBroker::GetAppComponents();
108 const auto appPower
= components
.GetComponent
<CApplicationPowerHandling
>();
109 if (!g_passwordManager
.IsProfileLockUnlocked())
111 appPower
->SetScreenSaverLockFailed();
114 appPower
->SetScreenSaverUnlocked();
119 return CGUIWindow::OnMessage(message
);