Mercurial > sdl-ios-xcode
comparison src/video/x11/SDL_x11events.c @ 3025:54fac87e1f34
Added an API to enable/disable the screen saver.
The screensaver is disabled by default when using SDL 1.2 compatibility.
Use the new XScreenSaver extension, removed unused DPMS extension.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 12 Jan 2009 06:19:05 +0000 |
parents | adbb7f8afd2d |
children | f13ad181f5b2 |
comparison
equal
deleted
inserted
replaced
3024:1a08749aebce | 3025:54fac87e1f34 |
---|---|
392 void | 392 void |
393 X11_PumpEvents(_THIS) | 393 X11_PumpEvents(_THIS) |
394 { | 394 { |
395 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; | 395 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; |
396 | 396 |
397 /* Update activity every 30 seconds to prevent screensaver */ | |
398 if (_this->suspend_screensaver) { | |
399 Uint32 now = SDL_GetTicks(); | |
400 if (!data->screensaver_activity || | |
401 (int)(now-data->screensaver_activity) >= 30000) { | |
402 XResetScreenSaver(data->display); | |
403 data->screensaver_activity = now; | |
404 } | |
405 } | |
406 | |
397 /* Keep processing pending events */ | 407 /* Keep processing pending events */ |
398 while (X11_Pending(data->display)) { | 408 while (X11_Pending(data->display)) { |
399 X11_DispatchEvent(_this); | 409 X11_DispatchEvent(_this); |
400 } | 410 } |
401 } | 411 } |
402 | 412 |
403 void | 413 void |
404 X11_SaveScreenSaver(Display * display, int *saved_timeout, BOOL * dpms) | 414 X11_SuspendScreenSaver(_THIS) |
405 { | 415 { |
406 int timeout, interval, prefer_blank, allow_exp; | 416 #if SDL_VIDEO_DRIVER_X11_SCRNSAVER |
407 XGetScreenSaver(display, &timeout, &interval, &prefer_blank, &allow_exp); | 417 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; |
408 *saved_timeout = timeout; | 418 int dummy; |
409 | 419 int major_version, minor_version; |
410 #if SDL_VIDEO_DRIVER_X11_DPMS | 420 |
411 if (SDL_X11_HAVE_DPMS) { | 421 if (!SDL_X11_HAVE_XSS) { |
412 int dummy; | 422 return; |
413 if (DPMSQueryExtension(display, &dummy, &dummy)) { | 423 } |
414 CARD16 state; | 424 |
415 DPMSInfo(display, &state, dpms); | 425 /* XScreenSaverSuspend was introduced in MIT-SCREEN-SAVER 1.1 */ |
416 } | 426 if (!XScreenSaverQueryExtension(data->display, &dummy, &dummy) || |
417 } | 427 !XScreenSaverQueryVersion(data->display, |
418 #else | 428 &major_version, &minor_version) || |
419 *dpms = 0; | 429 major_version < 1 || (major_version == 1 && minor_version < 1)) { |
420 #endif /* SDL_VIDEO_DRIVER_X11_DPMS */ | 430 return; |
431 } | |
432 | |
433 XScreenSaverSuspend(data->display, _this->suspend_screensaver); | |
434 XResetScreenSaver(data->display); | |
435 #endif | |
421 } | 436 } |
422 | 437 |
423 void | |
424 X11_DisableScreenSaver(Display * display) | |
425 { | |
426 int timeout, interval, prefer_blank, allow_exp; | |
427 XGetScreenSaver(display, &timeout, &interval, &prefer_blank, &allow_exp); | |
428 timeout = 0; | |
429 XSetScreenSaver(display, timeout, interval, prefer_blank, allow_exp); | |
430 | |
431 #if SDL_VIDEO_DRIVER_X11_DPMS | |
432 if (SDL_X11_HAVE_DPMS) { | |
433 int dummy; | |
434 if (DPMSQueryExtension(display, &dummy, &dummy)) { | |
435 DPMSDisable(display); | |
436 } | |
437 } | |
438 #endif /* SDL_VIDEO_DRIVER_X11_DPMS */ | |
439 } | |
440 | |
441 void | |
442 X11_RestoreScreenSaver(Display * display, int saved_timeout, BOOL dpms) | |
443 { | |
444 int timeout, interval, prefer_blank, allow_exp; | |
445 XGetScreenSaver(display, &timeout, &interval, &prefer_blank, &allow_exp); | |
446 timeout = saved_timeout; | |
447 XSetScreenSaver(display, timeout, interval, prefer_blank, allow_exp); | |
448 | |
449 #if SDL_VIDEO_DRIVER_X11_DPMS | |
450 if (SDL_X11_HAVE_DPMS) { | |
451 int dummy; | |
452 if (DPMSQueryExtension(display, &dummy, &dummy)) { | |
453 if (dpms) { | |
454 DPMSEnable(display); | |
455 } | |
456 } | |
457 } | |
458 #endif /* SDL_VIDEO_DRIVER_X11_DPMS */ | |
459 } | |
460 | |
461 /* vi: set ts=4 sw=4 expandtab: */ | 438 /* vi: set ts=4 sw=4 expandtab: */ |