Commit 8685de96 authored by Tony Novak's avatar Tony Novak Committed by Jonas Ådahl

input-settings: detect trackball using udev ID_INPUT_TRACKBALL

Previously, trackballs were detected based on the presence of the
substring "trackball" in the device name. This had the downside of
missing devices, such as the Kensington Expert Mouse, which don't have
"trackball" in their names.

Rather than depending on the device name, use the ID_INPUT_TRACKBALL
property from udev to determine whether or not to treat a device as a
trackball.

This adds a new function, `is_trackball_device`, to MetaInputEvents, and
eliminates the `meta_input_device_is_trackball` function.

Fixes: #258
parent a8a3c101
......@@ -115,6 +115,8 @@ struct _MetaInputSettingsClass
GDesktopStylusButtonAction tertiary);
gboolean (* has_two_finger_scroll) (MetaInputSettings *settings,
ClutterInputDevice *device);
gboolean (* is_trackball_device) (MetaInputSettings *settings,
ClutterInputDevice *device);
};
GSettings * meta_input_settings_get_tablet_settings (MetaInputSettings *settings,
......@@ -141,6 +143,4 @@ WacomDevice * meta_input_settings_get_tablet_wacom_device (MetaInputSettings *se
ClutterInputDevice *device);
#endif
gboolean meta_input_device_is_trackball (ClutterInputDevice *device);
#endif /* META_INPUT_SETTINGS_PRIVATE_H */
......@@ -709,22 +709,6 @@ update_touchpad_send_events (MetaInputSettings *input_settings,
}
}
gboolean
meta_input_device_is_trackball (ClutterInputDevice *device)
{
gboolean is_trackball;
char *name;
if (clutter_input_device_get_device_mode (device) == CLUTTER_INPUT_MODE_MASTER)
return FALSE;
name = g_ascii_strdown (clutter_input_device_get_device_name (device), -1);
is_trackball = strstr (name, "trackball") != NULL;
g_free (name);
return is_trackball;
}
static void
update_trackball_scroll_button (MetaInputSettings *input_settings,
ClutterInputDevice *device)
......@@ -733,11 +717,12 @@ update_trackball_scroll_button (MetaInputSettings *input_settings,
MetaInputSettingsPrivate *priv;
guint button;
if (device && !meta_input_device_is_trackball (device))
return;
priv = meta_input_settings_get_instance_private (input_settings);
input_settings_class = META_INPUT_SETTINGS_GET_CLASS (input_settings);
if (device && !input_settings_class->is_trackball_device (input_settings, device))
return;
/* This key is 'i' in the schema but it also specifies a minimum
* range of 0 so the cast here is safe. */
button = (guint) g_settings_get_int (priv->trackball_settings, "scroll-wheel-emulation-button");
......@@ -756,7 +741,7 @@ update_trackball_scroll_button (MetaInputSettings *input_settings,
{
device = devices->data;
if (meta_input_device_is_trackball (device))
if (input_settings_class->is_trackball_device (input_settings, device))
input_settings_class->set_scroll_button (input_settings, device, button);
devices = devices->next;
......
......@@ -398,9 +398,10 @@ is_mouse_device (ClutterInputDevice *device)
}
static gboolean
is_trackball_device (ClutterInputDevice *device)
meta_input_settings_native_is_trackball_device (MetaInputSettings *settings,
ClutterInputDevice *device)
{
return meta_input_device_is_trackball (device);
return has_udev_property (device, "ID_INPUT_TRACKBALL");
}
static void
......@@ -419,7 +420,7 @@ meta_input_settings_native_set_trackball_accel_profile (MetaInputSettings
ClutterInputDevice *device,
GDesktopPointerAccelProfile profile)
{
if (!is_trackball_device (device))
if (!meta_input_settings_native_is_trackball_device (settings, device))
return;
set_device_accel_profile (device, profile);
......@@ -588,6 +589,7 @@ meta_input_settings_native_class_init (MetaInputSettingsNativeClass *klass)
input_settings_class->set_stylus_button_map = meta_input_settings_native_set_stylus_button_map;
input_settings_class->has_two_finger_scroll = meta_input_settings_native_has_two_finger_scroll;
input_settings_class->is_trackball_device = meta_input_settings_native_is_trackball_device;
}
static void
......
......@@ -500,10 +500,10 @@ is_mouse (MetaInputSettings *settings,
}
static gboolean
is_trackball (MetaInputSettings *settings,
ClutterInputDevice *device)
meta_input_settings_x11_is_trackball_device (MetaInputSettings *settings,
ClutterInputDevice *device)
{
return meta_input_device_is_trackball (device);
return has_udev_property (settings, device, "ID_INPUT_TRACKBALL");
}
static void
......@@ -566,7 +566,7 @@ meta_input_settings_x11_set_trackball_accel_profile (MetaInputSettings
ClutterInputDevice *device,
GDesktopPointerAccelProfile profile)
{
if (!is_trackball (settings, device))
if (!meta_input_settings_x11_is_trackball_device (settings, device))
return;
set_device_accel_profile (device, profile);
......@@ -852,6 +852,7 @@ meta_input_settings_x11_class_init (MetaInputSettingsX11Class *klass)
input_settings_class->set_stylus_button_map = meta_input_settings_x11_set_stylus_button_map;
input_settings_class->has_two_finger_scroll = meta_input_settings_x11_has_two_finger_scroll;
input_settings_class->is_trackball_device = meta_input_settings_x11_is_trackball_device;
}
static void
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment