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.
This commit is contained in:
Christian Hergert 2022-02-25 12:30:08 -08:00 committed by Christian Hergert
parent 5b15bc86a3
commit 676e9ab127
4 changed files with 111 additions and 64 deletions

View File

@ -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);
}

View 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);

View 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)
{

View 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',