[gtk/wip/chergert/for-4-6: 6/56] macos: move feedback mechanisms into separate file




commit 676e9ab127902a2b7c3fd85c07b638f4429f8223
Author: Christian Hergert <christian hergert me>
Date:   Fri Feb 25 12:30:08 2022 -0800

    macos: move feedback mechanisms into separate file
    
    We will eventually be needing additional feedback from the display server
    which would be nice to keep away from the rest of GdkMacosDisplay for
    cleanliness sake. Particularly for feedback from mission control and other
    environment factors that requires private API for proper integration.

 gdk/macos/gdkmacosdisplay-feedback.c | 105 +++++++++++++++++++++++++++++++++++
 gdk/macos/gdkmacosdisplay-private.h  |   2 +
 gdk/macos/gdkmacosdisplay.c          |  67 +---------------------
 gdk/macos/meson.build                |   1 +
 4 files changed, 111 insertions(+), 64 deletions(-)
---
diff --git a/gdk/macos/gdkmacosdisplay-feedback.c b/gdk/macos/gdkmacosdisplay-feedback.c
new file mode 100644
index 0000000000..868ac0fbcd
--- /dev/null
+++ b/gdk/macos/gdkmacosdisplay-feedback.c
@@ -0,0 +1,105 @@
+/*
+ * Copyright © 2022 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ */
+
+#include "config.h"
+
+#include <AppKit/AppKit.h>
+
+#include "gdkmacosdisplay-private.h"
+#include "gdkmacossurface-private.h"
+
+static void
+gdk_macos_display_user_defaults_changed_cb (CFNotificationCenterRef  center,
+                                            void                    *observer,
+                                            CFStringRef              name,
+                                            const void              *object,
+                                            CFDictionaryRef          userInfo)
+{
+  GdkMacosDisplay *self = observer;
+
+  g_assert (GDK_IS_MACOS_DISPLAY (self));
+
+  _gdk_macos_display_reload_settings (self);
+}
+
+static void
+gdk_macos_display_monitors_changed_cb (CFNotificationCenterRef  center,
+                                       void                    *observer,
+                                       CFStringRef              name,
+                                       const void              *object,
+                                       CFDictionaryRef          userInfo)
+{
+  GdkMacosDisplay *self = observer;
+
+  g_assert (GDK_IS_MACOS_DISPLAY (self));
+
+  _gdk_macos_display_reload_monitors (self);
+
+  /* Now we need to update all our surface positions since they
+   * probably just changed origins.
+   */
+  for (const GList *iter = _gdk_macos_display_get_surfaces (self);
+       iter != NULL;
+       iter = iter->next)
+    {
+      GdkMacosSurface *surface = iter->data;
+
+      g_assert (GDK_IS_MACOS_SURFACE (surface));
+
+      _gdk_macos_surface_monitor_changed (surface);
+    }
+}
+
+
+void
+_gdk_macos_display_feedback_init (GdkMacosDisplay *self)
+{
+  g_return_if_fail (GDK_IS_MACOS_DISPLAY (self));
+
+  CFNotificationCenterAddObserver (CFNotificationCenterGetLocalCenter (),
+                                   self,
+                                   gdk_macos_display_monitors_changed_cb,
+                                   CFSTR ("NSApplicationDidChangeScreenParametersNotification"),
+                                   NULL,
+                                   CFNotificationSuspensionBehaviorDeliverImmediately);
+
+  CFNotificationCenterAddObserver (CFNotificationCenterGetDistributedCenter (),
+                                   self,
+                                   gdk_macos_display_user_defaults_changed_cb,
+                                   CFSTR ("NSUserDefaultsDidChangeNotification"),
+                                   NULL,
+                                   CFNotificationSuspensionBehaviorDeliverImmediately);
+}
+
+void
+_gdk_macos_display_feedback_destroy (GdkMacosDisplay *self)
+{
+  g_return_if_fail (GDK_IS_MACOS_DISPLAY (self));
+
+  CFNotificationCenterRemoveObserver (CFNotificationCenterGetDistributedCenter (),
+                                      self,
+                                      CFSTR ("NSApplicationDidChangeScreenParametersNotification"),
+                                      NULL);
+
+  CFNotificationCenterRemoveObserver (CFNotificationCenterGetDistributedCenter (),
+                                      self,
+                                      CFSTR ("NSUserDefaultsDidChangeNotification"),
+                                      NULL);
+
+}
diff --git a/gdk/macos/gdkmacosdisplay-private.h b/gdk/macos/gdkmacosdisplay-private.h
index be2290b89a..b9f33fe20e 100644
--- a/gdk/macos/gdkmacosdisplay-private.h
+++ b/gdk/macos/gdkmacosdisplay-private.h
@@ -124,6 +124,8 @@ GdkMonitor      *_gdk_macos_display_get_monitor_at_display_coords  (GdkMacosDisp
                                                                     int              y);
 GdkEvent        *_gdk_macos_display_translate                      (GdkMacosDisplay *self,
                                                                     NSEvent         *event);
