GDK/Win32: Rename "window" in GdkDevice/GdkDeviceManager code

Make the distinction between GdkSurfaces and the underlying native
Windows HWND clearer in the code and in the comments.
This commit is contained in:
Chun-wei Fan 2024-08-19 18:16:44 +08:00
parent df36ab3f93
commit 9ed7cecd42
8 changed files with 103 additions and 102 deletions

View File

@ -61,10 +61,10 @@ _gdk_device_virtual_set_active (GdkDevice *device,
static void
gdk_device_virtual_set_surface_cursor (GdkDevice *device,
GdkSurface *window,
GdkSurface *surface,
GdkCursor *cursor)
{
GdkDisplay *display = gdk_surface_get_display (window);
GdkDisplay *display = gdk_surface_get_display (surface);
GdkWin32HCursor *win32_hcursor = NULL;
if (cursor == NULL)
@ -74,19 +74,19 @@ gdk_device_virtual_set_surface_cursor (GdkDevice *device,
win32_hcursor = gdk_win32_display_get_win32hcursor (GDK_WIN32_DISPLAY (display), cursor);
/* This is correct because the code up the stack already
* checked that cursor is currently inside this window,
* checked that cursor is currently inside this surface,
* and wouldn't have called this function otherwise.
*/
if (win32_hcursor != NULL)
SetCursor (gdk_win32_hcursor_get_handle (win32_hcursor));
g_set_object (&GDK_WIN32_SURFACE (window)->cursor, win32_hcursor);
g_set_object (&GDK_WIN32_SURFACE (surface)->cursor, win32_hcursor);
}
void
gdk_device_virtual_query_state (GdkDevice *device,
GdkSurface *window,
GdkSurface **child_window,
GdkSurface *surface,
GdkSurface **child_surface,
double *win_x,
double *win_y,
GdkModifierType *mask)
@ -94,14 +94,14 @@ gdk_device_virtual_query_state (GdkDevice *device,
GdkDeviceVirtual *virtual = GDK_DEVICE_VIRTUAL (device);
_gdk_device_win32_query_state (virtual->active_device,
window, child_window,
surface, child_surface,
win_x, win_y,
mask);
}
static GdkGrabStatus
gdk_device_virtual_grab (GdkDevice *device,
GdkSurface *window,
GdkSurface *surface,
gboolean owner_events,
GdkEventMask event_mask,
GdkSurface *confine_to,
@ -124,7 +124,7 @@ gdk_device_virtual_grab (GdkDevice *device,
else
SetCursor (LoadCursor (NULL, IDC_ARROW));
SetCapture (GDK_SURFACE_HWND (window));
SetCapture (GDK_SURFACE_HWND (surface));
}
return GDK_GRAB_SUCCESS;

View File

@ -49,8 +49,8 @@ void _gdk_device_virtual_set_active (GdkDevice *device,
void
gdk_device_virtual_query_state (GdkDevice *device,
GdkSurface *window,
GdkSurface **child_window,
GdkSurface *surface,
GdkSurface **child_surface,
double *win_x,
double *win_y,
GdkModifierType *mask);

View File

@ -33,7 +33,7 @@ G_DEFINE_TYPE (GdkDeviceWin32, gdk_device_win32, GDK_TYPE_DEVICE)
static void
gdk_device_win32_set_surface_cursor (GdkDevice *device,
GdkSurface *window,
GdkSurface *surface,
GdkCursor *cursor)
{
}
@ -66,8 +66,8 @@ get_current_mask (void)
static void
gdk_device_win32_query_state (GdkDevice *device,
GdkSurface *window,
GdkSurface **child_window,
GdkSurface *surface,
GdkSurface **child_surface,
double *win_x,
double *win_y,
GdkModifierType *mask)
@ -76,10 +76,10 @@ gdk_device_win32_query_state (GdkDevice *device,
HWND hwnd, hwndc;
int scale;
if (window)
if (surface)
{
scale = GDK_WIN32_SURFACE (window)->surface_scale;
hwnd = GDK_SURFACE_HWND (window);
scale = GDK_WIN32_SURFACE (surface)->surface_scale;
hwnd = GDK_SURFACE_HWND (surface);
}
else
{
@ -100,14 +100,14 @@ gdk_device_win32_query_state (GdkDevice *device,
if (win_y)
*win_y = point.y / scale;
if (hwnd && child_window)
if (hwnd && child_surface)
{
hwndc = ChildWindowFromPoint (hwnd, point);
if (hwndc && hwndc != hwnd)
*child_window = gdk_win32_handle_table_lookup_ (hwndc);
*child_surface = gdk_win32_handle_table_lookup_ (hwndc);
else
*child_window = NULL; /* Direct child unknown to gdk */
*child_surface = NULL; /* Direct child unknown to gdk */
}
if (mask)
@ -116,23 +116,23 @@ gdk_device_win32_query_state (GdkDevice *device,
void
_gdk_device_win32_query_state (GdkDevice *device,
GdkSurface *window,
GdkSurface **child_window,
GdkSurface *surface,
GdkSurface **child_surface,
double *win_x,
double *win_y,
GdkModifierType *mask)
{
if (GDK_IS_DEVICE_VIRTUAL (device))
gdk_device_virtual_query_state (device, window, child_window, win_x, win_y, mask);
gdk_device_virtual_query_state (device, surface, child_surface, win_x, win_y, mask);
else if (GDK_IS_DEVICE_WINTAB (device))
gdk_device_wintab_query_state (device, window, child_window, win_x, win_y, mask);
gdk_device_wintab_query_state (device, surface, child_surface, win_x, win_y, mask);
else
gdk_device_win32_query_state (device, window, child_window, win_x, win_y, mask);
gdk_device_win32_query_state (device, surface, child_surface, win_x, win_y, mask);
}
static GdkGrabStatus
gdk_device_win32_grab (GdkDevice *device,
GdkSurface *window,
GdkSurface *surface,
gboolean owner_events,
GdkEventMask event_mask,
GdkSurface *confine_to,
@ -162,7 +162,7 @@ _gdk_device_win32_surface_at_position (GdkDevice *device,
double *win_y,
GdkModifierType *mask)
{
GdkSurface *window = NULL;
GdkSurface *surface = NULL;
GdkWin32Surface *impl = NULL;
POINT screen_pt, client_pt;
HWND hwnd;
@ -173,21 +173,21 @@ _gdk_device_win32_surface_at_position (GdkDevice *device,
/* Use WindowFromPoint instead of ChildWindowFromPoint(Ex).
* Only WindowFromPoint is able to look through transparent
* layered windows.
* layered HWNDs.
*/
hwnd = GetAncestor (WindowFromPoint (screen_pt), GA_ROOT);
/* Verify that we're really inside the client area of the window */
/* Verify that we're really inside the client area of the HWND */
GetClientRect (hwnd, &rect);
screen_to_client (hwnd, screen_pt, &client_pt);
if (!PtInRect (&rect, client_pt))
hwnd = NULL;
window = gdk_win32_handle_table_lookup_ (hwnd);
surface = gdk_win32_handle_table_lookup_ (hwnd);
if (window && (win_x || win_y))
if (surface && (win_x || win_y))
{
impl = GDK_WIN32_SURFACE (window);
impl = GDK_WIN32_SURFACE (surface);
if (win_x)
*win_x = client_pt.x / impl->surface_scale;
@ -195,7 +195,7 @@ _gdk_device_win32_surface_at_position (GdkDevice *device,
*win_y = client_pt.y / impl->surface_scale;
}
return window;
return surface;
}
static void

View File

@ -48,15 +48,15 @@ get_keyboard_mask (void)
static void
gdk_device_winpointer_set_surface_cursor (GdkDevice *device,
GdkSurface *window,
GdkSurface *surface,
GdkCursor *cursor)
{
}
void
gdk_device_winpointer_query_state (GdkDevice *device,
GdkSurface *window,
GdkSurface **child_window,
GdkSurface *surface,
GdkSurface **child_surface,
double *win_x,
double *win_y,
GdkModifierType *mask)
@ -67,10 +67,10 @@ gdk_device_winpointer_query_state (GdkDevice *device,
int scale;
device_winpointer = GDK_DEVICE_WINPOINTER (device);
if (window)
if (surface)
{
scale = GDK_WIN32_SURFACE (window)->surface_scale;
hwnd = GDK_SURFACE_HWND (window);
scale = GDK_WIN32_SURFACE (surface)->surface_scale;
hwnd = GDK_SURFACE_HWND (surface);
}
else
{
@ -91,14 +91,14 @@ gdk_device_winpointer_query_state (GdkDevice *device,
if (win_y)
*win_y = point.y / scale;
if (hwnd && child_window)
if (hwnd && child_surface)
{
hwndc = ChildWindowFromPoint (hwnd, point);
if (hwndc && hwndc != hwnd)
*child_window = gdk_win32_handle_table_lookup_ (hwndc);
*child_surface = gdk_win32_handle_table_lookup_ (hwndc);
else
*child_window = NULL; /* Direct child unknown to gdk */
*child_surface = NULL; /* Direct child unknown to gdk */
}
if (mask)
@ -110,7 +110,7 @@ gdk_device_winpointer_query_state (GdkDevice *device,
static GdkGrabStatus
gdk_device_winpointer_grab (GdkDevice *device,
GdkSurface *window,
GdkSurface *surface,
gboolean owner_events,
GdkEventMask event_mask,
GdkSurface *confine_to,
@ -150,7 +150,7 @@ gdk_device_winpointer_surface_at_position (GdkDevice *device,
/* Use WindowFromPoint instead of ChildWindowFromPoint(Ex).
* Only WindowFromPoint is able to look through transparent
* layered windows.
* layered HWNDs.
*/
hwnd = GetAncestor (WindowFromPoint (screen_pt), GA_ROOT);

View File

@ -56,15 +56,15 @@ get_current_mask (void)
static void
gdk_device_wintab_set_surface_cursor (GdkDevice *device,
GdkSurface *window,
GdkSurface *surface,
GdkCursor *cursor)
{
}
void
gdk_device_wintab_query_state (GdkDevice *device,
GdkSurface *window,
GdkSurface **child_window,
GdkSurface *surface,
GdkSurface **child_surface,
double *win_x,
double *win_y,
GdkModifierType *mask)
@ -75,10 +75,10 @@ gdk_device_wintab_query_state (GdkDevice *device,
int scale;
device_wintab = GDK_DEVICE_WINTAB (device);
if (window)
if (surface)
{
scale = GDK_WIN32_SURFACE (window)->surface_scale;
hwnd = GDK_SURFACE_HWND (window);
scale = GDK_WIN32_SURFACE (surface)->surface_scale;
hwnd = GDK_SURFACE_HWND (surface);
}
else
{
@ -99,14 +99,14 @@ gdk_device_wintab_query_state (GdkDevice *device,
if (win_y)
*win_y = point.y / scale;
if (hwnd && child_window)
if (hwnd && child_surface)
{
hwndc = ChildWindowFromPoint (hwnd, point);
if (hwndc && hwndc != hwnd)
*child_window = gdk_win32_handle_table_lookup_ (hwndc);
*child_surface = gdk_win32_handle_table_lookup_ (hwndc);
else
*child_window = NULL; /* Direct child unknown to gdk */
*child_surface = NULL; /* Direct child unknown to gdk */
}
if (mask)
@ -123,7 +123,7 @@ gdk_device_wintab_query_state (GdkDevice *device,
static GdkGrabStatus
gdk_device_wintab_grab (GdkDevice *device,
GdkSurface *window,
GdkSurface *surface,
gboolean owner_events,
GdkEventMask event_mask,
GdkSurface *confine_to,
@ -150,7 +150,7 @@ gdk_device_wintab_surface_at_position (GdkDevice *device,
void
_gdk_device_wintab_translate_axes (GdkDeviceWintab *device_wintab,
GdkSurface *window,
GdkSurface *surface,
double *axes,
double *x,
double *y)
@ -162,7 +162,7 @@ _gdk_device_wintab_translate_axes (GdkDeviceWintab *device_wintab,
int i;
device = GDK_DEVICE (device_wintab);
impl_surface = window;
impl_surface = surface;
temp_x = temp_y = 0;
gdk_surface_get_origin (impl_surface, &root_x, &root_y);
@ -181,12 +181,12 @@ _gdk_device_wintab_translate_axes (GdkDeviceWintab *device_wintab,
HMONITOR hmonitor;
MONITORINFO minfo = {sizeof (MONITORINFO),};
hmonitor = MonitorFromWindow (GDK_SURFACE_HWND (window),
hmonitor = MonitorFromWindow (GDK_SURFACE_HWND (surface),
MONITOR_DEFAULTTONEAREST);
GetMonitorInfo (hmonitor, &minfo);
/* XXX: the dimensions from minfo may need to be scaled for HiDPI usage */
_gdk_device_translate_screen_coord (device, window,
_gdk_device_translate_screen_coord (device, surface,
root_x, root_y,
minfo.rcWork.right - minfo.rcWork.left,
minfo.rcWork.bottom - minfo.rcWork.top,

View File

@ -60,15 +60,15 @@ struct _GdkDeviceWintabClass
GType gdk_device_wintab_get_type (void) G_GNUC_CONST;
void _gdk_device_wintab_translate_axes (GdkDeviceWintab *device,
GdkSurface *window,
GdkSurface *surface,
double *axes,
double *x,
double *y);
void
gdk_device_wintab_query_state (GdkDevice *device,
GdkSurface *window,
GdkSurface **child_window,
GdkSurface *surface,
GdkSurface **child_surface,
double *win_x,
double *win_y,
GdkModifierType *mask);

View File

@ -45,8 +45,9 @@
#define DEBUG_WINTAB 1 /* Verbose debug messages enabled */
#define TWOPI (2 * G_PI)
/* TODO: get rid of these global variables */
static GList *wintab_contexts = NULL;
static GdkSurface *wintab_window = NULL;
static GdkSurface *wintab_surface = NULL;
extern int _gdk_input_ignore_core;
typedef UINT (WINAPI *t_WTInfoA) (UINT a, UINT b, LPVOID c);
@ -426,10 +427,10 @@ wintab_init_check (GdkDeviceManagerWin32 *device_manager)
GDK_NOTE (INPUT, g_print ("NDEVICES: %d, NCURSORS: %d\n",
ndevices, ncursors));
#endif
/* Create a dummy window to receive wintab events */
wintab_window = gdk_win32_drag_surface_new (display);
/* Create a dummy surface to receive wintab events */
wintab_surface = gdk_win32_drag_surface_new (display);
g_object_ref (wintab_window);
g_object_ref (wintab_surface);
for (devix = 0; devix < ndevices; devix++)
{
@ -492,7 +493,7 @@ wintab_init_check (GdkDeviceManagerWin32 *device_manager)
print_lc(&lc)));
#endif
hctx = g_new (HCTX, 1);
if ((*hctx = (*p_WTOpenA) (GDK_SURFACE_HWND (wintab_window), &lc, TRUE)) == NULL)
if ((*hctx = (*p_WTOpenA) (GDK_SURFACE_HWND (wintab_surface), &lc, TRUE)) == NULL)
{
g_warning ("gdk_input_wintab_init: WTOpen failed");
return;
@ -653,7 +654,7 @@ wintab_init_check (GdkDeviceManagerWin32 *device_manager)
/* Only initialize Wintab after the default display is set for
* the first time. WTOpenA() executes code beyond our control,
* and it can cause messages to be sent to the application even
* before a window is opened. GDK has to be in a fit state to
* before a surface HWND is opened. GDK has to be in a fit state to
* handle them when they come.
*
* https://bugzilla.gnome.org/show_bug.cgi?id=774379
@ -798,7 +799,7 @@ _gdk_wintab_set_tablet_active (void)
HCTX *hctx;
/* Bring the contexts to the top of the overlap order when one of the
* application's windows is activated */
* application's HWNDs is activated */
if (!wintab_contexts)
return; /* No tablet devices found, or Wintab not initialized yet */
@ -908,7 +909,7 @@ gdk_device_manager_find_wintab_device (GdkDeviceManagerWin32 *device_manager,
GdkEvent *
gdk_wintab_make_event (GdkDisplay *display,
MSG *msg,
GdkSurface *window)
GdkSurface *surface)
{
GdkDeviceManagerWin32 *device_manager;
GdkDeviceWintab *source_device = NULL;
@ -932,21 +933,21 @@ gdk_wintab_make_event (GdkDisplay *display,
*/
static guint button_map[8] = {0, 1, 4, 5, 2, 3, 6, 7};
if (window != wintab_window)
if (surface != wintab_surface)
{
g_warning ("gdk_wintab_make_event: not wintab_window?");
g_warning ("gdk_wintab_make_event: not wintab_surface?");
return NULL;
}
device_manager = GDK_DEVICE_MANAGER_WIN32 (_gdk_device_manager);
window = gdk_device_get_surface_at_position (device_manager->core_pointer, &x, &y);
surface = gdk_device_get_surface_at_position (device_manager->core_pointer, &x, &y);
if (window)
g_object_ref (window);
if (surface)
g_object_ref (surface);
GDK_NOTE (EVENTS_OR_INPUT,
g_print ("gdk_wintab_make_event: window=%p %+g%+g\n",
window ? GDK_SURFACE_HWND (window) : NULL, x, y));
g_print ("gdk_wintab_make_event: surface=%p %+g%+g\n",
surface ? GDK_SURFACE_HWND (surface) : NULL, x, y));
if (msg->message == WT_PACKET || msg->message == WT_CSRCHANGE)
{
@ -1002,7 +1003,7 @@ gdk_wintab_make_event (GdkDisplay *display,
if (source_device == NULL)
return NULL;
/* Don't produce any button or motion events while a window is being
/* Don't produce any button or motion events while a surface is being
* moved or resized, see bug #151090.
*/
if (_modal_operation_in_progress & GDK_WIN32_MODAL_OP_SIZEMOVE_MASK)
@ -1015,12 +1016,12 @@ gdk_wintab_make_event (GdkDisplay *display,
if (last_grab && last_grab->surface)
{
g_object_unref (window);
g_object_unref (surface);
window = g_object_ref (last_grab->surface);
surface = g_object_ref (last_grab->surface);
}
if (window == NULL)
if (surface == NULL)
{
GDK_NOTE (EVENTS_OR_INPUT, g_print ("... is root\n"));
return NULL;
@ -1086,7 +1087,7 @@ gdk_wintab_make_event (GdkDisplay *display,
axes = g_new (double, GDK_AXIS_LAST);
_gdk_device_wintab_translate_axes (source_device,
window,
surface,
axes,
&event_x,
&event_y);
@ -1098,7 +1099,7 @@ gdk_wintab_make_event (GdkDisplay *display,
| GDK_BUTTON5_MASK));
event = gdk_button_event_new (event_type,
window,
surface,
device_manager->core_pointer,
NULL,
_gdk_win32_get_next_tick (msg->time),
@ -1120,7 +1121,7 @@ gdk_wintab_make_event (GdkDisplay *display,
{
axes = g_new (double, GDK_AXIS_LAST);
_gdk_device_wintab_translate_axes (source_device,
window,
surface,
axes,
&event_x,
&event_y);
@ -1131,7 +1132,7 @@ gdk_wintab_make_event (GdkDisplay *display,
| GDK_BUTTON3_MASK | GDK_BUTTON4_MASK
| GDK_BUTTON5_MASK));
event = gdk_motion_event_new (window,
event = gdk_motion_event_new (surface,
device_manager->core_pointer,
NULL,
_gdk_win32_get_next_tick (msg->time),

View File

@ -60,7 +60,7 @@ GType gdk_device_manager_win32_get_type (void) G_GNUC_CONST;
void _gdk_wintab_set_tablet_active (void);
GdkEvent * gdk_wintab_make_event (GdkDisplay *display,
MSG *msg,
GdkSurface *window);
GdkSurface *surface);
G_END_DECLS