2 * vim:ts=8:sw=3:sts=8:expandtab:cino=>5n-3f0^-2{2
7 #endif /* ifdef HAVE_CONFIG_H */
9 #include "ecore_x_private.h"
10 #include "ecore_x_randr.h"
16 #define Ecore_X_Randr_None 0
19 #define RANDR_1_1 ((1 << 16) | 1)
21 #define RANDR_VALIDATE_ROOT(screen, \
23 XRRRootToScreen(_ecore_x_disp, \
25 #define RANDR_CHECK_1_1_RET(ret) if (_randr_version < RANDR_1_1) \
28 extern XRRScreenResources *(*_ecore_x_randr_get_screen_resources)(Display *
32 extern int _randr_version;
33 #endif /* ifdef ECORE_XRANDR */
36 * @param root window which's primary output will be queried
38 EAPI Ecore_X_Randr_Orientation
39 ecore_x_randr_screen_primary_output_orientations_get(Ecore_X_Window root)
42 Rotation rot = Ecore_X_Randr_None, crot;
44 LOGFN(__FILE__, __LINE__, __FUNCTION__);
46 XRRRotations(_ecore_x_disp, XRRRootToScreen(_ecore_x_disp,
49 #else /* ifdef ECORE_XRANDR */
50 return Ecore_X_Randr_None;
51 #endif /* ifdef ECORE_XRANDR */
55 * @param root window which's primary output will be queried
56 * @return the current orientation of the root window's screen primary output
58 EAPI Ecore_X_Randr_Orientation
59 ecore_x_randr_screen_primary_output_orientation_get(Ecore_X_Window root)
62 Rotation crot = Ecore_X_Randr_None;
63 XRRRotations(_ecore_x_disp, XRRRootToScreen(_ecore_x_disp,
66 #else /* ifdef ECORE_XRANDR */
67 return Ecore_X_Randr_None;
68 #endif /* ifdef ECORE_XRANDR */
72 * @brief Sets a given screen's primary output's orientation.
74 * @param root Window which's screen's primary output will be queried.
75 * @param orientation orientation which should be set for the root window's
76 * screen primary output.
77 * @return @c EINA_TRUE if the primary output's orientation could be
78 * successfully altered.
81 ecore_x_randr_screen_primary_output_orientation_set(
83 Ecore_X_Randr_Orientation
87 XRRScreenConfiguration *xrr_screen_cfg = NULL;
90 Eina_Bool ret = EINA_FALSE;
91 if (!(xrr_screen_cfg = XRRGetScreenInfo(_ecore_x_disp, root)))
94 sizeid = XRRConfigCurrentConfiguration(xrr_screen_cfg, &crot);
95 if (!XRRSetScreenConfig(_ecore_x_disp, xrr_screen_cfg, root, sizeid,
96 orientation, CurrentTime))
100 XRRFreeScreenConfigInfo(xrr_screen_cfg);
103 #else /* ifdef ECORE_XRANDR */
105 #endif /* ifdef ECORE_XRANDR */
109 * @brief gets a screen's primary output's possible sizes
110 * @param root window which's primary output will be queried
111 * @param num number of sizes reported as supported by the screen's primary output
112 * @return an array of sizes reported as supported by the screen's primary output or - if query failed - NULL
114 EAPI Ecore_X_Randr_Screen_Size_MM *
115 ecore_x_randr_screen_primary_output_sizes_get(Ecore_X_Window root,
119 Ecore_X_Randr_Screen_Size_MM *ret = NULL;
120 XRRScreenSize *sizes;
123 /* we don't have to free sizes, because they're hold in a cache inside X*/
125 XRRSizes(_ecore_x_disp, XRRRootToScreen(_ecore_x_disp,
127 if ((!sizes) || (n <= 0)) return NULL;
128 ret = calloc(n, sizeof(Ecore_X_Randr_Screen_Size_MM));
135 for (i = 0; i < n; i++)
137 ret[i].width = sizes[i].width;
138 ret[i].height = sizes[i].height;
139 ret[i].width_mm = sizes[i].mwidth;
140 ret[i].height_mm = sizes[i].mheight;
143 #else /* ifdef ECORE_XRANDR */
145 #endif /* ifdef ECORE_XRANDR */
149 ecore_x_randr_screen_primary_output_current_size_get(Ecore_X_Window root,
157 XRRScreenSize *sizes;
158 XRRScreenConfiguration *sc = NULL;
160 Rotation orientation;
163 if (!(sc = XRRGetScreenInfo(_ecore_x_disp, root)))
165 ERR("Couldn't get screen information for %d", root);
169 idx = XRRConfigCurrentConfiguration(sc, &orientation);
172 XRRSizes(_ecore_x_disp, XRRRootToScreen(_ecore_x_disp,
174 if ((idx < n) && (idx >= 0))
177 *w = sizes[idx].width;
180 *h = sizes[idx].height;
183 *w_mm = sizes[idx].mwidth;
186 *h_mm = sizes[idx].mheight;
192 XRRFreeScreenConfigInfo(sc);
193 #endif /* ifdef ECORE_XRANDR */
197 * @brief Sets a given screen's primary output size, but disables all other
198 * outputs at the same time.
200 * @param root Window which's primary output will be queried.
201 * @param size_index Within the list of sizes reported as supported by the root
202 * window's screen primary output.
203 * @return @c EINA_TRUE on success, @c EINA_FALSE on failure due to e.g.
207 ecore_x_randr_screen_primary_output_size_set(Ecore_X_Window root,
211 XRRScreenConfiguration *sc = NULL;
212 Eina_Bool ret = EINA_FALSE;
215 if (size_index >= 0 && _ecore_x_randr_root_validate(root))
217 XRRSizes(_ecore_x_disp, XRRRootToScreen(_ecore_x_disp,
220 if (size_index < nsizes)
222 sc = XRRGetScreenInfo(_ecore_x_disp, root);
223 if (!XRRSetScreenConfig(_ecore_x_disp, sc,
225 ECORE_X_RANDR_ORIENTATION_ROT_0, CurrentTime))
231 XRRFreeScreenConfigInfo(sc);
236 #else /* ifdef ECORE_XRANDR */
238 #endif /* ifdef ECORE_XRANDR */
242 * @param root window which's primary output will be queried
243 * @return currently used refresh rate or - if request failed or RandRR is not available - 0.0
245 EAPI Ecore_X_Randr_Refresh_Rate
246 ecore_x_randr_screen_primary_output_current_refresh_rate_get(
250 Ecore_X_Randr_Refresh_Rate ret = 0.0;
251 XRRScreenConfiguration *sc = NULL;
253 if (!_ecore_x_randr_root_validate(root) ||
254 !(sc = XRRGetScreenInfo(_ecore_x_disp, root)))
257 ret = XRRConfigCurrentRate(sc);
259 XRRFreeScreenConfigInfo(sc);
262 #else /* ifdef ECORE_XRANDR */
264 #endif /* ifdef ECORE_XRANDR */
268 * @param root window which's primary output will be queried
269 * @param size_index referencing the size to query valid refresh rates for
270 * @return currently used refresh rate or - if request failed or RandRR is not available - NULL
272 EAPI Ecore_X_Randr_Refresh_Rate *
273 ecore_x_randr_screen_primary_output_refresh_rates_get(Ecore_X_Window root,
278 Ecore_X_Randr_Refresh_Rate *ret = NULL, *rates = NULL;
279 Ecore_X_Randr_Screen scr;
283 && RANDR_VALIDATE_ROOT(scr, root)
284 && (rates = XRRRates(_ecore_x_disp, scr, size_index, &n)))
286 if (rates && (ret = malloc(sizeof(Ecore_X_Randr_Refresh_Rate) * n)))
288 memcpy(ret, rates, (sizeof(Ecore_X_Randr_Refresh_Rate) * n));
294 #else /* ifdef ECORE_XRANDR */
296 #endif /* ifdef ECORE_XRANDR */
301 * @brief Sets the current primary output's refresh rate.
303 * @param root Window which's primary output will be queried.
304 * @param size_index Referencing the size to be set.
305 * @param rate The refresh rate to be set.
306 * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise.
309 ecore_x_randr_screen_primary_output_refresh_rate_set(
312 Ecore_X_Randr_Refresh_Rate
316 RANDR_CHECK_1_1_RET(EINA_FALSE);
317 Eina_Bool ret = EINA_FALSE;
318 XRRScreenConfiguration *sc = NULL;
320 if (!(sc = XRRGetScreenInfo(_ecore_x_disp, root)))
323 if (!XRRSetScreenConfigAndRate(_ecore_x_disp, sc,
325 RR_Rotate_0, rate, CurrentTime))
328 XRRFreeScreenConfigInfo(sc);
330 #else /* ifdef ECORE_XRANDR */
332 #endif /* ifdef ECORE_XRANDR */