+void             _gdk_macos_display_feedback_init                  (GdkMacosDisplay *self);
+void             _gdk_macos_display_feedback_destroy               (GdkMacosDisplay *self);
 void             _gdk_macos_display_break_all_grabs                (GdkMacosDisplay *self,
                                                                     guint32          time);
 GdkModifierType  _gdk_macos_display_get_current_keyboard_modifiers (GdkMacosDisplay *self);
diff --git a/gdk/macos/gdkmacosdisplay.c b/gdk/macos/gdkmacosdisplay.c
index 74095504a2..bc44eb3e93 100644
--- a/gdk/macos/gdkmacosdisplay.c
+++ b/gdk/macos/gdkmacosdisplay.c
@@ -159,48 +159,6 @@ gdk_macos_display_update_bounds (GdkMacosDisplay *self)
   GDK_END_MACOS_ALLOC_POOL;
 }
 
-static void
-gdk_macos_display_monitors_changed_cb (CFNotificationCenterRef  center,
-                                       void                    *observer,
-                                       CFStringRef              name,
-                                       const void              *object,
-                                       CFDictionaryRef          userInfo)
-{
-  GdkMacosDisplay *self = observer;
-
-  g_assert (GDK_IS_MACOS_DISPLAY (self));
-
-  _gdk_macos_display_reload_monitors (self);
-
-  /* Now we need to update all our surface positions since they
-   * probably just changed origins.
-   */
-  for (const GList *iter = _gdk_macos_display_get_surfaces (self);
-       iter != NULL;
-       iter = iter->next)
-    {
-      GdkMacosSurface *surface = iter->data;
-
-      g_assert (GDK_IS_MACOS_SURFACE (surface));
-
-      _gdk_macos_surface_monitor_changed (surface);
-    }
-}
-
-static void
-gdk_macos_display_user_defaults_changed_cb (CFNotificationCenterRef  center,
-                                            void                    *observer,
-                                            CFStringRef              name,
-                                            const void              *object,
-                                            CFDictionaryRef          userInfo)
-{
-  GdkMacosDisplay *self = observer;
-
-  g_assert (GDK_IS_MACOS_DISPLAY (self));
-
-  _gdk_macos_display_reload_settings (self);
-}
-
 void
 _gdk_macos_display_reload_monitors (GdkMacosDisplay *self)
 {
@@ -686,15 +644,7 @@ gdk_macos_display_finalize (GObject *object)
 {
   GdkMacosDisplay *self = (GdkMacosDisplay *)object;
 
-  CFNotificationCenterRemoveObserver (CFNotificationCenterGetDistributedCenter (),
-                                      self,
-                                      CFSTR ("NSApplicationDidChangeScreenParametersNotification"),
-                                      NULL);
-
-  CFNotificationCenterRemoveObserver (CFNotificationCenterGetDistributedCenter (),
-                                      self,
-                                      CFSTR ("NSUserDefaultsDidChangeNotification"),
-                                      NULL);
+  _gdk_macos_display_feedback_destroy (self);
 
   g_clear_pointer (&self->active_drags, g_hash_table_unref);
   g_clear_pointer (&self->active_drops, g_hash_table_unref);
@@ -779,19 +729,8 @@ _gdk_macos_display_open (const char *display_name)
   gdk_macos_display_load_display_link (self);
   _gdk_macos_display_reload_monitors (self);
 
-  CFNotificationCenterAddObserver (CFNotificationCenterGetLocalCenter (),
-                                   self,
-                                   gdk_macos_display_monitors_changed_cb,
-                                   CFSTR ("NSApplicationDidChangeScreenParametersNotification"),
-                                   NULL,
-                                   CFNotificationSuspensionBehaviorDeliverImmediately);
-
-  CFNotificationCenterAddObserver (CFNotificationCenterGetDistributedCenter (),
-                                   self,
-                                   gdk_macos_display_user_defaults_changed_cb,
-                                   CFSTR ("NSUserDefaultsDidChangeNotification"),
-                                   NULL,
-                                   CFNotificationSuspensionBehaviorDeliverImmediately);
+  /* Initialize feedback from display server */
+  _gdk_macos_display_feedback_init (self);
 
   if (event_source == NULL)
     {
diff --git a/gdk/macos/meson.build b/gdk/macos/meson.build
index d17a60ac09..bd7bbb5324 100644
--- a/gdk/macos/meson.build
+++ b/gdk/macos/meson.build
@@ -8,6 +8,7 @@ gdk_macos_sources = files([
   'gdkmacoscursor.c',
   'gdkmacosdevice.c',
   'gdkmacosdisplay.c',
+  'gdkmacosdisplay-feedback.c',
   'gdkmacosdisplay-settings.c',
   'gdkmacosdisplay-translate.c',
   'gdkmacosdisplay-wm.c',


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