move around - flatter.
[profile/ivi/ecore.git] / src / lib / ecore_x / xlib / ecore_x_window_shape.c
1 #include "Ecore.h"
2 #include "ecore_x_private.h"
3 #include "Ecore_X.h"
4
5 /**
6  * @defgroup Ecore_X_Window_Shape X Window Shape Functions
7  *
8  * These functions use the shape extension of the X server to change
9  * shape of given windows.
10  */
11
12 /**
13  * Sets the shape of the given window to that given by the pixmap @p mask.
14  * @param   win  The given window.
15  * @param   mask A 2-bit depth pixmap that provides the new shape of the
16  *               window.
17  * @ingroup Ecore_X_Window_Shape
18  */
19 EAPI void
20 ecore_x_window_shape_mask_set(Ecore_X_Window win, Ecore_X_Pixmap mask)
21 {
22    XShapeCombineMask(_ecore_x_disp, win, ShapeBounding, 0, 0, mask, ShapeSet);
23 }
24
25 EAPI void
26 ecore_x_window_shape_window_set(Ecore_X_Window win, Ecore_X_Window shape_win)
27 {
28    XShapeCombineShape(_ecore_x_disp, win, ShapeBounding, 0, 0, shape_win, ShapeBounding, ShapeSet);
29 }
30
31 EAPI void
32 ecore_x_window_shape_window_set_xy(Ecore_X_Window win, Ecore_X_Window shape_win, int x, int y)
33 {
34    XShapeCombineShape(_ecore_x_disp, win, ShapeBounding, x, y, shape_win, ShapeBounding, ShapeSet);
35 }
36
37 EAPI void
38 ecore_x_window_shape_rectangle_set(Ecore_X_Window win, int x, int y, int w, int h)
39 {
40    XRectangle rect;
41    
42    rect.x = x;
43    rect.y = y;
44    rect.width = w;
45    rect.height = h;
46    XShapeCombineRectangles(_ecore_x_disp, win, ShapeBounding, 0, 0, &rect, 1, ShapeSet, Unsorted);
47 }
48
49 EAPI void
50 ecore_x_window_shape_rectangles_set(Ecore_X_Window win, Ecore_X_Rectangle *rects, int num)
51 {
52    XRectangle *rect = NULL;
53    int i;
54    
55    if (num > 0)
56      {
57         rect = malloc(sizeof(XRectangle) * num);
58         if (rect)
59           {
60              for (i = 0; i < num; i++)
61                {
62                   rect[i].x = rects[i].x;
63                   rect[i].y = rects[i].y;
64                   rect[i].width = rects[i].width;
65                   rect[i].height = rects[i].height;
66                }
67           }
68         else
69           num = 0;
70      }
71    XShapeCombineRectangles(_ecore_x_disp, win, ShapeBounding, 0, 0, rect, num, ShapeSet, Unsorted);
72    if (rect) free(rect);
73 }
74
75 EAPI void
76 ecore_x_window_shape_window_add(Ecore_X_Window win, Ecore_X_Window shape_win)
77 {
78    XShapeCombineShape(_ecore_x_disp, win, ShapeBounding, 0, 0, shape_win, ShapeBounding, ShapeUnion);
79 }
80
81 EAPI void
82 ecore_x_window_shape_window_add_xy(Ecore_X_Window win, Ecore_X_Window shape_win, int x, int y)
83 {
84    XShapeCombineShape(_ecore_x_disp, win, ShapeBounding, x, y, shape_win, ShapeBounding, ShapeUnion);
85 }
86
87 EAPI void
88 ecore_x_window_shape_rectangle_add(Ecore_X_Window win, int x, int y, int w, int h)
89 {
90    XRectangle rect;
91    
92    rect.x = x;
93    rect.y = y;
94    rect.width = w;
95    rect.height = h;
96    XShapeCombineRectangles(_ecore_x_disp, win, ShapeBounding, 0, 0, &rect, 1, ShapeUnion, Unsorted);
97 }
98
99 EAPI void
100 ecore_x_window_shape_rectangle_clip(Ecore_X_Window win, int x, int y, int w, int h)
101 {
102    XRectangle rect;
103    
104    rect.x = x;
105    rect.y = y;
106    rect.width = w;
107    rect.height = h;
108    XShapeCombineRectangles(_ecore_x_disp, win, ShapeBounding, 0, 0, &rect, 1, ShapeIntersect, Unsorted);
109 }
110
111 EAPI void
112 ecore_x_window_shape_rectangles_add(Ecore_X_Window win, Ecore_X_Rectangle *rects, int num)
113 {
114    XRectangle *rect = NULL;
115    int i;
116    
117    if (num > 0)
118      {
119         rect = malloc(sizeof(XRectangle) * num);
120         if (rect)
121           {
122              for (i = 0; i < num; i++)
123                {
124                   rect[i].x = rects[i].x;
125                   rect[i].y = rects[i].y;
126                   rect[i].width = rects[i].width;
127                   rect[i].height = rects[i].height;
128                }
129           }
130         else
131           num = 0;
132      }
133    XShapeCombineRectangles(_ecore_x_disp, win, ShapeBounding, 0, 0, rect, num, ShapeUnion, Unsorted);
134    if (rect) free(rect);
135 }
136
137 EAPI Ecore_X_Rectangle *
138 ecore_x_window_shape_rectangles_get(Ecore_X_Window win, int *num_ret)
139 {
140    XRectangle *rect;
141    Ecore_X_Rectangle *rects = NULL;
142    int i, num = 0, ord;
143    
144    rect = XShapeGetRectangles(_ecore_x_disp, win, ShapeBounding, &num, &ord);
145    if (rect)
146      {
147         rects = malloc(sizeof(Ecore_X_Rectangle) * num);
148         if (rects)
149           {
150              for (i = 0; i < num; i++)
151                {
152                   rects[i].x = rect[i].x;
153                   rects[i].y = rect[i].y;
154                   rects[i].width = rect[i].width;
155                   rects[i].height = rect[i].height;
156                }
157           }
158         XFree(rect);
159      }
160    if (num_ret) *num_ret = num;
161    return rects;
162 }
163
164 EAPI void
165 ecore_x_window_shape_events_select(Ecore_X_Window win, int on)
166 {
167    if (on)
168      XShapeSelectInput(_ecore_x_disp, win, ShapeNotifyMask);
169    else
170      XShapeSelectInput(_ecore_x_disp, win, 0);
171 }
172
173 /**
174  * Sets the input shape of the given window to that given by the pixmap @p mask.
175  * @param   win  The given window.
176  * @param   mask A 2-bit depth pixmap that provides the new input shape of the
177  *               window.
178  * @ingroup Ecore_X_Window_Shape
179  */
180 EAPI void
181 ecore_x_window_shape_input_mask_set(Ecore_X_Window win, Ecore_X_Pixmap mask)
182 {
183 #ifdef ShapeInput
184    XShapeCombineMask(_ecore_x_disp, win, ShapeInput, 0, 0, mask, ShapeSet);
185 #else   
186    XShapeCombineMask(_ecore_x_disp, win, ShapeBounding, 0, 0, mask, ShapeSet);
187 #endif
188 }
189