From e3800c8a9a865b4ddeb4aef10081ac0b52996883 Mon Sep 17 00:00:00 2001 From: monsta Date: Fri, 23 Dec 2016 14:00:34 +0300 Subject: mouse: libinput - hook up click methods note: libinput does not allow for configuration of the click actions, the options are just "software buttons" or "clickfinger". If any clickfinger actions are set, we enable clickfinger, otherwise software buttons. adapted from: https://github.com/linuxmint/cinnamon-settings-daemon/commit/6394ea6c2754c434897cebfc6c331b4ee07ce1b8 --- plugins/mouse/msd-mouse-manager.c | 65 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 3 deletions(-) (limited to 'plugins') diff --git a/plugins/mouse/msd-mouse-manager.c b/plugins/mouse/msd-mouse-manager.c index b48189b..43fd124 100644 --- a/plugins/mouse/msd-mouse-manager.c +++ b/plugins/mouse/msd-mouse-manager.c @@ -810,9 +810,9 @@ set_tap_to_click_all (MsdMouseManager *manager) } static void -set_click_actions (XDeviceInfo *device_info, - gint enable_two_finger_click, - gint enable_three_finger_click) +set_click_actions_synaptics (XDeviceInfo *device_info, + gint enable_two_finger_click, + gint enable_three_finger_click) { XDevice *device; int format, rc; @@ -851,7 +851,66 @@ set_click_actions (XDeviceInfo *device_info, if (gdk_error_trap_pop ()) { g_warning ("Error in setting click actions on \"%s\"", device_info->name); } +} + +static void +set_click_actions_libinput (XDeviceInfo *device_info, + gint enable_two_finger_click, + gint enable_three_finger_click) +{ + XDevice *device; + int format, rc; + unsigned long nitems, bytes_after; + unsigned char *data; + Atom prop, type; + gboolean want_clickfinger; + gboolean want_softwarebuttons; + + prop = property_from_name ("libinput Click Method Enabled"); + if (!prop) + return; + + device = device_is_touchpad (device_info); + if (device == NULL) { + return; + } + + g_debug ("setting click action to click on %s", device_info->name); + + want_clickfinger = enable_two_finger_click || enable_three_finger_click; + want_softwarebuttons = !want_clickfinger; + + gdk_error_trap_push (); + rc = XGetDeviceProperty (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), device, prop, 0, 2, + False, XA_INTEGER, &type, &format, &nitems, + &bytes_after, &data); + + if (rc == Success && type == XA_INTEGER && format == 8 && nitems >= 2) { + data[0] = want_softwarebuttons; + data[1] = want_clickfinger; + XChangeDeviceProperty (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), device, prop, + XA_INTEGER, 8, PropModeReplace, data, nitems); + } + + if (rc == Success) + XFree (data); + + XCloseDevice (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), device); + if (gdk_error_trap_pop ()) { + g_warning ("Error in setting click actions on \"%s\"", device_info->name); + } +} + +static void +set_click_actions (XDeviceInfo *device_info, + gint enable_two_finger_click, + gint enable_three_finger_click) +{ + if (property_from_name ("Synaptics Click Action")) + set_click_actions_synaptics (device_info, enable_two_finger_click, enable_three_finger_click); + if (property_from_name ("libinput Click Method Enabled")) + set_click_actions_libinput (device_info, enable_two_finger_click, enable_three_finger_click); } static void -- cgit v1.2.1