clients/window: Dispose of previous keymap and state on keymap change

dev
Rui Matos 11 years ago committed by Kristian Høgsberg
parent 0c194ced57
commit 3eccb8658d
  1. 24
      clients/window.c

@ -2774,6 +2774,8 @@ keyboard_handle_keymap(void *data, struct wl_keyboard *keyboard,
uint32_t format, int fd, uint32_t size) uint32_t format, int fd, uint32_t size)
{ {
struct input *input = data; struct input *input = data;
struct xkb_keymap *keymap;
struct xkb_state *state;
char *map_str; char *map_str;
if (!data) { if (!data) {
@ -2792,26 +2794,30 @@ keyboard_handle_keymap(void *data, struct wl_keyboard *keyboard,
return; return;
} }
input->xkb.keymap = xkb_map_new_from_string(input->display->xkb_context, keymap = xkb_map_new_from_string(input->display->xkb_context,
map_str, map_str,
XKB_KEYMAP_FORMAT_TEXT_V1, XKB_KEYMAP_FORMAT_TEXT_V1,
0); 0);
munmap(map_str, size); munmap(map_str, size);
close(fd); close(fd);
if (!input->xkb.keymap) { if (!keymap) {
fprintf(stderr, "failed to compile keymap\n"); fprintf(stderr, "failed to compile keymap\n");
return; return;
} }
input->xkb.state = xkb_state_new(input->xkb.keymap); state = xkb_state_new(keymap);
if (!input->xkb.state) { if (!state) {
fprintf(stderr, "failed to create XKB state\n"); fprintf(stderr, "failed to create XKB state\n");
xkb_map_unref(input->xkb.keymap); xkb_map_unref(keymap);
input->xkb.keymap = NULL;
return; 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 = input->xkb.control_mask =
1 << xkb_map_mod_get_index(input->xkb.keymap, "Control"); 1 << xkb_map_mod_get_index(input->xkb.keymap, "Control");
input->xkb.alt_mask = input->xkb.alt_mask =

Loading…
Cancel
Save