aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/ecore_x/ecore_x_dpms.c
blob: ad946d45c9f2d93457fbfe9b0573f9d0e8c7347f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* ifdef HAVE_CONFIG_H */

#include "ecore_x_private.h"

static Eina_Bool _dpms_available = EINA_FALSE;

void
_ecore_x_dpms_init(void)
{
#ifdef ECORE_XDPMS
   int _dpms_major, _dpms_minor;

   EINA_SAFETY_ON_NULL_RETURN(_ecore_x_disp);

   _dpms_major = 1;
   _dpms_minor = 0;

   if (DPMSGetVersion(_ecore_x_disp, &_dpms_major, &_dpms_minor))
     _dpms_available = EINA_TRUE;
   else
     _dpms_available = EINA_FALSE;

#else /* ifdef ECORE_XDPMS */
   _dpms_available = EINA_FALSE;
#endif /* ifdef ECORE_XDPMS */
}

/**
 * @defgroup Ecore_X_DPMS_Group X DPMS Extension Functions
 * @ingroup Ecore_X_Group
 *
 * Functions related to the X DPMS extension.
 */

/**
 * Checks if the X DPMS extension is available on the server.
 * @return @c 1 if the X DPMS extension is available, @c 0 otherwise.
 * @ingroup Ecore_X_DPMS_Group
 */
EAPI Eina_Bool
ecore_x_dpms_query(void)
{
   return _dpms_available;
}

/**
 * Checks if the X server is capable of DPMS.
 * @return @c 1 if the X server is capable of DPMS, @c 0 otherwise.
 * @ingroup Ecore_X_DPMS_Group
 */
EAPI Eina_Bool
ecore_x_dpms_capable_get(void)
{
#ifdef ECORE_XDPMS
   LOGFN(__FILE__, __LINE__, __FUNCTION__);
   EINA_SAFETY_ON_NULL_RETURN_VAL(_ecore_x_disp, EINA_FALSE);
   return DPMSCapable(_ecore_x_disp) ? EINA_TRUE : EINA_FALSE;
#else /* ifdef ECORE_XDPMS */
   return EINA_FALSE;
#endif /* ifdef ECORE_XDPMS */
}

/**
 * Checks the DPMS state of the display.
 * @return @c 1 if DPMS is enabled, @c 0 otherwise.
 * @ingroup Ecore_X_DPMS_Group
 */
EAPI Eina_Bool
ecore_x_dpms_enabled_get(void)
{
#ifdef ECORE_XDPMS
   unsigned char state;
   unsigned short power_lvl;

   LOGFN(__FILE__, __LINE__, __FUNCTION__);
   EINA_SAFETY_ON_NULL_RETURN_VAL(_ecore_x_disp, EINA_FALSE);
   DPMSInfo(_ecore_x_disp, &power_lvl, &state);
   return state ? EINA_TRUE : EINA_FALSE;
#else /* ifdef ECORE_XDPMS */
   return EINA_FALSE;
#endif /* ifdef ECORE_XDPMS */
}

/**
 * Check the DPMS power level.
 * @return @c 0 if DPMS is :In Use
 * @return @c 1 if DPMS is :Blanked, low power
 * @return @c 2 if DPMS is :Blanked, lower power
 * @return @c 3 if DPMS is :Shut off, awaiting activity
 * @return @c -1 othwhise.
 */

EAPI Ecore_X_Dpms_Mode
ecore_x_dpms_power_level_get(void)
{
#ifdef ECORE_XDPMS
   unsigned char state;
   unsigned short power_lvl;

   LOGFN(__FILE__, __LINE__, __FUNCTION__);
   EINA_SAFETY_ON_NULL_RETURN_VAL(_ecore_x_disp, -1);
   DPMSInfo(_ecore_x_disp, &power_lvl, &state);
   return (int)power_lvl;
#else
   return -1;
#endif
}

