[gtk+/client-side-windows] Add gdk_window_get_root_coords
- From: Alexander Larsson <alexl src gnome org>
- To: svn-commits-list gnome org
- Subject: [gtk+/client-side-windows] Add gdk_window_get_root_coords
- Date: Mon, 8 Jun 2009 14:14:16 -0400 (EDT)
commit 4d54de336b02cdc01cbfd0debc72ede58fc5091b
Author: Alexander Larsson <alexl redhat com>
Date: Mon Jun 8 17:03:47 2009 +0200
Add gdk_window_get_root_coords
We want to be able to map any window coordinate to a root coordinate, not
just the origin, because you can't rely anymore on a simple translation
from window coordinates to parent with offscreen windows. This lets
us e.g. pop up menus in the right place even if they are popped up from
a no-window widget.
---
gdk/gdkoffscreenwindow.c | 36 +++++++++++++++++++-----------------
gdk/gdkwindow.c | 44 +++++++++++++++++++++++++++++++++++++++-----
gdk/gdkwindow.h | 5 +++++
gdk/gdkwindowimpl.h | 8 +++++---
gdk/x11/gdkwindow-x11.c | 20 +++++++++++---------
5 files changed, 79 insertions(+), 34 deletions(-)
diff --git a/gdk/gdkoffscreenwindow.c b/gdk/gdkoffscreenwindow.c
index 5289d71..6e92f62 100644
--- a/gdk/gdkoffscreenwindow.c
+++ b/gdk/gdkoffscreenwindow.c
@@ -735,35 +735,37 @@ to_parent (GdkWindow *window,
}
static gint
-gdk_offscreen_window_get_origin (GdkWindow *window,
- gint *x,
- gint *y)
+gdk_offscreen_window_get_root_coords (GdkWindow *window,
+ gint x,
+ gint y,
+ gint *root_x,
+ gint *root_y)
{
GdkWindow *parent;
int tmpx, tmpy;
- tmpx = 0;
- tmpy = 0;
+ tmpx = x;
+ tmpy = y;
parent = get_offscreen_parent (window);
if (parent)
{
double dx, dy;
- gdk_window_get_origin (parent,
- &tmpx, &tmpy);
-
to_parent (window,
- 0, 0,
+ x, y,
&dx, &dy);
- tmpx = floor (tmpx + dx + 0.5);
- tmpy = floor (tmpy + dy + 0.5);
- }
+ tmpx = floor (dx + 0.5);
+ tmpy = floor (dy + 0.5);
+ gdk_window_get_root_coords (parent,
+ tmpx, tmpy,
+ &tmpx, &tmpy);
+ }
- if (x)
- *x = tmpx;
- if (y)
- *y = tmpy;
+ if (root_x)
+ *root_x = tmpx;
+ if (root_y)
+ *root_y = tmpy;
return TRUE;
}
@@ -1217,7 +1219,7 @@ gdk_offscreen_window_impl_iface_init (GdkWindowImplIface *iface)
iface->set_static_gravities = gdk_offscreen_window_set_static_gravities;
iface->queue_antiexpose = gdk_offscreen_window_queue_antiexpose;
iface->queue_translation = gdk_offscreen_window_queue_translation;
- iface->get_origin = gdk_offscreen_window_get_origin;
+ iface->get_root_coords = gdk_offscreen_window_get_root_coords;
iface->get_deskrelative_origin = gdk_offscreen_window_get_deskrelative_origin;
iface->get_pointer = gdk_offscreen_window_get_pointer;
iface->destroy = gdk_offscreen_window_destroy;
diff --git a/gdk/gdkwindow.c b/gdk/gdkwindow.c
index c8714d2..ca042e6 100644
--- a/gdk/gdkwindow.c
+++ b/gdk/gdkwindow.c
@@ -6952,12 +6952,46 @@ gdk_window_get_origin (GdkWindow *window,
private = (GdkWindowObject *) window;
- GDK_WINDOW_IMPL_GET_IFACE (private->impl)->get_origin (window, x, y);
+ GDK_WINDOW_IMPL_GET_IFACE (private->impl)->get_root_coords (window,
+ private->abs_x,
+ private->abs_y,
+ x, y);
- if (x)
- *x += private->abs_x;
- if (y)
- *y += private->abs_y;
+ return TRUE;
+}
+
+/**
+ * gdk_window_get_root_coords:
+ * @window: a #GdkWindow
+ * @x: X coordinate in window
+ * @y: Y coordinate in window
+ * @root_x: return location for X coordinate
+ * @root_y: return location for Y coordinate
+ *
+ * Obtains the position of a window position in root
+ * window coordinates. This is similar to
+ * gdk_window_get_origin() but allows you go pass
+ * in any position in the window, not just the origin.
+ *
+ * Return value: not meaningful, ignore
+ */
+gint
+gdk_window_get_root_coords (GdkWindow *window,
+ gint x,
+ gint y,
+ gint *root_x,
+ gint *root_y)
+{
+ GdkWindowObject *private;
+
+ g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
+
+ private = (GdkWindowObject *) window;
+
+ GDK_WINDOW_IMPL_GET_IFACE (private->impl)->get_root_coords (window,
+ x + private->abs_x,
+ y + private->abs_y,
+ root_x, root_y);
return TRUE;
}
diff --git a/gdk/gdkwindow.h b/gdk/gdkwindow.h
index 5fefc92..7885b1b 100644
--- a/gdk/gdkwindow.h
+++ b/gdk/gdkwindow.h
@@ -531,6 +531,11 @@ void gdk_window_get_position (GdkWindow *window,
gint gdk_window_get_origin (GdkWindow *window,
gint *x,
gint *y);
+gint gdk_window_get_root_coords (GdkWindow *window,
+ gint x,
+ gint y,
+ gint *root_x,
+ gint *root_y);
#if !defined (GDK_DISABLE_DEPRECATED) || defined (GTK_COMPILATION)
/* Used by gtk_handle_box_button_changed () */
diff --git a/gdk/gdkwindowimpl.h b/gdk/gdkwindowimpl.h
index 7babfea..db1c2ac 100644
--- a/gdk/gdkwindowimpl.h
+++ b/gdk/gdkwindowimpl.h
@@ -80,9 +80,11 @@ struct _GdkWindowImplIface
gint *width,
gint *height,
gint *depth);
- gint (* get_origin) (GdkWindow *window,
- gint *x,
- gint *y);
+ gint (* get_root_coords) (GdkWindow *window,
+ gint x,
+ gint y,
+ gint *root_x,
+ gint *root_y);
gint (* get_deskrelative_origin) (GdkWindow *window,
gint *x,
gint *y);
diff --git a/gdk/x11/gdkwindow-x11.c b/gdk/x11/gdkwindow-x11.c
index 9513843..2d57c76 100644
--- a/gdk/x11/gdkwindow-x11.c
+++ b/gdk/x11/gdkwindow-x11.c
@@ -2759,9 +2759,11 @@ gdk_window_x11_get_geometry (GdkWindow *window,
}
static gint
-gdk_window_x11_get_origin (GdkWindow *window,
- gint *x,
- gint *y)
+gdk_window_x11_get_root_coords (GdkWindow *window,
+ gint x,
+ gint y,
+ gint *root_x,
+ gint *root_y)
{
gint return_val;
Window child;
@@ -2773,16 +2775,16 @@ gdk_window_x11_get_origin (GdkWindow *window,
return_val = XTranslateCoordinates (GDK_WINDOW_XDISPLAY (window),
GDK_WINDOW_XID (window),
GDK_WINDOW_XROOTWIN (window),
- 0, 0, &tx, &ty,
+ x, y, &tx, &ty,
&child);
}
else
return_val = 0;
- if (x)
- *x = tx;
- if (y)
- *y = ty;
+ if (root_x)
+ *root_x = tx;
+ if (root_y)
+ *root_y = ty;
return return_val;
}
@@ -5575,7 +5577,7 @@ gdk_window_impl_iface_init (GdkWindowImplIface *iface)
iface->reparent = gdk_window_x11_reparent;
iface->set_cursor = gdk_window_x11_set_cursor;
iface->get_geometry = gdk_window_x11_get_geometry;
- iface->get_origin = gdk_window_x11_get_origin;
+ iface->get_root_coords = gdk_window_x11_get_root_coords;
iface->get_pointer = gdk_window_x11_get_pointer;
iface->get_deskrelative_origin = gdk_window_x11_get_deskrelative_origin;
iface->shape_combine_region = gdk_window_x11_shape_combine_region;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]