svn update: 48958 (latest:48959)
[framework/uifw/ecore.git] / src / lib / ecore_x / xlib / ecore_x_dpms.c
1 /*
2  * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
3  */
4
5 #ifdef HAVE_CONFIG_H
6 # include <config.h>
7 #endif
8
9 #include "ecore_x_private.h"
10
11 static int _dpms_available;
12
13 void
14 _ecore_x_dpms_init(void)
15 {
16 #ifdef ECORE_XDPMS
17    int _dpms_major, _dpms_minor;
18
19    _dpms_major = 1;
20    _dpms_minor = 0;
21
22    if (DPMSGetVersion(_ecore_x_disp, &_dpms_major, &_dpms_minor))
23      _dpms_available = 1;
24    else
25      _dpms_available = 0;
26 #else
27    _dpms_available = 0;
28 #endif
29 }
30
31 /**
32  * @defgroup Ecore_X_DPMS_Group X DPMS Extension Functions
33  *
34  * Functions related to the X DPMS extension.
35  */
36
37 /**
38  * Checks if the X DPMS extension is available on the server.
39  * @return @c 1 if the X DPMS extension is available, @c 0 otherwise.
40  * @ingroup Ecore_X_DPMS_Group
41  */
42 EAPI int
43 ecore_x_dpms_query(void)
44 {
45    return _dpms_available;
46 }
47
48 /**
49  * Checks if the X server is capable of DPMS.
50  * @return @c 1 if the X server is capable of DPMS, @c 0 otherwise.
51  * @ingroup Ecore_X_DPMS_Group
52  */
53 EAPI int
54 ecore_x_dpms_capable_get(void)
55 {
56 #ifdef ECORE_XDPMS
57    LOGFN(__FILE__, __LINE__, __FUNCTION__);
58    return DPMSCapable(_ecore_x_disp);
59 #else
60    return 0;
61 #endif
62 }
63
64 /**
65  * Checks the DPMS state of the display.
66  * @return @c 1 if DPMS is enabled, @c 0 otherwise.
67  * @ingroup Ecore_X_DPMS_Group
68  */
69 EAPI int
70 ecore_x_dpms_enabled_get(void)
71 {
72 #ifdef ECORE_XDPMS
73    unsigned char state;
74    unsigned short power_lvl;
75
76    LOGFN(__FILE__, __LINE__, __FUNCTION__);
77    DPMSInfo(_ecore_x_disp, &power_lvl, &state);
78    return state;
79 #else
80    return 0;
81 #endif
82 }
83
84 /**
85  * Sets the DPMS state of the display.
86  * @param enabled @c 0 to disable DPMS characteristics of the server, enable it otherwise.
87  * @ingroup Ecore_X_DPMS_Group
88  */
89 EAPI void
90 ecore_x_dpms_enabled_set(int enabled)
91 {
92 #ifdef ECORE_XDPMS
93    LOGFN(__FILE__, __LINE__, __FUNCTION__);
94    if (enabled)
95      DPMSEnable(_ecore_x_disp);
96    else
97      DPMSDisable(_ecore_x_disp);
98 #endif
99 }
100
101 /**
102  * Gets the timeouts. The values are in unit of seconds.
103  * @param standby Amount of time of inactivity before standby mode will be invoked.
104  * @param suspend Amount of time of inactivity before the screen is placed into suspend mode.
105  * @param off     Amount of time of inactivity before the monitor is shut off.
106  * @ingroup Ecore_X_DPMS_Group
107  */
108 EAPI void
109 ecore_x_dpms_timeouts_get(unsigned int *standby, unsigned int *suspend, unsigned int *off)
110 {
111 #ifdef ECORE_XDPMS
112    LOGFN(__FILE__, __LINE__, __FUNCTION__);
113    DPMSGetTimeouts(_ecore_x_disp, (unsigned short *)standby, 
114                    (unsigned short *)suspend, (unsigned short *)off);
115 #endif
116 }
117
118 /**
119  * Sets the timeouts. The values are in unit of seconds.
120  * @param standby Amount of time of inactivity before standby mode will be invoked.
121  * @param suspend Amount of time of inactivity before the screen is placed into suspend mode.
122  * @param off     Amount of time of inactivity before the monitor is shut off.
123  * @ingroup Ecore_X_DPMS_Group
124  */
125 EAPI int
126 ecore_x_dpms_timeouts_set(unsigned int standby, unsigned int suspend, unsigned int off)
127 {
128 #ifdef ECORE_XDPMS
129    LOGFN(__FILE__, __LINE__, __FUNCTION__);
130    return DPMSSetTimeouts(_ecore_x_disp, standby, suspend, off);
131 #else
132    return 0;
133 #endif
134 }
135
136 /**
137  * Returns the amount of time of inactivity before standby mode is invoked.
138  * @return The standby timeout value.
139  * @ingroup Ecore_X_DPMS_Group
140  */
141 EAPI unsigned int
142 ecore_x_dpms_timeout_standby_get()
143 {
144 #ifdef ECORE_XDPMS
145    unsigned short standby, suspend, off;
146
147    LOGFN(__FILE__, __LINE__, __FUNCTION__);
148    DPMSGetTimeouts(_ecore_x_disp, &standby, &suspend, &off);
149    return standby;
150 #else
151    return 0;
152 #endif
153 }
154
155 /**
156  * Returns the amount of time of inactivity before the second level of
157  * power saving is invoked.
158  * @return The suspend timeout value.
159  * @ingroup Ecore_X_DPMS_Group
160  */
161 EAPI unsigned int
162 ecore_x_dpms_timeout_suspend_get()
163 {
164 #ifdef ECORE_XDPMS
165    unsigned short standby, suspend, off;
166
167    LOGFN(__FILE__, __LINE__, __FUNCTION__);
168    DPMSGetTimeouts(_ecore_x_disp, &standby, &suspend, &off);
169    return suspend;
170 #else
171    return 0;
172 #endif
173 }
174
175 /**
176  * Returns the amount of time of inactivity before the third and final
177  * level of power saving is invoked.
178  * @return The off timeout value.
179  * @ingroup Ecore_X_DPMS_Group
180  */
181 EAPI unsigned int
182 ecore_x_dpms_timeout_off_get()
183 {
184 #ifdef ECORE_XDPMS
185    unsigned short standby, suspend, off;
186
187    LOGFN(__FILE__, __LINE__, __FUNCTION__);
188    DPMSGetTimeouts(_ecore_x_disp, &standby, &suspend, &off);
189    return off;
190 #else
191    return 0;
192 #endif
193 }
194
195 /**
196  * Sets the standby timeout (in unit of seconds).
197  * @param new_standby Amount of time of inactivity before standby mode will be invoked.
198  * @ingroup Ecore_X_DPMS_Group
199  */
200 EAPI void
201 ecore_x_dpms_timeout_standby_set(unsigned int new_timeout)
202 {
203 #ifdef ECORE_XDPMS
204    unsigned short standby, suspend, off;
205
206    LOGFN(__FILE__, __LINE__, __FUNCTION__);
207    DPMSGetTimeouts(_ecore_x_disp, &standby, &suspend, &off);
208    DPMSSetTimeouts(_ecore_x_disp, new_timeout, suspend, off);
209 #endif
210 }
211
212 /**
213  * Sets the suspend timeout (in unit of seconds).
214  * @param suspend Amount of time of inactivity before the screen is placed into suspend mode.
215  * @ingroup Ecore_X_DPMS_Group
216  */
217 EAPI void
218 ecore_x_dpms_timeout_suspend_set(unsigned int new_timeout)
219 {
220 #ifdef ECORE_XDPMS
221    unsigned short standby, suspend, off;
222
223    LOGFN(__FILE__, __LINE__, __FUNCTION__);
224    DPMSGetTimeouts(_ecore_x_disp, &standby, &suspend, &off);
225    DPMSSetTimeouts(_ecore_x_disp, standby, new_timeout, off);
226 #endif
227 }
228
229 /**
230  * Sets the off timeout (in unit of seconds).
231  * @param off     Amount of time of inactivity before the monitor is shut off.
232  * @ingroup Ecore_X_DPMS_Group
233  */
234 EAPI void
235 ecore_x_dpms_timeout_off_set(unsigned int new_timeout)
236 {
237 #ifdef ECORE_XDPMS
238    unsigned short standby, suspend, off;
239
240    LOGFN(__FILE__, __LINE__, __FUNCTION__);
241    DPMSGetTimeouts(_ecore_x_disp, &standby, &suspend, &off);
242    DPMSSetTimeouts(_ecore_x_disp, standby, suspend, new_timeout);
243 #endif
244 }