/**
 * Sets the DPMS state of the display.
 * @param enabled @c 0 to disable DPMS characteristics of the server, enable it otherwise.
 * @ingroup Ecore_X_DPMS_Group
 */
EAPI void
ecore_x_dpms_enabled_set(int enabled)
{
#ifdef ECORE_XDPMS
   LOGFN(__FILE__, __LINE__, __FUNCTION__);
   EINA_SAFETY_ON_NULL_RETURN(_ecore_x_disp);
   if (enabled)
     DPMSEnable(_ecore_x_disp);
   else
     DPMSDisable(_ecore_x_disp);

#endif /* ifdef ECORE_XDPMS */
}

/**
 * Gets the timeouts. The values are in unit of seconds.
 * @param standby Amount of time of inactivity before standby mode will be invoked.
 * @param suspend Amount of time of inactivity before the screen is placed into suspend mode.
 * @param off     Amount of time of inactivity before the monitor is shut off.
 * @ingroup Ecore_X_DPMS_Group
 */
EAPI void
ecore_x_dpms_timeouts_get(unsigned int *standby,
                          unsigned int *suspend,
                          unsigned int *off)
{
#ifdef ECORE_XDPMS
   LOGFN(__FILE__, __LINE__, __FUNCTION__);
   EINA_SAFETY_ON_NULL_RETURN(_ecore_x_disp);
   DPMSGetTimeouts(_ecore_x_disp, (unsigned short *)standby,
                   (unsigned short *)suspend, (unsigned short *)off);
#endif /* ifdef ECORE_XDPMS */
}

/**
 * Sets the timeouts. The values are in unit of seconds.
 * @param standby Amount of time of inactivity before standby mode will be invoked.
 * @param suspend Amount of time of inactivity before the screen is placed into suspend mode.
 * @param off     Amount of time of inactivity before the monitor is shut off.
 * @ingroup Ecore_X_DPMS_Group
 */
EAPI Eina_Bool
ecore_x_dpms_timeouts_set(unsigned int standby,
                          unsigned int suspend,
                          unsigned int off)
{
#ifdef ECORE_XDPMS
   LOGFN(__FILE__, __LINE__, __FUNCTION__);
   EINA_SAFETY_ON_NULL_RETURN_VAL(_ecore_x_disp, EINA_FALSE);
   return DPMSSetTimeouts(_ecore_x_disp, standby, suspend, off) ? EINA_TRUE : EINA_FALSE;
#else /* ifdef ECORE_XDPMS */
   return EINA_FALSE;
#endif /* ifdef ECORE_XDPMS */
}

/**
 * Returns the amount of time of inactivity before standby mode is invoked.
 * @return The standby timeout value.
 * @ingroup Ecore_X_DPMS_Group
 */
EAPI unsigned int
ecore_x_dpms_timeout_standby_get(void)
{
#ifdef ECORE_XDPMS
   unsigned short standby, suspend, off;

   LOGFN(__FILE__, __LINE__, __FUNCTION__);
   EINA_SAFETY_ON_NULL_RETURN_VAL(_ecore_x_disp, 0);
   DPMSGetTimeouts(_ecore_x_disp, &standby, &suspend, &off);
   return standby;
#else /* ifdef ECORE_XDPMS */
   return 0;
#endif /* ifdef ECORE_XDPMS */
}

/**
 * Returns the amount of time of inactivity before the second level of
 * power saving is invoked.
 * @return The suspend timeout value.
 * @ingroup Ecore_X_DPMS_Group
 */
EAPI unsigned int
ecore_x_dpms_timeout_suspend_get(void)
{
#ifdef ECORE_XDPMS
   unsigned short standby, suspend, off;

   LOGFN(__FILE__, __LINE__, __FUNCTION__);
   EINA_SAFETY_ON_NULL_RETURN_VAL(_ecore_x_disp, 0);
   DPMSGetTimeouts(_ecore_x_disp, &standby, &suspend, &off);
   return suspend;
#else /* ifdef ECORE_XDPMS */
   return 0;
#endif /* ifdef ECORE_XDPMS */
}

