3 #endif /* ifdef HAVE_CONFIG_H */
10 #include "ecore_x_private.h"
12 #include "Ecore_X_Atoms.h"
14 static int ignore_num = 0;
15 static Ecore_X_Window *ignore_list = NULL;
18 * @defgroup Ecore_X_Window_Create_Group X Window Creation Functions
19 * @ingroup Ecore_X_Group
21 * Functions that can be used to create an X window.
25 ecore_x_window_full_new(Ecore_X_Window parent,
30 Ecore_X_Visual *visual,
31 Ecore_X_Colormap colormap,
36 XSetWindowAttributes attr;
38 LOGFN(__FILE__, __LINE__, __FUNCTION__);
40 parent = DefaultRootWindow(_ecore_x_disp);
42 attr.backing_store = NotUseful;
43 attr.override_redirect = override;
44 attr.border_pixel = 0;
45 attr.background_pixmap = None;
46 attr.bit_gravity = NorthWestGravity;
47 attr.win_gravity = NorthWestGravity;
48 attr.save_under = False;
49 attr.do_not_propagate_mask = NoEventMask;
50 attr.colormap = (Colormap)colormap;
51 attr.event_mask = KeyPressMask |
59 VisibilityChangeMask |
64 win = XCreateWindow(_ecore_x_disp, parent,
71 (colormap ? CWColormap : 0) |
80 if (_ecore_xlib_sync) ecore_x_sync();
81 if (parent == DefaultRootWindow(_ecore_x_disp))
82 ecore_x_window_defaults_set(win);
88 * Creates a new window.
89 * @param parent The parent window to use. If @p parent is @c 0, the root
90 * window of the default display is used.
91 * @param x X position.
92 * @param y Y position.
95 * @return The new window handle.
96 * @ingroup Ecore_X_Window_Create_Group
99 ecore_x_window_new(Ecore_X_Window parent,
106 XSetWindowAttributes attr;
108 LOGFN(__FILE__, __LINE__, __FUNCTION__);
110 parent = DefaultRootWindow(_ecore_x_disp);
112 attr.backing_store = NotUseful;
113 attr.override_redirect = False;
114 attr.border_pixel = 0;
115 attr.background_pixmap = None;
116 attr.bit_gravity = NorthWestGravity;
117 attr.win_gravity = NorthWestGravity;
118 attr.save_under = False;
119 attr.do_not_propagate_mask = NoEventMask;
120 attr.event_mask = KeyPressMask |
128 VisibilityChangeMask |
129 StructureNotifyMask |
133 win = XCreateWindow(_ecore_x_disp, parent,
135 CopyFromParent, /*DefaultDepth(_ecore_x_disp, DefaultScreen(_ecore_x_disp)),*/
137 CopyFromParent, /*DefaultVisual(_ecore_x_disp, DefaultScreen(_ecore_x_disp)),*/
149 if (_ecore_xlib_sync) ecore_x_sync();
150 if (parent == DefaultRootWindow(_ecore_x_disp))
151 ecore_x_window_defaults_set(win);
157 * Creates a window with the override redirect attribute set to @c True.
158 * @param parent The parent window to use. If @p parent is @c 0, the root
159 * window of the default display is used.
160 * @param x X position.
161 * @param y Y position.
164 * @return The new window handle.
165 * @ingroup Ecore_X_Window_Create_Group
168 ecore_x_window_override_new(Ecore_X_Window parent,
175 XSetWindowAttributes attr;
177 LOGFN(__FILE__, __LINE__, __FUNCTION__);
179 parent = DefaultRootWindow(_ecore_x_disp);
181 attr.backing_store = NotUseful;
182 attr.override_redirect = True;
183 attr.border_pixel = 0;
184 attr.background_pixmap = None;
185 attr.bit_gravity = NorthWestGravity;
186 attr.win_gravity = NorthWestGravity;
187 attr.save_under = False;
188 attr.do_not_propagate_mask = NoEventMask;
189 attr.event_mask = KeyPressMask |
197 VisibilityChangeMask |
198 StructureNotifyMask |
202 win = XCreateWindow(_ecore_x_disp, parent,
204 CopyFromParent, /*DefaultDepth(_ecore_x_disp, DefaultScreen(_ecore_x_disp)),*/
206 CopyFromParent, /*DefaultVisual(_ecore_x_disp, DefaultScreen(_ecore_x_disp)),*/
218 if (_ecore_xlib_sync) ecore_x_sync();
223 * Creates a new input window.
224 * @param parent The parent window to use. If @p parent is @c 0, the root
225 * window of the default display is used.
226 * @param x X position.
227 * @param y Y position.
230 * @return The new window.
231 * @ingroup Ecore_X_Window_Create_Group
234 ecore_x_window_input_new(Ecore_X_Window parent,
241 XSetWindowAttributes attr;
243 LOGFN(__FILE__, __LINE__, __FUNCTION__);
245 parent = DefaultRootWindow(_ecore_x_disp);
247 attr.override_redirect = True;
248 attr.do_not_propagate_mask = NoEventMask;
249 attr.event_mask = KeyPressMask |
257 VisibilityChangeMask |
258 StructureNotifyMask |
262 win = XCreateWindow(_ecore_x_disp, parent,
266 CopyFromParent, /*DefaultVisual(_ecore_x_disp, DefaultScreen(_ecore_x_disp)),*/
271 if (_ecore_xlib_sync) ecore_x_sync();
272 if (parent == DefaultRootWindow(_ecore_x_disp))
280 * @defgroup Ecore_X_Window_Properties_Group X Window Property Functions
281 * @ingroup Ecore_X_Group
283 * Functions that set window properties.
287 * Sets the default properties for the given window.
289 * The default properties set for the window are @c WM_CLIENT_MACHINE and
292 * @param win The given window.
293 * @ingroup Ecore_X_Window_Properties_Group
296 ecore_x_window_defaults_set(Ecore_X_Window win)
299 char buf[MAXHOSTNAMELEN];
305 LOGFN(__FILE__, __LINE__, __FUNCTION__);
307 * Set WM_CLIENT_MACHINE.
309 gethostname(buf, MAXHOSTNAMELEN);
310 buf[MAXHOSTNAMELEN - 1] = '\0';
312 /* The ecore function uses UTF8 which Xlib may not like (especially
313 * with older clients) */
314 /* ecore_x_window_prop_string_set(win, ECORE_X_ATOM_WM_CLIENT_MACHINE,
316 if (XStringListToTextProperty(hostname, 1, &xprop))
318 XSetWMClientMachine(_ecore_x_disp, win, &xprop);
320 if (_ecore_xlib_sync) ecore_x_sync();
322 if (_ecore_xlib_sync) ecore_x_sync();
327 ecore_x_netwm_pid_set(win, pid);
329 ecore_x_netwm_window_type_set(win, ECORE_X_WINDOW_TYPE_NORMAL);
331 ecore_app_args_get(&argc, &argv);
332 ecore_x_icccm_command_set(win, argc, argv);
336 ecore_x_window_configure(Ecore_X_Window win,
337 Ecore_X_Window_Configure_Mask mask,
343 Ecore_X_Window sibling,
351 LOGFN(__FILE__, __LINE__, __FUNCTION__);
357 xwc.border_width = border_width;
358 xwc.sibling = sibling;
359 xwc.stack_mode = stack_mode;
361 XConfigureWindow(_ecore_x_disp, win, mask, &xwc);
362 if (_ecore_xlib_sync) ecore_x_sync();
366 * @defgroup Ecore_X_Window_Destroy_Group X Window Destroy Functions
367 * @ingroup Ecore_X_Group
369 * Functions to destroy X windows.
373 * Deletes the given window.
374 * @param win The given window.
375 * @ingroup Ecore_X_Window_Destroy_Group
378 ecore_x_window_free(Ecore_X_Window win)
380 /* sorry sir, deleting the root window doesn't sound like
383 LOGFN(__FILE__, __LINE__, __FUNCTION__);
385 XDestroyWindow(_ecore_x_disp, win);
386 if (_ecore_xlib_sync) ecore_x_sync();
390 * Set if a window should be ignored.
391 * @param win The given window.
392 * @param ignore if to ignore
395 ecore_x_window_ignore_set(Ecore_X_Window win,
401 LOGFN(__FILE__, __LINE__, __FUNCTION__);
406 for (i = 0; i < ignore_num; i++)
408 if (win == ignore_list[i])
411 t = realloc(ignore_list, (ignore_num + 1) * sizeof(Ecore_X_Window));
414 ignore_list[ignore_num++] = win;
419 ignore_list = malloc(sizeof(Ecore_X_Window));
421 ignore_list[ignore_num++] = win;
429 for (cnt = ignore_num, i = 0, j = 0; i < cnt; i++)
431 if (win != ignore_list[i])
432 ignore_list[j++] = ignore_list[i];
443 t = realloc(ignore_list, ignore_num * sizeof(Ecore_X_Window));
444 if (t) ignore_list = t;
449 * Get the ignore list
450 * @param num number of windows in the list
451 * @return list of windows to ignore
453 EAPI Ecore_X_Window *
454 ecore_x_window_ignore_list(int *num)
463 * Sends a delete request to the given window.
464 * @param win The given window.
465 * @ingroup Ecore_X_Window_Destroy_Group
468 ecore_x_window_delete_request_send(Ecore_X_Window win)
472 /* sorry sir, deleting the root window doesn't sound like
478 LOGFN(__FILE__, __LINE__, __FUNCTION__);
479 xev.xclient.type = ClientMessage;
480 xev.xclient.display = _ecore_x_disp;
481 xev.xclient.window = win;
482 xev.xclient.message_type = ECORE_X_ATOM_WM_PROTOCOLS;
483 xev.xclient.format = 32;
484 xev.xclient.data.l[0] = ECORE_X_ATOM_WM_DELETE_WINDOW;
485 xev.xclient.data.l[1] = CurrentTime;
487 XSendEvent(_ecore_x_disp, win, False, NoEventMask, &xev);
488 if (_ecore_xlib_sync) ecore_x_sync();
492 * @defgroup Ecore_X_Window_Visibility_Group X Window Visibility Functions
493 * @ingroup Ecore_X_Group
495 * Functions to access and change the visibility of X windows.
501 * Synonymous to "mapping" a window in X Window System terminology.
503 * @param win The window to show.
504 * @ingroup Ecore_X_Window_Visibility
507 ecore_x_window_show(Ecore_X_Window win)
509 LOGFN(__FILE__, __LINE__, __FUNCTION__);
510 XMapWindow(_ecore_x_disp, win);
511 if (_ecore_xlib_sync) ecore_x_sync();
517 * Synonymous to "unmapping" a window in X Window System terminology.
519 * @param win The window to hide.
520 * @ingroup Ecore_X_Window_Visibility
523 ecore_x_window_hide(Ecore_X_Window win)
530 /* ICCCM: SEND unmap event... */
531 LOGFN(__FILE__, __LINE__, __FUNCTION__);
533 if (ScreenCount(_ecore_x_disp) == 1)
534 root = DefaultRootWindow(_ecore_x_disp);
536 XGetGeometry(_ecore_x_disp,
546 XUnmapWindow(_ecore_x_disp, win);
547 xev.xunmap.type = UnmapNotify;
548 xev.xunmap.serial = 0;
549 xev.xunmap.send_event = True;
550 xev.xunmap.display = _ecore_x_disp;
551 xev.xunmap.event = root;
552 xev.xunmap.window = win;
553 xev.xunmap.from_configure = False;
554 XSendEvent(_ecore_x_disp, xev.xunmap.event, False,
555 SubstructureRedirectMask | SubstructureNotifyMask, &xev);
556 if (_ecore_xlib_sync) ecore_x_sync();
560 * @defgroup Ecore_X_Window_Geometry_Group X Window Geometry Functions
561 * @ingroup Ecore_X_Group
563 * Functions that change or retrieve the geometry of X windows.
567 * Moves a window to the position @p x, @p y.
569 * The position is relative to the upper left hand corner of the
572 * @param win The window to move.
573 * @param x X position.
574 * @param y Y position.
575 * @ingroup Ecore_X_Window_Geometry_Group
578 ecore_x_window_move(Ecore_X_Window win,
582 LOGFN(__FILE__, __LINE__, __FUNCTION__);
583 XMoveWindow(_ecore_x_disp, win, x, y);
584 if (_ecore_xlib_sync) ecore_x_sync();
589 * @param win The window to resize.
590 * @param w New width of the window.
591 * @param h New height of the window.
592 * @ingroup Ecore_X_Window_Geometry_Group
595 ecore_x_window_resize(Ecore_X_Window win,
599 LOGFN(__FILE__, __LINE__, __FUNCTION__);
606 XResizeWindow(_ecore_x_disp, win, w, h);
607 if (_ecore_xlib_sync) ecore_x_sync();
611 * Moves and resizes a window.
612 * @param win The window to move and resize.
613 * @param x New X position of the window.
614 * @param y New Y position of the window.
615 * @param w New width of the window.
616 * @param h New height of the window.
617 * @ingroup Ecore_X_Window_Geometry_Group
620 ecore_x_window_move_resize(Ecore_X_Window win,
626 LOGFN(__FILE__, __LINE__, __FUNCTION__);
633 XMoveResizeWindow(_ecore_x_disp, win, x, y, w, h);
634 if (_ecore_xlib_sync) ecore_x_sync();
638 * @defgroup Ecore_X_Window_Focus_Functions X Window Focus Functions
639 * @ingroup Ecore_X_Group
641 * Functions that give the focus to an X Window.
645 * Sets the focus to the window @p win.
646 * @param win The window to focus.
647 * @ingroup Ecore_X_Window_Focus_Functions
650 ecore_x_window_focus(Ecore_X_Window win)
652 LOGFN(__FILE__, __LINE__, __FUNCTION__);
654 win = DefaultRootWindow(_ecore_x_disp); // XSetInputFocus(_ecore_x_disp, win, RevertToNone, CurrentTime);
656 // XSetInputFocus(_ecore_x_disp, win, RevertToPointerRoot, CurrentTime);
657 XSetInputFocus(_ecore_x_disp, win, RevertToParent, CurrentTime);
658 if (_ecore_xlib_sync) ecore_x_sync();
662 * Sets the focus to the given window at a specific time.
663 * @param win The window to focus.
664 * @param t When to set the focus to the window.
665 * @ingroup Ecore_X_Window_Focus_Functions
668 ecore_x_window_focus_at_time(Ecore_X_Window win,
671 LOGFN(__FILE__, __LINE__, __FUNCTION__);
673 win = DefaultRootWindow(_ecore_x_disp); // XSetInputFocus(_ecore_x_disp, win, RevertToNone, t);
675 // XSetInputFocus(_ecore_x_disp, win, PointerRoot, t);
676 XSetInputFocus(_ecore_x_disp, win, RevertToParent, t);
677 if (_ecore_xlib_sync) ecore_x_sync();
681 * gets the window that has focus.
682 * @return The window that has focus.
683 * @ingroup Ecore_X_Window_Focus_Functions
686 ecore_x_window_focus_get(void)
691 LOGFN(__FILE__, __LINE__, __FUNCTION__);
693 XGetInputFocus(_ecore_x_disp, &win, &revert_mode);
698 * @defgroup Ecore_X_Window_Z_Order_Group X Window Z Order Functions
699 * @ingroup Ecore_X_Group
701 * Functions that change the Z order of X windows.
705 * Raises the given window.
706 * @param win The window to raise.
707 * @ingroup Ecore_X_Window_Z_Order_Group
710 ecore_x_window_raise(Ecore_X_Window win)
712 LOGFN(__FILE__, __LINE__, __FUNCTION__);
713 XRaiseWindow(_ecore_x_disp, win);
714 if (_ecore_xlib_sync) ecore_x_sync();
718 * Lowers the given window.
719 * @param win The window to lower.
720 * @ingroup Ecore_X_Window_Z_Order_Group
723 ecore_x_window_lower(Ecore_X_Window win)
725 LOGFN(__FILE__, __LINE__, __FUNCTION__);
726 XLowerWindow(_ecore_x_disp, win);
727 if (_ecore_xlib_sync) ecore_x_sync();
731 * @defgroup Ecore_X_Window_Parent_Group X Window Parent Functions
732 * @ingroup Ecore_X_Group
734 * Functions that retrieve or changes the parent window of a window.
738 * Moves a window to within another window at a given position.
739 * @param win The window to reparent.
740 * @param new_parent The new parent window.
741 * @param x X position within new parent window.
742 * @param y Y position within new parent window.
743 * @ingroup Ecore_X_Window_Parent_Group
746 ecore_x_window_reparent(Ecore_X_Window win,
747 Ecore_X_Window new_parent,
751 LOGFN(__FILE__, __LINE__, __FUNCTION__);
753 new_parent = DefaultRootWindow(_ecore_x_disp);
755 XReparentWindow(_ecore_x_disp, win, new_parent, x, y);
756 if (_ecore_xlib_sync) ecore_x_sync();
760 * Retrieves the size of the given window.
761 * @param win The given window.
762 * @param w Pointer to an integer into which the width is to be stored.
763 * @param h Pointer to an integer into which the height is to be stored.
764 * @ingroup Ecore_X_Window_Geometry_Group
767 ecore_x_window_size_get(Ecore_X_Window win,
771 int dummy_x, dummy_y;
773 LOGFN(__FILE__, __LINE__, __FUNCTION__);
775 win = DefaultRootWindow(_ecore_x_disp);
777 ecore_x_drawable_geometry_get(win, &dummy_x, &dummy_y, w, h);
778 if (_ecore_xlib_sync) ecore_x_sync();
782 * Retrieves the geometry of the given window.
784 * Note that the x & y coordinates are relative to your parent. In
785 * particular for reparenting window managers - relative to you window border.
786 * If you want screen coordinates either walk the window tree to the root,
787 * else for ecore_evas applications see ecore_evas_geometry_get(). Elementary
788 * applications can use elm_win_screen_position_get().
790 * @param win The given window.
791 * @param x Pointer to an integer in which the X position is to be stored.
792 * @param y Pointer to an integer in which the Y position is to be stored.
793 * @param w Pointer to an integer in which the width is to be stored.
794 * @param h Pointer to an integer in which the height is to be stored.
795 * @ingroup Ecore_X_Window_Geometry_Group
798 ecore_x_window_geometry_get(Ecore_X_Window win,
804 LOGFN(__FILE__, __LINE__, __FUNCTION__);
806 win = DefaultRootWindow(_ecore_x_disp);
808 ecore_x_drawable_geometry_get(win, x, y, w, h);
809 if (_ecore_xlib_sync) ecore_x_sync();
813 * Retrieves the width of the border of the given window.
814 * @param win The given window.
815 * @return Width of the border of @p win.
816 * @ingroup Ecore_X_Window_Geometry_Group
819 ecore_x_window_border_width_get(Ecore_X_Window win)
822 LOGFN(__FILE__, __LINE__, __FUNCTION__);
823 /* doesn't make sense to call this on a root window */
827 w = ecore_x_drawable_border_width_get(win);
828 if (_ecore_xlib_sync) ecore_x_sync();
833 * Sets the width of the border of the given window.
834 * @param win The given window.
835 * @param width The new border width.
836 * @ingroup Ecore_X_Window_Geometry_Group
839 ecore_x_window_border_width_set(Ecore_X_Window win,
842 LOGFN(__FILE__, __LINE__, __FUNCTION__);
843 /* doesn't make sense to call this on a root window */
847 XSetWindowBorderWidth (_ecore_x_disp, win, width);
848 if (_ecore_xlib_sync) ecore_x_sync();
852 * Retrieves the depth of the given window.
853 * @param win The given window.
854 * @return Depth of the window.
857 ecore_x_window_depth_get(Ecore_X_Window win)
860 LOGFN(__FILE__, __LINE__, __FUNCTION__);
861 d = ecore_x_drawable_depth_get(win);
862 if (_ecore_xlib_sync) ecore_x_sync();
867 * @brief Show the cursor on a window of type Ecore_X_Window.
868 * @param win The window for which the cursor will be showed.
869 * @param show Enables the show of the cursor on the window if equals EINA_TRUE, disables if equals EINA_FALSE.
872 ecore_x_window_cursor_show(Ecore_X_Window win,
875 LOGFN(__FILE__, __LINE__, __FUNCTION__);
877 win = DefaultRootWindow(_ecore_x_disp);
887 p = XCreatePixmap(_ecore_x_disp, win, 1, 1, 1);
888 if (_ecore_xlib_sync) ecore_x_sync();
889 m = XCreatePixmap(_ecore_x_disp, win, 1, 1, 1);
890 if (_ecore_xlib_sync) ecore_x_sync();
891 gc = XCreateGC(_ecore_x_disp, m, 0, &gcv);
892 if (_ecore_xlib_sync) ecore_x_sync();
893 XSetForeground(_ecore_x_disp, gc, 0);
894 if (_ecore_xlib_sync) ecore_x_sync();
895 XDrawPoint(_ecore_x_disp, m, gc, 0, 0);
896 if (_ecore_xlib_sync) ecore_x_sync();
897 XFreeGC(_ecore_x_disp, gc);
898 c = XCreatePixmapCursor(_ecore_x_disp, p, m, &cl, &cl, 0, 0);
899 if (_ecore_xlib_sync) ecore_x_sync();
900 XDefineCursor(_ecore_x_disp, win, c);
901 XFreeCursor(_ecore_x_disp, c);
902 XFreePixmap(_ecore_x_disp, p);
903 XFreePixmap(_ecore_x_disp, m);
906 XDefineCursor(_ecore_x_disp, win, 0);
907 if (_ecore_xlib_sync) ecore_x_sync();
911 ecore_x_window_cursor_set(Ecore_X_Window win,
918 LOGFN(__FILE__, __LINE__, __FUNCTION__);
920 XIGetClientPointer(_ecore_x_disp, None, &devid);
922 XIUndefineCursor(_ecore_x_disp, devid, win);
924 XIDefineCursor(_ecore_x_disp, devid, win, c);
927 XUndefineCursor(_ecore_x_disp, win);
929 XDefineCursor(_ecore_x_disp, win, c);
931 if (_ecore_xlib_sync) ecore_x_sync();
935 * Finds out whether the given window is currently visible.
936 * @param win The given window.
937 * @return 1 if the window is visible, otherwise 0.
938 * @ingroup Ecore_X_Window_Visibility_Group
941 ecore_x_window_visible_get(Ecore_X_Window win)
944 XWindowAttributes attr;
946 LOGFN(__FILE__, __LINE__, __FUNCTION__);
947 ret = (XGetWindowAttributes(_ecore_x_disp, win, &attr) &&
948 (attr.map_state == IsViewable));
949 if (_ecore_xlib_sync) ecore_x_sync();
953 typedef struct _Shadow Shadow;
964 static Shadow **shadow_base = NULL;
965 static int shadow_num = 0;
968 _ecore_x_window_tree_walk(Window win)
971 Window parent_win = 0, root_win = 0;
974 XWindowAttributes att;
977 ret = (XGetWindowAttributes(_ecore_x_disp, win, &att) && (att.map_state == IsViewable));
978 if (_ecore_xlib_sync) ecore_x_sync();
979 if (!ret) return NULL; // if (att.class == InputOnly) return NULL;
981 s = calloc(1, sizeof(Shadow));
990 if (XQueryTree(_ecore_x_disp, s->win, &root_win, &parent_win,
993 if (_ecore_xlib_sync) ecore_x_sync();
994 s->children = calloc(1, sizeof(Shadow *) * num);
998 s->children_num = num;
999 for (i = 0; i < num; i++)
1001 s->children[i] = _ecore_x_window_tree_walk(list[i]);
1003 s->children[i]->parent = s;
1005 /* compress list down */
1007 for (i = 0; i < num; i++)
1011 s->children[j] = s->children[i];
1019 s->children_num = 0;
1023 s->children_num = j;
1024 sl = realloc(s->children, sizeof(Shadow *) * j);
1038 _ecore_x_window_tree_shadow_free1(Shadow *s)
1047 for (i = 0; i < s->children_num; i++)
1050 _ecore_x_window_tree_shadow_free1(s->children[i]);
1059 _ecore_x_window_tree_shadow_free(void)
1066 for (i = 0; i < shadow_num; i++)
1068 if (!shadow_base[i])
1071 _ecore_x_window_tree_shadow_free1(shadow_base[i]);
1079 _ecore_x_window_tree_shadow_populate(void)
1081 Ecore_X_Window *roots;
1084 roots = ecore_x_window_root_list(&num);
1087 shadow_base = calloc(1, sizeof(Shadow *) * num);
1091 for (i = 0; i < num; i++)
1092 shadow_base[i] = _ecore_x_window_tree_walk(roots[i]);
1100 static int shadow_count = 0;
1103 _ecore_x_window_tree_shadow_start(void)
1106 if (shadow_count > 1) return;
1107 _ecore_x_window_tree_shadow_populate();
1111 _ecore_x_window_tree_shadow_stop(void)
1114 if (shadow_count != 0) return;
1115 _ecore_x_window_tree_shadow_free();
1120 _ecore_x_window_shadow_tree_find_shadow(Shadow *s,
1130 for (i = 0; i < s->children_num; i++)
1132 if (!s->children[i])
1136 _ecore_x_window_shadow_tree_find_shadow(s->children[i], win)))
1144 _ecore_x_window_shadow_tree_find(Window base)
1149 for (i = 0; i < shadow_num; i++)
1151 if (!shadow_base[i])
1154 if ((s = _ecore_x_window_shadow_tree_find_shadow(shadow_base[i], base)))
1161 _inside_rects(Shadow *s,
1166 Ecore_X_Rectangle *rects,
1171 if (!rects) return 0;
1173 for (i = 0; i < num; i++)
1175 if ((x >= s->x + bx + rects[i].x) &&
1176 (y >= s->y + by + rects[i].y) &&
1177 (x < (int)(s->x + bx + rects[i].x + rects[i].width)) &&
1178 (y < (int)(s->y + by + rects[i].y + rects[i].height)))
1189 _ecore_x_window_shadow_tree_at_xy_get_shadow(Shadow *s,
1194 Ecore_X_Window *skip,
1203 if (!((x >= wx) && (y >= wy) && (x < (wx + s->w)) && (y < (wy + s->h))))
1206 /* FIXME: get shape */
1209 Ecore_X_Rectangle *rects;
1212 rects = ecore_x_window_shape_rectangles_get(s->win, &num);
1213 if (!_inside_rects(s, x, y, bx, by, rects, num)) return 0;
1215 rects = ecore_x_window_shape_input_rectangles_get(s->win, &num);
1216 if (!_inside_rects(s, x, y, bx, by, rects, num)) return 0;
1223 for (i = s->children_num - 1; i >= 0; --i)
1225 if (!s->children[i])
1230 for (j = 0; j < skip_num; j++)
1232 if (s->children[i]->win == skip[j])
1242 _ecore_x_window_shadow_tree_at_xy_get_shadow(s->
1255 _ecore_x_window_shadow_tree_at_xy_get(Window base,
1260 Ecore_X_Window *skip,
1267 _ecore_x_window_tree_shadow_populate();
1272 s = _ecore_x_window_shadow_tree_find(base);
1276 return _ecore_x_window_shadow_tree_at_xy_get_shadow(s,
1286 * Retrieves the top, visible window at the given location,
1287 * but skips the windows in the list. This uses a shadow tree built from the
1288 * window tree that is only updated the first time
1289 * ecore_x_window_shadow_tree_at_xy_with_skip_get() is called, or the next time
1290 * it is called after a ecore_x_window_shadow_tree_flush()
1291 * @param base The base window to start searching from (normally root).
1292 * @param x The given X position.
1293 * @param y The given Y position.
1294 * @param skip The list of windows to be skipped.
1295 * @param skip_num The number of windows to be skipped.
1296 * @return The window at that position.
1297 * @ingroup Ecore_X_Window_Geometry_Group
1300 ecore_x_window_shadow_tree_at_xy_with_skip_get(Ecore_X_Window base,
1303 Ecore_X_Window *skip,
1306 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1307 return _ecore_x_window_shadow_tree_at_xy_get(base,
1317 * Retrieves the parent window a given window has. This uses the shadow window
1319 * @param root The root window of @p win - if 0, this will be automatically determined with extra processing overhead
1320 * @param win The window to get the parent window of
1321 * @return The parent window of @p win
1322 * @ingroup Ecore_X_Window_Geometry_Group
1325 ecore_x_window_shadow_parent_get(Ecore_X_Window root EINA_UNUSED,
1331 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1334 _ecore_x_window_tree_shadow_populate();
1339 for (i = 0; i < shadow_num; i++)
1341 if (!shadow_base[i])
1344 s = _ecore_x_window_shadow_tree_find_shadow(shadow_base[i], win);
1350 return s->parent->win;
1357 * Flushes the window shadow tree so nothing is stored.
1358 * @ingroup Ecore_X_Window_Geometry_Group
1361 ecore_x_window_shadow_tree_flush(void)
1363 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1364 _ecore_x_window_tree_shadow_free();
1368 * Retrieves the root window a given window is on.
1369 * @param win The window to get the root window of
1370 * @return The root window of @p win
1371 * @ingroup Ecore_X_Window_Geometry_Group
1374 ecore_x_window_root_get(Ecore_X_Window win)
1376 XWindowAttributes att;
1378 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1379 if (!XGetWindowAttributes(_ecore_x_disp, win, &att))
1386 _ecore_x_window_at_xy_get(Window base,
1391 Ecore_X_Window *skip,
1394 Window *list = NULL;
1395 Window parent_win = 0, child = 0, root_win = 0;
1396 int i, j, wx, wy, ww, wh;
1399 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1400 if (!ecore_x_window_visible_get(base))
1403 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1404 ecore_x_window_geometry_get(base, &wx, &wy, &ww, &wh);
1408 if (!((x >= wx) && (y >= wy) && (x < (wx + ww)) && (y < (wy + wh))))
1411 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1412 if (!XQueryTree(_ecore_x_disp, base, &root_win, &parent_win, &list, &num))
1419 for (i = num - 1; i >= 0; --i)
1424 for (j = 0; j < skip_num; j++)
1426 if (list[i] == skip[j])
1436 _ecore_x_window_at_xy_get(list[i], wx, wy, x, y, skip,
1450 * Retrieves the top, visible window at the given location.
1451 * @param x The given X position.
1452 * @param y The given Y position.
1453 * @return The window at that position.
1454 * @ingroup Ecore_X_Window_Geometry_Group
1457 ecore_x_window_at_xy_get(int x,
1460 Ecore_X_Window win, root;
1462 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1463 /* FIXME: Proper function to determine current root/virtual root
1464 * window missing here */
1465 root = DefaultRootWindow(_ecore_x_disp);
1468 win = _ecore_x_window_at_xy_get(root, 0, 0, x, y, NULL, 0);
1471 return win ? win : root;
1475 * Retrieves the top, visible window at the given location,
1476 * but skips the windows in the list.
1477 * @param x The given X position.
1478 * @param y The given Y position.
1479 * @param skip The list of windows to be skipped.
1480 * @param skip_num The number of windows to be skipped.
1481 * @return The window at that position.
1482 * @ingroup Ecore_X_Window_Geometry_Group
1485 ecore_x_window_at_xy_with_skip_get(int x,
1487 Ecore_X_Window *skip,
1490 Ecore_X_Window win, root;
1492 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1493 /* FIXME: Proper function to determine current root/virtual root
1494 * window missing here */
1495 root = DefaultRootWindow(_ecore_x_disp);
1498 win = _ecore_x_window_at_xy_get(root, 0, 0, x, y, skip, skip_num);
1501 return win ? win : root;
1505 ecore_x_window_at_xy_begin_get(Ecore_X_Window begin,
1511 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1513 win = _ecore_x_window_at_xy_get(begin, 0, 0, x, y, NULL, 0);
1516 return win ? win : begin;
1520 * Retrieves the parent window of the given window.
1521 * @param win The given window.
1522 * @return The parent window of @p win.
1523 * @ingroup Ecore_X_Window_Parent_Group
1526 ecore_x_window_parent_get(Ecore_X_Window win)
1528 Window root, parent, *children = NULL;
1532 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1533 success = XQueryTree(_ecore_x_disp, win, &root, &parent, &children, &num);
1534 if (_ecore_xlib_sync) ecore_x_sync();
1535 if (!success) return 0;
1544 * Sets the background color of the given window.
1545 * @param win The given window
1546 * @param r red value (0...65536, 16 bits)
1547 * @param g green value (0...65536, 16 bits)
1548 * @param b blue value (0...65536, 16 bits)
1551 ecore_x_window_background_color_set(Ecore_X_Window win,
1556 XSetWindowAttributes attr;
1560 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1565 map = DefaultColormap(_ecore_x_disp, DefaultScreen(_ecore_x_disp));
1566 XAllocColor(_ecore_x_disp, map, &col);
1568 attr.background_pixel = col.pixel;
1569 XChangeWindowAttributes(_ecore_x_disp, win, CWBackPixel, &attr);
1570 if (_ecore_xlib_sync) ecore_x_sync();
1574 ecore_x_window_gravity_set(Ecore_X_Window win,
1575 Ecore_X_Gravity grav)
1577 XSetWindowAttributes att;
1579 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1580 att.win_gravity = grav;
1581 XChangeWindowAttributes(_ecore_x_disp, win, CWWinGravity, &att);
1582 if (_ecore_xlib_sync) ecore_x_sync();
1586 ecore_x_window_pixel_gravity_set(Ecore_X_Window win,
1587 Ecore_X_Gravity grav)
1589 XSetWindowAttributes att;
1591 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1592 att.bit_gravity = grav;
1593 XChangeWindowAttributes(_ecore_x_disp, win, CWBitGravity, &att);
1594 if (_ecore_xlib_sync) ecore_x_sync();
1598 ecore_x_window_pixmap_set(Ecore_X_Window win,
1599 Ecore_X_Pixmap pmap)
1601 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1602 XSetWindowBackgroundPixmap(_ecore_x_disp, win, pmap);
1603 if (_ecore_xlib_sync) ecore_x_sync();
1607 ecore_x_window_area_clear(Ecore_X_Window win,
1613 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1614 XClearArea(_ecore_x_disp, win, x, y, w, h, False);
1615 if (_ecore_xlib_sync) ecore_x_sync();
1619 ecore_x_window_area_expose(Ecore_X_Window win,
1625 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1626 XClearArea(_ecore_x_disp, win, x, y, w, h, True);
1627 if (_ecore_xlib_sync) ecore_x_sync();
1631 ecore_x_window_override_set(Ecore_X_Window win,
1634 XSetWindowAttributes att;
1636 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1637 att.override_redirect = override;
1638 XChangeWindowAttributes(_ecore_x_disp, win, CWOverrideRedirect, &att);
1639 if (_ecore_xlib_sync) ecore_x_sync();
1642 #ifdef ECORE_XRENDER
1643 static Ecore_X_Window
1644 _ecore_x_window_argb_internal_new(Ecore_X_Window parent,
1650 Eina_Bool saveunder)
1653 XSetWindowAttributes attr;
1654 XWindowAttributes att;
1657 int nvi, i, scr = 0;
1658 XRenderPictFormat *fmt;
1663 parent = DefaultRootWindow(_ecore_x_disp);
1664 scr = DefaultScreen(_ecore_x_disp);
1668 /* ewww - round trip */
1669 if (XGetWindowAttributes(_ecore_x_disp, parent, &att))
1671 if (_ecore_xlib_sync) ecore_x_sync();
1672 for (i = 0; i < ScreenCount(_ecore_x_disp); i++)
1674 if (att.screen == ScreenOfDisplay(_ecore_x_disp, i))
1685 vi_in.class = TrueColor;
1686 xvi = XGetVisualInfo(_ecore_x_disp,
1692 if (_ecore_xlib_sync) ecore_x_sync();
1697 for (i = 0; i < nvi; i++)
1699 fmt = XRenderFindVisualFormat(_ecore_x_disp, xvi[i].visual);
1700 if (_ecore_xlib_sync) ecore_x_sync();
1701 if ((fmt->type == PictTypeDirect) && (fmt->direct.alphaMask))
1703 vis = xvi[i].visual;
1709 attr.backing_store = NotUseful;
1710 attr.override_redirect = override;
1711 attr.colormap = XCreateColormap(_ecore_x_disp, parent,
1713 attr.border_pixel = 0;
1714 attr.background_pixmap = None;
1715 attr.bit_gravity = NorthWestGravity;
1716 attr.win_gravity = NorthWestGravity;
1717 attr.save_under = saveunder;
1718 attr.do_not_propagate_mask = NoEventMask;
1719 attr.event_mask = KeyPressMask |
1727 VisibilityChangeMask |
1728 StructureNotifyMask |
1730 PropertyChangeMask |
1732 win = XCreateWindow(_ecore_x_disp, parent,
1738 CWOverrideRedirect |
1748 if (_ecore_xlib_sync) ecore_x_sync();
1750 if (parent == DefaultRootWindow(_ecore_x_disp))
1751 ecore_x_window_defaults_set(win);
1756 #endif /* ifdef ECORE_XRENDER */
1759 ecore_x_window_argb_get(Ecore_X_Window win)
1761 #ifdef ECORE_XRENDER
1762 XWindowAttributes att;
1763 XRenderPictFormat *fmt;
1767 ret = XGetWindowAttributes(_ecore_x_disp, win, &att);
1768 if (_ecore_xlib_sync) ecore_x_sync();
1771 fmt = XRenderFindVisualFormat(_ecore_x_disp, att.visual);
1772 if (_ecore_xlib_sync) ecore_x_sync();
1776 if ((fmt->type == PictTypeDirect) && (fmt->direct.alphaMask))
1780 #else /* ifdef ECORE_XRENDER */
1782 #endif /* ifdef ECORE_XRENDER */
1786 * Creates a new window.
1787 * @param parent The parent window to use. If @p parent is @c 0, the root
1788 * window of the default display is used.
1789 * @param x X position.
1790 * @param y Y position.
1793 * @return The new window handle.
1794 * @ingroup Ecore_X_Window_Create_Group
1797 ecore_x_window_manager_argb_new(Ecore_X_Window parent,
1803 #ifdef ECORE_XRENDER
1804 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1805 return _ecore_x_window_argb_internal_new(parent, x, y, w, h, 1, 0);
1806 #else /* ifdef ECORE_XRENDER */
1808 #endif /* ifdef ECORE_XRENDER */
1812 * Creates a new window.
1813 * @param parent The parent window to use. If @p parent is @c 0, the root
1814 * window of the default display is used.
1815 * @param x X position.
1816 * @param y Y position.
1819 * @return The new window handle.
1820 * @ingroup Ecore_X_Window_Create_Group
1823 ecore_x_window_argb_new(Ecore_X_Window parent,
1829 #ifdef ECORE_XRENDER
1830 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1831 return _ecore_x_window_argb_internal_new(parent, x, y, w, h, 0, 0);
1832 #else /* ifdef ECORE_XRENDER */
1834 #endif /* ifdef ECORE_XRENDER */
1838 * Creates a window with the override redirect attribute set to @c True.
1839 * @param parent The parent window to use. If @p parent is @c 0, the root
1840 * window of the default display is used.
1841 * @param x X position.
1842 * @param y Y position.
1845 * @return The new window handle.
1846 * @ingroup Ecore_X_Window_Create_Group
1849 ecore_x_window_override_argb_new(Ecore_X_Window parent,
1855 #ifdef ECORE_XRENDER
1856 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1857 return _ecore_x_window_argb_internal_new(parent, x, y, w, h, 1, 0);
1858 #else /* ifdef ECORE_XRENDER */
1860 #endif /* ifdef ECORE_XRENDER */
1864 ecore_x_window_permanent_new(Ecore_X_Window parent, Ecore_X_Atom unique_atom)
1867 Window win, win2, realwin = 0;
1870 unsigned long ldata, bytes_after, num_ret, *datap;
1871 unsigned char *prop_ret;
1873 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1874 disp = XOpenDisplay(DisplayString(_ecore_x_disp));
1875 if (!disp) return 0;
1878 if (XGetWindowProperty(disp, parent, unique_atom, 0, 0x7fffffff,
1879 False, XA_WINDOW, &type_ret, &format_ret,
1880 &num_ret, &bytes_after, &prop_ret) == Success)
1884 if ((format_ret == 32) && (type_ret == XA_WINDOW) &&
1887 datap = (unsigned long *)prop_ret;
1888 win = (Window)(*datap);
1890 if (XGetWindowProperty(disp, win, unique_atom, 0, 0x7fffffff,
1891 False, XA_WINDOW, &type_ret, &format_ret,
1892 &num_ret, &bytes_after, &prop_ret) == Success)
1896 if ((format_ret == 32) && (type_ret == XA_WINDOW) &&
1899 datap = (unsigned long *)prop_ret;
1900 win2 = (Window)(*datap);
1902 if (win2 == win) realwin = win;
1904 else XFree(prop_ret);
1908 else XFree(prop_ret);
1913 XUngrabServer(disp);
1915 XCloseDisplay(disp);
1918 win = XCreateSimpleWindow(disp, parent, -77, -77, 7, 7, 0, 0, 0);
1919 ldata = (unsigned long)win;
1920 XChangeProperty(disp, win, unique_atom, XA_WINDOW, 32,
1921 PropModeReplace, (unsigned char *)(&ldata), 1);
1922 XChangeProperty(disp, parent, unique_atom, XA_WINDOW, 32,
1923 PropModeReplace, (unsigned char *)(&ldata), 1);
1924 XSetCloseDownMode(disp, RetainPermanent);
1925 XUngrabServer(disp);
1927 XCloseDisplay(disp);