[gtk/wip/otte/win32-cleanup: 55/63] win32: Store device manager in the display




commit d99d2c5e81692c41dd594ada8615f25794097099
Author: Benjamin Otte <otte redhat com>
Date:   Wed Jul 21 03:11:05 2021 +0200

    win32: Store device manager in the display
    
    One global variable less.

 gdk/win32/gdkdevicemanager-win32.c | 33 +++++++++++++++++++--------------
 gdk/win32/gdkdevicemanager-win32.h | 17 ++++++++++++-----
 gdk/win32/gdkdisplay-win32.c       |  4 +---
 gdk/win32/gdkdisplay-win32.h       |  7 ++++++-
 gdk/win32/gdkevents-win32.c        | 33 ++++++++++++++++-----------------
 gdk/win32/gdkglobals-win32.c       |  1 -
 gdk/win32/gdkprivate-win32.h       |  2 --
 7 files changed, 54 insertions(+), 43 deletions(-)
---
diff --git a/gdk/win32/gdkdevicemanager-win32.c b/gdk/win32/gdkdevicemanager-win32.c
index d12666eed9..990f949e55 100644
--- a/gdk/win32/gdkdevicemanager-win32.c
+++ b/gdk/win32/gdkdevicemanager-win32.c
@@ -21,14 +21,16 @@
 #include <stdio.h>
 #include <math.h>
 
-#include <gdk/gdk.h>
-#include "gdkwin32.h"
-#include "gdkprivate-win32.h"
 #include "gdkdevicemanager-win32.h"
-#include "gdkdeviceprivate.h"
-#include "gdkdevice-win32.h"
+
 #include "gdkdevice-virtual.h"
+#include "gdkdevice-win32.h"
 #include "gdkdevice-wintab.h"
+#include "gdkdisplay-win32.h"
+#include "gdkprivate-win32.h"
+#include "gdkwin32misc.h"
+
+#include "gdkdeviceprivate.h"
 #include "gdkdisplayprivate.h"
 #include "gdkseatdefaultprivate.h"
 
@@ -80,7 +82,7 @@ create_pointer (GdkDeviceManagerWin32 *device_manager,
                        "name", name,
                        "source", GDK_SOURCE_MOUSE,
                        "has-cursor", has_cursor,
-                       "display", _gdk_display,
+                       "display", device_manager->display,
                        NULL);
 }
 
@@ -93,7 +95,7 @@ create_keyboard (GdkDeviceManagerWin32 *device_manager,
                        "name", name,
                        "source", GDK_SOURCE_KEYBOARD,
                        "has-cursor", FALSE,
-                       "display", _gdk_display,
+                       "display", device_manager->display,
                        NULL);
 }
 
@@ -673,7 +675,7 @@ wintab_default_display_notify_cb (GdkDisplayManager *display_manager)
 
   g_assert (display != NULL);
 
-  device_manager = GDK_DEVICE_MANAGER_WIN32 (_gdk_device_manager);
+  device_manager = GDK_WIN32_DISPLAY (display)->device_manager;
   g_assert (display_manager != NULL);
 
   default_display_opened = TRUE;
@@ -681,15 +683,17 @@ wintab_default_display_notify_cb (GdkDisplayManager *display_manager)
   wintab_init_check (device_manager);
 }
 
-static void
-gdk_device_manager_win32_constructed (GObject *object)
+GdkDeviceManagerWin32 *
+gdk_device_manager_win32_new (GdkDisplay *display)
 {
   GdkDeviceManagerWin32 *device_manager;
   GdkSeat *seat;
   GdkDisplayManager *display_manager = NULL;
   GdkDisplay *default_display = NULL;
 
-  device_manager = GDK_DEVICE_MANAGER_WIN32 (object);
+  device_manager = g_object_new (GDK_TYPE_DEVICE_MANAGER_WIN32, NULL);
+  device_manager->display = display; /* no ref, the display owns us */
+
   device_manager->core_pointer =
     create_pointer (device_manager,
                    GDK_TYPE_DEVICE_VIRTUAL,
@@ -723,7 +727,7 @@ gdk_device_manager_win32_constructed (GObject *object)
 
   seat = gdk_seat_default_new_for_logical_pair (device_manager->core_pointer,
                                                 device_manager->core_keyboard);
-  gdk_display_add_seat (_gdk_display, seat);
+  gdk_display_add_seat (display, seat);
   gdk_seat_default_add_physical_device (GDK_SEAT_DEFAULT (seat), device_manager->system_pointer);
   gdk_seat_default_add_physical_device (GDK_SEAT_DEFAULT (seat), device_manager->system_keyboard);
   g_object_unref (seat);
@@ -740,6 +744,8 @@ gdk_device_manager_win32_constructed (GObject *object)
   g_signal_connect (display_manager, "notify::default-display",
                     G_CALLBACK (wintab_default_display_notify_cb),
                     NULL);
+
+  return device_manager;
 }
 
 static void
@@ -748,7 +754,6 @@ gdk_device_manager_win32_class_init (GdkDeviceManagerWin32Class *klass)
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
   object_class->finalize = gdk_device_manager_win32_finalize;
-  object_class->constructed = gdk_device_manager_win32_constructed;
 }
 
 void
