[gtk/wip/otte/win32-cleanup: 7/11] win32: Remove _gdk_display global




commit 8fb892b55aaa23ce5d121b82a3425e858d62e6b3
Author: Benjamin Otte <otte redhat com>
Date:   Wed Jul 21 04:21:41 2021 +0200

    win32: Remove _gdk_display global
    
    All functions have the display available, so no need for the global.
    
    Only gdk_win32_display_open() needs the global for now, because it
    doesn't support opening multiple displays yet.

 gdk/win32/gdkdisplay-win32.c | 43 +++++++++++++++++--------------------------
 gdk/win32/gdkevents-win32.c  | 23 ++++++++++++-----------
 gdk/win32/gdkglobals-win32.c |  2 --
 gdk/win32/gdkmain-win32.c    |  1 -
 gdk/win32/gdkprivate-win32.h |  2 --
 gdk/win32/gdksurface-win32.c |  2 --
 6 files changed, 29 insertions(+), 44 deletions(-)
---
diff --git a/gdk/win32/gdkdisplay-win32.c b/gdk/win32/gdkdisplay-win32.c
index 9762275d48..86e39938a6 100644
--- a/gdk/win32/gdkdisplay-win32.c
+++ b/gdk/win32/gdkdisplay-win32.c
@@ -500,54 +500,49 @@ gdk_win32_display_create_hwnd (GdkWin32Display *self)
 GdkDisplay *
 _gdk_win32_display_open (const char *display_name)
 {
+  static GdkDisplay *display = NULL;
   GdkWin32Display *win32_display;
 
   GDK_NOTE (MISC, g_print ("gdk_display_open: %s\n", (display_name ? display_name : "NULL")));
 
-  if (display_name == NULL ||
-      g_ascii_strcasecmp (display_name,
-                         gdk_display_get_name (_gdk_display)) == 0)
+  if (display_name != NULL)
     {
-      if (_gdk_display != NULL)
-       {
-         GDK_NOTE (MISC, g_print ("... return _gdk_display\n"));
-         return _gdk_display;
-       }
-    }
-  else
-    {
-      GDK_NOTE (MISC, g_print ("... return NULL\n"));
+      GDK_NOTE (MISC, g_print ("... return NULL for display name \"%s\"\n"));
       return NULL;
     }
 
-  _gdk_display = g_object_new (GDK_TYPE_WIN32_DISPLAY, NULL);
-  win32_display = GDK_WIN32_DISPLAY (_gdk_display);
+  if (display)
+    return display;
+
+  display = g_object_new (GDK_TYPE_WIN32_DISPLAY, NULL);
+  win32_display = GDK_WIN32_DISPLAY (display);
 
   gdk_win32_display_init_monitors (win32_display);
   
-  _gdk_events_init (_gdk_display);
+  _gdk_win32_keymap_set_active_layout (GDK_WIN32_KEYMAP (_gdk_win32_display_get_keymap (display)), 
_gdk_input_locale);
+  _gdk_events_init (display);
 
   _gdk_input_ignore_core = 0;
 
-  win32_display->device_manager = gdk_device_manager_win32_new (_gdk_display);
+  win32_display->device_manager = gdk_device_manager_win32_new (display);
 
   _gdk_win32_lang_notification_init ();
   _gdk_drag_init ();
   _gdk_drop_init ();
 
-  _gdk_display->clipboard = gdk_win32_clipboard_new (_gdk_display);
-  _gdk_display->primary_clipboard = gdk_clipboard_new (_gdk_display);
+  display->clipboard = gdk_win32_clipboard_new (display);
+  display->primary_clipboard = gdk_clipboard_new (display);
 
   /* Precalculate display name */
-  (void) gdk_display_get_name (_gdk_display);
+  (void) gdk_display_get_name (display);
 
   gdk_win32_display_create_hwnd (win32_display);
 
-  g_signal_emit_by_name (_gdk_display, "opened");
+  g_signal_emit_by_name (display, "opened");
 
-  GDK_NOTE (MISC, g_print ("... _gdk_display now set up\n"));
+  GDK_NOTE (MISC, g_print ("... win32 display now set up\n"));
 
-  return _gdk_display;
+  return display;
 }
 
 G_DEFINE_TYPE (GdkWin32Display, gdk_win32_display, GDK_TYPE_DISPLAY)
