compositor-wayland: Properly handle running inside a compositor that does not provide keymaps

Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
dev
Jason Ekstrand 11 years ago committed by Kristian Høgsberg
parent cf40a13820
commit b7d9f2eb2f
  1. 41
      src/compositor-wayland.c

@ -167,6 +167,7 @@ struct wayland_input {
} cursor; } cursor;
} parent; } parent;
enum weston_key_state_update keyboard_state_update;
uint32_t key_serial; uint32_t key_serial;
uint32_t enter_serial; uint32_t enter_serial;
int focus; int focus;
@ -1417,20 +1418,14 @@ input_handle_keymap(void *data, struct wl_keyboard *keyboard, uint32_t format,
struct xkb_keymap *keymap; struct xkb_keymap *keymap;
char *map_str; char *map_str;
if (!data) { if (!data)
close(fd); goto error;
return;
}
if (format != WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1) {
close(fd);
return;
}
if (format == WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1) {
map_str = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0); map_str = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);
if (map_str == MAP_FAILED) { if (map_str == MAP_FAILED) {
close(fd); weston_log("mmap failed: %m\n");
return; goto error;
} }
keymap = xkb_map_new_from_string(input->compositor->base.xkb_context, keymap = xkb_map_new_from_string(input->compositor->base.xkb_context,
@ -1438,19 +1433,37 @@ input_handle_keymap(void *data, struct wl_keyboard *keyboard, uint32_t format,
XKB_KEYMAP_FORMAT_TEXT_V1, XKB_KEYMAP_FORMAT_TEXT_V1,
0); 0);
munmap(map_str, size); munmap(map_str, size);
close(fd);
if (!keymap) { if (!keymap) {
weston_log("failed to compile keymap\n"); weston_log("failed to compile keymap\n");
return; goto error;
} }
input->keyboard_state_update = STATE_UPDATE_NONE;
} else if (format == WL_KEYBOARD_KEYMAP_FORMAT_NO_KEYMAP) {
weston_log("No keymap provided; falling back to defalt\n");
keymap = NULL;
input->keyboard_state_update = STATE_UPDATE_AUTOMATIC;
} else {
weston_log("Invalid keymap\n");
goto error;
}
close(fd);
if (input->base.keyboard) if (input->base.keyboard)
weston_seat_update_keymap(&input->base, keymap); weston_seat_update_keymap(&input->base, keymap);
else else
weston_seat_init_keyboard(&input->base, keymap); weston_seat_init_keyboard(&input->base, keymap);
if (keymap)
xkb_map_unref(keymap); xkb_map_unref(keymap);
return;
error:
wl_keyboard_release(input->parent.keyboard);
close(fd);
} }
static void static void
@ -1525,7 +1538,7 @@ input_handle_key(void *data, struct wl_keyboard *keyboard,
notify_key(&input->base, time, key, notify_key(&input->base, time, key,
state ? WL_KEYBOARD_KEY_STATE_PRESSED : state ? WL_KEYBOARD_KEY_STATE_PRESSED :
WL_KEYBOARD_KEY_STATE_RELEASED, WL_KEYBOARD_KEY_STATE_RELEASED,
STATE_UPDATE_NONE); input->keyboard_state_update);
} }
static void static void

Loading…
Cancel
Save