[gtk/wip/otte/win32-cleanup: 19/19] win32: Use GWL_USERDATA instead of a global hash table




commit 40b83c3050d5003c348df687c39b0cec3499007d
Author: Benjamin Otte <otte redhat com>
Date:   Wed Jul 21 03:44:39 2021 +0200

    win32: Use GWL_USERDATA instead of a global hash table
    
    We can delete a whole source file again!
    
    Also deprecate a bunch of stupid and dangerous APIs that shouldn't have
    made it to 4.0, but who's gonna review the Windows backend, amirite?

 gdk/win32/gdkdevice-win32.c  |  9 ++---
 gdk/win32/gdkdevice-wintab.c |  5 ++-
 gdk/win32/gdkdrop-win32.c    |  2 +-
 gdk/win32/gdkevents-win32.c  | 26 +++++---------
 gdk/win32/gdkprivate-win32.h |  4 ---
 gdk/win32/gdksurface-win32.c | 30 ++++++----------
 gdk/win32/gdkwin32id.c       | 81 --------------------------------------------
 gdk/win32/gdkwin32misc.h     | 14 ++++----
 gdk/win32/meson.build        |  1 -
 9 files changed, 35 insertions(+), 137 deletions(-)
---
diff --git a/gdk/win32/gdkdevice-win32.c b/gdk/win32/gdkdevice-win32.c
index 283df3c519..9cfcef1b83 100644
--- a/gdk/win32/gdkdevice-win32.c
+++ b/gdk/win32/gdkdevice-win32.c
@@ -72,6 +72,7 @@ gdk_device_win32_query_state (GdkDevice        *device,
                               double           *win_y,
                               GdkModifierType  *mask)
 {
+  GdkDisplay *display = gdk_device_get_display (device);
   POINT point;
   HWND hwnd, hwndc;
   int scale;
@@ -83,8 +84,6 @@ gdk_device_win32_query_state (GdkDevice        *device,
     }
   else
     {
-      GdkDisplay *display = gdk_device_get_display (device);
-
       scale = GDK_WIN32_DISPLAY (display)->surface_scale;
       hwnd = NULL;
     }
@@ -105,7 +104,7 @@ gdk_device_win32_query_state (GdkDevice        *device,
       hwndc = ChildWindowFromPoint (hwnd, point);
 
       if (hwndc && hwndc != hwnd)
-        *child_window = gdk_win32_handle_table_lookup (hwndc);
+        *child_window = gdk_win32_surface_lookup_for_display (display, hwndc);
       else
         *child_window = NULL; /* Direct child unknown to gdk */
     }
@@ -162,6 +161,7 @@ _gdk_device_win32_surface_at_position (GdkDevice       *device,
                                        double          *win_y,
                                        GdkModifierType *mask)
 {
+  GdkDisplay *display = gdk_device_get_display (device);
   GdkSurface *window = NULL;
   GdkWin32Surface *impl = NULL;
   POINT screen_pt, client_pt;
@@ -183,7 +183,8 @@ _gdk_device_win32_surface_at_position (GdkDevice       *device,
   if (!PtInRect (&rect, client_pt))
     hwnd = NULL;
 
-  window = gdk_win32_handle_table_lookup (hwnd);
+  if (hwnd)
+    window = gdk_win32_surface_lookup_for_display (display, hwnd);
 
   if (window && (win_x || win_y))
     {
diff --git a/gdk/win32/gdkdevice-wintab.c b/gdk/win32/gdkdevice-wintab.c
index 4822eb042e..39dc2ac922 100644
--- a/gdk/win32/gdkdevice-wintab.c
+++ b/gdk/win32/gdkdevice-wintab.c
@@ -69,6 +69,7 @@ gdk_device_wintab_query_state (GdkDevice        *device,
                                double           *win_y,
                                GdkModifierType  *mask)
 {
+  GdkDisplay *display = gdk_device_get_display (device);
   GdkDeviceWintab *device_wintab;
   POINT point;
   HWND hwnd, hwndc;
@@ -82,8 +83,6 @@ gdk_device_wintab_query_state (GdkDevice        *device,
     }
   else
     {
-      GdkDisplay *display = gdk_device_get_display (device);
-
       scale = GDK_WIN32_DISPLAY (display)->surface_scale;
       hwnd = NULL;
     }
@@ -104,7 +103,7 @@ gdk_device_wintab_query_state (GdkDevice        *device,
       hwndc = ChildWindowFromPoint (hwnd, point);
 
       if (hwndc && hwndc != hwnd)
-        *child_window = gdk_win32_handle_table_lookup (hwndc);
+        *child_window = gdk_win32_surface_lookup_for_display (display, hwndc);
       else
         *child_window = NULL; /* Direct child unknown to gdk */
     }
diff --git a/gdk/win32/gdkdrop-win32.c b/gdk/win32/gdkdrop-win32.c
index 980bfeb94c..82989608c5 100644
--- a/gdk/win32/gdkdrop-win32.c
+++ b/gdk/win32/gdkdrop-win32.c
@@ -812,7 +812,7 @@ gdk_dropfiles_filter (GdkWin32Display *display,
 
   GDK_NOTE (DND, g_print ("WM_DROPFILES: %p\n", msg->hwnd));
 
-  window = gdk_win32_handle_table_lookup (msg->hwnd);
+  window = GDK_SURFACE (GetWindowLongPtr (msg->hwnd, GWLP_USERDATA));
 
   drop = gdk_drop_new (GDK_DISPLAY (display),
                        gdk_seat_get_pointer (gdk_display_get_default_seat (GDK_DISPLAY (display))),
diff --git a/gdk/win32/gdkevents-win32.c b/gdk/win32/gdkevents-win32.c
index 216e40962e..c6584ada43 100644
--- a/gdk/win32/gdkevents-win32.c
+++ b/gdk/win32/gdkevents-win32.c
@@ -259,15 +259,7 @@ inner_window_procedure (HWND   hwnd,
         {
           surface = (UNALIGNED GdkSurface *) (((LPCREATESTRUCTW) lparam)->lpCreateParams);
           GDK_SURFACE_HWND (surface) = hwnd;
-         /* Take note: we're inserting a pointer into a heap-allocated
-          * object (impl). Inserting a pointer to a stack variable
-          * will break the logic, since stack variables are short-lived.
-          * We insert a pointer to the handle instead of the handle itsel
-          * probably because we need to hash them differently depending
-          * on the bitness of the OS. That pointer is still unique,
-          * so this works out in the end.
-          */
-         gdk_win32_handle_table_insert (&GDK_SURFACE_HWND (surface), surface);
+          SetWindowLongPtr (hwnd, GWLP_USERDATA, (LONG_PTR) surface);
         }
       else
         {
@@ -407,7 +399,7 @@ low_level_keyboard_proc (int    code,
     if (kbd_focus_owner == NULL)
       break;
 
-    gdk_kbd_focus_owner = gdk_win32_handle_table_lookup (kbd_focus_owner);
+    gdk_kbd_focus_owner = GDK_SURFACE (GetWindowLongPtr (kbd_focus_owner, GWLP_USERDATA));
 
     if (gdk_kbd_focus_owner == NULL)
       break;
@@ -636,7 +628,7 @@ find_window_for_mouse_event (GdkDisplay *display,
          ScreenToClient (hwnd, &client_pt);
          GetClientRect (hwnd, &rect);
          if (PtInRect (&rect, client_pt))
-           event_surface = gdk_win32_handle_table_lookup (hwnd);
+           event_surface = GDK_SURFACE (GetWindowLongPtr (hwnd, GWLP_USERDATA));
        }
       if (event_surface == NULL)
        event_surface = grab->surface;
@@ -1814,7 +1806,7 @@ gdk_event_translate (GdkDisplay *display,
        return TRUE;
     }
 
-  window = gdk_win32_handle_table_lookup (msg->hwnd);
+  window = GDK_SURFACE (GetWindowLongPtr (msg->hwnd, GWLP_USERDATA));
 
   keyboard_grab = _gdk_display_get_last_device_grab (display,
                                                      device_manager_win32->core_keyboard);
@@ -2248,7 +2240,7 @@ gdk_event_translate (GdkDisplay *display,
                  ScreenToClient (hwnd, &client_pt);
                  GetClientRect (hwnd, &rect);
                  if (PtInRect (&rect, client_pt))
-                   new_window = gdk_win32_handle_table_lookup (hwnd);
+                   new_window = GDK_SURFACE (GetWindowLongPtr (hwnd, GWLP_USERDATA));
                }
 
              synthesize_crossing_events (display,
@@ -2302,7 +2294,7 @@ gdk_event_translate (GdkDisplay *display,
              ScreenToClient (hwnd, &client_pt);
              GetClientRect (hwnd, &rect);
              if (PtInRect (&rect, client_pt))
-               new_window = gdk_win32_handle_table_lookup (hwnd);
+               new_window = GDK_SURFACE (GetWindowLongPtr (hwnd, GWLP_USERDATA));
            }
 
          if (!pointer_grab->owner_events &&
@@ -2404,7 +2396,7 @@ gdk_event_translate (GdkDisplay *display,
          ScreenToClient (hwnd, &client_pt);
          GetClientRect (hwnd, &rect);
          if (PtInRect (&rect, client_pt))
-           new_window = gdk_win32_handle_table_lookup (hwnd);
+           new_window = GDK_SURFACE (GetWindowLongPtr (hwnd, GWLP_USERDATA));
        }
 
       if (!ignore_leave)
@@ -2462,7 +2454,7 @@ gdk_event_translate (GdkDisplay *display,
       }
 
       msg->hwnd = hwnd;
-      if ((new_window = gdk_win32_handle_table_lookup (msg->hwnd)) == NULL)
+      if ((new_window = GDK_SURFACE (GetWindowLongPtr (msg->hwnd, GWLP_USERDATA))) == NULL)
        break;
 
       if (new_window != window)
@@ -3023,7 +3015,7 @@ gdk_event_translate (GdkDisplay *display,
         {
           if (msg->lParam != 0)
             {
-               GdkSurface *other_surface = gdk_win32_handle_table_lookup ((HWND) msg->lParam);
+               GdkSurface *other_surface = GDK_SURFACE (GetWindowLongPtr ((HWND) msg->lParam, 
GWLP_USERDATA));
                if (other_surface != NULL &&
                    (GDK_IS_POPUP (other_surface) || GDK_IS_DRAG_SURFACE (other_surface)))
                 {
diff --git a/gdk/win32/gdkprivate-win32.h b/gdk/win32/gdkprivate-win32.h
index 3407e634b0..2ec24de973 100644
--- a/gdk/win32/gdkprivate-win32.h
+++ b/gdk/win32/gdkprivate-win32.h
@@ -183,10 +183,6 @@ void _gdk_win32_surface_move_region (GdkSurface       *window,
 void _gdk_win32_selection_init (void);
 void _gdk_win32_dnd_exit (void);
 
-void     gdk_win32_handle_table_insert  (HANDLE   *handle,
-                                         gpointer data);
-void     gdk_win32_handle_table_remove  (HANDLE handle);
-
 HRGN      _gdk_win32_cairo_region_to_hrgn (const cairo_region_t *region,
                                            int                   x_origin,
                                            int                   y_origin);
diff --git a/gdk/win32/gdksurface-win32.c b/gdk/win32/gdksurface-win32.c
index 5b1dd2b6a5..b6ddeb14d0 100644
--- a/gdk/win32/gdksurface-win32.c
+++ b/gdk/win32/gdksurface-win32.c
@@ -177,11 +177,6 @@ gdk_surface_win32_finalize (GObject *object)
 
   surface = GDK_WIN32_SURFACE (object);
 
-  if (!GDK_SURFACE_DESTROYED (surface))
-    {
-      gdk_win32_handle_table_remove (surface->handle);
-    }
-
   g_clear_pointer (&surface->snap_stash, g_free);
   g_clear_pointer (&surface->snap_stash_int, g_free);
 
@@ -615,15 +610,6 @@ _gdk_win32_display_create_surface (GdkDisplay     *display,
     }
 
   g_object_ref (impl);
-  /* Take note: we're inserting a pointer into a heap-allocated
-   * object (impl). Inserting a pointer to a stack variable
-   * will break the logic, since stack variables are short-lived.
-   * We insert a pointer to the handle instead of the handle itself
-   * probably because we need to hash them differently depending
-   * on the bitness of the OS. That pointer is still unique,
-   * so this works out in the end.
-   */
-  gdk_win32_handle_table_insert (&GDK_SURFACE_HWND (impl), impl);
 
   GDK_NOTE (MISC, g_print ("... \"%s\" %dx%d@%+d%+d %p = %p\n",
                           title,
@@ -734,7 +720,6 @@ gdk_win32_surface_destroy_notify (GdkSurface *window)
       _gdk_surface_destroy (window, TRUE);
     }
 
-  gdk_win32_handle_table_remove (GDK_SURFACE_HWND (window));
   g_object_unref (window);
 }
 
@@ -4242,13 +4227,20 @@ gdk_win32_surface_focus (GdkSurface *window,
   SetFocus (GDK_SURFACE_HWND (window));
 }
 
+/* Yay for nobody cleaning up the win32 API.
+   At least there's no documentation for this crap,
+   so there's nothing we can break.*/
+gpointer
+gdk_win32_handle_table_lookup (HWND handle)
+{
+  return NULL;
+}
+
 GdkSurface *
 gdk_win32_surface_lookup_for_display (GdkDisplay *display,
-                                     HWND        anid)
+                                      HWND        anid)
 {
-  g_return_val_if_fail (display == gdk_display_get_default (), NULL);
-
-  return (GdkSurface*) gdk_win32_handle_table_lookup (anid);
+  return NULL;
 }
 
 gboolean
diff --git a/gdk/win32/gdkwin32misc.h b/gdk/win32/gdkwin32misc.h
index 3582e81572..2542b745d7 100644
--- a/gdk/win32/gdkwin32misc.h
+++ b/gdk/win32/gdkwin32misc.h
@@ -69,21 +69,21 @@ G_BEGIN_DECLS
 #endif
 
 /* Return true if the GdkSurface is a win32 implemented window */
-GDK_AVAILABLE_IN_ALL
+GDK_DEPRECATED_IN_4_4_FOR (GDK_IS_WIN32_SURFACE)
 gboolean      gdk_win32_surface_is_win32 (GdkSurface *window);
-GDK_AVAILABLE_IN_ALL
-HWND          gdk_win32_surface_get_impl_hwnd (GdkSurface *window);
+GDK_DEPRECATED_IN_4_4_FOR (gdk_win32_surface_get_handle)
+HWND gdk_win32_surface_get_impl_hwnd (GdkSurface *window);
 
 /* Return the Gdk* for a particular HANDLE */
-GDK_AVAILABLE_IN_ALL
+GDK_DEPRECATED_IN_4_4
 gpointer      gdk_win32_handle_table_lookup (HWND handle);
 /* Translate from window to Windows handle */
 GDK_AVAILABLE_IN_ALL
 HGDIOBJ       gdk_win32_surface_get_handle (GdkSurface *window);
 
-GDK_AVAILABLE_IN_ALL
-GdkSurface *   gdk_win32_surface_lookup_for_display (GdkDisplay *display,
-                                                     HWND        anid);
+GDK_DEPRECATED_IN_4_4
+GdkSurface *  gdk_win32_surface_lookup_for_display (GdkDisplay *display,
+                                                    HWND        anid);
 
 #if defined (INSIDE_GDK_WIN32) || defined (GTK_COMPILATION) || defined (GTK_COMPILATION)
 
diff --git a/gdk/win32/meson.build b/gdk/win32/meson.build
index 796cec8fb9..de4c219a69 100644
--- a/gdk/win32/meson.build
+++ b/gdk/win32/meson.build
@@ -24,7 +24,6 @@ gdk_win32_sources = files([
   'gdkvulkancontext-win32.c',
   'gdkwin32cursor.h',
   'gdkwin32display.h',
-  'gdkwin32id.c',
   'gdksurface-win32.c',
 ])
 


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