commit 675b0e9
Michael Forney
·
2013-11-20 02:19:40 +0000 UTC
parent 6bc25c1
Add swc_array_remove helper
2 files changed,
+12,
-8
+1,
-8
1@@ -129,14 +129,7 @@ void swc_keyboard_handle_key(struct swc_keyboard * keyboard, uint32_t time,
2 else
3 {
4 /* Remove the key from the array */
5- uint32_t bytes_to_copy = keyboard->keys.size + 1
6- - (((void *) pressed_key) - keyboard->keys.data);
7-
8- if (bytes_to_copy > 0)
9- memmove(pressed_key, pressed_key + 1, bytes_to_copy);
10-
11- keyboard->keys.size -= sizeof key;
12-
13+ swc_array_remove(&keyboard->keys, pressed_key, sizeof key);
14 break;
15 }
16 }
+11,
-0
1@@ -3,9 +3,11 @@
2
3 #include <stdlib.h>
4 #include <stdbool.h>
5+#include <string.h>
6 #include <sys/time.h>
7 #include <sys/param.h>
8 #include <pixman.h>
9+#include <wayland-util.h>
10
11 #ifdef offsetof
12 # define OFFSET_OF offsetof
13@@ -46,6 +48,15 @@ static inline bool swc_rectangle_overlap
14 < r1->height + r2->height);
15 }
16
17+static inline void swc_array_remove(struct wl_array * array,
18+ void * item, size_t size)
19+{
20+ size_t bytes = array->size - (item + size - array->data);
21+ if (bytes > 0)
22+ memmove(item, item + size, bytes);
23+ array->size -= size;
24+}
25+
26 /* Launch Utilities */
27 int swc_launch_open_device(const char * path, int flags);
28 bool swc_launch_activate_vt(unsigned vt);