GNOME Bugzilla – Bug 668088
Possibly use NSUserDefaultsController in nextstep gsettings backend
Last modified: 2018-05-24 13:43:14 UTC
I looked a bit at the nextstep gsettings backend and it appeared that change notification would not work (empty subscribe/unsubscribe). Would it be possible to implement this using NSUserDefaultsController (which seems to support change notification).
I am no expert here but i would *guess* that NSUserDefaultsController is an objc wrapper around some plain C core foundation api. In the quartz backend for example we use the following to get notified ok keymap changes: CFNotificationCenterAddObserver (CFNotificationCenterGetDistributedCenter (), NULL, input_sources_changed_notification, CFSTR ("AppleSelectedInputSourcesChangedNotification"), NULL, CFNotificationSuspensionBehaviorDeliverImmediately);
I'm not sure either, but the docs says that it's a cocoa bindings thingie, i.e. key/value observer. Some informative references: https://developer.apple.com/library/mac/documentation/cocoa/Conceptual/CocoaBindings/Concepts/NSUserDefaultsController.html#//apple_ref/doc/uid/TP40001092-BCICADHC http://stackoverflow.com/questions/1141388/cocoa-notification-on-nsuserdefaults-value-change
You want to use https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSUserDefaults_Class/Reference/Reference.html#//apple_ref/c/data/NSUserDefaultsDidChangeNotification The corresponding CF API is https://developer.apple.com/library/mac/documentation/CoreFoundation/Reference/CFPreferencesUtils/Reference/reference.html#//apple_ref/doc/uid/20001450 but it doesn't appear to support notification. NSUserDefaultsController is for binding a Cocoa/UIKit widget to a particular defaults item. While it might be interesting to connect it to a Gtk Widget somehow, it's too high-level for GSettings.
As I understood it, you don't get information on which key changed with NSUserDefaultsDidChangeNotification, only that something has changed, right? You can still observe keys using addObserver on the NSUserDefaults.values though.
Yes, I think that's correct. You'd have to either have an observer (probably what NSUserDefaultsController abstracts) or iterate over the keys you're interested in.
I took a stab at this, but while implementing I'm not sure anymore it's actually necessary at all. The only reason to implement subscribe/unsubscribe seems to be to be able to observe external changes. However, external changes are very uncommon on OS X, especially since settings are per app. The only practical limitation of not having subscribe seems to be if an application would instantiate several backends. This however is very uncommon too as far as I know.
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/glib/issues/505.