summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormonsta <[email protected]>2016-12-23 15:58:02 +0300
committermonsta <[email protected]>2017-01-02 16:53:33 +0300
commit2f03aca366d22bd844eb75ebcee47e0c251cee6b (patch)
tree124deda4a8576acc311cd53552f8993202864fbc
parent9bbce5943c7cba741781f9bf8b1391624a590cb8 (diff)
downloadmate-settings-daemon-2f03aca366d22bd844eb75ebcee47e0c251cee6b.tar.bz2
mate-settings-daemon-2f03aca366d22bd844eb75ebcee47e0c251cee6b.tar.xz
mouse: libinput - hook up acceleration setting
note: threshold setting is ignored as libinput doesn't have it adapted from: https://github.com/linuxmint/cinnamon-settings-daemon/commit/1e7d504a5d0003b1c71e8bcacc3476002107d414
-rw-r--r--plugins/mouse/msd-mouse-manager.c90
1 files changed, 88 insertions, 2 deletions
diff --git a/plugins/mouse/msd-mouse-manager.c b/plugins/mouse/msd-mouse-manager.c
index 6c9dd99..ab1b116 100644
--- a/plugins/mouse/msd-mouse-manager.c
+++ b/plugins/mouse/msd-mouse-manager.c
@@ -511,8 +511,8 @@ set_devicepresence_handler (MsdMouseManager *manager)
}
static void
-set_motion (MsdMouseManager *manager,
- XDeviceInfo *device_info)
+set_motion_legacy_driver (MsdMouseManager *manager,
+ XDeviceInfo *device_info)
{
XDevice *device;
XPtrFeedbackControl feedback;
@@ -601,6 +601,92 @@ set_motion (MsdMouseManager *manager,
}
static void
+set_motion_libinput (MsdMouseManager *manager,
+ XDeviceInfo *device_info)
+{
+ XDevice *device;
+ Atom prop;
+ Atom type;
+ Atom float_type;
+ int format, rc;
+ unsigned long nitems, bytes_after;
+ GSettings *settings;
+ union {
+ unsigned char *c;
+ long *l;
+ } data;
+ gfloat accel;
+ gfloat motion_acceleration;
+
+ float_type = property_from_name ("FLOAT");
+ if (!float_type)
+ return;
+
+ prop = property_from_name ("libinput Accel Speed");
+ if (!prop) {
+ return;
+ }
+
+ device = device_is_touchpad (device_info);
+ if (device != NULL) {
+ settings = manager->priv->settings_touchpad;
+ } else {
+ gdk_error_trap_push ();
+ device = XOpenDevice (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), device_info->id);
+ if ((gdk_error_trap_pop () != 0) || (device == NULL))
+ return;
+
+ settings = manager->priv->settings_mouse;
+ }
+
+ /* Calculate acceleration */
+ motion_acceleration = g_settings_get_double (settings, KEY_MOTION_ACCELERATION);
+
+ /* panel gives us a range of 1.0-10.0, map to libinput's [-1, 1]
+ *
+ * oldrange = (oldmax - oldmin)
+ * newrange = (newmax - newmin)
+ *
+ * mapped = (value - oldmin) * newrange / oldrange + oldmin
+ */
+
+ if (motion_acceleration == -1.0) /* unset */
+ accel = 0.0;
+ else
+ accel = (motion_acceleration - 1.0) * 2.0 / 9.0 - 1;
+
+ gdk_error_trap_push ();
+ rc = XGetDeviceProperty (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()),
+ device, prop, 0, 1, False, float_type, &type, &format,
+ &nitems, &bytes_after, &data.c);
+
+ if (rc == Success && type == float_type && format == 32 && nitems >= 1) {
+ *(float *) data.l = accel;
+ XChangeDeviceProperty (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()),
+ device, prop, float_type, 32, PropModeReplace, data.c, nitems);
+ }
+
+ if (rc == Success) {
+ XFree (data.c);
+ }
+
+ XCloseDevice (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), device);
+ if (gdk_error_trap_pop ()) {
+ g_warning ("Error while setting accel speed on \"%s\"", device_info->name);
+ }
+}
+
+static void
+set_motion (MsdMouseManager *manager,
+ XDeviceInfo *device_info)
+{
+ if (property_exists_on_device (device_info, "libinput Accel Speed"))
+ set_motion_libinput (manager, device_info);
+ else
+ set_motion_legacy_driver (manager, device_info);
+}
+
+static void
set_motion_all (MsdMouseManager *manager)
{
XDeviceInfo *device_info;