Implement gtk-primary-button-warps-slider GtkSetting

It replaces the recently added GtkRange:primary-button-warps-slider
style property. Implement the setting in the quartz backend,
it proxies the "click in the scroll bar to" property from the
OS X PrefPane.
This commit is contained in:
Kristian Rietveld 2012-08-24 11:49:43 +02:00 committed by Michael Natterer
parent 15999ec5f3
commit b4ddf24234
3 changed files with 88 additions and 10 deletions

View File

@ -64,10 +64,62 @@ gdk_quartz_event_get_nsevent (GdkEvent *event)
return ((GdkEventPrivate *) event)->windowing_data;
}
static void
gdk_quartz_ns_notification_callback (CFNotificationCenterRef center,
void *observer,
CFStringRef name,
const void *object,
CFDictionaryRef userInfo)
{
GdkEvent new_event;
new_event.type = GDK_SETTING;
new_event.setting.window = gdk_screen_get_root_window (_gdk_screen);
new_event.setting.send_event = FALSE;
new_event.setting.action = GDK_SETTING_ACTION_CHANGED;
new_event.setting.name = NULL;
/* Translate name */
if (CFStringCompare (name,
CFSTR("AppleNoRedisplayAppearancePreferenceChanged"),
0) == kCFCompareEqualTo)
new_event.setting.name = "gtk-primary-button-warps-slider";
if (!new_event.setting.name)
return;
gdk_event_put (&new_event);
}
static void
gdk_quartz_events_init_notifications (void)
{
static gboolean notifications_initialized = FALSE;
if (notifications_initialized)
return;
notifications_initialized = TRUE;
/* Initialize any handlers for notifications we want to push to GTK
* through GdkEventSettings.
*/
/* This is an undocumented *distributed* notification to listen for changes
* in scrollbar jump behavior. It is used by LibreOffice and WebKit as well.
*/
CFNotificationCenterAddObserver (CFNotificationCenterGetDistributedCenter (),
NULL,
&gdk_quartz_ns_notification_callback,
CFSTR ("AppleNoRedisplayAppearancePreferenceChanged"),
NULL,
CFNotificationSuspensionBehaviorDeliverImmediately);
}
void
_gdk_events_init (void)
{
_gdk_quartz_event_loop_init ();
gdk_quartz_events_init_notifications ();
current_keyboard_window = g_object_ref (_gdk_root);
}
@ -1563,6 +1615,19 @@ gdk_screen_get_setting (GdkScreen *screen,
GDK_QUARTZ_RELEASE_POOL;
return TRUE;
}
else if (strcmp (name, "gtk-primary-button-warps-slider") == 0)
{
GDK_QUARTZ_ALLOC_POOL;
BOOL setting = [[NSUserDefaults standardUserDefaults] boolForKey:@"AppleScrollerPagingBehavior"];
/* If the Apple property is YES, it means "warp" */
g_value_set_boolean (value, setting == YES);
GDK_QUARTZ_RELEASE_POOL;
return TRUE;
}

View File

@ -532,12 +532,6 @@ gtk_range_class_init (GtkRangeClass *class)
G_MAXINT,
0,
GTK_PARAM_READABLE));
gtk_widget_class_install_style_property (widget_class,
g_param_spec_boolean ("primary-button-warps-slider",
P_("Primary button warps slider"),
P_("Whether a primary click on the trough should warp the slider into position"),
FALSE,
GTK_PARAM_READABLE));
/**
* GtkRange:activate-slider:
@ -2331,9 +2325,9 @@ gtk_range_button_press (GtkWidget *widget,
if (gtk_range_update_mouse_location (range))
gtk_widget_queue_draw (widget);
gtk_widget_style_get (widget,
"primary-button-warps-slider", &primary_warps,
NULL);
g_object_get (gtk_widget_get_settings (widget),
"gtk-primary-button-warps-slider", &primary_warps,
NULL);
if (primary_warps)
{
warp_button = 1;

View File

@ -125,7 +125,8 @@ enum {
PROP_ENABLE_TOOLTIPS,
PROP_TOOLBAR_STYLE,
PROP_TOOLBAR_ICON_SIZE,
PROP_AUTO_MNEMONICS
PROP_AUTO_MNEMONICS,
PROP_PRIMARY_BUTTON_WARPS_SLIDER
};
@ -1023,6 +1024,24 @@ gtk_settings_class_init (GtkSettingsClass *class)
GTK_PARAM_READWRITE),
NULL);
g_assert (result == PROP_AUTO_MNEMONICS);
/**
* GtkSettings:gtk-primary-button-warps-slider
*
* Whether a click in a #GtkRange trough should scroll to the click position or
* scroll by a single page in the respective direction.
*
* Since: 2.24
*/
result = settings_install_property_parser (class,
g_param_spec_boolean ("gtk-primary-button-warps-slider",
P_("Primary button warps slider"),
P_("Whether a primary click on the trough should warp the slider into position"),
FALSE,
GTK_PARAM_READWRITE),
NULL);
g_assert (result == PROP_PRIMARY_BUTTON_WARPS_SLIDER);
}
static void