eolian: rename is_ref API to is_ptr to match syntax
[platform/upstream/efl.git] / src / lib / ecore_x / xlib / ecore_x_fixes.c
1 #ifdef HAVE_CONFIG_H
2 # include <config.h>
3 #endif /* ifdef HAVE_CONFIG_H */
4
5 #include <stdlib.h>
6
7 #include "ecore_x_private.h"
8 #include "Ecore_X.h"
9
10 static int _fixes_available;
11 #ifdef ECORE_XFIXES
12 static int _fixes_major, _fixes_minor;
13 #endif /* ifdef ECORE_XFIXES */
14
15 void
16 _ecore_x_fixes_init(void)
17 {
18 #ifdef ECORE_XFIXES
19    _fixes_major = 3;
20    _fixes_minor = 0;
21
22    LOGFN(__FILE__, __LINE__, __FUNCTION__);
23
24    EINA_SAFETY_ON_NULL_RETURN(_ecore_x_disp);
25
26    if (XFixesQueryVersion(_ecore_x_disp, &_fixes_major, &_fixes_minor))
27      {
28         _fixes_available = 1;
29
30         ECORE_X_EVENT_FIXES_SELECTION_NOTIFY = ecore_event_type_new();
31      }
32    else
33      _fixes_available = 0;
34
35 #else /* ifdef ECORE_XFIXES */
36    _fixes_available = 0;
37 #endif /* ifdef ECORE_XFIXES */
38 }
39
40 #ifdef ECORE_XFIXES
41 /* I don't know what to call this function. */
42 static XRectangle *
43 _ecore_x_rectangle_ecore_to_x(Ecore_X_Rectangle *rects,
44                               int num)
45 {
46    XRectangle *xrect;
47    int i;
48
49    if (num == 0)
50      return NULL;
51
52    xrect = malloc(sizeof(XRectangle) * num);
53    if (!xrect)
54      return NULL;
55
56    for (i = 0; i < num; i++)
57      {
58         xrect[i].x = rects[i].x;
59         xrect[i].y = rects[i].y;
60         xrect[i].width = rects[i].width;
61         xrect[i].height = rects[i].height;
62      }
63    return xrect;
64 }
65
66 static Ecore_X_Rectangle *
67 _ecore_x_rectangle_x_to_ecore(XRectangle *xrect,
68                               int num)
69 {
70    Ecore_X_Rectangle *rects;
71    int i;
72
73    if (num == 0)
74      return NULL;
75
76    rects = malloc(sizeof(Ecore_X_Rectangle) * num);
77    if (!rects)
78      return NULL;
79
80    for (i = 0; i < num; i++)
81      {
82         rects[i].x = xrect[i].x;
83         rects[i].y = xrect[i].y;
84         rects[i].width = xrect[i].width;
85         rects[i].height = xrect[i].height;
86      }
87    return rects;
88 }
89
90 #endif /* ifdef ECORE_XFIXES */
91
92 EAPI Eina_Bool
93 ecore_x_fixes_selection_notification_request(Ecore_X_Atom selection)
94 {
95    EINA_SAFETY_ON_NULL_RETURN_VAL(_ecore_x_disp, EINA_FALSE);
96
97 #ifdef ECORE_XFIXES
98    if (_fixes_available)
99      {
100         XFixesSelectSelectionInput (_ecore_x_disp,
101                                     DefaultRootWindow(_ecore_x_disp),
102                                     selection,
103                                     XFixesSetSelectionOwnerNotifyMask |
104                                     XFixesSelectionWindowDestroyNotifyMask |
105                                     XFixesSelectionClientCloseNotifyMask);
106         return EINA_TRUE;
107      }
108 #endif
109    return EINA_FALSE;
110 }
111
112 EAPI Ecore_X_Region
113 ecore_x_region_new(Ecore_X_Rectangle *rects,
114                    int num)
115 {
116    EINA_SAFETY_ON_NULL_RETURN_VAL(_ecore_x_disp, 0);
117
118 #ifdef ECORE_XFIXES
119    Ecore_X_Region region;
120    XRectangle *xrect;
121
122    LOGFN(__FILE__, __LINE__, __FUNCTION__);
123    xrect = _ecore_x_rectangle_ecore_to_x(rects, num);
124    region = XFixesCreateRegion(_ecore_x_disp, xrect, num);
125    free(xrect);
126    return region;
127 #else /* ifdef ECORE_XFIXES */
128    return 0;
129 #endif /* ifdef ECORE_XFIXES */
130 }
131
132 EAPI Ecore_X_Region
133 ecore_x_region_new_from_bitmap(Ecore_X_Pixmap bitmap)
134 {
135    EINA_SAFETY_ON_NULL_RETURN_VAL(_ecore_x_disp, 0);
136 #ifdef ECORE_XFIXES
137    Ecore_X_Region region;
138
139    LOGFN(__FILE__, __LINE__, __FUNCTION__);
140    region = XFixesCreateRegionFromBitmap(_ecore_x_disp, bitmap);
141    if (_ecore_xlib_sync) ecore_x_sync();
142    return region;
143 #else /* ifdef ECORE_XFIXES */
144    return 0;
145 #endif /* ifdef ECORE_XFIXES */
146 }
147
148 EAPI Ecore_X_Region
149 ecore_x_region_new_from_window(Ecore_X_Window win,
150                                Ecore_X_Region_Type type)
151 {
152    EINA_SAFETY_ON_NULL_RETURN_VAL(_ecore_x_disp, 0);
153 #ifdef ECORE_XFIXES
154    Ecore_X_Region region;
155
156    LOGFN(__FILE__, __LINE__, __FUNCTION__);
157    region = XFixesCreateRegionFromWindow(_ecore_x_disp, win, type);
158    if (_ecore_xlib_sync) ecore_x_sync();
159    return region;
160 #else /* ifdef ECORE_XFIXES */
161    return 0;
162 #endif /* ifdef ECORE_XFIXES */
163 }
164
165 EAPI Ecore_X_Region
166 ecore_x_region_new_from_gc(Ecore_X_GC gc)
167 {
168    EINA_SAFETY_ON_NULL_RETURN_VAL(_ecore_x_disp, 0);
169 #ifdef ECORE_XFIXES
170    Ecore_X_Region region;
171
172    LOGFN(__FILE__, __LINE__, __FUNCTION__);
173    region = XFixesCreateRegionFromGC(_ecore_x_disp, gc);
174    if (_ecore_xlib_sync) ecore_x_sync();
175    return region;
176 #else /* ifdef ECORE_XFIXES */
177    return 0;
178 #endif /* ifdef ECORE_XFIXES */
179 }
180
181 EAPI Ecore_X_Region
182 ecore_x_region_new_from_picture(Ecore_X_Picture picture)
183 {
184    EINA_SAFETY_ON_NULL_RETURN_VAL(_ecore_x_disp, 0);
185 #ifdef ECORE_XFIXES
186    Ecore_X_Region region;
187
188    LOGFN(__FILE__, __LINE__, __FUNCTION__);
189    region = XFixesCreateRegionFromPicture(_ecore_x_disp, picture);
190    if (_ecore_xlib_sync) ecore_x_sync();
191    return region;
192 #else /* ifdef ECORE_XFIXES */
193    return 0;
194 #endif /* ifdef ECORE_XFIXES */
195 }
196
197 EAPI void
198 ecore_x_region_free(Ecore_X_Region region)
199 {
200    EINA_SAFETY_ON_NULL_RETURN(_ecore_x_disp);
201 #ifdef ECORE_XFIXES
202    LOGFN(__FILE__, __LINE__, __FUNCTION__);
203    XFixesDestroyRegion(_ecore_x_disp, region);
204 #endif /* ifdef ECORE_XFIXES */
205 }
206
207 EAPI void
208 ecore_x_region_set(Ecore_X_Region region,
209                    Ecore_X_Rectangle *rects,
210                    int num)
211 {
212    EINA_SAFETY_ON_NULL_RETURN(_ecore_x_disp);
213 #ifdef ECORE_XFIXES
214    XRectangle *xrect = _ecore_x_rectangle_ecore_to_x(rects, num);
215    LOGFN(__FILE__, __LINE__, __FUNCTION__);
216    XFixesSetRegion(_ecore_x_disp, region, xrect, num);
217    if (_ecore_xlib_sync) ecore_x_sync();
218 #endif /* ifdef ECORE_XFIXES */
219 }
220
221 EAPI void
222 ecore_x_region_copy(Ecore_X_Region dest,
223                     Ecore_X_Region source)
224 {
225    EINA_SAFETY_ON_NULL_RETURN(_ecore_x_disp);
226 #ifdef ECORE_XFIXES
227    LOGFN(__FILE__, __LINE__, __FUNCTION__);
228    XFixesCopyRegion(_ecore_x_disp, dest, source);
229    if (_ecore_xlib_sync) ecore_x_sync();
230 #endif /* ifdef ECORE_XFIXES */
231 }
232
233 EAPI void
234 ecore_x_region_combine(Ecore_X_Region dest,
235                        Ecore_X_Region source1,
236                        Ecore_X_Region source2)
237 {
238    EINA_SAFETY_ON_NULL_RETURN(_ecore_x_disp);
239 #ifdef ECORE_XFIXES
240    LOGFN(__FILE__, __LINE__, __FUNCTION__);
241    XFixesUnionRegion(_ecore_x_disp, dest, source1, source2);
242    if (_ecore_xlib_sync) ecore_x_sync();
243 #endif /* ifdef ECORE_XFIXES */
244 }
245
246 EAPI void
247 ecore_x_region_intersect(Ecore_X_Region dest,
248                          Ecore_X_Region source1,
249                          Ecore_X_Region source2)
250 {
251    EINA_SAFETY_ON_NULL_RETURN(_ecore_x_disp);
252 #ifdef ECORE_XFIXES
253    LOGFN(__FILE__, __LINE__, __FUNCTION__);
254    XFixesIntersectRegion(_ecore_x_disp, dest, source1, source2);
255    if (_ecore_xlib_sync) ecore_x_sync();
256 #endif /* ifdef ECORE_XFIXES */
257 }
258
259 EAPI void
260 ecore_x_region_subtract(Ecore_X_Region dest,
261                         Ecore_X_Region source1,
262                         Ecore_X_Region source2)
263 {
264    EINA_SAFETY_ON_NULL_RETURN(_ecore_x_disp);
265 #ifdef ECORE_XFIXES
266    LOGFN(__FILE__, __LINE__, __FUNCTION__);
267    XFixesSubtractRegion(_ecore_x_disp, dest, source1, source2);
268    if (_ecore_xlib_sync) ecore_x_sync();
269 #endif /* ifdef ECORE_XFIXES */
270 }
271
272 EAPI void
273 ecore_x_region_invert(Ecore_X_Region dest,
274                       Ecore_X_Rectangle *bounds,
275                       Ecore_X_Region source)
276 {
277    EINA_SAFETY_ON_NULL_RETURN(_ecore_x_disp);
278 #ifdef ECORE_XFIXES
279    XRectangle *xbound;
280    int num = 1;
281
282    LOGFN(__FILE__, __LINE__, __FUNCTION__);
283    xbound = _ecore_x_rectangle_ecore_to_x(bounds, num);
284
285    XFixesInvertRegion(_ecore_x_disp, dest, xbound, source);
286    if (_ecore_xlib_sync) ecore_x_sync();
287    free(xbound);
288 #endif /* ifdef ECORE_XFIXES */
289 }
290
291 EAPI void
292 ecore_x_region_translate(Ecore_X_Region region,
293                          int dx,
294                          int dy)
295 {
296    EINA_SAFETY_ON_NULL_RETURN(_ecore_x_disp);
297 #ifdef ECORE_XFIXES
298    LOGFN(__FILE__, __LINE__, __FUNCTION__);
299    XFixesTranslateRegion(_ecore_x_disp, region, dx, dy);
300    if (_ecore_xlib_sync) ecore_x_sync();
301 #endif /* ifdef ECORE_XFIXES */
302 }
303
304 EAPI void
305 ecore_x_region_extents(Ecore_X_Region dest,
306                        Ecore_X_Region source)
307 {
308    EINA_SAFETY_ON_NULL_RETURN(_ecore_x_disp);
309 #ifdef ECORE_XFIXES
310    LOGFN(__FILE__, __LINE__, __FUNCTION__);
311    XFixesRegionExtents(_ecore_x_disp, dest, source);
312    if (_ecore_xlib_sync) ecore_x_sync();
313 #endif /* ifdef ECORE_XFIXES */
314 }
315
316 EAPI Ecore_X_Rectangle *
317 ecore_x_region_fetch(Ecore_X_Region region,
318                      int *num,
319                      Ecore_X_Rectangle *bounds)
320 {
321    EINA_SAFETY_ON_NULL_RETURN_VAL(_ecore_x_disp, NULL);
322 #ifdef ECORE_XFIXES
323    Ecore_X_Rectangle *rects;
324    XRectangle *xrect, xbound;
325
326    LOGFN(__FILE__, __LINE__, __FUNCTION__);
327    xrect = XFixesFetchRegionAndBounds(_ecore_x_disp, region, num, &xbound);
328    if (_ecore_xlib_sync) ecore_x_sync();
329    rects = _ecore_x_rectangle_x_to_ecore(xrect, *num);
330    (*bounds).x = xbound.x;
331    (*bounds).y = xbound.y;
332    (*bounds).width = xbound.width;
333    (*bounds).height = xbound.height;
334    XFree(xrect);
335    return rects;
336 #else /* ifdef ECORE_XFIXES */
337    return NULL;
338 #endif /* ifdef ECORE_XFIXES */
339 }
340
341 EAPI void
342 ecore_x_region_expand(Ecore_X_Region dest,
343                       Ecore_X_Region source,
344                       unsigned int left,
345                       unsigned int right,
346                       unsigned int top,
347                       unsigned int bottom)
348 {
349    EINA_SAFETY_ON_NULL_RETURN(_ecore_x_disp);
350 #ifdef ECORE_XFIXES
351    LOGFN(__FILE__, __LINE__, __FUNCTION__);
352    XFixesExpandRegion(_ecore_x_disp, dest, source, left, right, top, bottom);
353    if (_ecore_xlib_sync) ecore_x_sync();
354 #endif /* ifdef ECORE_XFIXES */
355 }
356
357 EAPI void
358 ecore_x_region_gc_clip_set(Ecore_X_Region region,
359                            Ecore_X_GC gc,
360                            int x_origin,
361                            int y_origin)
362 {
363    EINA_SAFETY_ON_NULL_RETURN(_ecore_x_disp);
364 #ifdef ECORE_XFIXES
365    LOGFN(__FILE__, __LINE__, __FUNCTION__);
366    XFixesSetGCClipRegion(_ecore_x_disp, gc, x_origin, y_origin, region);
367    if (_ecore_xlib_sync) ecore_x_sync();
368 #endif /* ifdef ECORE_XFIXES */
369 }
370
371 EAPI void
372 ecore_x_region_window_shape_set(Ecore_X_Region region,
373                                 Ecore_X_Window win,
374                                 Ecore_X_Shape_Type type,
375                                 int x_offset,
376                                 int y_offset)
377 {
378    EINA_SAFETY_ON_NULL_RETURN(_ecore_x_disp);
379 #ifdef ECORE_XFIXES
380    LOGFN(__FILE__, __LINE__, __FUNCTION__);
381    XFixesSetWindowShapeRegion(_ecore_x_disp,
382                               win,
383                               type,
384                               x_offset,
385                               y_offset,
386                               region);
387    if (_ecore_xlib_sync) ecore_x_sync();
388 #endif /* ifdef ECORE_XFIXES */
389 }
390
391 EAPI void
392 ecore_x_region_picture_clip_set(Ecore_X_Region region,
393                                 Ecore_X_Picture picture,
394                                 int x_origin,
395                                 int y_origin)
396 {
397    EINA_SAFETY_ON_NULL_RETURN(_ecore_x_disp);
398 #ifdef ECORE_XFIXES
399    LOGFN(__FILE__, __LINE__, __FUNCTION__);
400    XFixesSetPictureClipRegion(_ecore_x_disp,
401                               picture,
402                               x_origin,
403                               y_origin,
404                               region);
405    if (_ecore_xlib_sync) ecore_x_sync();
406 #endif /* ifdef ECORE_XFIXES */
407 }