[PATCH libinput 1/2] tablet: add a quirk for the HUION PenTablet that doesn't send proximity out events

2017-09-13 Thread Peter Hutterer
Could be fixed in the kernel, but these tablets are effectively abandoned and
fixing them is a one-by-one issue. Let's put the infrastructure in place to
have this fixed once for this type of device and move on.

Signed-off-by: Peter Hutterer 
---
 doc/device-configuration-via-udev.dox |  19 +
 src/evdev-tablet.c| 113 +
 src/evdev-tablet.h|   7 ++
 src/evdev.c   |   1 +
 src/evdev.h   |   1 +
 test/litest-device-huion-pentablet.c  |  15 ++--
 test/litest.c |   6 ++
 test/litest.h |   3 +
 test/test-tablet.c| 132 ++
 udev/90-libinput-model-quirks.hwdb|  19 +
 10 files changed, 312 insertions(+), 4 deletions(-)

diff --git a/doc/device-configuration-via-udev.dox 
b/doc/device-configuration-via-udev.dox
index 2ebfa321..3050cd80 100644
--- a/doc/device-configuration-via-udev.dox
+++ b/doc/device-configuration-via-udev.dox
@@ -162,4 +162,23 @@ model quirks hwdb for instructions.
 This property must not be used for any other purpose, no specific behavior
 is guaranteed.
 
+@subsection model_specific_configuration_huion_tablets Graphics tablets 
without BTN_TOOL_PEN proximity events
+
+On graphics tablets, the BTN_TOOL_PEN bit signals that the pen is in
+detectable range and will send events. When the pen leaves the sensor range,
+the bit must be unset to signal that the tablet is out of proximity again.
+Some HUION PenTablet devices are buggy and do not send this event. To a
+caller, it thus looks like the pen is constantly in proximity. This causes
+unexpected behavior in applications that rely on tablet device proximity.
+
+The property LIBINPUT_MODEL_TABLET_NO_PROXIMITY_OUT may be set
+by a user in a local hwdb file. This property designates the tablet
+to be buggy and that libinput should work around this bug.
+
+Many of the affected tablets cannot be detected automatically by libinput
+because HUION tablets reuse USB IDs.  Local configuration is required to set
+this property. Refer to the libinput model quirks hwdb for instructions.
+
+This property must not be used for any other purpose, no specific behavior
+is guaranteed.
 */
diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c
index 77540496..057b498c 100644
--- a/src/evdev-tablet.c
+++ b/src/evdev-tablet.c
@@ -32,6 +32,10 @@
 #include 
 #endif
 
+/* The tablet sends events every ~2ms , 50ms should be plenty enough to
+   detect out-of-range */
+#define FORCED_PROXOUT_TIMEOUT ms2us(50)
+
 #define tablet_set_status(tablet_,s_) (tablet_)->status |= (s_)
 #define tablet_unset_status(tablet_,s_) (tablet_)->status &= ~(s_)
 #define tablet_has_status(tablet_,s_) (!!((tablet_)->status & (s_)))
@@ -1633,6 +1637,97 @@ tablet_reset_state(struct tablet_dispatch *tablet)
   sizeof(tablet->button_state));
 }
 
