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