<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Sep 14, 2017 at 3:04 AM, Peter Hutterer <span dir="ltr"><<a href="mailto:peter.hutterer@who-t.net" target="_blank">peter.hutterer@who-t.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Some devices like the UC Logic WP5540U has BTN_STYLUS but not BTN_TOOL_PEN.<br>
While a kernel bug, let's just handle these correctly anyway.<br>
<br>
<a href="https://bugs.freedesktop.org/show_bug.cgi?id=102570" rel="noreferrer" target="_blank">https://bugs.freedesktop.org/<wbr>show_bug.cgi?id=102570</a><br>
<br>
Signed-off-by: Peter Hutterer <<a href="mailto:peter.hutterer@who-t.net">peter.hutterer@who-t.net</a>><br>
---<br></blockquote><div><br></div><div>Hi,</div><div><br></div><div>I had a look at the kernel and here is what I think:</div><div>long story short: hid-uclogic uses "pure" HID, i.e. through hid-input.c, to assign and process usages. It could be said that there is no logic, the driver just forwards the incoming events.</div><div>So, knowing that BTN_TOOL_PEN is mapped when we see an InRange HID usage, this means that either the tablet are not fixed because they appeared after DIGIMend died, or they simply don't provide the information.</div><div><br></div><div>I think the latter is more probable and will be more frequent.</div><div><br></div><div>So basically, all we *could* do in the kernel is to emulate BTN_TOOL_PEN based on heuristics, which is basically what you are doing here. And I think having heuristics in user space is much better than having them in the kernel where any fix will have a 3 months delay before going into the users hands.</div><div><br></div><div>So I think the libinput only fix is the correct one (IMHO).<br></div><div><br></div><div>Yay-by: Benjamin Tissoires <<a href="mailto:benjamin.tissoires@gmail.com">benjamin.tissoires@gmail.com</a>></div><div><br></div><div>Cheers,</div><div>Benjamin<br></div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
 meson.build                         |   1 +<br>
 src/evdev-tablet.c                  |  16 +++++-<br>
 test/litest-device-uclogic-<wbr>tablet.c | 106 ++++++++++++++++++++++++++++++<wbr>++++++<br>
 test/litest.c                       |   2 +<br>
 test/litest.h                       |   1 +<br>
 test/test-tablet.c                  |   2 +<br>
 6 files changed, 126 insertions(+), 2 deletions(-)<br>
 create mode 100644 test/litest-device-uclogic-<wbr>tablet.c<br>
<br>
diff --git a/meson.build b/meson.build<br>
index 41381553..dc3ab1b6 100644<br>
--- a/meson.build<br>
+++ b/meson.build<br>
@@ -569,6 +569,7 @@ if get_option('tests')<br>
                'test/litest-device-<wbr>trackpoint.c',<br>
                'test/litest-device-touch-<wbr>screen.c',<br>
                'test/litest-device-<wbr>touchscreen-fuzz.c',<br>
+               'test/litest-device-uclogic-<wbr>tablet.c',<br>
                'test/litest-device-wacom-<wbr>bamboo-16fg-pen.c',<br>
                'test/litest-device-wacom-<wbr>cintiq-12wx-pen.c',<br>
                'test/litest-device-wacom-<wbr>cintiq-13hdt-finger.c',<br>
diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c<br>
index 057b498c..7e9281d1 100644<br>
--- a/src/evdev-tablet.c<br>
+++ b/src/evdev-tablet.c<br>
@@ -1975,7 +1975,8 @@ tablet_reject_device(struct evdev_device *device)<br>
            !libevdev_has_event_code(<wbr>evdev, EV_ABS, ABS_Y))<br>
                goto out;<br>
<br>
-       if (!libevdev_has_event_code(<wbr>evdev, EV_KEY, BTN_TOOL_PEN))<br>
+       if (!libevdev_has_event_code(<wbr>evdev, EV_KEY, BTN_TOOL_PEN) &&<br>
+           !libevdev_has_event_code(<wbr>evdev, EV_KEY, BTN_STYLUS))<br>
                goto out;<br>
<br>
        if (evdev_device_get_size(device, &w, &h) != 0)<br>