+static inline void
+tablet_proximity_out_quirk_set_timer(struct tablet_dispatch *tablet,
+uint64_t time)
+{
+   libinput_timer_set(&tablet->quirks.prox_out_timer,
+  time + FORCED_PROXOUT_TIMEOUT);
+}
+
+static void
+tablet_proximity_out_quirk_timer_func(uint64_t now, void *data)
+{
+   struct tablet_dispatch *tablet = data;
+   struct input_event events[2] = {
+   { .time = us2tv(now),
+ .type = EV_KEY,
+ .code = BTN_TOOL_PEN,
+ .value = 0 },
+   { .time = us2tv(now),
+ .type = EV_SYN,
+ .code = SYN_REPORT,
+ .value = 0 },
+   };
+   struct input_event *e;
+
+   if (tablet->quirks.last_event_time > now - FORCED_PROXOUT_TIMEOUT) {
+   tablet_proximity_out_quirk_set_timer(tablet,
+
tablet->quirks.last_event_time);
+   return;
+   }
+
+   ARRAY_FOR_EACH(events, e) {
+   tablet->base.interface->process(&tablet->base,
+tablet->device,
+e,
+now);
+   }
+
+   tablet->quirks.proximity_out_forced = true;
+}
+
+/**
+ * Handling for the proximity out workaround. Some tablets only send
+ * BTN_TOOL_PEN on the very first event, then leave it set even when the pen
+ * leaves the detectable range. To libinput this looks like we always have
+ * the pen in proximity.
+ *
+ * To avoid this, we set a timer on BTN_TOOL_PEN in. We expect the tablet to
+ * continuously send events, and while it's doing so we keep updating the
+ * timer. Once we go Xms without an event we assume proximity out and inject
+ * a BTN_TOOL_PEN event into the sequence through the timer func.
+ *
+ * We need to remember that we did that, on the first event after the
+ * timeout we need to inject a BTN_TOOL_PEN event again to

[PATCH libinput 2/2] tablet: support tablet devices without BTN_TOOL_PEN

2017-09-13 Thread Peter Hutterer
Some devices like the UC Logic WP5540U has BTN_STYLUS but not BTN_TOOL_PEN.
While a kernel bug, let's just handle these correctly anyway.

https://bugs.freedesktop.org/show_bug.cgi?id=102570

Signed-off-by: Peter Hutterer 
---
 meson.build |   1 +
 src/evdev-tablet.c  |  16 +-
 test/litest-device-uclogic-tablet.c | 106 
 test/litest.c   |   2 +
 test/litest.h   |   1 +
 test/test-tablet.c  |   2 +
 6 files changed, 126 insertions(+), 2 deletions(-)
 create mode 100644 test/litest-device-uclogic-tablet.c

diff --git a/meson.build b/meson.build
index 41381553..dc3ab1b6 100644
--- a/meson.build
+++ b/meson.build
@@ -569,6 +569,7 @@ if get_option('tests')
'test/litest-device-trackpoint.c',
'test/litest-device-touch-screen.c',
'test/litest-device-touchscreen-fuzz.c',
+   'test/litest-device-uclogic-tablet.c',
'test/litest-device-wacom-bamboo-16fg-pen.c',
'test/litest-device-wacom-cintiq-12wx-pen.c',
'test/litest-device-wacom-cintiq-13hdt-finger.c',
diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c
index 057b498c..7e9281d1 100644
--- a/src/evdev-tablet.c
+++ b/src/evdev-tablet.c
@@ -1975,7 +1975,8 @@ tablet_reject_device(struct evdev_device *device)
!libevdev_has_event_code(evdev, EV_ABS, ABS_Y))
goto out;
 
-   if (!libevdev_has_event_code(evdev, EV_KEY, BTN_TOOL_PEN))
+   if (!libevdev_has_event_code(evdev, EV_KEY, BTN_TOOL_PEN) &&
+   !libevdev_has_event_code(evdev, EV_KEY, BTN_STYLUS))
goto out;
 
if (evdev_device_get_size(device, &w, &h) != 0)
@@ -1996,7 +1997,9 @@ static int
 tablet_init(struct tablet_dispatch *tablet,
struct evdev_device *device)
 {
+   struct libevdev *evdev = device->evdev;
enum libinput_tablet_tool_axis axis;
+   bool want_proximity_quirk = false;
int rc;
 
tablet->base.dispatch_type = DISPATCH_TABLET;
@@ -2026,7 +2029,16 @@ tablet_init(struct tablet_dispatch *tablet,
 
tablet_set_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY);
 
-   if (device->model_flags & EVDEV_MODEL_TABLET_NO_PROXIMITY_OUT) {
+   if (!libevdev_has_event_code(evdev, EV_KEY, BTN_TOOL_PEN)) {
+   libevdev_enable_event_code(evdev, EV_KEY, BTN_TOOL_PEN, NULL);
+   want_proximity_quirk = true;
+   tablet->quirks.proximity_out_forced = true;
+   }
+
+   if (device->model_flags & EVDEV_MODEL_TABLET_NO_PROXIMITY_OUT)
+   want_proximity_quirk = true;
+
+   if (want_proximity_quirk) {
tablet->quirks.need_to_force_prox_out = true;
libinput_timer_init(&tablet->quirks.prox_out_timer,
tablet_libinput_context(tablet),
diff --git a/test/litest-device-uclogic-tablet.c 
b/test/litest-device-uclogic-tablet.c
new file mode 100644
index ..b0393d65
--- /dev/null
+++ b/test/litest-device-uclogic-tablet.c
@@ -0,0 +1,106 @@
+/*
+ * Copyright © 2017 Red Hat, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#include "config.h"
+
+#include "litest.h"
+#include "litest-int.h"
+
+static void litest_uclogic_tablet_setup(void)
+{
+   struct litest_device *d = litest_create_device(LITEST_UCLOGIC_TABLET);
+   litest_set_current_device(d);
+}
+
+static struct input_event proximity_in[] = {
+   { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN },
+   { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN },
+   { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN },
+   { .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
+   { .type = -1, .code = -1 },
+};
+
+static struct input_event proximity_out[] = {
+   { .type 

[PATCH] connection: add sanity check to avoid buffer overflow

2017-09-13 Thread Boram Park
Before putting data into a buffer, we have to make sure that the data size is
smaller than not only the buffer's full size but also the buffer's empty size.

https://bugs.freedesktop.org/show_bug.cgi?id=102690

Signed-off-by: Boram Park 
Acked-by: Pekka Paalanen 
---
 src/connection.c | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/connection.c b/src/connection.c
index 5c3d187..53b1621 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -63,14 +63,17 @@ struct wl_connection {
int want_flush;
 };
 
+static uint32_t wl_buffer_size(struct wl_buffer *b);
+
 static int
 wl_buffer_put(struct wl_buffer *b, const void *data, size_t count)
 {
-   uint32_t head, size;
+   uint32_t head, size, empty;
 
-   if (count > sizeof(b->data)) {
+   empty = sizeof(b->data) - wl_buffer_size(b);
+   if (count > empty) {
wl_log("Data too big for buffer (%d > %d).\n",
-  count, sizeof(b->data));
+  count, empty);
errno = E2BIG;
return -1;
}
-- 
1.9.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


Re: [PATCH xserver v2] xwayland: add envvar XWAYLAND_NO_GLAMOR

2017-09-13 Thread Adam Jackson
On Thu, 2017-03-02 at 11:03 +0100, Olivier Fourdan wrote:
> Not all compositors allow for customizing the Xwayland command line,
> gnome-shell/mutter for example have the command line and path to
> Xwayland binary hardcoded, which makes it harder for users to disable
> glamor acceleration in Xwayland (glamor being used by default).
> 
> Add an environment variable XWAYLAND_NO_GLAMOR to disable glamor support
> in Xwayland.
> 
> Signed-off-by: Olivier Fourdan 
> Reviewed-by: Eric Engestrom 

remote: I: patch #141495 updated using rev 
1089d5d518a315963a8cda6c7d47a0ce09de0979.
remote: I: 1 patch(es) updated to state Accepted.
To ssh://git.freedesktop.org/git/xorg/xserver
   5abaa50b29..1089d5d518  master -> master

- ajax
___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


Lightweight desktop environments for Wayland?

2017-09-13 Thread lan lan
Hi,

weston doesn't seem to have any kind of "settings manager", regular
desktop controls,
 or task-bar. Is there a lightweight desktop environments for Wayland?
___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH] weston: added missing header time.h

2017-09-13 Thread Valery Kartel
without it I can't built weston on alpinelinux
---
 tests/timespec-test.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tests/timespec-test.c b/tests/timespec-test.c
index a5039110..11d39f11 100644
--- a/tests/timespec-test.c
+++ b/tests/timespec-test.c
@@ -32,6 +32,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "timespec-util.h"
 
-- 
2.13.3

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


Re: [PATCH] Add aspect-ratio support in wayland layer.

2017-09-13 Thread Sharma, Shashank

Hello Pekka

Thanks for your review comments and constructive discussions with Ankit 
on IRC.
I am Shashank from Intel, I am guiding Ankit on this activity.  I have 
few comments (inline),

it would be great if you can let us know your view on this.

Regards
Shashank
On 9/8/2017 7:43 PM, Pekka Paalanen wrote:

On Wed,  6 Sep 2017 17:50:00 +0530
Nautiyal Ankit  wrote:


From: Ankit Nautiyal 

This patch series adds video mode aspect ratio support for
wayland protocol and weston drm compositor. This patch series
adds two patches:
1- Adds aspect ratio flag bits bits in wl_output_mode flags
as per DRM layer implementation.
2- Preserves and uses the aspect ratio flags while selecting
the mode for modeset in weston drm compositor.

The corresponding kernel implementation for the aspect ratio support
in DRM Layer can be found here:
https://patchwork.freedesktop.org/series/10850/

This is a four patch series, in which two patches are already
merged, and two are waiting for user space implementation.

Hi,

we discussed these patches on #wayland in IRC, and I believe we came to
the following conclusion:

- Let's not add to wayland.xml, and not advertise the aspect ratio to
   clients. There is no need to do this, and clients are currently not
   able to take advantage of it either.
- In this case, how to decide what should be the aspect ratio of the 
output mode and based on what ?
  For example If a CEA mode is available for 16:9 and 4:3 aspects, 
which one to pick and how ? If we don't
  get inputs from the client, we would be picking the first mode in the 
list which might not be the best practice.
- While supporting advance display outputs like HDMI 2.0 / UHD, when the 
content can be in super wide aspect
   like 64:27 for movies/game, wouldn't it be under utilization of 
display capabilities not to pick it ?


- Shashank

- With the wl_output bits dropped, the idea in the Weston patch is
   good. You are adding a way to choose non-square pixel modes via
   weston.ini, and to choose the refresh rate as well.

The purpose of the Weston patch is to provide a real test vehicle for
the remaining kernel patches. The above mentioned should suffice, I
believe.


Thanks,
pq


___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH] docs: Add documentation for wl_event_source callbacks

2017-09-13 Thread raof
From: Christopher James Halse Rogers 

Signed-off-by: Christopher James Halse Rogers 

---
 src/wayland-server-core.h | 59 +++
 1 file changed, 59 insertions(+)

diff --git a/src/wayland-server-core.h b/src/wayland-server-core.h
index 61da8ab..0a2c689 100644
--- a/src/wayland-server-core.h
+++ b/src/wayland-server-core.h
@@ -43,9 +43,68 @@ enum {
WL_EVENT_ERROR= 0x08
 };
 
+/** Callback for fd-based wl_event_source
+ *
+ * \param fd   The fd that this wl_event_source watches
+ * \param mask Event mask of the wakeup trigger
+ * \param data Userdata that was passed to wl_event_loop_add_fd
+ *
+ * \return Ignored, unless this source has been registered with
+ * wl_event_source_check().
+ *
+ * If triggered from the post-dispatch check, returning non-zero
+ * will influence whether or not checked sources will be
+ * immediately checked again.
+ *
+ * The return values all checked sources will be accumulated;
+ * if their sum is > 0 all checked sources will be re-checked.
+ */
 typedef int (*wl_event_loop_fd_func_t)(int fd, uint32_t mask, void *data);
