d4645a7400dd376ad759877ee614b9528c02ce6e
[framework/uifw/ecore.git] / src / lib / ecore_x / xlib / ecore_x_fixes.c
1 /*
2  * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
3  */
4
5 #include "ecore_x_private.h"
6 #include "Ecore_X.h"
7
8 static int _fixes_available;
9 #ifdef ECORE_XFIXES
10 static int _fixes_major, _fixes_minor;
11 #endif
12
13 void
14 _ecore_x_fixes_init(void)
15 {
16 #ifdef ECORE_XFIXES
17    _fixes_major = 3;
18    _fixes_minor = 0;
19
20    if (XFixesQueryVersion(_ecore_x_disp, &_fixes_major, &_fixes_minor))
21      _fixes_available = 1;
22    else
23      _fixes_available = 0;
24 #else
25    _fixes_available = 0;
26 #endif
27 }
28
29 #ifdef ECORE_XFIXES
30 /* I don't know what to call this function. */
31 static XRectangle *
32 _ecore_x_rectangle_ecore_to_x(Ecore_X_Rectangle *rects, int num)
33 {
34    XRectangle *xrect;
35    int i;
36
37    if (num == 0) return NULL;
38
39    xrect = malloc(sizeof(XRectangle) * num);
40    if (!xrect) return NULL;
41    for (i = 0; i < num; i++)
42      {
43         xrect[i].x = rects[i].x;
44         xrect[i].y = rects[i].y;
45         xrect[i].width = rects[i].width;
46         xrect[i].height = rects[i].height;
47      }
48    return xrect;
49 }
50
51 static Ecore_X_Rectangle *
52 _ecore_x_rectangle_x_to_ecore(XRectangle *xrect, int num)
53 {
54    Ecore_X_Rectangle *rects;
55    int i;
56
57    if (num == 0) return NULL;
58    rects = malloc(sizeof(Ecore_X_Rectangle) * num);
59    if (!rects) return NULL;
60    for (i = 0; i < num; i++)
61      {
62         rects[i].x = xrect[i].x;
63         rects[i].y = xrect[i].y;
64         rects[i].width = xrect[i].width;
65         rects[i].height = xrect[i].height;
66      }
67    return rects;
68 }
69 #endif
70
71 EAPI Ecore_X_Region
72 ecore_x_region_new(Ecore_X_Rectangle *rects, int num)
73 {
74 #ifdef ECORE_XFIXES
75    Ecore_X_Region region;
76    XRectangle *xrect;
77
78    xrect = _ecore_x_rectangle_ecore_to_x(rects, num);
79    region = XFixesCreateRegion(_ecore_x_disp, xrect, num);
80    free(xrect);
81    return region;
82 #else
83    return 0;
84 #endif
85 }
86
87 EAPI Ecore_X_Region
88 ecore_x_region_new_from_bitmap(Ecore_X_Pixmap bitmap)
89 {
90 #ifdef ECORE_XFIXES
91    Ecore_X_Region region;
92
93    region = XFixesCreateRegionFromBitmap(_ecore_x_disp, bitmap);
94    return region;
95 #else
96    return 0;
97 #endif
98 }
99
100 EAPI Ecore_X_Region
101 ecore_x_region_new_from_window(Ecore_X_Window win, Ecore_X_Region_Type type)
102 {
103 #ifdef ECORE_XFIXES
104    Ecore_X_Region region;
105
106    region = XFixesCreateRegionFromWindow(_ecore_x_disp, win, type);
107    return region;
108 #else
109    return 0;
110 #endif
111 }
112
113 EAPI Ecore_X_Region
114 ecore_x_region_new_from_gc(Ecore_X_GC gc)
115 {
116 #ifdef ECORE_XFIXES
117    Ecore_X_Region region;
118
119    region = XFixesCreateRegionFromGC(_ecore_x_disp, gc);
120    return region;
121 #else
122    return 0;
123 #endif
124 }
125
126 EAPI Ecore_X_Region
127 ecore_x_region_new_from_picture(Ecore_X_Picture picture)
128 {
129 #ifdef ECORE_XFIXES
130    Ecore_X_Region region;
131
132    region = XFixesCreateRegionFromPicture(_ecore_x_disp, picture);
133    return region;
134 #else
135    return 0;
136 #endif
137 }
138
139 EAPI void
140 ecore_x_region_del(Ecore_X_Region region)
141 {
142 #ifdef ECORE_XFIXES
143    XFixesDestroyRegion(_ecore_x_disp, region);
144 #endif
145 }
146
147 EAPI void
148 ecore_x_region_set(Ecore_X_Region region, Ecore_X_Rectangle *rects, int num)
149 {
150 #ifdef ECORE_XFIXES
151    XRectangle *xrect = _ecore_x_rectangle_ecore_to_x(rects, num);
152    XFixesSetRegion(_ecore_x_disp, region, xrect, num);
153 #endif
154 }
155
156 EAPI void
157 ecore_x_region_copy(Ecore_X_Region dest, Ecore_X_Region source)
158 {
159 #ifdef ECORE_XFIXES
160    XFixesCopyRegion(_ecore_x_disp, dest, source);
161 #endif
162 }
163
164 EAPI void
165 ecore_x_region_combine(Ecore_X_Region dest, Ecore_X_Region source1, Ecore_X_Region source2)
166 {
167 #ifdef ECORE_XFIXES
168    XFixesUnionRegion(_ecore_x_disp, dest, source1, source2);
169 #endif
170 }
171
172 EAPI void
173 ecore_x_region_intersect(Ecore_X_Region dest, Ecore_X_Region source1, Ecore_X_Region source2)
174 {
175 #ifdef ECORE_XFIXES
176    XFixesIntersectRegion(_ecore_x_disp, dest, source1, source2);
177 #endif
178 }
179
180 EAPI void
181 ecore_x_region_subtract(Ecore_X_Region dest, Ecore_X_Region source1, Ecore_X_Region source2)
182 {
183 #ifdef ECORE_XFIXES
184    XFixesSubtractRegion(_ecore_x_disp, dest, source1, source2);
185 #endif
186 }
187
188 EAPI void
189 ecore_x_region_invert(Ecore_X_Region dest, Ecore_X_Rectangle *bounds, Ecore_X_Region source)
190 {
191 #ifdef ECORE_XFIXES
192    XRectangle *xbound;
193    int num = 0;
194
195    while(bounds + num) num++;
196    xbound = _ecore_x_rectangle_ecore_to_x(bounds, num);
197
198    XFixesInvertRegion(_ecore_x_disp, dest, xbound, source);
199 #endif
200 }
201
202 EAPI void
203 ecore_x_region_translate(Ecore_X_Region region, int dx, int dy)
204 {
205 #ifdef ECORE_XFIXES
206    XFixesTranslateRegion(_ecore_x_disp, region, dx, dy);
207 #endif
208 }
209
210 EAPI void
211 ecore_x_region_extents(Ecore_X_Region dest, Ecore_X_Region source)
212 {
213 #ifdef ECORE_XFIXES
214    XFixesRegionExtents(_ecore_x_disp, dest, source);
215 #endif
216 }
217
218 EAPI Ecore_X_Rectangle *
219 ecore_x_region_fetch(Ecore_X_Region region, int *num, Ecore_X_Rectangle *bounds){
220 #ifdef ECORE_XFIXES
221      Ecore_X_Rectangle *rects;
222      XRectangle *xrect, xbound;
223
224      xrect = XFixesFetchRegionAndBounds(_ecore_x_disp, region, num, &xbound);
225      rects = _ecore_x_rectangle_x_to_ecore(xrect, *num);
226      (*bounds).x = xbound.x;
227      (*bounds).y = xbound.y;
228      (*bounds).width = xbound.width;
229      (*bounds).height = xbound.height;
230      return rects;
231 #else
232      return NULL;
233 #endif
234 }
235
236 EAPI void
237 ecore_x_region_expand(Ecore_X_Region dest, Ecore_X_Region source, unsigned int left, unsigned int right, unsigned int top, unsigned int bottom)
238 {
239 #ifdef ECORE_XFIXES
240    XFixesExpandRegion(_ecore_x_disp, dest, source, left, right, top, bottom);
241 #endif
242 }
243
244 EAPI void
245 ecore_x_region_gc_clip_set(Ecore_X_Region region, Ecore_X_GC gc, int x_origin, int y_origin)
246 {
247 #ifdef ECORE_XFIXES
248    XFixesSetGCClipRegion(_ecore_x_disp, gc, x_origin, y_origin, region);
249 #endif
250 }
251
252 EAPI void
253 ecore_x_region_window_shape_set(Ecore_X_Region region, Ecore_X_Window win, Ecore_X_Shape_Type type, int x_offset, int y_offset)
254 {
255 #ifdef ECORE_XFIXES
256    XFixesSetWindowShapeRegion(_ecore_x_disp, win, type, x_offset, y_offset, region);
257 #endif
258 }
259
260 EAPI void
261 ecore_x_region_picture_clip_set(Ecore_X_Region region, Ecore_X_Picture picture, int x_origin, int y_origin)
262 {
263 #ifdef ECORE_XFIXES
264    XFixesSetPictureClipRegion(_ecore_x_disp, picture, x_origin, y_origin, region);
265 #endif
266 }
267