-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from pkerling/issue/7-screensaver
Screensaver inhibition
- Loading branch information
Showing
24 changed files
with
450 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright (C) 2017 Team XBMC | ||
* http://xbmc.org | ||
* | ||
* This Program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2, or (at your option) | ||
* any later version. | ||
* | ||
* This Program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with XBMC; see the file COPYING. If not, see | ||
* <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
#pragma once | ||
|
||
#include <string> | ||
|
||
namespace KODI | ||
{ | ||
namespace LINUX | ||
{ | ||
|
||
/** | ||
* Name of the kodi .desktop file without the extension | ||
*/ | ||
const std::string DESKTOP_FILE_NAME = "kodi"; | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
set(SOURCES "") | ||
set(HEADERS "") | ||
|
||
if(DBUS_FOUND) | ||
list(APPEND SOURCES OSScreenSaverFreedesktop.cpp) | ||
list(APPEND HEADERS OSScreenSaverFreedesktop.h) | ||
endif() | ||
|
||
if(SOURCES) | ||
core_add_library(windowing_linux) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Copyright (C) 2017 Team XBMC | ||
* http://xbmc.org | ||
* | ||
* This Program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2, or (at your option) | ||
* any later version. | ||
* | ||
* This Program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with XBMC; see the file COPYING. If not, see | ||
* <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
#include "OSScreenSaverFreedesktop.h" | ||
|
||
#include "guilib/LocalizeStrings.h" | ||
#include "linux/DBusMessage.h" | ||
#include "linux/DBusUtil.h" | ||
#include "linux/PlatformConstants.h" | ||
#include "utils/log.h" | ||
|
||
using namespace KODI::WINDOWING::LINUX; | ||
|
||
namespace | ||
{ | ||
const std::string SCREENSAVER_OBJECT = "/org/freedesktop/ScreenSaver"; | ||
const std::string SCREENSAVER_INTERFACE = "org.freedesktop.ScreenSaver"; | ||
} | ||
|
||
bool COSScreenSaverFreedesktop::IsAvailable() | ||
{ | ||
// Test by making a call to a function without side-effects | ||
CDBusMessage dummyMessage(SCREENSAVER_INTERFACE, SCREENSAVER_OBJECT, SCREENSAVER_INTERFACE, "GetActive"); | ||
CDBusError error; | ||
dummyMessage.SendSession(error); | ||
// We do not care whether GetActive() is actually supported, we're just checking for the name to be there | ||
// (GNOME for example does not support GetActive) | ||
return !error || error.Name() == DBUS_ERROR_NOT_SUPPORTED; | ||
} | ||
|
||
void COSScreenSaverFreedesktop::Inhibit() | ||
{ | ||
if (m_inhibited) | ||
{ | ||
return; | ||
} | ||
|
||
CDBusMessage inhibitMessage(SCREENSAVER_INTERFACE, SCREENSAVER_OBJECT, SCREENSAVER_INTERFACE, "Inhibit"); | ||
inhibitMessage.AppendArguments(KODI::LINUX::DESKTOP_FILE_NAME, g_localizeStrings.Get(14086)); | ||
if (!inhibitMessage.SendSession()) | ||
{ | ||
// DBus call failed | ||
CLog::Log(LOGERROR, "Inhibiting freedesktop screen saver failed"); | ||
return; | ||
} | ||
|
||
if (!inhibitMessage.GetReplyArguments(&m_cookie)) | ||
{ | ||
CLog::Log(LOGERROR, "Could not retrieve cookie from org.freedesktop.ScreenSaver Inhibit response"); | ||
return; | ||
} | ||
|
||
m_inhibited = true; | ||
} | ||
|
||
void COSScreenSaverFreedesktop::Uninhibit() | ||
{ | ||
if (!m_inhibited) | ||
{ | ||
return; | ||
} | ||
|
||
CDBusMessage uninhibitMessage(SCREENSAVER_INTERFACE, SCREENSAVER_OBJECT, SCREENSAVER_INTERFACE, "UnInhibit"); | ||
uninhibitMessage.AppendArgument(m_cookie); | ||
if (!uninhibitMessage.SendSession()) | ||
{ | ||
CLog::Log(LOGERROR, "Uninhibiting freedesktop screen saver failed"); | ||
} | ||
|
||
m_inhibited = false; | ||
} |
Oops, something went wrong.