diff options
author | Tim Janik <timj@gtk.org> | 1998-09-25 23:04:32 +0000 |
---|---|---|
committer | Tim Janik <timj@src.gnome.org> | 1998-09-25 23:04:32 +0000 |
commit | c961dd184bee95fe213f770a963e13f34cc1a2de (patch) | |
tree | 3e2bb95ee86c10eeb6d68e9296dc565d11254f01 /gdk | |
parent | 416b69a2c1b79c9f14cfd3099c88d82c2dc6d876 (diff) | |
download | gtk+-c961dd184bee95fe213f770a963e13f34cc1a2de.tar.gz |
new function to get the *real* geometry position of a window, taken
Sat Sep 25 23:33:55 1998 Tim Janik <timj@gtk.org>
* gdk/gdkwindow.c (gdk_window_get_root_origin): new function to get
the *real* geometry position of a window, taken possible window
manager offsets into account.
this has been succesfully tested with fvwm, fvwm-2, bowman, olwm,
olvwm, twm, ctwm, mlvwm, windowmaker and enlightenment.
it does fail though for amiwm which adds windows to a pseudo root
window, and for icewm by a small offset because it defines the
geometry position whithin its border.
* gtk/testgtk.c: added "saved position" test to figure how
gdk_window_get_root_origin() interacts with window managers (repopup
this window to figure ;).
Diffstat (limited to 'gdk')
-rw-r--r-- | gdk/gdk.h | 3 | ||||
-rw-r--r-- | gdk/gdkglobals.c | 2 | ||||
-rw-r--r-- | gdk/gdkwindow.c | 58 | ||||
-rw-r--r-- | gdk/x11/gdkglobals-x11.c | 2 | ||||
-rw-r--r-- | gdk/x11/gdkwindow-x11.c | 58 |
5 files changed, 119 insertions, 4 deletions
@@ -282,6 +282,9 @@ GdkWindowType gdk_window_get_type (GdkWindow *window); gint gdk_window_get_origin (GdkWindow *window, gint *x, gint *y); +void gdk_window_get_root_origin (GdkWindow *window, + gint *x, + gint *y); GdkWindow* gdk_window_get_pointer (GdkWindow *window, gint *x, gint *y, diff --git a/gdk/gdkglobals.c b/gdk/gdkglobals.c index bd8d537852..d21be2f294 100644 --- a/gdk/gdkglobals.c +++ b/gdk/gdkglobals.c @@ -29,7 +29,7 @@ Display *gdk_display = NULL; gint gdk_screen; Window gdk_root_window; Window gdk_leader_window; -GdkWindowPrivate gdk_root_parent; +GdkWindowPrivate gdk_root_parent = { { NULL, }, NULL, }; Atom gdk_wm_delete_window; Atom gdk_wm_take_focus; Atom gdk_wm_protocols; diff --git a/gdk/gdkwindow.c b/gdk/gdkwindow.c index afbcdc4cc9..7c2d9b099c 100644 --- a/gdk/gdkwindow.c +++ b/gdk/gdkwindow.c @@ -208,8 +208,8 @@ gdk_window_init (void) &x, &y, &width, &height, &border_width, &depth); XGetWindowAttributes (gdk_display, gdk_root_window, &xattributes); - gdk_root_parent.xdisplay = gdk_display; gdk_root_parent.xwindow = gdk_root_window; + gdk_root_parent.xdisplay = gdk_display; gdk_root_parent.window_type = GDK_WINDOW_ROOT; gdk_root_parent.window.user_data = NULL; gdk_root_parent.width = width; @@ -1322,6 +1322,62 @@ gdk_window_get_origin (GdkWindow *window, return return_val; } +void +gdk_window_get_root_origin (GdkWindow *window, + gint *x, + gint *y) +{ + GdkWindowPrivate *private; + Window xwindow; + Window xparent; + Window root; + Window *children; + unsigned int nchildren; + + g_return_if_fail (window != NULL); + + private = (GdkWindowPrivate*) window; + if (x) + *x = 0; + if (y) + *y = 0; + if (private->destroyed) + return; + + while (private->parent && ((GdkWindowPrivate*) private->parent)->parent) + private = (GdkWindowPrivate*) private->parent; + if (private->destroyed) + return; + + xparent = private->xwindow; + do + { + xwindow = xparent; + if (!XQueryTree (private->xdisplay, xwindow, + &root, &xparent, + &children, &nchildren)) + return; + + if (children) + XFree (children); + } + while (xparent != root); + + if (xparent == root) + { + unsigned int ww, wh, wb, wd; + int wx, wy; + + if (XGetGeometry (private->xdisplay, xwindow, &root, &wx, &wy, &ww, &wh, &wb, &wd)) + { + if (x) + *x = wx; + if (y) + *y = wy; + } + } +} + GdkWindow* gdk_window_get_pointer (GdkWindow *window, gint *x, diff --git a/gdk/x11/gdkglobals-x11.c b/gdk/x11/gdkglobals-x11.c index bd8d537852..d21be2f294 100644 --- a/gdk/x11/gdkglobals-x11.c +++ b/gdk/x11/gdkglobals-x11.c @@ -29,7 +29,7 @@ Display *gdk_display = NULL; gint gdk_screen; Window gdk_root_window; Window gdk_leader_window; -GdkWindowPrivate gdk_root_parent; +GdkWindowPrivate gdk_root_parent = { { NULL, }, NULL, }; Atom gdk_wm_delete_window; Atom gdk_wm_take_focus; Atom gdk_wm_protocols; diff --git a/gdk/x11/gdkwindow-x11.c b/gdk/x11/gdkwindow-x11.c index afbcdc4cc9..7c2d9b099c 100644 --- a/gdk/x11/gdkwindow-x11.c +++ b/gdk/x11/gdkwindow-x11.c @@ -208,8 +208,8 @@ gdk_window_init (void) &x, &y, &width, &height, &border_width, &depth); XGetWindowAttributes (gdk_display, gdk_root_window, &xattributes); - gdk_root_parent.xdisplay = gdk_display; gdk_root_parent.xwindow = gdk_root_window; + gdk_root_parent.xdisplay = gdk_display; gdk_root_parent.window_type = GDK_WINDOW_ROOT; gdk_root_parent.window.user_data = NULL; gdk_root_parent.width = width; @@ -1322,6 +1322,62 @@ gdk_window_get_origin (GdkWindow *window, return return_val; } +void +gdk_window_get_root_origin (GdkWindow *window, + gint *x, + gint *y) +{ + GdkWindowPrivate *private; + Window xwindow; + Window xparent; + Window root; + Window *children; + unsigned int nchildren; + + g_return_if_fail (window != NULL); + + private = (GdkWindowPrivate*) window; + if (x) + *x = 0; + if (y) + *y = 0; + if (private->destroyed) + return; + + while (private->parent && ((GdkWindowPrivate*) private->parent)->parent) + private = (GdkWindowPrivate*) private->parent; + if (private->destroyed) + return; + + xparent = private->xwindow; + do + { + xwindow = xparent; + if (!XQueryTree (private->xdisplay, xwindow, + &root, &xparent, + &children, &nchildren)) + return; + + if (children) + XFree (children); + } + while (xparent != root); + + if (xparent == root) + { + unsigned int ww, wh, wb, wd; + int wx, wy; + + if (XGetGeometry (private->xdisplay, xwindow, &root, &wx, &wy, &ww, &wh, &wb, &wd)) + { + if (x) + *x = wx; + if (y) + *y = wy; + } + } +} + GdkWindow* gdk_window_get_pointer (GdkWindow *window, gint *x, |