Tizen 2.1 base
[framework/uifw/ecore.git] / src / lib / ecore_x / xlib / ecore_x_window.c
1 #ifdef HAVE_CONFIG_H
2 # include <config.h>
3 #endif /* ifdef HAVE_CONFIG_H */
4
5 #include <stdlib.h>
6 #include <sys/types.h>
7 #include <unistd.h>
8
9 #include "Ecore.h"
10 #include "ecore_x_private.h"
11 #include "Ecore_X.h"
12 #include "Ecore_X_Atoms.h"
13
14 static int ignore_num = 0;
15 static Ecore_X_Window *ignore_list = NULL;
16
17 /**
18  * @defgroup Ecore_X_Window_Create_Group X Window Creation Functions
19  *
20  * Functions that can be used to create an X window.
21  */
22
23 /**
24  * Creates a new window.
25  * @param   parent The parent window to use.  If @p parent is @c 0, the root
26  *                 window of the default display is used.
27  * @param   x      X position.
28  * @param   y      Y position.
29  * @param   w      Width.
30  * @param   h      Height.
31  * @return  The new window handle.
32  * @ingroup Ecore_X_Window_Create_Group
33  */
34 EAPI Ecore_X_Window
35 ecore_x_window_new(Ecore_X_Window parent,
36                    int x,
37                    int y,
38                    int w,
39                    int h)
40 {
41    Window win;
42    XSetWindowAttributes attr;
43
44    LOGFN(__FILE__, __LINE__, __FUNCTION__);
45    if (parent == 0)
46      parent = DefaultRootWindow(_ecore_x_disp);
47
48    attr.backing_store = NotUseful;
49    attr.override_redirect = False;
50    attr.border_pixel = 0;
51    attr.background_pixmap = None;
52    attr.bit_gravity = NorthWestGravity;
53    attr.win_gravity = NorthWestGravity;
54    attr.save_under = False;
55    attr.do_not_propagate_mask = NoEventMask;
56    attr.event_mask = KeyPressMask |
57      KeyReleaseMask |
58      ButtonPressMask |
59      ButtonReleaseMask |
60      EnterWindowMask |
61      LeaveWindowMask |
62      PointerMotionMask |
63      ExposureMask |
64      VisibilityChangeMask |
65      StructureNotifyMask |
66      FocusChangeMask |
67      PropertyChangeMask |
68      ColormapChangeMask;
69    win = XCreateWindow(_ecore_x_disp, parent,
70                        x, y, w, h, 0,
71                        CopyFromParent, /*DefaultDepth(_ecore_x_disp, DefaultScreen(_ecore_x_disp)),*/
72                        InputOutput,
73                        CopyFromParent, /*DefaultVisual(_ecore_x_disp, DefaultScreen(_ecore_x_disp)),*/
74                        CWBackingStore |
75                        CWOverrideRedirect |
76 /*                     CWColormap | */
77                        CWBorderPixel |
78                        CWBackPixmap |
79                        CWSaveUnder |
80                        CWDontPropagate |
81                        CWEventMask |
82                        CWBitGravity |
83                        CWWinGravity,
84                        &attr);
85
86    if (parent == DefaultRootWindow(_ecore_x_disp))
87      ecore_x_window_defaults_set(win);
88
89    return win;
90 }
91
92 /**
93  * Creates a window with the override redirect attribute set to @c True.
94  * @param   parent The parent window to use.  If @p parent is @c 0, the root
95  *                 window of the default display is used.
96  * @param   x      X position.
97  * @param   y      Y position.
98  * @param   w      Width.
99  * @param   h      Height.
100  * @return  The new window handle.
101  * @ingroup Ecore_X_Window_Create_Group
102  */
103 EAPI Ecore_X_Window
104 ecore_x_window_override_new(Ecore_X_Window parent,
105                             int x,
106                             int y,
107                             int w,
108                             int h)
109 {
110    Window win;
111    XSetWindowAttributes attr;
112
113    LOGFN(__FILE__, __LINE__, __FUNCTION__);
114    if (parent == 0)
115      parent = DefaultRootWindow(_ecore_x_disp);
116
117    attr.backing_store = NotUseful;
118    attr.override_redirect = True;
119    attr.border_pixel = 0;
120    attr.background_pixmap = None;
121    attr.bit_gravity = NorthWestGravity;
122    attr.win_gravity = NorthWestGravity;
123    attr.save_under = False;
124    attr.do_not_propagate_mask = NoEventMask;
125    attr.event_mask = KeyPressMask |
126      KeyReleaseMask |
127      ButtonPressMask |
128      ButtonReleaseMask |
129      EnterWindowMask |
130      LeaveWindowMask |
131      PointerMotionMask |
132      ExposureMask |
133      VisibilityChangeMask |
134      StructureNotifyMask |
135      FocusChangeMask |
136      PropertyChangeMask |
137      ColormapChangeMask;
138    win = XCreateWindow(_ecore_x_disp, parent,
139                        x, y, w, h, 0,
140                        CopyFromParent, /*DefaultDepth(_ecore_x_disp, DefaultScreen(_ecore_x_disp)),*/
141                        InputOutput,
142                        CopyFromParent, /*DefaultVisual(_ecore_x_disp, DefaultScreen(_ecore_x_disp)),*/
143                        CWBackingStore |
144                        CWOverrideRedirect |
145 /*                     CWColormap | */
146                        CWBorderPixel |
147                        CWBackPixmap |
148                        CWSaveUnder |
149                        CWDontPropagate |
150                        CWEventMask |
151                        CWBitGravity |
152                        CWWinGravity,
153                        &attr);
154    return win;
155 }
156
157 /**
158  * Creates a new input window.
159  * @param   parent The parent window to use.    If @p parent is @c 0, the root
160  *                 window of the default display is used.
161  * @param   x      X position.
162  * @param   y      Y position.
163  * @param   w      Width.
164  * @param   h      Height.
165  * @return  The new window.
166  * @ingroup Ecore_X_Window_Create_Group
167  */
168 EAPI Ecore_X_Window
169 ecore_x_window_input_new(Ecore_X_Window parent,
170                          int x,
171                          int y,
172                          int w,
173                          int h)
174 {
175    Window win;
176    XSetWindowAttributes attr;
177
178    LOGFN(__FILE__, __LINE__, __FUNCTION__);
179    if (parent == 0)
180      parent = DefaultRootWindow(_ecore_x_disp);
181
182    attr.override_redirect = True;
183    attr.do_not_propagate_mask = NoEventMask;
184    attr.event_mask = KeyPressMask |
185      KeyReleaseMask |
186      ButtonPressMask |
187      ButtonReleaseMask |
188      EnterWindowMask |
189      LeaveWindowMask |
190      PointerMotionMask |
191      ExposureMask |
192      VisibilityChangeMask |
193      StructureNotifyMask |
194      FocusChangeMask |
195      PropertyChangeMask |
196      ColormapChangeMask;
197    win = XCreateWindow(_ecore_x_disp, parent,
198                        x, y, w, h, 0,
199                        CopyFromParent,
200                        InputOnly,
201                        CopyFromParent, /*DefaultVisual(_ecore_x_disp, DefaultScreen(_ecore_x_disp)),*/
202                        CWOverrideRedirect |
203                        CWDontPropagate |
204                        CWEventMask,
205                        &attr);
206
207    if (parent == DefaultRootWindow(_ecore_x_disp))
208      {
209      }
210
211    return win;
212 }
213
214 /**
215  * @defgroup Ecore_X_Window_Properties_Group X Window Property Functions
216  *
217  * Functions that set window properties.
218  */
219
220 /**
221  * Sets the default properties for the given window.
222  *
223  * The default properties set for the window are @c WM_CLIENT_MACHINE and
224  * @c _NET_WM_PID.
225  *
226  * @param   win The given window.
227  * @ingroup Ecore_X_Window_Properties_Group
228  */
229 EAPI void
230 ecore_x_window_defaults_set(Ecore_X_Window win)
231 {
232    long pid;
233    char buf[MAXHOSTNAMELEN];
234    char *hostname[1];
235    int argc;
236    char **argv;
237    XTextProperty xprop;
238
239    LOGFN(__FILE__, __LINE__, __FUNCTION__);
240    /*
241     * Set WM_CLIENT_MACHINE.
242     */
243    gethostname(buf, MAXHOSTNAMELEN);
244    buf[MAXHOSTNAMELEN - 1] = '\0';
245    hostname[0] = buf;
246    /* The ecore function uses UTF8 which Xlib may not like (especially
247     * with older clients) */
248    /* ecore_x_window_prop_string_set(win, ECORE_X_ATOM_WM_CLIENT_MACHINE,
249                                   (char *)buf); */
250    if (XStringListToTextProperty(hostname, 1, &xprop))
251      {
252         XSetWMClientMachine(_ecore_x_disp, win, &xprop);
253         XFree(xprop.value);
254      }
255
256    /*
257     * Set _NET_WM_PID
258     */
259    pid = getpid();
260    ecore_x_netwm_pid_set(win, pid);
261
262    ecore_x_netwm_window_type_set(win, ECORE_X_WINDOW_TYPE_NORMAL);
263
264    ecore_app_args_get(&argc, &argv);
265    ecore_x_icccm_command_set(win, argc, argv);
266 }
267
268 EAPI void
269 ecore_x_window_configure(Ecore_X_Window win,
270                          Ecore_X_Window_Configure_Mask mask,
271                          int x,
272                          int y,
273                          int w,
274                          int h,
275                          int border_width,
276                          Ecore_X_Window sibling,
277                          int stack_mode)
278 {
279    XWindowChanges xwc;
280
281    if (!win)
282      return;
283
284    LOGFN(__FILE__, __LINE__, __FUNCTION__);
285
286    xwc.x = x;
287    xwc.y = y;
288    xwc.width = w;
289    xwc.height = h;
290    xwc.border_width = border_width;
291    xwc.sibling = sibling;
292    xwc.stack_mode = stack_mode;
293
294    XConfigureWindow(_ecore_x_disp, win, mask, &xwc);
295 }
296
297 /**
298  * @defgroup Ecore_X_Window_Destroy_Group X Window Destroy Functions
299  *
300  * Functions to destroy X windows.
301  */
302
303 /**
304  * Deletes the given window.
305  * @param   win The given window.
306  * @ingroup Ecore_X_Window_Destroy_Group
307  */
308 EAPI void
309 ecore_x_window_free(Ecore_X_Window win)
310 {
311    /* sorry sir, deleting the root window doesn't sound like
312     * a smart idea.
313     */
314    LOGFN(__FILE__, __LINE__, __FUNCTION__);
315    if (win)
316      XDestroyWindow(_ecore_x_disp, win);
317 }
318
319 /**
320  * Set if a window should be ignored.
321  * @param   win The given window.
322  * @param   ignore if to ignore
323  */
324 EAPI void
325 ecore_x_window_ignore_set(Ecore_X_Window win,
326                           int ignore)
327 {
328    int i, j, cnt;
329    Ecore_X_Window *t;
330
331    LOGFN(__FILE__, __LINE__, __FUNCTION__);
332    if (ignore)
333      {
334         if (ignore_list)
335           {
336              for (i = 0; i < ignore_num; i++)
337                {
338                   if (win == ignore_list[i])
339                     return;
340                }
341              t = realloc(ignore_list, (ignore_num + 1) * sizeof(Ecore_X_Window));
342              if (!t) return;
343              ignore_list = t;
344              ignore_list[ignore_num++] = win;
345           }
346         else
347           {
348              ignore_num = 0;
349              ignore_list = malloc(sizeof(Ecore_X_Window));
350              if (ignore_list)
351                ignore_list[ignore_num++] = win;
352           }
353      }
354    else
355      {
356         if (!ignore_list)
357           return;
358
359         for (cnt = ignore_num, i = 0, j = 0; i < cnt; i++)
360           {
361              if (win != ignore_list[i])
362                ignore_list[j++] = ignore_list[i];
363              else
364                ignore_num--;
365           }
366
367         if (ignore_num <= 0)
368           {
369              free(ignore_list);
370              ignore_list = NULL;
371              return;
372           }
373         t = realloc(ignore_list, ignore_num * sizeof(Ecore_X_Window));
374         if (t) ignore_list = t;
375      }
376 }
377
378 /**
379  * Get the ignore list
380  * @param   num number of windows in the list
381  * @return  list of windows to ignore
382  */
383 EAPI Ecore_X_Window *
384 ecore_x_window_ignore_list(int *num)
385 {
386    if (num)
387      *num = ignore_num;
388
389    return ignore_list;
390 }
391
392 /**
393  * Sends a delete request to the given window.
394  * @param   win The given window.
395  * @ingroup Ecore_X_Window_Destroy_Group
396  */
397 EAPI void
398 ecore_x_window_delete_request_send(Ecore_X_Window win)
399 {
400    XEvent xev;
401
402    /* sorry sir, deleting the root window doesn't sound like
403     * a smart idea.
404     */
405    if (!win)
406      return;
407
408    LOGFN(__FILE__, __LINE__, __FUNCTION__);
409    xev.xclient.type = ClientMessage;
410    xev.xclient.display = _ecore_x_disp;
411    xev.xclient.window = win;
412    xev.xclient.message_type = ECORE_X_ATOM_WM_PROTOCOLS;
413    xev.xclient.format = 32;
414    xev.xclient.data.l[0] = ECORE_X_ATOM_WM_DELETE_WINDOW;
415    xev.xclient.data.l[1] = CurrentTime;
416
417    XSendEvent(_ecore_x_disp, win, False, NoEventMask, &xev);
418 }
419
420 /**
421  * @defgroup Ecore_X_Window_Visibility_Group X Window Visibility Functions
422  *
423  * Functions to access and change the visibility of X windows.
424  */
425
426 /**
427  * Shows a window.
428  *
429  * Synonymous to "mapping" a window in X Window System terminology.
430  *
431  * @param   win The window to show.
432  * @ingroup Ecore_X_Window_Visibility
433  */
434 EAPI void
435 ecore_x_window_show(Ecore_X_Window win)
436 {
437    LOGFN(__FILE__, __LINE__, __FUNCTION__);
438    XMapWindow(_ecore_x_disp, win);
439 }
440
441 /**
442  * Hides a window.
443  *
444  * Synonymous to "unmapping" a window in X Window System terminology.
445  *
446  * @param   win The window to hide.
447  * @ingroup Ecore_X_Window_Visibility
448  */
449 EAPI void
450 ecore_x_window_hide(Ecore_X_Window win)
451 {
452    XEvent xev;
453    Window root;
454    int idum;
455    unsigned int uidum;
456
457    /* ICCCM: SEND unmap event... */
458    LOGFN(__FILE__, __LINE__, __FUNCTION__);
459    root = win;
460    if (ScreenCount(_ecore_x_disp) == 1)
461      root = DefaultRootWindow(_ecore_x_disp);
462    else
463      XGetGeometry(_ecore_x_disp,
464                   win,
465                   &root,
466                   &idum,
467                   &idum,
468                   &uidum,
469                   &uidum,
470                   &uidum,
471                   &uidum);
472
473    xev.xunmap.type = UnmapNotify;
474    xev.xunmap.serial = 0;
475    xev.xunmap.send_event = True;
476    xev.xunmap.display = _ecore_x_disp;
477    xev.xunmap.event = root;
478    xev.xunmap.window = win;
479    xev.xunmap.from_configure = False;
480    XSendEvent(_ecore_x_disp, xev.xunmap.event, False,
481               SubstructureRedirectMask | SubstructureNotifyMask, &xev);
482    XUnmapWindow(_ecore_x_disp, win);
483 }
484
485 /**
486  * @defgroup Ecore_X_Window_Geometry_Group X Window Geometry Functions
487  *
488  * Functions that change or retrieve the geometry of X windows.
489  */
490
491 /**
492  * Moves a window to the position @p x, @p y.
493  *
494  * The position is relative to the upper left hand corner of the
495  * parent window.
496  *
497  * @param   win The window to move.
498  * @param   x   X position.
499  * @param   y   Y position.
500  * @ingroup Ecore_X_Window_Geometry_Group
501  */
502 EAPI void
503 ecore_x_window_move(Ecore_X_Window win,
504                     int x,
505                     int y)
506 {
507    LOGFN(__FILE__, __LINE__, __FUNCTION__);
508    XMoveWindow(_ecore_x_disp, win, x, y);
509 }
510
511 /**
512  * Resizes a window.
513  * @param   win The window to resize.
514  * @param   w   New width of the window.
515  * @param   h   New height of the window.
516  * @ingroup Ecore_X_Window_Geometry_Group
517  */
518 EAPI void
519 ecore_x_window_resize(Ecore_X_Window win,
520                       int w,
521                       int h)
522 {
523    LOGFN(__FILE__, __LINE__, __FUNCTION__);
524    if (w < 1)
525      w = 1;
526
527    if (h < 1)
528      h = 1;
529
530    XResizeWindow(_ecore_x_disp, win, w, h);
531 }
532
533 /**
534  * Moves and resizes a window.
535  * @param   win The window to move and resize.
536  * @param   x   New X position of the window.
537  * @param   y   New Y position of the window.
538  * @param   w   New width of the window.
539  * @param   h   New height of the window.
540  * @ingroup Ecore_X_Window_Geometry_Group
541  */
542 EAPI void
543 ecore_x_window_move_resize(Ecore_X_Window win,
544                            int x,
545                            int y,
546                            int w,
547                            int h)
548 {
549    LOGFN(__FILE__, __LINE__, __FUNCTION__);
550    if (w < 1)
551      w = 1;
552
553    if (h < 1)
554      h = 1;
555
556    XMoveResizeWindow(_ecore_x_disp, win, x, y, w, h);
557 }
558
559 /**
560  * @defgroup Ecore_X_Window_Focus_Functions X Window Focus Functions
561  *
562  * Functions that give the focus to an X Window.
563  */
564
565 /**
566  * Sets the focus to the window @p win.
567  * @param   win The window to focus.
568  * @ingroup Ecore_X_Window_Focus_Functions
569  */
570 EAPI void
571 ecore_x_window_focus(Ecore_X_Window win)
572 {
573    LOGFN(__FILE__, __LINE__, __FUNCTION__);
574    if (win == 0)
575      win = DefaultRootWindow(_ecore_x_disp);  //   XSetInputFocus(_ecore_x_disp, win, RevertToNone, CurrentTime);
576
577 //   XSetInputFocus(_ecore_x_disp, win, RevertToPointerRoot, CurrentTime);
578    XSetInputFocus(_ecore_x_disp, win, RevertToParent, CurrentTime);
579 }
580
581 /**
582  * Sets the focus to the given window at a specific time.
583  * @param   win The window to focus.
584  * @param   t   When to set the focus to the window.
585  * @ingroup Ecore_X_Window_Focus_Functions
586  */
587 EAPI void
588 ecore_x_window_focus_at_time(Ecore_X_Window win,
589                              Ecore_X_Time t)
590 {
591    LOGFN(__FILE__, __LINE__, __FUNCTION__);
592    if (win == 0)
593      win = DefaultRootWindow(_ecore_x_disp);  //   XSetInputFocus(_ecore_x_disp, win, RevertToNone, t);
594
595 //   XSetInputFocus(_ecore_x_disp, win, PointerRoot, t);
596    XSetInputFocus(_ecore_x_disp, win, RevertToParent, t);
597 }
598
599 /**
600  * gets the window that has focus.
601  * @return  The window that has focus.
602  * @ingroup Ecore_X_Window_Focus_Functions
603  */
604 EAPI Ecore_X_Window
605 ecore_x_window_focus_get(void)
606 {
607    Window win;
608    int revert_mode;
609
610    LOGFN(__FILE__, __LINE__, __FUNCTION__);
611    win = 0;
612    XGetInputFocus(_ecore_x_disp, &win, &revert_mode);
613    return win;
614 }
615
616 /**
617  * @defgroup Ecore_X_Window_Z_Order_Group X Window Z Order Functions
618  *
619  * Functions that change the Z order of X windows.
620  */
621
622 /**
623  * Raises the given window.
624  * @param   win The window to raise.
625  * @ingroup Ecore_X_Window_Z_Order_Group
626  */
627 EAPI void
628 ecore_x_window_raise(Ecore_X_Window win)
629 {
630    LOGFN(__FILE__, __LINE__, __FUNCTION__);
631    XRaiseWindow(_ecore_x_disp, win);
632 }
633
634 /**
635  * Lowers the given window.
636  * @param   win The window to lower.
637  * @ingroup Ecore_X_Window_Z_Order_Group
638  */
639 EAPI void
640 ecore_x_window_lower(Ecore_X_Window win)
641 {
642    LOGFN(__FILE__, __LINE__, __FUNCTION__);
643    XLowerWindow(_ecore_x_disp, win);
644 }
645
646 /**
647  * @defgroup Ecore_X_Window_Parent_Group X Window Parent Functions
648  *
649  * Functions that retrieve or changes the parent window of a window.
650  */
651
652 /**
653  * Moves a window to within another window at a given position.
654  * @param   win        The window to reparent.
655  * @param   new_parent The new parent window.
656  * @param   x          X position within new parent window.
657  * @param   y          Y position within new parent window.
658  * @ingroup Ecore_X_Window_Parent_Group
659  */
660 EAPI void
661 ecore_x_window_reparent(Ecore_X_Window win,
662                         Ecore_X_Window new_parent,
663                         int x,
664                         int y)
665 {
666    LOGFN(__FILE__, __LINE__, __FUNCTION__);
667    if (new_parent == 0)
668      new_parent = DefaultRootWindow(_ecore_x_disp);
669
670    XReparentWindow(_ecore_x_disp, win, new_parent, x, y);
671 }
672
673 /**
674  * Retrieves the size of the given window.
675  * @param   win The given window.
676  * @param   w   Pointer to an integer into which the width is to be stored.
677  * @param   h   Pointer to an integer into which the height is to be stored.
678  * @ingroup Ecore_X_Window_Geometry_Group
679  */
680 EAPI void
681 ecore_x_window_size_get(Ecore_X_Window win,
682                         int *w,
683                         int *h)
684 {
685    int dummy_x, dummy_y;
686
687    LOGFN(__FILE__, __LINE__, __FUNCTION__);
688    if (win == 0)
689      win = DefaultRootWindow(_ecore_x_disp);
690
691    ecore_x_drawable_geometry_get(win, &dummy_x, &dummy_y, w, h);
692 }
693
694 /**
695  * Retrieves the geometry of the given window.
696  *
697  * Note that the x & y coordinates are relative to your parent.  In
698  * particular for reparenting window managers - relative to you window border.
699  * If you want screen coordinates either walk the window tree to the root,
700  * else for ecore_evas applications see ecore_evas_geometry_get().  Elementary
701  * applications can use elm_win_screen_position_get().
702  *
703  * @param   win The given window.
704  * @param   x   Pointer to an integer in which the X position is to be stored.
705  * @param   y   Pointer to an integer in which the Y position is to be stored.
706  * @param   w   Pointer to an integer in which the width is to be stored.
707  * @param   h   Pointer to an integer in which the height is to be stored.
708  * @ingroup Ecore_X_Window_Geometry_Group
709  */
710 EAPI void
711 ecore_x_window_geometry_get(Ecore_X_Window win,
712                             int *x,
713                             int *y,
714                             int *w,
715                             int *h)
716 {
717    LOGFN(__FILE__, __LINE__, __FUNCTION__);
718    if (!win)
719      win = DefaultRootWindow(_ecore_x_disp);
720
721    ecore_x_drawable_geometry_get(win, x, y, w, h);
722 }
723
724 /**
725  * Retrieves the width of the border of the given window.
726  * @param   win The given window.
727  * @return  Width of the border of @p win.
728  * @ingroup Ecore_X_Window_Geometry_Group
729  */
730 EAPI int
731 ecore_x_window_border_width_get(Ecore_X_Window win)
732 {
733    LOGFN(__FILE__, __LINE__, __FUNCTION__);
734    /* doesn't make sense to call this on a root window */
735    if (!win)
736      return 0;
737
738    return ecore_x_drawable_border_width_get(win);
739 }
740
741 /**
742  * Sets the width of the border of the given window.
743  * @param   win The given window.
744  * @param   width The new border width.
745  * @ingroup Ecore_X_Window_Geometry_Group
746  */
747 EAPI void
748 ecore_x_window_border_width_set(Ecore_X_Window win,
749                                 int width)
750 {
751    LOGFN(__FILE__, __LINE__, __FUNCTION__);
752    /* doesn't make sense to call this on a root window */
753    if (!win)
754      return;
755
756    XSetWindowBorderWidth (_ecore_x_disp, win, width);
757 }
758
759 /**
760  * Retrieves the depth of the given window.
761  * @param  win The given window.
762  * @return Depth of the window.
763  */
764 EAPI int
765 ecore_x_window_depth_get(Ecore_X_Window win)
766 {
767    LOGFN(__FILE__, __LINE__, __FUNCTION__);
768    return ecore_x_drawable_depth_get(win);
769 }
770
771 /**
772  * @brief Show the cursor on a window of type Ecore_X_Window.
773  * @param win The window for which the cursor will be showed.
774  * @param show Enables the show of the cursor on the window if equals EINA_TRUE, disables if equals EINA_FALSE.
775  */
776 EAPI void
777 ecore_x_window_cursor_show(Ecore_X_Window win,
778                            Eina_Bool show)
779 {
780    LOGFN(__FILE__, __LINE__, __FUNCTION__);
781    if (win == 0)
782      win = DefaultRootWindow(_ecore_x_disp);
783
784    if (!show)
785      {
786         Cursor c;
787         XColor cl;
788         Pixmap p, m;
789         GC gc;
790         XGCValues gcv;
791
792         p = XCreatePixmap(_ecore_x_disp, win, 1, 1, 1);
793         m = XCreatePixmap(_ecore_x_disp, win, 1, 1, 1);
794         gc = XCreateGC(_ecore_x_disp, m, 0, &gcv);
795         XSetForeground(_ecore_x_disp, gc, 0);
796         XDrawPoint(_ecore_x_disp, m, gc, 0, 0);
797         XFreeGC(_ecore_x_disp, gc);
798         c = XCreatePixmapCursor(_ecore_x_disp, p, m, &cl, &cl, 0, 0);
799         XDefineCursor(_ecore_x_disp, win, c);
800         XFreeCursor(_ecore_x_disp, c);
801         XFreePixmap(_ecore_x_disp, p);
802         XFreePixmap(_ecore_x_disp, m);
803      }
804    else
805      XDefineCursor(_ecore_x_disp, win, 0);
806 }
807
808 EAPI void
809 ecore_x_window_cursor_set(Ecore_X_Window win,
810                           Ecore_X_Cursor c)
811 {
812    LOGFN(__FILE__, __LINE__, __FUNCTION__);
813    if (c == 0)
814      XUndefineCursor(_ecore_x_disp, win);
815    else
816      XDefineCursor(_ecore_x_disp, win, c);
817 }
818
819 /**
820  * Finds out whether the given window is currently visible.
821  * @param   win The given window.
822  * @return  1 if the window is visible, otherwise 0.
823  * @ingroup Ecore_X_Window_Visibility_Group
824  */
825 EAPI int
826 ecore_x_window_visible_get(Ecore_X_Window win)
827 {
828    XWindowAttributes attr;
829
830    LOGFN(__FILE__, __LINE__, __FUNCTION__);
831    return XGetWindowAttributes(_ecore_x_disp, win, &attr) &&
832           (attr.map_state == IsViewable);
833 }
834
835 typedef struct _Shadow Shadow;
836 struct _Shadow
837 {
838    Shadow        *parent;
839    Shadow       **children;
840    Window         win;
841    int            children_num;
842    short          x, y;
843    unsigned short w, h;
844 };
845
846 static Shadow **shadow_base = NULL;
847 static int shadow_num = 0;
848
849 static Shadow *
850 _ecore_x_window_tree_walk(Window win)
851 {
852    Window *list = NULL;
853    Window parent_win = 0, root_win = 0;
854    unsigned int num;
855    Shadow *s, **sl;
856    XWindowAttributes att;
857
858    if (!XGetWindowAttributes(_ecore_x_disp, win, &att))
859      return NULL;  //   if (att.class == InputOnly) return NULL;
860
861    if (att.map_state != IsViewable)
862      return NULL;
863
864    s = calloc(1, sizeof(Shadow));
865    if (!s)
866      return NULL;
867
868    s->win = win;
869    s->x = att.x;
870    s->y = att.y;
871    s->w = att.width;
872    s->h = att.height;
873    if (XQueryTree(_ecore_x_disp, s->win, &root_win, &parent_win,
874                   &list, &num))
875      {
876         s->children = calloc(1, sizeof(Shadow *) * num);
877         if (s->children)
878           {
879              size_t i, j;
880              s->children_num = num;
881              for (i = 0; i < num; i++)
882                {
883                   s->children[i] = _ecore_x_window_tree_walk(list[i]);
884                   if (s->children[i])
885                     s->children[i]->parent = s;
886                }
887              /* compress list down */
888              j = 0;
889              for (i = 0; i < num; i++)
890                {
891                   if (s->children[i])
892                     {
893                        s->children[j] = s->children[i];
894                        j++;
895                     }
896                }
897              if (j == 0)
898                {
899                   free(s->children);
900                   s->children = NULL;
901                   s->children_num = 0;
902                }
903              else
904                {
905                   s->children_num = j;
906                   sl = realloc(s->children, sizeof(Shadow *) * j);
907                   if (sl)
908                     s->children = sl;
909                }
910           }
911      }
912
913    if (list)
914      XFree(list);
915
916    return s;
917 }
918
919 static void
920 _ecore_x_window_tree_shadow_free1(Shadow *s)
921 {
922    int i;
923
924    if (!s)
925      return;
926
927    if (s->children)
928      {
929         for (i = 0; i < s->children_num; i++)
930           {
931              if (s->children[i])
932                _ecore_x_window_tree_shadow_free1(s->children[i]);
933           }
934         free(s->children);
935      }
936
937    free(s);
938 }
939
940 static void
941 _ecore_x_window_tree_shadow_free(void)
942 {
943    int i;
944
945    if (!shadow_base)
946      return;
947
948    for (i = 0; i < shadow_num; i++)
949      {
950         if (!shadow_base[i])
951           continue;
952
953         _ecore_x_window_tree_shadow_free1(shadow_base[i]);
954      }
955    free(shadow_base);
956    shadow_base = NULL;
957    shadow_num = 0;
958 }
959
960 static void
961 _ecore_x_window_tree_shadow_populate(void)
962 {
963    Ecore_X_Window *roots;
964    int i, num;
965
966    roots = ecore_x_window_root_list(&num);
967    if (roots)
968      {
969         shadow_base = calloc(1, sizeof(Shadow *) * num);
970         if (shadow_base)
971           {
972              shadow_num = num;
973              for (i = 0; i < num; i++)
974                shadow_base[i] = _ecore_x_window_tree_walk(roots[i]);
975           }
976
977         free(roots);
978      }
979 }
980
981 /*
982    static int shadow_count = 0;
983
984    static void
985    _ecore_x_window_tree_shadow_start(void)
986    {
987    shadow_count++;
988    if (shadow_count > 1) return;
989    _ecore_x_window_tree_shadow_populate();
990    }
991
992    static void
993    _ecore_x_window_tree_shadow_stop(void)
994    {
995    shadow_count--;
996    if (shadow_count != 0) return;
997    _ecore_x_window_tree_shadow_free();
998    }
999  */
1000
1001 static Shadow *
1002 _ecore_x_window_shadow_tree_find_shadow(Shadow *s,
1003                                         Window win)
1004 {
1005    Shadow *ss;
1006    int i;
1007
1008    if (s->win == win)
1009      return s;
1010
1011    if (s->children)
1012      for (i = 0; i < s->children_num; i++)
1013        {
1014           if (!s->children[i])
1015             continue;
1016
1017           if ((ss =
1018                  _ecore_x_window_shadow_tree_find_shadow(s->children[i], win)))
1019             return ss;
1020        }
1021
1022    return NULL;
1023 }
1024
1025 static Shadow *
1026 _ecore_x_window_shadow_tree_find(Window base)
1027 {
1028    Shadow *s;
1029    int i;
1030
1031    for (i = 0; i < shadow_num; i++)
1032      {
1033         if (!shadow_base[i])
1034           continue;
1035
1036         if ((s = _ecore_x_window_shadow_tree_find_shadow(shadow_base[i], base)))
1037           return s;
1038      }
1039    return NULL;
1040 }
1041
1042 static int
1043 _inside_rects(Shadow *s,
1044               int x,
1045               int y,
1046               int bx,
1047               int by,
1048               Ecore_X_Rectangle *rects,
1049               int num)
1050 {
1051    int i, inside;
1052
1053    if (!rects) return 0;
1054    inside = 0;
1055    for (i = 0; i < num; i++)
1056      {
1057         if ((x >= s->x + bx + rects[i].x) &&
1058             (y >= s->y + by + rects[i].y) &&
1059             (x < (int)(s->x + bx + rects[i].x + rects[i].width)) &&
1060             (y < (int)(s->y + by + rects[i].y + rects[i].height)))
1061           {
1062              inside = 1;
1063              break;
1064           }
1065      }
1066    free(rects);
1067    return inside;
1068 }
1069
1070 static Window
1071 _ecore_x_window_shadow_tree_at_xy_get_shadow(Shadow *s,
1072                                              int bx,
1073                                              int by,
1074                                              int x,
1075                                              int y,
1076                                              Ecore_X_Window *skip,
1077                                              int skip_num)
1078 {
1079    Window child;
1080    int i, j;
1081    int wx, wy;
1082
1083    wx = s->x + bx;
1084    wy = s->y + by;
1085    if (!((x >= wx) && (y >= wy) && (x < (wx + s->w)) && (y < (wy + s->h))))
1086      return 0;
1087
1088    /* FIXME: get shape */
1089    {
1090       int num;
1091       Ecore_X_Rectangle *rects;
1092
1093       num = 0;
1094       rects = ecore_x_window_shape_rectangles_get(s->win, &num);
1095       if (!_inside_rects(s, x, y, bx, by, rects, num)) return 0;
1096       num = 0;
1097       rects = ecore_x_window_shape_input_rectangles_get(s->win, &num);
1098       if (!_inside_rects(s, x, y, bx, by, rects, num)) return 0;
1099    }
1100
1101    if (s->children)
1102      {
1103         int skipit = 0;
1104
1105         for (i = s->children_num - 1; i >= 0; --i)
1106           {
1107              if (!s->children[i])
1108                continue;
1109
1110              skipit = 0;
1111              if (skip)
1112                for (j = 0; j < skip_num; j++)
1113                  {
1114                     if (s->children[i]->win == skip[j])
1115                       {
1116                          skipit = 1;
1117                          goto onward;
1118                       }
1119                  }
1120
1121 onward:
1122              if (!skipit)
1123                if ((child =
1124                       _ecore_x_window_shadow_tree_at_xy_get_shadow(s->
1125                                                                    children[i
1126                                                                    ], wx, wy,
1127                                                                    x, y, skip,
1128                                                                    skip_num)))
1129                  return child;
1130           }
1131      }
1132
1133    return s->win;
1134 }
1135
1136 static Window
1137 _ecore_x_window_shadow_tree_at_xy_get(Window base,
1138                                       int bx,
1139                                       int by,
1140                                       int x,
1141                                       int y,
1142                                       Ecore_X_Window *skip,
1143                                       int skip_num)
1144 {
1145    Shadow *s;
1146
1147    if (!shadow_base)
1148      {
1149         _ecore_x_window_tree_shadow_populate();
1150         if (!shadow_base)
1151           return 0;
1152      }
1153
1154    s = _ecore_x_window_shadow_tree_find(base);
1155    if (!s)
1156      return 0;
1157
1158    return _ecore_x_window_shadow_tree_at_xy_get_shadow(s,
1159                                                        bx,
1160                                                        by,
1161                                                        x,
1162                                                        y,
1163                                                        skip,
1164                                                        skip_num);
1165 }
1166
1167 /**
1168  * Retrieves the top, visible window at the given location,
1169  * but skips the windows in the list. This uses a shadow tree built from the
1170  * window tree that is only updated the first time
1171  * ecore_x_window_shadow_tree_at_xy_with_skip_get() is called, or the next time
1172  * it is called after a  ecore_x_window_shadow_tree_flush()
1173  * @param   base The base window to start searching from (normally root).
1174  * @param   x The given X position.
1175  * @param   y The given Y position.
1176  * @param   skip The list of windows to be skipped.
1177  * @param   skip_num The number of windows to be skipped.
1178  * @return  The window at that position.
1179  * @ingroup Ecore_X_Window_Geometry_Group
1180  */
1181 EAPI Ecore_X_Window
1182 ecore_x_window_shadow_tree_at_xy_with_skip_get(Ecore_X_Window base,
1183                                                int x,
1184                                                int y,
1185                                                Ecore_X_Window *skip,
1186                                                int skip_num)
1187 {
1188    LOGFN(__FILE__, __LINE__, __FUNCTION__);
1189    return _ecore_x_window_shadow_tree_at_xy_get(base,
1190                                                 0,
1191                                                 0,
1192                                                 x,
1193                                                 y,
1194                                                 skip,
1195                                                 skip_num);
1196 }
1197
1198 /**
1199  * Retrieves the parent window a given window has. This uses the shadow window
1200  * tree.
1201  * @param   root The root window of @p win - if 0, this will be automatically determined with extra processing overhead
1202  * @param   win The window to get the parent window of
1203  * @return  The parent window of @p win
1204  * @ingroup Ecore_X_Window_Geometry_Group
1205  */
1206 EAPI Ecore_X_Window
1207 ecore_x_window_shadow_parent_get(Ecore_X_Window root __UNUSED__,
1208                                  Ecore_X_Window win)
1209 {
1210    Shadow *s;
1211    int i;
1212
1213    LOGFN(__FILE__, __LINE__, __FUNCTION__);
1214    if (!shadow_base)
1215      {
1216         _ecore_x_window_tree_shadow_populate();
1217         if (!shadow_base)
1218           return 0;
1219      }
1220
1221    for (i = 0; i < shadow_num; i++)
1222      {
1223         if (!shadow_base[i])
1224           continue;
1225
1226         s = _ecore_x_window_shadow_tree_find_shadow(shadow_base[i], win);
1227         if (s)
1228           {
1229              if (!s->parent)
1230                return 0;
1231
1232              return s->parent->win;
1233           }
1234      }
1235    return 0;
1236 }
1237
1238 /**
1239  * Flushes the window shadow tree so nothing is stored.
1240  * @ingroup Ecore_X_Window_Geometry_Group
1241  */
1242 EAPI void
1243 ecore_x_window_shadow_tree_flush(void)
1244 {
1245    LOGFN(__FILE__, __LINE__, __FUNCTION__);
1246    _ecore_x_window_tree_shadow_free();
1247 }
1248
1249 /**
1250  * Retrieves the root window a given window is on.
1251  * @param   win The window to get the root window of
1252  * @return  The root window of @p win
1253  * @ingroup Ecore_X_Window_Geometry_Group
1254  */
1255 EAPI Ecore_X_Window
1256 ecore_x_window_root_get(Ecore_X_Window win)
1257 {
1258    XWindowAttributes att;
1259
1260    LOGFN(__FILE__, __LINE__, __FUNCTION__);
1261    if (!XGetWindowAttributes(_ecore_x_disp, win, &att))
1262      return 0;
1263
1264    return att.root;
1265 }
1266
1267 static Window
1268 _ecore_x_window_at_xy_get(Window base,
1269                           int bx,
1270                           int by,
1271                           int x,
1272                           int y,
1273                           Ecore_X_Window *skip,
1274                           int skip_num)
1275 {
1276    Window *list = NULL;
1277    Window parent_win = 0, child = 0, root_win = 0;
1278    int i, j, wx, wy, ww, wh;
1279    unsigned int num;
1280
1281    LOGFN(__FILE__, __LINE__, __FUNCTION__);
1282    if (!ecore_x_window_visible_get(base))
1283      return 0;
1284
1285    LOGFN(__FILE__, __LINE__, __FUNCTION__);
1286    ecore_x_window_geometry_get(base, &wx, &wy, &ww, &wh);
1287    wx += bx;
1288    wy += by;
1289
1290    if (!((x >= wx) && (y >= wy) && (x < (wx + ww)) && (y < (wy + wh))))
1291      return 0;
1292
1293    LOGFN(__FILE__, __LINE__, __FUNCTION__);
1294    if (!XQueryTree(_ecore_x_disp, base, &root_win, &parent_win, &list, &num))
1295      return base;
1296
1297    if (list)
1298      {
1299         int skipit = 0;
1300
1301         for (i = num - 1; i >= 0; --i)
1302           {
1303              skipit = 0;
1304
1305              if (skip)
1306                for (j = 0; j < skip_num; j++)
1307                  {
1308                     if (list[i] == skip[j])
1309                       {
1310                          skipit = 1;
1311                          goto onward;
1312                       }
1313                  }
1314
1315 onward:
1316              if (!skipit)
1317                if ((child =
1318                       _ecore_x_window_at_xy_get(list[i], wx, wy, x, y, skip,
1319                                                 skip_num)))
1320                  {
1321                     XFree(list);
1322                     return child;
1323                  }
1324           }
1325         XFree(list);
1326      }
1327
1328    return base;
1329 }
1330
1331 /**
1332  * Retrieves the top, visible window at the given location.
1333  * @param   x The given X position.
1334  * @param   y The given Y position.
1335  * @return  The window at that position.
1336  * @ingroup Ecore_X_Window_Geometry_Group
1337  */
1338 EAPI Ecore_X_Window
1339 ecore_x_window_at_xy_get(int x,
1340                          int y)
1341 {
1342    Ecore_X_Window win, root;
1343
1344    LOGFN(__FILE__, __LINE__, __FUNCTION__);
1345    /* FIXME: Proper function to determine current root/virtual root
1346     * window missing here */
1347    root = DefaultRootWindow(_ecore_x_disp);
1348
1349    ecore_x_grab();
1350    win = _ecore_x_window_at_xy_get(root, 0, 0, x, y, NULL, 0);
1351    ecore_x_ungrab();
1352
1353    return win ? win : root;
1354 }
1355
1356 /**
1357  * Retrieves the top, visible window at the given location,
1358  * but skips the windows in the list.
1359  * @param   x The given X position.
1360  * @param   y The given Y position.
1361  * @param   skip The list of windows to be skipped.
1362  * @param   skip_num The number of windows to be skipped.
1363  * @return  The window at that position.
1364  * @ingroup Ecore_X_Window_Geometry_Group
1365  */
1366 EAPI Ecore_X_Window
1367 ecore_x_window_at_xy_with_skip_get(int x,
1368                                    int y,
1369                                    Ecore_X_Window *skip,
1370                                    int skip_num)
1371 {
1372    Ecore_X_Window win, root;
1373
1374    LOGFN(__FILE__, __LINE__, __FUNCTION__);
1375    /* FIXME: Proper function to determine current root/virtual root
1376     * window missing here */
1377    root = DefaultRootWindow(_ecore_x_disp);
1378
1379    ecore_x_grab();
1380    win = _ecore_x_window_at_xy_get(root, 0, 0, x, y, skip, skip_num);
1381    ecore_x_ungrab();
1382
1383    return win ? win : root;
1384 }
1385
1386 EAPI Ecore_X_Window
1387 ecore_x_window_at_xy_begin_get(Ecore_X_Window begin,
1388                                int x,
1389                                int y)
1390 {
1391    Ecore_X_Window win;
1392
1393    LOGFN(__FILE__, __LINE__, __FUNCTION__);
1394    ecore_x_grab();
1395    win = _ecore_x_window_at_xy_get(begin, 0, 0, x, y, NULL, 0);
1396    ecore_x_ungrab();
1397
1398    return win ? win : begin;
1399 }
1400
1401 /**
1402  * Retrieves the parent window of the given window.
1403  * @param   win The given window.
1404  * @return  The parent window of @p win.
1405  * @ingroup Ecore_X_Window_Parent_Group
1406  */
1407 EAPI Ecore_X_Window
1408 ecore_x_window_parent_get(Ecore_X_Window win)
1409 {
1410    Window root, parent, *children = NULL;
1411    unsigned int num;
1412
1413    LOGFN(__FILE__, __LINE__, __FUNCTION__);
1414    if (!XQueryTree(_ecore_x_disp, win, &root, &parent, &children, &num))
1415      return 0;
1416
1417    if (children)
1418      XFree(children);
1419
1420    return parent;
1421 }
1422
1423 /**
1424  * Sets the background color of the given window.
1425  * @param win   The given window
1426  * @param r     red value (0...65536, 16 bits)
1427  * @param g     green value (0...65536, 16 bits)
1428  * @param b     blue value (0...65536, 16 bits)
1429  */
1430 EAPI void
1431 ecore_x_window_background_color_set(Ecore_X_Window win,
1432                                     unsigned short r,
1433                                     unsigned short g,
1434                                     unsigned short b)
1435 {
1436    XSetWindowAttributes attr;
1437    Colormap map;
1438    XColor col;
1439
1440    LOGFN(__FILE__, __LINE__, __FUNCTION__);
1441    col.red = r;
1442    col.green = g;
1443    col.blue = b;
1444
1445    map = DefaultColormap(_ecore_x_disp, DefaultScreen(_ecore_x_disp));
1446    XAllocColor(_ecore_x_disp, map, &col);
1447
1448    attr.background_pixel = col.pixel;
1449    XChangeWindowAttributes(_ecore_x_disp, win, CWBackPixel, &attr);
1450 }
1451
1452 EAPI void
1453 ecore_x_window_gravity_set(Ecore_X_Window win,
1454                            Ecore_X_Gravity grav)
1455 {
1456    XSetWindowAttributes att;
1457
1458    LOGFN(__FILE__, __LINE__, __FUNCTION__);
1459    att.win_gravity = grav;
1460    XChangeWindowAttributes(_ecore_x_disp, win, CWWinGravity, &att);
1461 }
1462
1463 EAPI void
1464 ecore_x_window_pixel_gravity_set(Ecore_X_Window win,
1465                                  Ecore_X_Gravity grav)
1466 {
1467    XSetWindowAttributes att;
1468
1469    LOGFN(__FILE__, __LINE__, __FUNCTION__);
1470    att.bit_gravity = grav;
1471    XChangeWindowAttributes(_ecore_x_disp, win, CWBitGravity, &att);
1472 }
1473
1474 EAPI void
1475 ecore_x_window_pixmap_set(Ecore_X_Window win,
1476                           Ecore_X_Pixmap pmap)
1477 {
1478    LOGFN(__FILE__, __LINE__, __FUNCTION__);
1479    XSetWindowBackgroundPixmap(_ecore_x_disp, win, pmap);
1480 }
1481
1482 EAPI void
1483 ecore_x_window_area_clear(Ecore_X_Window win,
1484                           int x,
1485                           int y,
1486                           int w,
1487                           int h)
1488 {
1489    LOGFN(__FILE__, __LINE__, __FUNCTION__);
1490    XClearArea(_ecore_x_disp, win, x, y, w, h, False);
1491 }
1492
1493 EAPI void
1494 ecore_x_window_area_expose(Ecore_X_Window win,
1495                            int x,
1496                            int y,
1497                            int w,
1498                            int h)
1499 {
1500    LOGFN(__FILE__, __LINE__, __FUNCTION__);
1501    XClearArea(_ecore_x_disp, win, x, y, w, h, True);
1502 }
1503
1504 EAPI void
1505 ecore_x_window_override_set(Ecore_X_Window win,
1506                             Eina_Bool override)
1507 {
1508    XSetWindowAttributes att;
1509
1510    LOGFN(__FILE__, __LINE__, __FUNCTION__);
1511    att.override_redirect = override;
1512    XChangeWindowAttributes(_ecore_x_disp, win, CWOverrideRedirect, &att);
1513 }
1514
1515 #ifdef ECORE_XRENDER
1516 static Ecore_X_Window
1517 _ecore_x_window_argb_internal_new(Ecore_X_Window parent,
1518                                   int x,
1519                                   int y,
1520                                   int w,
1521                                   int h,
1522                                   Eina_Bool override,
1523                                   Eina_Bool saveunder)
1524 {
1525    Window win;
1526    XSetWindowAttributes attr;
1527    XWindowAttributes att;
1528    XVisualInfo *xvi;
1529    XVisualInfo vi_in;
1530    int nvi, i, scr = 0;
1531    XRenderPictFormat *fmt;
1532    Visual *vis;
1533
1534    if (parent == 0)
1535      {
1536         parent = DefaultRootWindow(_ecore_x_disp);
1537         scr = DefaultScreen(_ecore_x_disp);
1538      }
1539    else
1540      {
1541         /* ewww - round trip */
1542         XGetWindowAttributes(_ecore_x_disp, parent, &att);
1543         for (i = 0; i < ScreenCount(_ecore_x_disp); i++)
1544           {
1545              if (att.screen == ScreenOfDisplay(_ecore_x_disp, i))
1546                {
1547                   scr = i;
1548                   break;
1549                }
1550           }
1551      }
1552
1553    vi_in.screen = scr;
1554    vi_in.depth = 32;
1555    vi_in.class = TrueColor;
1556    xvi = XGetVisualInfo(_ecore_x_disp,
1557                         VisualScreenMask |
1558                         VisualDepthMask |
1559                         VisualClassMask,
1560                         &vi_in,
1561                         &nvi);
1562    if (!xvi)
1563      return 0;
1564
1565    vis = NULL;
1566    for (i = 0; i < nvi; i++)
1567      {
1568         fmt = XRenderFindVisualFormat(_ecore_x_disp, xvi[i].visual);
1569         if ((fmt->type == PictTypeDirect) && (fmt->direct.alphaMask))
1570           {
1571              vis = xvi[i].visual;
1572              break;
1573           }
1574      }
1575    XFree (xvi);
1576
1577    attr.backing_store = NotUseful;
1578    attr.override_redirect = override;
1579    attr.colormap = XCreateColormap(_ecore_x_disp, parent,
1580                                    vis, AllocNone);
1581    attr.border_pixel = 0;
1582    attr.background_pixmap = None;
1583    attr.bit_gravity = NorthWestGravity;
1584    attr.win_gravity = NorthWestGravity;
1585    attr.save_under = saveunder;
1586    attr.do_not_propagate_mask = NoEventMask;
1587    attr.event_mask = KeyPressMask |
1588      KeyReleaseMask |
1589      ButtonPressMask |
1590      ButtonReleaseMask |
1591      EnterWindowMask |
1592      LeaveWindowMask |
1593      PointerMotionMask |
1594      ExposureMask |
1595      VisibilityChangeMask |
1596      StructureNotifyMask |
1597      FocusChangeMask |
1598      PropertyChangeMask |
1599      ColormapChangeMask;
1600    win = XCreateWindow(_ecore_x_disp, parent,
1601                        x, y, w, h, 0,
1602                        32,
1603                        InputOutput,
1604                        vis,
1605                        CWBackingStore |
1606                        CWOverrideRedirect |
1607                        CWColormap |
1608                        CWBorderPixel |
1609                        CWBackPixmap |
1610                        CWSaveUnder |
1611                        CWDontPropagate |
1612                        CWEventMask |
1613                        CWBitGravity |
1614                        CWWinGravity,
1615                        &attr);
1616    XFreeColormap(_ecore_x_disp, attr.colormap);
1617
1618    if (parent == DefaultRootWindow(_ecore_x_disp))
1619      ecore_x_window_defaults_set(win);
1620
1621    return win;
1622 }
1623
1624 #endif /* ifdef ECORE_XRENDER */
1625
1626 EAPI int
1627 ecore_x_window_argb_get(Ecore_X_Window win)
1628 {
1629 #ifdef ECORE_XRENDER
1630    XWindowAttributes att;
1631    XRenderPictFormat *fmt;
1632
1633    att.visual = 0;
1634    if (!XGetWindowAttributes(_ecore_x_disp, win, &att))
1635      return 0;
1636
1637    fmt = XRenderFindVisualFormat(_ecore_x_disp, att.visual);
1638    if (!fmt)
1639      return 0;
1640
1641    if ((fmt->type == PictTypeDirect) && (fmt->direct.alphaMask))
1642      return 1;
1643
1644    return 0;
1645 #else /* ifdef ECORE_XRENDER */
1646    return 0;
1647 #endif /* ifdef ECORE_XRENDER */
1648 }
1649
1650 /**
1651  * Creates a new window.
1652  * @param   parent The parent window to use.  If @p parent is @c 0, the root
1653  *                 window of the default display is used.
1654  * @param   x      X position.
1655  * @param   y      Y position.
1656  * @param   w      Width.
1657  * @param   h      Height.
1658  * @return  The new window handle.
1659  * @ingroup Ecore_X_Window_Create_Group
1660  */
1661 EAPI Ecore_X_Window
1662 ecore_x_window_manager_argb_new(Ecore_X_Window parent,
1663                                 int x,
1664                                 int y,
1665                                 int w,
1666                                 int h)
1667 {
1668 #ifdef ECORE_XRENDER
1669    LOGFN(__FILE__, __LINE__, __FUNCTION__);
1670    return _ecore_x_window_argb_internal_new(parent, x, y, w, h, 1, 0);
1671 #else /* ifdef ECORE_XRENDER */
1672    return 0;
1673 #endif /* ifdef ECORE_XRENDER */
1674 }
1675
1676 /**
1677  * Creates a new window.
1678  * @param   parent The parent window to use.  If @p parent is @c 0, the root
1679  *                 window of the default display is used.
1680  * @param   x      X position.
1681  * @param   y      Y position.
1682  * @param   w      Width.
1683  * @param   h      Height.
1684  * @return  The new window handle.
1685  * @ingroup Ecore_X_Window_Create_Group
1686  */
1687 EAPI Ecore_X_Window
1688 ecore_x_window_argb_new(Ecore_X_Window parent,
1689                         int x,
1690                         int y,
1691                         int w,
1692                         int h)
1693 {
1694 #ifdef ECORE_XRENDER
1695    LOGFN(__FILE__, __LINE__, __FUNCTION__);
1696    return _ecore_x_window_argb_internal_new(parent, x, y, w, h, 0, 0);
1697 #else /* ifdef ECORE_XRENDER */
1698    return 0;
1699 #endif /* ifdef ECORE_XRENDER */
1700 }
1701
1702 /**
1703  * Creates a window with the override redirect attribute set to @c True.
1704  * @param   parent The parent window to use.  If @p parent is @c 0, the root
1705  *                 window of the default display is used.
1706  * @param   x      X position.
1707  * @param   y      Y position.
1708  * @param   w      Width.
1709  * @param   h      Height.
1710  * @return  The new window handle.
1711  * @ingroup Ecore_X_Window_Create_Group
1712  */
1713 EAPI Ecore_X_Window
1714 ecore_x_window_override_argb_new(Ecore_X_Window parent,
1715                                  int x,
1716                                  int y,
1717                                  int w,
1718                                  int h)
1719 {
1720 #ifdef ECORE_XRENDER
1721    LOGFN(__FILE__, __LINE__, __FUNCTION__);
1722    return _ecore_x_window_argb_internal_new(parent, x, y, w, h, 1, 0);
1723 #else /* ifdef ECORE_XRENDER */
1724    return 0;
1725 #endif /* ifdef ECORE_XRENDER */
1726 }
1727