Another round of feedback from acrisci

This commit is contained in:
Markus Ongyerth 2018-07-07 17:56:37 +02:00
parent 43b20bfea2
commit 74ca2f8fcf
5 changed files with 44 additions and 42 deletions

9
include/util/array.h Normal file
View File

@ -0,0 +1,9 @@
#ifndef UTIL_ARRAY_H
#define UTIL_ARRAY_H
#include <stdint.h>
#include <stdlib.h>
size_t push_zeroes_to_end(uint32_t arr[], size_t n);
#endif

View File

@ -3,6 +3,7 @@
#endif
#include "tablet-unstable-v2-protocol.h"
#include "util/array.h"
#include <assert.h>
#include <stdlib.h>
#include <types/wlr_tablet_v2.h>
@ -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) {
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;
}

View File

@ -1,3 +1,4 @@
#include "util/array.h"
#include <assert.h>
#include <stdlib.h>
#include <string.h>
@ -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;

21
util/array.c Normal file
View File

@ -0,0 +1,21 @@
#include <stdlib.h>
#include <stdint.h>
// 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;
}

View File

@ -1,6 +1,7 @@
lib_wlr_util = static_library(
'wlr_util',
files(
'array.c',
'log.c',
'os-compatibility.c',
'region.c',