forked from AuroraMiddleware/gtk
Win32: Fix _gdk_windowing_window_at_pointer to correctly return a toplevel
Commit 5ebb32d1ff
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
This commit is contained in:
parent
f9d8f9758b
commit
05e982a11a
@ -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);
|
||||
/* 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);
|
||||
}
|
||||
while (hwndc != hwnd && (hwnd = hwndc, 1));
|
||||
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user