summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2016-06-30 15:49:40 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2016-07-04 09:41:33 +1000
commit0526044f6d4ebb614699d87f23de3d3256a568ff (patch)
treebe0cc527eef0185697bf7e7a35151774a85e249e /src
parent9e477d21bce17561c37688b25f1dc990df131265 (diff)
touchpad: remove software middle button when emulation is enabled
Expose the middle button emulation on software buttons as proper config option. When enabled, remove the middle button software button area. https://bugs.freedesktop.org/show_bug.cgi?id=96663 Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Diffstat (limited to 'src')
-rw-r--r--src/evdev-middle-button.c6
-rw-r--r--src/evdev-mt-touchpad-buttons.c92
-rw-r--r--src/evdev-mt-touchpad.c2
-rw-r--r--src/evdev-mt-touchpad.h3
-rw-r--r--src/evdev.h9
-rw-r--r--src/libinput.h4
6 files changed, 111 insertions, 5 deletions
diff --git a/src/evdev-middle-button.c b/src/evdev-middle-button.c
index 48650a45..09f77de4 100644
--- a/src/evdev-middle-button.c
+++ b/src/evdev-middle-button.c
@@ -643,7 +643,7 @@ evdev_middlebutton_handle_timeout(uint64_t now, void *data)
evdev_middlebutton_handle_event(device, now, MIDDLEBUTTON_EVENT_TIMEOUT);
}
-static int
+int
evdev_middlebutton_is_available(struct libinput_device *device)
{
return 1;
@@ -671,7 +671,7 @@ evdev_middlebutton_set(struct libinput_device *device,
return LIBINPUT_CONFIG_STATUS_SUCCESS;
}
-static enum libinput_config_middle_emulation_state
+enum libinput_config_middle_emulation_state
evdev_middlebutton_get(struct libinput_device *device)
{
struct evdev_device *evdev = (struct evdev_device*)device;
@@ -681,7 +681,7 @@ evdev_middlebutton_get(struct libinput_device *device)
LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED;
}
-static enum libinput_config_middle_emulation_state
+enum libinput_config_middle_emulation_state
evdev_middlebutton_get_default(struct libinput_device *device)
{
struct evdev_device *evdev = (struct evdev_device*)device;
diff --git a/src/evdev-mt-touchpad-buttons.c b/src/evdev-mt-touchpad-buttons.c
index a9b75216..a2f31217 100644
--- a/src/evdev-mt-touchpad-buttons.c
+++ b/src/evdev-mt-touchpad-buttons.c
@@ -564,6 +564,13 @@ tp_init_softbuttons(struct tp_dispatch *tp,
tp->buttons.bottom_area.top_edge = height * .85 + yoffset;
}
+ tp->buttons.bottom_area.middlebutton_left_edge = INT_MAX;
+ tp->buttons.bottom_area.rightbutton_left_edge = width/2 + xoffset;
+
+ /* if middlebutton emulation is enabled, don't init a software area */
+ if (device->middlebutton.want_enabled)
+ return;
+
/* The middle button is 25% of the touchpad and centered. Many
* touchpads don't have markings for the middle button at all so we
* need to make it big enough to reliably hit it but not too big so
@@ -699,6 +706,80 @@ tp_button_config_click_get_default_method(struct libinput_device *device)
return tp_click_get_default_method(tp);
}
+void
+tp_clickpad_middlebutton_apply_config(struct evdev_device *device)
+{
+ struct tp_dispatch *tp = (struct tp_dispatch*)device->dispatch;
+
+ if (!tp->buttons.is_clickpad ||
+ tp->buttons.state != 0)
+ return;
+
+ if (device->middlebutton.want_enabled ==
+ device->middlebutton.enabled)
+ return;
+
+ device->middlebutton.enabled = device->middlebutton.want_enabled;
+ if (tp->buttons.click_method ==
+ LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS)
+ tp_init_softbuttons(tp, device);
+}
+
+static int
+tp_clickpad_middlebutton_is_available(struct libinput_device *device)
+{
+ return evdev_middlebutton_is_available(device);
+}
+
+static enum libinput_config_status
+tp_clickpad_middlebutton_set(struct libinput_device *device,
+ enum libinput_config_middle_emulation_state enable)
+{
+ struct evdev_device *evdev = (struct evdev_device*)device;
+
+ switch (enable) {
+ case LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED:
+ evdev->middlebutton.want_enabled = true;
+ break;
+ case LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED:
+ evdev->middlebutton.want_enabled = false;
+ break;
+ default:
+ return LIBINPUT_CONFIG_STATUS_INVALID;
+ }
+
+ tp_clickpad_middlebutton_apply_config(evdev);
+
+ return LIBINPUT_CONFIG_STATUS_SUCCESS;
+}
+
+static enum libinput_config_middle_emulation_state
+tp_clickpad_middlebutton_get(struct libinput_device *device)
+{
+ return evdev_middlebutton_get(device);
+}
+
+static enum libinput_config_middle_emulation_state
+tp_clickpad_middlebutton_get_default(struct libinput_device *device)
+{
+ return evdev_middlebutton_get_default(device);
+}
+
+static inline void
+tp_init_clickpad_middlebutton_emulation(struct tp_dispatch *tp,
+ struct evdev_device *device)
+{
+ device->middlebutton.enabled_default = false;
+ device->middlebutton.want_enabled = false;
+ device->middlebutton.enabled = false;
+
+ device->middlebutton.config.available = tp_clickpad_middlebutton_is_available;
+ device->middlebutton.config.set = tp_clickpad_middlebutton_set;
+ device->middlebutton.config.get = tp_clickpad_middlebutton_get;
+ device->middlebutton.config.get_default = tp_clickpad_middlebutton_get_default;
+ device->base.config.middle_emulation = &device->middlebutton.config;
+}
+
static inline void
tp_init_middlebutton_emulation(struct tp_dispatch *tp,
struct evdev_device *device)
@@ -706,8 +787,12 @@ tp_init_middlebutton_emulation(struct tp_dispatch *tp,
bool enable_by_default,
want_config_option;
- if (tp->buttons.is_clickpad)
+ /* On clickpads we provide the config option but disable by default.
+ When enabled, the middle software button disappears */
+ if (tp->buttons.is_clickpad) {
+ tp_init_clickpad_middlebutton_emulation(tp, device);
return;
+ }
/* init middle button emulation on non-clickpads, but only if we
* don't have a middle button. Exception: ALPS touchpads don't know
@@ -1038,7 +1123,10 @@ tp_post_clickpadbutton_buttons(struct tp_dispatch *tp, uint64_t time)
return 0;
}
- if ((area & MIDDLE) || ((area & LEFT) && (area & RIGHT))) {
+ if ((tp->device->middlebutton.enabled || is_top) &&
+ (area & LEFT) && (area & RIGHT)) {
+ button = BTN_MIDDLE;
+ } else if (area & MIDDLE) {
button = BTN_MIDDLE;
} else if (area & RIGHT) {
button = BTN_RIGHT;
diff --git a/src/evdev-mt-touchpad.c b/src/evdev-mt-touchpad.c
index 21d83ad6..4dd6b641 100644
--- a/src/evdev-mt-touchpad.c
+++ b/src/evdev-mt-touchpad.c
@@ -1145,6 +1145,8 @@ tp_handle_state(struct tp_dispatch *tp,
tp_process_state(tp, time);
tp_post_events(tp, time);
tp_post_process_state(tp, time);
+
+ tp_clickpad_middlebutton_apply_config(tp->device);
}
static void
diff --git a/src/evdev-mt-touchpad.h b/src/evdev-mt-touchpad.h
index 3f3b728a..fe1f1b36 100644
--- a/src/evdev-mt-touchpad.h
+++ b/src/evdev-mt-touchpad.h
@@ -527,4 +527,7 @@ tp_gesture_stop_twofinger_scroll(struct tp_dispatch *tp, uint64_t time);
bool
tp_palm_tap_is_palm(const struct tp_dispatch *tp, const struct tp_touch *t);
+void
+tp_clickpad_middlebutton_apply_config(struct evdev_device *device);
+
#endif
diff --git a/src/evdev.h b/src/evdev.h
index f0fb2f9d..2b60faaf 100644
--- a/src/evdev.h
+++ b/src/evdev.h
@@ -465,6 +465,15 @@ evdev_init_middlebutton(struct evdev_device *device,
bool enabled,
bool want_config);
+enum libinput_config_middle_emulation_state
+evdev_middlebutton_get(struct libinput_device *device);
+
+int
+evdev_middlebutton_is_available(struct libinput_device *device);
+
+enum libinput_config_middle_emulation_state
+evdev_middlebutton_get_default(struct libinput_device *device);
+
static inline double
evdev_convert_to_mm(const struct input_absinfo *absinfo, double v)
{
diff --git a/src/libinput.h b/src/libinput.h
index ed3eb7d7..abc737e5 100644
--- a/src/libinput.h
+++ b/src/libinput.h
@@ -4307,6 +4307,10 @@ libinput_device_config_middle_emulation_is_available(
*
* The middle button emulation behavior when combined with other device
* buttons, including a physical middle button is device-dependent.
+ * For example, @ref clickpad_softbuttons provides a middle button area when
+ * middle button emulation is disabled. That middle button area disappears
+ * when middle button emulation is enabled - a middle click can then only be
+ * triggered by a simultaneous left + right click.
*
* @note Some devices provide middle mouse button emulation but do not allow
* enabling/disabling that emulation.