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