+/** Callback for timer wl_event_source
+ *
+ * \param data Userdata that was passed to wl_event_loop_add_timer()
+ *
+ * \return Ignored, unless this source has been registered with
+ * wl_event_source_check().
+ *
+ * If triggered from the post-dispatch check, returning non-zero
+ * will influence whether or not checked sources will be
+ * immediately checked again.
+ *
+ * The return values all checked sources will be accumulated;
+ * if their sum is > 0 all checked sources will be re-checked.
+ */
 typedef int (*wl_event_loop_timer_func_t)(void *data);
+/** Callback for signal-based wl_event_source
+ *
+ * \param signal_numberSignal number that triggered this wakeup
+ * \param data Userdata that was passed to wl_event_loop_add_signal
+ *
+ * \return Ignored, unless this source has been registered with
+ * wl_event_source_check().
+ *
+ * If triggered from the post-dispatch check, returning non-zero
+ * will influence whether or not checked sources will be
+ * immediately checked again.
+ *
+ * The return values all checked sources will be accumulated;
+ * if their sum is > 0 all checked sources will be re-checked.
+ */
 typedef int (*wl_event_loop_signal_func_t)(int signal_number, void *data);
+/** Callback for idle wl_event_source
+ *
+ * \param data Userdata that was passed to wl_event_loop_add_fd
+ *
+ * \return Ignored, unless this source has been registered with
+ * wl_event_source_check().
+ *
+ * If triggered from the post-dispatch check, returning non-zero
+ * will influence whether or not checked sources will be
+ * immediately checked again.
+ *
+ * The return values all checked sources will be accumulated;
+ * if their sum is > 0 all checked sources will be re-checked.
+ */
 typedef void (*wl_event_loop_idle_func_t)(void *data);
 
 struct wl_event_loop *
