GdkWin32: Remove the global screen offset

Removes the _gdk_offset_x / _gdk_offset_y variables,
as today are not needed anymore.
This commit is contained in:
Luca Bacci 2021-10-29 18:39:52 +02:00
parent 8338e55549
commit 4c8e703803
No known key found for this signature in database
GPG Key ID: 8E3C8D989C98883D
10 changed files with 48 additions and 165 deletions

View File

@ -100,15 +100,6 @@ gdk_device_win32_query_state (GdkDevice *device,
if (win_y)
*win_y = point.y / scale;
if (window)
{
if (win_x)
*win_x += _gdk_offset_x;
if (win_y)
*win_y += _gdk_offset_y;
}
if (hwnd && child_window)
{
hwndc = ChildWindowFromPoint (hwnd, point);

View File

@ -91,15 +91,6 @@ gdk_device_winpointer_query_state (GdkDevice *device,
if (win_y)
*win_y = point.y / scale;
if (!window)
{
if (win_x)
*win_x += _gdk_offset_x;
if (win_y)
*win_y += _gdk_offset_y;
}
if (hwnd && child_window)
{
hwndc = ChildWindowFromPoint (hwnd, point);

View File

@ -99,15 +99,6 @@ gdk_device_wintab_query_state (GdkDevice *device,
if (win_y)
*win_y = point.y / scale;
if (!window)
{
if (win_x)
*win_x += _gdk_offset_x;
if (win_y)
*win_y += _gdk_offset_y;
}
if (hwnd && child_window)
{
hwndc = ChildWindowFromPoint (hwnd, point);

View File

@ -2082,8 +2082,8 @@ gdk_dnd_handle_motion_event (GdkDrag *drag,
API_CALL (PostThreadMessage, (clipdrop->dnd_thread_id,
WM_MOUSEMOVE,
key_state,
MAKELPARAM (x_root * drag_win32->scale - _gdk_offset_x,
y_root * drag_win32->scale - _gdk_offset_y)));
MAKELPARAM (x_root * drag_win32->scale,
y_root * drag_win32->scale)));
return TRUE;
}

View File

@ -425,14 +425,9 @@ set_source_actions_helper (GdkDrop *drop,
return actions;
}
/* Utility function to translate win32 screen coordinates to
* client coordinates (i.e. relative to the surface origin)
*
* Note that input is expected to be:
* a) NOT scaled by dpi_scale
* b) NOT translated by the GDK screen offset (gdk_offset_x / y)
*
* This utility function preserves subpixel precision
/* Utility function to translate screen coordinates to surface-relative
* coordinates. This routine only works with pixel values that aren't
* scaled by any GDK DPI scale factor.
*/
static void
unscaled_screen_to_client (GdkSurface* surface,
@ -514,8 +509,8 @@ idroptarget_dragenter (LPDROPTARGET This,
grfKeyState);
set_data_object (&ctx->data_object, pDataObj);
pt_x = pt.x / drop_win32->scale + _gdk_offset_x;
pt_y = pt.y / drop_win32->scale + _gdk_offset_y;
pt_x = pt.x / drop_win32->scale;
pt_y = pt.y / drop_win32->scale;
unscaled_screen_to_client (ctx->surface, pt.x, pt.y, &x, &y);
x /= drop_win32->scale;
@ -554,8 +549,8 @@ idroptarget_dragover (LPDROPTARGET This,
{
drop_target_context *ctx = (drop_target_context *) This;
GdkWin32Drop *drop_win32 = GDK_WIN32_DROP (ctx->drop);
int pt_x = pt.x / drop_win32->scale + _gdk_offset_x;
int pt_y = pt.y / drop_win32->scale + _gdk_offset_y;
int pt_x = pt.x / drop_win32->scale;
int pt_y = pt.y / drop_win32->scale;
GdkDragAction source_actions;
GdkDragAction dest_actions;
@ -624,8 +619,6 @@ idroptarget_drop (LPDROPTARGET This,
{
drop_target_context *ctx = (drop_target_context *) This;
GdkWin32Drop *drop_win32 = GDK_WIN32_DROP (ctx->drop);
int pt_x = pt.x / drop_win32->scale + _gdk_offset_x;
int pt_y = pt.y / drop_win32->scale + _gdk_offset_y;
double x = 0.0;
double y = 0.0;
GdkDragAction dest_action;

View File

@ -1291,13 +1291,12 @@ make_crossing_event (GdkDevice *physical_device,
}
/* Acquires actual client area size of the underlying native window.
* Rectangle is in GDK screen coordinates (_gdk_offset_* is added).
* Returns FALSE if configure events should be inhibited,
* TRUE otherwise.
*/
gboolean
_gdk_win32_get_window_rect (GdkSurface *window,
RECT *rect)
RECT *rect)
{
RECT client_rect;
POINT point;
@ -1312,11 +1311,7 @@ _gdk_win32_get_window_rect (GdkSurface *window,
/* top level windows need screen coords */
if (GDK_IS_TOPLEVEL (window))
{
ClientToScreen (hwnd, &point);
point.x += _gdk_offset_x * impl->surface_scale;
point.y += _gdk_offset_y * impl->surface_scale;
}
ClientToScreen (hwnd, &point);
rect->left = point.x;
rect->top = point.y;
@ -2410,15 +2405,15 @@ gdk_event_translate (MSG *msg,
impl = GDK_WIN32_SURFACE (window);
/* If we haven't moved, don't create any GDK event. Windows
* sends WM_MOUSEMOVE messages after a new window is shows under
* sends WM_MOUSEMOVE messages after a new window is shown under
* the mouse, even if the mouse hasn't moved. This disturbs gtk.
*/
if ((msg->pt.x + _gdk_offset_x) / impl->surface_scale == current_root_x &&
(msg->pt.y + _gdk_offset_y) / impl->surface_scale == current_root_y)
break;
if (msg->pt.x / impl->surface_scale == current_root_x &&
msg->pt.y / impl->surface_scale == current_root_y)
break;
current_root_x = (msg->pt.x + _gdk_offset_x) / impl->surface_scale;
current_root_y = (msg->pt.y + _gdk_offset_y) / impl->surface_scale;
current_root_x = msg->pt.x / impl->surface_scale;
current_root_y = msg->pt.y / impl->surface_scale;
if (impl->drag_move_resize_context.op != GDK_WIN32_DRAGOP_NONE)
gdk_win32_surface_do_move_resize_drag (window, current_root_x, current_root_y);

View File

@ -30,8 +30,6 @@
GdkDisplay *_gdk_display = NULL;
GdkDeviceManagerWin32 *_gdk_device_manager = NULL;
int _gdk_offset_x, _gdk_offset_y;
HDC _gdk_display_hdc;
HINSTANCE _gdk_dll_hinstance;
HINSTANCE _gdk_app_hmodule;

View File

@ -673,9 +673,6 @@ enum_monitor (HMONITOR hmonitor,
HMONITOR hmonitor;
POINT pt;
/* Not subtracting _gdk_offset_x and _gdk_offset_y because they will only
* be added later on, in _gdk_win32_display_get_monitor_list().
*/
pt.x = w32mon->work_rect.x + w32mon->work_rect.width / 2;
pt.y = w32mon->work_rect.y + w32mon->work_rect.height / 2;
hmonitor = MonitorFromPoint (pt, MONITOR_DEFAULTTONEAREST);
@ -772,45 +769,6 @@ _gdk_win32_display_get_monitor_list (GdkWin32Display *win32_display)
prune_monitors (&data);
}
_gdk_offset_x = G_MININT;
_gdk_offset_y = G_MININT;
for (i = 0; i < data.monitors->len; i++)
{
GdkWin32Monitor *m;
GdkRectangle rect;
m = g_ptr_array_index (data.monitors, i);
/* Calculate offset */
gdk_monitor_get_geometry (GDK_MONITOR (m), &rect);
_gdk_offset_x = MAX (_gdk_offset_x, -rect.x);
_gdk_offset_y = MAX (_gdk_offset_y, -rect.y);
}
GDK_NOTE (MISC, g_print ("Multi-monitor offset: (%d,%d)\n",
_gdk_offset_x, _gdk_offset_y));
/* Translate monitor coords into GDK coordinate space */
for (i = 0; i < data.monitors->len; i++)
{
GdkWin32Monitor *m;
GdkRectangle rect;
m = g_ptr_array_index (data.monitors, i);
gdk_monitor_get_geometry (GDK_MONITOR (m), &rect);
rect.x += _gdk_offset_x;
rect.y += _gdk_offset_y;
gdk_monitor_set_geometry (GDK_MONITOR (m), &rect);
m->work_rect.x += _gdk_offset_x;
m->work_rect.y += _gdk_offset_y;
GDK_NOTE (MISC, g_print ("Monitor %d: %dx%d@%+d%+d\n", i,
rect.width, rect.height, rect.x, rect.y));
}
return data.monitors;
}

View File

@ -258,13 +258,6 @@ extern GdkDisplay *_gdk_display;
extern GdkDeviceManagerWin32 *_gdk_device_manager;
/* Offsets to add to Windows coordinates (which are relative to the
* primary monitor's origin, and thus might be negative for monitors
* to the left and/or above the primary monitor) to get GDK
* coordinates, which should be non-negative on the whole screen.
*/
extern int _gdk_offset_x, _gdk_offset_y;
extern HDC _gdk_display_hdc;
extern HINSTANCE _gdk_dll_hinstance;
extern HINSTANCE _gdk_app_hmodule;

View File

@ -473,7 +473,6 @@ _gdk_win32_display_create_surface (GdkDisplay *display,
wchar_t *wtitle;
int window_width, window_height;
int window_x, window_y;
int offset_x = 0, offset_y = 0;
int real_x = 0, real_y = 0;
GdkFrameClock *frame_clock;
@ -528,8 +527,6 @@ _gdk_win32_display_create_surface (GdkDisplay *display,
dwExStyle = 0;
owner = NULL;
offset_x = _gdk_offset_x;
offset_y = _gdk_offset_y;
/* MSDN: We need WS_CLIPCHILDREN and WS_CLIPSIBLINGS for GL Context Creation */
dwStyle = WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
@ -561,8 +558,8 @@ _gdk_win32_display_create_surface (GdkDisplay *display,
AdjustWindowRectEx (&rect, dwStyle, FALSE, dwExStyle);
real_x = (x - offset_x) * impl->surface_scale;
real_y = (y - offset_y) * impl->surface_scale;
real_x = x * impl->surface_scale;
real_y = y * impl->surface_scale;
if (surface_type == GDK_SURFACE_TOPLEVEL)
{
@ -627,8 +624,8 @@ _gdk_win32_display_create_surface (GdkDisplay *display,
GDK_NOTE (MISC, g_print ("... \"%s\" %dx%d@%+d%+d %p = %p\n",
title,
window_width, window_height,
surface->x - offset_x,
surface->y - offset_y,
surface->x,
surface->y,
owner,
hwndNew));
@ -864,8 +861,8 @@ show_window_internal (GdkSurface *window,
{
GdkSurface *owner = surface->transient_owner;
/* Center on transient parent */
center_on_rect.left = (owner->x - _gdk_offset_x) * surface->surface_scale;
center_on_rect.top = (owner->y - _gdk_offset_y) * surface->surface_scale;
center_on_rect.left = owner->x * surface->surface_scale;
center_on_rect.top = owner->y * surface->surface_scale;
center_on_rect.right = center_on_rect.left + owner->width * surface->surface_scale;
center_on_rect.bottom = center_on_rect.top + owner->height * surface->surface_scale;
@ -1047,13 +1044,13 @@ gdk_win32_surface_do_move (GdkSurface *window,
GDK_NOTE (MISC, g_print ("... SetWindowPos(%p,NULL,%d,%d,0,0,"
"NOACTIVATE|NOSIZE|NOZORDER)\n",
GDK_SURFACE_HWND (window),
(x - _gdk_offset_x) * impl->surface_scale,
(y - _gdk_offset_y) * impl->surface_scale));
x * impl->surface_scale,
y * impl->surface_scale));
API_CALL (SetWindowPos, (GDK_SURFACE_HWND (window),
SWP_NOZORDER_SPECIFIED,
(x - _gdk_offset_x) * impl->surface_scale,
(y - _gdk_offset_y) * impl->surface_scale,
x * impl->surface_scale,
y * impl->surface_scale,
0, 0,
SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER));
}
@ -1133,15 +1130,15 @@ gdk_win32_surface_do_move_resize (GdkSurface *window,
GDK_NOTE (MISC, g_print ("... SetWindowPos(%p,NULL,%d,%d,%ld,%ld,"
"NOACTIVATE|NOZORDER)\n",
GDK_SURFACE_HWND (window),
(x - _gdk_offset_x) * impl->surface_scale,
(y - _gdk_offset_y) * impl->surface_scale,
x * impl->surface_scale,
y * impl->surface_scale,
outer_rect.right - outer_rect.left,
outer_rect.bottom - outer_rect.top));
API_CALL (SetWindowPos, (GDK_SURFACE_HWND (window),
SWP_NOZORDER_SPECIFIED,
(x - _gdk_offset_x) * impl->surface_scale,
(y - _gdk_offset_y) * impl->surface_scale,
x * impl->surface_scale,
y * impl->surface_scale,
outer_rect.right - outer_rect.left,
outer_rect.bottom - outer_rect.top,
SWP_NOACTIVATE | SWP_NOZORDER));
@ -1681,14 +1678,6 @@ gdk_win32_surface_get_geometry (GdkSurface *window,
rect.right = pt.x;
rect.bottom = pt.y;
if (parent == NULL)
{
rect.left += _gdk_offset_x * impl->surface_scale;
rect.top += _gdk_offset_y * impl->surface_scale;
rect.right += _gdk_offset_x * impl->surface_scale;
rect.bottom += _gdk_offset_y * impl->surface_scale;
}
}
if (x)
@ -1727,16 +1716,16 @@ gdk_win32_surface_get_root_coords (GdkSurface *window,
ty = pt.y;
if (root_x)
*root_x = (tx + _gdk_offset_x) / impl->surface_scale;
*root_x = tx / impl->surface_scale;
if (root_y)
*root_y = (ty + _gdk_offset_y) / impl->surface_scale;
*root_y = ty / impl->surface_scale;
GDK_NOTE (MISC, g_print ("gdk_win32_surface_get_root_coords: %p: %+d%+d %+d%+d\n",
GDK_SURFACE_HWND (window),
x * impl->surface_scale,
y * impl->surface_scale,
(tx + _gdk_offset_x) / impl->surface_scale,
(ty + _gdk_offset_y) / impl->surface_scale));
tx / impl->surface_scale,
ty / impl->surface_scale));
}
static gboolean
@ -2883,8 +2872,8 @@ redraw_indicator (gpointer user_data)
last_draw = draw_indicator (context, context->draw_timestamp);
window_position.x = (context->indicator_window_rect.x - _gdk_offset_x) * impl->surface_scale;
window_position.y = (context->indicator_window_rect.y - _gdk_offset_y) * impl->surface_scale;
window_position.x = context->indicator_window_rect.x * impl->surface_scale;
window_position.y = context->indicator_window_rect.y * impl->surface_scale;
window_size.cx = context->indicator_window_rect.width * impl->surface_scale;
window_size.cy = context->indicator_window_rect.height * impl->surface_scale;
@ -3575,8 +3564,8 @@ setup_drag_move_resize_context (GdkSurface *window,
GDK_NOTE (MISC, g_print ("W32 WM unmaximized window placement is %ld x %ld @ %ld : %ld\n",
placement.rcNormalPosition.right - placement.rcNormalPosition.left,
placement.rcNormalPosition.bottom - placement.rcNormalPosition.top,
placement.rcNormalPosition.left + _gdk_offset_x * impl->surface_scale,
placement.rcNormalPosition.top + _gdk_offset_y * impl->surface_scale));
placement.rcNormalPosition.left,
placement.rcNormalPosition.top));
unmax_width = placement.rcNormalPosition.right - placement.rcNormalPosition.left;
unmax_height = placement.rcNormalPosition.bottom - placement.rcNormalPosition.top;
@ -3587,40 +3576,36 @@ setup_drag_move_resize_context (GdkSurface *window,
if (offsetx * impl->surface_scale < (shadow_unmax_width / 2) &&
offsety * impl->surface_scale < (shadow_unmax_height / 2))
{
placement.rcNormalPosition.top = (root_y - offsety + impl->shadow.top - _gdk_offset_y) * impl->surface_scale;
placement.rcNormalPosition.top = (root_y - offsety + impl->shadow.top) * impl->surface_scale;
placement.rcNormalPosition.bottom = placement.rcNormalPosition.top + unmax_height;
if (left_half)
{
placement.rcNormalPosition.left = (root_x - offsetx + impl->shadow.left - _gdk_offset_x) * impl->surface_scale;
placement.rcNormalPosition.left = (root_x - offsetx + impl->shadow.left) * impl->surface_scale;
placement.rcNormalPosition.right = placement.rcNormalPosition.left + unmax_width;
}
else
{
placement.rcNormalPosition.right = (root_x + offsetx + impl->shadow.right - _gdk_offset_x) * impl->surface_scale;
placement.rcNormalPosition.right = (root_x + offsetx + impl->shadow.right) * impl->surface_scale;
placement.rcNormalPosition.left = placement.rcNormalPosition.right - unmax_width;
}
}
else
{
placement.rcNormalPosition.left = (root_x * impl->surface_scale) -
(unmax_width / 2) -
(_gdk_offset_x * impl->surface_scale);
placement.rcNormalPosition.left = root_x * impl->surface_scale - unmax_width / 2;
if (offsety * impl->surface_scale < shadow_unmax_height / 2)
placement.rcNormalPosition.top = (root_y - offsety + impl->shadow.top - _gdk_offset_y) * impl->surface_scale;
placement.rcNormalPosition.top = (root_y - offsety + impl->shadow.top) * impl->surface_scale;
else
placement.rcNormalPosition.top = (root_y * impl->surface_scale) -
(unmax_height / 2) -
(_gdk_offset_y * impl->surface_scale);
placement.rcNormalPosition.top = root_y * impl->surface_scale - unmax_height / 2;
placement.rcNormalPosition.right = placement.rcNormalPosition.left + unmax_width;
placement.rcNormalPosition.bottom = placement.rcNormalPosition.top + unmax_height;
}
GDK_NOTE (MISC, g_print ("Unmaximized window will be at %ld : %ld\n",
placement.rcNormalPosition.left + _gdk_offset_x * impl->surface_scale,
placement.rcNormalPosition.top + _gdk_offset_y * impl->surface_scale));
placement.rcNormalPosition.left,
placement.rcNormalPosition.top));
API_CALL (SetWindowPlacement, (GDK_SURFACE_HWND (window), &placement));
}
@ -3678,7 +3663,7 @@ setup_drag_move_resize_context (GdkSurface *window,
* the titlebar is, if any.
*/
root_y = wy + wheight / 2;
SetCursorPos (root_x - _gdk_offset_x, root_y - _gdk_offset_y);
SetCursorPos (root_x, root_y);
}
}
@ -3799,12 +3784,6 @@ gdk_win32_get_window_size_and_position_from_client_rect (GdkSurface *window,
/* Turn client area into window area */
_gdk_win32_adjust_client_rect (window, window_rect);
/* Convert GDK screen coordinates to W32 desktop coordinates */
window_rect->left -= _gdk_offset_x * impl->surface_scale;
window_rect->right -= _gdk_offset_x * impl->surface_scale;
window_rect->top -= _gdk_offset_y * impl->surface_scale;
window_rect->bottom -= _gdk_offset_y * impl->surface_scale;
window_position->x = window_rect->left;
window_position->y = window_rect->top;
window_size->cx = window_rect->right - window_rect->left;
@ -5100,12 +5079,6 @@ gdk_win32_surface_get_queued_window_rect (GdkSurface *surface,
/* Turn client area into window area */
_gdk_win32_adjust_client_rect (surface, &window_rect);
/* Convert GDK screen coordinates to W32 desktop coordinates */
window_rect.left -= _gdk_offset_x * impl->surface_scale;
window_rect.right -= _gdk_offset_x * impl->surface_scale;
window_rect.top -= _gdk_offset_y * impl->surface_scale;
window_rect.bottom -= _gdk_offset_y * impl->surface_scale;
*return_window_rect = window_rect;
}