@@ -1996,7 +1997,9 @@ static int<br>
 tablet_init(struct tablet_dispatch *tablet,<br>
            struct evdev_device *device)<br>
 {<br>
+       struct libevdev *evdev = device->evdev;<br>
        enum libinput_tablet_tool_axis axis;<br>
+       bool want_proximity_quirk = false;<br>
        int rc;<br>
<br>
        tablet->base.dispatch_type = DISPATCH_TABLET;<br>
@@ -2026,7 +2029,16 @@ tablet_init(struct tablet_dispatch *tablet,<br>
<br>
        tablet_set_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY);<br>
<br>
-       if (device->model_flags & EVDEV_MODEL_TABLET_NO_<wbr>PROXIMITY_OUT) {<br>
+       if (!libevdev_has_event_code(<wbr>evdev, EV_KEY, BTN_TOOL_PEN)) {<br>
+               libevdev_enable_event_code(<wbr>evdev, EV_KEY, BTN_TOOL_PEN, NULL);<br>
+               want_proximity_quirk = true;<br>
+               tablet->quirks.proximity_out_<wbr>forced = true;<br>
+       }<br>
+<br>
+       if (device->model_flags & EVDEV_MODEL_TABLET_NO_<wbr>PROXIMITY_OUT)<br>
+               want_proximity_quirk = true;<br>
+<br>
+       if (want_proximity_quirk) {<br>
                tablet->quirks.need_to_force_<wbr>prox_out = true;<br>
                libinput_timer_init(&tablet-><wbr>quirks.prox_out_timer,<br>
                                    tablet_libinput_context(<wbr>tablet),<br>
diff --git a/test/litest-device-uclogic-<wbr>tablet.c b/test/litest-device-uclogic-<wbr>tablet.c<br>
new file mode 100644<br>
index 00000000..b0393d65<br>
--- /dev/null<br>
+++ b/test/litest-device-uclogic-<wbr>tablet.c<br>
@@ -0,0 +1,106 @@<br>
+/*<br>
+ * Copyright © 2017 Red Hat, Inc.<br>
+ *<br>
+ * Permission is hereby granted, free of charge, to any person obtaining a<br>
+ * copy of this software and associated documentation files (the "Software"),<br>
+ * to deal in the Software without restriction, including without limitation<br>
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,<br>
+ * and/or sell copies of the Software, and to permit persons to whom the<br>
+ * Software is furnished to do so, subject to the following conditions:<br>
+ *<br>
+ * The above copyright notice and this permission notice (including the next<br>
+ * paragraph) shall be included in all copies or substantial portions of the<br>
+ * Software.<br>
+ *<br>
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br>
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL<br>
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br>
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING<br>
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER<br>
+ * DEALINGS IN THE SOFTWARE.<br>
+ */<br>
+<br>
+#include "config.h"<br>
+<br>
+#include "litest.h"<br>
+#include "litest-int.h"<br>
+<br>
+static void litest_uclogic_tablet_setup(<wbr>void)<br>
+{<br>
+       struct litest_device *d = litest_create_device(LITEST_<wbr>UCLOGIC_TABLET);<br>
+       litest_set_current_device(d);<br>
+}<br>
+<br>
+static struct input_event proximity_in[] = {<br>
+       { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN },<br>
+       { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN },<br>
+       { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN },<br>
+       { .type = EV_SYN, .code = SYN_REPORT, .value = 0 },<br>
+       { .type = -1, .code = -1 },<br>
+};<br>
+<br>
+static struct input_event proximity_out[] = {<br>
+       { .type = -1, .code = -1 },<br>
+};<br>
+<br>
+static struct input_event motion[] = {<br>
+       { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN },<br>
+       { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN },<br>
+       { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN },<br>
+       { .type = EV_SYN, .code = SYN_REPORT, .value = 0 },<br>
+       { .type = -1, .code = -1 },<br>
+};<br>
+<br>
+static int<br>
+get_axis_default(struct litest_device *d, unsigned int evcode, int32_t *value)<br>
+{<br>
+       switch (evcode) {<br>
+       case ABS_PRESSURE:<br>
+               *value = 100;<br>
+               return 0;<br>
+       }<br>
+       return 1;<br>
+}<br>
+<br>
+static struct litest_device_interface interface = {<br>
+       .tablet_proximity_in_events = proximity_in,<br>
+       .tablet_proximity_out_events = proximity_out,<br>
+       .tablet_motion_events = motion,<br>
+<br>
+       .get_axis_default = get_axis_default,<br>
+};<br>
+<br>
+static struct input_absinfo absinfo[] = {<br>
+       { ABS_X, 0, 32767, 0, 0, 235 },<br>
+       { ABS_Y, 0, 32767, 0, 0, 323 },<br>
+       { ABS_PRESSURE, 0, 1023, 0, 0, 0 },<br>
+       { .value = -1 },<br>
+};<br>
+<br>
+static struct input_id input_id = {<br>
+       .bustype = 0x3,<br>
+       .vendor = 0x256c,<br>
+       .product = 0x6e,<br>
+};<br>
+<br>
+static int events[] = {<br>
+       EV_KEY, BTN_TOUCH,<br>
+       EV_KEY, BTN_STYLUS,<br>
+       EV_KEY, BTN_STYLUS2,<br>
+       EV_MSC, MSC_SCAN,<br>
+       -1, -1,<br>
+};<br>
+<br>
+struct litest_test_device litest_uclogic_tablet_device = {<br>
+       .type = LITEST_UCLOGIC_TABLET,<br>
+       .features = LITEST_TABLET,<br>
+       .shortname = "uclogic-tablet",<br>
+       .setup = litest_uclogic_tablet_setup,<br>
+       .interface = &interface,<br>
+<br>
+       .name = "uclogic PenTablet Pen",<br>
+       .id = &input_id,<br>
+       .events = events,<br>
+       .absinfo = absinfo,<br>
+};<br>
diff --git a/test/litest.c b/test/litest.c<br>
index 868dfb69..cb95a670 100644<br>
--- a/test/litest.c<br>
+++ b/test/litest.c<br>
@@ -418,6 +418,7 @@ extern struct litest_test_device litest_gpio_keys_device;<br>
 extern struct litest_test_device litest_ignored_mouse_device;<br>
 extern struct litest_test_device litest_wacom_mobilestudio_<wbr>13hdt_pad_device;<br>
 extern struct litest_test_device litest_thinkpad_extrabuttons_<wbr>device;<br>
+extern struct litest_test_device litest_uclogic_tablet_device;<br>
<br>
 struct litest_test_device* devices[] = {<br>
        &litest_synaptics_clickpad_<wbr>device,<br>
@@ -487,6 +488,7 @@ struct litest_test_device* devices[] = {<br>
        &litest_ignored_mouse_device,<br>
        &litest_wacom_mobilestudio_<wbr>13hdt_pad_device,<br>
        &litest_thinkpad_extrabuttons_<wbr>device,<br>
+       &litest_uclogic_tablet_device,<br>
        NULL,<br>
 };<br>
<br>
diff --git a/test/litest.h b/test/litest.h<br>
index 8f3c3bc9..5868045c 100644<br>
--- a/test/litest.h<br>
+++ b/test/litest.h<br>
@@ -238,6 +238,7 @@ enum litest_device_type {<br>
        LITEST_IGNORED_MOUSE,<br>
        LITEST_WACOM_MOBILESTUDIO_PRO_<wbr>16_PAD,<br>
        LITEST_THINKPAD_EXTRABUTTONS,<br>
+       LITEST_UCLOGIC_TABLET,<br>
 };<br>
<br>
 enum litest_device_feature {<br>
diff --git a/test/test-tablet.c b/test/test-tablet.c<br>
index 4a36c79a..66b4f79c 100644<br>
--- a/test/test-tablet.c<br>
+++ b/test/test-tablet.c<br>
@@ -260,6 +260,8 @@ tablet_has_proxout_quirk(<wbr>struct litest_device *dev)<br>
<br>
        has_quirk = !!udev_device_get_property_<wbr>value(udev_device,<br>
                           "LIBINPUT_MODEL_TABLET_NO_<wbr>PROXIMITY_OUT");<br>
+       if (!has_quirk)<br>
+               has_quirk = !libevdev_has_event_code(dev-><wbr>evdev, EV_KEY, BTN_TOOL_PEN);<br>
<br>
        udev_device_unref(udev_device)<wbr>;<br>
<span class="gmail-HOEnZb"><font color="#888888"><br>
--<br>
2.13.5<br>
<br>
______________________________<wbr>_________________<br>
wayland-devel mailing list<br>
<a href="mailto:wayland-devel@lists.freedesktop.org">wayland-devel@lists.<wbr>freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/wayland-devel" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/wayland-devel</a><br>
</font></span></blockquote></div><br></div></div>