summaryrefslogtreecommitdiff
path: root/gdk/win32/gdkdevice-win32.c
diff options
context:
space:
mode:
authorPeter Clifton <pcjc2@cam.ac.uk>2011-09-10 16:30:56 +0100
committerAlexander Larsson <alexl@redhat.com>2011-11-10 17:40:50 +0100
commit05e982a11a7e69c93d5cba42847f838bc7e108d5 (patch)
tree51b7a6ef3f66d8acecb5ca1fa693e8950d488555 /gdk/win32/gdkdevice-win32.c
parentf9d8f9758bfe1417416e0b2bbea955f1cee75674 (diff)
downloadgtk+-05e982a11a7e69c93d5cba42847f838bc7e108d5.tar.gz
Win32: Fix _gdk_windowing_window_at_pointer to correctly return a toplevel
Commit 5ebb32d1ffa23241d562fb4d5be02bc6f156b515 didn't add the correct code to find the toplevel window. The WindowFromPoint() function does not return the toplevel window in the hierarchy, it returns the deepest non-disabled, non-invisible child. As we don't use invisible or disabled windows, we don't actually need to use the ChildWindowFromPoint walk for the non get_toplevel case, so we can remove that code path. To find a toplevel, we need to start from the desktop and work up, using ChildWindowFromPointEx (to ignore invisible and disabled windows). If we don't ignore invisible and disabled windows (as is the case with the ChildWindowFromPoint call, we are liable to get returns of hidden or disabled children of the desktop which don't belong to us, but notionally occupy the same area under the pointer. An alternative might be to start our walk with one of the children of the desktop owned by our process and thread - which we can enumerate using, the EnumThreadWindows call, or (presumably) determine internally. This would not work when we are inside a GtkSocket though, as the children of the desktop would belong to the process owning the GtkPlug - we would have to rely on our own list of windows. For correctness, this commit adds tests to ensure that we don't try to return either x or y window coordinates if that corresponding pointer is NULL. https://bugzilla.gnome.org/show_bug.cgi?id=658842
Diffstat (limited to 'gdk/win32/gdkdevice-win32.c')
-rw-r--r--gdk/win32/gdkdevice-win32.c76
1 files changed, 50 insertions, 26 deletions
diff --git a/gdk/win32/gdkdevice-win32.c b/gdk/win32/gdkdevice-win32.c
index e61dfd53d0..27bf807979 100644
--- a/gdk/win32/gdkdevice-win32.c
+++ b/gdk/win32/gdkdevice-win32.c
@@ -343,6 +343,13 @@ gdk_device_win32_ungrab (GdkDevice *device,
_gdk_display_device_grab_update (display, device, NULL, 0);
}
+static void
+screen_to_client (HWND hwnd, POINT screen_pt, POINT *client_pt)
+{
+ *client_pt = screen_pt;
+ ScreenToClient (hwnd, client_pt);
+}
+
static GdkWindow *
gdk_device_win32_window_at_position (GdkDevice *device,
gint *win_x,
@@ -350,45 +357,62 @@ gdk_device_win32_window_at_position (GdkDevice *device,
GdkModifierType *mask,
gboolean get_toplevel)
{
- GdkWindow *window;
- POINT point, pointc;
+ GdkWindow *window = NULL;
+ POINT screen_pt, client_pt;
HWND hwnd, hwndc;
RECT rect;
- GetCursorPos (&pointc);
- point = pointc;
- hwnd = WindowFromPoint (point);
+ GetCursorPos (&screen_pt);
- if (hwnd == NULL)
+ if (get_toplevel)
{
- window = _gdk_root;
- *win_x = pointc.x + _gdk_offset_x;
- *win_y = pointc.y + _gdk_offset_y;
- return window;
- }
+ /* Only consider visible children of the desktop to avoid the various
+ * non-visible windows you often find on a running Windows box. These
+ * might overlap our windows and cause our walk to fail. As we assume
+ * WindowFromPoint() can find our windows, we follow similar logic
+ * here, and ignore invisible and disabled windows.
+ */
+ hwnd = GetDesktopWindow ();
+ do {
+ window = gdk_win32_handle_table_lookup (hwnd);
+
+ if (window != NULL &&
+ GDK_WINDOW_TYPE (window) != GDK_WINDOW_ROOT &&
+ GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN)
+ break;
+
+ screen_to_client (hwnd, screen_pt, &client_pt);
+ hwndc = ChildWindowFromPointEx (hwnd, client_pt, CWP_SKIPDISABLED |
+ CWP_SKIPINVISIBLE);
+ } while (hwndc != hwnd && (hwnd = hwndc, 1));
- ScreenToClient (hwnd, &point);
-
- do
+ }
+ else
{
- if (get_toplevel &&
- (window = gdk_win32_handle_table_lookup (hwnd)) != NULL &&
- GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN)
- break;
+ hwnd = WindowFromPoint (screen_pt);
- hwndc = ChildWindowFromPoint (hwnd, point);
- ClientToScreen (hwnd, &point);
- ScreenToClient (hwndc, &point);
- }
- while (hwndc != hwnd && (hwnd = hwndc, 1));
+ /* If we didn't hit any window at that point, return the desktop */
+ if (hwnd == NULL)
+ {
+ if (win_x)
+ *win_x = screen_pt.x + _gdk_offset_x;
+ if (win_y)
+ *win_y = screen_pt.y + _gdk_offset_y;
+ return _gdk_root;
+ }
- window = gdk_win32_handle_table_lookup (hwnd);
+ window = gdk_win32_handle_table_lookup (hwnd);
+ }
if (window && (win_x || win_y))
{
+ screen_to_client (hwnd, screen_pt, &client_pt);
GetClientRect (hwnd, &rect);
- *win_x = point.x - rect.left;
- *win_y = point.y - rect.top;
+
+ if (win_x)
+ *win_x = client_pt.x - rect.left;
+ if (win_y)
+ *win_y = client_pt.y - rect.top;
}
return window;