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
53 * Functions related to the X DPMS Extension
57 * Checks if the DPMS extension is available or not.
59 * @return @c EINA_TRUE if the DPMS extension is available,
60 * @c EINA_FALSE otherwise.
62 * Return @c EINA_TRUE if the X server supports the DPMS Extension version 1.0,
63 * @c EINA_FALSE otherwise.
65 * @ingroup Ecore_X_DPMS_Group
68 ecore_x_dpms_query(void)
70 // LOGFN(__FILE__, __LINE__, __FUNCTION__);
76 * Checks if the X server is capable of DPMS.
77 * @return @c 1 if the X server is capable of DPMS, @c 0 otherwise.
78 * @ingroup Ecore_X_DPMS_Group
81 ecore_x_dpms_capable_get(void)
83 Eina_Bool ret = EINA_FALSE;
85 xcb_dpms_capable_cookie_t cookie;
86 xcb_dpms_capable_reply_t *reply;
89 LOGFN(__FILE__, __LINE__, __FUNCTION__);
92 if (!_dpms_avail) return EINA_FALSE;
95 cookie = xcb_dpms_capable_unchecked(_ecore_xcb_conn);
96 reply = xcb_dpms_capable_reply(_ecore_xcb_conn, cookie, NULL);
108 * Checks the DPMS state of the display.
109 * @return @c EINA_TRUE if DPMS is enabled, @c EINA_FALSE otherwise.
110 * @ingroup Ecore_X_DPMS_Group
113 ecore_x_dpms_enabled_get(void)
115 Eina_Bool ret = EINA_FALSE;
116 #ifdef ECORE_XCB_DPMS
117 xcb_dpms_info_cookie_t cookie;
118 xcb_dpms_info_reply_t *reply;
121 LOGFN(__FILE__, __LINE__, __FUNCTION__);
124 if (!_dpms_avail) return EINA_FALSE;
126 #ifdef ECORE_XCB_DPMS
127 cookie = xcb_dpms_info_unchecked(_ecore_xcb_conn);
128 reply = xcb_dpms_info_reply(_ecore_xcb_conn, cookie, NULL);
129 if (!reply) return EINA_FALSE;
130 if (reply->state) ret = EINA_TRUE;
138 * Sets the DPMS state of the display.
139 * @param enabled @c 0 to disable DPMS characteristics of the server, enable it otherwise.
140 * @ingroup Ecore_X_DPMS_Group
143 ecore_x_dpms_enabled_set(int enabled)
145 LOGFN(__FILE__, __LINE__, __FUNCTION__);
148 if (!_dpms_avail) return;
150 #ifdef ECORE_XCB_DPMS
152 xcb_dpms_enable(_ecore_xcb_conn);
154 xcb_dpms_disable(_ecore_xcb_conn);
159 * Gets the timeouts. The values are in unit of seconds.
160 * @param standby Amount of time of inactivity before standby mode will be invoked.
161 * @param suspend Amount of time of inactivity before the screen is placed into suspend mode.
162 * @param off Amount of time of inactivity before the monitor is shut off.
163 * @ingroup Ecore_X_DPMS_Group
166 ecore_x_dpms_timeouts_get(unsigned int *standby,
167 unsigned int *suspend,
170 #ifdef ECORE_XCB_DPMS
171 xcb_dpms_get_timeouts_cookie_t cookie;
172 xcb_dpms_get_timeouts_reply_t *reply;
175 LOGFN(__FILE__, __LINE__, __FUNCTION__);
178 if (standby) *standby = 0;
179 if (suspend) *suspend = 0;
182 if (!_dpms_avail) return;
184 #ifdef ECORE_XCB_DPMS
185 cookie = xcb_dpms_get_timeouts_unchecked(_ecore_xcb_conn);
186 reply = xcb_dpms_get_timeouts_reply(_ecore_xcb_conn, cookie, NULL);
188 if (standby) *standby = reply->standby_timeout;
189 if (suspend) *suspend = reply->suspend_timeout;
190 if (off) *off = reply->off_timeout;
196 * Sets the timeouts. The values are in unit of seconds.
198 * @param standby Amount of time of inactivity before standby mode will be invoked.
199 * @param suspend Amount of time of inactivity before the screen is placed into suspend mode.
200 * @param off Amount of time of inactivity before the monitor is shut off.
201 * @return @c EINA_TRUE on success, @c EINA_FALSE on failure.
202 * @ingroup Ecore_X_DPMS_Group
205 ecore_x_dpms_timeouts_set(unsigned int standby,
206 unsigned int suspend,
209 LOGFN(__FILE__, __LINE__, __FUNCTION__);
212 if (!_dpms_avail) return EINA_FALSE;
214 #ifdef ECORE_XCB_DPMS
215 // FIXME: Add request check
216 xcb_dpms_set_timeouts(_ecore_xcb_conn, standby, suspend, off);
224 * Returns the amount of time of inactivity before standby mode is invoked.
225 * @return The standby timeout value.
226 * @ingroup Ecore_X_DPMS_Group
229 ecore_x_dpms_timeout_standby_get(void)
231 unsigned int standby = 0;
233 LOGFN(__FILE__, __LINE__, __FUNCTION__);
235 ecore_x_dpms_timeouts_get(&standby, NULL, NULL);
240 * Returns the amount of time of inactivity before the second level of
241 * power saving is invoked.
242 * @return The suspend timeout value.
243 * @ingroup Ecore_X_DPMS_Group
246 ecore_x_dpms_timeout_suspend_get(void)
248 unsigned int suspend = 0;
250 LOGFN(__FILE__, __LINE__, __FUNCTION__);
252 ecore_x_dpms_timeouts_get(NULL, &suspend, NULL);
257 * Returns the amount of time of inactivity before the third and final
258 * level of power saving is invoked.
259 * @return The off timeout value.
260 * @ingroup Ecore_X_DPMS_Group
263 ecore_x_dpms_timeout_off_get(void)
265 unsigned int off = 0;
267 LOGFN(__FILE__, __LINE__, __FUNCTION__);
269 ecore_x_dpms_timeouts_get(NULL, NULL, &off);
274 * Sets the standby timeout (in unit of seconds).
275 * @param new_timeout Amount of time of inactivity before standby mode will be invoked.
276 * @ingroup Ecore_X_DPMS_Group
279 ecore_x_dpms_timeout_standby_set(unsigned int new_timeout)
281 unsigned int standby = 0, suspend = 0, off = 0;
283 LOGFN(__FILE__, __LINE__, __FUNCTION__);
285 ecore_x_dpms_timeouts_get(&standby, &suspend, &off);
286 ecore_x_dpms_timeouts_set(new_timeout, suspend, off);
290 * Sets the suspend timeout (in unit of seconds).
291 * @param new_timeout Amount of time of inactivity before the screen is placed into suspend mode.
292 * @ingroup Ecore_X_DPMS_Group
295 ecore_x_dpms_timeout_suspend_set(unsigned int new_timeout)
297 unsigned int standby = 0, suspend = 0, off = 0;
299 LOGFN(__FILE__, __LINE__, __FUNCTION__);
301 ecore_x_dpms_timeouts_get(&standby, &suspend, &off);
302 ecore_x_dpms_timeouts_set(standby, new_timeout, off);
306 * Sets the off timeout (in unit of seconds).
307 * @param new_timeout Amount of time of inactivity before the monitor is shut off.
308 * @ingroup Ecore_X_DPMS_Group
311 ecore_x_dpms_timeout_off_set(unsigned int new_timeout)
313 unsigned int standby = 0, suspend = 0, off = 0;
315 LOGFN(__FILE__, __LINE__, __FUNCTION__);
317 ecore_x_dpms_timeouts_get(&standby, &suspend, &off);
318 ecore_x_dpms_timeouts_set(standby, suspend, new_timeout);