[gtk/wip/otte/win32-cleanup: 2/5] win32: Remove _gdk_offset_x and _gdk_offset_y




commit 98424bd90c860d4c9b22c7c3fb6ca3c1d91f9fe4
Author: Benjamin Otte <otte redhat com>
Date:   Fri Jul 30 19:39:16 2021 +0200

    win32: Remove _gdk_offset_x and _gdk_offset_y
    
    GTK can deal with negative coordinates just fine these days, so
    keeping offsets is not necessary and massively simplifies things.

 gdk/win32/gdkdevice-win32.c  |  9 -----
 gdk/win32/gdkdevice-wintab.c |  9 -----
 gdk/win32/gdkdrag-win32.c    |  4 +-
 gdk/win32/gdkdrop-win32.c    | 16 ++++----
 gdk/win32/gdkevents-win32.c  | 10 ++---
 gdk/win32/gdkglobals-win32.c |  2 -
 gdk/win32/gdkmonitor-win32.c | 44 +---------------------
 gdk/win32/gdkprivate-win32.h |  7 ----
 gdk/win32/gdksurface-win32.c | 87 ++++++++++++++++----------------------------
 9 files changed, 47 insertions(+), 141 deletions(-)
---
diff --git a/gdk/win32/gdkdevice-win32.c b/gdk/win32/gdkdevice-win32.c
index 35802b93a2..283df3c519 100644
--- a/gdk/win32/gdkdevice-win32.c
+++ b/gdk/win32/gdkdevice-win32.c
@@ -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);
diff --git a/gdk/win32/gdkdevice-wintab.c b/gdk/win32/gdkdevice-wintab.c
index 6e94545767..4822eb042e 100644
--- a/gdk/win32/gdkdevice-wintab.c
+++ b/gdk/win32/gdkdevice-wintab.c
@@ -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);
diff --git a/gdk/win32/gdkdrag-win32.c b/gdk/win32/gdkdrag-win32.c
index 13d33f4bd7..cd8561aca3 100644
--- a/gdk/win32/gdkdrag-win32.c
+++ b/gdk/win32/gdkdrag-win32.c
@@ -1845,8 +1845,8 @@ gdk_win32_drag_find_window (GdkDrag    *drag,
   g_assert (_win32_main_thread == NULL ||
             _win32_main_thread == g_thread_self ());
 
-  a.x = x_root * drag_win32->scale - _gdk_offset_x;
-  a.y = y_root * drag_win32->scale - _gdk_offset_y;
+  a.x = x_root * drag_win32->scale;
+  a.y = y_root * drag_win32->scale;
   a.ignore = drag_surface ? GDK_SURFACE_HWND (drag_surface) : NULL;
   a.result = INVALID_HANDLE_VALUE;
 
diff --git a/gdk/win32/gdkdrop-win32.c b/gdk/win32/gdkdrop-win32.c
index 18be1c8dee..e8e8205840 100644
--- a/gdk/win32/gdkdrop-win32.c
+++ b/gdk/win32/gdkdrop-win32.c
@@ -558,8 +558,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;
   gdk_drop_emit_enter_event (drop, TRUE, pt_x, pt_y, GDK_CURRENT_TIME);
   drop_win32->last_key_state = grfKeyState;
   drop_win32->last_x = pt_x;
@@ -642,8 +642,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;
 
@@ -746,8 +746,8 @@ 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;
+  int pt_x = pt.x / drop_win32->scale;
+  int pt_y = pt.y / drop_win32->scale;
   GdkDragAction dest_action;
 
   GDK_NOTE (DND, g_print ("idroptarget_drop %p ", This));
@@ -1049,8 +1049,8 @@ gdk_dropfiles_filter (GdkWin32Display *display,
 
   gdk_drop_emit_drop_event (drop,
                             FALSE, 
-                            pt.x / drop_win32->scale + _gdk_offset_x,
-                            pt.y / drop_win32->scale + _gdk_offset_y,
+                            pt.x / drop_win32->scale,
+                            pt.y / drop_win32->scale,
                             _gdk_win32_get_next_tick (msg->time));
 
   DragFinish (hdrop);
diff --git a/gdk/win32/gdkevents-win32.c b/gdk/win32/gdkevents-win32.c
index 30f05bdd30..216e40962e 100644
--- a/gdk/win32/gdkevents-win32.c
+++ b/gdk/win32/gdkevents-win32.c
@@ -1298,8 +1298,6 @@ _gdk_win32_get_window_rect (GdkSurface *window,
   if (GDK_IS_TOPLEVEL (window))
     {
       ClientToScreen (hwnd, &point);
-      point.x += _gdk_offset_x * impl->surface_scale;
-      point.y += _gdk_offset_y * impl->surface_scale;
     }
 
   rect->left = point.x;
@@ -2347,12 +2345,12 @@ gdk_event_translate (GdkDisplay *display,
        * sends WM_MOUSEMOVE messages after a new window is shows 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)
+      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);
diff --git a/gdk/win32/gdkglobals-win32.c b/gdk/win32/gdkglobals-win32.c
index 969f1bf648..c0b370c205 100644
--- a/gdk/win32/gdkglobals-win32.c
+++ b/gdk/win32/gdkglobals-win32.c
@@ -27,8 +27,6 @@
 #include "gdktypes.h"
 #include "gdkprivate-win32.h"
 
-int              _gdk_offset_x, _gdk_offset_y;
-
 HINSTANCE        _gdk_dll_hinstance;
 HINSTANCE        _gdk_app_hmodule;
 
diff --git a/gdk/win32/gdkmonitor-win32.c b/gdk/win32/gdkmonitor-win32.c
index 0dad478345..9ccdf9a3ad 100644
--- a/gdk/win32/gdkmonitor-win32.c
+++ b/gdk/win32/gdkmonitor-win32.c
@@ -689,9 +689,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);
@@ -787,46 +784,7 @@ _gdk_win32_display_get_monitor_list (GdkWin32Display *win32_display)
       EnumDisplayMonitors (NULL, NULL, enum_monitor, (LPARAM) &data);
       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;
 }
 
