macos: move feedback mechanisms into separate file
authorChristian Hergert <christian@hergert.me>
Fri, 25 Feb 2022 20:30:08 +0000 (12:30 -0800)
committerChristian Hergert <christian@hergert.me>
Mon, 28 Feb 2022 19:36:23 +0000 (11:36 -0800)
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 [new file with mode: 0644]
gdk/macos/gdkmacosdisplay-private.h
gdk/macos/gdkmacosdisplay.c
gdk/macos/meson.build

diff --git a/gdk/macos/gdkmacosdisplay-feedback.c b/gdk/macos/gdkmacosdisplay-feedback.c
new file mode 100644 (file)
index 0000000..868ac0f
--- /dev/null
@@ -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);
+
+}
index be2290b89a3158754c613b123e8f1edbabe0d92c..b9f33fe20eb1fd45548dd44abb4ad117d03751cb 100644 (file)
@@ -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);
index 74095504a2d6edda2dd12c7589df694d5b230131..bc44eb3e93df5b59a3503903a69d151b91c7644d 100644 (file)
@@ -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)
     {
index d17a60ac092c9e68d89f89a284bddd0abb12edbe..bd7bbb532453c24b742abe6951034812af84533d 100644 (file)
@@ -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',