Merge pull request #26273 from 78andyp/blurayfixes2
[xbmc.git] / xbmc / windowing / linux / OSScreenSaverFreedesktop.cpp
blob167930dacb90b4f49e98cd94c3da4a297095d673
1 /*
2 * Copyright (C) 2017-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.
7 */
9 #include "OSScreenSaverFreedesktop.h"
11 #include "CompileInfo.h"
12 #include "guilib/LocalizeStrings.h"
13 #include "utils/log.h"
15 #include "platform/linux/DBusMessage.h"
16 #include "platform/linux/DBusUtil.h"
18 using namespace KODI::WINDOWING::LINUX;
20 namespace
22 const std::string SCREENSAVER_OBJECT = "/org/freedesktop/ScreenSaver";
23 const std::string SCREENSAVER_INTERFACE = "org.freedesktop.ScreenSaver";
26 bool COSScreenSaverFreedesktop::IsAvailable()
28 // Test by making a call to a function without side-effects
29 CDBusMessage dummyMessage(SCREENSAVER_INTERFACE, SCREENSAVER_OBJECT, SCREENSAVER_INTERFACE, "GetActive");
30 CDBusError error;
31 dummyMessage.SendSession(error);
32 // We do not care whether GetActive() is actually supported, we're just checking for the name to be there
33 // (GNOME for example does not support GetActive)
34 return !error || error.Name() == DBUS_ERROR_NOT_SUPPORTED;
37 void COSScreenSaverFreedesktop::Inhibit()
39 if (m_inhibited)
41 return;
44 CDBusMessage inhibitMessage(SCREENSAVER_INTERFACE, SCREENSAVER_OBJECT, SCREENSAVER_INTERFACE, "Inhibit");
45 inhibitMessage.AppendArguments(std::string(CCompileInfo::GetAppName()),
46 g_localizeStrings.Get(14086));
47 if (!inhibitMessage.SendSession())
49 // DBus call failed
50 CLog::Log(LOGERROR, "Inhibiting freedesktop screen saver failed");
51 return;
54 if (!inhibitMessage.GetReplyArguments(&m_cookie))
56 CLog::Log(LOGERROR, "Could not retrieve cookie from org.freedesktop.ScreenSaver Inhibit response");
57 return;
60 m_inhibited = true;
63 void COSScreenSaverFreedesktop::Uninhibit()
65 if (!m_inhibited)
67 return;
70 CDBusMessage uninhibitMessage(SCREENSAVER_INTERFACE, SCREENSAVER_OBJECT, SCREENSAVER_INTERFACE, "UnInhibit");
71 uninhibitMessage.AppendArgument(m_cookie);
72 if (!uninhibitMessage.SendSession())
74 CLog::Log(LOGERROR, "Uninhibiting freedesktop screen saver failed");
77 m_inhibited = false;