W32: avoid code duplication in gdkdevice-win32|virtual
The same get_position function is cut and pasted in the two classes.
This commit is contained in:

committed by
Ignacio Casal Quinteiro

parent
75b3eec7a6
commit
7f17468afc
@ -24,6 +24,7 @@
|
|||||||
|
|
||||||
#include "gdkdisplayprivate.h"
|
#include "gdkdisplayprivate.h"
|
||||||
#include "gdkdevice-virtual.h"
|
#include "gdkdevice-virtual.h"
|
||||||
|
#include "gdkdevice-win32.h"
|
||||||
#include "gdkwin32.h"
|
#include "gdkwin32.h"
|
||||||
|
|
||||||
static gboolean gdk_device_virtual_get_history (GdkDevice *device,
|
static gboolean gdk_device_virtual_get_history (GdkDevice *device,
|
||||||
@ -61,11 +62,6 @@ static GdkGrabStatus gdk_device_virtual_grab (GdkDevice *device,
|
|||||||
guint32 time_);
|
guint32 time_);
|
||||||
static void gdk_device_virtual_ungrab (GdkDevice *device,
|
static void gdk_device_virtual_ungrab (GdkDevice *device,
|
||||||
guint32 time_);
|
guint32 time_);
|
||||||
static GdkWindow * gdk_device_virtual_window_at_position (GdkDevice *device,
|
|
||||||
gdouble *win_x,
|
|
||||||
gdouble *win_y,
|
|
||||||
GdkModifierType *mask,
|
|
||||||
gboolean get_toplevel);
|
|
||||||
static void gdk_device_virtual_select_window_events (GdkDevice *device,
|
static void gdk_device_virtual_select_window_events (GdkDevice *device,
|
||||||
GdkWindow *window,
|
GdkWindow *window,
|
||||||
GdkEventMask event_mask);
|
GdkEventMask event_mask);
|
||||||
@ -85,7 +81,7 @@ gdk_device_virtual_class_init (GdkDeviceVirtualClass *klass)
|
|||||||
device_class->query_state = gdk_device_virtual_query_state;
|
device_class->query_state = gdk_device_virtual_query_state;
|
||||||
device_class->grab = gdk_device_virtual_grab;
|
device_class->grab = gdk_device_virtual_grab;
|
||||||
device_class->ungrab = gdk_device_virtual_ungrab;
|
device_class->ungrab = gdk_device_virtual_ungrab;
|
||||||
device_class->window_at_position = gdk_device_virtual_window_at_position;
|
device_class->window_at_position = _gdk_device_win32_window_at_position;
|
||||||
device_class->select_window_events = gdk_device_virtual_select_window_events;
|
device_class->select_window_events = gdk_device_virtual_select_window_events;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -311,94 +307,6 @@ gdk_device_virtual_ungrab (GdkDevice *device,
|
|||||||
_gdk_display_device_grab_update (display, device, device, 0);
|
_gdk_display_device_grab_update (display, device, device, 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_virtual_window_at_position (GdkDevice *device,
|
|
||||||
gdouble *win_x,
|
|
||||||
gdouble *win_y,
|
|
||||||
GdkModifierType *mask,
|
|
||||||
gboolean get_toplevel)
|
|
||||||
{
|
|
||||||
GdkWindow *window = NULL;
|
|
||||||
POINT screen_pt, client_pt;
|
|
||||||
HWND hwnd, hwndc;
|
|
||||||
RECT rect;
|
|
||||||
|
|
||||||
GetCursorPos (&screen_pt);
|
|
||||||
|
|
||||||
if (get_toplevel)
|
|
||||||
{
|
|
||||||
/* 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);
|
|
||||||
|
|
||||||
/* Verify that we're really inside the client area of the window */
|
|
||||||
if (hwndc != hwnd)
|
|
||||||
{
|
|
||||||
GetClientRect (hwndc, &rect);
|
|
||||||
screen_to_client (hwndc, screen_pt, &client_pt);
|
|
||||||
if (!PtInRect (&rect, client_pt))
|
|
||||||
hwndc = hwnd;
|
|
||||||
}
|
|
||||||
|
|
||||||
} while (hwndc != hwnd && (hwnd = hwndc, 1));
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
hwnd = WindowFromPoint (screen_pt);
|
|
||||||
|
|
||||||
/* Verify that we're really inside the client area of the window */
|
|
||||||
GetClientRect (hwnd, &rect);
|
|
||||||
screen_to_client (hwnd, screen_pt, &client_pt);
|
|
||||||
if (!PtInRect (&rect, client_pt))
|
|
||||||
hwnd = NULL;
|
|
||||||
|
|
||||||
/* 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (window && (win_x || win_y))
|
|
||||||
{
|
|
||||||
if (win_x)
|
|
||||||
*win_x = client_pt.x;
|
|
||||||
if (win_y)
|
|
||||||
*win_y = client_pt.y;
|
|
||||||
}
|
|
||||||
|
|
||||||
return window;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gdk_device_virtual_select_window_events (GdkDevice *device,
|
gdk_device_virtual_select_window_events (GdkDevice *device,
|
||||||
GdkWindow *window,
|
GdkWindow *window,
|
||||||
|
@ -61,11 +61,6 @@ static GdkGrabStatus gdk_device_win32_grab (GdkDevice *device,
|
|||||||
guint32 time_);
|
guint32 time_);
|
||||||
static void gdk_device_win32_ungrab (GdkDevice *device,
|
static void gdk_device_win32_ungrab (GdkDevice *device,
|
||||||
guint32 time_);
|
guint32 time_);
|
||||||
static GdkWindow * gdk_device_win32_window_at_position (GdkDevice *device,
|
|
||||||
gdouble *win_x,
|
|
||||||
gdouble *win_y,
|
|
||||||
GdkModifierType *mask,
|
|
||||||
gboolean get_toplevel);
|
|
||||||
static void gdk_device_win32_select_window_events (GdkDevice *device,
|
static void gdk_device_win32_select_window_events (GdkDevice *device,
|
||||||
GdkWindow *window,
|
GdkWindow *window,
|
||||||
GdkEventMask event_mask);
|
GdkEventMask event_mask);
|
||||||
@ -85,7 +80,7 @@ gdk_device_win32_class_init (GdkDeviceWin32Class *klass)
|
|||||||
device_class->query_state = gdk_device_win32_query_state;
|
device_class->query_state = gdk_device_win32_query_state;
|
||||||
device_class->grab = gdk_device_win32_grab;
|
device_class->grab = gdk_device_win32_grab;
|
||||||
device_class->ungrab = gdk_device_win32_ungrab;
|
device_class->ungrab = gdk_device_win32_ungrab;
|
||||||
device_class->window_at_position = gdk_device_win32_window_at_position;
|
device_class->window_at_position = _gdk_device_win32_window_at_position;
|
||||||
device_class->select_window_events = gdk_device_win32_select_window_events;
|
device_class->select_window_events = gdk_device_win32_select_window_events;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -263,8 +258,8 @@ screen_to_client (HWND hwnd, POINT screen_pt, POINT *client_pt)
|
|||||||
ScreenToClient (hwnd, client_pt);
|
ScreenToClient (hwnd, client_pt);
|
||||||
}
|
}
|
||||||
|
|
||||||
static GdkWindow *
|
GdkWindow *
|
||||||
gdk_device_win32_window_at_position (GdkDevice *device,
|
_gdk_device_win32_window_at_position (GdkDevice *device,
|
||||||
gdouble *win_x,
|
gdouble *win_x,
|
||||||
gdouble *win_y,
|
gdouble *win_y,
|
||||||
GdkModifierType *mask,
|
GdkModifierType *mask,
|
||||||
|
@ -44,6 +44,12 @@ struct _GdkDeviceWin32Class
|
|||||||
|
|
||||||
GType gdk_device_win32_get_type (void) G_GNUC_CONST;
|
GType gdk_device_win32_get_type (void) G_GNUC_CONST;
|
||||||
|
|
||||||
|
GdkWindow *_gdk_device_win32_window_at_position (GdkDevice *device,
|
||||||
|
gdouble *win_x,
|
||||||
|
gdouble *win_y,
|
||||||
|
GdkModifierType *mask,
|
||||||
|
gboolean get_toplevel);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
#endif /* __GDK_DEVICE_WIN32_H__ */
|
#endif /* __GDK_DEVICE_WIN32_H__ */
|
||||||
|
Reference in New Issue
Block a user