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