1 #include "ecore_xcb_private.h"
2 # ifdef ECORE_XCB_XFIXES
3 # include <xcb/xfixes.h>
6 /* local function prototypes */
7 static xcb_rectangle_t *_ecore_xcb_rect_to_xcb(Ecore_X_Rectangle *rects,
9 static Ecore_X_Rectangle *_ecore_xcb_rect_to_ecore(xcb_rectangle_t *rects,
13 static Eina_Bool _xfixes_avail = EINA_FALSE;
15 /* external variables */
16 int _ecore_xcb_event_xfixes = -1;
19 _ecore_xcb_xfixes_init(void)
21 LOGFN(__FILE__, __LINE__, __FUNCTION__);
23 #ifdef ECORE_XCB_XFIXES
24 xcb_prefetch_extension_data(_ecore_xcb_conn, &xcb_xfixes_id);
29 _ecore_xcb_xfixes_finalize(void)
31 #ifdef ECORE_XCB_XFIXES
32 const xcb_query_extension_reply_t *ext_reply;
35 LOGFN(__FILE__, __LINE__, __FUNCTION__);
37 #ifdef ECORE_XCB_XFIXES
38 ext_reply = xcb_get_extension_data(_ecore_xcb_conn, &xcb_xfixes_id);
39 if ((ext_reply) && (ext_reply->present))
41 xcb_xfixes_query_version_cookie_t cookie;
42 xcb_xfixes_query_version_reply_t *reply;
45 xcb_xfixes_query_version_unchecked(_ecore_xcb_conn,
46 XCB_XFIXES_MAJOR_VERSION,
47 XCB_XFIXES_MINOR_VERSION);
48 reply = xcb_xfixes_query_version_reply(_ecore_xcb_conn, cookie, NULL);
51 /* NB: XFixes Extension >= 3 needed for shape stuff.
52 * for now, I am removing this check so that it matches the
53 * xlib code closer. If the extension version ends up being
54 * that important, then re-enable this */
56 /* if (reply->major_version >= 3) */
57 _xfixes_avail = EINA_TRUE;
62 _ecore_xcb_event_xfixes = ext_reply->first_event;
68 ecore_x_fixes_selection_notification_request(Ecore_X_Atom selection)
70 #ifdef ECORE_XCB_XFIXES
71 Ecore_X_Window root = 0;
72 xcb_void_cookie_t cookie;
73 xcb_generic_error_t *err;
79 if (!_xfixes_avail) return EINA_FALSE;
81 #ifdef ECORE_XCB_XFIXES
82 root = ((xcb_screen_t *)_ecore_xcb_screen)->root;
84 mask = (XCB_XFIXES_SELECTION_EVENT_MASK_SET_SELECTION_OWNER |
85 XCB_XFIXES_SELECTION_EVENT_MASK_SELECTION_WINDOW_DESTROY |
86 XCB_XFIXES_SELECTION_EVENT_MASK_SELECTION_CLIENT_CLOSE);
89 xcb_xfixes_select_selection_input_checked(_ecore_xcb_conn, root,
91 err = xcb_request_check(_ecore_xcb_conn, cookie);
104 _ecore_xcb_xfixes_avail_get(void)
106 return _xfixes_avail;
110 * @defgroup Ecore_X_Fixes_Group X Fixes Extension Functions
112 * Functions related to the X Fixes extension.
116 * Create a region from rectangles.
117 * @param rects The rectangles used to initialize the region.
118 * @param num The number of rectangles.
119 * @return The newly created region.
121 * Create a region initialized to the specified list of rectangles
122 * @p rects. The rectangles may be specified in any order, their union
123 * becomes the region.
124 * @ingroup Ecore_X_Fixes_Group
127 ecore_x_region_new(Ecore_X_Rectangle *rects,
130 Ecore_X_Region region = 0;
131 #ifdef ECORE_XCB_XFIXES
132 xcb_rectangle_t *xrects;
135 LOGFN(__FILE__, __LINE__, __FUNCTION__);
138 if (!_xfixes_avail) return 0;
140 #ifdef ECORE_XCB_XFIXES
141 xrects = _ecore_xcb_rect_to_xcb(rects, num);
142 region = xcb_generate_id(_ecore_xcb_conn);
143 xcb_xfixes_create_region(_ecore_xcb_conn, region, num, xrects);
152 * Create a region from a pixmap.
153 * @param bitmap The bitmap used to initialize the region.
154 * @return The newly created region.
156 * Creates a region initialized to the set of 'one' pixels in @p bitmap
157 * (which must be of depth 1, else Match error).
158 * @ingroup Ecore_X_Fixes_Group
161 ecore_x_region_new_from_bitmap(Ecore_X_Pixmap bitmap)
163 Ecore_X_Region region = 0;
165 LOGFN(__FILE__, __LINE__, __FUNCTION__);
168 if (!_xfixes_avail) return 0;
170 #ifdef ECORE_XCB_XFIXES
171 region = xcb_generate_id(_ecore_xcb_conn);
172 xcb_xfixes_create_region_from_bitmap(_ecore_xcb_conn, region, bitmap);
180 * Create a region from a window.
181 * @param win The window used to initialize the region.
182 * @param type The type of the region.
183 * @return The newly created region.
185 * Creates a region initialized to the specified @p window region. See
186 * the Shape extension for the definition of Bounding and Clip
188 * @ingroup Ecore_X_Fixes_Group
191 ecore_x_region_new_from_window(Ecore_X_Window win,
192 Ecore_X_Region_Type type)
194 Ecore_X_Region region = 0;
196 LOGFN(__FILE__, __LINE__, __FUNCTION__);
199 if (!_xfixes_avail) return 0;
201 #ifdef ECORE_XCB_XFIXES
202 region = xcb_generate_id(_ecore_xcb_conn);
203 xcb_xfixes_create_region_from_window(_ecore_xcb_conn, region, win, type);
211 * Create a region from a graphic context.
212 * @param gc The graphic context used to initialize the region.
213 * @return The newly created region.
215 * Creates a region initialized from the clip list of @p gc.
216 * @ingroup Ecore_X_Fixes_Group
219 ecore_x_region_new_from_gc(Ecore_X_GC gc)
221 Ecore_X_Region region = 0;
223 LOGFN(__FILE__, __LINE__, __FUNCTION__);
226 if (!_xfixes_avail) return 0;
228 #ifdef ECORE_XCB_XFIXES
229 region = xcb_generate_id(_ecore_xcb_conn);
230 xcb_xfixes_create_region_from_gc(_ecore_xcb_conn, region, gc);
238 * Create a region from a picture.
239 * @param picture The picture used to initialize the region.
240 * @return The newly created region.
242 * Creates a region initialized from the clip list of @p picture.
243 * @ingroup Ecore_X_Fixes_Group
246 ecore_x_region_new_from_picture(Ecore_X_Picture picture)
248 Ecore_X_Region region = 0;
250 LOGFN(__FILE__, __LINE__, __FUNCTION__);
253 if (!_xfixes_avail) return 0;
255 #ifdef ECORE_XCB_XFIXES
256 region = xcb_generate_id(_ecore_xcb_conn);
257 xcb_xfixes_create_region_from_picture(_ecore_xcb_conn, region, picture);
266 * @param region The region to destroy.
268 * Destroy the specified @p region.
269 * @ingroup Ecore_X_Fixes_Group
272 ecore_x_region_free(Ecore_X_Region region)
274 LOGFN(__FILE__, __LINE__, __FUNCTION__);
277 if (!_xfixes_avail) return;
279 #ifdef ECORE_XCB_XFIXES
280 xcb_xfixes_destroy_region(_ecore_xcb_conn, region);
286 * Set the content of a region.
287 * @param region The region to destroy.
288 * @param rects The rectangles used to set the region.
289 * @param num The number of rectangles.
291 * Replace the current contents of @p region with the region formed
292 * by the union of the rectangles @p rects.
293 * @ingroup Ecore_X_Fixes_Group
296 ecore_x_region_set(Ecore_X_Region region,
297 Ecore_X_Rectangle *rects,
300 #ifdef ECORE_XCB_XFIXES
301 xcb_rectangle_t *xrects;
304 LOGFN(__FILE__, __LINE__, __FUNCTION__);
307 if (!_xfixes_avail) return;
309 #ifdef ECORE_XCB_XFIXES
310 xrects = _ecore_xcb_rect_to_xcb(rects, num);
311 xcb_xfixes_set_region(_ecore_xcb_conn, region, num, xrects);
318 * Copy the content of a region.
319 * @param dest The destination region.
320 * @param source The source region.
322 * Replace the contents of @p dest with the contents of @p source.
323 * @ingroup Ecore_X_Fixes_Group
326 ecore_x_region_copy(Ecore_X_Region dest,
327 Ecore_X_Region source)
329 LOGFN(__FILE__, __LINE__, __FUNCTION__);
332 if (!_xfixes_avail) return;
334 // NB: Hmmmm...this may need converting to/fro xcb_rectangle_t
335 #ifdef ECORE_XCB_XFIXES
336 xcb_xfixes_copy_region(_ecore_xcb_conn, source, dest);
342 * Make the union of two regions.
343 * @param dest The destination region.
344 * @param source1 The first source region.
345 * @param source2 The second source region.
347 * Replace the contents of @p dest with the union of @p source1 and
349 * @ingroup Ecore_X_Fixes_Group
352 ecore_x_region_combine(Ecore_X_Region dest,
353 Ecore_X_Region source1,
354 Ecore_X_Region source2)
356 LOGFN(__FILE__, __LINE__, __FUNCTION__);
359 if (!_xfixes_avail) return;
361 #ifdef ECORE_XCB_XFIXES
362 xcb_xfixes_union_region(_ecore_xcb_conn, source1, source2, dest);
368 * Make the intersection of two regions.
369 * @param dest The destination region.
370 * @param source1 The first source region.
371 * @param source2 The second source region.
373 * Replace the contents of @p dest with the intersection of @p source1 and
375 * @ingroup Ecore_X_Fixes_Group
378 ecore_x_region_intersect(Ecore_X_Region dest,
379 Ecore_X_Region source1,
380 Ecore_X_Region source2)
382 LOGFN(__FILE__, __LINE__, __FUNCTION__);
385 if (!_xfixes_avail) return;
387 #ifdef ECORE_XCB_XFIXES
388 xcb_xfixes_intersect_region(_ecore_xcb_conn, source1, source2, dest);
394 * Make the subtraction of two regions.
395 * @param dest The destination region.
396 * @param source1 The first source region.
397 * @param source2 The second source region.
399 * Replace the contents of @p dest with the subtraction of @p source1 by
401 * @ingroup Ecore_X_Fixes_Group
404 ecore_x_region_subtract(Ecore_X_Region dest,
405 Ecore_X_Region source1,
406 Ecore_X_Region source2)
408 LOGFN(__FILE__, __LINE__, __FUNCTION__);
411 if (!_xfixes_avail) return;
413 #ifdef ECORE_XCB_XFIXES
414 xcb_xfixes_subtract_region(_ecore_xcb_conn, source1, source2, dest);
420 * Make the subtraction of regions by bounds.
421 * @param dest The destination region.
422 * @param bounds The bounds.
423 * @param source The source region.
425 * The @p source region is subtracted from the region specified by
426 * @p bounds. The result is placed in @p dest, replacing its
428 * @ingroup Ecore_X_Fixes_Group
431 ecore_x_region_invert(Ecore_X_Region dest,
432 Ecore_X_Rectangle *bounds,
433 Ecore_X_Region source)
435 #ifdef ECORE_XCB_XFIXES
436 xcb_rectangle_t xrects;
439 LOGFN(__FILE__, __LINE__, __FUNCTION__);
442 if (!_xfixes_avail) return;
444 #ifdef ECORE_XCB_XFIXES
445 xrects.x = bounds->x;
446 xrects.y = bounds->y;
447 xrects.width = bounds->width;
448 xrects.height = bounds->height;
450 xcb_xfixes_invert_region(_ecore_xcb_conn, source, xrects, dest);
456 * Translate a region.
457 * @param region The region to translate.
458 * @param dx The horizontal translation.
459 * @param dy The vertical translation.
461 * The @p region is translated by @p dx and @p dy in place.
462 * @ingroup Ecore_X_Fixes_Group
465 ecore_x_region_translate(Ecore_X_Region region,
469 LOGFN(__FILE__, __LINE__, __FUNCTION__);
472 if (!_xfixes_avail) return;
474 #ifdef ECORE_XCB_XFIXES
475 xcb_xfixes_translate_region(_ecore_xcb_conn, region, dx, dy);
482 * @param dest The destination region.
483 * @param source The source region.
485 * The extents of the @p source region are placed in @p dest.
486 * @ingroup Ecore_X_Fixes_Group
489 ecore_x_region_extents(Ecore_X_Region dest,
490 Ecore_X_Region source)
492 LOGFN(__FILE__, __LINE__, __FUNCTION__);
495 if (!_xfixes_avail) return;
497 #ifdef ECORE_XCB_XFIXES
498 xcb_xfixes_region_extents(_ecore_xcb_conn, source, dest);
504 * Return the rectangles that compose a region.
505 * @param region The region (Unused).
506 * @param num The number of returned rectangles.
507 * @param bounds The returned bounds of the region.
508 * @return The returned rectangles.
510 * @ingroup Ecore_X_Fixes_Group
512 EAPI Ecore_X_Rectangle *
513 ecore_x_region_fetch(Ecore_X_Region region,
515 Ecore_X_Rectangle *bounds)
517 Ecore_X_Rectangle extents = { 0, 0, 0, 0 };
518 Ecore_X_Rectangle *rects = NULL;
519 #ifdef ECORE_XCB_XFIXES
520 xcb_xfixes_fetch_region_cookie_t cookie;
521 xcb_xfixes_fetch_region_reply_t *reply;
526 LOGFN(__FILE__, __LINE__, __FUNCTION__);
530 if (bounds) *bounds = extents;
531 if (!_xfixes_avail) return NULL;
533 #ifdef ECORE_XCB_XFIXES
534 cookie = xcb_xfixes_fetch_region_unchecked(_ecore_xcb_conn, region);
535 reply = xcb_xfixes_fetch_region_reply(_ecore_xcb_conn, cookie, NULL);
536 if (!reply) return NULL;
538 r = xcb_xfixes_fetch_region_rectangles(reply);
539 n = xcb_xfixes_fetch_region_rectangles_length(reply);
540 rects = _ecore_xcb_rect_to_ecore(r, n);
543 /* rects = (Ecore_X_Rectangle *)malloc(n * sizeof(Ecore_X_Rectangle)); */
550 /* for (i = 0; i < n; i++) */
552 /* rects[i].x = r[i].x; */
553 /* rects[i].y = r[i].y; */
554 /* rects[i].width = r[i].width; */
555 /* rects[i].height = r[i].height; */
558 (*bounds).x = reply->extents.x;
559 (*bounds).y = reply->extents.y;
560 (*bounds).width = reply->extents.width;
561 (*bounds).height = reply->extents.height;
571 * @param dest The destination region.
572 * @param source The source region.
573 * @param left The number of pixels to add on the left.
574 * @param right The number of pixels to add on the right.
575 * @param top The number of pixels to add at the top.
576 * @param bottom The number of pixels to add at the bottom.
578 * Put in @p dest the area specified by expanding each rectangle in
579 * the @p source region by the specified number of pixels to the
580 * @p left, @p right, @p top and @p bottom.
581 * @ingroup Ecore_X_Fixes_Group
584 ecore_x_region_expand(Ecore_X_Region dest,
585 Ecore_X_Region source,
591 LOGFN(__FILE__, __LINE__, __FUNCTION__);
594 if (!_xfixes_avail) return;
596 #ifdef ECORE_XCB_XFIXES
597 xcb_xfixes_expand_region(_ecore_xcb_conn, source, dest, left, right, top, bottom);
603 * Change clip-mask in a graphic context to the specified region.
604 * @param region The region to change.
605 * @param gc The clip-mask graphic context.
606 * @param x The horizontal translation.
607 * @param y The vertical translation.
609 * Changes clip-mask in @p gc to the specified @p region and
610 * sets the clip origin with the values of @p x_origin and @p y_origin.
611 * Output will be clippped to remain contained within the region. The
612 * clip origin is interpreted relative to the origin of whatever
613 * destination drawable is specified in a graphics request. The
614 * region is interpreted relative to the clip origin. Future changes
615 * to region have no effect on the gc clip-mask.
616 * @ingroup Ecore_X_Fixes_Group
619 ecore_x_region_gc_clip_set(Ecore_X_Region region,
624 LOGFN(__FILE__, __LINE__, __FUNCTION__);
627 if (!_xfixes_avail) return;
629 #ifdef ECORE_XCB_XFIXES
630 xcb_xfixes_set_gc_clip_region(_ecore_xcb_conn, gc, region, x, y);
636 * Change the shape extension of a window.
637 * @param region The region.
638 * @param dest The window whose shape is changed.
639 * @param type The kind of shape.
640 * @param x The horizontal offset.
641 * @param y The vertical offset.
643 * Set the specified Shape extension region of @p window to @p region,
644 * offset by @p x_offset and @p y_offset. Future changes to region
645 * have no effect on the window shape.
646 * @ingroup Ecore_X_Fixes_Group
649 ecore_x_region_window_shape_set(Ecore_X_Region region,
651 Ecore_X_Shape_Type type,
655 LOGFN(__FILE__, __LINE__, __FUNCTION__);
658 if (!_xfixes_avail) return;
660 #ifdef ECORE_XCB_XFIXES
661 xcb_xfixes_set_window_shape_region(_ecore_xcb_conn, dest, type, x, y, region);
667 * Change clip-mask in picture to the specified region.
668 * @param region The region.
669 * @param picture The picture.
670 * @param x The X coordinate of the origin.
671 * @param y The Y coordinate of the origin.
673 * Changes clip-mask in picture to the specified @p region
674 * and sets the clip origin. Input and output will be clipped to
675 * remain contained within the region. The clip origin is interpreted
676 * relative to the origin of the drawable associated with @p picture. The
677 * region is interpreted relative to the clip origin. Future changes
678 * to region have no effect on the picture clip-mask.
679 * @ingroup Ecore_X_Fixes_Group
682 ecore_x_region_picture_clip_set(Ecore_X_Region region,
683 Ecore_X_Picture picture,
687 LOGFN(__FILE__, __LINE__, __FUNCTION__);
690 if (!_xfixes_avail) return;
692 #ifdef ECORE_XCB_XFIXES
693 xcb_xfixes_set_picture_clip_region(_ecore_xcb_conn, picture, region, x, y);
698 /* local function prototypes */
699 static xcb_rectangle_t *
700 _ecore_xcb_rect_to_xcb(Ecore_X_Rectangle *rects,
703 xcb_rectangle_t *xrect;
706 if (!num) return NULL;
708 xrect = malloc(sizeof(xcb_rectangle_t) * num);
709 if (!xrect) return NULL;
711 for (i = 0; i < num; i++)
713 xrect[i].x = rects[i].x;
714 xrect[i].y = rects[i].y;
715 xrect[i].width = rects[i].width;
716 xrect[i].height = rects[i].height;
722 static Ecore_X_Rectangle *
723 _ecore_xcb_rect_to_ecore(xcb_rectangle_t *rects,
726 Ecore_X_Rectangle *erect;
729 if (!num) return NULL;
731 erect = malloc(sizeof(Ecore_X_Rectangle) * num);
732 if (!erect) return NULL;
734 for (i = 0; i < num; i++)
736 erect[i].x = rects[i].x;
737 erect[i].y = rects[i].y;
738 erect[i].width = rects[i].width;
739 erect[i].height = rects[i].height;