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/GUITexture.h"
21 #include "guilib/GUIWindowManager.h"
22 #include "settings/Settings.h"
23 #include "settings/SettingsComponent.h"
27 CGUIWindowScreensaver::CGUIWindowScreensaver()
28 : CGUIDialog(WINDOW_SCREENSAVER
, "", DialogModalityType::MODELESS
)
30 m_renderOrder
= RENDER_ORDER_WINDOW_SCREENSAVER
;
33 void CGUIWindowScreensaver::Process(unsigned int currentTime
, CDirtyRegionList
& regions
)
36 CGUIWindow::Process(currentTime
, regions
);
37 const auto& context
= CServiceBroker::GetWinSystem()->GetGfxContext();
38 m_renderRegion
.SetRect(0, 0, static_cast<float>(context
.GetWidth()),
39 static_cast<float>(context
.GetHeight()));
42 void CGUIWindowScreensaver::Render()
44 // FIXME/TODO: Screensaver addons should make the screen black instead
45 // keeping this just for compatibility reasons since it's now a dialog.
46 CGUITexture::DrawQuad(m_renderRegion
, UTILS::COLOR::BLACK
);
50 auto& context
= CServiceBroker::GetWinSystem()->GetGfxContext();
52 context
.CaptureStateBlock();
54 context
.ApplyStateBlock();
61 void CGUIWindowScreensaver::OnInitWindow()
63 CGUIDialog::OnInitWindow();
67 void CGUIWindowScreensaver::UpdateVisibility()
69 auto& components
= CServiceBroker::GetAppComponents();
70 const auto appPower
= components
.GetComponent
<CApplicationPowerHandling
>();
71 if (!appPower
->IsInScreenSaver() && m_visible
)
78 bool CGUIWindowScreensaver::OnMessage(CGUIMessage
& message
)
80 switch (message
.GetMessage())
82 case GUI_MSG_WINDOW_DEINIT
:
90 CServiceBroker::GetWinSystem()->GetGfxContext().ApplyStateBlock();
94 case GUI_MSG_WINDOW_INIT
:
96 CGUIWindow::OnMessage(message
);
98 CServiceBroker::GetWinSystem()->GetGfxContext().CaptureStateBlock();
100 const std::string addon
= CServiceBroker::GetSettingsComponent()->GetSettings()->GetString(
101 CSettings::SETTING_SCREENSAVER_MODE
);
102 const ADDON::AddonInfoPtr addonBase
=
103 CServiceBroker::GetAddonMgr().GetAddonInfo(addon
, ADDON::AddonType::SCREENSAVER
);
106 m_addon
= std::make_unique
<KODI::ADDONS::CScreenSaver
>(addonBase
);
107 return m_addon
->Start();
110 case GUI_MSG_CHECK_LOCK
:
112 auto& components
= CServiceBroker::GetAppComponents();
113 const auto appPower
= components
.GetComponent
<CApplicationPowerHandling
>();
114 if (!g_passwordManager
.IsProfileLockUnlocked())
116 appPower
->SetScreenSaverLockFailed();
119 appPower
->SetScreenSaverUnlocked();
124 return CGUIWindow::OnMessage(message
);