@@ -898,7 +903,7 @@ gdk_input_other_event (GdkDisplay *display,
       return NULL;
     }
 
-  device_manager = GDK_DEVICE_MANAGER_WIN32 (_gdk_device_manager);
+  device_manager = GDK_WIN32_DISPLAY (display)->device_manager;
   window = gdk_device_get_surface_at_position (device_manager->core_pointer, &x, &y);
 
   if (window)
diff --git a/gdk/win32/gdkdevicemanager-win32.h b/gdk/win32/gdkdevicemanager-win32.h
index 003be32a44..1375f75db4 100644
--- a/gdk/win32/gdkdevicemanager-win32.h
+++ b/gdk/win32/gdkdevicemanager-win32.h
@@ -18,6 +18,10 @@
 #ifndef __GDK_DEVICE_MANAGER_WIN32_H__
 #define __GDK_DEVICE_MANAGER_WIN32_H__
 
+#include <gdk/gdkdisplay.h>
+
+#include <windows.h>
+
 G_BEGIN_DECLS
 
 #define GDK_TYPE_DEVICE_MANAGER_WIN32         (gdk_device_manager_win32_get_type ())
@@ -54,12 +58,15 @@ struct _GdkDeviceManagerWin32Class
   GObjectClass parent_class;
 };
 
-GType gdk_device_manager_win32_get_type (void) G_GNUC_CONST;
+GType                   gdk_device_manager_win32_get_type       (void) G_GNUC_CONST;
+
+void                    _gdk_input_set_tablet_active            (void);
+
+GdkDeviceManagerWin32 * gdk_device_manager_win32_new            (GdkDisplay             *display);
 
-void     _gdk_input_set_tablet_active (void);
-GdkEvent * gdk_input_other_event      (GdkDisplay *display,
-                                       MSG        *msg,
-                                       GdkSurface  *window);
+GdkEvent *              gdk_input_other_event                   (GdkDisplay             *display,
+                                                                 MSG                    *msg,
+                                                                 GdkSurface             *window);
 
 G_END_DECLS
 
diff --git a/gdk/win32/gdkdisplay-win32.c b/gdk/win32/gdkdisplay-win32.c
index 95097ae6f0..9762275d48 100644
--- a/gdk/win32/gdkdisplay-win32.c
+++ b/gdk/win32/gdkdisplay-win32.c
@@ -529,9 +529,7 @@ _gdk_win32_display_open (const char *display_name)
 
   _gdk_input_ignore_core = 0;
 
-  _gdk_device_manager = g_object_new (GDK_TYPE_DEVICE_MANAGER_WIN32,
-                                      NULL);
-  _gdk_device_manager->display = _gdk_display;
+  win32_display->device_manager = gdk_device_manager_win32_new (_gdk_display);
 
   _gdk_win32_lang_notification_init ();
   _gdk_drag_init ();
diff --git a/gdk/win32/gdkdisplay-win32.h b/gdk/win32/gdkdisplay-win32.h
index 4b81bfff36..fc6699fc00 100644
--- a/gdk/win32/gdkdisplay-win32.h
+++ b/gdk/win32/gdkdisplay-win32.h
@@ -24,6 +24,9 @@
 
 #include "gdkwin32cursor.h"
  
+#include "gdkdevicemanager-win32.h"
+#include "gdkprivate-win32.h"
+
 #ifdef GDK_WIN32_ENABLE_EGL
 # include <epoxy/egl.h>
 #endif
