svn update: 60286 (latest:60286)
[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 /**
33  * Sets the input shape of the given window to that given by the pixmap @p mask.
34  * @param   win  The given window.
35  * @param   mask A 1-bit depth pixmap that provides the new input shape of the
36  *               window.
37  * @ingroup Ecore_X_Window_Shape
38  */
39 EAPI void
40 ecore_x_window_shape_input_mask_set(Ecore_X_Window win, Ecore_X_Pixmap mask)
41 {
42    LOGFN(__FILE__, __LINE__, __FUNCTION__);
43 #ifdef ShapeInput
44    XShapeCombineMask(_ecore_x_disp, win, ShapeInput,    0, 0, mask, ShapeSet);
45 #else /* ifdef ShapeInput */
46    return;
47    win = mask = 0;
48 #endif /* ifdef ShapeInput */
49 } /* ecore_x_window_shape_input_mask_set */
50
51 EAPI void
52 ecore_x_window_shape_window_set(Ecore_X_Window win, Ecore_X_Window shape_win)
53 {
54    LOGFN(__FILE__, __LINE__, __FUNCTION__);
55    XShapeCombineShape(_ecore_x_disp,
56                       win,
57                       ShapeBounding,
58                       0,
59                       0,
60                       shape_win,
61                       ShapeBounding,
62                       ShapeSet);
63 } /* ecore_x_window_shape_window_set */
64
65 EAPI void
66 ecore_x_window_shape_input_window_set(Ecore_X_Window win,
67                                       Ecore_X_Window shape_win)
68 {
69 #ifdef ShapeInput
70    LOGFN(__FILE__, __LINE__, __FUNCTION__);
71    XShapeCombineShape(_ecore_x_disp,
72                       win,
73                       ShapeInput,
74                       0,
75                       0,
76                       shape_win,
77                       ShapeInput,
78                       ShapeSet);
79 #else
80    return;
81    win = shape_win = 0;
82 #endif
83 } /* ecore_x_window_shape_input_window_set */
84
85 EAPI void
86 ecore_x_window_shape_window_set_xy(Ecore_X_Window win,
87                                    Ecore_X_Window shape_win,
88                                    int            x,
89                                    int            y)
90 {
91    LOGFN(__FILE__, __LINE__, __FUNCTION__);
92    XShapeCombineShape(_ecore_x_disp,
93                       win,
94                       ShapeBounding,
95                       x,
96                       y,
97                       shape_win,
98                       ShapeBounding,
99                       ShapeSet);
100 } /* ecore_x_window_shape_window_set_xy */
101
102 EAPI void
103 ecore_x_window_shape_input_window_set_xy(Ecore_X_Window win,
104                                          Ecore_X_Window shape_win,
105                                          int            x,
106                                          int            y)
107 {
108 #ifdef ShapeInput
109    LOGFN(__FILE__, __LINE__, __FUNCTION__);
110    XShapeCombineShape(_ecore_x_disp,
111                       win,
112                       ShapeInput,
113                       x,
114                       y,
115                       shape_win,
116                       ShapeInput,
117                       ShapeSet);
118 #else
119    return;
120    win = shape_win = x = y = 0;
121 #endif
122 } /* ecore_x_window_shape_input_window_set_xy */
123
124 EAPI void
125 ecore_x_window_shape_rectangle_set(Ecore_X_Window win,
126                                    int            x,
127                                    int            y,
128                                    int            w,
129                                    int            h)
130 {
131    XRectangle rect;
132
133    LOGFN(__FILE__, __LINE__, __FUNCTION__);
134    rect.x = x;
135    rect.y = y;
136    rect.width = w;
137    rect.height = h;
138    XShapeCombineRectangles(_ecore_x_disp,
139                            win,
140                            ShapeBounding,
141                            0,
142                            0,
143                            &rect,
144                            1,
145                            ShapeSet,
146                            Unsorted);
147 } /* ecore_x_window_shape_rectangle_set */
148
149 EAPI void
150 ecore_x_window_shape_input_rectangle_set(Ecore_X_Window win,
151                                          int            x,
152                                          int            y,
153                                          int            w,
154                                          int            h)
155 {
156 #ifdef ShapeInput
157    XRectangle rect;
158
159    LOGFN(__FILE__, __LINE__, __FUNCTION__);
160    rect.x = x;
161    rect.y = y;
162    rect.width = w;
163    rect.height = h;
164    XShapeCombineRectangles(_ecore_x_disp,
165                            win,
166                            ShapeInput,
167                            0,
168                            0,
169                            &rect,
170                            1,
171                            ShapeSet,
172                            Unsorted);
173 #else
174    return;
175    win = x = y = w = h = 0;
176 #endif
177 } /* ecore_x_window_shape_input_rectangle_set */
178
179 EAPI void
180 ecore_x_window_shape_rectangles_set(Ecore_X_Window     win,
181                                     Ecore_X_Rectangle *rects,
182                                     int                num)
183 {
184 #ifdef ShapeInput
185    XRectangle *rect = NULL;
186    int i;
187
188    LOGFN(__FILE__, __LINE__, __FUNCTION__);
189    if (!rects) return;
190    if (num > 0)
191      {
192         rect = malloc(sizeof(XRectangle) * num);
193         if (!rect) return;
194         for (i = 0; i < num; i++)
195           {
196              rect[i].x = rects[i].x;
197              rect[i].y = rects[i].y;
198              rect[i].width = rects[i].width;
199              rect[i].height = rects[i].height;
200           }
201      }
202    XShapeCombineRectangles(_ecore_x_disp,
203                            win,
204                            ShapeBounding,
205                            0,
206                            0,
207                            rect,
208                            num,
209                            ShapeSet,
210                            Unsorted);
211    if (rect) free(rect);
212 #else
213    return;
214    win = rects = num = 0;
215 #endif
216 } /* ecore_x_window_shape_rectangles_set */
217
218 EAPI void
219 ecore_x_window_shape_input_rectangles_set(Ecore_X_Window     win,
220                                           Ecore_X_Rectangle *rects,
221                                           int                num)
222 {
223 #ifdef ShapeInput
224    XRectangle *rect = NULL;
225    int i;
226
227    LOGFN(__FILE__, __LINE__, __FUNCTION__);
228    if (!rects) return;
229    if (num > 0)
230      {
231         rect = malloc(sizeof(XRectangle) * num);
232         if (!rect) return;
233         for (i = 0; i < num; i++)
234           {
235              rect[i].x = rects[i].x;
236              rect[i].y = rects[i].y;
237              rect[i].width = rects[i].width;
238              rect[i].height = rects[i].height;
239           }
240      }
241    XShapeCombineRectangles(_ecore_x_disp,
242                            win,
243                            ShapeInput,
244                            0,
245                            0,
246                            rect,
247                            num,
248                            ShapeSet,
249                            Unsorted);
250    if (rect) free(rect);
251 #else
252    return;
253    win = rects = num = 0;
254 #endif
255 } /* ecore_x_window_shape_input_rectangles_set */
256
257 EAPI void
258 ecore_x_window_shape_rectangle_subtract(Ecore_X_Window win,
259                                         int            x,
260                                         int            y,
261                                         int            w,
262                                         int            h)
263 {
264    XRectangle rect;
265
266    LOGFN(__FILE__, __LINE__, __FUNCTION__);
267    rect.x = x;
268    rect.y = y;
269    rect.width = w;
270    rect.height = h;
271    XShapeCombineRectangles(_ecore_x_disp,
272                            win,
273                            ShapeBounding,
274                            0,
275                            0,
276                            &rect,
277                            1,
278                            ShapeSubtract,
279                            Unsorted);
280 } /* ecore_x_window_shape_rectangle_subtract */
281
282 EAPI void
283 ecore_x_window_shape_input_rectangle_subtract(Ecore_X_Window win,
284                                               int            x,
285                                               int            y,
286                                               int            w,
287                                               int            h)
288 {
289 #ifdef ShapeInput
290    XRectangle rect;
291
292    LOGFN(__FILE__, __LINE__, __FUNCTION__);
293    rect.x = x;
294    rect.y = y;
295    rect.width = w;
296    rect.height = h;
297    XShapeCombineRectangles(_ecore_x_disp,
298                            win,
299                            ShapeInput,
300                            0,
301                            0,
302                            &rect,
303                            1,
304                            ShapeSubtract,
305                            Unsorted);
306 #else
307    return;
308    win = x = y = w = h = 0;
309 #endif
310 } /* ecore_x_window_shape_input_rectangle_subtract */
311
312 EAPI void
313 ecore_x_window_shape_window_add(Ecore_X_Window win, Ecore_X_Window shape_win)
314 {
315    LOGFN(__FILE__, __LINE__, __FUNCTION__);
316    XShapeCombineShape(_ecore_x_disp,
317                       win,
318                       ShapeBounding,
319                       0,
320                       0,
321                       shape_win,
322                       ShapeBounding,
323                       ShapeUnion);
324 } /* ecore_x_window_shape_window_add */
325
326 EAPI void
327 ecore_x_window_shape_window_add_xy(Ecore_X_Window win,
328                                    Ecore_X_Window shape_win,
329                                    int            x,
330                                    int            y)
331 {
332    LOGFN(__FILE__, __LINE__, __FUNCTION__);
333    XShapeCombineShape(_ecore_x_disp,
334                       win,
335                       ShapeBounding,
336                       x,
337                       y,
338                       shape_win,
339                       ShapeBounding,
340                       ShapeUnion);
341 } /* ecore_x_window_shape_window_add_xy */
342
343 EAPI void
344 ecore_x_window_shape_input_window_add_xy(Ecore_X_Window win,
345                                          Ecore_X_Window shape_win,
346                                          int            x,
347                                          int            y)
348 {
349 #ifdef ShapeInput
350    LOGFN(__FILE__, __LINE__, __FUNCTION__);
351    XShapeCombineShape(_ecore_x_disp,
352                       win,
353                       ShapeInput,
354                       x,
355                       y,
356                       shape_win,
357                       ShapeInput,
358                       ShapeUnion);
359 #else
360    return;
361    win = shape_win = x = y = 0;
362 #endif
363 } /* ecore_x_window_shape_input_window_add_xy */
364
365 EAPI void
366 ecore_x_window_shape_rectangle_add(Ecore_X_Window win,
367                                    int            x,
368                                    int            y,
369                                    int            w,
370                                    int            h)
371 {
372    XRectangle rect;
373
374    LOGFN(__FILE__, __LINE__, __FUNCTION__);
375    rect.x = x;
376    rect.y = y;
377    rect.width = w;
378    rect.height = h;
379    XShapeCombineRectangles(_ecore_x_disp,
380                            win,
381                            ShapeBounding,
382                            0,
383                            0,
384                            &rect,
385                            1,
386                            ShapeUnion,
387                            Unsorted);
388 } /* ecore_x_window_shape_rectangle_add */
389
390 EAPI void
391 ecore_x_window_shape_input_rectangle_add(Ecore_X_Window win,
392                                          int            x,
393                                          int            y,
394                                          int            w,
395                                          int            h)
396 {
397 #ifdef ShapeInput
398    XRectangle rect;
399
400    LOGFN(__FILE__, __LINE__, __FUNCTION__);
401    rect.x = x;
402    rect.y = y;
403    rect.width = w;
404    rect.height = h;
405    XShapeCombineRectangles(_ecore_x_disp,
406                            win,
407                            ShapeInput,
408                            0,
409                            0,
410                            &rect,
411                            1,
412                            ShapeUnion,
413                            Unsorted);
414 #else
415    return;
416    win = x = y = w = h = 0;
417 #endif
418 } /* ecore_x_window_shape_input_rectangle_add */
419
420 EAPI void
421 ecore_x_window_shape_rectangle_clip(Ecore_X_Window win,
422                                     int            x,
423                                     int            y,
424                                     int            w,
425                                     int            h)
426 {
427    XRectangle rect;
428
429    LOGFN(__FILE__, __LINE__, __FUNCTION__);
430    rect.x = x;
431    rect.y = y;
432    rect.width = w;
433    rect.height = h;
434    XShapeCombineRectangles(_ecore_x_disp,
435                            win,
436                            ShapeBounding,
437                            0,
438                            0,
439                            &rect,
440                            1,
441                            ShapeIntersect,
442                            Unsorted);
443 } /* ecore_x_window_shape_rectangle_clip */
444
445 EAPI void
446 ecore_x_window_shape_input_rectangle_clip(Ecore_X_Window win,
447                                           int            x,
448                                           int            y,
449                                           int            w,
450                                           int            h)
451 {
452 #ifdef ShapeInput
453    XRectangle rect;
454
455    LOGFN(__FILE__, __LINE__, __FUNCTION__);
456    rect.x = x;
457    rect.y = y;
458    rect.width = w;
459    rect.height = h;
460    XShapeCombineRectangles(_ecore_x_disp,
461                            win,
462                            ShapeInput,
463                            0,
464                            0,
465                            &rect,
466                            1,
467                            ShapeIntersect,
468                            Unsorted);
469 #else
470    return;
471    win = x = y = w = h = 0;
472 #endif
473 } /* ecore_x_window_shape_input_rectangle_clip */
474
475 EAPI void
476 ecore_x_window_shape_rectangles_add(Ecore_X_Window     win,
477                                     Ecore_X_Rectangle *rects,
478                                     int                num)
479 {
480    XRectangle *rect = NULL;
481    int i;
482
483    LOGFN(__FILE__, __LINE__, __FUNCTION__);
484    if (num > 0)
485      {
486         rect = malloc(sizeof(XRectangle) * num);
487         if (!rect) return;
488         for (i = 0; i < num; i++)
489           {
490              rect[i].x = rects[i].x;
491              rect[i].y = rects[i].y;
492              rect[i].width = rects[i].width;
493              rect[i].height = rects[i].height;
494           }
495      }
496    
497    XShapeCombineRectangles(_ecore_x_disp,
498                            win,
499                            ShapeBounding,
500                            0,
501                            0,
502                            rect,
503                            num,
504                            ShapeUnion,
505                            Unsorted);
506    if (rect) free(rect);
507 } /* ecore_x_window_shape_rectangles_add */
508
509 EAPI void
510 ecore_x_window_shape_input_rectangles_add(Ecore_X_Window     win,
511                                           Ecore_X_Rectangle *rects,
512                                           int                num)
513 {
514 #ifdef ShapeInput
515    XRectangle *rect = NULL;
516    int i;
517
518    LOGFN(__FILE__, __LINE__, __FUNCTION__);
519    if (num > 0)
520      {
521         rect = malloc(sizeof(XRectangle) * num);
522         if (!rect) return;
523         for (i = 0; i < num; i++)
524           {
525              rect[i].x = rects[i].x;
526              rect[i].y = rects[i].y;
527              rect[i].width = rects[i].width;
528              rect[i].height = rects[i].height;
529           }
530      }
531
532    XShapeCombineRectangles(_ecore_x_disp,
533                            win,
534                            ShapeInput,
535                            0,
536                            0,
537                            rect,
538                            num,
539                            ShapeUnion,
540                            Unsorted);
541    if (rect) free(rect);
542 #else
543    return;
544    win = rects = num = 0;
545 #endif
546 } /* ecore_x_window_shape_input_rectangles_add */
547
548 EAPI Ecore_X_Rectangle *
549 ecore_x_window_shape_rectangles_get(Ecore_X_Window win, int *num_ret)
550 {
551    XRectangle *rect;
552    Ecore_X_Rectangle *rects = NULL;
553    int i, num = 0, ord;
554
555    LOGFN(__FILE__, __LINE__, __FUNCTION__);
556    rect = XShapeGetRectangles(_ecore_x_disp, win, ShapeBounding, &num, &ord);
557    if (rect)
558      {
559         if (num < 1)
560           {
561              XFree(rect);
562              if (num_ret) *num_ret = 0;
563              return NULL;
564           }
565         rects = malloc(sizeof(Ecore_X_Rectangle) * num);
566         if (!rects)
567           {
568              XFree(rect);
569              if (num_ret) *num_ret = 0;
570              return NULL;
571           }
572         for (i = 0; i < num; i++)
573           {
574              rects[i].x = rect[i].x;
575              rects[i].y = rect[i].y;
576              rects[i].width = rect[i].width;
577              rects[i].height = rect[i].height;
578           }
579         XFree(rect);
580      }
581    if (num_ret) *num_ret = num;
582    return rects;
583 } /* ecore_x_window_shape_rectangles_get */
584
585 EAPI Ecore_X_Rectangle *
586 ecore_x_window_shape_input_rectangles_get(Ecore_X_Window win, int *num_ret)
587 {
588    Ecore_X_Rectangle *rects = NULL;
589 #ifdef ShapeInput
590    XRectangle *rect;
591    int i, num = 0, ord;
592
593    LOGFN(__FILE__, __LINE__, __FUNCTION__);
594    rect = XShapeGetRectangles(_ecore_x_disp, win, ShapeInput, &num, &ord);
595    if (rect)
596      {
597         if (num < 1)
598           {
599              XFree(rect);
600              if (num_ret) *num_ret = 0;
601              return NULL;
602           }
603         rects = malloc(sizeof(Ecore_X_Rectangle) * num);
604         if (!rects)
605           {
606              XFree(rect);
607              if (num_ret) *num_ret = 0;
608              return NULL;
609           }
610         for (i = 0; i < num; i++)
611           {
612              rects[i].x = rect[i].x;
613              rects[i].y = rect[i].y;
614              rects[i].width = rect[i].width;
615              rects[i].height = rect[i].height;
616           }
617         XFree(rect);
618      }
619    if (num_ret) *num_ret = num;
620    return rects;
621 #else
622    // have to return fake shape input rect of size of window
623    Window dw;
624    unsigned int di;
625    
626    if (num_ret) *num_ret = 0;
627    rects = malloc(sizeof(Ecore_X_Rectangle));
628    if (!rects) return NULL;
629    if (!XGetGeometry(_ecore_x_disp, win, &dw,
630                      &(rects[0].x), &(rects[0].y),
631                      &(rects[0].width), &(rects[0].height),
632                      &di, &di))
633      {
634         free(rects);
635         return NULL;
636      }
637    if (num_ret) *num_ret = 1;
638    return rects;
639 #endif
640 } /* ecore_x_window_shape_input_rectangles_get */
641
642 EAPI void
643 ecore_x_window_shape_events_select(Ecore_X_Window win, Eina_Bool on)
644 {
645    LOGFN(__FILE__, __LINE__, __FUNCTION__);
646    if (on)
647       XShapeSelectInput(_ecore_x_disp, win, ShapeNotifyMask);
648    else
649       XShapeSelectInput(_ecore_x_disp, win, 0);
650 } /* ecore_x_window_shape_events_select */