2f56e72df740eb8fca7bbf6635a125e65e1c6314
[profile/ivi/ecore.git] / src / lib / ecore_x / xlib / ecore_x_window_shape.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.h"
8 #include "ecore_x_private.h"
9 #include "Ecore_X.h"
10
11 /**
12  * @defgroup Ecore_X_Window_Shape X Window Shape Functions
13  *
14  * These functions use the shape extension of the X server to change
15  * shape of given windows.
16  */
17
18 /**
19  * Sets the shape of the given window to that given by the pixmap @p mask.
20  * @param   win  The given window.
21  * @param   mask A 2-bit depth pixmap that provides the new shape of the
22  *               window.
23  * @ingroup Ecore_X_Window_Shape
24  */
25 EAPI void
26 ecore_x_window_shape_mask_set(Ecore_X_Window win, Ecore_X_Pixmap mask)
27 {
28    LOGFN(__FILE__, __LINE__, __FUNCTION__);
29    XShapeCombineMask(_ecore_x_disp, win, ShapeBounding, 0, 0, mask, ShapeSet);
30 } /* ecore_x_window_shape_mask_set */
31
32 EAPI void
33 ecore_x_window_shape_window_set(Ecore_X_Window win, Ecore_X_Window shape_win)
34 {
35    LOGFN(__FILE__, __LINE__, __FUNCTION__);
36    XShapeCombineShape(_ecore_x_disp,
37                       win,
38                       ShapeBounding,
39                       0,
40                       0,
41                       shape_win,
42                       ShapeBounding,
43                       ShapeSet);
44 } /* ecore_x_window_shape_window_set */
45
46 EAPI void
47 ecore_x_window_shape_window_set_xy(Ecore_X_Window win,
48                                    Ecore_X_Window shape_win,
49                                    int            x,
50                                    int            y)
51 {
52    LOGFN(__FILE__, __LINE__, __FUNCTION__);
53    XShapeCombineShape(_ecore_x_disp,
54                       win,
55                       ShapeBounding,
56                       x,
57                       y,
58                       shape_win,
59                       ShapeBounding,
60                       ShapeSet);
61 } /* ecore_x_window_shape_window_set_xy */
62
63 EAPI void
64 ecore_x_window_shape_rectangle_set(Ecore_X_Window win,
65                                    int            x,
66                                    int            y,
67                                    int            w,
68                                    int            h)
69 {
70    XRectangle rect;
71
72    LOGFN(__FILE__, __LINE__, __FUNCTION__);
73    rect.x = x;
74    rect.y = y;
75    rect.width = w;
76    rect.height = h;
77    XShapeCombineRectangles(_ecore_x_disp,
78                            win,
79                            ShapeBounding,
80                            0,
81                            0,
82                            &rect,
83                            1,
84                            ShapeSet,
85                            Unsorted);
86 } /* ecore_x_window_shape_rectangle_set */
87
88 EAPI void
89 ecore_x_window_shape_rectangles_set(Ecore_X_Window     win,
90                                     Ecore_X_Rectangle *rects,
91                                     int                num)
92 {
93    XRectangle *rect = NULL;
94    int i;
95
96    LOGFN(__FILE__, __LINE__, __FUNCTION__);
97    if (num > 0)
98      {
99         rect = malloc(sizeof(XRectangle) * num);
100         if (rect)
101            for (i = 0; i < num; i++)
102              {
103                 rect[i].x = rects[i].x;
104                 rect[i].y = rects[i].y;
105                 rect[i].width = rects[i].width;
106                 rect[i].height = rects[i].height;
107              }
108         else
109            num = 0;
110      }
111
112    XShapeCombineRectangles(_ecore_x_disp,
113                            win,
114                            ShapeBounding,
115                            0,
116                            0,
117                            rect,
118                            num,
119                            ShapeSet,
120                            Unsorted);
121    if (rect)
122       free(rect);
123 } /* ecore_x_window_shape_rectangles_set */
124
125 EAPI void
126 ecore_x_window_shape_window_add(Ecore_X_Window win, Ecore_X_Window shape_win)
127 {
128    LOGFN(__FILE__, __LINE__, __FUNCTION__);
129    XShapeCombineShape(_ecore_x_disp,
130                       win,
131                       ShapeBounding,
132                       0,
133                       0,
134                       shape_win,
135                       ShapeBounding,
136                       ShapeUnion);
137 } /* ecore_x_window_shape_window_add */
138
139 EAPI void
140 ecore_x_window_shape_window_add_xy(Ecore_X_Window win,
141                                    Ecore_X_Window shape_win,
142                                    int            x,
143                                    int            y)
144 {
145    LOGFN(__FILE__, __LINE__, __FUNCTION__);
146    XShapeCombineShape(_ecore_x_disp,
147                       win,
148                       ShapeBounding,
149                       x,
150                       y,
151                       shape_win,
152                       ShapeBounding,
153                       ShapeUnion);
154 } /* ecore_x_window_shape_window_add_xy */
155
156 EAPI void
157 ecore_x_window_shape_rectangle_add(Ecore_X_Window win,
158                                    int            x,
159                                    int            y,
160                                    int            w,
161                                    int            h)
162 {
163    XRectangle rect;
164
165    LOGFN(__FILE__, __LINE__, __FUNCTION__);
166    rect.x = x;
167    rect.y = y;
168    rect.width = w;
169    rect.height = h;
170    XShapeCombineRectangles(_ecore_x_disp,
171                            win,
172                            ShapeBounding,
173                            0,
174                            0,
175                            &rect,
176                            1,
177                            ShapeUnion,
178                            Unsorted);
179 } /* ecore_x_window_shape_rectangle_add */
180
181 EAPI void
182 ecore_x_window_shape_rectangle_clip(Ecore_X_Window win,
183                                     int            x,
184                                     int            y,
185                                     int            w,
186                                     int            h)
187 {
188    XRectangle rect;
189
190    LOGFN(__FILE__, __LINE__, __FUNCTION__);
191    rect.x = x;
192    rect.y = y;
193    rect.width = w;
194    rect.height = h;
195    XShapeCombineRectangles(_ecore_x_disp,
196                            win,
197                            ShapeBounding,
198                            0,
199                            0,
200                            &rect,
201                            1,
202                            ShapeIntersect,
203                            Unsorted);
204 } /* ecore_x_window_shape_rectangle_clip */
205
206 EAPI void
207 ecore_x_window_shape_rectangles_add(Ecore_X_Window     win,
208                                     Ecore_X_Rectangle *rects,
209                                     int                num)
210 {
211    XRectangle *rect = NULL;
212    int i;
213
214    LOGFN(__FILE__, __LINE__, __FUNCTION__);
215    if (num > 0)
216      {
217         rect = malloc(sizeof(XRectangle) * num);
218         if (rect)
219            for (i = 0; i < num; i++)
220              {
221                 rect[i].x = rects[i].x;
222                 rect[i].y = rects[i].y;
223                 rect[i].width = rects[i].width;
224                 rect[i].height = rects[i].height;
225              }
226         else
227            num = 0;
228      }
229
230    XShapeCombineRectangles(_ecore_x_disp,
231                            win,
232                            ShapeBounding,
233                            0,
234                            0,
235                            rect,
236                            num,
237                            ShapeUnion,
238                            Unsorted);
239    if (rect)
240       free(rect);
241 } /* ecore_x_window_shape_rectangles_add */
242
243 EAPI Ecore_X_Rectangle *
244 ecore_x_window_shape_rectangles_get(Ecore_X_Window win, int *num_ret)
245 {
246    XRectangle *rect;
247    Ecore_X_Rectangle *rects = NULL;
248    int i, num = 0, ord;
249
250    LOGFN(__FILE__, __LINE__, __FUNCTION__);
251    rect = XShapeGetRectangles(_ecore_x_disp, win, ShapeBounding, &num, &ord);
252    if (rect)
253      {
254         rects = malloc(sizeof(Ecore_X_Rectangle) * num);
255         if (rects)
256            for (i = 0; i < num; i++)
257              {
258                 rects[i].x = rect[i].x;
259                 rects[i].y = rect[i].y;
260                 rects[i].width = rect[i].width;
261                 rects[i].height = rect[i].height;
262              }
263
264         XFree(rect);
265      }
266
267    if (num_ret)
268       *num_ret = num;
269
270    return rects;
271 } /* ecore_x_window_shape_rectangles_get */
272
273 EAPI void
274 ecore_x_window_shape_events_select(Ecore_X_Window win, int on)
275 {
276    LOGFN(__FILE__, __LINE__, __FUNCTION__);
277    if (on)
278       XShapeSelectInput(_ecore_x_disp, win, ShapeNotifyMask);
279    else
280       XShapeSelectInput(_ecore_x_disp, win, 0);
281 } /* ecore_x_window_shape_events_select */
282
283 /**
284  * Sets the input shape of the given window to that given by the pixmap @p mask.
285  * @param   win  The given window.
286  * @param   mask A 2-bit depth pixmap that provides the new input shape of the
287  *               window.
288  * @ingroup Ecore_X_Window_Shape
289  */
290 EAPI void
291 ecore_x_window_shape_input_mask_set(Ecore_X_Window win, Ecore_X_Pixmap mask)
292 {
293    LOGFN(__FILE__, __LINE__, __FUNCTION__);
294 #ifdef ShapeInput
295    XShapeCombineMask(_ecore_x_disp, win, ShapeInput,    0, 0, mask, ShapeSet);
296 #else /* ifdef ShapeInput */
297    XShapeCombineMask(_ecore_x_disp, win, ShapeBounding, 0, 0, mask, ShapeSet);
298 #endif /* ifdef ShapeInput */
299 } /* ecore_x_window_shape_input_mask_set */
300