diff --git a/gdk/win32/gdkprivate-win32.h b/gdk/win32/gdkprivate-win32.h
index f4ec9b3cd1..b7977d2f27 100644
--- a/gdk/win32/gdkprivate-win32.h
+++ b/gdk/win32/gdkprivate-win32.h
@@ -260,13 +260,6 @@ void    _gdk_other_api_failed        (const char *where,
 
 extern LRESULT CALLBACK _gdk_win32_surface_procedure (HWND, UINT, WPARAM, LPARAM);
 
-/* 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 HINSTANCE         _gdk_dll_hinstance;
 extern HINSTANCE         _gdk_app_hmodule;
 
diff --git a/gdk/win32/gdksurface-win32.c b/gdk/win32/gdksurface-win32.c
index 2f297d10ab..5b1dd2b6a5 100644
--- a/gdk/win32/gdksurface-win32.c
+++ b/gdk/win32/gdksurface-win32.c
@@ -472,7 +472,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;
 
@@ -525,8 +524,7 @@ _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;
 
@@ -558,8 +556,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)
     {
@@ -630,8 +628,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));
 
@@ -863,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;
 
@@ -1046,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));
 }
@@ -1132,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));
@@ -1683,14 +1681,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)
@@ -1729,16 +1719,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
@@ -2867,8 +2857,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;
 
@@ -3559,8 +3549,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;
@@ -3571,40 +3561,38 @@ 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);
+                                                (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);
+                                                 (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));
         }
@@ -3662,7 +3650,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);
         }
     }
 
@@ -3784,11 +3772,6 @@ gdk_win32_get_window_size_and_position_from_client_rect (GdkSurface *window,
   _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;
@@ -5088,12 +5071,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;
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]