input-settings: Ensure that we always apply the same set of settings

This makes the hotplug and coldplug paths the same so that we don't
miss out on any setting.

https://bugzilla.gnome.org/show_bug.cgi?id=747434
This commit is contained in:
Rui Matos 2015-04-14 15:27:47 +02:00
parent f8b82c376c
commit 8769b3d554

View File

@ -279,51 +279,82 @@ update_mouse_left_handed (MetaInputSettings *input_settings,
} }
} }
static void static GSettings *
update_device_speed (MetaInputSettings *input_settings, get_settings_for_device_type (MetaInputSettings *input_settings,
GSettings *settings,
ClutterInputDevice *device,
ClutterInputDeviceType type) ClutterInputDeviceType type)
{ {
MetaInputSettingsClass *input_settings_class; MetaInputSettingsPrivate *priv;
gdouble speed; priv = meta_input_settings_get_instance_private (input_settings);
switch (type)
{
case CLUTTER_POINTER_DEVICE:
return priv->mouse_settings;
case CLUTTER_TOUCHPAD_DEVICE:
return priv->touchpad_settings;
default:
return NULL;
}
}
input_settings_class = META_INPUT_SETTINGS_GET_CLASS (input_settings); static void
speed = g_settings_get_double (settings, "speed"); update_device_speed (MetaInputSettings *input_settings,
ClutterInputDevice *device)
{
GSettings *settings;
ConfigDoubleFunc func;
const gchar *key = "speed";
func = META_INPUT_SETTINGS_GET_CLASS (input_settings)->set_speed;
if (device) if (device)
settings_device_set_double_setting (input_settings, device, {
input_settings_class->set_speed, settings = get_settings_for_device_type (input_settings,
speed); clutter_input_device_get_device_type (device));
if (!settings)
return;
settings_device_set_double_setting (input_settings, device, func,
g_settings_get_double (settings, key));
}
else else
settings_set_double_setting (input_settings, type, {
input_settings_class->set_speed, settings = get_settings_for_device_type (input_settings, CLUTTER_POINTER_DEVICE);
speed); settings_set_double_setting (input_settings, CLUTTER_POINTER_DEVICE, func,
g_settings_get_double (settings, key));
settings = get_settings_for_device_type (input_settings, CLUTTER_TOUCHPAD_DEVICE);
settings_set_double_setting (input_settings, CLUTTER_TOUCHPAD_DEVICE, func,
g_settings_get_double (settings, key));
}
} }
static void static void
update_device_natural_scroll (MetaInputSettings *input_settings, update_device_natural_scroll (MetaInputSettings *input_settings,
GSettings *settings, ClutterInputDevice *device)
ClutterInputDevice *device,
ClutterInputDeviceType type)
{ {
MetaInputSettingsClass *input_settings_class; GSettings *settings;
gboolean enabled; ConfigBoolFunc func;
const gchar *key = "natural-scroll";
input_settings_class = META_INPUT_SETTINGS_GET_CLASS (input_settings); func = META_INPUT_SETTINGS_GET_CLASS (input_settings)->set_invert_scroll;
enabled = g_settings_get_boolean (settings, "natural-scroll");
if (device) if (device)
{ {
settings_device_set_bool_setting (input_settings, device, settings = get_settings_for_device_type (input_settings,
input_settings_class->set_invert_scroll, clutter_input_device_get_device_type (device));
enabled); if (!settings)
return;
settings_device_set_bool_setting (input_settings, device, func,
g_settings_get_boolean (settings, key));
} }
else else
{ {
settings_set_bool_setting (input_settings, type, settings = get_settings_for_device_type (input_settings, CLUTTER_POINTER_DEVICE);
input_settings_class->set_invert_scroll, settings_set_bool_setting (input_settings, CLUTTER_POINTER_DEVICE, func,
enabled); g_settings_get_boolean (settings, key));
settings = get_settings_for_device_type (input_settings, CLUTTER_TOUCHPAD_DEVICE);
settings_set_bool_setting (input_settings, CLUTTER_TOUCHPAD_DEVICE, func,
g_settings_get_boolean (settings, key));
} }
} }
@ -573,22 +604,18 @@ meta_input_settings_changed_cb (GSettings *settings,
if (strcmp (key, "left-handed") == 0) if (strcmp (key, "left-handed") == 0)
update_mouse_left_handed (input_settings, NULL); update_mouse_left_handed (input_settings, NULL);
else if (strcmp (key, "speed") == 0) else if (strcmp (key, "speed") == 0)
update_device_speed (input_settings, settings, NULL, update_device_speed (input_settings, NULL);
CLUTTER_POINTER_DEVICE);
else if (strcmp (key, "natural-scroll") == 0) else if (strcmp (key, "natural-scroll") == 0)
update_device_natural_scroll (input_settings, settings, update_device_natural_scroll (input_settings, NULL);
NULL, CLUTTER_POINTER_DEVICE);
} }
else if (settings == priv->touchpad_settings) else if (settings == priv->touchpad_settings)
{ {
if (strcmp (key, "left-handed") == 0) if (strcmp (key, "left-handed") == 0)
update_touchpad_left_handed (input_settings, NULL); update_touchpad_left_handed (input_settings, NULL);
else if (strcmp (key, "speed") == 0) else if (strcmp (key, "speed") == 0)
update_device_speed (input_settings, settings, NULL, update_device_speed (input_settings, NULL);
CLUTTER_TOUCHPAD_DEVICE);
else if (strcmp (key, "natural-scroll") == 0) else if (strcmp (key, "natural-scroll") == 0)
update_device_natural_scroll (input_settings, settings, update_device_natural_scroll (input_settings, NULL);
NULL, CLUTTER_TOUCHPAD_DEVICE);
else if (strcmp (key, "tap-to-click") == 0) else if (strcmp (key, "tap-to-click") == 0)
update_touchpad_tap_enabled (input_settings, NULL); update_touchpad_tap_enabled (input_settings, NULL);
else if (strcmp (key, "send-events") == 0) else if (strcmp (key, "send-events") == 0)
@ -706,46 +733,36 @@ check_add_mappable_device (MetaInputSettings *input_settings,
return TRUE; return TRUE;
} }
static void
apply_device_settings (MetaInputSettings *input_settings,
ClutterInputDevice *device)
{
update_mouse_left_handed (input_settings, device);
update_device_speed (input_settings, device);
update_device_natural_scroll (input_settings, device);
update_touchpad_left_handed (input_settings, device);
update_device_speed (input_settings, device);
update_device_natural_scroll (input_settings, device);
update_touchpad_tap_enabled (input_settings, device);
update_touchpad_send_events (input_settings, device);
update_touchpad_scroll_method (input_settings, device);
update_touchpad_click_method (input_settings, device);
update_trackball_scroll_button (input_settings, device);
}
static void static void
meta_input_settings_device_added (ClutterDeviceManager *device_manager, meta_input_settings_device_added (ClutterDeviceManager *device_manager,
ClutterInputDevice *device, ClutterInputDevice *device,
MetaInputSettings *input_settings) MetaInputSettings *input_settings)
{ {
ClutterInputDeviceType type;
MetaInputSettingsPrivate *priv;
if (clutter_input_device_get_device_mode (device) == CLUTTER_INPUT_MODE_MASTER) if (clutter_input_device_get_device_mode (device) == CLUTTER_INPUT_MODE_MASTER)
return; return;
priv = meta_input_settings_get_instance_private (input_settings); apply_device_settings (input_settings, device);
type = clutter_input_device_get_device_type (device);
if (type == CLUTTER_POINTER_DEVICE)
{
update_mouse_left_handed (input_settings, device);
update_device_speed (input_settings, priv->mouse_settings, device, type);
if (device_is_trackball (device))
update_trackball_scroll_button (input_settings, device);
}
else if (type == CLUTTER_TOUCHPAD_DEVICE)
{
update_touchpad_left_handed (input_settings, device);
update_touchpad_tap_enabled (input_settings, device);
update_touchpad_scroll_method (input_settings, device);
update_touchpad_click_method (input_settings, device);
update_touchpad_send_events (input_settings, device);
update_device_speed (input_settings, priv->touchpad_settings,
device, type);
update_device_natural_scroll (input_settings, priv->touchpad_settings,
device, type);
}
else
{
check_add_mappable_device (input_settings, device); check_add_mappable_device (input_settings, device);
} }
}
static void static void
meta_input_settings_device_removed (ClutterDeviceManager *device_manager, meta_input_settings_device_removed (ClutterDeviceManager *device_manager,
@ -782,25 +799,9 @@ static void
meta_input_settings_constructed (GObject *object) meta_input_settings_constructed (GObject *object)
{ {
MetaInputSettings *input_settings = META_INPUT_SETTINGS (object); MetaInputSettings *input_settings = META_INPUT_SETTINGS (object);
MetaInputSettingsPrivate *priv;
priv = meta_input_settings_get_instance_private (input_settings);
update_mouse_left_handed (input_settings, NULL);
update_touchpad_left_handed (input_settings, NULL);
update_touchpad_tap_enabled (input_settings, NULL);
update_touchpad_send_events (input_settings, NULL);
update_device_natural_scroll (input_settings, priv->touchpad_settings,
NULL, CLUTTER_TOUCHPAD_DEVICE);
update_device_speed (input_settings, priv->touchpad_settings, NULL,
CLUTTER_TOUCHPAD_DEVICE);
update_device_speed (input_settings, priv->mouse_settings, NULL,
CLUTTER_POINTER_DEVICE);
apply_device_settings (input_settings, NULL);
update_keyboard_repeat (input_settings); update_keyboard_repeat (input_settings);
check_mappable_devices (input_settings); check_mappable_devices (input_settings);
} }