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