From fae12f43c23fbfe492db1b2b68144b500b86e685 Mon Sep 17 00:00:00 2001 From: Glenn Rice Date: Thu, 25 Nov 2010 02:26:46 +0000 Subject: [PATCH] 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 --- CMakeLists.txt | 9 ++++ Source/Core/DolphinWX/Src/FrameTools.cpp | 10 +++++ Source/Core/DolphinWX/Src/MainNoGUI.cpp | 9 ++++ Source/Core/DolphinWX/Src/X11Utils.cpp | 43 ++++++++++++++++++- Source/Core/DolphinWX/Src/X11Utils.h | 4 ++ .../Plugin_VideoSoftware/CMakeLists.txt | 2 +- 6 files changed, 75 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2273dc0402..091ce5175a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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( diff --git a/Source/Core/DolphinWX/Src/FrameTools.cpp b/Source/Core/DolphinWX/Src/FrameTools.cpp index 34bd79c9da..aeb96259de 100644 --- a/Source/Core/DolphinWX/Src/FrameTools.cpp +++ b/Source/Core/DolphinWX/Src/FrameTools.cpp @@ -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), diff --git a/Source/Core/DolphinWX/Src/MainNoGUI.cpp b/Source/Core/DolphinWX/Src/MainNoGUI.cpp index c07ee7f379..0abb2c1b6c 100644 --- a/Source/Core/DolphinWX/Src/MainNoGUI.cpp +++ b/Source/Core/DolphinWX/Src/MainNoGUI.cpp @@ -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); diff --git a/Source/Core/DolphinWX/Src/X11Utils.cpp b/Source/Core/DolphinWX/Src/X11Utils.cpp index 513eae4b44..ad721739c4 100644 --- a/Source/Core/DolphinWX/Src/X11Utils.cpp +++ b/Source/Core/DolphinWX/Src/X11Utils.cpp @@ -17,6 +17,14 @@ #include "X11Utils.h" +#if defined(HAVE_XDG_SCREENSAVER) && HAVE_XDG_SCREENSAVER +#include +#include +#include + +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) diff --git a/Source/Core/DolphinWX/Src/X11Utils.h b/Source/Core/DolphinWX/Src/X11Utils.h index 2b1f6471ef..32a508ac92 100644 --- a/Source/Core/DolphinWX/Src/X11Utils.h +++ b/Source/Core/DolphinWX/Src/X11Utils.h @@ -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 { diff --git a/Source/Plugins/Plugin_VideoSoftware/CMakeLists.txt b/Source/Plugins/Plugin_VideoSoftware/CMakeLists.txt index 4235fe0ac1..dd34855536 100644 --- a/Source/Plugins/Plugin_VideoSoftware/CMakeLists.txt +++ b/Source/Plugins/Plugin_VideoSoftware/CMakeLists.txt @@ -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()