From 55974dcac53021c7f690e25ac8bcfe1a9960aa8c Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 8 Jul 2015 15:03:06 +1000 Subject: [PATCH] Add a configuration interface for enabling/disabling disable-while-typing DWT can interfere with some applications where keyboard and touchpad use at the same time is common, e.g. games but also anything that requires a combination of frequent pointer motion and use of keyboard shortcuts. Expose a toggle to disable DWT where needed. https://bugs.freedesktop.org/show_bug.cgi?id=90624 Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede --- src/libinput-private.h | 12 +++++ src/libinput.c | 42 ++++++++++++++++ src/libinput.h | 90 +++++++++++++++++++++++++++++++++++ src/libinput.sym | 7 +++ tools/event-debug.c | 8 ++++ tools/libinput-list-devices.c | 14 ++++++ tools/shared.c | 16 +++++++ tools/shared.h | 1 + 8 files changed, 190 insertions(+) diff --git a/src/libinput-private.h b/src/libinput-private.h index 927528b9..110955db 100644 --- a/src/libinput-private.h +++ b/src/libinput-private.h @@ -196,6 +196,17 @@ struct libinput_device_config_middle_emulation { struct libinput_device *device); }; +struct libinput_device_config_dwt { + int (*is_available)(struct libinput_device *device); + enum libinput_config_status (*set_enabled)( + struct libinput_device *device, + enum libinput_config_dwt_state enable); + enum libinput_config_dwt_state (*get_enabled)( + struct libinput_device *device); + enum libinput_config_dwt_state (*get_default_enabled)( + struct libinput_device *device); +}; + struct libinput_device_config { struct libinput_device_config_tap *tap; struct libinput_device_config_calibration *calibration; @@ -206,6 +217,7 @@ struct libinput_device_config { struct libinput_device_config_scroll_method *scroll_method; struct libinput_device_config_click_method *click_method; struct libinput_device_config_middle_emulation *middle_emulation; + struct libinput_device_config_dwt *dwt; }; struct libinput_device_group { diff --git a/src/libinput.c b/src/libinput.c index 563ad0d3..cab6224a 100644 --- a/src/libinput.c +++ b/src/libinput.c @@ -2401,3 +2401,45 @@ libinput_device_config_scroll_get_default_button(struct libinput_device *device) return device->config.scroll_method->get_default_button(device); } + +LIBINPUT_EXPORT int +libinput_device_config_dwt_is_available(struct libinput_device *device) +{ + if (!device->config.dwt) + return 0; + + return device->config.dwt->is_available(device); +} + +LIBINPUT_EXPORT enum libinput_config_status +libinput_device_config_dwt_set_enabled(struct libinput_device *device, + enum libinput_config_dwt_state enable) +{ + if (enable != LIBINPUT_CONFIG_DWT_ENABLED && + enable != LIBINPUT_CONFIG_DWT_DISABLED) + return LIBINPUT_CONFIG_STATUS_INVALID; + + if (!libinput_device_config_dwt_is_available(device)) + return enable ? LIBINPUT_CONFIG_STATUS_UNSUPPORTED : + LIBINPUT_CONFIG_STATUS_SUCCESS; + + return device->config.dwt->set_enabled(device, enable); +} + +LIBINPUT_EXPORT enum libinput_config_dwt_state +libinput_device_config_dwt_get_enabled(struct libinput_device *device) +{ + if (!libinput_device_config_dwt_is_available(device)) + return LIBINPUT_CONFIG_DWT_DISABLED; + + return device->config.dwt->get_enabled(device); +} + +LIBINPUT_EXPORT enum libinput_config_dwt_state +libinput_device_config_dwt_get_default_enabled(struct libinput_device *device) +{ + if (!libinput_device_config_dwt_is_available(device)) + return LIBINPUT_CONFIG_DWT_DISABLED; + + return device->config.dwt->get_default_enabled(device); +} diff --git a/src/libinput.h b/src/libinput.h index 3595fd1d..f9a7d681 100644 --- a/src/libinput.h +++ b/src/libinput.h @@ -3078,6 +3078,96 @@ libinput_device_config_scroll_get_button(struct libinput_device *device); uint32_t libinput_device_config_scroll_get_default_button(struct libinput_device *device); +/** + * @ingroup config + * + * Possible states for the disable-while-typing feature. See @ref + * disable-while-typing for details. + */ +enum libinput_config_dwt_state { + LIBINPUT_CONFIG_DWT_DISABLED, + LIBINPUT_CONFIG_DWT_ENABLED, +}; + +/** + * @ingroup config + * + * Check if this device supports configurable disable-while-typing feature. + * This feature is usally available on built-in touchpads and disables the + * touchpad while typing. See @ref disable-while-typing for details. + * + * @param device The device to configure + * @return 0 if this device does not support disable-while-typing, or 1 + * otherwise. + * + * @see libinput_device_config_dwt_set_enabled + * @see libinput_device_config_dwt_get_enabled + * @see libinput_device_config_dwt_get_default_enabled + */ +int +libinput_device_config_dwt_is_available(struct libinput_device *device); + +/** + * @ingroup config + * + * Enable or disable the disable-while-typing feature. When enabled, the + * device will be disabled while typing and for a short period after. See + * @ref disable-while-typing for details. + * + * @note Enabling or disabling disable-while-typing may not take effect + * immediately. + * + * @param device The device to configure + * @param enable @ref LIBINPUT_CONFIG_DWT_DISABLED to disable + * disable-while-typing, @ref LIBINPUT_CONFIG_DWT_ENABLED to enable + * + * @return A config status code. Disabling disable-while-typing on a + * device that does not support the feature always succeeds. + * + * @see libinput_device_config_dwt_is_available + * @see libinput_device_config_dwt_get_enabled + * @see libinput_device_config_dwt_get_default_enabled + */ +enum libinput_config_status +libinput_device_config_dwt_set_enabled(struct libinput_device *device, + enum libinput_config_dwt_state enable); + +/** + * @ingroup config + * + * Check if the disable-while typing feature is currently enabled on this + * device. If the device does not support disable-while-typing, this + * function returns @ref LIBINPUT_CONFIG_DWT_DISABLED. + * + * @param device The device to configure + * @return @ref LIBINPUT_CONFIG_DWT_DISABLED if disabled, @ref + * LIBINPUT_CONFIG_DWT_ENABLED if enabled. + * + * @see libinput_device_config_dwt_is_available + * @see libinput_device_config_dwt_set_enabled + * @see libinput_device_config_dwt_get_default_enabled + */ +enum libinput_config_dwt_state +libinput_device_config_dwt_get_enabled(struct libinput_device *device); + +/** + * @ingroup config + * + * Check if the disable-while typing feature is enabled on this device by + * default. If the device does not support disable-while-typing, this + * function returns @ref LIBINPUT_CONFIG_DWT_DISABLED. + * + * @param device The device to configure + * @return @ref LIBINPUT_CONFIG_DWT_DISABLED if disabled, @ref + * LIBINPUT_CONFIG_DWT_ENABLED if enabled. + * + * @see libinput_device_config_dwt_is_available + * @see libinput_device_config_dwt_set_enabled + * @see libinput_device_config_dwt_get_enabled + */ +enum libinput_config_dwt_state +libinput_device_config_dwt_get_default_enabled(struct libinput_device *device); + #ifdef __cplusplus } #endif diff --git a/src/libinput.sym b/src/libinput.sym index 6bdd3bab..d7d12e40 100644 --- a/src/libinput.sym +++ b/src/libinput.sym @@ -161,3 +161,10 @@ LIBINPUT_0.20.0 { libinput_event_gesture_get_time; libinput_event_get_gesture_event; } LIBINPUT_0.19.0; + +LIBINPUT_0.21.0 { + libinput_device_config_dwt_is_available; + libinput_device_config_dwt_set_enabled; + libinput_device_config_dwt_get_enabled; + libinput_device_config_dwt_get_default_enabled; +} LIBINPUT_0.20.0; diff --git a/tools/event-debug.c b/tools/event-debug.c index 44e22e18..1ac00864 100644 --- a/tools/event-debug.c +++ b/tools/event-debug.c @@ -194,6 +194,14 @@ print_device_notify(struct libinput_event *ev) printf("-clickfinger"); } + if (libinput_device_config_dwt_is_available(dev)) { + if (libinput_device_config_dwt_get_enabled(dev) == + LIBINPUT_CONFIG_DWT_ENABLED) + printf(" dwt-on"); + else + printf(" dwt-off)"); + } + printf("\n"); } diff --git a/tools/libinput-list-devices.c b/tools/libinput-list-devices.c index f9ce7e46..c156bf0b 100644 --- a/tools/libinput-list-devices.c +++ b/tools/libinput-list-devices.c @@ -172,6 +172,18 @@ click_defaults(struct libinput_device *device) return str; } +static const char * +dwt_default(struct libinput_device *device) +{ + if (!libinput_device_config_dwt_is_available(device)) + return "n/a"; + + if (libinput_device_config_dwt_get_default_enabled(device)) + return "enabled"; + else + return "disabled"; +} + static void print_device_notify(struct libinput_event *ev) { @@ -235,6 +247,8 @@ print_device_notify(struct libinput_event *ev) printf("Click methods: %s\n", str); free(str); + printf("Disable-w-typing: %s\n", dwt_default(dev)); + printf("\n"); } diff --git a/tools/shared.c b/tools/shared.c index 64544c5c..cea4c50c 100644 --- a/tools/shared.c +++ b/tools/shared.c @@ -53,6 +53,8 @@ enum options { OPT_LEFT_HANDED_DISABLE, OPT_MIDDLEBUTTON_ENABLE, OPT_MIDDLEBUTTON_DISABLE, + OPT_DWT_ENABLE, + OPT_DWT_DISABLE, OPT_CLICK_METHOD, OPT_SCROLL_METHOD, OPT_SCROLL_BUTTON, @@ -87,6 +89,8 @@ tools_usage() "--disable-left-handed.... enable/disable left-handed button configuration\n" "--enable-middlebutton\n" "--disable-middlebutton.... enable/disable middle button emulation\n" + "--enable-dwt\n" + "--disable-dwt..... enable/disable disable-while-typing\n" "--set-click-method=[none|clickfinger|buttonareas] .... set the desired click method\n" "--set-scroll-method=[none|twofinger|edge|button] ... set the desired scroll method\n" "--set-scroll-button=BTN_MIDDLE ... set the button to the given button code\n" @@ -115,6 +119,7 @@ tools_init_context(struct tools_context *context) options->natural_scroll = -1; options->left_handed = -1; options->middlebutton = -1; + options->dwt = -1; options->click_method = -1; options->scroll_method = -1; options->scroll_button = -1; @@ -147,6 +152,8 @@ tools_parse_args(int argc, char **argv, struct tools_context *context) { "disable-left-handed", 0, 0, OPT_LEFT_HANDED_DISABLE }, { "enable-middlebutton", 0, 0, OPT_MIDDLEBUTTON_ENABLE }, { "disable-middlebutton", 0, 0, OPT_MIDDLEBUTTON_DISABLE }, + { "enable-dwt", 0, 0, OPT_DWT_ENABLE }, + { "disable-dwt", 0, 0, OPT_DWT_DISABLE }, { "set-click-method", 1, 0, OPT_CLICK_METHOD }, { "set-scroll-method", 1, 0, OPT_SCROLL_METHOD }, { "set-scroll-button", 1, 0, OPT_SCROLL_BUTTON }, @@ -212,6 +219,12 @@ tools_parse_args(int argc, char **argv, struct tools_context *context) case OPT_MIDDLEBUTTON_DISABLE: options->middlebutton = 0; break; + case OPT_DWT_ENABLE: + options->dwt = LIBINPUT_CONFIG_DWT_ENABLED; + break; + case OPT_DWT_DISABLE: + options->dwt = LIBINPUT_CONFIG_DWT_DISABLED; + break; case OPT_CLICK_METHOD: if (!optarg) { tools_usage(); @@ -419,6 +432,9 @@ tools_device_apply_config(struct libinput_device *device, libinput_device_config_middle_emulation_set_enabled(device, options->middlebutton); + if (options->dwt != -1) + libinput_device_config_dwt_set_enabled(device, options->dwt); + if (options->click_method != -1) libinput_device_config_click_set_method(device, options->click_method); diff --git a/tools/shared.h b/tools/shared.h index a848e2d1..a9cf6d96 100644 --- a/tools/shared.h +++ b/tools/shared.h @@ -47,6 +47,7 @@ struct tools_options { enum libinput_config_scroll_method scroll_method; int scroll_button; double speed; + int dwt; }; struct tools_context {