Debian Codegraph @

lib/video/VideoDPMS.cpp

raw
1 #include "VideoDPMS.h"
2 #include "avm_output.h"
3
4 #ifdef HAVE_DPMS
5 #include <X11/X.h>
6 #include <X11/Xlib.h>
7 #include <X11/Xutil.h>
8 #include <X11/Xmd.h>
9 #endif
10
11 #ifdef HAVE_OK_DPMS_H
12 extern "C"
13 {
14 #include <X11/extensions/dpms.h>
15 }
16
17 //#include <stdio.h>
18
19 #ifndef sun
20 // on linux its just int
21 #undef CARD32
22 #define CARD32 int
23 #endif // sun
24
25 #else // !HAVE_OK_DPMS_H
26
27 #ifndef sun
28 #undef CARD32
29 #define CARD32 int
30 #endif // sun
31 /* there are several prototypes missing on solaris 8: */
32 #ifdef HAVE_DPMS
33 extern "C"
34 {
35 Bool DPMSQueryExtension(Display*, CARD32*, CARD32*);
36 Status DPMSEnable(Display*);
37 Status DPMSDisable(Display*);
38 Status DPMSInfo(Display*, CARD16*, BOOL*);
39 }
40 #endif
41
42 #endif // !HAVE_OK_DPMS_H
43
44 AVM_BEGIN_NAMESPACE;
45
46 // copy from mplayer
47 // FIXME - create class and add it as a member later..
48 // with construtor Off destructor On
49 VideoDPMS::VideoDPMS(Display *dpy)
50 :m_pDisplay(dpy), m_bDisabled(false)
51 {
52 #ifdef HAVE_DPMS
53 int interval, prefer_blank, allow_exp;
54 CARD32 nothing;
55
56 if (DPMSQueryExtension(m_pDisplay, &nothing, &nothing))
57 {
58 BOOL onoff;
59 CARD16 state;
60 DPMSInfo(m_pDisplay, &state, &onoff);
61 if (onoff)
62 {
63 AVM_WRITE("DPMS module", "Disabling DPMS\n");
64 m_bDisabled = true;
65 DPMSDisable(m_pDisplay); // monitor powersave off
66 }
67 }
68 XGetScreenSaver(m_pDisplay, &m_iTimeoutSave, &interval, &prefer_blank, &allow_exp);
69 if (m_iTimeoutSave)
70 // turning off screensaver
71 XSetScreenSaver(m_pDisplay, 0, interval, prefer_blank, allow_exp);
72 #else
73 AVM_WRITE("DPMS module", "DPMS suppport not compiled\n");
74
75 #endif
76 }
77
78 VideoDPMS::~VideoDPMS()
79 {
80 #ifdef HAVE_DPMS
81 CARD32 nothing;
82
83 if (m_bDisabled)
84 {
85 if (DPMSQueryExtension(m_pDisplay, &nothing, &nothing))
86 {
87 AVM_WRITE("DPMS module", "Enabling DPMS\n");
88 DPMSEnable(m_pDisplay); // restoring power saving settings
89 DPMSQueryExtension(m_pDisplay, &nothing, &nothing);
90 }
91 }
92
93 if (m_iTimeoutSave)
94 {
95 int dummy, interval, prefer_blank, allow_exp;
96 XGetScreenSaver(m_pDisplay, &dummy, &interval, &prefer_blank, &allow_exp);
97 XSetScreenSaver(m_pDisplay, m_iTimeoutSave, interval, prefer_blank, allow_exp);
98 XGetScreenSaver(m_pDisplay, &m_iTimeoutSave, &interval, &prefer_blank, &allow_exp);
99 }
100 #endif
101 }
102
103 AVM_END_NAMESPACE;