diff options
author | Simon Ser <contact@emersion.fr> | 2022-12-19 10:03:38 +0100 |
---|---|---|
committer | Isaac Freund <mail@isaacfreund.com> | 2023-01-26 15:06:45 +0000 |
commit | f41dcb3a97401d28e7da5c56a93c9a3409813947 (patch) | |
tree | e7a5ba60eb26e340be7c0aa06e21bbd0759344b7 | |
parent | 90d7bce9940682a36921d5dc70c1213710df8746 (diff) |
seat/keyboard: skip wl_array allocation
We can just create a wl_array from the array passed by the user.
Here, wl_array is only necessary to make libwayland happy.
-rw-r--r-- | types/seat/wlr_seat_keyboard.c | 16 |
1 files changed, 4 insertions, 12 deletions
diff --git a/types/seat/wlr_seat_keyboard.c b/types/seat/wlr_seat_keyboard.c index 186b8251..95d9f637 100644 --- a/types/seat/wlr_seat_keyboard.c +++ b/types/seat/wlr_seat_keyboard.c @@ -254,17 +254,10 @@ void wlr_seat_keyboard_enter(struct wlr_seat *seat, // enter the current surface if (client != NULL) { - struct wl_array keys; - wl_array_init(&keys); - for (size_t i = 0; i < num_keycodes; ++i) { - uint32_t *p = wl_array_add(&keys, sizeof(uint32_t)); - if (!p) { - wlr_log(WLR_ERROR, "Cannot allocate memory, skipping keycode: %" PRIu32 "\n", - keycodes[i]); - continue; - } - *p = keycodes[i]; - } + struct wl_array keys = { + .data = keycodes, + .size = num_keycodes * sizeof(keycodes[0]), + }; uint32_t serial = wlr_seat_client_next_serial(client); struct wl_resource *resource; wl_resource_for_each(resource, &client->keyboards) { @@ -273,7 +266,6 @@ void wlr_seat_keyboard_enter(struct wlr_seat *seat, } wl_keyboard_send_enter(resource, serial, surface->resource, &keys); } - wl_array_release(&keys); } // reinitialize the focus destroy events |