2 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
10 #include <sys/types.h>
14 #include "ecore_x_private.h"
16 #include "Ecore_X_Atoms.h"
18 static int ignore_num = 0;
19 static Ecore_X_Window *ignore_list = NULL;
22 * @defgroup Ecore_X_Window_Create_Group X Window Creation Functions
24 * Functions that can be used to create an X window.
28 * Creates a new window.
29 * @param parent The parent window to use. If @p parent is @c 0, the root
30 * window of the default display is used.
31 * @param x X position.
32 * @param y Y position.
35 * @return The new window handle.
36 * @ingroup Ecore_X_Window_Create_Group
39 ecore_x_window_new(Ecore_X_Window parent, int x, int y, int w, int h)
42 XSetWindowAttributes attr;
44 LOGFN(__FILE__, __LINE__, __FUNCTION__);
45 if (parent == 0) parent = DefaultRootWindow(_ecore_x_disp);
46 attr.backing_store = NotUseful;
47 attr.override_redirect = False;
48 attr.border_pixel = 0;
49 attr.background_pixmap = None;
50 attr.bit_gravity = NorthWestGravity;
51 attr.win_gravity = NorthWestGravity;
52 attr.save_under = False;
53 attr.do_not_propagate_mask = NoEventMask;
54 attr.event_mask = KeyPressMask |
62 VisibilityChangeMask |
67 win = XCreateWindow(_ecore_x_disp, parent,
69 CopyFromParent, /*DefaultDepth(_ecore_x_disp, DefaultScreen(_ecore_x_disp)),*/
71 CopyFromParent, /*DefaultVisual(_ecore_x_disp, DefaultScreen(_ecore_x_disp)),*/
84 if (parent == DefaultRootWindow(_ecore_x_disp)) ecore_x_window_defaults_set(win);
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.
96 * @return The new window handle.
97 * @ingroup Ecore_X_Window_Create_Group
100 ecore_x_window_override_new(Ecore_X_Window parent, int x, int y, int w, int h)
103 XSetWindowAttributes attr;
105 LOGFN(__FILE__, __LINE__, __FUNCTION__);
106 if (parent == 0) parent = DefaultRootWindow(_ecore_x_disp);
107 attr.backing_store = NotUseful;
108 attr.override_redirect = True;
109 attr.border_pixel = 0;
110 attr.background_pixmap = None;
111 attr.bit_gravity = NorthWestGravity;
112 attr.win_gravity = NorthWestGravity;
113 attr.save_under = False;
114 attr.do_not_propagate_mask = NoEventMask;
115 attr.event_mask = KeyPressMask |
123 VisibilityChangeMask |
124 StructureNotifyMask |
128 win = XCreateWindow(_ecore_x_disp, parent,
130 CopyFromParent, /*DefaultDepth(_ecore_x_disp, DefaultScreen(_ecore_x_disp)),*/
132 CopyFromParent, /*DefaultVisual(_ecore_x_disp, DefaultScreen(_ecore_x_disp)),*/
148 * Creates a new input window.
149 * @param parent The parent window to use. If @p parent is @c 0, the root
150 * window of the default display is used.
151 * @param x X position.
152 * @param y Y position.
155 * @return The new window.
156 * @ingroup Ecore_X_Window_Create_Group
159 ecore_x_window_input_new(Ecore_X_Window parent, int x, int y, int w, int h)
162 XSetWindowAttributes attr;
164 LOGFN(__FILE__, __LINE__, __FUNCTION__);
165 if (parent == 0) parent = DefaultRootWindow(_ecore_x_disp);
166 attr.override_redirect = True;
167 attr.do_not_propagate_mask = NoEventMask;
168 attr.event_mask = KeyPressMask |
176 VisibilityChangeMask |
177 StructureNotifyMask |
181 win = XCreateWindow(_ecore_x_disp, parent,
185 CopyFromParent, /*DefaultVisual(_ecore_x_disp, DefaultScreen(_ecore_x_disp)),*/
191 if (parent == DefaultRootWindow(_ecore_x_disp))
198 * @defgroup Ecore_X_Window_Properties_Group X Window Property Functions
200 * Functions that set window properties.
204 * Sets the default properties for the given window.
206 * The default properties set for the window are @c WM_CLIENT_MACHINE and
209 * @param win The given window.
210 * @ingroup Ecore_X_Window_Properties_Groups
213 ecore_x_window_defaults_set(Ecore_X_Window win)
216 char buf[MAXHOSTNAMELEN];
222 LOGFN(__FILE__, __LINE__, __FUNCTION__);
224 * Set WM_CLIENT_MACHINE.
226 gethostname(buf, MAXHOSTNAMELEN);
227 buf[MAXHOSTNAMELEN - 1] = '\0';
229 /* The ecore function uses UTF8 which Xlib may not like (especially
230 * with older clients) */
231 /* ecore_x_window_prop_string_set(win, ECORE_X_ATOM_WM_CLIENT_MACHINE,
233 if (XStringListToTextProperty(hostname, 1, &xprop))
235 XSetWMClientMachine(_ecore_x_disp, win, &xprop);
243 ecore_x_netwm_pid_set(win, pid);
245 ecore_x_netwm_window_type_set(win, ECORE_X_WINDOW_TYPE_NORMAL);
247 ecore_app_args_get(&argc, &argv);
248 ecore_x_icccm_command_set(win, argc, argv);
252 ecore_x_window_configure(Ecore_X_Window win,
253 Ecore_X_Window_Configure_Mask mask,
254 int x, int y, int w, int h,
255 int border_width, Ecore_X_Window sibling,
262 LOGFN(__FILE__, __LINE__, __FUNCTION__);
268 xwc.border_width = border_width;
269 xwc.sibling = sibling;
270 xwc.stack_mode = stack_mode;
272 XConfigureWindow(_ecore_x_disp, win, mask, &xwc);
276 * @defgroup Ecore_X_Window_Destroy_Group X Window Destroy Functions
278 * Functions to destroy X windows.
282 * Deletes the given window.
283 * @param win The given window.
284 * @ingroup Ecore_X_Window_Destroy_Group
287 ecore_x_window_free(Ecore_X_Window win)
289 /* sorry sir, deleting the root window doesn't sound like
292 LOGFN(__FILE__, __LINE__, __FUNCTION__);
293 if (win) XDestroyWindow(_ecore_x_disp, win);
297 * Set if a window should be ignored.
298 * @param win The given window.
299 * @param ignore if to ignore
302 ecore_x_window_ignore_set(Ecore_X_Window win, int ignore)
306 LOGFN(__FILE__, __LINE__, __FUNCTION__);
311 for (i = 0; i < ignore_num; i++)
313 if (win == ignore_list[i])
316 ignore_list = realloc(ignore_list, (ignore_num + 1) * sizeof(Ecore_X_Window));
317 if (!ignore_list) return;
318 ignore_list[ignore_num++] = win;
323 ignore_list = malloc(sizeof(Ecore_X_Window));
324 ignore_list[ignore_num++] = win;
329 if (!ignore_list) return;
330 for (i = 0, j = 0; i < ignore_num; i++)
332 if (win != ignore_list[i])
333 ignore_list[i] = ignore_list[j++];
337 ignore_list = realloc(ignore_list, ignore_num * sizeof(Ecore_X_Window));
342 * Get the ignore list
343 * @param num number of windows in the list
344 * @return list of windows to ignore
346 EAPI Ecore_X_Window *
347 ecore_x_window_ignore_list(int *num)
349 if (num) *num = ignore_num;
354 * Sends a delete request to the given window.
355 * @param win The given window.
356 * @ingroup Ecore_X_Window_Destroy_Group
359 ecore_x_window_delete_request_send(Ecore_X_Window win)
363 /* sorry sir, deleting the root window doesn't sound like
368 LOGFN(__FILE__, __LINE__, __FUNCTION__);
369 xev.xclient.type = ClientMessage;
370 xev.xclient.display = _ecore_x_disp;
371 xev.xclient.window = win;
372 xev.xclient.message_type = ECORE_X_ATOM_WM_PROTOCOLS;
373 xev.xclient.format = 32;
374 xev.xclient.data.l[0] = ECORE_X_ATOM_WM_DELETE_WINDOW;
375 xev.xclient.data.l[1] = CurrentTime;
377 XSendEvent(_ecore_x_disp, win, False, NoEventMask, &xev);
381 * @defgroup Ecore_X_Window_Visibility_Group X Window Visibility Functions
383 * Functions to access and change the visibility of X windows.
389 * Synonymous to "mapping" a window in X Window System terminology.
391 * @param win The window to show.
392 * @ingroup Ecore_X_Window_Visibility
395 ecore_x_window_show(Ecore_X_Window win)
397 LOGFN(__FILE__, __LINE__, __FUNCTION__);
398 XMapWindow(_ecore_x_disp, win);
404 * Synonymous to "unmapping" a window in X Window System terminology.
406 * @param win The window to hide.
407 * @ingroup Ecore_X_Window_Visibility
410 ecore_x_window_hide(Ecore_X_Window win)
417 /* ICCCM: SEND unmap event... */
418 LOGFN(__FILE__, __LINE__, __FUNCTION__);
420 if (ScreenCount(_ecore_x_disp) == 1)
421 root = DefaultRootWindow(_ecore_x_disp);
423 XGetGeometry(_ecore_x_disp, win, &root, &idum, &idum, &uidum, &uidum, &uidum, &uidum);
424 xev.xunmap.type = UnmapNotify;
425 xev.xunmap.serial = 0;
426 xev.xunmap.send_event = True;
427 xev.xunmap.display = _ecore_x_disp;
428 xev.xunmap.event = root;
429 xev.xunmap.window = win;
430 xev.xunmap.from_configure = False;
431 XSendEvent(_ecore_x_disp, xev.xunmap.event, False,
432 SubstructureRedirectMask | SubstructureNotifyMask, &xev);
433 XUnmapWindow(_ecore_x_disp, win);
437 * @defgroup Ecore_X_Window_Geometry_Group X Window Geometry Functions
439 * Functions that change or retrieve the geometry of X windows.
443 * Moves a window to the position @p x, @p y.
445 * The position is relative to the upper left hand corner of the
448 * @param win The window to move.
449 * @param x X position.
450 * @param y Y position.
451 * @ingroup Ecore_X_Window_Geometry_Group
454 ecore_x_window_move(Ecore_X_Window win, int x, int y)
456 LOGFN(__FILE__, __LINE__, __FUNCTION__);
457 XMoveWindow(_ecore_x_disp, win, x, y);
462 * @param win The window to resize.
463 * @param w New width of the window.
464 * @param h New height of the window.
465 * @ingroup Ecore_X_Window_Geometry_Group
468 ecore_x_window_resize(Ecore_X_Window win, int w, int h)
470 LOGFN(__FILE__, __LINE__, __FUNCTION__);
473 XResizeWindow(_ecore_x_disp, win, w, h);
477 * Moves and resizes a window.
478 * @param win The window to move and resize.
479 * @param x New X position of the window.
480 * @param y New Y position of the window.
481 * @param w New width of the window.
482 * @param h New height of the window.
483 * @ingroup Ecore_X_Window_Geometry_Group
486 ecore_x_window_move_resize(Ecore_X_Window win, int x, int y, int w, int h)
488 LOGFN(__FILE__, __LINE__, __FUNCTION__);
491 XMoveResizeWindow(_ecore_x_disp, win, x, y, w, h);
495 * @defgroup Ecore_X_Window_Focus_Functions X Window Focus Functions
497 * Functions that give the focus to an X Window.
501 * Sets the focus to the window @p win.
502 * @param win The window to focus.
503 * @ingroup Ecore_X_Window_Focus_Functions
506 ecore_x_window_focus(Ecore_X_Window win)
508 LOGFN(__FILE__, __LINE__, __FUNCTION__);
509 if (win == 0) win = DefaultRootWindow(_ecore_x_disp);
510 // XSetInputFocus(_ecore_x_disp, win, RevertToNone, CurrentTime);
511 // XSetInputFocus(_ecore_x_disp, win, RevertToPointerRoot, CurrentTime);
512 XSetInputFocus(_ecore_x_disp, win, RevertToParent, CurrentTime);
516 * Sets the focus to the given window at a specific time.
517 * @param win The window to focus.
518 * @param t When to set the focus to the window.
519 * @ingroup Ecore_X_Window_Focus_Functions
522 ecore_x_window_focus_at_time(Ecore_X_Window win, Ecore_X_Time t)
524 LOGFN(__FILE__, __LINE__, __FUNCTION__);
525 if (win == 0) win = DefaultRootWindow(_ecore_x_disp);
526 // XSetInputFocus(_ecore_x_disp, win, RevertToNone, t);
527 // XSetInputFocus(_ecore_x_disp, win, PointerRoot, t);
528 XSetInputFocus(_ecore_x_disp, win, RevertToParent, t);
532 * gets the focus to the window @p win.
533 * @return The window that has focus.
534 * @ingroup Ecore_X_Window_Focus_Functions
537 ecore_x_window_focus_get(void)
542 LOGFN(__FILE__, __LINE__, __FUNCTION__);
544 XGetInputFocus(_ecore_x_disp, &win, &revert_mode);
549 * @defgroup Ecore_X_Window_Z_Order_Group X Window Z Order Functions
551 * Functions that change the Z order of X windows.
555 * Raises the given window.
556 * @param win The window to raise.
557 * @ingroup Ecore_X_Window_Z_Order_Group
560 ecore_x_window_raise(Ecore_X_Window win)
562 LOGFN(__FILE__, __LINE__, __FUNCTION__);
563 XRaiseWindow(_ecore_x_disp, win);
567 * Lowers the given window.
568 * @param win The window to lower.
569 * @ingroup Ecore_X_Window_Z_Order_Group
572 ecore_x_window_lower(Ecore_X_Window win)
574 LOGFN(__FILE__, __LINE__, __FUNCTION__);
575 XLowerWindow(_ecore_x_disp, win);
579 * @defgroup Ecore_X_Window_Parent_Group X Window Parent Functions
581 * Functions that retrieve or changes the parent window of a window.
585 * Moves a window to within another window at a given position.
586 * @param win The window to reparent.
587 * @param new_parent The new parent window.
588 * @param x X position within new parent window.
589 * @param y Y position within new parent window.
590 * @ingroup Ecore_X_Window_Parent_Group
593 ecore_x_window_reparent(Ecore_X_Window win, Ecore_X_Window new_parent, int x, int y)
595 LOGFN(__FILE__, __LINE__, __FUNCTION__);
596 if (new_parent == 0) new_parent = DefaultRootWindow(_ecore_x_disp);
597 XReparentWindow(_ecore_x_disp, win, new_parent, x, y);
601 * Retrieves the size of the given window.
602 * @param win The given window.
603 * @param w Pointer to an integer into which the width is to be stored.
604 * @param h Pointer to an integer into which the height is to be stored.
605 * @ingroup Ecore_X_Window_Geometry_Group
608 ecore_x_window_size_get(Ecore_X_Window win, int *w, int *h)
610 int dummy_x, dummy_y;
612 LOGFN(__FILE__, __LINE__, __FUNCTION__);
613 if (win == 0) win = DefaultRootWindow(_ecore_x_disp);
614 ecore_x_drawable_geometry_get(win, &dummy_x, &dummy_y, w, h);
618 * Retrieves the geometry of the given window.
619 * @param win The given window.
620 * @param x Pointer to an integer in which the X position is to be stored.
621 * @param y Pointer to an integer in which the Y position is to be stored.
622 * @param w Pointer to an integer in which the width is to be stored.
623 * @param h Pointer to an integer in which the height is to be stored.
624 * @ingroup Ecore_X_Window_Geometry_Group
627 ecore_x_window_geometry_get(Ecore_X_Window win, int *x, int *y, int *w, int *h)
629 LOGFN(__FILE__, __LINE__, __FUNCTION__);
630 if (!win) win = DefaultRootWindow(_ecore_x_disp);
631 ecore_x_drawable_geometry_get(win, x, y, w, h);
635 * Retrieves the width of the border of the given window.
636 * @param win The given window.
637 * @return Width of the border of @p win.
638 * @ingroup Ecore_X_Window_Geometry_Group
641 ecore_x_window_border_width_get(Ecore_X_Window win)
643 LOGFN(__FILE__, __LINE__, __FUNCTION__);
644 /* doesn't make sense to call this on a root window */
646 return ecore_x_drawable_border_width_get(win);
650 * Sets the width of the border of the given window.
651 * @param win The given window.
652 * @param width The new border width.
653 * @ingroup Ecore_X_Window_Geometry_Group
656 ecore_x_window_border_width_set(Ecore_X_Window win, int width)
658 LOGFN(__FILE__, __LINE__, __FUNCTION__);
659 /* doesn't make sense to call this on a root window */
661 XSetWindowBorderWidth (_ecore_x_disp, win, width);
665 * Retrieves the depth of the given window.
666 * @param win The given window.
667 * @return Depth of the window.
670 ecore_x_window_depth_get(Ecore_X_Window win)
672 LOGFN(__FILE__, __LINE__, __FUNCTION__);
673 return ecore_x_drawable_depth_get(win);
679 * FIXME: To be fixed.
682 ecore_x_window_cursor_show(Ecore_X_Window win, int show)
684 LOGFN(__FILE__, __LINE__, __FUNCTION__);
685 if (win == 0) win = DefaultRootWindow(_ecore_x_disp);
694 p = XCreatePixmap(_ecore_x_disp, win, 1, 1, 1);
695 m = XCreatePixmap(_ecore_x_disp, win, 1, 1, 1);
696 gc = XCreateGC(_ecore_x_disp, m, 0, &gcv);
697 XSetForeground(_ecore_x_disp, gc, 0);
698 XDrawPoint(_ecore_x_disp, m, gc, 0, 0);
699 XFreeGC(_ecore_x_disp, gc);
700 c = XCreatePixmapCursor(_ecore_x_disp, p, m, &cl, &cl, 0, 0);
701 XDefineCursor(_ecore_x_disp, win, c);
702 XFreeCursor(_ecore_x_disp, c);
703 XFreePixmap(_ecore_x_disp, p);
704 XFreePixmap(_ecore_x_disp, m);
708 XDefineCursor(_ecore_x_disp, win, 0);
713 ecore_x_window_cursor_set(Ecore_X_Window win, Ecore_X_Cursor c)
715 LOGFN(__FILE__, __LINE__, __FUNCTION__);
717 XUndefineCursor(_ecore_x_disp, win);
719 XDefineCursor(_ecore_x_disp, win, c);
723 * Finds out whether the given window is currently visible.
724 * @param win The given window.
725 * @return 1 if the window is visible, otherwise 0.
726 * @ingroup Ecore_X_Window_Visibility_Group
729 ecore_x_window_visible_get(Ecore_X_Window win)
731 XWindowAttributes attr;
733 LOGFN(__FILE__, __LINE__, __FUNCTION__);
734 return (XGetWindowAttributes(_ecore_x_disp, win, &attr) &&
735 (attr.map_state == IsViewable));
740 typedef struct _Shadow Shadow;
751 static Shadow **shadow_base = NULL;
752 static int shadow_num = 0;
755 _ecore_x_window_tree_walk(Window win)
758 Window parent_win = 0, root_win = 0;
761 XWindowAttributes att;
763 if (!XGetWindowAttributes(_ecore_x_disp, win, &att)) return NULL;
764 // if (att.class == InputOnly) return NULL;
765 if (att.map_state != IsViewable) return NULL;
767 s = calloc(1, sizeof(Shadow));
774 if (XQueryTree(_ecore_x_disp, s->win, &root_win, &parent_win,
777 s->children = calloc(1, sizeof(Shadow *) * num);
781 s->children_num = num;
782 for (i = 0; i < num; i++)
784 s->children[i] = _ecore_x_window_tree_walk(list[i]);
785 if (s->children[i]) s->children[i]->parent = s;
787 /* compress list down */
789 for (i = 0; i < num; i++)
793 s->children[j] = s->children[i];
806 sl = realloc(s->children, sizeof(Shadow *) * j);
807 if (sl) s->children = sl;
811 if (list) XFree(list);
816 _ecore_x_window_tree_shadow_free1(Shadow *s)
823 for (i = 0; i < s->children_num; i++)
826 _ecore_x_window_tree_shadow_free1(s->children[i]);
834 _ecore_x_window_tree_shadow_free(void)
838 if (!shadow_base) return;
839 for (i = 0; i < shadow_num; i++)
841 if (!shadow_base[i]) continue;
842 _ecore_x_window_tree_shadow_free1(shadow_base[i]);
850 _ecore_x_window_tree_shadow_populate(void)
852 Ecore_X_Window *roots;
855 roots = ecore_x_window_root_list(&num);
858 shadow_base = calloc(1, sizeof(Shadow *) * num);
862 for (i = 0; i < num; i++)
863 shadow_base[i] = _ecore_x_window_tree_walk(roots[i]);
870 static int shadow_count = 0;
873 _ecore_x_window_tree_shadow_start(void)
876 if (shadow_count > 1) return;
877 _ecore_x_window_tree_shadow_populate();
881 _ecore_x_window_tree_shadow_stop(void)
884 if (shadow_count != 0) return;
885 _ecore_x_window_tree_shadow_free();
890 _ecore_x_window_shadow_tree_find_shadow(Shadow *s, Window win)
895 if (s->win == win) return s;
898 for (i = 0; i < s->children_num; i++)
900 if (!s->children[i]) continue;
901 if ((ss = _ecore_x_window_shadow_tree_find_shadow(s->children[i], win)))
909 _ecore_x_window_shadow_tree_find(Window base)
914 for (i = 0; i < shadow_num; i++)
916 if (!shadow_base[i]) continue;
917 if ((s = _ecore_x_window_shadow_tree_find_shadow(shadow_base[i], base)))
924 _ecore_x_window_shadow_tree_at_xy_get_shadow(Shadow *s, int bx, int by, int x, int y,
925 Ecore_X_Window *skip, int skip_num)
933 if (!((x >= wx) && (y >= wy) && (x < (wx + s->w)) && (y < (wy + s->h))))
939 for (i = s->children_num - 1; i >= 0; --i)
941 if (!s->children[i]) continue;
945 for (j = 0; j < skip_num; j++)
947 if (s->children[i]->win == skip[j])
957 if ((child = _ecore_x_window_shadow_tree_at_xy_get_shadow(s->children[i], wx, wy, x, y, skip, skip_num)))
968 _ecore_x_window_shadow_tree_at_xy_get(Window base, int bx, int by, int x, int y,
969 Ecore_X_Window *skip, int skip_num)
975 _ecore_x_window_tree_shadow_populate();
976 if (!shadow_base) return 0;
978 s = _ecore_x_window_shadow_tree_find(base);
980 return _ecore_x_window_shadow_tree_at_xy_get_shadow(s, bx, by, x, y, skip, skip_num);
984 * Retrieves the top, visible window at the given location,
985 * but skips the windows in the list. This uses a shadow tree built from the
986 * window tree that is only updated the first time
987 * ecore_x_window_shadow_tree_at_xy_with_skip_get() is called, or the next time
988 * it is called after a ecore_x_window_shadow_tree_flush()
989 * @param base The base window to start searching from (normally root).
990 * @param x The given X position.
991 * @param y The given Y position.
992 * @return The window at that position.
993 * @ingroup Ecore_X_Window_Geometry_Group
996 ecore_x_window_shadow_tree_at_xy_with_skip_get(Ecore_X_Window base, int x, int y, Ecore_X_Window *skip, int skip_num)
998 LOGFN(__FILE__, __LINE__, __FUNCTION__);
999 return _ecore_x_window_shadow_tree_at_xy_get(base, 0, 0, x, y, skip, skip_num);
1003 * Retrieves the parent window a given window has. This uses the shadow window
1005 * @param root The root window of @p win - if 0, this will be automatically determined with extra processing overhead
1006 * @param win The window to get the parent window of
1007 * @return The parent window of @p win
1008 * @ingroup Ecore_X_Window_Geometry_Group
1011 ecore_x_window_shadow_parent_get(Ecore_X_Window root __UNUSED__, Ecore_X_Window win)
1016 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1019 _ecore_x_window_tree_shadow_populate();
1020 if (!shadow_base) return 0;
1022 for (i = 0; i < shadow_num; i++)
1024 if (!shadow_base[i]) continue;
1025 s = _ecore_x_window_shadow_tree_find_shadow(shadow_base[i], win);
1028 if (!s->parent) return 0;
1029 return s->parent->win;
1036 * Flushes the window shadow tree so nothing is stored.
1037 * @ingroup Ecore_X_Window_Geometry_Group
1040 ecore_x_window_shadow_tree_flush(void)
1042 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1043 _ecore_x_window_tree_shadow_free();
1047 * Retrieves the root window a given window is on.
1048 * @param win The window to get the root window of
1049 * @return The root window of @p win
1050 * @ingroup Ecore_X_Window_Geometry_Group
1053 ecore_x_window_root_get(Ecore_X_Window win)
1055 XWindowAttributes att;
1057 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1058 if (!XGetWindowAttributes(_ecore_x_disp, win, &att)) return 0;
1063 _ecore_x_window_at_xy_get(Window base, int bx, int by, int x, int y,
1064 Ecore_X_Window *skip, int skip_num)
1066 Window *list = NULL;
1067 Window parent_win = 0, child = 0, root_win = 0;
1068 int i, j, wx, wy, ww, wh;
1071 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1072 if (!ecore_x_window_visible_get(base))
1075 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1076 ecore_x_window_geometry_get(base, &wx, &wy, &ww, &wh);
1080 if (!((x >= wx) && (y >= wy) && (x < (wx + ww)) && (y < (wy + wh))))
1083 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1084 if (!XQueryTree(_ecore_x_disp, base, &root_win, &parent_win, &list, &num))
1091 for (i = num - 1; i >= 0; --i)
1097 for (j = 0; j < skip_num; j++)
1099 if (list[i] == skip[j])
1109 if ((child = _ecore_x_window_at_xy_get(list[i], wx, wy, x, y, skip, skip_num)))
1122 * Retrieves the top, visible window at the given location.
1123 * @param x The given X position.
1124 * @param y The given Y position.
1125 * @return The window at that position.
1126 * @ingroup Ecore_X_Window_Geometry_Group
1129 ecore_x_window_at_xy_get(int x, int y)
1131 Ecore_X_Window win, root;
1133 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1134 /* FIXME: Proper function to determine current root/virtual root
1135 * window missing here */
1136 root = DefaultRootWindow(_ecore_x_disp);
1139 win = _ecore_x_window_at_xy_get(root, 0, 0, x, y, NULL, 0);
1142 return win ? win : root;
1146 * Retrieves the top, visible window at the given location,
1147 * but skips the windows in the list.
1148 * @param x The given X position.
1149 * @param y The given Y position.
1150 * @return The window at that position.
1151 * @ingroup Ecore_X_Window_Geometry_Group
1154 ecore_x_window_at_xy_with_skip_get(int x, int y, Ecore_X_Window *skip, int skip_num)
1156 Ecore_X_Window win, root;
1158 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1159 /* FIXME: Proper function to determine current root/virtual root
1160 * window missing here */
1161 root = DefaultRootWindow(_ecore_x_disp);
1164 win = _ecore_x_window_at_xy_get(root, 0, 0, x, y, skip, skip_num);
1167 return win ? win : root;
1171 ecore_x_window_at_xy_begin_get(Ecore_X_Window begin, int x, int y)
1175 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1177 win = _ecore_x_window_at_xy_get(begin, 0, 0, x, y, NULL, 0);
1180 return win ? win : begin;
1184 * Retrieves the parent window of the given window.
1185 * @param win The given window.
1186 * @return The parent window of @p win.
1187 * @ingroup Ecore_X_Window_Parent_Group
1190 ecore_x_window_parent_get(Ecore_X_Window win)
1192 Window root, parent, *children = NULL;
1195 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1196 if (!XQueryTree(_ecore_x_disp, win, &root, &parent, &children, &num))
1205 * Sets the background color of the given window.
1206 * @param win The given window
1207 * @param r red value (0...65536, 16 bits)
1208 * @param g green value (0...65536, 16 bits)
1209 * @param b blue value (0...65536, 16 bits)
1212 ecore_x_window_background_color_set(Ecore_X_Window win, unsigned short r,
1213 unsigned short g, unsigned short b)
1215 XSetWindowAttributes attr;
1219 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1224 map = DefaultColormap(_ecore_x_disp, DefaultScreen(_ecore_x_disp));
1225 XAllocColor(_ecore_x_disp, map, &col);
1227 attr.background_pixel = col.pixel;
1228 XChangeWindowAttributes(_ecore_x_disp, win, CWBackPixel, &attr);
1232 ecore_x_window_gravity_set(Ecore_X_Window win, Ecore_X_Gravity grav)
1234 XSetWindowAttributes att;
1236 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1237 att.win_gravity = grav;
1238 XChangeWindowAttributes(_ecore_x_disp, win, CWWinGravity, &att);
1242 ecore_x_window_pixel_gravity_set(Ecore_X_Window win, Ecore_X_Gravity grav)
1244 XSetWindowAttributes att;
1246 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1247 att.bit_gravity = grav;
1248 XChangeWindowAttributes(_ecore_x_disp, win, CWBitGravity, &att);
1252 ecore_x_window_pixmap_set(Ecore_X_Window win, Ecore_X_Pixmap pmap)
1254 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1255 XSetWindowBackgroundPixmap(_ecore_x_disp, win, pmap);
1259 ecore_x_window_area_clear(Ecore_X_Window win, int x, int y, int w, int h)
1261 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1262 XClearArea(_ecore_x_disp, win, x, y, w, h, False);
1266 ecore_x_window_area_expose(Ecore_X_Window win, int x, int y, int w, int h)
1268 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1269 XClearArea(_ecore_x_disp, win, x, y, w, h, True);
1273 ecore_x_window_override_set(Ecore_X_Window win, int override)
1275 XSetWindowAttributes att;
1277 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1278 att.override_redirect = override;
1279 XChangeWindowAttributes(_ecore_x_disp, win, CWOverrideRedirect, &att);
1282 #ifdef ECORE_XRENDER
1283 static Ecore_X_Window
1284 _ecore_x_window_argb_internal_new(Ecore_X_Window parent, int x, int y, int w, int h, int override, int saveunder)
1287 XSetWindowAttributes attr;
1288 XWindowAttributes att;
1291 int nvi, i, scr = 0;
1292 XRenderPictFormat *fmt;
1297 parent = DefaultRootWindow(_ecore_x_disp);
1298 scr = DefaultScreen(_ecore_x_disp);
1302 /* ewww - round trip */
1303 XGetWindowAttributes(_ecore_x_disp, parent, &att);
1304 for (i = 0; i < ScreenCount(_ecore_x_disp); i++)
1306 if (att.screen == ScreenOfDisplay(_ecore_x_disp, i))
1315 vi_in.class = TrueColor;
1316 xvi = XGetVisualInfo(_ecore_x_disp,
1322 if (xvi == NULL) return 0;
1324 for (i = 0; i < nvi; i++)
1326 fmt = XRenderFindVisualFormat(_ecore_x_disp, xvi[i].visual);
1327 if ((fmt->type == PictTypeDirect) && (fmt->direct.alphaMask))
1329 vis = xvi[i].visual;
1335 attr.backing_store = NotUseful;
1336 attr.override_redirect = override;
1337 attr.colormap = XCreateColormap(_ecore_x_disp, parent,
1339 attr.border_pixel = 0;
1340 attr.background_pixmap = None;
1341 attr.bit_gravity = NorthWestGravity;
1342 attr.win_gravity = NorthWestGravity;
1343 attr.save_under = saveunder;
1344 attr.do_not_propagate_mask = NoEventMask;
1345 attr.event_mask = KeyPressMask |
1353 VisibilityChangeMask |
1354 StructureNotifyMask |
1356 PropertyChangeMask |
1358 win = XCreateWindow(_ecore_x_disp, parent,
1364 CWOverrideRedirect |
1374 XFreeColormap(_ecore_x_disp, attr.colormap);
1376 if (parent == DefaultRootWindow(_ecore_x_disp)) ecore_x_window_defaults_set(win);
1382 ecore_x_window_argb_get(Ecore_X_Window win)
1384 #ifdef ECORE_XRENDER
1385 XWindowAttributes att;
1386 XRenderPictFormat *fmt;
1389 if (!XGetWindowAttributes(_ecore_x_disp, win, &att)) return 0;
1390 fmt = XRenderFindVisualFormat(_ecore_x_disp, att.visual);
1392 if ((fmt->type == PictTypeDirect) && (fmt->direct.alphaMask)) return 1;
1400 * Creates a new window.
1401 * @param parent The parent window to use. If @p parent is @c 0, the root
1402 * window of the default display is used.
1403 * @param x X position.
1404 * @param y Y position.
1407 * @return The new window handle.
1408 * @ingroup Ecore_X_Window_Create_Group
1411 ecore_x_window_manager_argb_new(Ecore_X_Window parent, int x, int y, int w, int h)
1413 #ifdef ECORE_XRENDER
1414 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1415 return _ecore_x_window_argb_internal_new(parent, x, y, w, h, 1, 0);
1422 * Creates a new window.
1423 * @param parent The parent window to use. If @p parent is @c 0, the root
1424 * window of the default display is used.
1425 * @param x X position.
1426 * @param y Y position.
1429 * @return The new window handle.
1430 * @ingroup Ecore_X_Window_Create_Group
1433 ecore_x_window_argb_new(Ecore_X_Window parent, int x, int y, int w, int h)
1435 #ifdef ECORE_XRENDER
1436 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1437 return _ecore_x_window_argb_internal_new(parent, x, y, w, h, 0, 0);
1444 * Creates a window with the override redirect attribute set to @c True.
1445 * @param parent The parent window to use. If @p parent is @c 0, the root
1446 * window of the default display is used.
1447 * @param x X position.
1448 * @param y Y position.
1451 * @return The new window handle.
1452 * @ingroup Ecore_X_Window_Create_Group
1455 ecore_x_window_override_argb_new(Ecore_X_Window parent, int x, int y, int w, int h)
1457 #ifdef ECORE_XRENDER
1458 LOGFN(__FILE__, __LINE__, __FUNCTION__);
1459 return _ecore_x_window_argb_internal_new(parent, x, y, w, h, 1, 0);