aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/ecore/src/lib/ecore_x/xlib/ecore_x_randr_11.c
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/ecore/src/lib/ecore_x/xlib/ecore_x_randr_11.c')
-rw-r--r--libraries/ecore/src/lib/ecore_x/xlib/ecore_x_randr_11.c332
1 files changed, 332 insertions, 0 deletions
diff --git a/libraries/ecore/src/lib/ecore_x/xlib/ecore_x_randr_11.c b/libraries/ecore/src/lib/ecore_x/xlib/ecore_x_randr_11.c
new file mode 100644
index 0000000..a6bafb6
--- /dev/null
+++ b/libraries/ecore/src/lib/ecore_x/xlib/ecore_x_randr_11.c
@@ -0,0 +1,332 @@
1/*
2 * vim:ts=8:sw=3:sts=8:expandtab:cino=>5n-3f0^-2{2
3 */
4
5#ifdef HAVE_CONFIG_H
6# include <config.h>
7#endif /* ifdef HAVE_CONFIG_H */
8
9#include "ecore_x_private.h"
10#include "ecore_x_randr.h"
11
12#define Ecore_X_Randr_None 0
13#ifdef ECORE_XRANDR
14
15#define RANDR_1_1 ((1 << 16) | 1)
16
17#define RANDR_VALIDATE_ROOT(screen, \
18 root) ((screen = \
19 XRRRootToScreen(_ecore_x_disp, \
20 root)) != -1)
21#define RANDR_CHECK_1_1_RET(ret) if(_randr_version < RANDR_1_1) return ret
22
23extern XRRScreenResources *(*_ecore_x_randr_get_screen_resources)(Display *
24 dpy,
25 Window
26 window);
27extern int _randr_version;
28#endif /* ifdef ECORE_XRANDR */
29
30/*
31 * @param root window which's primary output will be queried
32 */
33EAPI Ecore_X_Randr_Orientation
34ecore_x_randr_screen_primary_output_orientations_get(Ecore_X_Window root)
35{
36#ifdef ECORE_XRANDR
37 Rotation rot = Ecore_X_Randr_None, crot;
38
39 LOGFN(__FILE__, __LINE__, __FUNCTION__);
40 rot =
41 XRRRotations(_ecore_x_disp, XRRRootToScreen(_ecore_x_disp,
42 root), &crot);
43 return rot;
44#else /* ifdef ECORE_XRANDR */
45 return Ecore_X_Randr_None;
46#endif /* ifdef ECORE_XRANDR */
47} /* ecore_x_randr_screen_primary_output_orientations_get */
48
49/*
50 * @param root window which's primary output will be queried
51 * @return the current orientation of the root window's screen primary output
52 */
53EAPI Ecore_X_Randr_Orientation
54ecore_x_randr_screen_primary_output_orientation_get(Ecore_X_Window root)
55{
56#ifdef ECORE_XRANDR
57 Rotation crot = Ecore_X_Randr_None;
58 XRRRotations(_ecore_x_disp, XRRRootToScreen(_ecore_x_disp,
59 root), &crot);
60 return crot;
61#else /* ifdef ECORE_XRANDR */
62 return Ecore_X_Randr_None;
63#endif /* ifdef ECORE_XRANDR */
64} /* ecore_x_randr_screen_primary_output_orientation_get */
65
66/*
67 * @brief sets a given screen's primary output's orientation
68 * @param root window which's screen's primary output will be queried
69 * @param orientation orientation which should be set for the root window's screen primary output
70 * @return EINA_TRUE if the primary output's orientation could be successfully altered
71 */
72EAPI Eina_Bool
73ecore_x_randr_screen_primary_output_orientation_set(
74 Ecore_X_Window root,
75 Ecore_X_Randr_Orientation
76 orientation)
77{
78#ifdef ECORE_XRANDR
79 XRRScreenConfiguration *xrr_screen_cfg = NULL;
80 int sizeid;
81 Rotation crot;
82 Eina_Bool ret = EINA_FALSE;
83 if (!(xrr_screen_cfg = XRRGetScreenInfo(_ecore_x_disp, root)))
84 return EINA_FALSE;
85
86 sizeid = XRRConfigCurrentConfiguration(xrr_screen_cfg, &crot);
87 if (!XRRSetScreenConfig(_ecore_x_disp, xrr_screen_cfg, root, sizeid,
88 orientation, CurrentTime))
89 ret = EINA_TRUE;
90
91 if (xrr_screen_cfg)
92 XRRFreeScreenConfigInfo(xrr_screen_cfg);
93
94 return ret;
95#else /* ifdef ECORE_XRANDR */
96 return EINA_FALSE;
97#endif /* ifdef ECORE_XRANDR */
98} /* ecore_x_randr_screen_primary_output_orientation_set */
99
100/*
101 * @brief gets a screen's primary output's possible sizes
102 * @param root window which's primary output will be queried
103 * @param num number of sizes reported as supported by the screen's primary output
104 * @return an array of sizes reported as supported by the screen's primary output or - if query failed - NULL
105 */
106EAPI Ecore_X_Randr_Screen_Size_MM *
107ecore_x_randr_screen_primary_output_sizes_get(Ecore_X_Window root,
108 int *num)
109{
110#ifdef ECORE_XRANDR
111 Ecore_X_Randr_Screen_Size_MM *ret = NULL;
112 XRRScreenSize *sizes;
113 int i, n;
114
115 /* we don't have to free sizes, because they're hold in a cache inside X*/
116 sizes =
117 XRRSizes(_ecore_x_disp, XRRRootToScreen(_ecore_x_disp,
118 root), &n);
119 if ((!sizes) || (n <= 0)) return NULL;
120 ret = calloc(n, sizeof(Ecore_X_Randr_Screen_Size_MM));
121 if (!ret)
122 return NULL;
123
124 if (num)
125 *num = n;
126
127 for (i = 0; i < n; i++)
128 {
129 ret[i].width = sizes[i].width;
130 ret[i].height = sizes[i].height;
131 ret[i].width_mm = sizes[i].mwidth;
132 ret[i].height_mm = sizes[i].mheight;
133 }
134 return ret;
135#else /* ifdef ECORE_XRANDR */
136 return NULL;
137#endif /* ifdef ECORE_XRANDR */
138} /* ecore_x_randr_screen_primary_output_sizes_get */
139
140/*
141 * @brief get the current set size of a given screen's primary output
142 * @param root window which's primary output will be queried
143 * @param w the current size's width
144 * @param h the current size's height
145 * @param w_mm the current size's width in mm
146 * @param h_mm the current size's height in mm
147 * @param size_index of current set size to be used with ecore_x_randr_primary_output_size_set()
148 */
149EAPI void
150ecore_x_randr_screen_primary_output_current_size_get(Ecore_X_Window root,
151 int *w,
152 int *h,
153 int *w_mm,
154 int *h_mm,
155 int *size_index)
156{
157#ifdef ECORE_XRANDR
158 XRRScreenSize *sizes;
159 XRRScreenConfiguration *sc = NULL;
160 int idx;
161 Rotation orientation;
162 int n;
163
164 if (!(sc = XRRGetScreenInfo(_ecore_x_disp, root)))
165 {
166 ERR("Couldn't get screen information for %d", root);
167 return;
168 }
169
170 idx = XRRConfigCurrentConfiguration(sc, &orientation);
171
172 sizes =
173 XRRSizes(_ecore_x_disp, XRRRootToScreen(_ecore_x_disp,
174 root), &n);
175 if ((idx < n) && (idx >= 0))
176 {
177 if (w)
178 *w = sizes[idx].width;
179
180 if (h)
181 *h = sizes[idx].height;
182
183 if (w_mm)
184 *w_mm = sizes[idx].mwidth;
185
186 if (h_mm)
187 *h_mm = sizes[idx].mheight;
188
189 if (size_index)
190 *size_index = idx;
191 }
192
193 XRRFreeScreenConfigInfo(sc);
194#endif /* ifdef ECORE_XRANDR */
195} /* ecore_x_randr_screen_primary_output_current_size_get */
196
197/*
198 * @brief sets a given screen's primary output size, but disables all other outputs at the same time
199 * @param root window which's primary output will be queried
200 * @param size_index within the list of sizes reported as supported by the root window's screen primary output
201 * @return EINA_TRUE on success, EINA_FALSE on failure due to e.g. invalid times
202 */
203EAPI Eina_Bool
204ecore_x_randr_screen_primary_output_size_set(Ecore_X_Window root,
205 int size_index)
206{
207#ifdef ECORE_XRANDR
208 XRRScreenConfiguration *sc = NULL;
209 XRRScreenSize *sizes;
210 Eina_Bool ret = EINA_FALSE;
211 int nsizes = 0;
212
213 if (size_index >= 0 && _ecore_x_randr_root_validate(root))
214 {
215 sizes =
216 XRRSizes(_ecore_x_disp, XRRRootToScreen(_ecore_x_disp,
217 root), &nsizes);
218
219 if (size_index < nsizes)
220 {
221 sc = XRRGetScreenInfo(_ecore_x_disp, root);
222 if (!XRRSetScreenConfig(_ecore_x_disp, sc,
223 root, size_index,
224 ECORE_X_RANDR_ORIENTATION_ROT_0, CurrentTime))
225 {
226 ret = EINA_TRUE;
227 }
228
229 if (sc)
230 XRRFreeScreenConfigInfo(sc);
231 }
232 }
233
234 return ret;
235#else /* ifdef ECORE_XRANDR */
236 return EINA_FALSE;
237#endif /* ifdef ECORE_XRANDR */
238} /* ecore_x_randr_screen_primary_output_size_set */
239
240/*
241 * @param root window which's primary output will be queried
242 * @return currently used refresh rate or - if request failed or RandRR is not available - 0.0
243 */
244EAPI Ecore_X_Randr_Refresh_Rate
245ecore_x_randr_screen_primary_output_current_refresh_rate_get(
246 Ecore_X_Window root)
247{
248#ifdef ECORE_XRANDR
249 Ecore_X_Randr_Refresh_Rate ret = 0.0;
250 XRRScreenConfiguration *sc = NULL;
251
252 if (!_ecore_x_randr_root_validate(root) ||
253 !(sc = XRRGetScreenInfo(_ecore_x_disp, root)))
254 return ret;
255
256 ret = XRRConfigCurrentRate(sc);
257 if (sc)
258 XRRFreeScreenConfigInfo(sc);
259
260 return ret;
261#else /* ifdef ECORE_XRANDR */
262 return 0.0;
263#endif /* ifdef ECORE_XRANDR */
264} /* ecore_x_randr_screen_primary_output_current_refresh_rate_get */
265
266/*
267 * @param root window which's primary output will be queried
268 * @param size_index referencing the size to query valid refresh rates for
269 * @return currently used refresh rate or - if request failed or RandRR is not available - NULL
270 */
271EAPI Ecore_X_Randr_Refresh_Rate *
272ecore_x_randr_screen_primary_output_refresh_rates_get(Ecore_X_Window root,
273 int size_index,
274 int *num)
275{
276#ifdef ECORE_XRANDR
277 Ecore_X_Randr_Refresh_Rate *ret = NULL, *rates = NULL;
278 Ecore_X_Randr_Screen scr;
279 int n;
280
281 if (num
282 && RANDR_VALIDATE_ROOT(scr, root)
283 && (rates = XRRRates(_ecore_x_disp, scr, size_index, &n)))
284 {
285 if (rates && (ret = malloc(sizeof(Ecore_X_Randr_Refresh_Rate) * n)))
286 {
287 memcpy(ret, rates, (sizeof(Ecore_X_Randr_Refresh_Rate) * n));
288 *num = n;
289 }
290 }
291
292 return ret;
293#else /* ifdef ECORE_XRANDR */
294 return NULL;
295#endif /* ifdef ECORE_XRANDR */
296} /* ecore_x_randr_screen_primary_output_refresh_rates_get */
297
298//>= 1.1
299/*
300 * @brief sets the current primary output's refresh rate
301 * @param root window which's primary output will be queried
302 * @param size_index referencing the size to be set
303 * @param rate the refresh rate to be set
304 * @return EINA_TRUE on success else EINA_FALSE
305 */
306EAPI Eina_Bool
307ecore_x_randr_screen_primary_output_refresh_rate_set(
308 Ecore_X_Window root,
309 int size_index,
310 Ecore_X_Randr_Refresh_Rate
311 rate)
312{
313#ifdef ECORE_XRANDR
314 RANDR_CHECK_1_1_RET(EINA_FALSE);
315 Eina_Bool ret = EINA_FALSE;
316 XRRScreenConfiguration *sc = NULL;
317
318 if (!(sc = XRRGetScreenInfo(_ecore_x_disp, root)))
319 return ret;
320
321 if (!XRRSetScreenConfigAndRate(_ecore_x_disp, sc,
322 root, size_index,
323 RR_Rotate_0, rate, CurrentTime))
324 ret = EINA_TRUE;
325
326 XRRFreeScreenConfigInfo(sc);
327 return ret;
328#else /* ifdef ECORE_XRANDR */
329 return EINA_FALSE;
330#endif /* ifdef ECORE_XRANDR */
331} /* ecore_x_randr_screen_primary_output_refresh_rate_set */
332