Disable and reenable screen saver and DPMS.

This commit is contained in:
Johns 2012-03-08 15:25:10 +01:00
parent acc35fe30c
commit 7d3f4f4434
3 changed files with 155 additions and 13 deletions

View File

@ -1,6 +1,7 @@
User johns
Date:
Disable and reenable screen saver and DPMS.
Video source code cleanup.
Fix fast backward with some h264 streams.
Make soft start sync setup menu configurable.

2
Todo
View File

@ -26,7 +26,6 @@ missing:
Option deinterlace off / deinterlace force!
ColorSpace aren't configurable with the gui.
Replay of old vdr 1.6 recordings.
svdrp support for hot-keys.
Remote learning support.
restart vdr not working, when started x11 was killed.
@ -75,7 +74,6 @@ libva-vdpau-driver:
libva-xvba-driver:
x11:
disable screensaver
skip multiple configure-notify, handle only the last one.
support embedded mode

165
video.c
View File

@ -37,6 +37,7 @@
///
#define USE_XLIB_XCB ///< use xlib/xcb backend
#define USE_SCREENSAVER ///< support disable screensaver
#define USE_AUTOCROP ///< compile auto-crop support
#define USE_GRAB ///< experimental grab code
#define noUSE_GLX ///< outdated GLX code
@ -87,16 +88,18 @@
#include <X11/keysym.h>
#include <xcb/xcb.h>
#include <xcb/bigreq.h>
#include <xcb/dpms.h>
#include <xcb/glx.h>
#include <xcb/randr.h>
//#include <xcb/bigreq.h>
//#include <xcb/glx.h>
//#include <xcb/randr.h>
#ifdef USE_SCREENSAVER
#include <xcb/screensaver.h>
#include <xcb/shm.h>
#include <xcb/xv.h>
#include <xcb/dpms.h>
#endif
//#include <xcb/shm.h>
//#include <xcb/xv.h>
#include <xcb/xcb_image.h>
#include <xcb/xcb_event.h>
//#include <xcb/xcb_image.h>
//#include <xcb/xcb_event.h>
#include <xcb/xcb_atom.h>
#include <xcb/xcb_icccm.h>
#ifdef XCB_ICCCM_NUM_WM_SIZE_HINTS_ELEMENTS
@ -116,7 +119,6 @@ typedef enum
XCB_EWMH_WM_STATE_TOGGLE = 2
} xcb_ewmh_wm_state_action_t;
#endif
#include <xcb/xcb_keysyms.h>
#endif
#ifdef USE_GLX
@ -8938,6 +8940,137 @@ uint8_t *VideoGrab(int *size, int *width, int *height, int write_header)
return NULL;
}
#ifdef USE_SCREENSAVER
//----------------------------------------------------------------------------
// DPMS / Screensaver
//----------------------------------------------------------------------------
static char DPMSDisabled; ///< flag we have disabled dpms
///
/// Suspend X11 screen saver.
///
/// @param connection X11 connection to enable/disable screensaver
/// @param suspend True suspend screensaver,
/// false enable screensaver
///
static void X11SuspendScreenSaver(xcb_connection_t * connection, int suspend)
{
const xcb_query_extension_reply_t *query_extension_reply;
query_extension_reply =
xcb_get_extension_data(connection, &xcb_screensaver_id);
if (query_extension_reply && query_extension_reply->present) {
xcb_screensaver_query_version_cookie_t cookie;
xcb_screensaver_query_version_reply_t *reply;
Debug(3, "video: screen saver extension present\n");
cookie =
xcb_screensaver_query_version_unchecked(connection,
XCB_SCREENSAVER_MAJOR_VERSION, XCB_SCREENSAVER_MINOR_VERSION);
reply = xcb_screensaver_query_version_reply(connection, cookie, NULL);
if (reply
&& (reply->server_major_version >= XCB_SCREENSAVER_MAJOR_VERSION)
&& (reply->server_minor_version >= XCB_SCREENSAVER_MINOR_VERSION)
) {
xcb_screensaver_suspend(connection, suspend);
}
free(reply);
}
}
///
/// DPMS (Display Power Management Signaling) extension available.
///
/// @param connection X11 connection to check for DPMS
///
static int X11HaveDPMS(xcb_connection_t * connection)
{
static int have_dpms = -1;
const xcb_query_extension_reply_t *query_extension_reply;
if (have_dpms != -1) { // already checked
return have_dpms;
}
have_dpms = 0;
query_extension_reply = xcb_get_extension_data(connection, &xcb_dpms_id);
if (query_extension_reply && query_extension_reply->present) {
xcb_dpms_get_version_cookie_t cookie;
xcb_dpms_get_version_reply_t *reply;
int major;
int minor;
Debug(3, "video: dpms extension present\n");
cookie =
xcb_dpms_get_version_unchecked(connection, XCB_DPMS_MAJOR_VERSION,
XCB_DPMS_MINOR_VERSION);
reply = xcb_dpms_get_version_reply(connection, cookie, NULL);
// use locals to avoid gcc warning
major = XCB_DPMS_MAJOR_VERSION;
minor = XCB_DPMS_MINOR_VERSION;
if (reply && (reply->server_major_version >= major)
&& (reply->server_minor_version >= minor)
) {
have_dpms = 1;
}
free(reply);
}
return have_dpms;
}
///
/// Disable DPMS (Display Power Management Signaling)
///
/// @param connection X11 connection to disable DPMS
///
static void X11DPMSDisable(xcb_connection_t * connection)
{
if (X11HaveDPMS(connection)) {
xcb_dpms_info_cookie_t cookie;
xcb_dpms_info_reply_t *reply;
cookie = xcb_dpms_info_unchecked(connection);
reply = xcb_dpms_info_reply(connection, cookie, NULL);
if (reply) {
if (reply->state) {
Debug(3, "video: dpms was enabled\n");
DPMSDisabled = 1;
xcb_dpms_disable(connection); // monitor powersave off
}
free(reply);
}
}
}
///
/// Reenable DPMS (Display Power Management Signaling)
///
/// @param connection X11 connection to enable DPMS
///
static void X11DPMSReenable(xcb_connection_t * connection)
{
if (DPMSDisabled && X11HaveDPMS(connection)) {
xcb_dpms_enable(connection); // monitor powersave on
xcb_dpms_force_level(connection, XCB_DPMS_DPMS_MODE_ON);
DPMSDisabled = 0;
}
}
#else
/// dummy function: Suspend X11 screen saver.
#define X11SuspendScreenSaver(connection, suspend)
/// dummy function: Disable X11 DPMS.
#define X11DPMSDisable(connection)
/// dummy function: Reenable X11 DPMS.
#define X11DPMSReenable(connection)
#endif
//----------------------------------------------------------------------------
// Setup
//----------------------------------------------------------------------------
@ -9402,10 +9535,12 @@ void VideoInit(const char *display_name)
}
// prefetch extensions
//xcb_prefetch_extension_data(Connection, &xcb_big_requests_id);
//xcb_prefetch_extension_data(Connection, &xcb_dpms_id);
//xcb_prefetch_extension_data(Connection, &xcb_glx_id);
//xcb_prefetch_extension_data(Connection, &xcb_randr_id);
//xcb_prefetch_extension_data(Connection, &xcb_screensaver_id);
#ifdef USE_SCREENSAVER
xcb_prefetch_extension_data(Connection, &xcb_screensaver_id);
xcb_prefetch_extension_data(Connection, &xcb_dpms_id);
#endif
//xcb_prefetch_extension_data(Connection, &xcb_shm_id);
//xcb_prefetch_extension_data(Connection, &xcb_xv_id);
@ -9488,6 +9623,10 @@ void VideoInit(const char *display_name)
if (getenv("STUDIO_LEVELS")) {
VideoStudioLevels = 1;
}
// disable x11 screensaver
X11SuspendScreenSaver(Connection, 1);
X11DPMSDisable(Connection);
//xcb_prefetch_maximum_request_length(Connection);
xcb_flush(Connection);
@ -9507,6 +9646,10 @@ void VideoExit(void)
if (!XlibDisplay) { // no init or failed
return;
}
// reenable x11 screensaver
X11DPMSReenable(Connection);
X11SuspendScreenSaver(Connection, 0);
#ifdef USE_VIDEO_THREAD
VideoThreadExit();
// VDPAU cleanup hangs in XLockDisplay every 100 exits