Inhibit the screensaver while the emulator is running on linux. Fixes issue 3279. Uses the xdg-screensaver method suggested in that issue.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@6477 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Glenn Rice 2010-11-25 02:26:46 +00:00
parent 7fe6a0b451
commit fae12f43c2
6 changed files with 75 additions and 2 deletions

View File

@ -186,6 +186,15 @@ if(ENCODE_FRAMEDUMPS)
endif()
endif()
find_program(XDG_SCREENSAVER xdg-screensaver)
if(XDG_SCREENSAVER)
message("xdg-screensaver found, enabling screensaver inhibition")
add_definitions(-DHAVE_XDG_SCREENSAVER=1)
else()
message("xdg-screensaver not found, disabling screensaver inhibition")
add_definitions(-DHAVE_XDG_SCREENSAVER=0)
endif()
include(CheckCXXSourceRuns)
set(CMAKE_REQUIRED_LIBRARIES portaudio)
CHECK_CXX_SOURCE_RUNS(

View File

@ -815,6 +815,11 @@ void CFrame::StartGame(const std::string& filename)
}
else
{
#if defined(HAVE_XDG_SCREENSAVER) && HAVE_XDG_SCREENSAVER
X11Utils::InhibitScreensaver(X11Utils::XDisplayFromHandle(GetHandle()),
X11Utils::XWindowFromHandle(GetHandle()), true);
#endif
DoFullscreen(SConfig::GetInstance().m_LocalCoreStartupParameter.bFullscreen);
#ifdef _WIN32
@ -915,6 +920,11 @@ void CFrame::DoStop()
BootManager::Stop();
#if defined(HAVE_XDG_SCREENSAVER) && HAVE_XDG_SCREENSAVER
X11Utils::InhibitScreensaver(X11Utils::XDisplayFromHandle(GetHandle()),
X11Utils::XWindowFromHandle(GetHandle()), false);
#endif
// Destroy the renderer frame when not rendering to main
m_RenderParent->Disconnect(wxID_ANY, wxEVT_SIZE,
wxSizeEventHandler(CFrame::OnRenderParentResize),

View File

@ -141,6 +141,10 @@ void X11_MainLoop()
Window win = (Window)Core::GetWindowHandle();
XSelectInput(dpy, win, KeyPressMask | FocusChangeMask);
#if defined(HAVE_XDG_SCREENSAVER) && HAVE_XDG_SCREENSAVER
X11Utils::InhibitScreensaver(dpy, win, true);
#endif
#if defined(HAVE_XRANDR) && HAVE_XRANDR
X11Utils::XRRConfiguration *XRRConfig = new X11Utils::XRRConfiguration(dpy, win);
#endif
@ -251,6 +255,11 @@ void X11_MainLoop()
#if defined(HAVE_XRANDR) && HAVE_XRANDR
delete XRRConfig;
#endif
#if defined(HAVE_XDG_SCREENSAVER) && HAVE_XDG_SCREENSAVER
X11Utils::InhibitScreensaver(dpy, win, false);
#endif
if (SConfig::GetInstance().m_LocalCoreStartupParameter.bHideCursor)
XFreeCursor(dpy, blankCursor);
XCloseDisplay(dpy);

View File

@ -17,6 +17,14 @@
#include "X11Utils.h"
#if defined(HAVE_XDG_SCREENSAVER) && HAVE_XDG_SCREENSAVER
#include <unistd.h>
#include <spawn.h>
#include <sys/wait.h>
extern char **environ;
#endif
namespace X11Utils
{
@ -78,6 +86,7 @@ void EWMH_Fullscreen(Display *dpy, int action)
ERROR_LOG(VIDEO, "Failed to switch fullscreen/windowed mode.");
}
#if defined(HAVE_WX) && HAVE_WX
Window XWindowFromHandle(void *Handle)
{
@ -90,6 +99,39 @@ Display *XDisplayFromHandle(void *Handle)
}
#endif
#if defined(HAVE_XDG_SCREENSAVER) && HAVE_XDG_SCREENSAVER
void InhibitScreensaver(Display *dpy, Window win, bool suspend)
{
// Get X server window id
Atom actual_type;
int actual_format, status;
unsigned long nitems, bytes_after;
unsigned char *prop;
status = XGetWindowProperty(dpy, win, XInternAtom(dpy, "_NET_FRAME_WINDOW", True),
0, 125000, False, AnyPropertyType,
&actual_type, &actual_format, &nitems, &bytes_after, &prop);
char id[11];
snprintf(id, sizeof(id), "0x%lx", *(unsigned long *)prop & 0xffffffff);
// Call xdg-screensaver
char *argv[4] = {
(char *)"xdg-screensaver",
(char *)(suspend ? "suspend" : "resume"),
id,
NULL};
pid_t pid;
if (!posix_spawnp(&pid, "xdg-screensaver", NULL, NULL, argv, environ))
{
int status;
while (waitpid (pid, &status, 0) == -1);
DEBUG_LOG(VIDEO, "Started xdg-screensaver (PID = %d)", (int)pid);
}
}
#endif
#if defined(HAVE_XRANDR) && HAVE_XRANDR
XRRConfiguration::XRRConfiguration(Display *_dpy, Window _win)
: dpy(_dpy)
@ -125,7 +167,6 @@ XRRConfiguration::~XRRConfiguration()
}
}
void XRRConfiguration::Update()
{
if (!bValid)

View File

@ -52,6 +52,10 @@ Window XWindowFromHandle(void *Handle);
Display *XDisplayFromHandle(void *Handle);
#endif
#if defined(HAVE_XDG_SCREENSAVER) && HAVE_XDG_SCREENSAVER
void InhibitScreensaver(Display *dpy, Window win, bool suspend);
#endif
#if defined(HAVE_XRANDR) && HAVE_XRANDR
class XRRConfiguration
{

View File

@ -34,7 +34,7 @@ set(LIBS videocommon
if((${CMAKE_SYSTEM_NAME} MATCHES "Darwin") AND NOT wxWidgets_FOUND)
set(SRCS ${SRCS} Src/cocoaGL.m)
elseif(WIN32)
set(SRCS ${SRCS} Src/OS/Win32.cpp)
set(SRCS ${SRCS} Src/Win32.cpp)
elseif(NOT (${CMAKE_SYSTEM_NAME} MATCHES "Darwin"))
set(LIBS ${LIBS} clrun)
endif()