Skip to content
Permalink
Browse files

Add support for xdg-screensaver from xdg-utils ( http://portland.free…

…desktop.org/wiki/ ).

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: http://svn.mythtv.org/svn/trunk@24559 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 {
DEFINES += USING_X11
HEADERS += screensaver-x11.h
SOURCES += screensaver-x11.cpp
HEADERS += screensaver-x11.h screensaver-xdg.h
SOURCES += screensaver-x11.cpp screensaver-xdg.cpp
LIBS += $$EXTRA_LIBS
}

@@ -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;

public:
ScreenSaverXDGPrivate(ScreenSaverXDG *outer) :
m_xdgscreensaverRunning(false),
m_display(NULL)
{
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");
}

~ScreenSaverXDGPrivate()
{
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")
.arg(windowId));
return windowId;
}

private:
bool m_xdgscreensaverRunning;

MythXDisplay *m_display;
};

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

ScreenSaverXDG::~ScreenSaverXDG()
{
delete d;
}

bool ScreenSaverXDG::IsXDGInstalled(void)
{
bool result = myth_system("xdg-screensaver --version >&- 2>&-") == 0;
if (result)
VERBOSE(VB_GENERAL, "xdg-screensaver is available.");
else
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>&- &")
.arg(d->GetXWindowId()));
}
}

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

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 @@
#ifndef MYTH_SCREENSAVER_XDG_H
#define MYTH_SCREENSAVER_XDG_H

#include <QObject>

#include "screensaver.h"

class ScreenSaverXDG : public QObject, public ScreenSaverControl
{
Q_OBJECT

public:
ScreenSaverXDG();
~ScreenSaverXDG();

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

bool Asleep(void);

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

protected:
class ScreenSaverXDGPrivate *d;
};

#endif // MYTH_SCREENSAVER_XDG_H

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

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

#if CONFIG_DARWIN
@@ -21,7 +22,10 @@ ScreenSaverControl* ScreenSaverControl::get(void)
{

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

0 comments on commit dd96b80

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