commit 675b0e9450199dfde78a43a34d586b89b89b7644
parent 6bc25c1e3edc4635d617a2dbab8c8c5e63865604
Author: Michael Forney <mforney@mforney.org>
Date: Tue, 19 Nov 2013 18:19:40 -0800
Add swc_array_remove helper
Diffstat:
2 files changed, 12 insertions(+), 8 deletions(-)
diff --git a/libswc/keyboard.c b/libswc/keyboard.c
@@ -129,14 +129,7 @@ void swc_keyboard_handle_key(struct swc_keyboard * keyboard, uint32_t time,
else
{
/* Remove the key from the array */
- uint32_t bytes_to_copy = keyboard->keys.size + 1
- - (((void *) pressed_key) - keyboard->keys.data);
-
- if (bytes_to_copy > 0)
- memmove(pressed_key, pressed_key + 1, bytes_to_copy);
-
- keyboard->keys.size -= sizeof key;
-
+ swc_array_remove(&keyboard->keys, pressed_key, sizeof key);
break;
}
}
diff --git a/libswc/util.h b/libswc/util.h
@@ -3,9 +3,11 @@
#include <stdlib.h>
#include <stdbool.h>
+#include <string.h>
#include <sys/time.h>
#include <sys/param.h>
#include <pixman.h>
+#include <wayland-util.h>
#ifdef offsetof
# define OFFSET_OF offsetof
@@ -46,6 +48,15 @@ static inline bool swc_rectangle_overlap
< r1->height + r2->height);
}
+static inline void swc_array_remove(struct wl_array * array,
+ void * item, size_t size)
+{
+ size_t bytes = array->size - (item + size - array->data);
+ if (bytes > 0)
+ memmove(item, item + size, bytes);
+ array->size -= size;
+}
+
/* Launch Utilities */
int swc_launch_open_device(const char * path, int flags);
bool swc_launch_activate_vt(unsigned vt);