Merge pull request #32 from myfreeweb/keymap

More keymap stuff
pull/40/head
Andri Yngvason 2020-04-09 13:39:50 +00:00 committed by GitHub
commit 83a226c439
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 5 deletions

View File

@ -18,6 +18,7 @@
* interface. * interface.
*/ */
#include <errno.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <stdbool.h> #include <stdbool.h>
@ -169,25 +170,34 @@ int keyboard_init(struct keyboard* self, const char* layout)
if (!keymap_string) if (!keymap_string)
goto keymap_string_failure; goto keymap_string_failure;
size_t keymap_len = strlen(keymap_string); size_t keymap_size = strlen(keymap_string) + 1;
int keymap_fd = shm_alloc_fd(keymap_len); int keymap_fd = shm_alloc_fd(keymap_size);
if (keymap_fd < 0) if (keymap_fd < 0)
goto fd_failure; goto fd_failure;
// TODO: Check that write finished writing everything int written = 0;
write(keymap_fd, keymap_string, keymap_len); while (written < keymap_size) {
ssize_t ret = write(keymap_fd, keymap_string + written, keymap_size - written);
if (ret == -1 && errno == EINTR)
continue;
if (ret == -1)
goto write_failure;
written += ret;
}
free(keymap_string); free(keymap_string);
zwp_virtual_keyboard_v1_keymap(self->virtual_keyboard, zwp_virtual_keyboard_v1_keymap(self->virtual_keyboard,
WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1,
keymap_fd, keymap_len); keymap_fd, keymap_size);
close(keymap_fd); close(keymap_fd);
return 0; return 0;
write_failure:
close(keymap_fd);
fd_failure: fd_failure:
free(keymap_string); free(keymap_string);
keymap_string_failure: keymap_string_failure: