(Linux) Suspend screen saver when using SDL or XVIDEO

This doesn't add support for the opengl backend because I'm too tired to
figure out the context mess.

Signed-off-by: Saggi Mizrahi <ficoos@gmail.com>
This commit is contained in:
Saggi Mizrahi 2012-07-25 00:52:57 -04:00
parent 5a6bec18b6
commit de8c4b9a5f
4 changed files with 70 additions and 0 deletions

View File

@ -33,6 +33,12 @@
#endif
#endif
#if IS_LINUX
#include <unistd.h>
#include <errno.h>
#include <sys/wait.h>
#endif
#if defined(__CELLOS_LV2__) && !defined(__PSL1GHT__) || defined(_MSC_VER)
static int gettimeofday(struct timeval *val, void *dummy)
{
@ -107,6 +113,37 @@ bool gfx_window_title(char *buf, size_t size)
return ret;
}
#ifdef IS_LINUX
void suspend_screensaver(Window wnd) {
char wid[20];
snprintf(wid, 20, "%d", (int) wnd);
wid[19] = '\0';
char* args[4];
args[0] = "xdg-screensaver";
args[1] = "suspend";
args[2] = wid;
args[3] = NULL;
int cpid = fork();
if (cpid < 0) {
RARCH_WARN("Could not suspend screen saver: %s\n", strerror(errno));
return;
}
if (!cpid) {
execvp(args[0], args);
exit(errno);
}
int err = 0;
waitpid(cpid, &err, 0);
if (err) {
RARCH_WARN("Could not suspend screen saver: %s\n", strerror(err));
}
}
#endif
#if defined(_WIN32) && !defined(_XBOX)
#include <windows.h>
#include "../dynamic.h"

View File

@ -22,6 +22,11 @@
bool gfx_window_title(char *buf, size_t size);
void gfx_window_title_reset(void);
#ifdef IS_LINUX
#include <X11/Xlib.h>
void suspend_screensaver(Window wnd);
#endif
#ifdef _WIN32
void gfx_set_dwm(void);
#endif

View File

@ -21,6 +21,10 @@
#include "../input/rarch_sdl_input.h"
#include "gfx_common.h"
#ifdef IS_LINUX
#include "SDL_syswm.h"
#endif
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
@ -243,6 +247,21 @@ static void sdl_render_msg_32(sdl_video_t *vid, SDL_Surface *buffer, const char
#endif
}
#ifdef IS_LINUX
static Window sdl_get_window_id() {
SDL_SysWMinfo sys_info;
SDL_VERSION(&sys_info.version);
if(SDL_GetWMInfo(&sys_info) <= 0) {
RARCH_WARN("%s", SDL_GetError());
return -1;
}
Window wid = sys_info.info.x11.window;
return wid;
}
#endif
static void *sdl_gfx_init(const video_info_t *video, const input_driver_t **input, void **input_data)
{
#ifdef _WIN32
@ -270,6 +289,13 @@ static void *sdl_gfx_init(const video_info_t *video, const input_driver_t **inpu
vid->render32 = video->rgb32 && !g_settings.video.force_16bit;
vid->screen = SDL_SetVideoMode(video->width, video->height, vid->render32 ? 32 : 15, SDL_HWSURFACE | SDL_HWACCEL | SDL_DOUBLEBUF | (video->fullscreen ? SDL_FULLSCREEN : 0));
#ifdef IS_LINUX
int wid = sdl_get_window_id();
if (wid > 0) {
suspend_screensaver(wid);
}
#endif
if (!vid->screen && !g_settings.video.force_16bit && !video->rgb32)
{
vid->upsample = true;

View File

@ -527,6 +527,8 @@ static void *xv_init(const video_info_t *video, const input_driver_t **input, vo
xv_set_nonblock_state(xv, !video->vsync);
xv->focus = true;
suspend_screensaver(xv->window);
xinput = input_x.init();
if (xinput)
{