-- 
2.14.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH Weston] Load xkb map from file

2017-09-13 Thread Constantine Bytensky
I use my own keymap file on X.Org and I want to use it at Weston.

 compositor/main.c  |  2 ++
 libweston/compositor.h |  1 +
 libweston/input.c  | 13 ++---
 3 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/compositor/main.c b/compositor/main.c
index f8a60e9..fccc741 100644
--- a/compositor/main.c
+++ b/compositor/main.c
@@ -888,6 +888,8 @@ weston_compositor_init_config(struct weston_compositor *ec,
int vt_switching;
 
s = weston_config_get_section(config, "keyboard", NULL, NULL);
+   weston_config_section_get_string(s, "keymap_file",
+(char **) &ec->xkb_file, NULL);
weston_config_section_get_string(s, "keymap_rules",
 (char **) &xkb_names.rules, NULL);
weston_config_section_get_string(s, "keymap_model",
diff --git a/libweston/compositor.h b/libweston/compositor.h
index 769203a..9359b00 100644
--- a/libweston/compositor.h
+++ b/libweston/compositor.h
@@ -921,6 +921,7 @@ struct weston_compositor {
uint32_t output_id_pool;
 
struct xkb_rule_names xkb_names;
+   char *xkb_file;
struct xkb_context *xkb_context;
struct weston_xkb_info *xkb_info;
 
diff --git a/libweston/input.c b/libweston/input.c
index 81a94a9..0e93a54 100644
--- a/libweston/input.c
+++ b/libweston/input.c
@@ -2778,13 +2778,20 @@ static int
 weston_compositor_build_global_keymap(struct weston_compositor *ec)
 {
struct xkb_keymap *keymap;
+   FILE *file;
 
if (ec->xkb_info != NULL)
return 0;
 
-   keymap = xkb_keymap_new_from_names(ec->xkb_context,
-  &ec->xkb_names,
-  0);
+   if (ec->xkb_file != NULL) {
+   file = fopen(ec->xkb_file, "r");
+   keymap = xkb_keymap_new_from_file(ec->xkb_context, file, 
XKB_KEYMAP_FORMAT_TEXT_V1, 0);
+   fclose(file);
+   } else {
+   keymap = xkb_keymap_new_from_names(ec->xkb_context,
+   &ec->xkb_names,
+   0);
+   }
if (keymap == NULL) {
weston_log("failed to compile global XKB keymap\n");
weston_log("  tried rules %s, model %s, layout %s, variant %s, "
___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel