[PATCH v2 4/4] clients/window: Dispose of previous keymap and state on keymap change
Rui Matos
tiagomatos at gmail.com
Thu Oct 10 19:44:22 CEST 2013
---
clients/window.c | 24 +++++++++++++++---------
1 file changed, 15 insertions(+), 9 deletions(-)
diff --git a/clients/window.c b/clients/window.c
index 5b20da5..1f32c73 100644
--- a/clients/window.c
+++ b/clients/window.c
@@ -3037,6 +3037,8 @@ keyboard_handle_keymap(void *data, struct wl_keyboard *keyboard,
uint32_t format, int fd, uint32_t size)
{
struct input *input = data;
+ struct xkb_keymap *keymap;
+ struct xkb_state *state;
char *map_str;
if (!data) {
@@ -3055,26 +3057,30 @@ keyboard_handle_keymap(void *data, struct wl_keyboard *keyboard,
return;
}
- input->xkb.keymap = xkb_map_new_from_string(input->display->xkb_context,
- map_str,
- XKB_KEYMAP_FORMAT_TEXT_V1,
- 0);
+ keymap = xkb_map_new_from_string(input->display->xkb_context,
+ map_str,
+ XKB_KEYMAP_FORMAT_TEXT_V1,
+ 0);
munmap(map_str, size);
close(fd);
- if (!input->xkb.keymap) {
+ if (!keymap) {
fprintf(stderr, "failed to compile keymap\n");
return;
}
- input->xkb.state = xkb_state_new(input->xkb.keymap);
- if (!input->xkb.state) {
+ state = xkb_state_new(keymap);
+ if (!state) {
fprintf(stderr, "failed to create XKB state\n");
- xkb_map_unref(input->xkb.keymap);
- input->xkb.keymap = NULL;
+ xkb_map_unref(keymap);
return;
}
+ xkb_keymap_unref(input->xkb.keymap);
+ xkb_state_unref(input->xkb.state);
+ input->xkb.keymap = keymap;
+ input->xkb.state = state;
+
input->xkb.control_mask =
1 << xkb_map_mod_get_index(input->xkb.keymap, "Control");
input->xkb.alt_mask =
--
1.8.3.1
More information about the wayland-devel
mailing list