Skip to content
Browse files

Add support for xdg-screensaver from xdg-utils (…

… ).

This adds a new class ScreenSaverXDG that provides support for enabling/disabling an X11 screensaver using the xdg-screensaver script from xdg-utils.  xdg-screensaver basically implements all of the functionality MythTV had implemented in ScreenSaverX11 (and more)--it handles making sure any supported screensaver applications do not activate when not wanted and handles DPMS enabling/disabling--even if no screensaver applications are running.  Therefore, ScreenSaverXDG is significantly simpler than ScreenSaverX11.  xdg-screensaver currently supports xscreensaver, GNOME screenaver, KDE screensaver, and support for other screensavers can easily be added to the script.

The biggest benefit of using xdg-screensaver is that it is designed to allow safely disabling a screensaver application such that the screensaver state will be restored even in the event that the suspending application crashes.  If mythfrontend crashes after suspending the screensaver, xdg-screensaver will notice that the mythfrontend window no longer exists, so it will re-enable the screensaver.  Therefore, rather than poke the screensaver once every 50s during playback, as we do with xscreensaver and gnome-screensaver in ScreenSaverX11 (so we never have to disable the screensaver and risk leaving it in the wrong state after a crash), xdg-screensaver allows us to simply "suspend" the screensaver on playback startup and "resume" the screensaver on playback pause/exit/...  This means that users on underpowered systems or users affected by the GNOME screensaver issue that causes gnome-screensaver-command to take significant resources on every execution will no longer see playback issues every 50s or so if they have xdg-screensaver installed.

Refs #7291.  Fixes #8357 with slightly modified patch from Johnny Walker.  Thanks to Johnny for the patch and for the testing.

git-svn-id: 7dbf422c-18fa-0310-86e9-fd20926502f2
  • Loading branch information...
sphery committed May 11, 2010
1 parent ba5922f commit dd96b80f515249213e52767e42eea5116d02519a
@@ -75,8 +75,8 @@ using_vdpau {

using_x11 {
HEADERS += screensaver-x11.h
SOURCES += screensaver-x11.cpp
HEADERS += screensaver-x11.h screensaver-xdg.h
SOURCES += screensaver-x11.cpp screensaver-xdg.cpp

@@ -0,0 +1,118 @@

// Own header
#include "screensaver-xdg.h"

// QT headers
#include <QString>

// Mythdb headers
#include "mythverbose.h"

// Mythui headers
#include "mythmainwindow.h"
#include "mythsystem.h"
#include "mythxdisplay.h"

#define LOC QString("ScreenSaverXDG: ")

class ScreenSaverXDGPrivate
friend class ScreenSaverXDG;

ScreenSaverXDGPrivate(ScreenSaverXDG *outer) :
m_xdgscreensaverRunning =
myth_system("xdg-screensaver --version >&- 2>&-") == 0;

if (IsScreenSaverRunning())
VERBOSE(VB_GENERAL, "xdg-screensaver support enabled");

m_display = OpenMythXDisplay();
if (!m_display)
VERBOSE(VB_IMPORTANT, "ScreenSaverXDGPrivate: Failed to open "
"connection to X11 server");

delete m_display;

bool IsScreenSaverRunning(void) const
return m_xdgscreensaverRunning;

QString GetXWindowId(void)
// return window id
WId myWId = GetMythMainWindow()->winId();
QString windowId = QString("0x%1").arg(myWId, 0, 16);
VERBOSE(VB_PLAYBACK, QString("ScreenSaverXDGPrivate::"
"GetXWindowId: X window ID of MythMainWindow: %1")
return windowId;

bool m_xdgscreensaverRunning;

MythXDisplay *m_display;

ScreenSaverXDG::ScreenSaverXDG() :
d(new ScreenSaverXDGPrivate(this))

delete d;

bool ScreenSaverXDG::IsXDGInstalled(void)
bool result = myth_system("xdg-screensaver --version >&- 2>&-") == 0;
if (result)
VERBOSE(VB_GENERAL, "xdg-screensaver is available.");
VERBOSE(VB_GENERAL, "xdg-utils are not installed. For best "
"screensaver-handling performance and compatibility, please "
"install xdg-utils.");
return result;

void ScreenSaverXDG::Disable(void)
if (d->m_display)
VERBOSE(VB_PLAYBACK, LOC + "Calling xdg-screensaver suspend");
myth_system(QString("xdg-screensaver suspend %1 >&- 2>&- &")

void ScreenSaverXDG::Restore(void)
if (d->m_display)
VERBOSE(VB_PLAYBACK, LOC + "Calling xdg-screensaver resume");
myth_system(QString("xdg-screensaver resume %1 >&- 2>&- &")

void ScreenSaverXDG::Reset(void)
VERBOSE(VB_PLAYBACK, LOC + "Calling xdg-screensaver reset");
myth_system(QString("xdg-screensaver reset >&- 2>&- &"));

bool ScreenSaverXDG::Asleep(void)
return false;

@@ -0,0 +1,30 @@

#include <QObject>

#include "screensaver.h"

class ScreenSaverXDG : public QObject, public ScreenSaverControl


void Disable(void);
void Restore(void);
void Reset(void);

bool Asleep(void);

// determine if xdg-utils is installed
static bool IsXDGInstalled(void);

class ScreenSaverXDGPrivate *d;


@@ -4,6 +4,7 @@

#ifdef USING_X11
#include "screensaver-x11.h"
#include "screensaver-xdg.h"
#endif // USING_X11

@@ -21,7 +22,10 @@ ScreenSaverControl* ScreenSaverControl::get(void)

#if defined(USING_X11)
ScreenSaverSingleton = new ScreenSaverX11();
if (ScreenSaverXDG::IsXDGInstalled())
ScreenSaverSingleton = new ScreenSaverXDG();
ScreenSaverSingleton = new ScreenSaverX11();
ScreenSaverSingleton = new ScreenSaverOSX();

0 comments on commit dd96b80

Please sign in to comment.
You can’t perform that action at this time.