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




commit ce957bd996707a3dc7c76b83b2bf0477990cb576
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  |  4 +--
 gdk/win32/gdkdevice-wintab.c |  2 +-
 gdk/win32/gdkdrag-win32.c    |  4 +--
 gdk/win32/gdkdrop-win32.c    |  2 +-
 gdk/win32/gdkevents-win32.c  | 16 ++++-----
 gdk/win32/gdkprivate-win32.h |  4 ---
 gdk/win32/gdksurface-win32.c | 31 +++++++----------
 gdk/win32/gdkwin32id.c       | 81 --------------------------------------------
 gdk/win32/gdkwin32misc.h     | 14 ++++----
 gdk/win32/meson.build        |  1 -
 10 files changed, 33 insertions(+), 126 deletions(-)
---
diff --git a/gdk/win32/gdkdevice-win32.c b/gdk/win32/gdkdevice-win32.c
index 35802b93a2..462794086a 100644
--- a/gdk/win32/gdkdevice-win32.c
+++ b/gdk/win32/gdkdevice-win32.c
@@ -114,7 +114,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_SURFACE (GetWindowLongPtr (hwndc, GWLP_USERDATA));
       else
         *child_window = NULL; /* Direct child unknown to gdk */
     }
@@ -192,7 +192,7 @@ _gdk_device_win32_surface_at_position (GdkDevice       *device,
   if (!PtInRect (&rect, client_pt))
     hwnd = NULL;
 
-  window = gdk_win32_handle_table_lookup (hwnd);
+  window = GDK_SURFACE (GetWindowLongPtr (hwnd, GWLP_USERDATA));
 
   if (window && (win_x || win_y))
     {
diff --git a/gdk/win32/gdkdevice-wintab.c b/gdk/win32/gdkdevice-wintab.c
index 6e94545767..6dbdc0ca7e 100644
--- a/gdk/win32/gdkdevice-wintab.c
+++ b/gdk/win32/gdkdevice-wintab.c
@@ -113,7 +113,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_SURFACE (GetWindowLongPtr (hwndc, GWLP_USERDATA));
       else
         *child_window = NULL; /* Direct child unknown to gdk */
     }
diff --git a/gdk/win32/gdkdrag-win32.c b/gdk/win32/gdkdrag-win32.c
index 1b92e85efa..bcffd65cc1 100644
--- a/gdk/win32/gdkdrag-win32.c
+++ b/gdk/win32/gdkdrag-win32.c
@@ -1895,7 +1895,7 @@ manufacture_keystate_from_GMT (GdkModifierType state)
 static GdkDrop *
 _gdk_win32_get_drop_for_dest_window (HWND dest_window)
 {
-  GdkSurface *drop_surface = gdk_win32_handle_table_lookup (dest_window);
+  GdkSurface *drop_surface = GDK_SURFACE (GetWindowLongPtr (dest_window, GWLP_USERDATA));
   GdkDrop    *result = NULL;
 
   if (drop_surface)
@@ -1946,7 +1946,7 @@ gdk_win32_local_drag_motion (GdkDrag         *drag,
       drag_win32->drag_status = GDK_DRAG_STATUS_DRAG;
 
       _gdk_win32_local_drop_target_dragenter (drag,
-                                              gdk_win32_handle_table_lookup (dest_window),
+                                              GDK_SURFACE (GetWindowLongPtr (dest_window, GWLP_USERDATA)),
                                               x_root,
                                               y_root,
                                               key_state,
diff --git a/gdk/win32/gdkdrop-win32.c b/gdk/win32/gdkdrop-win32.c
index 8e09b181ca..87c5e36905 100644
--- a/gdk/win32/gdkdrop-win32.c
+++ b/gdk/win32/gdkdrop-win32.c
@@ -950,7 +950,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 d25ba06d4c..753652118b 100644
--- a/gdk/win32/gdkevents-win32.c
+++ b/gdk/win32/gdkevents-win32.c
@@ -374,7 +374,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;
@@ -604,7 +604,7 @@ find_window_for_mouse_event (GdkSurface* reported_window,
          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;
@@ -1784,7 +1784,7 @@ gdk_event_translate (MSG *msg,
        return TRUE;
     }
 
-  window = gdk_win32_handle_table_lookup (msg->hwnd);
+  window = GDK_SURFACE (GetWindowLongPtr (msg->hwnd, GWLP_USERDATA));
 
   if (window == NULL)
     {
@@ -2238,7 +2238,7 @@ gdk_event_translate (MSG *msg,
                  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,
@@ -2292,7 +2292,7 @@ gdk_event_translate (MSG *msg,
              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 &&
@@ -2394,7 +2394,7 @@ gdk_event_translate (MSG *msg,
          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)
@@ -2452,7 +2452,7 @@ gdk_event_translate (MSG *msg,
       }
 
       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)
@@ -3013,7 +3013,7 @@ gdk_event_translate (MSG *msg,
         {
           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 fdef1e97b1..6ae9a24199 100644
--- a/gdk/win32/gdkprivate-win32.h
+++ b/gdk/win32/gdkprivate-win32.h
@@ -184,10 +184,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 4c1f7c1a3f..266070c242 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);
 
@@ -619,15 +614,7 @@ _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);
+  SetWindowLongPtr (GDK_SURFACE_HWND (impl), GWLP_USERDATA, (LONG_PTR) impl);
 
   GDK_NOTE (MISC, g_print ("... \"%s\" %dx%d@%+d%+d %p = %p\n",
                           title,
@@ -738,7 +725,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);
 }
 
@@ -4261,13 +4247,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]