1 #include "ecore_xcb_private.h"
2 #ifdef ECORE_XCB_DAMAGE
7 static Eina_Bool _dpms_avail = EINA_FALSE;
10 _ecore_xcb_dpms_init(void)
12 LOGFN(__FILE__, __LINE__, __FUNCTION__);
15 xcb_prefetch_extension_data(_ecore_xcb_conn, &xcb_dpms_id);
20 _ecore_xcb_dpms_finalize(void)
23 const xcb_query_extension_reply_t *ext_reply;
26 LOGFN(__FILE__, __LINE__, __FUNCTION__);
29 ext_reply = xcb_get_extension_data(_ecore_xcb_conn, &xcb_dpms_id);
30 if ((ext_reply) && (ext_reply->present))
32 xcb_dpms_get_version_cookie_t cookie;
33 xcb_dpms_get_version_reply_t *reply;
36 xcb_dpms_get_version_unchecked(_ecore_xcb_conn,
37 XCB_DPMS_MAJOR_VERSION,
38 XCB_DPMS_MINOR_VERSION);
39 reply = xcb_dpms_get_version_reply(_ecore_xcb_conn, cookie, NULL);
42 if (reply->server_major_version >= 1)
43 _dpms_avail = EINA_TRUE;
51 * @defgroup Ecore_X_DPMS_Group X DPMS Extension Functions
52 * @ingroup Ecore_X_Group
54 * Functions related to the X DPMS Extension
58 * Checks if the DPMS extension is available or not.
60 * @return @c EINA_TRUE if the DPMS extension is available,
61 * @c EINA_FALSE otherwise.
63 * Return @c EINA_TRUE if the X server supports the DPMS Extension version 1.0,
64 * @c EINA_FALSE otherwise.
66 * @ingroup Ecore_X_DPMS_Group
69 ecore_x_dpms_query(void)
71 // LOGFN(__FILE__, __LINE__, __FUNCTION__);
77 * Checks if the X server is capable of DPMS.
78 * @return @c 1 if the X server is capable of DPMS, @c 0 otherwise.
79 * @ingroup Ecore_X_DPMS_Group
82 ecore_x_dpms_capable_get(void)
84 Eina_Bool ret = EINA_FALSE;
86 xcb_dpms_capable_cookie_t cookie;
87 xcb_dpms_capable_reply_t *reply;
90 LOGFN(__FILE__, __LINE__, __FUNCTION__);
93 if (!_dpms_avail) return EINA_FALSE;
96 cookie = xcb_dpms_capable_unchecked(_ecore_xcb_conn);
97 reply = xcb_dpms_capable_reply(_ecore_xcb_conn, cookie, NULL);
100 ret = reply->capable;
109 * Checks the DPMS state of the display.
110 * @return @c EINA_TRUE if DPMS is enabled, @c EINA_FALSE otherwise.
111 * @ingroup Ecore_X_DPMS_Group
114 ecore_x_dpms_enabled_get(void)
116 Eina_Bool ret = EINA_FALSE;
117 #ifdef ECORE_XCB_DPMS
118 xcb_dpms_info_cookie_t cookie;
119 xcb_dpms_info_reply_t *reply;
122 LOGFN(__FILE__, __LINE__, __FUNCTION__);
125 if (!_dpms_avail) return EINA_FALSE;
127 #ifdef ECORE_XCB_DPMS
128 cookie = xcb_dpms_info_unchecked(_ecore_xcb_conn);
129 reply = xcb_dpms_info_reply(_ecore_xcb_conn, cookie, NULL);
130 if (!reply) return EINA_FALSE;
131 if (reply->state) ret = EINA_TRUE;
139 * Sets the DPMS state of the display.
140 * @param enabled @c 0 to disable DPMS characteristics of the server, enable it otherwise.
141 * @ingroup Ecore_X_DPMS_Group
144 ecore_x_dpms_enabled_set(int enabled)
146 LOGFN(__FILE__, __LINE__, __FUNCTION__);
149 if (!_dpms_avail) return;
151 #ifdef ECORE_XCB_DPMS
153 xcb_dpms_enable(_ecore_xcb_conn);
155 xcb_dpms_disable(_ecore_xcb_conn);
160 * Gets the timeouts. The values are in unit of seconds.
161 * @param standby Amount of time of inactivity before standby mode will be invoked.
162 * @param suspend Amount of time of inactivity before the screen is placed into suspend mode.
163 * @param off Amount of time of inactivity before the monitor is shut off.
164 * @ingroup Ecore_X_DPMS_Group
167 ecore_x_dpms_timeouts_get(unsigned int *standby,
168 unsigned int *suspend,
171 #ifdef ECORE_XCB_DPMS
172 xcb_dpms_get_timeouts_cookie_t cookie;
173 xcb_dpms_get_timeouts_reply_t *reply;
176 LOGFN(__FILE__, __LINE__, __FUNCTION__);
179 if (standby) *standby = 0;
180 if (suspend) *suspend = 0;
183 if (!_dpms_avail) return;
185 #ifdef ECORE_XCB_DPMS
186 cookie = xcb_dpms_get_timeouts_unchecked(_ecore_xcb_conn);
187 reply = xcb_dpms_get_timeouts_reply(_ecore_xcb_conn, cookie, NULL);
189 if (standby) *standby = reply->standby_timeout;
190 if (suspend) *suspend = reply->suspend_timeout;
191 if (off) *off = reply->off_timeout;
197 * Sets the timeouts. The values are in unit of seconds.
199 * @param standby Amount of time of inactivity before standby mode will be invoked.
200 * @param suspend Amount of time of inactivity before the screen is placed into suspend mode.
201 * @param off Amount of time of inactivity before the monitor is shut off.
202 * @return @c EINA_TRUE on success, @c EINA_FALSE on failure.
203 * @ingroup Ecore_X_DPMS_Group
206 ecore_x_dpms_timeouts_set(unsigned int standby,
207 unsigned int suspend,
210 LOGFN(__FILE__, __LINE__, __FUNCTION__);
213 if (!_dpms_avail) return EINA_FALSE;
215 #ifdef ECORE_XCB_DPMS
216 // FIXME: Add request check
217 xcb_dpms_set_timeouts(_ecore_xcb_conn, standby, suspend, off);
225 * Returns the amount of time of inactivity before standby mode is invoked.
226 * @return The standby timeout value.
227 * @ingroup Ecore_X_DPMS_Group
230 ecore_x_dpms_timeout_standby_get(void)
232 unsigned int standby = 0;
234 LOGFN(__FILE__, __LINE__, __FUNCTION__);
236 ecore_x_dpms_timeouts_get(&standby, NULL, NULL);
241 * Returns the amount of time of inactivity before the second level of
242 * power saving is invoked.
243 * @return The suspend timeout value.
244 * @ingroup Ecore_X_DPMS_Group
247 ecore_x_dpms_timeout_suspend_get(void)
249 unsigned int suspend = 0;
251 LOGFN(__FILE__, __LINE__, __FUNCTION__);
253 ecore_x_dpms_timeouts_get(NULL, &suspend, NULL);
258 * Returns the amount of time of inactivity before the third and final
259 * level of power saving is invoked.
260 * @return The off timeout value.
261 * @ingroup Ecore_X_DPMS_Group
264 ecore_x_dpms_timeout_off_get(void)
266 unsigned int off = 0;
268 LOGFN(__FILE__, __LINE__, __FUNCTION__);
270 ecore_x_dpms_timeouts_get(NULL, NULL, &off);
275 * Sets the standby timeout (in unit of seconds).
276 * @param new_timeout Amount of time of inactivity before standby mode will be invoked.
277 * @ingroup Ecore_X_DPMS_Group
280 ecore_x_dpms_timeout_standby_set(unsigned int new_timeout)
282 unsigned int standby = 0, suspend = 0, off = 0;
284 LOGFN(__FILE__, __LINE__, __FUNCTION__);
286 ecore_x_dpms_timeouts_get(&standby, &suspend, &off);
287 ecore_x_dpms_timeouts_set(new_timeout, suspend, off);
291 * Sets the suspend timeout (in unit of seconds).
292 * @param new_timeout Amount of time of inactivity before the screen is placed into suspend mode.
293 * @ingroup Ecore_X_DPMS_Group
296 ecore_x_dpms_timeout_suspend_set(unsigned int new_timeout)
298 unsigned int standby = 0, suspend = 0, off = 0;
300 LOGFN(__FILE__, __LINE__, __FUNCTION__);
302 ecore_x_dpms_timeouts_get(&standby, &suspend, &off);
303 ecore_x_dpms_timeouts_set(standby, new_timeout, off);
307 * Sets the off timeout (in unit of seconds).
308 * @param new_timeout Amount of time of inactivity before the monitor is shut off.
309 * @ingroup Ecore_X_DPMS_Group
312 ecore_x_dpms_timeout_off_set(unsigned int new_timeout)
314 unsigned int standby = 0, suspend = 0, off = 0;
316 LOGFN(__FILE__, __LINE__, __FUNCTION__);
318 ecore_x_dpms_timeouts_get(&standby, &suspend, &off);
319 ecore_x_dpms_timeouts_set(standby, suspend, new_timeout);
323 * Check the DPMS power level.
324 * @return @c 0 if DPMS is :In Use
325 * @return @c 1 if DPMS is :Blanked, low power
326 * @return @c 2 if DPMS is :Blanked, lower power
327 * @return @c 3 if DPMS is :Shut off, awaiting activity
328 * @return @c -1 otherwise.
330 EAPI Ecore_X_Dpms_Mode
331 ecore_x_dpms_power_level_get(void)
333 Ecore_X_Dpms_Mode ret = -1;
334 #ifdef ECORE_XCB_DPMS
335 xcb_dpms_info_cookie_t cookie;
336 xcb_dpms_info_reply_t *reply;
339 LOGFN(__FILE__, __LINE__, __FUNCTION__);
342 if (!_dpms_avail) return ret;
344 #ifdef ECORE_XCB_DPMS
345 cookie = xcb_dpms_info_unchecked(_ecore_xcb_conn);
346 reply = xcb_dpms_info_reply(_ecore_xcb_conn, cookie, NULL);
347 if (!reply) return -1;
349 ret = reply->power_level;