/**
 * Returns the amount of time of inactivity before the third and final
 * level of power saving is invoked.
 * @return The off timeout value.
 * @ingroup Ecore_X_DPMS_Group
 */
EAPI unsigned int
ecore_x_dpms_timeout_off_get(void)
{
#ifdef ECORE_XDPMS
   unsigned short standby, suspend, off;

   LOGFN(__FILE__, __LINE__, __FUNCTION__);
   EINA_SAFETY_ON_NULL_RETURN_VAL(_ecore_x_disp, 0);
   DPMSGetTimeouts(_ecore_x_disp, &standby, &suspend, &off);
   return off;
#else /* ifdef ECORE_XDPMS */
   return 0;
#endif /* ifdef ECORE_XDPMS */
}

/**
 * Sets the standby timeout (in unit of seconds).
 * @param new_timeout Amount of time of inactivity before standby mode will be invoked.
 * @ingroup Ecore_X_DPMS_Group
 */
EAPI void
ecore_x_dpms_timeout_standby_set(unsigned int new_timeout)
{
#ifdef ECORE_XDPMS
   unsigned short standby, suspend, off;

   LOGFN(__FILE__, __LINE__, __FUNCTION__);
   EINA_SAFETY_ON_NULL_RETURN(_ecore_x_disp);
   DPMSGetTimeouts(_ecore_x_disp, &standby, &suspend, &off);
   DPMSSetTimeouts(_ecore_x_disp, new_timeout, suspend, off);
#endif /* ifdef ECORE_XDPMS */
}

/**
 * Sets the suspend timeout (in unit of seconds).
 * @param new_timeout Amount of time of inactivity before the screen is placed into suspend mode.
 * @ingroup Ecore_X_DPMS_Group
 */
EAPI void
ecore_x_dpms_timeout_suspend_set(unsigned int new_timeout)
{
#ifdef ECORE_XDPMS
   unsigned short standby, suspend, off;

   LOGFN(__FILE__, __LINE__, __FUNCTION__);
   EINA_SAFETY_ON_NULL_RETURN(_ecore_x_disp);
   DPMSGetTimeouts(_ecore_x_disp, &standby, &suspend, &off);
   DPMSSetTimeouts(_ecore_x_disp, standby, new_timeout, off);
#endif /* ifdef ECORE_XDPMS */
}

/**
 * Sets the off timeout (in unit of seconds).
 * @param new_timeout     Amount of time of inactivity before the monitor is shut off.
 * @ingroup Ecore_X_DPMS_Group
 */
EAPI void
ecore_x_dpms_timeout_off_set(unsigned int new_timeout)
{
#ifdef ECORE_XDPMS
   unsigned short standby, suspend, off;

   LOGFN(__FILE__, __LINE__, __FUNCTION__);
   EINA_SAFETY_ON_NULL_RETURN(_ecore_x_disp);
   DPMSGetTimeouts(_ecore_x_disp, &standby, &suspend, &off);
   DPMSSetTimeouts(_ecore_x_disp, standby, suspend, new_timeout);
#endif /* ifdef ECORE_XDPMS */
}

/**
 * Forces DPMS on or off
 * @param on If DPMS is to be forced on (EINA_TRUE) or forced off
 * @ingroup Ecore_X_DPMS_Group
 */
EAPI void
ecore_x_dpms_force(Eina_Bool on)
{
#ifdef ECORE_XDPMS
   LOGFN(__FILE__, __LINE__, __FUNCTION__);
   EINA_SAFETY_ON_NULL_RETURN(_ecore_x_disp);
   if (on) DPMSForceLevel(_ecore_x_disp, DPMSModeOn);
   else DPMSForceLevel(_ecore_x_disp, DPMSModeOff);
#endif /* ifdef ECORE_XDPMS */
}