@@ -115,7 +118,7 @@ struct _GdkWin32Display
 {
   GdkDisplay display;
 
-    Win32CursorTheme *cursor_theme;
+  Win32CursorTheme *cursor_theme;
   char *cursor_theme_name;
   int cursor_theme_size;
 
@@ -157,6 +160,8 @@ struct _GdkWin32Display
   GdkWin32ShcoreFuncs shcore_funcs;
   GdkWin32User32DPIFuncs user32_dpi_funcs;
   
+  GdkDeviceManagerWin32 *device_manager;
+
   /* Cursor Items (GdkCursor->GdkWin32HCursor) */
   GHashTable *cursors;
   /* The cursor that is used by current grab (if any) */
diff --git a/gdk/win32/gdkevents-win32.c b/gdk/win32/gdkevents-win32.c
index 808354c4ae..d25ba06d4c 100644
--- a/gdk/win32/gdkevents-win32.c
+++ b/gdk/win32/gdkevents-win32.c
@@ -583,8 +583,8 @@ find_window_for_mouse_event (GdkSurface* reported_window,
   GdkDeviceGrabInfo *grab;
 
   display = gdk_display_get_default ();
-  device_manager = GDK_DEVICE_MANAGER_WIN32 (_gdk_device_manager);
-
+  device_manager = GDK_WIN32_DISPLAY (display)->device_manager;
+  
   grab = _gdk_display_get_last_device_grab (display, device_manager->core_pointer);
   if (grab == NULL)
     return reported_window;
@@ -1050,8 +1050,8 @@ send_crossing_event (GdkDisplay                 *display,
   POINT pt;
   GdkWin32Surface *impl = GDK_WIN32_SURFACE (window);
 
-  device_manager = _gdk_device_manager;
-
+  device_manager = GDK_WIN32_DISPLAY (display)->device_manager;
+  
   grab = _gdk_display_has_device_grab (display, device_manager->core_pointer, 0);
 
   if (grab != NULL &&
@@ -1508,20 +1508,18 @@ handle_dpi_changed (GdkSurface *window,
 }
 
 static void
-generate_button_event (GdkEventType      type,
-                       int               button,
-                       GdkSurface        *window,
-                       MSG              *msg)
+generate_button_event (GdkDeviceManagerWin32 *device_manager,
+                       GdkEventType           type,
+                       int                    button,
+                       GdkSurface            *window,
+                       MSG                   *msg)
 {
   GdkEvent *event;
-  GdkDeviceManagerWin32 *device_manager;
   GdkWin32Surface *impl = GDK_WIN32_SURFACE (window);
 
   if (_gdk_input_ignore_core > 0)
     return;
 
-  device_manager = GDK_DEVICE_MANAGER_WIN32 (_gdk_device_manager);
-
   current_x = (gint16) GET_X_LPARAM (msg->lParam) / impl->surface_scale;
   current_y = (gint16) GET_Y_LPARAM (msg->lParam) / impl->surface_scale;
 
@@ -1775,6 +1773,7 @@ gdk_event_translate (MSG *msg,
 
   display = gdk_display_get_default ();
   win32_display = GDK_WIN32_DISPLAY (display);
+  device_manager_win32 = win32_display->device_manager;
 
   if (win32_display->filters)
     {
@@ -1807,8 +1806,6 @@ gdk_event_translate (MSG *msg,
       return FALSE;
     }
 
-  device_manager_win32 = GDK_DEVICE_MANAGER_WIN32 (_gdk_device_manager);
-
   keyboard_grab = _gdk_display_get_last_device_grab (display,
                                                      device_manager_win32->core_keyboard);
   pointer_grab = _gdk_display_get_last_device_grab (display,
@@ -2191,7 +2188,8 @@ gdk_event_translate (MSG *msg,
       else
        g_set_object (&implicit_grab_surface, NULL);
 
-      generate_button_event (GDK_BUTTON_PRESS, button,
+      generate_button_event (device_manager_win32,
+                            GDK_BUTTON_PRESS, button,
                             window, msg);
 
       return_val = TRUE;
@@ -2258,7 +2256,8 @@ gdk_event_translate (MSG *msg,
       else
        g_set_object (&implicit_grab_surface, NULL);
 
-      generate_button_event (GDK_BUTTON_RELEASE, button,
+      generate_button_event (device_manager_win32,
+                            GDK_BUTTON_RELEASE, button,
                             window, msg);
 
       impl = GDK_WIN32_SURFACE (window);
@@ -2568,7 +2567,7 @@ gdk_event_translate (MSG *msg,
          !GDK_SURFACE_DESTROYED (keyboard_grab->surface) &&
          (_modal_operation_in_progress & GDK_WIN32_MODAL_OP_DND) == 0)
        {
-         generate_grab_broken_event (_gdk_device_manager, keyboard_grab->surface, TRUE, NULL);
+          generate_grab_broken_event (device_manager_win32, keyboard_grab->surface, TRUE, NULL);
        }
       G_GNUC_FALLTHROUGH;
 
@@ -2580,7 +2579,7 @@ gdk_event_translate (MSG *msg,
       if (GDK_SURFACE_DESTROYED (window))
        break;
 
-      generate_focus_event (_gdk_device_manager, window, (msg->message == WM_SETFOCUS));
+      generate_focus_event (device_manager_win32, window, (msg->message == WM_SETFOCUS));
       return_val = TRUE;
       break;
 
diff --git a/gdk/win32/gdkglobals-win32.c b/gdk/win32/gdkglobals-win32.c
index b1eb8210a3..2ac8db165d 100644
--- a/gdk/win32/gdkglobals-win32.c
+++ b/gdk/win32/gdkglobals-win32.c
@@ -28,7 +28,6 @@
 #include "gdkprivate-win32.h"
 
 GdkDisplay      *_gdk_display = NULL;
-GdkDeviceManagerWin32 *_gdk_device_manager = NULL;
 
 int              _gdk_offset_x, _gdk_offset_y;
 
diff --git a/gdk/win32/gdkprivate-win32.h b/gdk/win32/gdkprivate-win32.h
index 5485bf5eff..fdef1e97b1 100644
--- a/gdk/win32/gdkprivate-win32.h
+++ b/gdk/win32/gdkprivate-win32.h
@@ -262,8 +262,6 @@ extern LRESULT CALLBACK _gdk_win32_surface_procedure (HWND, UINT, WPARAM, LPARAM
 
 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


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