1 /* TODO: List of missing functions
3 * ecore_x_randr_crtc_clone_set
4 * ecore_x_randr_output_crtc_set
5 * ecore_x_randr_edid_version_get
6 * ecore_x_randr_edid_info_has_valid_checksum
7 * ecore_x_randr_edid_manufacturer_name_get
8 * ecore_x_randr_edid_display_ascii_get
9 * ecore_x_randr_edid_display_serial_get
10 * ecore_x_randr_edid_model_get
11 * ecore_x_randr_edid_manufacturer_serial_number_get
12 * ecore_x_randr_edid_manufacturer_model_get
13 * ecore_x_randr_edid_dpms_available_get
14 * ecore_x_randr_edid_dpms_standby_available_get
15 * ecore_x_randr_edid_dpms_suspend_available_get
16 * ecore_x_randr_edid_dpms_off_available_get
17 * ecore_x_randr_edid_display_aspect_ratio_preferred_get
18 * ecore_x_randr_edid_display_aspect_ratios_get
19 * ecore_x_randr_edid_display_colorscheme_get
20 * ecore_x_randr_edid_display_type_digital_get
21 * ecore_x_randr_edid_display_interface_type_get
22 * ecore_x_randr_screen_backlight_level_set
23 * ecore_x_randr_output_subpixel_order_get
24 * ecore_x_randr_output_wired_clones_get
25 * ecore_x_randr_output_compatibility_list_get
26 * ecore_x_randr_output_signal_formats_get
27 * ecore_x_randr_output_signal_format_set
28 * ecore_x_randr_output_signal_properties_get
29 * ecore_x_randr_output_connector_number_get
30 * ecore_x_randr_output_connector_type_get
31 * ecore_x_randr_crtc_panning_area_get
32 * ecore_x_randr_crtc_panning_area_set
33 * ecore_x_randr_crtc_tracking_area_get
34 * ecore_x_randr_crtc_tracking_area_set
35 * ecore_x_randr_crtc_border_area_get
36 * ecore_x_randr_crtc_border_area_set
39 #include "ecore_xcb_private.h"
40 # ifdef ECORE_XCB_RANDR
41 # include <xcb/randr.h>
44 #define Ecore_X_Randr_None 0
45 #define Ecore_X_Randr_Unset -1
47 #define RANDR_1_1 ((1 << 16) | 1)
48 #define RANDR_1_2 ((1 << 16) | 2)
49 #define RANDR_1_3 ((1 << 16) | 3)
51 #define RANDR_CHECK_1_1_RET(ret) if (_randr_version < RANDR_1_1) return ret
52 #define RANDR_CHECK_1_2_RET(ret) if (_randr_version < RANDR_1_2) return ret
53 #define RANDR_CHECK_1_3_RET(ret) if (_randr_version < RANDR_1_3) return ret
55 #define ECORE_X_RANDR_EDID_VERSION_13 ((1 << 8) | 3)
56 #define _ECORE_X_RANDR_EDID_OFFSET_VERSION_MAJOR 0x12
57 #define _ECORE_X_RANDR_EDID_OFFSET_VERSION_MINOR 0x13
58 #define _ECORE_X_RANDR_EDID_OFFSET_DESCRIPTOR_BLOCK 0x36
59 #define _ECORE_X_RANDR_EDID_OFFSET_DESCRIPTOR_BLOCK_TYPE 3
60 #define _ECORE_X_RANDR_EDID_OFFSET_DESCRIPTOR_BLOCK_CONTENT 5
61 #define _ECORE_X_RANDR_EDID_DISPLAY_DESCRIPTOR_BLOCK_CONTENT_LENGTH_MAX 13
63 #define _ECORE_X_RANDR_EDID_FOR_EACH_DESCRIPTOR_BLOCK(edid, block) \
64 for (block = edid + _ECORE_X_RANDR_EDID_OFFSET_DESCRIPTOR_BLOCK; block <= (edid + _ECORE_X_RANDR_EDID_OFFSET_DESCRIPTOR_BLOCK + (3 * 18)); block += 18)
66 #define _ECORE_X_RANDR_EDID_FOR_EACH_NON_PIXEL_DESCRIPTOR_BLOCK(edid, block) \
67 _ECORE_X_RANDR_EDID_FOR_EACH_DESCRIPTOR_BLOCK(edid, block) \
68 if ((block[0] == 0) && (block[1] == 0))
70 /* local function prototypes */
71 static Eina_Bool _ecore_xcb_randr_output_validate(Ecore_X_Window root,
72 Ecore_X_Randr_Output output);
73 static Eina_Bool _ecore_xcb_randr_crtc_validate(Ecore_X_Window root,
74 Ecore_X_Randr_Crtc crtc);
75 static Eina_Bool _ecore_xcb_randr_root_validate(Ecore_X_Window root);
76 static int _ecore_xcb_randr_root_to_screen(Ecore_X_Window root);
77 #ifdef ECORE_XCB_RANDR
78 static xcb_randr_get_screen_resources_reply_t *_ecore_xcb_randr_12_get_resources(Ecore_X_Window win);
79 static xcb_randr_get_screen_resources_current_reply_t *_ecore_xcb_randr_13_get_resources(Ecore_X_Window win);
81 static xcb_timestamp_t _ecore_xcb_randr_12_get_resource_timestamp(Ecore_X_Window win);
82 static xcb_timestamp_t _ecore_xcb_randr_13_get_resource_timestamp(Ecore_X_Window win);
84 static Ecore_X_Randr_Mode *_ecore_xcb_randr_12_output_modes_get(Ecore_X_Window root,
85 Ecore_X_Randr_Output output,
88 static Ecore_X_Randr_Mode *_ecore_xcb_randr_13_output_modes_get(Ecore_X_Window root,
89 Ecore_X_Randr_Output output,
92 static Ecore_X_Randr_Mode_Info *_ecore_xcb_randr_12_mode_info_get(Ecore_X_Window root,
93 Ecore_X_Randr_Mode mode);
94 static Ecore_X_Randr_Mode_Info *_ecore_xcb_randr_13_mode_info_get(Ecore_X_Window root,
95 Ecore_X_Randr_Mode mode);
96 static Ecore_X_Randr_Mode_Info **_ecore_xcb_randr_12_modes_info_get(Ecore_X_Window root,
98 static Ecore_X_Randr_Mode_Info **_ecore_xcb_randr_13_modes_info_get(Ecore_X_Window root,
100 static void _ecore_xcb_randr_12_mode_size_get(Ecore_X_Window root,
101 Ecore_X_Randr_Mode mode,
104 static void _ecore_xcb_randr_13_mode_size_get(Ecore_X_Window root,
105 Ecore_X_Randr_Mode mode,
108 static Ecore_X_Randr_Output *_ecore_xcb_randr_12_output_clones_get(Ecore_X_Window root,
109 Ecore_X_Randr_Output output,
111 static Ecore_X_Randr_Output *_ecore_xcb_randr_13_output_clones_get(Ecore_X_Window root,
112 Ecore_X_Randr_Output output,
114 static Ecore_X_Randr_Crtc *_ecore_xcb_randr_12_output_possible_crtcs_get(Ecore_X_Window root,
115 Ecore_X_Randr_Output output,
117 static Ecore_X_Randr_Crtc *_ecore_xcb_randr_13_output_possible_crtcs_get(Ecore_X_Window root,
118 Ecore_X_Randr_Output output,
120 static char *_ecore_xcb_randr_12_output_name_get(Ecore_X_Window root,
121 Ecore_X_Randr_Output output,
123 static char *_ecore_xcb_randr_13_output_name_get(Ecore_X_Window root,
124 Ecore_X_Randr_Output output,
126 static Ecore_X_Randr_Connection_Status _ecore_xcb_randr_12_output_connection_status_get(Ecore_X_Window root,
127 Ecore_X_Randr_Output output);
128 static Ecore_X_Randr_Connection_Status _ecore_xcb_randr_13_output_connection_status_get(Ecore_X_Window root,
129 Ecore_X_Randr_Output output);
130 static Ecore_X_Randr_Output *_ecore_xcb_randr_12_outputs_get(Ecore_X_Window root,
132 static Ecore_X_Randr_Output *_ecore_xcb_randr_13_outputs_get(Ecore_X_Window root,
134 static Ecore_X_Randr_Crtc _ecore_xcb_randr_12_output_crtc_get(Ecore_X_Window root,
135 Ecore_X_Randr_Output output);
136 static Ecore_X_Randr_Crtc _ecore_xcb_randr_13_output_crtc_get(Ecore_X_Window root,
137 Ecore_X_Randr_Output output);
139 /* local variables */
140 static Eina_Bool _randr_avail = EINA_FALSE;
141 static int _randr_version = -1;
143 /* external variables */
144 int _ecore_xcb_event_randr = -1;
147 _ecore_xcb_randr_init(void)
149 LOGFN(__FILE__, __LINE__, __FUNCTION__);
151 #ifdef ECORE_XCB_RANDR
152 xcb_prefetch_extension_data(_ecore_xcb_conn, &xcb_randr_id);
157 _ecore_xcb_randr_finalize(void)
159 #ifdef ECORE_XCB_RANDR
160 const xcb_query_extension_reply_t *ext_reply;
163 LOGFN(__FILE__, __LINE__, __FUNCTION__);
165 #ifdef ECORE_XCB_RANDR
166 ext_reply = xcb_get_extension_data(_ecore_xcb_conn, &xcb_randr_id);
167 if ((ext_reply) && (ext_reply->present))
169 xcb_randr_query_version_cookie_t cookie;
170 xcb_randr_query_version_reply_t *reply;
173 xcb_randr_query_version_unchecked(_ecore_xcb_conn,
174 XCB_RANDR_MAJOR_VERSION,
175 XCB_RANDR_MINOR_VERSION);
176 reply = xcb_randr_query_version_reply(_ecore_xcb_conn, cookie, NULL);
179 if ((reply->major_version >= XCB_RANDR_MAJOR_VERSION) &&
180 (reply->minor_version >= XCB_RANDR_MINOR_VERSION))
181 _randr_avail = EINA_TRUE;
184 ((reply->major_version << 16) | reply->minor_version);
190 _ecore_xcb_event_randr = ext_reply->first_event;
196 #ifdef ECORE_XCB_RANDR
197 _ecore_xcb_randr_root_validate(Ecore_X_Window root)
199 _ecore_xcb_randr_root_validate(Ecore_X_Window root __UNUSED__)
202 #ifdef ECORE_XCB_RANDR
203 Ecore_X_Randr_Screen scr = -1;
204 # define RANDR_VALIDATE_ROOT(screen, root) \
205 ((screen == _ecore_xcb_randr_root_to_screen(root)) != -1)
208 LOGFN(__FILE__, __LINE__, __FUNCTION__);
210 #ifdef ECORE_XCB_RANDR
211 if ((root) && RANDR_VALIDATE_ROOT(scr, root))
219 _ecore_xcb_randr_root_to_screen(Ecore_X_Window root)
221 int count = 0, num = 0;
225 count = xcb_setup_roots_length(xcb_get_setup(_ecore_xcb_conn));
226 for (num = 0; num < count; num++)
227 if (_ecore_xcb_window_root_of_screen_get(num) == root)
233 /* public functions */
236 * @brief Query whether RandR is available or not.
238 * @return @c EINA_TRUE if extension is available, @c EINA_FALSE otherwise.
241 ecore_x_randr_query(void)
247 * @return version of the RandRR extension supported by the server or,
248 * in case RandRR extension is not available, Ecore_X_Randr_Unset (=-1).
249 * bit version information: 31 MAJOR 16 | 15 MINOR 0
252 ecore_x_randr_version_get(void)
254 return _randr_version;
258 * @brief This function returns the current config timestamp from
259 * XRRScreenConfiguration.
261 * @params root root window to query screen configuration from
263 * @returns The screen configuration timestamp
268 ecore_x_randr_config_timestamp_get(Ecore_X_Window root)
270 Ecore_X_Time timestamp = 0;
272 #ifdef ECORE_XCB_RANDR
273 xcb_randr_get_screen_info_cookie_t cookie;
274 xcb_randr_get_screen_info_reply_t *reply;
277 LOGFN(__FILE__, __LINE__, __FUNCTION__);
280 #ifdef ECORE_XCB_RANDR
281 cookie = xcb_randr_get_screen_info_unchecked(_ecore_xcb_conn, root);
282 reply = xcb_randr_get_screen_info_reply(_ecore_xcb_conn, cookie, NULL);
285 timestamp = (Ecore_X_Time)reply->config_timestamp;
294 * @param root window which's primary output will be queried
296 EAPI Ecore_X_Randr_Orientation
297 ecore_x_randr_screen_primary_output_orientations_get(Ecore_X_Window root)
299 int ret = Ecore_X_Randr_None;
300 #ifdef ECORE_XCB_RANDR
301 xcb_randr_get_screen_info_cookie_t cookie;
302 xcb_randr_get_screen_info_reply_t *reply;
305 LOGFN(__FILE__, __LINE__, __FUNCTION__);
308 #ifdef ECORE_XCB_RANDR
309 cookie = xcb_randr_get_screen_info_unchecked(_ecore_xcb_conn, root);
310 reply = xcb_randr_get_screen_info_reply(_ecore_xcb_conn, cookie, NULL);
313 ret = reply->rotations;
322 * @param root window which's primary output will be queried
323 * @return the current orientation of the root window's screen primary output
325 EAPI Ecore_X_Randr_Orientation
326 ecore_x_randr_screen_primary_output_orientation_get(Ecore_X_Window root)
328 int ret = Ecore_X_Randr_None;
329 #ifdef ECORE_XCB_RANDR
330 xcb_randr_get_screen_info_cookie_t cookie;
331 xcb_randr_get_screen_info_reply_t *reply;
334 LOGFN(__FILE__, __LINE__, __FUNCTION__);
337 #ifdef ECORE_XCB_RANDR
338 cookie = xcb_randr_get_screen_info_unchecked(_ecore_xcb_conn, root);
339 reply = xcb_randr_get_screen_info_reply(_ecore_xcb_conn, cookie, NULL);
342 ret = reply->rotation;
351 * @brief Sets a given screen's primary output's orientation.
353 * @param root Window which's screen's primary output will be queried.
354 * @param orientation Orientation which should be set for the root window's
355 * screen primary output.
356 * @return @c EINA_TRUE if the primary output's orientation could be
357 * successfully altered.
360 ecore_x_randr_screen_primary_output_orientation_set(Ecore_X_Window root,
361 Ecore_X_Randr_Orientation orientation)
363 int ret = EINA_FALSE;
364 #ifdef ECORE_XCB_RANDR
365 xcb_randr_get_screen_info_cookie_t cookie;
366 xcb_randr_get_screen_info_reply_t *reply;
369 LOGFN(__FILE__, __LINE__, __FUNCTION__);
372 #ifdef ECORE_XCB_RANDR
373 cookie = xcb_randr_get_screen_info_unchecked(_ecore_xcb_conn, root);
374 reply = xcb_randr_get_screen_info_reply(_ecore_xcb_conn, cookie, NULL);
377 xcb_randr_set_screen_config_cookie_t scookie;
378 xcb_randr_set_screen_config_reply_t *sreply;
381 xcb_randr_set_screen_config_unchecked(_ecore_xcb_conn, root,
383 reply->config_timestamp,
384 reply->sizeID, orientation,
387 xcb_randr_set_screen_config_reply(_ecore_xcb_conn, scookie, NULL);
392 ret = (sreply->status == XCB_RANDR_SET_CONFIG_SUCCESS) ?
393 EINA_TRUE : EINA_FALSE;
404 * @brief gets a screen's primary output's possible sizes
405 * @param root window which's primary output will be queried
406 * @param num number of sizes reported as supported by the screen's primary output
407 * @return an array of sizes reported as supported by the screen's primary output or - if query failed - NULL
409 EAPI Ecore_X_Randr_Screen_Size_MM *
410 ecore_x_randr_screen_primary_output_sizes_get(Ecore_X_Window root,
413 #ifdef ECORE_XCB_RANDR
414 xcb_randr_get_screen_info_cookie_t cookie;
415 xcb_randr_get_screen_info_reply_t *reply;
416 Ecore_X_Randr_Screen_Size_MM *ret = NULL;
419 LOGFN(__FILE__, __LINE__, __FUNCTION__);
422 #ifdef ECORE_XCB_RANDR
423 cookie = xcb_randr_get_screen_info_unchecked(_ecore_xcb_conn, root);
424 reply = xcb_randr_get_screen_info_reply(_ecore_xcb_conn, cookie, NULL);
428 xcb_randr_screen_size_t *sizes;
430 len = xcb_randr_get_screen_info_sizes_length(reply);
431 sizes = xcb_randr_get_screen_info_sizes(reply);
432 if ((!sizes) || (len <= 0))
438 ret = calloc(len, sizeof(Ecore_X_Randr_Screen_Size_MM));
444 for (i = 0; i < len; i++)
446 ret[i].width = sizes[i].width;
447 ret[i].height = sizes[i].height;
448 ret[i].width_mm = sizes[i].mwidth;
449 ret[i].height_mm = sizes[i].mheight;
462 * @brief get the current set size of a given screen's primary output
463 * @param root window which's primary output will be queried
464 * @param w the current size's width
465 * @param h the current size's height
466 * @param w_mm the current size's width in mm
467 * @param h_mm the current size's height in mm
468 * @param size_index of current set size to be used with ecore_x_randr_primary_output_size_set()
471 ecore_x_randr_screen_primary_output_current_size_get(Ecore_X_Window root,
478 #ifdef ECORE_XCB_RANDR
479 xcb_randr_get_screen_info_cookie_t cookie;
480 xcb_randr_get_screen_info_reply_t *reply;
483 LOGFN(__FILE__, __LINE__, __FUNCTION__);
486 #ifdef ECORE_XCB_RANDR
487 cookie = xcb_randr_get_screen_info_unchecked(_ecore_xcb_conn, root);
488 reply = xcb_randr_get_screen_info_reply(_ecore_xcb_conn, cookie, NULL);
491 int len = 0, idx = 0;
492 xcb_randr_screen_size_t *sizes;
494 len = xcb_randr_get_screen_info_sizes_length(reply);
495 sizes = xcb_randr_get_screen_info_sizes(reply);
496 if ((!sizes) || (len <= 0))
502 if ((idx < len) && (idx >= 0))
504 if (w) *w = sizes[idx].width;
505 if (h) *h = sizes[idx].height;
506 if (w_mm) *w_mm = sizes[idx].mwidth;
507 if (h_mm) *h_mm = sizes[idx].mheight;
508 if (size_index) *size_index = idx;
517 * @brief Sets a given screen's primary output size, but disables all other
518 * outputs at the same time.
520 * @param root Window which's primary output will be queried.
521 * @param size_index Within the list of sizes reported as supported by the root
522 * window's screen primary output.
523 * @return @c EINA_TRUE on success, @c EINA_FALSE on failure due to e.g.
527 ecore_x_randr_screen_primary_output_size_set(Ecore_X_Window root,
530 Eina_Bool ret = EINA_FALSE;
531 #ifdef ECORE_XCB_RANDR
532 xcb_randr_get_screen_info_cookie_t cookie;
533 xcb_randr_get_screen_info_reply_t *reply;
536 LOGFN(__FILE__, __LINE__, __FUNCTION__);
539 #ifdef ECORE_XCB_RANDR
540 if (!((size_index >= 0) && (_ecore_xcb_randr_root_validate(root))))
543 cookie = xcb_randr_get_screen_info_unchecked(_ecore_xcb_conn, root);
544 reply = xcb_randr_get_screen_info_reply(_ecore_xcb_conn, cookie, NULL);
549 len = xcb_randr_get_screen_info_sizes_length(reply);
555 if ((size_index < len) && (size_index >= 0))
557 xcb_randr_set_screen_config_cookie_t scookie;
558 xcb_randr_set_screen_config_reply_t *sreply;
561 xcb_randr_set_screen_config_unchecked(_ecore_xcb_conn, root,
563 reply->config_timestamp,
568 xcb_randr_set_screen_config_reply(_ecore_xcb_conn,
574 ret = (sreply->status == XCB_RANDR_SET_CONFIG_SUCCESS) ?
575 EINA_TRUE : EINA_FALSE;
587 * @param root window which's primary output will be queried
588 * @return currently used refresh rate or - if request failed or RandRR is not available - 0.0
590 EAPI Ecore_X_Randr_Refresh_Rate
591 ecore_x_randr_screen_primary_output_current_refresh_rate_get(Ecore_X_Window root)
593 #ifdef ECORE_XCB_RANDR
594 xcb_randr_get_screen_info_cookie_t cookie;
595 xcb_randr_get_screen_info_reply_t *reply;
596 Ecore_X_Randr_Refresh_Rate ret = 0.0;
599 LOGFN(__FILE__, __LINE__, __FUNCTION__);
602 #ifdef ECORE_XCB_RANDR
603 if (!_ecore_xcb_randr_root_validate(root)) return ret;
605 cookie = xcb_randr_get_screen_info_unchecked(_ecore_xcb_conn, root);
606 reply = xcb_randr_get_screen_info_reply(_ecore_xcb_conn, cookie, NULL);
620 * @param root window which's primary output will be queried
621 * @param size_index referencing the size to query valid refresh rates for
622 * @return currently used refresh rate or - if request failed or RandRR is not available - NULL
624 EAPI Ecore_X_Randr_Refresh_Rate *
625 ecore_x_randr_screen_primary_output_refresh_rates_get(Ecore_X_Window root,
629 #ifdef ECORE_XCB_RANDR
630 xcb_randr_get_screen_info_cookie_t cookie;
631 xcb_randr_get_screen_info_reply_t *reply;
632 Ecore_X_Randr_Refresh_Rate *ret = NULL;
635 LOGFN(__FILE__, __LINE__, __FUNCTION__);
638 #ifdef ECORE_XCB_RANDR
639 if (!_ecore_xcb_randr_root_validate(root)) return ret;
641 cookie = xcb_randr_get_screen_info_unchecked(_ecore_xcb_conn, root);
642 reply = xcb_randr_get_screen_info_reply(_ecore_xcb_conn, cookie, NULL);
647 len = xcb_randr_get_screen_info_rates_length(reply);
650 ret = malloc(sizeof(Ecore_X_Randr_Refresh_Rate) * len);
653 xcb_randr_refresh_rates_iterator_t iter;
656 iter = xcb_randr_get_screen_info_rates_iterator(reply);
657 while (i++ < size_index)
658 xcb_randr_refresh_rates_next(&iter);
660 memcpy(ret, xcb_randr_refresh_rates_rates(iter.data),
661 sizeof(Ecore_X_Randr_Refresh_Rate) * len);
673 * @brief Sets the current primary output's refresh rate.
675 * @param root Window which's primary output will be queried.
676 * @param size_index Referencing the size to be set.
677 * @param rate The refresh rate to be set.
678 * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise.
681 ecore_x_randr_screen_primary_output_refresh_rate_set(Ecore_X_Window root,
683 Ecore_X_Randr_Refresh_Rate rate)
685 Eina_Bool ret = EINA_FALSE;
686 #ifdef ECORE_XCB_RANDR
687 xcb_randr_get_screen_info_cookie_t cookie;
688 xcb_randr_get_screen_info_reply_t *reply;
691 LOGFN(__FILE__, __LINE__, __FUNCTION__);
694 #ifdef ECORE_XCB_RANDR
695 if (_randr_version < RANDR_1_1) return EINA_FALSE;
697 cookie = xcb_randr_get_screen_info_unchecked(_ecore_xcb_conn, root);
698 reply = xcb_randr_get_screen_info_reply(_ecore_xcb_conn, cookie, NULL);
701 xcb_randr_set_screen_config_cookie_t scookie;
702 xcb_randr_set_screen_config_reply_t *sreply;
705 xcb_randr_set_screen_config_unchecked(_ecore_xcb_conn, root,
707 reply->config_timestamp,
709 reply->rotation, rate);
711 xcb_randr_set_screen_config_reply(_ecore_xcb_conn,
717 ret = (sreply->status == XCB_RANDR_SET_CONFIG_SUCCESS) ?
718 EINA_TRUE : EINA_FALSE;
729 * @brief Free detailed mode information. The pointer handed in will be set to
730 * @c NULL after freeing the memory.
732 * @param mode_info The mode information that should be freed.
735 ecore_x_randr_mode_info_free(Ecore_X_Randr_Mode_Info *mode_info)
737 LOGFN(__FILE__, __LINE__, __FUNCTION__);
740 RANDR_CHECK_1_2_RET();
742 if (!mode_info) return;
744 if (mode_info->name) free(mode_info->name);
750 * @param root window which's screen should be queried
751 * @return Ecore_X_Randr_Ouptut_Id or - if query failed or none is set - Ecore_X_Randr_None
753 EAPI Ecore_X_Randr_Output
754 ecore_x_randr_primary_output_get(Ecore_X_Window root)
756 Ecore_X_Randr_Output ret = Ecore_X_Randr_None;
757 #ifdef ECORE_XCB_RANDR
758 xcb_randr_get_output_primary_cookie_t cookie;
759 xcb_randr_get_output_primary_reply_t *reply;
762 LOGFN(__FILE__, __LINE__, __FUNCTION__);
765 #ifdef ECORE_XCB_RANDR
766 RANDR_CHECK_1_3_RET(Ecore_X_Randr_None);
768 if (!_ecore_xcb_randr_root_validate(root))
769 return Ecore_X_Randr_None;
771 cookie = xcb_randr_get_output_primary_unchecked(_ecore_xcb_conn, root);
772 reply = xcb_randr_get_output_primary_reply(_ecore_xcb_conn, cookie, NULL);
783 * @param root window which's screen should be queried
784 * @param output that should be set as given root window's screen primary output
787 ecore_x_randr_primary_output_set(Ecore_X_Window root,
788 Ecore_X_Randr_Output output)
790 LOGFN(__FILE__, __LINE__, __FUNCTION__);
793 #ifdef ECORE_XCB_RANDR
794 RANDR_CHECK_1_3_RET();
796 if ((output) && (_ecore_xcb_randr_root_validate(root)))
797 xcb_randr_set_output_primary(_ecore_xcb_conn, root, output);
801 EAPI Ecore_X_Randr_Mode *
802 ecore_x_randr_output_modes_get(Ecore_X_Window root,
803 Ecore_X_Randr_Output output,
807 Ecore_X_Randr_Mode *modes = NULL;
809 LOGFN(__FILE__, __LINE__, __FUNCTION__);
812 #ifdef ECORE_XCB_RANDR
813 RANDR_CHECK_1_2_RET(NULL);
815 if (_randr_version >= RANDR_1_3)
818 _ecore_xcb_randr_13_output_modes_get(root, output, num, npreferred);
820 else if (_randr_version == RANDR_1_2)
823 _ecore_xcb_randr_12_output_modes_get(root, output, num, npreferred);
831 ecore_x_randr_output_mode_add(Ecore_X_Randr_Output output, Ecore_X_Randr_Mode mode)
833 LOGFN(__FILE__, __LINE__, __FUNCTION__);
836 #ifdef ECORE_XCB_RANDR
837 RANDR_CHECK_1_2_RET(EINA_FALSE);
839 if ((output == Ecore_X_Randr_None) || (mode == Ecore_X_Randr_None))
842 xcb_randr_add_output_mode(_ecore_xcb_conn, output, mode);
849 * @brief get detailed information for a given mode id
850 * @param root window which's screen's ressources are queried
851 * @param mode the XID which identifies the mode of interest
852 * @return mode's detailed information
854 EAPI Ecore_X_Randr_Mode_Info *
855 ecore_x_randr_mode_info_get(Ecore_X_Window root,
856 Ecore_X_Randr_Mode mode)
858 Ecore_X_Randr_Mode_Info *ret = NULL;
860 LOGFN(__FILE__, __LINE__, __FUNCTION__);
863 #ifdef ECORE_XCB_RANDR
864 RANDR_CHECK_1_2_RET(NULL);
866 if (!_ecore_xcb_randr_root_validate(root)) return NULL;
868 if (_randr_version >= RANDR_1_3)
869 ret = _ecore_xcb_randr_13_mode_info_get(root, mode);
870 else if (_randr_version == RANDR_1_2)
871 ret = _ecore_xcb_randr_12_mode_info_get(root, mode);
877 * @brief add a mode to a display
878 * @param root window to which's screen's ressources are added
880 * @return Ecore_X_Randr_Mode of the added mode. Ecore_X_Randr_None if mode
884 EAPI Ecore_X_Randr_Mode
885 ecore_x_randr_mode_info_add(Ecore_X_Window root, Ecore_X_Randr_Mode_Info *mode_info)
887 Ecore_X_Randr_Mode mode = Ecore_X_Randr_None;
888 #ifdef ECORE_XCB_RANDR
889 xcb_randr_create_mode_cookie_t cookie;
890 xcb_randr_create_mode_reply_t *reply;
891 xcb_randr_mode_info_t info;
895 LOGFN(__FILE__, __LINE__, __FUNCTION__);
898 #ifdef ECORE_XCB_RANDR
899 RANDR_CHECK_1_2_RET(EINA_FALSE);
901 if (!mode_info) return Ecore_X_Randr_None;
902 if (!_ecore_xcb_randr_root_validate(root)) return Ecore_X_Randr_None;
904 namelen = strlen(mode_info->name);
906 memset(&info, 0, sizeof(info));
907 info.width = mode_info->width;
908 info.height = mode_info->height;
909 info.dot_clock = mode_info->dotClock;
910 info.hsync_start = mode_info->hSyncStart;
911 info.hsync_end = mode_info->hSyncEnd;
912 info.htotal = mode_info->hTotal;
913 info.hskew = mode_info->hSkew;
914 info.vsync_start = mode_info->vSyncStart;
915 info.vsync_end = mode_info->vSyncEnd;
916 info.vtotal = mode_info->vTotal;
917 info.mode_flags = mode_info->modeFlags;
918 info.name_len = namelen;
921 xcb_randr_create_mode_unchecked(_ecore_xcb_conn, root, info,
922 namelen, mode_info->name);
923 reply = xcb_randr_create_mode_reply(_ecore_xcb_conn, cookie, NULL);
926 mode = mode_info->xid;
934 * @brief get detailed information for all modes related to a root window's screen
935 * @param root window which's screen's ressources are queried
936 * @param num number of modes returned
937 * @return modes' information
939 EAPI Ecore_X_Randr_Mode_Info **
940 ecore_x_randr_modes_info_get(Ecore_X_Window root,
943 Ecore_X_Randr_Mode_Info **ret = NULL;
945 LOGFN(__FILE__, __LINE__, __FUNCTION__);
950 #ifdef ECORE_XCB_RANDR
951 RANDR_CHECK_1_2_RET(NULL);
953 if (!_ecore_xcb_randr_root_validate(root)) return NULL;
955 if (_randr_version >= RANDR_1_3)
956 ret = _ecore_xcb_randr_13_modes_info_get(root, num);
957 else if (_randr_version == RANDR_1_2)
958 ret = _ecore_xcb_randr_12_modes_info_get(root, num);
964 * @brief Gets the width and hight of a given mode.
966 * @param root Window which's screen's ressources are queried.
967 * @param mode The mode which's size is to be looked up.
968 * @param w Width of given mode in px.
969 * @param h Height of given mode in px.
972 ecore_x_randr_mode_size_get(Ecore_X_Window root,
973 Ecore_X_Randr_Mode mode,
977 LOGFN(__FILE__, __LINE__, __FUNCTION__);
980 #ifdef ECORE_XCB_RANDR
981 RANDR_CHECK_1_2_RET();
983 if (mode == Ecore_X_Randr_None) return;
985 if (_randr_version >= RANDR_1_3)
986 _ecore_xcb_randr_13_mode_size_get(root, mode, w, h);
987 else if (_randr_version == RANDR_1_2)
988 _ecore_xcb_randr_12_mode_size_get(root, mode, w, h);
993 * @brief Gets the EDID information of an attached output if available.
994 * Note that this information is not to be compared using ordinary string
995 * comparison functions, since it includes 0-bytes.
997 * @param root Window this information should be queried from.
998 * @param output The XID of the output.
999 * @param length Length of the byte-array. If @c NULL, request will fail.
1000 * @return EDID information of the output.
1002 EAPI unsigned char *
1003 ecore_x_randr_output_edid_get(Ecore_X_Window root,
1004 Ecore_X_Randr_Output output,
1005 unsigned long *length)
1007 unsigned char *ret = NULL;
1008 #ifdef ECORE_XCB_RANDR
1009 xcb_randr_get_output_property_cookie_t cookie;
1010 xcb_randr_get_output_property_reply_t *reply;
1014 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1017 #ifdef ECORE_XCB_RANDR
1018 RANDR_CHECK_1_2_RET(NULL);
1020 if ((!length) || (!_ecore_xcb_randr_output_validate(root, output)))
1023 atom = ecore_x_atom_get("EDID");
1025 xcb_randr_get_output_property_unchecked(_ecore_xcb_conn, output, atom,
1026 XCB_GET_PROPERTY_TYPE_ANY,
1029 xcb_randr_get_output_property_reply(_ecore_xcb_conn, cookie, NULL);
1032 if ((reply->type == XCB_ATOM_INTEGER) && (reply->format == 8))
1034 if (length) *length = reply->num_items;
1035 if ((ret = malloc(reply->num_items * sizeof(unsigned char))))
1037 memcpy(ret, xcb_randr_get_output_property_data(reply),
1038 (reply->num_items * sizeof(unsigned char)));
1048 * @brief Gets the outputs which might be used simultaneously on the same CRTC.
1050 * @param root Window that this information should be queried for.
1051 * @param output The output which's clones we concern.
1052 * @param num Number of possible clones.
1053 * @return The existing outputs, @c NULL otherwise.
1055 EAPI Ecore_X_Randr_Output *
1056 ecore_x_randr_output_clones_get(Ecore_X_Window root,
1057 Ecore_X_Randr_Output output,
1060 Ecore_X_Randr_Output *outputs = NULL;
1062 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1065 #ifdef ECORE_XCB_RANDR
1066 RANDR_CHECK_1_2_RET(NULL);
1068 if (output == Ecore_X_Randr_None) return NULL;
1070 if (_randr_version >= RANDR_1_3)
1071 outputs = _ecore_xcb_randr_13_output_clones_get(root, output, num);
1072 else if (_randr_version == RANDR_1_2)
1073 outputs = _ecore_xcb_randr_12_output_clones_get(root, output, num);
1078 EAPI Ecore_X_Randr_Crtc *
1079 ecore_x_randr_output_possible_crtcs_get(Ecore_X_Window root,
1080 Ecore_X_Randr_Output output,
1083 Ecore_X_Randr_Crtc *crtcs = NULL;
1085 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1088 #ifdef ECORE_XCB_RANDR
1089 RANDR_CHECK_1_2_RET(NULL);
1091 if (output == Ecore_X_Randr_None) return NULL;
1093 if (_randr_version >= RANDR_1_3)
1094 crtcs = _ecore_xcb_randr_13_output_possible_crtcs_get(root, output, num);
1095 else if (_randr_version == RANDR_1_2)
1096 crtcs = _ecore_xcb_randr_12_output_possible_crtcs_get(root, output, num);
1102 * @brief gets the given output's name as reported by X
1103 * @param root the window which's screen will be queried
1104 * @param output The output name given to be reported.
1105 * @param len length of returned c-string.
1106 * @return name of the output as reported by X
1109 ecore_x_randr_output_name_get(Ecore_X_Window root,
1110 Ecore_X_Randr_Output output,
1113 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1116 #ifdef ECORE_XCB_RANDR
1117 RANDR_CHECK_1_2_RET(NULL);
1119 if (output == Ecore_X_Randr_None) return NULL;
1121 if (_randr_version >= RANDR_1_3)
1122 return _ecore_xcb_randr_13_output_name_get(root, output, len);
1123 else if (_randr_version == RANDR_1_2)
1124 return _ecore_xcb_randr_12_output_name_get(root, output, len);
1130 EAPI Ecore_X_Randr_Connection_Status
1131 ecore_x_randr_output_connection_status_get(Ecore_X_Window root,
1132 Ecore_X_Randr_Output output)
1134 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1137 #ifdef ECORE_XCB_RANDR
1138 RANDR_CHECK_1_2_RET(ECORE_X_RANDR_CONNECTION_STATUS_UNKNOWN);
1140 if (output == Ecore_X_Randr_None)
1141 return ECORE_X_RANDR_CONNECTION_STATUS_UNKNOWN;
1143 if (_randr_version >= RANDR_1_3)
1144 return _ecore_xcb_randr_13_output_connection_status_get(root, output);
1145 else if (_randr_version == RANDR_1_2)
1146 return _ecore_xcb_randr_12_output_connection_status_get(root, output);
1149 return ECORE_X_RANDR_CONNECTION_STATUS_UNKNOWN;
1152 EAPI Ecore_X_Randr_Output *
1153 ecore_x_randr_outputs_get(Ecore_X_Window root,
1156 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1159 #ifdef ECORE_XCB_RANDR
1160 RANDR_CHECK_1_2_RET(NULL);
1162 if (_randr_version >= RANDR_1_3)
1163 return _ecore_xcb_randr_13_outputs_get(root, num);
1164 else if (_randr_version == RANDR_1_2)
1165 return _ecore_xcb_randr_12_outputs_get(root, num);
1171 EAPI Ecore_X_Randr_Crtc
1172 ecore_x_randr_output_crtc_get(Ecore_X_Window root,
1173 Ecore_X_Randr_Output output)
1175 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1178 #ifdef ECORE_XCB_RANDR
1179 RANDR_CHECK_1_2_RET(Ecore_X_Randr_None);
1181 if (output == Ecore_X_Randr_None) return Ecore_X_Randr_None;
1183 if (_randr_version >= RANDR_1_3)
1184 return _ecore_xcb_randr_13_output_crtc_get(root, output);
1185 else if (_randr_version == RANDR_1_2)
1186 return _ecore_xcb_randr_12_output_crtc_get(root, output);
1189 return Ecore_X_Randr_None;
1193 ecore_x_randr_output_size_mm_get(Ecore_X_Window root, Ecore_X_Randr_Output output, int *w_mm, int *h_mm)
1195 #ifdef ECORE_XCB_RANDR
1196 xcb_randr_get_output_info_cookie_t ocookie;
1197 xcb_randr_get_output_info_reply_t *oreply;
1198 xcb_timestamp_t timestamp = 0;
1201 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1204 if (w_mm) *w_mm = 0;
1205 if (h_mm) *h_mm = 0;
1207 #ifdef ECORE_XCB_RANDR
1208 RANDR_CHECK_1_2_RET();
1210 if ((output != Ecore_X_Randr_None) && (_randr_version >= RANDR_1_3))
1212 xcb_randr_get_screen_resources_current_reply_t *reply;
1214 reply = _ecore_xcb_randr_13_get_resources(root);
1215 timestamp = reply->config_timestamp;
1218 else if ((output != Ecore_X_Randr_None) && (_randr_version == RANDR_1_2))
1220 xcb_randr_get_screen_resources_reply_t *reply;
1222 reply = _ecore_xcb_randr_12_get_resources(root);
1223 timestamp = reply->config_timestamp;
1228 xcb_randr_get_output_info_unchecked(_ecore_xcb_conn, output, timestamp);
1229 oreply = xcb_randr_get_output_info_reply(_ecore_xcb_conn, ocookie, NULL);
1232 if (w_mm) *w_mm = oreply->mm_width;
1233 if (h_mm) *h_mm = oreply->mm_height;
1240 * @brief Sets the demanded parameters for a given CRTC. Note that the CRTC is
1241 * auto enabled in it's preferred mode, when it was disabled before.
1243 * @param root The root window which's default display will be queried.
1244 * @param crtc The CRTC which's configuration should be altered.
1245 * @param outputs An array of outputs, that should display this CRTC's content.
1246 * @param noutputs Number of outputs in the array of outputs. If set to
1247 * Ecore_X_Randr_Unset, current outputs and number of outputs will be used. If
1248 * set to Ecore_X_Randr_None, CRTC will be disabled.
1249 * @param x New x coordinate. If <0 (e.g. Ecore_X_Randr_Unset) the current x
1250 * coordinate will be assumed.
1251 * @param y New y coordinate. If <0 (e.g. Ecore_X_Randr_Unset) the current y
1252 * coordinate will be assumed.
1253 * @param mode The new mode to be set. If Ecore_X_Randr_None is passed, the
1254 * CRTC will be disabled. If Ecore_X_Randr_Unset is passed, the current mode is
1256 * @param orientation The new orientation to be set. If Ecore_X_Randr_Unset is
1257 * used, the current mode is assumed.
1258 * @return @c EINA_TRUE if the configuration alteration was successful,
1259 * @c EINA_FALSE otherwise.
1262 ecore_x_randr_crtc_settings_set(Ecore_X_Window root,
1263 Ecore_X_Randr_Crtc crtc,
1264 Ecore_X_Randr_Output *outputs,
1268 Ecore_X_Randr_Mode mode,
1269 Ecore_X_Randr_Orientation orientation)
1271 Eina_Bool ret = EINA_FALSE;
1272 #ifdef ECORE_XCB_RANDR
1273 xcb_timestamp_t stamp = 0;
1274 xcb_randr_get_crtc_info_cookie_t ccookie;
1275 xcb_randr_get_crtc_info_reply_t *creply;
1278 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1281 #ifdef ECORE_XCB_RANDR
1282 RANDR_CHECK_1_2_RET(EINA_FALSE);
1284 if (!_ecore_xcb_randr_crtc_validate(root, crtc)) return ret;
1286 if (_randr_version >= RANDR_1_3)
1287 stamp = _ecore_xcb_randr_13_get_resource_timestamp(root);
1288 else if (_randr_version == RANDR_1_2)
1289 stamp = _ecore_xcb_randr_12_get_resource_timestamp(root);
1292 xcb_randr_get_crtc_info_unchecked(_ecore_xcb_conn, crtc, stamp);
1294 xcb_randr_get_crtc_info_reply(_ecore_xcb_conn, ccookie, NULL);
1297 xcb_randr_set_crtc_config_cookie_t scookie;
1298 xcb_randr_set_crtc_config_reply_t *sreply;
1300 if ((mode == Ecore_X_Randr_None) ||
1301 (noutputs == Ecore_X_Randr_None))
1306 else if (noutputs == (int)Ecore_X_Randr_Unset)
1308 outputs = xcb_randr_get_crtc_info_outputs(creply);
1309 noutputs = creply->num_outputs;
1311 if ((int)mode == Ecore_X_Randr_Unset) mode = creply->mode;
1312 if (x < 0) x = creply->x;
1313 if (y < 0) y = creply->y;
1314 if ((int)orientation == Ecore_X_Randr_Unset)
1315 orientation = creply->rotation;
1318 xcb_randr_set_crtc_config_unchecked(_ecore_xcb_conn,
1319 crtc, XCB_CURRENT_TIME, stamp,
1320 x, y, mode, orientation,
1323 xcb_randr_set_crtc_config_reply(_ecore_xcb_conn, scookie, NULL);
1326 ret = (sreply->status == XCB_RANDR_SET_CONFIG_SUCCESS) ?
1327 EINA_TRUE : EINA_FALSE;
1338 * @brief Sets a mode for a CRTC and the outputs attached to it.
1340 * @param root The window's screen to be queried
1341 * @param crtc The CRTC which shall be set
1342 * @param outputs Array of outputs which have to be compatible with the mode. If
1343 * @c NULL CRTC will be disabled.
1344 * @param noutputs Number of outputs in array to be used. Use
1345 * Ecore_X_Randr_Unset (or @c -1) to use currently used outputs.
1346 * @param mode XID of the mode to be set. If set to @c 0 the CRTC will be
1347 * disabled. If set to @c -1 the call will fail.
1348 * @return @c EINA_TRUE if mode setting was successful, @c EINA_FALSE
1352 ecore_x_randr_crtc_mode_set(Ecore_X_Window root,
1353 Ecore_X_Randr_Crtc crtc,
1354 Ecore_X_Randr_Output *outputs,
1356 Ecore_X_Randr_Mode mode)
1358 Eina_Bool ret = EINA_FALSE;
1360 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1363 #ifdef ECORE_XCB_RANDR
1364 RANDR_CHECK_1_2_RET(EINA_FALSE);
1366 if ((int)mode == Ecore_X_Randr_Unset) return ret;
1368 ecore_x_randr_crtc_settings_set(root, crtc, outputs, noutputs,
1369 Ecore_X_Randr_Unset, Ecore_X_Randr_Unset,
1370 mode, Ecore_X_Randr_Unset);
1377 * @brief Get the current set mode of a given CRTC
1378 * @param root the window's screen to be queried
1379 * @param crtc the CRTC which's should be queried
1380 * @return currently set mode or - in case parameters are invalid -
1381 * Ecore_X_Randr_Unset
1383 EAPI Ecore_X_Randr_Mode
1384 ecore_x_randr_crtc_mode_get(Ecore_X_Window root,
1385 Ecore_X_Randr_Crtc crtc)
1387 Ecore_X_Randr_Mode ret = Ecore_X_Randr_Unset;
1388 #ifdef ECORE_XCB_RANDR
1389 xcb_timestamp_t stamp = 0;
1390 xcb_randr_get_crtc_info_cookie_t ocookie;
1391 xcb_randr_get_crtc_info_reply_t *oreply;
1394 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1397 #ifdef ECORE_XCB_RANDR
1398 RANDR_CHECK_1_2_RET(Ecore_X_Randr_Unset);
1400 if (!_ecore_xcb_randr_crtc_validate(root, crtc)) return ret;
1402 if (_randr_version >= RANDR_1_3)
1403 stamp = _ecore_xcb_randr_13_get_resource_timestamp(root);
1404 else if (_randr_version == RANDR_1_2)
1405 stamp = _ecore_xcb_randr_12_get_resource_timestamp(root);
1408 xcb_randr_get_crtc_info_unchecked(_ecore_xcb_conn, crtc, stamp);
1409 oreply = xcb_randr_get_crtc_info_reply(_ecore_xcb_conn, ocookie, NULL);
1420 EAPI Ecore_X_Randr_Orientation
1421 ecore_x_randr_crtc_orientation_get(Ecore_X_Window root,
1422 Ecore_X_Randr_Crtc crtc)
1424 Ecore_X_Randr_Orientation ret = Ecore_X_Randr_None;
1425 #ifdef ECORE_XCB_RANDR
1426 xcb_timestamp_t stamp = 0;
1427 xcb_randr_get_crtc_info_cookie_t ocookie;
1428 xcb_randr_get_crtc_info_reply_t *oreply;
1431 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1434 #ifdef ECORE_XCB_RANDR
1435 RANDR_CHECK_1_2_RET(Ecore_X_Randr_None);
1437 if (!_ecore_xcb_randr_crtc_validate(root, crtc)) return ret;
1439 if (_randr_version >= RANDR_1_3)
1440 stamp = _ecore_xcb_randr_13_get_resource_timestamp(root);
1441 else if (_randr_version == RANDR_1_2)
1442 stamp = _ecore_xcb_randr_12_get_resource_timestamp(root);
1445 xcb_randr_get_crtc_info_unchecked(_ecore_xcb_conn, crtc, stamp);
1446 oreply = xcb_randr_get_crtc_info_reply(_ecore_xcb_conn, ocookie, NULL);
1449 ret = oreply->rotation;
1458 ecore_x_randr_crtc_orientation_set(Ecore_X_Window root,
1459 Ecore_X_Randr_Crtc crtc,
1460 Ecore_X_Randr_Orientation orientation)
1462 Eina_Bool ret = EINA_FALSE;
1464 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1467 #ifdef ECORE_XCB_RANDR
1468 RANDR_CHECK_1_2_RET(EINA_FALSE);
1470 if (orientation != Ecore_X_Randr_None)
1473 ecore_x_randr_crtc_settings_set(root, crtc, NULL,
1474 Ecore_X_Randr_Unset, Ecore_X_Randr_Unset,
1475 Ecore_X_Randr_Unset, Ecore_X_Randr_Unset,
1482 EAPI Ecore_X_Randr_Orientation
1483 ecore_x_randr_crtc_orientations_get(Ecore_X_Window root,
1484 Ecore_X_Randr_Crtc crtc)
1486 Ecore_X_Randr_Orientation ret = Ecore_X_Randr_None;
1487 #ifdef ECORE_XCB_RANDR
1488 xcb_timestamp_t stamp = 0;
1489 xcb_randr_get_crtc_info_cookie_t ocookie;
1490 xcb_randr_get_crtc_info_reply_t *oreply;
1493 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1496 #ifdef ECORE_XCB_RANDR
1497 RANDR_CHECK_1_2_RET(Ecore_X_Randr_None);
1499 if (!_ecore_xcb_randr_crtc_validate(root, crtc)) return ret;
1501 if (_randr_version >= RANDR_1_3)
1502 stamp = _ecore_xcb_randr_13_get_resource_timestamp(root);
1503 else if (_randr_version == RANDR_1_2)
1504 stamp = _ecore_xcb_randr_12_get_resource_timestamp(root);
1507 xcb_randr_get_crtc_info_unchecked(_ecore_xcb_conn, crtc, stamp);
1509 xcb_randr_get_crtc_info_reply(_ecore_xcb_conn, ocookie, NULL);
1512 ret = oreply->rotations;
1521 * @brief get a CRTC's possible outputs.
1522 * @param root the root window which's screen will be queried
1523 * @param num number of possible outputs referenced by given CRTC
1525 EAPI Ecore_X_Randr_Output *
1526 ecore_x_randr_crtc_possible_outputs_get(Ecore_X_Window root,
1527 Ecore_X_Randr_Crtc crtc,
1530 Ecore_X_Randr_Output *ret = NULL;
1531 #ifdef ECORE_XCB_RANDR
1532 xcb_timestamp_t stamp = 0;
1533 xcb_randr_get_crtc_info_cookie_t ocookie;
1534 xcb_randr_get_crtc_info_reply_t *oreply;
1537 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1540 #ifdef ECORE_XCB_RANDR
1541 RANDR_CHECK_1_2_RET(NULL);
1543 if (!_ecore_xcb_randr_crtc_validate(root, crtc)) return ret;
1545 if (_randr_version >= RANDR_1_3)
1546 stamp = _ecore_xcb_randr_13_get_resource_timestamp(root);
1547 else if (_randr_version == RANDR_1_2)
1548 stamp = _ecore_xcb_randr_12_get_resource_timestamp(root);
1551 xcb_randr_get_crtc_info_unchecked(_ecore_xcb_conn, crtc, stamp);
1552 oreply = xcb_randr_get_crtc_info_reply(_ecore_xcb_conn, ocookie, NULL);
1555 if (num) *num = oreply->num_possible_outputs;
1556 ret = malloc(sizeof(Ecore_X_Randr_Output) *
1557 oreply->num_possible_outputs);
1560 memcpy(ret, xcb_randr_get_crtc_info_possible(oreply),
1561 sizeof(Ecore_X_Randr_Output) *
1562 oreply->num_possible_outputs);
1572 * @brief get all known CRTCs related to a root window's screen
1573 * @param root window which's screen's ressources are queried
1574 * @param num number of CRTCs returned
1577 EAPI Ecore_X_Randr_Crtc *
1578 ecore_x_randr_crtcs_get(Ecore_X_Window root,
1581 Ecore_X_Randr_Crtc *ret = NULL;
1583 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1586 #ifdef ECORE_XCB_RANDR
1587 RANDR_CHECK_1_2_RET(NULL);
1589 if (_randr_version >= RANDR_1_3)
1591 xcb_randr_get_screen_resources_current_reply_t *reply;
1593 reply = _ecore_xcb_randr_13_get_resources(root);
1596 if (num) *num = reply->num_crtcs;
1597 ret = malloc(sizeof(Ecore_X_Randr_Crtc) * reply->num_crtcs);
1599 memcpy(ret, xcb_randr_get_screen_resources_current_crtcs(reply),
1600 sizeof(Ecore_X_Randr_Crtc) * reply->num_crtcs);
1604 else if (_randr_version == RANDR_1_2)
1606 xcb_randr_get_screen_resources_reply_t *reply;
1608 reply = _ecore_xcb_randr_12_get_resources(root);
1611 if (num) *num = reply->num_crtcs;
1612 ret = malloc(sizeof(Ecore_X_Randr_Crtc) * reply->num_crtcs);
1614 memcpy(ret, xcb_randr_get_screen_resources_crtcs(reply),
1615 sizeof(Ecore_X_Randr_Crtc) * reply->num_crtcs);
1625 * @deprecated bad naming. Use ecore_x_randr_window_crtcs_get instead.
1626 * @brief Get the CRTCs, which display a certain window.
1628 * @param window Window the displaying CRTCs shall be found for.
1629 * @param num The number of CRTCs displaying the window.
1630 * @return Array of CRTCs that display a certain window. @c NULL if no CRTCs
1631 * was found that displays the specified window.
1633 EAPI Ecore_X_Randr_Crtc *
1634 ecore_x_randr_current_crtc_get(Ecore_X_Window window,
1637 return ecore_x_randr_window_crtcs_get(window, num);
1641 * @brief Get the CRTCs, which display a certain window.
1643 * @param window Window the displaying crtcs shall be found for.
1644 * @param num The number of crtcs displaying the window.
1645 * @return Array of crtcs that display a certain window. @c NULL if no crtcs
1646 * was found that displays the specified window.
1649 EAPI Ecore_X_Randr_Crtc *
1650 ecore_x_randr_window_crtcs_get(Ecore_X_Window window,
1653 #ifdef ECORE_XCB_RANDR
1654 Ecore_X_Window root;
1655 Eina_Rectangle w_geo, c_geo;
1656 Ecore_X_Randr_Crtc *crtcs, *ret = NULL;
1657 Ecore_X_Randr_Mode mode;
1658 int ncrtcs, i, nret = 0;
1659 xcb_translate_coordinates_cookie_t cookie;
1660 xcb_translate_coordinates_reply_t *trans;
1663 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1666 #ifdef ECORE_XCB_RANDR
1667 RANDR_CHECK_1_2_RET(NULL);
1669 ecore_x_window_geometry_get(window, &w_geo.x, &w_geo.y, &w_geo.w, &w_geo.h);
1671 root = ecore_x_window_root_get(window);
1672 crtcs = ecore_x_randr_crtcs_get(root, &ncrtcs);
1673 if (!crtcs) goto _ecore_x_randr_window_crtcs_get_fail;
1675 /* now get window RELATIVE to root window - thats what matters. */
1676 cookie = xcb_translate_coordinates(_ecore_xcb_conn, window, root, 0, 0);
1677 trans = xcb_translate_coordinates_reply(_ecore_xcb_conn, cookie, NULL);
1678 w_geo.x = trans->dst_x;
1679 w_geo.y = trans->dst_y;
1682 ret = calloc(1, ncrtcs * sizeof(Ecore_X_Randr_Crtc));
1686 goto _ecore_x_randr_window_crtcs_get_fail;
1688 for (i = 0, nret = 0; i < ncrtcs; i++)
1690 /* if crtc is not enabled, don't bother about it any further */
1691 mode = ecore_x_randr_crtc_mode_get(root, crtcs[i]);
1692 if (mode == Ecore_X_Randr_None) continue;
1694 ecore_x_randr_crtc_geometry_get(root, crtcs[i], &c_geo.x, &c_geo.y,
1695 &c_geo.w, &c_geo.h);
1696 if (eina_rectangles_intersect(&w_geo, &c_geo))
1698 ret[nret] = crtcs[i];
1704 if (num) *num = nret;
1707 _ecore_x_randr_window_crtcs_get_fail:
1714 * @brief get a CRTC's outputs.
1715 * @param root the root window which's screen will be queried
1716 * @param num number of outputs referenced by given CRTC
1718 EAPI Ecore_X_Randr_Output *
1719 ecore_x_randr_crtc_outputs_get(Ecore_X_Window root,
1720 Ecore_X_Randr_Crtc crtc,
1723 Ecore_X_Randr_Output *ret = NULL;
1724 #ifdef ECORE_XCB_RANDR
1725 xcb_timestamp_t stamp = 0;
1726 xcb_randr_get_crtc_info_cookie_t ocookie;
1727 xcb_randr_get_crtc_info_reply_t *oreply;
1730 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1733 #ifdef ECORE_XCB_RANDR
1734 RANDR_CHECK_1_2_RET(NULL);
1736 if (!_ecore_xcb_randr_crtc_validate(root, crtc)) return ret;
1738 if (_randr_version >= RANDR_1_3)
1739 stamp = _ecore_xcb_randr_13_get_resource_timestamp(root);
1740 else if (_randr_version == RANDR_1_2)
1741 stamp = _ecore_xcb_randr_12_get_resource_timestamp(root);
1744 xcb_randr_get_crtc_info_unchecked(_ecore_xcb_conn, crtc, stamp);
1745 oreply = xcb_randr_get_crtc_info_reply(_ecore_xcb_conn, ocookie, NULL);
1748 if (num) *num = oreply->num_outputs;
1749 ret = malloc(sizeof(Ecore_X_Randr_Output) * oreply->num_outputs);
1751 memcpy(ret, xcb_randr_get_crtc_info_outputs(oreply),
1752 sizeof(Ecore_X_Randr_Output) * oreply->num_outputs);
1761 ecore_x_randr_crtc_geometry_get(Ecore_X_Window root,
1762 Ecore_X_Randr_Crtc crtc,
1768 #ifdef ECORE_XCB_RANDR
1769 xcb_timestamp_t stamp = 0;
1770 xcb_randr_get_crtc_info_cookie_t ocookie;
1771 xcb_randr_get_crtc_info_reply_t *oreply;
1774 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1777 #ifdef ECORE_XCB_RANDR
1778 RANDR_CHECK_1_2_RET();
1780 if (!_ecore_xcb_randr_crtc_validate(root, crtc)) return;
1782 if (_randr_version >= RANDR_1_3)
1783 stamp = _ecore_xcb_randr_13_get_resource_timestamp(root);
1784 else if (_randr_version == RANDR_1_2)
1785 stamp = _ecore_xcb_randr_12_get_resource_timestamp(root);
1788 xcb_randr_get_crtc_info_unchecked(_ecore_xcb_conn, crtc, stamp);
1789 oreply = xcb_randr_get_crtc_info_reply(_ecore_xcb_conn, ocookie, NULL);
1792 if (x) *x = oreply->x;
1793 if (y) *y = oreply->y;
1794 if (w) *w = oreply->width;
1795 if (h) *h = oreply->height;
1802 * @brief Sets a CRTC relative to another one.
1804 * @param root The window on which CRTC's position will be set.
1805 * @param crtc_r1 The CRTC to be positioned.
1806 * @param crtc_r2 The CRTC the position should be relative to.
1807 * @param policy The relation between the crtcs.
1808 * @param alignment In case CRTCs size differ, aligns CRTC1 accordingly at
1810 * @return @c EINA_TRUE if crtc could be successfully positioned, @c EINA_FALSE
1811 * if repositioning failed or if position of new crtc would be out of given
1812 * screen's min/max bounds.
1815 ecore_x_randr_crtc_pos_relative_set(Ecore_X_Window root,
1816 Ecore_X_Randr_Crtc crtc_r1,
1817 Ecore_X_Randr_Crtc crtc_r2,
1818 Ecore_X_Randr_Output_Policy policy,
1819 Ecore_X_Randr_Relative_Alignment alignment)
1821 #ifdef ECORE_XCB_RANDR
1822 Eina_Rectangle r1, r2;
1823 int w_max = 0, h_max = 0, cw = 0, ch = 0, xn = -1, yn = -1;
1826 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1829 #ifdef ECORE_XCB_RANDR
1830 RANDR_CHECK_1_2_RET(EINA_FALSE);
1832 if ((ecore_x_randr_crtc_mode_get(root, crtc_r1) == 0) ||
1833 (ecore_x_randr_crtc_mode_get(root, crtc_r2) == 0))
1836 if ((!_ecore_xcb_randr_crtc_validate(root, crtc_r1) ||
1837 (!(crtc_r1 != crtc_r2) && (!_ecore_xcb_randr_crtc_validate(root, crtc_r2)))))
1840 ecore_x_randr_crtc_geometry_get(root, crtc_r1, &r1.x, &r1.y, &r1.w, &r1.h);
1841 ecore_x_randr_crtc_geometry_get(root, crtc_r2, &r2.x, &r2.y, &r2.w, &r2.h);
1842 ecore_x_randr_screen_size_range_get(root, NULL, NULL, &w_max, &h_max);
1843 ecore_x_randr_screen_current_size_get(root, &cw, &ch, NULL, NULL);
1847 case ECORE_X_RANDR_OUTPUT_POLICY_RIGHT:
1849 if (alignment == ECORE_X_RANDR_RELATIVE_ALIGNMENT_NONE)
1851 else if (alignment == ECORE_X_RANDR_RELATIVE_ALIGNMENT_CENTER_REL)
1852 yn = ((int)(((double)r2.h / 2.0) + (double)r2.y - ((double)r1.h / 2.0)));
1853 else if (alignment == ECORE_X_RANDR_RELATIVE_ALIGNMENT_CENTER_SCR)
1854 yn = ((int)((double)ch / 2.0) - ((double)r1.h / 2.0));
1857 case ECORE_X_RANDR_OUTPUT_POLICY_LEFT:
1859 if (alignment == ECORE_X_RANDR_RELATIVE_ALIGNMENT_NONE)
1861 else if (alignment == ECORE_X_RANDR_RELATIVE_ALIGNMENT_CENTER_REL)
1862 yn = ((int)(((double)r2.h / 2.0) + (double)r2.y - ((double)r1.h / 2.0)));
1863 else if (alignment == ECORE_X_RANDR_RELATIVE_ALIGNMENT_CENTER_SCR)
1864 yn = ((int)((double)ch / 2.0) - ((double)r1.h / 2.0));
1867 case ECORE_X_RANDR_OUTPUT_POLICY_BELOW:
1869 if (alignment == ECORE_X_RANDR_RELATIVE_ALIGNMENT_NONE)
1871 else if (alignment == ECORE_X_RANDR_RELATIVE_ALIGNMENT_CENTER_REL)
1872 xn = ((int)((((double)r2.x + (double)r2.w) / 2.0) - ((double)r1.w / 2.0)));
1873 else if (alignment == ECORE_X_RANDR_RELATIVE_ALIGNMENT_CENTER_SCR)
1874 xn = ((int)((double)cw / 2.0));
1877 case ECORE_X_RANDR_OUTPUT_POLICY_ABOVE:
1879 if (alignment == ECORE_X_RANDR_RELATIVE_ALIGNMENT_NONE)
1881 else if (alignment == ECORE_X_RANDR_RELATIVE_ALIGNMENT_CENTER_REL)
1882 xn = ((int)((((double)r2.x + (double)r2.w) / 2.0) - ((double)r1.w / 2.0)));
1883 else if (alignment == ECORE_X_RANDR_RELATIVE_ALIGNMENT_CENTER_SCR)
1884 xn = ((int)((double)cw / 2.0));
1887 case ECORE_X_RANDR_OUTPUT_POLICY_CLONE:
1888 return ecore_x_randr_crtc_pos_set(root, crtc_r1, r2.x, r2.y);
1891 case ECORE_X_RANDR_OUTPUT_POLICY_NONE:
1897 if ((xn == r1.x) && (yn == r1.x)) return EINA_TRUE;
1898 if (((yn + r1.h) > h_max) || ((xn + r1.w) > w_max))
1901 return ecore_x_randr_crtc_pos_set(root, crtc_r1, xn, yn);
1908 ecore_x_randr_move_all_crtcs_but(Ecore_X_Window root,
1909 const Ecore_X_Randr_Crtc *not_moved,
1914 Eina_Bool ret = EINA_FALSE;
1915 #ifdef ECORE_XCB_RANDR
1916 Ecore_X_Randr_Crtc *crtcs = NULL, *move = NULL;
1917 int i = 0, j = 0, k = 0, n = 0, total = 0;
1920 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1923 #ifdef ECORE_XCB_RANDR
1924 if ((num <= 0) || (!not_moved) || (!_ecore_xcb_randr_root_validate(root)))
1927 crtcs = ecore_x_randr_crtcs_get(root, &total);
1929 move = malloc(sizeof(Ecore_X_Randr_Crtc) * n);
1932 for (i = 0, k = 0; (i < total) && (k < n); i++)
1934 for (j = 0; j < num; j++)
1935 if (crtcs[i] == not_moved[j]) break;
1937 move[k++] = crtcs[i];
1939 ret = ecore_x_randr_move_crtcs(root, move, n, dx, dy);
1949 ecore_x_randr_crtc_pos_get(Ecore_X_Window root,
1950 Ecore_X_Randr_Crtc crtc,
1954 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1957 #ifdef ECORE_XCB_RANDR
1958 RANDR_CHECK_1_2_RET();
1960 ecore_x_randr_crtc_geometry_get(root, crtc, x, y, NULL, NULL);
1965 * @brief Sets the position of given CRTC within root window's screen.
1967 * @param root The window's screen to be queried.
1968 * @param crtc The CRTC which's position within the mentioned screen is to be
1970 * @param x Position on the x-axis (0 == left) of the screen. if x < 0 current
1971 * value will be kept.
1972 * @param y Position on the y-ayis (0 == top) of the screen. if y < 0, current
1973 * value will be kept.
1974 * @return @c EINA_TRUE if position could be successfully be altered.
1977 ecore_x_randr_crtc_pos_set(Ecore_X_Window root,
1978 Ecore_X_Randr_Crtc crtc,
1982 Eina_Bool ret = EINA_FALSE;
1983 #ifdef ECORE_XCB_RANDR
1984 int w = 0, h = 0, nw = 0, nh = 0;
1985 Eina_Rectangle rect;
1988 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1991 #ifdef ECORE_XCB_RANDR
1992 RANDR_CHECK_1_2_RET(EINA_FALSE);
1994 ecore_x_randr_crtc_geometry_get(root, crtc,
1995 &rect.x, &rect.y, &rect.w, &rect.h);
1996 ecore_x_randr_screen_current_size_get(root, &w, &h, NULL, NULL);
1997 if (x < 0) x = rect.x;
1998 if (y < 0) y = rect.y;
1999 if ((x + rect.w) > w)
2001 if ((y + rect.h) > h)
2004 if ((nw != 0) || (nh != 0))
2006 if (!ecore_x_randr_screen_current_size_set(root, nw, nh, 0, 0))
2010 ret = ecore_x_randr_crtc_settings_set(root, crtc, NULL, -1, x, y, -1, -1);
2017 ecore_x_randr_crtc_size_get(Ecore_X_Window root,
2018 Ecore_X_Randr_Crtc crtc,
2022 LOGFN(__FILE__, __LINE__, __FUNCTION__);
2025 #ifdef ECORE_XCB_RANDR
2026 RANDR_CHECK_1_2_RET();
2027 ecore_x_randr_crtc_geometry_get(root, crtc, NULL, NULL, w, h);
2032 ecore_x_randr_crtc_clone_set(Ecore_X_Window root, Ecore_X_Randr_Crtc original, Ecore_X_Randr_Crtc cln)
2034 Eina_Bool ret = EINA_FALSE;
2036 LOGFN(__FILE__, __LINE__, __FUNCTION__);
2039 #ifdef ECORE_XCB_RANDR
2040 RANDR_CHECK_1_2_RET(EINA_FALSE);
2042 if (_randr_version >= RANDR_1_3)
2044 xcb_randr_get_screen_resources_current_reply_t *reply;
2045 xcb_timestamp_t stamp = 0;
2047 reply = _ecore_xcb_randr_13_get_resources(root);
2050 xcb_randr_get_crtc_info_cookie_t rcookie;
2051 xcb_randr_get_crtc_info_reply_t *rreply;
2053 if (_randr_version >= RANDR_1_3)
2054 stamp = _ecore_xcb_randr_13_get_resource_timestamp(root);
2055 else if (_randr_version == RANDR_1_2)
2056 stamp = _ecore_xcb_randr_12_get_resource_timestamp(root);
2059 xcb_randr_get_crtc_info_unchecked(_ecore_xcb_conn, original,
2062 rreply = xcb_randr_get_crtc_info_reply(_ecore_xcb_conn,
2067 Ecore_X_Randr_Orientation orient = 0;
2068 Ecore_X_Randr_Mode mode = -1;
2072 orient = rreply->rotation;
2073 mode = rreply->mode;
2077 ret = ecore_x_randr_crtc_settings_set(root, cln, NULL, -1,
2078 ox, oy, mode, orient);
2089 EAPI Ecore_X_Randr_Crtc_Info *
2090 ecore_x_randr_crtc_info_get(Ecore_X_Window root, const Ecore_X_Randr_Crtc crtc)
2092 Ecore_X_Randr_Crtc_Info *ret = NULL;
2094 LOGFN(__FILE__, __LINE__, __FUNCTION__);
2097 #ifdef ECORE_XCB_RANDR
2098 RANDR_CHECK_1_2_RET(NULL);
2100 if (!_ecore_xcb_randr_crtc_validate(root, crtc)) return NULL;
2102 if (_randr_version >= RANDR_1_3)
2104 xcb_randr_get_screen_resources_current_reply_t *reply;
2105 xcb_timestamp_t stamp = 0;
2107 reply = _ecore_xcb_randr_13_get_resources(root);
2110 xcb_randr_get_crtc_info_cookie_t rcookie;
2111 xcb_randr_get_crtc_info_reply_t *rreply;
2113 if (_randr_version >= RANDR_1_3)
2114 stamp = _ecore_xcb_randr_13_get_resource_timestamp(root);
2115 else if (_randr_version == RANDR_1_2)
2116 stamp = _ecore_xcb_randr_12_get_resource_timestamp(root);
2119 xcb_randr_get_crtc_info_unchecked(_ecore_xcb_conn, crtc,
2122 rreply = xcb_randr_get_crtc_info_reply(_ecore_xcb_conn,
2126 if ((ret = malloc(sizeof(Ecore_X_Randr_Crtc_Info))))
2128 ret->timestamp = rreply->timestamp;
2131 ret->width = rreply->width;
2132 ret->height = rreply->height;
2133 ret->mode = rreply->mode;
2134 ret->rotation = rreply->rotation;
2136 xcb_randr_get_crtc_info_outputs_length(rreply);
2138 xcb_randr_get_crtc_info_possible_length(rreply);
2141 malloc(ret->noutput * sizeof(Ecore_X_Randr_Output))))
2143 xcb_randr_output_t *outs;
2146 outs = xcb_randr_get_crtc_info_outputs(rreply);
2147 for (i = 0; i < ret->noutput; i++)
2148 ret->outputs[i] = outs[i];
2151 if ((ret->possible =
2152 malloc(ret->npossible * sizeof(Ecore_X_Randr_Output))))
2154 xcb_randr_output_t *outs;
2157 outs = xcb_randr_get_crtc_info_possible(rreply);
2158 for (i = 0; i < ret->npossible; i++)
2159 ret->possible[i] = outs[i];
2174 ecore_x_randr_crtc_info_free(Ecore_X_Randr_Crtc_Info *info)
2176 #ifdef ECORE_XCB_RANDR
2177 if (_randr_version >= RANDR_1_2)
2181 if (info->outputs) free(info->outputs);
2182 if (info->possible) free(info->possible);
2190 EAPI Ecore_X_Randr_Refresh_Rate
2191 ecore_x_randr_crtc_refresh_rate_get(Ecore_X_Window root,
2192 Ecore_X_Randr_Crtc crtc,
2193 Ecore_X_Randr_Mode mode)
2195 Ecore_X_Randr_Refresh_Rate ret = 0.0;
2197 LOGFN(__FILE__, __LINE__, __FUNCTION__);
2200 #ifdef ECORE_XCB_RANDR
2201 RANDR_CHECK_1_2_RET(0.0);
2203 if (!_ecore_xcb_randr_crtc_validate(root, crtc)) return 0.0;
2205 if (_randr_version >= RANDR_1_3)
2207 xcb_randr_get_screen_resources_current_reply_t *reply;
2209 reply = _ecore_xcb_randr_13_get_resources(root);
2212 xcb_randr_mode_info_iterator_t miter;
2215 xcb_randr_get_screen_resources_current_modes_iterator(reply);
2218 xcb_randr_mode_info_t *minfo;
2221 if (minfo->id == mode)
2223 if ((minfo->htotal) && (minfo->vtotal))
2225 ret = ((double)minfo->dot_clock /
2226 ((double)minfo->htotal *
2227 (double)minfo->vtotal));
2231 xcb_randr_mode_info_next(&miter);
2236 else if (_randr_version == RANDR_1_2)
2238 xcb_randr_get_screen_resources_reply_t *reply;
2240 reply = _ecore_xcb_randr_12_get_resources(root);
2243 xcb_randr_mode_info_iterator_t miter;
2245 miter = xcb_randr_get_screen_resources_modes_iterator(reply);
2248 xcb_randr_mode_info_t *minfo;
2251 if (minfo->id == mode)
2253 if ((minfo->htotal) && (minfo->vtotal))
2255 ret = ((double)minfo->dot_clock /
2256 ((double)minfo->htotal *
2257 (double)minfo->vtotal));
2261 xcb_randr_mode_info_next(&miter);
2271 * @brief Move given CRTCs belonging to the given root window's screen dx/dy
2272 * pixels relative to their current position. The screen size will be
2273 * automatically adjusted if necessary and possible.
2275 * @param root Window which's screen's resources are used.
2276 * @param crtcs List of CRTCs to be moved.
2277 * @param ncrtc Number of CRTCs in array.
2278 * @param dx Amount of pixels the CRTCs should be moved in x direction.
2279 * @param dy Amount of pixels the CRTCs should be moved in y direction.
2280 * @return @c EINA_TRUE if all crtcs could be moved successfully.
2283 ecore_x_randr_move_crtcs(Ecore_X_Window root,
2284 const Ecore_X_Randr_Crtc *crtcs,
2289 Eina_Bool ret = EINA_TRUE;
2290 #ifdef ECORE_XCB_RANDR
2291 xcb_timestamp_t stamp = 0;
2292 xcb_randr_get_crtc_info_reply_t *oreply[num];
2293 int i = 0, cw = 0, ch = 0;
2294 int mw = 0, mh = 0, nw = 0, nh = 0;
2297 LOGFN(__FILE__, __LINE__, __FUNCTION__);
2300 #ifdef ECORE_XCB_RANDR
2301 RANDR_CHECK_1_2_RET(EINA_FALSE);
2303 if (!_ecore_xcb_randr_root_validate(root)) return EINA_FALSE;
2305 if (_randr_version >= RANDR_1_3)
2306 stamp = _ecore_xcb_randr_13_get_resource_timestamp(root);
2307 else if (_randr_version == RANDR_1_2)
2308 stamp = _ecore_xcb_randr_12_get_resource_timestamp(root);
2310 ecore_x_randr_screen_size_range_get(root, NULL, NULL, &mw, &mh);
2311 ecore_x_randr_screen_current_size_get(root, &cw, &ch, NULL, NULL);
2315 for (i = 0; i < num; i++)
2317 xcb_randr_get_crtc_info_cookie_t ocookie;
2320 xcb_randr_get_crtc_info_unchecked(_ecore_xcb_conn, crtcs[i],
2322 oreply[i] = xcb_randr_get_crtc_info_reply(_ecore_xcb_conn,
2326 if (((oreply[i]->x + dx) < 0) ||
2327 ((oreply[i]->y + dy) < 0) ||
2328 ((oreply[i]->x + oreply[i]->width + dx) > mw) ||
2329 ((oreply[i]->y + oreply[i]->height + dy) > mh))
2333 nw = MAX((int)(oreply[i]->x + oreply[i]->width + dx), nw);
2334 nh = MAX((int)(oreply[i]->y + oreply[i]->height + dy), nh);
2338 if ((nw > cw) || (nh > ch))
2340 if (!ecore_x_randr_screen_current_size_set(root, nw, nh, -1, -1))
2342 for (i = 0; i < num; i++)
2343 if (oreply[i]) free(oreply[i]);
2349 for (i = 0; ((i < num) && (oreply[i])); i++)
2351 if (!oreply[i]) continue;
2352 if (!ecore_x_randr_crtc_settings_set(root, crtcs[i], NULL, -1,
2353 (oreply[i]->x + dx),
2354 (oreply[i]->y + dy),
2356 oreply[i]->rotation))
2368 ecore_x_randr_crtc_settings_set(root, crtcs[i], NULL, -1,
2369 (oreply[i]->x - dx),
2370 (oreply[i]->y - dy),
2372 oreply[i]->rotation);
2376 for (i = 0; i < num; i++)
2377 if (oreply[i]) free(oreply[i]);
2384 * @brief enable event selection. This enables basic interaction with
2385 * output/crtc events and requires RRandR >= 1.2.
2386 * @param win select this window's properties for RandRR events
2387 * @param on enable/disable selecting
2390 ecore_x_randr_events_select(Ecore_X_Window win,
2393 #ifdef ECORE_XCB_RANDR
2397 LOGFN(__FILE__, __LINE__, __FUNCTION__);
2400 #ifdef ECORE_XCB_RANDR
2403 mask = XCB_RANDR_NOTIFY_MASK_SCREEN_CHANGE;
2404 if (_randr_version >= ((1 << 16) | 2))
2406 mask |= (XCB_RANDR_NOTIFY_MASK_CRTC_CHANGE |
2407 XCB_RANDR_NOTIFY_MASK_OUTPUT_CHANGE |
2408 XCB_RANDR_NOTIFY_MASK_OUTPUT_PROPERTY);
2412 xcb_randr_select_input(_ecore_xcb_conn, win, mask);
2417 * @brief removes unused screen space. The most upper left CRTC is set to 0x0
2418 * and all other CRTCs dx,dy respectively.
2419 * @param root the window's screen which will be reset.
2422 ecore_x_randr_screen_reset(Ecore_X_Window root)
2424 #ifdef ECORE_XCB_RANDR
2425 xcb_timestamp_t stamp = 0;
2426 Ecore_X_Randr_Crtc *crtcs = NULL;
2427 int total = 0, i = 0, w = 0, h = 0;
2428 int dx = 100000, dy = 100000, num = 0;
2431 LOGFN(__FILE__, __LINE__, __FUNCTION__);
2434 #ifdef ECORE_XCB_RANDR
2435 if (!_ecore_xcb_randr_root_validate(root)) return;
2436 crtcs = ecore_x_randr_crtcs_get(root, &total);
2438 if (_randr_version >= RANDR_1_3)
2439 stamp = _ecore_xcb_randr_13_get_resource_timestamp(root);
2440 else if (_randr_version == RANDR_1_2)
2441 stamp = _ecore_xcb_randr_12_get_resource_timestamp(root);
2443 /* I hate declaring variables inside code like this, but we need the
2444 * value of 'total' before we can */
2445 Ecore_X_Randr_Crtc enabled[total];
2447 for (i = 0; i < total; i++)
2449 xcb_randr_get_crtc_info_cookie_t ocookie;
2450 xcb_randr_get_crtc_info_reply_t *oreply;
2453 xcb_randr_get_crtc_info_unchecked(_ecore_xcb_conn, crtcs[i], stamp);
2454 oreply = xcb_randr_get_crtc_info_reply(_ecore_xcb_conn,
2456 if (!oreply) continue;
2457 if ((oreply->mode <= 0) || (oreply->num_outputs == 0))
2463 enabled[num++] = crtcs[i];
2464 if ((int)(oreply->x + oreply->width) > w)
2465 w = (oreply->x + oreply->width);
2466 if ((int)(oreply->y + oreply->height) > h)
2467 h = (oreply->y + oreply->height);
2469 if (oreply->x < dx) dx = oreply->x;
2470 if (oreply->y < dy) dy = oreply->y;
2476 if ((dx > 0) || (dy > 0))
2478 if (ecore_x_randr_move_crtcs(root, enabled, num, -dx, -dy))
2485 ecore_x_randr_screen_current_size_set(root, w, h, -1, -1);
2490 * @param root window which's screen will be queried
2491 * @param wmin minimum width the screen can be set to
2492 * @param hmin minimum height the screen can be set to
2493 * @param wmax maximum width the screen can be set to
2494 * @param hmax maximum height the screen can be set to
2497 ecore_x_randr_screen_size_range_get(Ecore_X_Window root,
2503 #ifdef ECORE_XCB_RANDR
2504 xcb_randr_get_screen_size_range_cookie_t cookie;
2505 xcb_randr_get_screen_size_range_reply_t *reply;
2508 LOGFN(__FILE__, __LINE__, __FUNCTION__);
2511 #ifdef ECORE_XCB_RANDR
2512 RANDR_CHECK_1_2_RET();
2514 cookie = xcb_randr_get_screen_size_range_unchecked(_ecore_xcb_conn, root);
2515 reply = xcb_randr_get_screen_size_range_reply(_ecore_xcb_conn, cookie, NULL);
2518 if (minw) *minw = reply->min_width;
2519 if (minh) *minh = reply->min_height;
2520 if (maxw) *maxw = reply->max_width;
2521 if (maxh) *maxh = reply->max_height;
2528 * @param w width of screen in px
2529 * @param h height of screen in px
2532 ecore_x_randr_screen_current_size_get(Ecore_X_Window root,
2538 #ifdef ECORE_XCB_RANDR
2539 Ecore_X_Randr_Screen scr = 0;
2541 # define RANDR_VALIDATE_ROOT(screen, root) \
2542 ((screen == _ecore_xcb_randr_root_to_screen(root)) != -1)
2545 LOGFN(__FILE__, __LINE__, __FUNCTION__);
2548 #ifdef ECORE_XCB_RANDR
2549 RANDR_CHECK_1_2_RET();
2551 if (!RANDR_VALIDATE_ROOT(scr, root)) return;
2553 s = ecore_x_screen_get(scr);
2554 if (w) *w = s->width_in_pixels;
2555 if (h) *h = s->height_in_pixels;
2556 if (w_mm) *w_mm = s->width_in_millimeters;
2557 if (h_mm) *h_mm = s->height_in_millimeters;
2562 * @param root Window which's screen's size should be set. If invalid (e.g.
2563 * @c NULL) no action is taken.
2564 * @param w Width in px the screen should be set to. If out of valid
2565 * boundaries, current value is assumed.
2566 * @param h Height in px the screen should be set to. If out of valid
2567 * boundaries, current value is assumed.
2568 * @param w_mm Width in mm the screen should be set to. If @c 0, current
2569 * aspect is assumed.
2570 * @param h_mm Height in mm the screen should be set to. If @c 0, current
2571 * aspect is assumed.
2572 * @return @c EINA_TRUE if request was successfully sent or screen is already
2573 * in requested size, @c EINA_FALSE if parameters are invalid.
2576 ecore_x_randr_screen_current_size_set(Ecore_X_Window root,
2582 Eina_Bool ret = EINA_TRUE;
2583 #ifdef ECORE_XCB_RANDR
2584 Ecore_X_Randr_Screen scr;
2585 int wc = 0, hc = 0, w_mm_c = 0, h_mm_c = 0;
2586 int mw = 0, mh = 0, xw = 0, xh = 0;
2587 # define RANDR_VALIDATE_ROOT(screen, root) \
2588 ((screen == _ecore_xcb_randr_root_to_screen(root)) != -1)
2591 LOGFN(__FILE__, __LINE__, __FUNCTION__);
2594 #ifdef ECORE_XCB_RANDR
2595 RANDR_CHECK_1_2_RET(EINA_FALSE);
2597 if (!RANDR_VALIDATE_ROOT(scr, root)) return EINA_FALSE;
2598 ecore_x_randr_screen_current_size_get(root, &wc, &hc, &w_mm_c, &h_mm_c);
2599 if ((w == wc) && (h == hc) && (w_mm == w_mm_c) && (h_mm == h_mm_c))
2601 ecore_x_randr_screen_size_range_get(root, &mw, &mh, &xw, &xh);
2602 if (((w != 1) && ((w < mw) || (w > xw))) ||
2603 ((h != -1) && ((h < mh) || (h > xh)))) return EINA_FALSE;
2606 w = ((xcb_screen_t *)_ecore_xcb_screen)->width_in_pixels;
2608 h = ((xcb_screen_t *)_ecore_xcb_screen)->height_in_pixels;
2610 /* NB: Hmmmm, xlib version divides w_mm by width ... that seems wrong */
2612 w_mm = ((xcb_screen_t *)_ecore_xcb_screen)->width_in_millimeters;
2614 h_mm = ((xcb_screen_t *)_ecore_xcb_screen)->height_in_millimeters;
2616 xcb_randr_set_screen_size(_ecore_xcb_conn, root, w, h, w_mm, h_mm);
2623 * @deprecated bad naming. Use ecore_x_randr_window_outputs_get instead.
2624 * @brief Get the outputs, which display a certain window.
2626 * @param window Window the displaying outputs shall be found for.
2627 * @param num The number of outputs displaying the window.
2628 * @return Array of outputs that display a certain window. @c NULL if no
2629 * outputs was found that displays the specified window.
2632 Ecore_X_Randr_Output *
2633 ecore_x_randr_current_output_get(Ecore_X_Window window,
2636 return ecore_x_randr_window_outputs_get(window, num);
2640 * @brief Get the outputs, which display a certain window.
2642 * @param window Window the displaying outputs shall be found for.
2643 * @param num The number of outputs displaying the window.
2644 * @return Array of outputs that display a certain window. @c NULL if no
2645 * outputs was found that displays the specified window.
2647 EAPI Ecore_X_Randr_Output *
2648 ecore_x_randr_window_outputs_get(Ecore_X_Window window,
2651 #ifdef ECORE_XCB_RANDR
2652 Ecore_X_Window root;
2653 Ecore_X_Randr_Crtc *crtcs;
2654 Ecore_X_Randr_Output *outputs, *ret = NULL, *tret;
2655 int ncrtcs, noutputs, i, nret = 0;
2658 LOGFN(__FILE__, __LINE__, __FUNCTION__);
2663 #ifdef ECORE_XCB_RANDR
2664 if (_randr_version < RANDR_1_2) goto _ecore_x_randr_current_output_get_fail;
2666 root = ecore_x_window_root_get(window);
2667 if (!(crtcs = ecore_x_randr_window_crtcs_get(window, &ncrtcs)))
2668 goto _ecore_x_randr_current_output_get_fail;
2670 for (i = 0, nret = 0; i < ncrtcs; i++)
2673 outputs = ecore_x_randr_crtc_outputs_get(root, crtcs[i],
2676 goto _ecore_x_randr_current_output_get_fail_free;
2677 tret = realloc(ret, ((nret + noutputs) * sizeof(Ecore_X_Randr_Output)));
2678 if (!tret) goto _ecore_x_randr_current_output_get_fail_free;
2680 memcpy(&ret[nret], outputs, (noutputs * sizeof(Ecore_X_Randr_Output)));
2692 _ecore_x_randr_current_output_get_fail_free:
2696 _ecore_x_randr_current_output_get_fail:
2703 * @brief get the backlight level of the given output
2704 * @param root window which's screen should be queried
2705 * @param output from which the backlight level should be retrieved
2706 * @return the backlight level
2709 ecore_x_randr_output_backlight_level_get(Ecore_X_Window root,
2710 Ecore_X_Randr_Output output)
2712 #ifdef ECORE_XCB_RANDR
2713 Ecore_X_Atom _backlight;
2714 xcb_intern_atom_cookie_t acookie;
2715 xcb_intern_atom_reply_t *areply;
2716 xcb_randr_get_output_property_cookie_t cookie;
2717 xcb_randr_get_output_property_reply_t *reply;
2718 xcb_randr_query_output_property_cookie_t qcookie;
2719 xcb_randr_query_output_property_reply_t *qreply;
2721 long value, max, min;
2724 LOGFN(__FILE__, __LINE__, __FUNCTION__);
2727 #ifdef ECORE_XCB_RANDR
2728 RANDR_CHECK_1_2_RET(-1);
2731 xcb_intern_atom_unchecked(_ecore_xcb_conn, 1,
2732 strlen("Backlight"), "Backlight");
2733 areply = xcb_intern_atom_reply(_ecore_xcb_conn, acookie, NULL);
2737 ERR("Backlight property is not suppported on this server or driver");
2742 _backlight = areply->atom;
2746 if (!_ecore_xcb_randr_output_validate(root, output))
2748 ERR("Invalid output");
2753 xcb_randr_get_output_property_unchecked(_ecore_xcb_conn,
2755 XCB_ATOM_NONE, 0, 4, 0, 0);
2757 xcb_randr_get_output_property_reply(_ecore_xcb_conn, cookie, NULL);
2760 WRN("Backlight not supported on this output");
2764 if ((reply->format != 32) || (reply->num_items != 1) ||
2765 (reply->type != XCB_ATOM_INTEGER))
2771 value = *((long *)xcb_randr_get_output_property_data(reply));
2774 /* I have the current value of the backlight */
2775 /* Now retrieve the min and max intensities of the output */
2777 xcb_randr_query_output_property_unchecked(_ecore_xcb_conn,
2778 output, _backlight);
2780 xcb_randr_query_output_property_reply(_ecore_xcb_conn, qcookie, NULL);
2784 if ((qreply->range) &&
2785 (xcb_randr_query_output_property_valid_values_length(qreply) == 2))
2789 vals = xcb_randr_query_output_property_valid_values(qreply);
2790 /* finally convert the current value in the interval [0..1] */
2793 dvalue = ((double)(value - min)) / ((double)(max - min));
2803 * @brief Set the backlight level of a given output.
2805 * @param root Window which's screen should be queried.
2806 * @param output That should be set.
2807 * @param level For which the backlight should be set.
2808 * @return @c EINA_TRUE in case of success.
2811 ecore_x_randr_output_backlight_level_set(Ecore_X_Window root,
2812 Ecore_X_Randr_Output output,
2815 #ifdef ECORE_XCB_RANDR
2816 Ecore_X_Atom _backlight;
2817 xcb_intern_atom_cookie_t acookie;
2818 xcb_intern_atom_reply_t *areply;
2819 xcb_randr_query_output_property_cookie_t qcookie;
2820 xcb_randr_query_output_property_reply_t *qreply;
2823 LOGFN(__FILE__, __LINE__, __FUNCTION__);
2826 #ifdef ECORE_XCB_RANDR
2827 RANDR_CHECK_1_2_RET(EINA_FALSE);
2829 if ((level < 0) || (level > 1))
2831 ERR("Backlight level should be between 0 and 1");
2835 if (!_ecore_xcb_randr_output_validate(root, output))
2837 ERR("Wrong output value");
2842 xcb_intern_atom_unchecked(_ecore_xcb_conn, 1,
2843 strlen("Backlight"), "Backlight");
2844 areply = xcb_intern_atom_reply(_ecore_xcb_conn, acookie, NULL);
2847 WRN("Backlight property is not suppported on this server or driver");
2852 _backlight = areply->atom;
2857 xcb_randr_query_output_property_unchecked(_ecore_xcb_conn,
2858 output, _backlight);
2860 xcb_randr_query_output_property_reply(_ecore_xcb_conn, qcookie, NULL);
2863 if ((qreply->range) && (qreply->length == 2))
2866 double min, max, tmp;
2869 vals = xcb_randr_query_output_property_valid_values(qreply);
2872 tmp = (level * (max - min)) + min;
2874 if (n > max) n = max;
2875 if (n < min) n = min;
2876 xcb_randr_change_output_property(_ecore_xcb_conn, output,
2877 _backlight, XCB_ATOM_INTEGER,
2878 32, XCB_PROP_MODE_REPLACE,
2879 1, (unsigned char *)&n);
2880 ecore_x_flush(); // needed
2891 * @brief Check if a backlight is available.
2893 * @return Whether a backlight is available.
2896 ecore_x_randr_output_backlight_available(void)
2898 #ifdef ECORE_XCB_RANDR
2899 Ecore_X_Atom _backlight;
2900 xcb_intern_atom_cookie_t acookie;
2901 xcb_intern_atom_reply_t *areply;
2904 LOGFN(__FILE__, __LINE__, __FUNCTION__);
2907 #ifdef ECORE_XCB_RANDR
2908 RANDR_CHECK_1_2_RET(EINA_FALSE);
2911 xcb_intern_atom_unchecked(_ecore_xcb_conn, 1,
2912 strlen("Backlight"), "Backlight");
2913 areply = xcb_intern_atom_reply(_ecore_xcb_conn, acookie, NULL);
2917 ERR("Backlight property is not suppported on this server or driver");
2922 _backlight = areply->atom;
2931 ecore_x_randr_edid_version_get(unsigned char *edid, unsigned long edid_length)
2933 if ((edid_length > _ECORE_X_RANDR_EDID_OFFSET_VERSION_MINOR) &&
2934 (ecore_x_randr_edid_has_valid_header(edid, edid_length)))
2935 return (edid[_ECORE_X_RANDR_EDID_OFFSET_VERSION_MAJOR] << 8) |
2936 edid[_ECORE_X_RANDR_EDID_OFFSET_VERSION_MINOR];
2937 return ECORE_X_RANDR_EDID_UNKNOWN_VALUE;
2941 ecore_x_randr_edid_display_name_get(unsigned char *edid, unsigned long edid_length)
2943 unsigned char *block = NULL;
2946 version = ecore_x_randr_edid_version_get(edid, edid_length);
2947 if (version < ECORE_X_RANDR_EDID_VERSION_13) return NULL;
2949 _ECORE_X_RANDR_EDID_FOR_EACH_NON_PIXEL_DESCRIPTOR_BLOCK(edid, block)
2951 if (block[_ECORE_X_RANDR_EDID_OFFSET_DESCRIPTOR_BLOCK_TYPE] == 0xfc)
2954 const char *edid_name;
2956 edid_name = (const char *)block +
2957 _ECORE_X_RANDR_EDID_OFFSET_DESCRIPTOR_BLOCK_CONTENT;
2959 malloc(_ECORE_X_RANDR_EDID_DISPLAY_DESCRIPTOR_BLOCK_CONTENT_LENGTH_MAX + 1);
2960 if (!name) return NULL;
2962 strncpy(name, edid_name,
2963 _ECORE_X_RANDR_EDID_DISPLAY_DESCRIPTOR_BLOCK_CONTENT_LENGTH_MAX);
2964 name[_ECORE_X_RANDR_EDID_DISPLAY_DESCRIPTOR_BLOCK_CONTENT_LENGTH_MAX] = 0;
2965 for (p = name; *p; p++)
2966 if ((*p < ' ') || (*p > '~')) *p = 0;
2975 ecore_x_randr_edid_has_valid_header(unsigned char *edid, unsigned long edid_length)
2977 const unsigned char header[] =
2979 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00
2982 if ((!edid) || (edid_length < 8)) return EINA_FALSE;
2983 if (!memcmp(edid, header, 8)) return EINA_TRUE;
2987 /* local functions */
2989 _ecore_xcb_randr_output_validate(Ecore_X_Window root,
2990 Ecore_X_Randr_Output output)
2992 Eina_Bool ret = EINA_FALSE;
2994 LOGFN(__FILE__, __LINE__, __FUNCTION__);
2997 #ifdef ECORE_XCB_RANDR
2998 RANDR_CHECK_1_2_RET(EINA_FALSE);
3000 if ((output) && (_ecore_xcb_randr_root_validate(root)))
3002 if (_randr_version >= RANDR_1_3)
3004 xcb_randr_get_screen_resources_current_reply_t *reply;
3006 reply = _ecore_xcb_randr_13_get_resources(root);
3010 xcb_randr_output_t *outputs;
3013 xcb_randr_get_screen_resources_current_outputs_length(reply);
3015 xcb_randr_get_screen_resources_current_outputs(reply);
3016 for (i = 0; i < len; i++)
3018 if (outputs[i] == output)
3027 else if (_randr_version == RANDR_1_2)
3029 xcb_randr_get_screen_resources_reply_t *reply;
3031 reply = _ecore_xcb_randr_12_get_resources(root);
3035 xcb_randr_output_t *outputs;
3037 len = xcb_randr_get_screen_resources_outputs_length(reply);
3038 outputs = xcb_randr_get_screen_resources_outputs(reply);
3039 for (i = 0; i < len; i++)
3041 if (outputs[i] == output)
3056 * @brief Validates a CRTC for a given root window's screen.
3058 * @param root The window which's default display will be queried.
3059 * @param crtc The CRTC to be validated.
3060 * @return In case it is found @c EINA_TRUE will be returned, else
3061 * @c EINA_FALSE is returned.
3064 _ecore_xcb_randr_crtc_validate(Ecore_X_Window root,
3065 Ecore_X_Randr_Crtc crtc)
3067 Eina_Bool ret = EINA_FALSE;
3069 LOGFN(__FILE__, __LINE__, __FUNCTION__);
3072 #ifdef ECORE_XCB_RANDR
3073 RANDR_CHECK_1_2_RET(EINA_FALSE);
3075 if (((int)crtc == Ecore_X_Randr_None) || ((int)crtc == Ecore_X_Randr_Unset))
3078 if ((crtc) && (_ecore_xcb_randr_root_validate(root)))
3080 if (_randr_version >= RANDR_1_3)
3082 xcb_randr_get_screen_resources_current_reply_t *reply;
3084 reply = _ecore_xcb_randr_13_get_resources(root);
3088 xcb_randr_crtc_t *crtcs;
3090 crtcs = xcb_randr_get_screen_resources_current_crtcs(reply);
3091 for (i = 0; i < reply->num_crtcs; i++)
3093 if (crtcs[i] == crtc)
3102 else if (_randr_version == RANDR_1_2)
3104 xcb_randr_get_screen_resources_reply_t *reply;
3106 reply = _ecore_xcb_randr_12_get_resources(root);
3110 xcb_randr_crtc_t *crtcs;
3112 crtcs = xcb_randr_get_screen_resources_crtcs(reply);
3113 for (i = 0; i < reply->num_crtcs; i++)
3115 if (crtcs[i] == crtc)
3130 static Ecore_X_Randr_Mode *
3131 _ecore_xcb_randr_12_output_modes_get(Ecore_X_Window root,
3132 Ecore_X_Randr_Output output,
3136 Ecore_X_Randr_Mode *modes = NULL;
3137 #ifdef ECORE_XCB_RANDR
3138 xcb_randr_get_screen_resources_reply_t *reply;
3140 reply = _ecore_xcb_randr_12_get_resources(root);
3143 xcb_randr_get_output_info_cookie_t ocookie;
3144 xcb_randr_get_output_info_reply_t *oreply;
3147 xcb_randr_get_output_info_unchecked(_ecore_xcb_conn, output,
3148 reply->config_timestamp);
3149 oreply = xcb_randr_get_output_info_reply(_ecore_xcb_conn,
3153 if (num) *num = oreply->num_modes;
3154 if (npreferred) *npreferred = oreply->num_preferred;
3156 modes = malloc(sizeof(Ecore_X_Randr_Mode) *
3160 xcb_randr_mode_t *rmodes;
3163 len = xcb_randr_get_output_info_modes_length(oreply);
3164 rmodes = xcb_randr_get_output_info_modes(oreply);
3165 memcpy(modes, rmodes, sizeof(Ecore_X_Randr_Mode) * len);
3175 static Ecore_X_Randr_Mode *
3176 _ecore_xcb_randr_13_output_modes_get(Ecore_X_Window root,
3177 Ecore_X_Randr_Output output,
3181 Ecore_X_Randr_Mode *modes = NULL;
3182 #ifdef ECORE_XCB_RANDR
3183 xcb_timestamp_t stamp = 0;
3184 xcb_randr_get_output_info_cookie_t ocookie;
3185 xcb_randr_get_output_info_reply_t *oreply;
3187 stamp = _ecore_xcb_randr_13_get_resource_timestamp(root);
3190 xcb_randr_get_output_info_unchecked(_ecore_xcb_conn, output, stamp);
3191 oreply = xcb_randr_get_output_info_reply(_ecore_xcb_conn, ocookie, NULL);
3194 if (num) *num = oreply->num_modes;
3195 if (npreferred) *npreferred = oreply->num_preferred;
3197 modes = malloc(sizeof(Ecore_X_Randr_Mode) * oreply->num_modes);
3200 xcb_randr_mode_t *rmodes;
3203 len = xcb_randr_get_output_info_modes_length(oreply);
3204 rmodes = xcb_randr_get_output_info_modes(oreply);
3205 memcpy(modes, rmodes, sizeof(Ecore_X_Randr_Mode) * len);
3213 static Ecore_X_Randr_Mode_Info *
3214 _ecore_xcb_randr_12_mode_info_get(Ecore_X_Window root,
3215 Ecore_X_Randr_Mode mode)
3217 Ecore_X_Randr_Mode_Info *ret = NULL;
3218 #ifdef ECORE_XCB_RANDR
3219 xcb_randr_get_screen_resources_reply_t *reply;
3221 reply = _ecore_xcb_randr_12_get_resources(root);
3224 if ((ret = malloc(sizeof(Ecore_X_Randr_Mode_Info))))
3227 xcb_randr_mode_info_iterator_t miter;
3229 nbuf = xcb_randr_get_screen_resources_names(reply);
3230 miter = xcb_randr_get_screen_resources_modes_iterator(reply);
3233 xcb_randr_mode_info_t *minfo;
3236 nbuf += minfo->name_len;
3238 if (minfo->id == mode)
3240 ret->xid = minfo->id;
3241 ret->width = minfo->width;
3242 ret->height = minfo->height;
3243 ret->dotClock = minfo->dot_clock;
3244 ret->hSyncStart = minfo->hsync_start;
3245 ret->hSyncEnd = minfo->hsync_end;
3246 ret->hTotal = minfo->htotal;
3247 ret->vSyncStart = minfo->vsync_start;
3248 ret->vSyncEnd = minfo->vsync_end;
3249 ret->vTotal = minfo->vtotal;
3250 ret->modeFlags = minfo->mode_flags;
3253 ret->nameLength = minfo->name_len;
3254 if (ret->nameLength > 0)
3256 ret->name = malloc(ret->nameLength + 1);
3258 memcpy(ret->name, nbuf, ret->nameLength + 1);
3263 xcb_randr_mode_info_next(&miter);
3273 static Ecore_X_Randr_Mode_Info *
3274 _ecore_xcb_randr_13_mode_info_get(Ecore_X_Window root,
3275 Ecore_X_Randr_Mode mode)
3277 Ecore_X_Randr_Mode_Info *ret = NULL;
3278 #ifdef ECORE_XCB_RANDR
3279 xcb_randr_get_screen_resources_current_reply_t *reply;
3281 reply = _ecore_xcb_randr_13_get_resources(root);
3284 if ((ret = malloc(sizeof(Ecore_X_Randr_Mode_Info))))
3287 xcb_randr_mode_info_iterator_t miter;
3289 nbuf = xcb_randr_get_screen_resources_current_names(reply);
3291 xcb_randr_get_screen_resources_current_modes_iterator(reply);
3294 xcb_randr_mode_info_t *minfo;
3297 nbuf += minfo->name_len;
3299 if (minfo->id == mode)
3301 ret->xid = minfo->id;
3302 ret->width = minfo->width;
3303 ret->height = minfo->height;
3304 ret->dotClock = minfo->dot_clock;
3305 ret->hSyncStart = minfo->hsync_start;
3306 ret->hSyncEnd = minfo->hsync_end;
3307 ret->hTotal = minfo->htotal;
3308 ret->vSyncStart = minfo->vsync_start;
3309 ret->vSyncEnd = minfo->vsync_end;
3310 ret->vTotal = minfo->vtotal;
3311 ret->modeFlags = minfo->mode_flags;
3314 ret->nameLength = minfo->name_len;
3315 if (ret->nameLength > 0)
3317 ret->name = malloc(ret->nameLength + 1);
3319 memcpy(ret->name, nbuf, ret->nameLength + 1);
3324 xcb_randr_mode_info_next(&miter);
3334 static Ecore_X_Randr_Mode_Info **
3335 _ecore_xcb_randr_12_modes_info_get(Ecore_X_Window root,
3338 Ecore_X_Randr_Mode_Info **ret = NULL;
3339 #ifdef ECORE_XCB_RANDR
3340 xcb_randr_get_screen_resources_reply_t *reply;
3342 reply = _ecore_xcb_randr_12_get_resources(root);
3345 if (num) *num = reply->num_modes;
3346 ret = malloc(sizeof(Ecore_X_Randr_Mode_Info *) * reply->num_modes);
3349 xcb_randr_mode_info_iterator_t miter;
3353 nbuf = xcb_randr_get_screen_resources_names(reply);
3354 miter = xcb_randr_get_screen_resources_modes_iterator(reply);
3357 xcb_randr_mode_info_t *minfo;
3360 nbuf += minfo->name_len;
3361 if ((ret[i] = malloc(sizeof(Ecore_X_Randr_Mode_Info))))
3363 ret[i]->xid = minfo->id;
3364 ret[i]->width = minfo->width;
3365 ret[i]->height = minfo->height;
3366 ret[i]->dotClock = minfo->dot_clock;
3367 ret[i]->hSyncStart = minfo->hsync_start;
3368 ret[i]->hSyncEnd = minfo->hsync_end;
3369 ret[i]->hTotal = minfo->htotal;
3370 ret[i]->vSyncStart = minfo->vsync_start;
3371 ret[i]->vSyncEnd = minfo->vsync_end;
3372 ret[i]->vTotal = minfo->vtotal;
3373 ret[i]->modeFlags = minfo->mode_flags;
3375 ret[i]->name = NULL;
3376 ret[i]->nameLength = minfo->name_len;
3377 if (ret[i]->nameLength > 0)
3379 ret[i]->name = malloc(ret[i]->nameLength + 1);
3381 memcpy(ret[i]->name, nbuf,
3382 ret[i]->nameLength + 1);
3394 xcb_randr_mode_info_next(&miter);
3403 static Ecore_X_Randr_Mode_Info **
3404 _ecore_xcb_randr_13_modes_info_get(Ecore_X_Window root,
3407 Ecore_X_Randr_Mode_Info **ret = NULL;
3408 #ifdef ECORE_XCB_RANDR
3409 xcb_randr_get_screen_resources_current_reply_t *reply;
3411 reply = _ecore_xcb_randr_13_get_resources(root);
3414 if (num) *num = reply->num_modes;
3415 ret = malloc(sizeof(Ecore_X_Randr_Mode_Info *) * reply->num_modes);
3418 xcb_randr_mode_info_iterator_t miter;
3422 nbuf = xcb_randr_get_screen_resources_current_names(reply);
3424 xcb_randr_get_screen_resources_current_modes_iterator(reply);
3427 xcb_randr_mode_info_t *minfo;
3430 nbuf += minfo->name_len;
3431 if ((ret[i] = malloc(sizeof(Ecore_X_Randr_Mode_Info))))
3433 ret[i]->xid = minfo->id;
3434 ret[i]->width = minfo->width;
3435 ret[i]->height = minfo->height;
3436 ret[i]->dotClock = minfo->dot_clock;
3437 ret[i]->hSyncStart = minfo->hsync_start;
3438 ret[i]->hSyncEnd = minfo->hsync_end;
3439 ret[i]->hTotal = minfo->htotal;
3440 ret[i]->vSyncStart = minfo->vsync_start;
3441 ret[i]->vSyncEnd = minfo->vsync_end;
3442 ret[i]->vTotal = minfo->vtotal;
3443 ret[i]->modeFlags = minfo->mode_flags;
3445 ret[i]->name = NULL;
3446 ret[i]->nameLength = minfo->name_len;
3447 if (ret[i]->nameLength > 0)
3449 ret[i]->name = malloc(ret[i]->nameLength + 1);
3451 memcpy(ret[i]->name, nbuf,
3452 ret[i]->nameLength + 1);
3464 xcb_randr_mode_info_next(&miter);
3474 _ecore_xcb_randr_12_mode_size_get(Ecore_X_Window root,
3475 Ecore_X_Randr_Mode mode,
3482 #ifdef ECORE_XCB_RANDR
3483 xcb_randr_get_screen_resources_reply_t *reply;
3485 reply = _ecore_xcb_randr_12_get_resources(root);
3488 xcb_randr_mode_info_iterator_t miter;
3490 miter = xcb_randr_get_screen_resources_modes_iterator(reply);
3493 xcb_randr_mode_info_t *minfo;
3496 if (minfo->id == mode)
3498 if (w) *w = minfo->width;
3499 if (h) *h = minfo->height;
3502 xcb_randr_mode_info_next(&miter);
3510 _ecore_xcb_randr_13_mode_size_get(Ecore_X_Window root,
3511 Ecore_X_Randr_Mode mode,
3518 #ifdef ECORE_XCB_RANDR
3519 xcb_randr_get_screen_resources_current_reply_t *reply;
3521 reply = _ecore_xcb_randr_13_get_resources(root);
3524 xcb_randr_mode_info_iterator_t miter;
3526 miter = xcb_randr_get_screen_resources_current_modes_iterator(reply);
3529 xcb_randr_mode_info_t *minfo;
3532 if (minfo->id == mode)
3534 if (w) *w = minfo->width;
3535 if (h) *h = minfo->height;
3538 xcb_randr_mode_info_next(&miter);
3545 static Ecore_X_Randr_Output *
3546 _ecore_xcb_randr_12_output_clones_get(Ecore_X_Window root,
3547 Ecore_X_Randr_Output output,
3550 Ecore_X_Randr_Output *outputs = NULL;
3551 #ifdef ECORE_XCB_RANDR
3552 xcb_randr_get_screen_resources_reply_t *reply;
3554 reply = _ecore_xcb_randr_12_get_resources(root);
3557 xcb_randr_get_output_info_cookie_t ocookie;
3558 xcb_randr_get_output_info_reply_t *oreply;
3561 xcb_randr_get_output_info_unchecked(_ecore_xcb_conn, output,
3562 reply->config_timestamp);
3563 oreply = xcb_randr_get_output_info_reply(_ecore_xcb_conn,
3567 if (num) *num = oreply->num_clones;
3570 malloc(sizeof(Ecore_X_Randr_Output) * oreply->num_clones);
3573 memcpy(outputs, xcb_randr_get_output_info_clones(oreply),
3574 sizeof(Ecore_X_Randr_Output) * oreply->num_clones);
3584 static Ecore_X_Randr_Output *
3585 _ecore_xcb_randr_13_output_clones_get(Ecore_X_Window root,
3586 Ecore_X_Randr_Output output,
3589 Ecore_X_Randr_Output *outputs = NULL;
3590 #ifdef ECORE_XCB_RANDR
3591 xcb_randr_get_screen_resources_current_reply_t *reply;
3593 reply = _ecore_xcb_randr_13_get_resources(root);
3596 xcb_randr_get_output_info_cookie_t ocookie;
3597 xcb_randr_get_output_info_reply_t *oreply;
3600 xcb_randr_get_output_info_unchecked(_ecore_xcb_conn, output,
3601 reply->config_timestamp);
3602 oreply = xcb_randr_get_output_info_reply(_ecore_xcb_conn,
3606 if (num) *num = oreply->num_clones;
3609 malloc(sizeof(Ecore_X_Randr_Output) * oreply->num_clones);
3612 memcpy(outputs, xcb_randr_get_output_info_clones(oreply),
3613 sizeof(Ecore_X_Randr_Output) * oreply->num_clones);
3623 static Ecore_X_Randr_Crtc *
3624 _ecore_xcb_randr_12_output_possible_crtcs_get(Ecore_X_Window root,
3625 Ecore_X_Randr_Output output,
3628 Ecore_X_Randr_Crtc *crtcs = NULL;
3629 #ifdef ECORE_XCB_RANDR
3630 xcb_randr_get_screen_resources_reply_t *reply;
3632 reply = _ecore_xcb_randr_12_get_resources(root);
3635 xcb_randr_get_output_info_cookie_t ocookie;
3636 xcb_randr_get_output_info_reply_t *oreply;
3639 xcb_randr_get_output_info_unchecked(_ecore_xcb_conn, output,
3640 reply->config_timestamp);
3641 oreply = xcb_randr_get_output_info_reply(_ecore_xcb_conn,
3645 if (num) *num = oreply->num_crtcs;
3647 crtcs = malloc(sizeof(Ecore_X_Randr_Crtc) * oreply->num_crtcs);
3650 memcpy(crtcs, xcb_randr_get_output_info_crtcs(oreply),
3651 sizeof(Ecore_X_Randr_Crtc) * oreply->num_crtcs);
3661 static Ecore_X_Randr_Crtc *
3662 _ecore_xcb_randr_13_output_possible_crtcs_get(Ecore_X_Window root,
3663 Ecore_X_Randr_Output output,
3666 Ecore_X_Randr_Crtc *crtcs = NULL;
3667 #ifdef ECORE_XCB_RANDR
3668 xcb_randr_get_screen_resources_current_reply_t *reply;
3670 reply = _ecore_xcb_randr_13_get_resources(root);
3673 xcb_randr_get_output_info_cookie_t ocookie;
3674 xcb_randr_get_output_info_reply_t *oreply;
3677 xcb_randr_get_output_info_unchecked(_ecore_xcb_conn, output,
3678 reply->config_timestamp);
3679 oreply = xcb_randr_get_output_info_reply(_ecore_xcb_conn,
3683 if (num) *num = oreply->num_crtcs;
3685 crtcs = malloc(sizeof(Ecore_X_Randr_Crtc) * oreply->num_crtcs);
3688 memcpy(crtcs, xcb_randr_get_output_info_crtcs(oreply),
3689 sizeof(Ecore_X_Randr_Crtc) * oreply->num_crtcs);
3700 _ecore_xcb_randr_12_output_name_get(Ecore_X_Window root,
3701 Ecore_X_Randr_Output output,
3705 #ifdef ECORE_XCB_RANDR
3706 xcb_randr_get_screen_resources_reply_t *reply;
3708 reply = _ecore_xcb_randr_12_get_resources(root);
3711 xcb_randr_get_output_info_cookie_t ocookie;
3712 xcb_randr_get_output_info_reply_t *oreply;
3715 xcb_randr_get_output_info_unchecked(_ecore_xcb_conn, output,
3716 reply->config_timestamp);
3717 oreply = xcb_randr_get_output_info_reply(_ecore_xcb_conn,
3723 nbuf = xcb_randr_get_output_info_name(oreply);
3724 nbuf += oreply->name_len;
3726 if (len) *len = oreply->name_len;
3727 if (oreply->name_len > 0)
3729 ret = malloc(oreply->name_len + 1);
3731 memcpy(ret, nbuf, oreply->name_len + 1);
3743 _ecore_xcb_randr_13_output_name_get(Ecore_X_Window root,
3744 Ecore_X_Randr_Output output,
3748 #ifdef ECORE_XCB_RANDR
3749 xcb_randr_get_screen_resources_current_reply_t *reply;
3751 reply = _ecore_xcb_randr_13_get_resources(root);
3754 xcb_randr_get_output_info_cookie_t ocookie;
3755 xcb_randr_get_output_info_reply_t *oreply;
3758 xcb_randr_get_output_info_unchecked(_ecore_xcb_conn, output,
3759 reply->config_timestamp);
3760 oreply = xcb_randr_get_output_info_reply(_ecore_xcb_conn,
3766 nbuf = xcb_randr_get_output_info_name(oreply);
3767 nbuf += oreply->name_len;
3769 if (len) *len = oreply->name_len;
3770 if (oreply->name_len > 0)
3772 ret = malloc(oreply->name_len + 1);
3774 memcpy(ret, nbuf, oreply->name_len + 1);
3785 static Ecore_X_Randr_Connection_Status
3786 _ecore_xcb_randr_12_output_connection_status_get(Ecore_X_Window root,
3787 Ecore_X_Randr_Output output)
3789 Ecore_X_Randr_Connection_Status ret = ECORE_X_RANDR_CONNECTION_STATUS_UNKNOWN;
3790 #ifdef ECORE_XCB_RANDR
3791 xcb_randr_get_screen_resources_reply_t *reply;
3793 reply = _ecore_xcb_randr_12_get_resources(root);
3796 xcb_randr_get_output_info_cookie_t ocookie;
3797 xcb_randr_get_output_info_reply_t *oreply;
3800 xcb_randr_get_output_info_unchecked(_ecore_xcb_conn, output,
3801 reply->config_timestamp);
3802 oreply = xcb_randr_get_output_info_reply(_ecore_xcb_conn,
3806 ret = oreply->connection;
3815 static Ecore_X_Randr_Connection_Status
3816 _ecore_xcb_randr_13_output_connection_status_get(Ecore_X_Window root,
3817 Ecore_X_Randr_Output output)
3819 Ecore_X_Randr_Connection_Status ret = ECORE_X_RANDR_CONNECTION_STATUS_UNKNOWN;
3820 #ifdef ECORE_XCB_RANDR
3821 xcb_randr_get_screen_resources_current_reply_t *reply;
3823 reply = _ecore_xcb_randr_13_get_resources(root);
3826 xcb_randr_get_output_info_cookie_t ocookie;
3827 xcb_randr_get_output_info_reply_t *oreply;
3830 xcb_randr_get_output_info_unchecked(_ecore_xcb_conn, output,
3831 reply->config_timestamp);
3832 oreply = xcb_randr_get_output_info_reply(_ecore_xcb_conn,
3836 ret = oreply->connection;
3845 static Ecore_X_Randr_Output *
3846 _ecore_xcb_randr_12_outputs_get(Ecore_X_Window root,
3849 Ecore_X_Randr_Output *ret = NULL;
3850 #ifdef ECORE_XCB_RANDR
3851 xcb_randr_get_screen_resources_reply_t *reply;
3853 reply = _ecore_xcb_randr_12_get_resources(root);
3856 if (num) *num = reply->num_outputs;
3857 ret = malloc(sizeof(Ecore_X_Randr_Output) * reply->num_outputs);
3859 memcpy(ret, xcb_randr_get_screen_resources_outputs(reply),
3860 sizeof(Ecore_X_Randr_Output) * reply->num_outputs);
3867 static Ecore_X_Randr_Output *
3868 _ecore_xcb_randr_13_outputs_get(Ecore_X_Window root,
3871 Ecore_X_Randr_Output *ret = NULL;
3872 #ifdef ECORE_XCB_RANDR
3873 xcb_randr_get_screen_resources_current_reply_t *reply;
3875 reply = _ecore_xcb_randr_13_get_resources(root);
3878 if (num) *num = reply->num_outputs;
3879 ret = malloc(sizeof(Ecore_X_Randr_Output) * reply->num_outputs);
3881 memcpy(ret, xcb_randr_get_screen_resources_current_outputs(reply),
3882 sizeof(Ecore_X_Randr_Output) * reply->num_outputs);
3889 static Ecore_X_Randr_Crtc
3890 _ecore_xcb_randr_12_output_crtc_get(Ecore_X_Window root,
3891 Ecore_X_Randr_Output output)
3893 Ecore_X_Randr_Crtc ret = Ecore_X_Randr_None;
3894 #ifdef ECORE_XCB_RANDR
3895 xcb_randr_get_screen_resources_reply_t *reply;
3897 reply = _ecore_xcb_randr_12_get_resources(root);
3900 xcb_randr_get_output_info_cookie_t ocookie;
3901 xcb_randr_get_output_info_reply_t *oreply;
3904 xcb_randr_get_output_info_unchecked(_ecore_xcb_conn, output,
3905 reply->config_timestamp);
3906 oreply = xcb_randr_get_output_info_reply(_ecore_xcb_conn,
3919 static Ecore_X_Randr_Crtc
3920 _ecore_xcb_randr_13_output_crtc_get(Ecore_X_Window root,
3921 Ecore_X_Randr_Output output)
3923 Ecore_X_Randr_Crtc ret = Ecore_X_Randr_None;
3924 #ifdef ECORE_XCB_RANDR
3925 xcb_randr_get_screen_resources_current_reply_t *reply;
3927 reply = _ecore_xcb_randr_13_get_resources(root);
3930 xcb_randr_get_output_info_cookie_t ocookie;
3931 xcb_randr_get_output_info_reply_t *oreply;
3934 xcb_randr_get_output_info_unchecked(_ecore_xcb_conn, output,
3935 reply->config_timestamp);
3936 oreply = xcb_randr_get_output_info_reply(_ecore_xcb_conn,
3949 static xcb_randr_get_screen_resources_reply_t *
3950 _ecore_xcb_randr_12_get_resources(Ecore_X_Window win)
3952 xcb_randr_get_screen_resources_cookie_t cookie;
3953 xcb_randr_get_screen_resources_reply_t *reply;
3955 cookie = xcb_randr_get_screen_resources_unchecked(_ecore_xcb_conn, win);
3956 reply = xcb_randr_get_screen_resources_reply(_ecore_xcb_conn, cookie, NULL);
3960 static xcb_randr_get_screen_resources_current_reply_t *
3961 _ecore_xcb_randr_13_get_resources(Ecore_X_Window win)
3963 xcb_randr_get_screen_resources_current_cookie_t cookie;
3964 xcb_randr_get_screen_resources_current_reply_t *reply;
3967 xcb_randr_get_screen_resources_current_unchecked(_ecore_xcb_conn, win);
3969 xcb_randr_get_screen_resources_current_reply(_ecore_xcb_conn,
3974 static xcb_timestamp_t
3975 _ecore_xcb_randr_12_get_resource_timestamp(Ecore_X_Window win)
3977 xcb_timestamp_t stamp = 0;
3978 #ifdef ECORE_XCB_RANDR
3979 xcb_randr_get_screen_resources_reply_t *reply;
3981 reply = _ecore_xcb_randr_12_get_resources(win);
3982 stamp = reply->config_timestamp;
3988 static xcb_timestamp_t
3989 _ecore_xcb_randr_13_get_resource_timestamp(Ecore_X_Window win)
3991 xcb_timestamp_t stamp = 0;
3992 #ifdef ECORE_XCB_RANDR
3993 xcb_randr_get_screen_resources_current_reply_t *reply;
3995 reply = _ecore_xcb_randr_13_get_resources(win);
3996 stamp = reply->config_timestamp;