1 #ifdef HAVE_CONFIG_H
2 # include <config.h>
3 #endif /* ifdef HAVE_CONFIG_H */
4
5 #include "ecore_x_private.h"
6
7 static Eina_Bool _dpms_available = EINA_FALSE;
8
9 void
_ecore_x_dpms_init(void)10 _ecore_x_dpms_init(void)
11 {
12 #ifdef ECORE_XDPMS
13 int _dpms_major, _dpms_minor;
14
15 EINA_SAFETY_ON_NULL_RETURN(_ecore_x_disp);
16
17 _dpms_major = 1;
18 _dpms_minor = 0;
19
20 if (DPMSGetVersion(_ecore_x_disp, &_dpms_major, &_dpms_minor))
21 _dpms_available = EINA_TRUE;
22 else
23 _dpms_available = EINA_FALSE;
24
25 #else /* ifdef ECORE_XDPMS */
26 _dpms_available = EINA_FALSE;
27 #endif /* ifdef ECORE_XDPMS */
28 }
29
30 /**
31 * @defgroup Ecore_X_DPMS_Group X DPMS Extension Functions
32 * @ingroup Ecore_X_Group
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 Eina_Bool
ecore_x_dpms_query(void)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 Eina_Bool
ecore_x_dpms_capable_get(void)54 ecore_x_dpms_capable_get(void)
55 {
56 #ifdef ECORE_XDPMS
57 LOGFN;
58 EINA_SAFETY_ON_NULL_RETURN_VAL(_ecore_x_disp, EINA_FALSE);
59 return DPMSCapable(_ecore_x_disp) ? EINA_TRUE : EINA_FALSE;
60 #else /* ifdef ECORE_XDPMS */
61 return EINA_FALSE;
62 #endif /* ifdef ECORE_XDPMS */
63 }
64
65 /**
66 * Checks the DPMS state of the display.
67 * @return @c 1 if DPMS is enabled, @c 0 otherwise.
68 * @ingroup Ecore_X_DPMS_Group
69 */
70 EAPI Eina_Bool
ecore_x_dpms_enabled_get(void)71 ecore_x_dpms_enabled_get(void)
72 {
73 #ifdef ECORE_XDPMS
74 unsigned char state;
75 unsigned short power_lvl;
76
77 LOGFN;
78 EINA_SAFETY_ON_NULL_RETURN_VAL(_ecore_x_disp, EINA_FALSE);
79 DPMSInfo(_ecore_x_disp, &power_lvl, &state);
80 return state ? EINA_TRUE : EINA_FALSE;
81 #else /* ifdef ECORE_XDPMS */
82 return EINA_FALSE;
83 #endif /* ifdef ECORE_XDPMS */
84 }
85
86 /**
87 * Check the DPMS power level.
88 * @return @c 0 if DPMS is :In Use
89 * @return @c 1 if DPMS is :Blanked, low power
90 * @return @c 2 if DPMS is :Blanked, lower power
91 * @return @c 3 if DPMS is :Shut off, awaiting activity
92 * @return @c -1 othwhise.
93 */
94
95 EAPI Ecore_X_Dpms_Mode
ecore_x_dpms_power_level_get(void)96 ecore_x_dpms_power_level_get(void)
97 {
98 #ifdef ECORE_XDPMS
99 unsigned char state;
100 unsigned short power_lvl;
101
102 LOGFN;
103 EINA_SAFETY_ON_NULL_RETURN_VAL(_ecore_x_disp, -1);
104 DPMSInfo(_ecore_x_disp, &power_lvl, &state);
105 return (int)power_lvl;
106 #else
107 return -1;
108 #endif
109 }
110
111 /**
112 * Sets the DPMS state of the display.
113 * @param enabled @c 0 to disable DPMS characteristics of the server, enable it otherwise.
114 * @ingroup Ecore_X_DPMS_Group
115 */
116 EAPI void
ecore_x_dpms_enabled_set(int enabled)117 ecore_x_dpms_enabled_set(int enabled)
118 {
119 #ifdef ECORE_XDPMS
120 LOGFN;
121 EINA_SAFETY_ON_NULL_RETURN(_ecore_x_disp);
122 if (enabled)
123 DPMSEnable(_ecore_x_disp);
124 else
125 DPMSDisable(_ecore_x_disp);
126
127 #endif /* ifdef ECORE_XDPMS */
128 }
129
130 /**
131 * Gets the timeouts. The values are in unit of seconds.
132 * @param standby Amount of time of inactivity before standby mode will be invoked.
133 * @param suspend Amount of time of inactivity before the screen is placed into suspend mode.
134 * @param off Amount of time of inactivity before the monitor is shut off.
135 * @ingroup Ecore_X_DPMS_Group
136 */
137 EAPI void
ecore_x_dpms_timeouts_get(unsigned int * standby,unsigned int * suspend,unsigned int * off)138 ecore_x_dpms_timeouts_get(unsigned int *standby,
139 unsigned int *suspend,
140 unsigned int *off)
141 {
142 #ifdef ECORE_XDPMS
143 LOGFN;
144 EINA_SAFETY_ON_NULL_RETURN(_ecore_x_disp);
145 DPMSGetTimeouts(_ecore_x_disp, (unsigned short *)standby,
146 (unsigned short *)suspend, (unsigned short *)off);
147 #endif /* ifdef ECORE_XDPMS */
148 }
149
150 /**
151 * Sets the timeouts. The values are in unit of seconds.
152 * @param standby Amount of time of inactivity before standby mode will be invoked.
153 * @param suspend Amount of time of inactivity before the screen is placed into suspend mode.
154 * @param off Amount of time of inactivity before the monitor is shut off.
155 * @ingroup Ecore_X_DPMS_Group
156 */
157 EAPI Eina_Bool
ecore_x_dpms_timeouts_set(unsigned int standby,unsigned int suspend,unsigned int off)158 ecore_x_dpms_timeouts_set(unsigned int standby,
159 unsigned int suspend,
160 unsigned int off)
161 {
162 #ifdef ECORE_XDPMS
163 LOGFN;
164 EINA_SAFETY_ON_NULL_RETURN_VAL(_ecore_x_disp, EINA_FALSE);
165 return DPMSSetTimeouts(_ecore_x_disp, standby, suspend, off) ? EINA_TRUE : EINA_FALSE;
166 #else /* ifdef ECORE_XDPMS */
167 return EINA_FALSE;
168 #endif /* ifdef ECORE_XDPMS */
169 }
170
171 /**
172 * Returns the amount of time of inactivity before standby mode is invoked.
173 * @return The standby timeout value.
174 * @ingroup Ecore_X_DPMS_Group
175 */
176 EAPI unsigned int
ecore_x_dpms_timeout_standby_get(void)177 ecore_x_dpms_timeout_standby_get(void)
178 {
179 #ifdef ECORE_XDPMS
180 unsigned short standby, suspend, off;
181
182 LOGFN;
183 EINA_SAFETY_ON_NULL_RETURN_VAL(_ecore_x_disp, 0);
184 DPMSGetTimeouts(_ecore_x_disp, &standby, &suspend, &off);
185 return standby;
186 #else /* ifdef ECORE_XDPMS */
187 return 0;
188 #endif /* ifdef ECORE_XDPMS */
189 }
190
191 /**
192 * Returns the amount of time of inactivity before the second level of
193 * power saving is invoked.
194 * @return The suspend timeout value.
195 * @ingroup Ecore_X_DPMS_Group
196 */
197 EAPI unsigned int
ecore_x_dpms_timeout_suspend_get(void)198 ecore_x_dpms_timeout_suspend_get(void)
199 {
200 #ifdef ECORE_XDPMS
201 unsigned short standby, suspend, off;
202
203 LOGFN;
204 EINA_SAFETY_ON_NULL_RETURN_VAL(_ecore_x_disp, 0);
205 DPMSGetTimeouts(_ecore_x_disp, &standby, &suspend, &off);
206 return suspend;
207 #else /* ifdef ECORE_XDPMS */
208 return 0;
209 #endif /* ifdef ECORE_XDPMS */
210 }
211
212 /**
213 * Returns the amount of time of inactivity before the third and final
214 * level of power saving is invoked.
215 * @return The off timeout value.
216 * @ingroup Ecore_X_DPMS_Group
217 */
218 EAPI unsigned int
ecore_x_dpms_timeout_off_get(void)219 ecore_x_dpms_timeout_off_get(void)
220 {
221 #ifdef ECORE_XDPMS
222 unsigned short standby, suspend, off;
223
224 LOGFN;
225 EINA_SAFETY_ON_NULL_RETURN_VAL(_ecore_x_disp, 0);
226 DPMSGetTimeouts(_ecore_x_disp, &standby, &suspend, &off);
227 return off;
228 #else /* ifdef ECORE_XDPMS */
229 return 0;
230 #endif /* ifdef ECORE_XDPMS */
231 }
232
233 /**
234 * Sets the standby timeout (in unit of seconds).
235 * @param new_timeout Amount of time of inactivity before standby mode will be invoked.
236 * @ingroup Ecore_X_DPMS_Group
237 */
238 EAPI void
ecore_x_dpms_timeout_standby_set(unsigned int new_timeout)239 ecore_x_dpms_timeout_standby_set(unsigned int new_timeout)
240 {
241 #ifdef ECORE_XDPMS
242 unsigned short standby, suspend, off;
243
244 LOGFN;
245 EINA_SAFETY_ON_NULL_RETURN(_ecore_x_disp);
246 DPMSGetTimeouts(_ecore_x_disp, &standby, &suspend, &off);
247 DPMSSetTimeouts(_ecore_x_disp, new_timeout, suspend, off);
248 #endif /* ifdef ECORE_XDPMS */
249 }
250
251 /**
252 * Sets the suspend timeout (in unit of seconds).
253 * @param new_timeout Amount of time of inactivity before the screen is placed into suspend mode.
254 * @ingroup Ecore_X_DPMS_Group
255 */
256 EAPI void
ecore_x_dpms_timeout_suspend_set(unsigned int new_timeout)257 ecore_x_dpms_timeout_suspend_set(unsigned int new_timeout)
258 {
259 #ifdef ECORE_XDPMS
260 unsigned short standby, suspend, off;
261
262 LOGFN;
263 EINA_SAFETY_ON_NULL_RETURN(_ecore_x_disp);
264 DPMSGetTimeouts(_ecore_x_disp, &standby, &suspend, &off);
265 DPMSSetTimeouts(_ecore_x_disp, standby, new_timeout, off);
266 #endif /* ifdef ECORE_XDPMS */
267 }
268
269 /**
270 * Sets the off timeout (in unit of seconds).
271 * @param new_timeout Amount of time of inactivity before the monitor is shut off.
272 * @ingroup Ecore_X_DPMS_Group
273 */
274 EAPI void
ecore_x_dpms_timeout_off_set(unsigned int new_timeout)275 ecore_x_dpms_timeout_off_set(unsigned int new_timeout)
276 {
277 #ifdef ECORE_XDPMS
278 unsigned short standby, suspend, off;
279
280 LOGFN;
281 EINA_SAFETY_ON_NULL_RETURN(_ecore_x_disp);
282 DPMSGetTimeouts(_ecore_x_disp, &standby, &suspend, &off);
283 DPMSSetTimeouts(_ecore_x_disp, standby, suspend, new_timeout);
284 #endif /* ifdef ECORE_XDPMS */
285 }
286
287 /**
288 * Forces DPMS on or off
289 * @param on If DPMS is to be forced on (EINA_TRUE) or forced off
290 * @ingroup Ecore_X_DPMS_Group
291 */
292 EAPI void
ecore_x_dpms_force(Eina_Bool on)293 ecore_x_dpms_force(Eina_Bool on)
294 {
295 #ifdef ECORE_XDPMS
296 LOGFN;
297 EINA_SAFETY_ON_NULL_RETURN(_ecore_x_disp);
298 if (on) DPMSForceLevel(_ecore_x_disp, DPMSModeOn);
299 else DPMSForceLevel(_ecore_x_disp, DPMSModeOff);
300 #endif /* ifdef ECORE_XDPMS */
301 }
302