From 74ca2f8fcf10f5b00b4a3eeb121e418e1b5212e0 Mon Sep 17 00:00:00 2001 From: Markus Ongyerth Date: Sat, 7 Jul 2018 17:56:37 +0200 Subject: [PATCH] Another round of feedback from acrisci --- include/util/array.h | 9 +++++++ types/tablet_v2/wlr_tablet_v2_tool.c | 35 ++++++++++------------------ types/wlr_keyboard.c | 20 +--------------- util/array.c | 21 +++++++++++++++++ util/meson.build | 1 + 5 files changed, 44 insertions(+), 42 deletions(-) create mode 100644 include/util/array.h create mode 100644 util/array.c diff --git a/include/util/array.h b/include/util/array.h new file mode 100644 index 00000000..1c046e1d --- /dev/null +++ b/include/util/array.h @@ -0,0 +1,9 @@ +#ifndef UTIL_ARRAY_H +#define UTIL_ARRAY_H + +#include +#include + +size_t push_zeroes_to_end(uint32_t arr[], size_t n); + +#endif diff --git a/types/tablet_v2/wlr_tablet_v2_tool.c b/types/tablet_v2/wlr_tablet_v2_tool.c index f476c2db..c7a1fa54 100644 --- a/types/tablet_v2/wlr_tablet_v2_tool.c +++ b/types/tablet_v2/wlr_tablet_v2_tool.c @@ -3,6 +3,7 @@ #endif #include "tablet-unstable-v2-protocol.h" +#include "util/array.h" #include #include #include @@ -231,25 +232,8 @@ struct wlr_tablet_tool_client_v2 *tablet_tool_client_from_resource(struct wl_res /* Actual protocol foo */ -// https://www.geeksforgeeks.org/move-zeroes-end-array/ -static size_t push_zeroes_to_end(uint32_t arr[], size_t n) { - size_t count = 0; - - for (size_t i = 0; i < n; i++) { - if (arr[i] != 0) { - arr[count++] = arr[i]; - } - } - - size_t ret = count; - - while (count < n) { - arr[count++] = 0; - } - - return ret; -} +// Button 0 is KEY_RESERVED in input-event-codes on linux (and freebsd) static ssize_t tablet_tool_button_update(struct wlr_tablet_v2_tablet_tool *tool, uint32_t button, enum zwp_tablet_pad_v2_button_state state) { bool found = false; @@ -261,11 +245,16 @@ static ssize_t tablet_tool_button_update(struct wlr_tablet_v2_tablet_tool *tool, } } - if (state == ZWP_TABLET_PAD_V2_BUTTON_STATE_PRESSED && !found && - tool->num_buttons < WLR_TABLET_V2_TOOL_BUTTONS_CAP) { - i = tool->num_buttons++; - tool->pressed_buttons[i] = button; - tool->pressed_serials[i] = -1; + if (state == ZWP_TABLET_PAD_V2_BUTTON_STATE_PRESSED && !found) { + if (tool->num_buttons < WLR_TABLET_V2_TOOL_BUTTONS_CAP) { + i = tool->num_buttons++; + tool->pressed_buttons[i] = button; + tool->pressed_serials[i] = -1; + } else { + i = -1; + wlr_log(WLR_ERROR, "You pressed more than %d tablet tool buttons. This is currently not supporte by wlroots. Please report this with a description of your tablet, since this is either a bug, or fancy hardware", + WLR_TABLET_V2_TOOL_BUTTONS_CAP); + } } else { i = -1; } diff --git a/types/wlr_keyboard.c b/types/wlr_keyboard.c index e941e8d1..3a4f5f67 100644 --- a/types/wlr_keyboard.c +++ b/types/wlr_keyboard.c @@ -1,3 +1,4 @@ +#include "util/array.h" #include #include #include @@ -58,25 +59,6 @@ static bool keyboard_modifier_update(struct wlr_keyboard *keyboard) { return true; } -// https://www.geeksforgeeks.org/move-zeroes-end-array/ -static size_t push_zeroes_to_end(uint32_t arr[], size_t n) { - size_t count = 0; - - for (size_t i = 0; i < n; i++) { - if (arr[i] != 0) { - arr[count++] = arr[i]; - } - } - - size_t ret = count; - - while (count < n) { - arr[count++] = 0; - } - - return ret; -} - static void keyboard_key_update(struct wlr_keyboard *keyboard, struct wlr_event_keyboard_key *event) { bool found = false; diff --git a/util/array.c b/util/array.c new file mode 100644 index 00000000..9ee39d33 --- /dev/null +++ b/util/array.c @@ -0,0 +1,21 @@ +#include +#include + +// https://www.geeksforgeeks.org/move-zeroes-end-array/ +size_t push_zeroes_to_end(uint32_t arr[], size_t n) { + size_t count = 0; + + for (size_t i = 0; i < n; i++) { + if (arr[i] != 0) { + arr[count++] = arr[i]; + } + } + + size_t ret = count; + + while (count < n) { + arr[count++] = 0; + } + + return ret; +} diff --git a/util/meson.build b/util/meson.build index adc52a53..f9d1997d 100644 --- a/util/meson.build +++ b/util/meson.build @@ -1,6 +1,7 @@ lib_wlr_util = static_library( 'wlr_util', files( + 'array.c', 'log.c', 'os-compatibility.c', 'region.c',