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