diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2015-04-23 17:48:44 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2015-04-23 17:48:44 +1000 |
commit | d5fa03c3433637c0fa8cbbfb38dadcf384f06ac3 (patch) | |
tree | 6a609c00ed7ca4344f1713ab9afdbc99c1a7ceb4 | |
parent | 446401bea9d0335273963f476e897d8c4916420e (diff) |
Add a property for middle button emulation
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | include/libinput-properties.h | 7 | ||||
-rw-r--r-- | man/libinput.man | 9 | ||||
-rw-r--r-- | src/libinput.c | 87 |
4 files changed, 103 insertions, 2 deletions
diff --git a/configure.ac b/configure.ac index 0ba780c..aab6356 100644 --- a/configure.ac +++ b/configure.ac @@ -45,7 +45,7 @@ XORG_DEFAULT_OPTIONS # Obtain compiler/linker options from server and required extensions PKG_CHECK_MODULES(XORG, [xorg-server >= 1.10] xproto [inputproto >= 2.2]) -PKG_CHECK_MODULES(LIBINPUT, [libinput >= 0.11.0]) +PKG_CHECK_MODULES(LIBINPUT, [libinput >= 0.14.0]) # Define a configure option for an alternate input module directory AC_ARG_WITH(xorg-module-dir, diff --git a/include/libinput-properties.h b/include/libinput-properties.h index 8947126..6760b50 100644 --- a/include/libinput-properties.h +++ b/include/libinput-properties.h @@ -95,4 +95,11 @@ /* Click method: BOOL, 2 values in order buttonareas, clickfinger only one enabled at a time at max, read-only */ #define LIBINPUT_PROP_CLICK_METHOD_ENABLED_DEFAULT "libinput Click Method Enabled Default" + +/* Middle button emulation: BOOL, 1 value */ +#define LIBINPUT_PROP_MIDDLE_EMULATION_ENABLED "libinput Middle Emulation Enabled" + +/* Middle button emulation: BOOL, 1 value, read-only */ +#define LIBINPUT_PROP_MIDDLE_EMULATION_ENABLED_DEFAULT "libinput Middle Emulation Enabled Default" + #endif /* _LIBINPUT_PROPERTIES_H_ */ diff --git a/man/libinput.man b/man/libinput.man index e807578..4d44c18 100644 --- a/man/libinput.man +++ b/man/libinput.man @@ -64,6 +64,10 @@ default click method for this device is used. .BI "Option \*qLeftHanded\*q \*q" bool \*q Enables left-handed button orientation, i.e. swapping left and right buttons. .TP 7 +.BI "Option \*qMiddleEmulation\*q \*q" bool \*q +Enables middle button emulation. When enabled, pressing the left and right +buttons simultaneously produces a middle mouse button click. +.TP 7 .BI "Option \*qNaturalScrolling\*q \*q" bool \*q Enables or disables natural scrolling behavior. .TP 7 @@ -151,6 +155,11 @@ Indicates which click methods are available on this device. .BI "libinput Click Methods Enabled" 2 boolean values (8 bit, 0 or 1), in order "buttonareas", "clickfinger". Indicates which click methods are enabled on this device. +.TP 7 +.BI "libinput Middle Emulation Enabled" +1 boolean value (8 bit, 0 or 1). Indicates if middle emulation is enabled or +disabled. +.TP7 .PP The above properties have a .BI "libinput <property name> Default" diff --git a/src/libinput.c b/src/libinput.c index 15a9c1f..ae905df 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -89,6 +89,7 @@ struct xf86libinput { BOOL tapping; BOOL natural_scrolling; BOOL left_handed; + BOOL middle_emulation; CARD32 sendevents; CARD32 scroll_button; /* xorg button number */ float speed; @@ -309,6 +310,13 @@ LibinputApplyConfig(DeviceIntPtr dev) "Failed to set click method to %s\n", method); } + + if (libinput_device_config_middle_emulation_is_available(device) && + libinput_device_config_middle_emulation_set_enabled(device, + driver_data->options.middle_emulation) != LIBINPUT_CONFIG_STATUS_SUCCESS) + xf86IDrvMsg(pInfo, X_ERROR, + "Failed to set MiddleEmulation to %d\n", + driver_data->options.middle_emulation); } static int @@ -1167,6 +1175,20 @@ xf86libinput_parse_options(InputInfoPtr pInfo, driver_data->options.click_method = m; free(method); } + + if (libinput_device_config_middle_emulation_is_available(device)) { + BOOL enabled = xf86SetBoolOption(pInfo->options, + "MiddleEmulation", + libinput_device_config_middle_emulation_get_default_enabled(device)); + if (libinput_device_config_middle_emulation_set_enabled(device, enabled) != + LIBINPUT_CONFIG_STATUS_SUCCESS) { + xf86IDrvMsg(pInfo, X_ERROR, + "Failed to set MiddleEmulation to %d\n", + enabled); + enabled = libinput_device_config_middle_emulation_get_enabled(device); + } + driver_data->options.middle_emulation = enabled; + } } static int @@ -1347,6 +1369,8 @@ static Atom prop_scroll_button_default; static Atom prop_click_methods_available; static Atom prop_click_method_enabled; static Atom prop_click_method_default; +static Atom prop_middle_emulation; +static Atom prop_middle_emulation_default; /* general properties */ static Atom prop_float; @@ -1694,6 +1718,37 @@ LibinputSetPropertyClickMethod(DeviceIntPtr dev, return Success; } +static inline int +LibinputSetPropertyMiddleEmulation(DeviceIntPtr dev, + Atom atom, + XIPropertyValuePtr val, + BOOL checkonly) +{ + InputInfoPtr pInfo = dev->public.devicePrivate; + struct xf86libinput *driver_data = pInfo->private; + struct libinput_device *device = driver_data->device; + BOOL* data; + + if (val->format != 8 || val->size != 1 || val->type != XA_INTEGER) + return BadMatch; + + data = (BOOL*)val->data; + if (checkonly) { + if (*data != 0 && *data != 1) + return BadValue; + + if (!xf86libinput_check_device(dev, atom)) + return BadMatch; + + if (!libinput_device_config_middle_emulation_is_available(device)) + return BadMatch; + } else { + driver_data->options.middle_emulation = *data; + } + + return Success; +} + static int LibinputSetProperty(DeviceIntPtr dev, Atom atom, XIPropertyValuePtr val, BOOL checkonly) @@ -1725,6 +1780,8 @@ LibinputSetProperty(DeviceIntPtr dev, Atom atom, XIPropertyValuePtr val, return BadAccess; /* read-only */ else if (atom == prop_click_method_enabled) rc = LibinputSetPropertyClickMethod(dev, atom, val, checkonly); + else if (atom == prop_middle_emulation) + rc = LibinputSetPropertyMiddleEmulation(dev, atom, val, checkonly); else if (atom == prop_device || atom == prop_product_id || atom == prop_tap_default || atom == prop_calibration_default || @@ -1734,7 +1791,8 @@ LibinputSetProperty(DeviceIntPtr dev, Atom atom, XIPropertyValuePtr val, atom == prop_left_handed_default || atom == prop_scroll_method_default || atom == prop_scroll_button_default || - atom == prop_click_method_default) + atom == prop_click_method_default || + atom == prop_middle_emulation_default) return BadAccess; /* read-only */ else return Success; @@ -2117,6 +2175,32 @@ LibinputInitClickMethodsProperty(DeviceIntPtr dev, } static void +LibinputInitMiddleEmulationProperty(DeviceIntPtr dev, + struct xf86libinput *driver_data, + struct libinput_device *device) +{ + BOOL middle = driver_data->options.middle_emulation; + + if (!libinput_device_config_middle_emulation_is_available(device)) + return; + + prop_middle_emulation = LibinputMakeProperty(dev, + LIBINPUT_PROP_MIDDLE_EMULATION_ENABLED, + XA_INTEGER, + 8, + 1, + &middle); + if (!prop_middle_emulation) + return; + + middle = libinput_device_config_middle_emulation_get_default_enabled(device); + prop_middle_emulation_default = LibinputMakeProperty(dev, + LIBINPUT_PROP_MIDDLE_EMULATION_ENABLED_DEFAULT, + XA_INTEGER, 8, + 1, &middle); +} + +static void LibinputInitProperty(DeviceIntPtr dev) { InputInfoPtr pInfo = dev->public.devicePrivate; @@ -2136,6 +2220,7 @@ LibinputInitProperty(DeviceIntPtr dev) LibinputInitLeftHandedProperty(dev, driver_data, device); LibinputInitScrollMethodsProperty(dev, driver_data, device); LibinputInitClickMethodsProperty(dev, driver_data, device); + LibinputInitMiddleEmulationProperty(dev, driver_data, device); /* Device node property, read-only */ device_node = driver_data->path; |