@@ -627,16 +622,12 @@ gdk_win32_display_beep (GdkDisplay *display)
 static void
 gdk_win32_display_flush (GdkDisplay * display)
 {
-  g_return_if_fail (display == _gdk_display);
-
   GdiFlush ();
 }
 
 static void
 gdk_win32_display_sync (GdkDisplay * display)
 {
-  g_return_if_fail (display == _gdk_display);
-
   GdiFlush ();
 }
 
diff --git a/gdk/win32/gdkevents-win32.c b/gdk/win32/gdkevents-win32.c
index 753652118b..b951b8025f 100644
--- a/gdk/win32/gdkevents-win32.c
+++ b/gdk/win32/gdkevents-win32.c
@@ -620,7 +620,8 @@ find_window_for_mouse_event (GdkSurface* reported_window,
 }
 
 static GdkModifierType
-build_key_event_state (BYTE *key_state)
+build_key_event_state (GdkDisplay *display,
+                       BYTE       *key_state)
 {
   GdkModifierType state;
   GdkWin32Keymap *keymap;
@@ -644,7 +645,7 @@ build_key_event_state (BYTE *key_state)
   if (key_state[VK_XBUTTON2] & 0x80)
     state |= GDK_BUTTON5_MASK;
 
-  keymap = GDK_WIN32_KEYMAP (_gdk_win32_display_get_keymap (_gdk_display));
+  keymap = GDK_WIN32_KEYMAP (_gdk_win32_display_get_keymap (display));
 
   if (_gdk_win32_keymap_has_altgr (keymap) &&
       (key_state[VK_LCONTROL] & 0x80) &&
@@ -668,11 +669,11 @@ build_key_event_state (BYTE *key_state)
 }
 
 static guint8
-get_active_group (void)
+get_active_group (GdkDisplay *display)
 {
   GdkWin32Keymap *keymap;
 
-  keymap = GDK_WIN32_KEYMAP (_gdk_win32_display_get_keymap (_gdk_display));
+  keymap = GDK_WIN32_KEYMAP (_gdk_win32_display_get_keymap (display));
 
   return _gdk_win32_keymap_get_active_group (keymap);
 }
@@ -1828,7 +1829,7 @@ gdk_event_translate (MSG *msg,
     {
     case WM_INPUTLANGCHANGE:
       _gdk_input_locale = (HKL) msg->lParam;
-      _gdk_win32_keymap_set_active_layout (GDK_WIN32_KEYMAP (_gdk_win32_display_get_keymap (_gdk_display)), 
_gdk_input_locale);
+      _gdk_win32_keymap_set_active_layout (GDK_WIN32_KEYMAP (_gdk_win32_display_get_keymap (display)), 
_gdk_input_locale);
       GetLocaleInfo (MAKELCID (LOWORD (_gdk_input_locale), SORT_DEFAULT),
                     LOCALE_IDEFAULTANSICODEPAGE,
                     buf, sizeof (buf));
@@ -1959,7 +1960,7 @@ gdk_event_translate (MSG *msg,
            }
        }
       else if (msg->wParam == VK_SHIFT &&
-              LOBYTE (HIWORD (msg->lParam)) == _gdk_win32_keymap_get_rshift_scancode (GDK_WIN32_KEYMAP 
(_gdk_win32_display_get_keymap (_gdk_display))))
+              LOBYTE (HIWORD (msg->lParam)) == _gdk_win32_keymap_get_rshift_scancode (GDK_WIN32_KEYMAP 
(_gdk_win32_display_get_keymap (display))))
        keycode = VK_RSHIFT;
 
       is_modifier = (msg->wParam == VK_CONTROL ||
@@ -1967,8 +1968,8 @@ gdk_event_translate (MSG *msg,
                      msg->wParam == VK_MENU);
       /* g_print ("ctrl:%02x lctrl:%02x rctrl:%02x alt:%02x lalt:%02x ralt:%02x\n", key_state[VK_CONTROL], 
key_state[VK_LCONTROL], key_state[VK_RCONTROL], key_state[VK_MENU], key_state[VK_LMENU], 
key_state[VK_RMENU]); */
 
-      state = build_key_event_state (key_state);
-      group = get_active_group ();
+      state = build_key_event_state (display, key_state);
+      group = get_active_group (display);
 
       if (msg->wParam == VK_PACKET && ccount == 1)
        {
@@ -2122,14 +2123,14 @@ gdk_event_translate (MSG *msg,
           /* Build a key press event */
           translated.keyval = gdk_unicode_to_keyval (wbuf[i]);
           translated.consumed = 0;
-          translated.layout = get_active_group ();
+          translated.layout = get_active_group (display);
           translated.level = 0;
           event = gdk_key_event_new (GDK_KEY_PRESS,
                                      window,
                                      device_manager_win32->core_keyboard,
                                      _gdk_win32_get_next_tick (msg->time),
                                      0,
-                                     build_key_event_state (key_state),
+                                     build_key_event_state (display, key_state),
                                      FALSE,
                                      &translated,
                                      &translated);
@@ -2142,7 +2143,7 @@ gdk_event_translate (MSG *msg,
                                      device_manager_win32->core_keyboard,
                                      _gdk_win32_get_next_tick (msg->time),
                                      0,
-                                     build_key_event_state (key_state),
+                                     build_key_event_state (display, key_state),
                                      FALSE,
                                      &translated,
                                      &translated);
diff --git a/gdk/win32/gdkglobals-win32.c b/gdk/win32/gdkglobals-win32.c
index 2ac8db165d..969f1bf648 100644
--- a/gdk/win32/gdkglobals-win32.c
+++ b/gdk/win32/gdkglobals-win32.c
@@ -27,8 +27,6 @@
 #include "gdktypes.h"
 #include "gdkprivate-win32.h"
 
-GdkDisplay      *_gdk_display = NULL;
-
 int              _gdk_offset_x, _gdk_offset_y;
 
 HINSTANCE        _gdk_dll_hinstance;
diff --git a/gdk/win32/gdkmain-win32.c b/gdk/win32/gdkmain-win32.c
index 706a86e5d2..faa5c80021 100644
--- a/gdk/win32/gdkmain-win32.c
+++ b/gdk/win32/gdkmain-win32.c
@@ -64,7 +64,6 @@ _gdk_win32_surfaceing_init (void)
 
   _gdk_app_hmodule = GetModuleHandle (NULL);
   _gdk_input_locale = GetKeyboardLayout (0);
-  _gdk_win32_keymap_set_active_layout (GDK_WIN32_KEYMAP (_gdk_win32_display_get_keymap (_gdk_display)), 
_gdk_input_locale);
   GetLocaleInfo (MAKELCID (LOWORD (_gdk_input_locale), SORT_DEFAULT),
                 LOCALE_IDEFAULTANSICODEPAGE,
                 buf, sizeof (buf));
diff --git a/gdk/win32/gdkprivate-win32.h b/gdk/win32/gdkprivate-win32.h
index 6ae9a24199..2823d0f912 100644
--- a/gdk/win32/gdkprivate-win32.h
+++ b/gdk/win32/gdkprivate-win32.h
@@ -256,8 +256,6 @@ void    _gdk_other_api_failed        (const char *where,
 
 extern LRESULT CALLBACK _gdk_win32_surface_procedure (HWND, UINT, WPARAM, LPARAM);
 
-extern GdkDisplay       *_gdk_display;
-
 /* 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
diff --git a/gdk/win32/gdksurface-win32.c b/gdk/win32/gdksurface-win32.c
index 266070c242..b96e25ccff 100644
--- a/gdk/win32/gdksurface-win32.c
+++ b/gdk/win32/gdksurface-win32.c
@@ -471,8 +471,6 @@ _gdk_win32_display_create_surface (GdkDisplay     *display,
   int real_x = 0, real_y = 0;
   GdkFrameClock *frame_clock;
 
-  g_return_val_if_fail (display == _gdk_display, NULL);
-
   GDK_NOTE (MISC,
             g_print ("_gdk_surface_new: %s\n", (surface_type == GDK_SURFACE_TOPLEVEL ? "TOPLEVEL" :
                                                        (surface_type == GDK_SURFACE_TEMP ? "TEMP" :


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