input: Move the xkb fields from weston_seat to weston_keyboard

XKB integration is a keyboard feature and should as such be kept track
of in the keyboard struct.

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
dev
Jonas Ådahl 11 years ago committed by Kristian Høgsberg
parent 918f2dd4cf
commit 7395ea05c7
  1. 2
      src/compositor-wayland.c
  2. 8
      src/compositor-x11.c
  3. 14
      src/compositor.h
  4. 137
      src/input.c
  5. 4
      src/text-backend.c

@ -1270,7 +1270,7 @@ input_handle_modifiers(void *data, struct wl_keyboard *keyboard,
else else
serial_out = wl_display_next_serial(c->base.wl_display); serial_out = wl_display_next_serial(c->base.wl_display);
xkb_state_update_mask(input->base.xkb_state.state, xkb_state_update_mask(input->base.keyboard->xkb_state.state,
mods_depressed, mods_latched, mods_depressed, mods_latched,
mods_locked, 0, 0, group); mods_locked, 0, 0, group);
notify_modifiers(&input->base, serial_out); notify_modifiers(&input->base, serial_out);

@ -162,7 +162,7 @@ x11_compositor_get_keymap(struct x11_compositor *c)
static uint32_t static uint32_t
get_xkb_mod_mask(struct x11_compositor *c, uint32_t in) get_xkb_mod_mask(struct x11_compositor *c, uint32_t in)
{ {
struct weston_xkb_info *info = c->core_seat.xkb_info; struct weston_xkb_info *info = c->core_seat.keyboard->xkb_info;
uint32_t ret = 0; uint32_t ret = 0;
if ((in & ShiftMask) && info->shift_mod != XKB_MOD_INVALID) if ((in & ShiftMask) && info->shift_mod != XKB_MOD_INVALID)
@ -273,7 +273,7 @@ x11_compositor_setup_xkb(struct x11_compositor *c)
return; return;
} }
xkb_state_update_mask(c->core_seat.xkb_state.state, xkb_state_update_mask(c->core_seat.keyboard->xkb_state.state,
get_xkb_mod_mask(c, state_reply->baseMods), get_xkb_mod_mask(c, state_reply->baseMods),
get_xkb_mod_mask(c, state_reply->latchedMods), get_xkb_mod_mask(c, state_reply->latchedMods),
get_xkb_mod_mask(c, state_reply->lockedMods), get_xkb_mod_mask(c, state_reply->lockedMods),
@ -920,7 +920,7 @@ x11_compositor_find_output(struct x11_compositor *c, xcb_window_t window)
static void static void
update_xkb_state(struct x11_compositor *c, xcb_xkb_state_notify_event_t *state) update_xkb_state(struct x11_compositor *c, xcb_xkb_state_notify_event_t *state)
{ {
xkb_state_update_mask(c->core_seat.xkb_state.state, xkb_state_update_mask(c->core_seat.keyboard->xkb_state.state,
get_xkb_mod_mask(c, state->baseMods), get_xkb_mod_mask(c, state->baseMods),
get_xkb_mod_mask(c, state->latchedMods), get_xkb_mod_mask(c, state->latchedMods),
get_xkb_mod_mask(c, state->lockedMods), get_xkb_mod_mask(c, state->lockedMods),
@ -950,7 +950,7 @@ update_xkb_state_from_core(struct x11_compositor *c, uint16_t x11_mask)
uint32_t mask = get_xkb_mod_mask(c, x11_mask); uint32_t mask = get_xkb_mod_mask(c, x11_mask);
struct weston_keyboard *keyboard = c->core_seat.keyboard; struct weston_keyboard *keyboard = c->core_seat.keyboard;
xkb_state_update_mask(c->core_seat.xkb_state.state, xkb_state_update_mask(c->core_seat.keyboard->xkb_state.state,
keyboard->modifiers.mods_depressed & mask, keyboard->modifiers.mods_depressed & mask,
keyboard->modifiers.mods_latched & mask, keyboard->modifiers.mods_latched & mask,
keyboard->modifiers.mods_locked & mask, keyboard->modifiers.mods_locked & mask,

@ -466,6 +466,13 @@ struct weston_keyboard {
struct weston_keyboard_grab input_method_grab; struct weston_keyboard_grab input_method_grab;
struct wl_resource *input_method_resource; struct wl_resource *input_method_resource;
struct weston_xkb_info *xkb_info;
struct {
struct xkb_state *state;
enum weston_led leds;
} xkb_state;
struct xkb_keymap *pending_keymap;
}; };
struct weston_seat { struct weston_seat {
@ -497,13 +504,6 @@ struct weston_seat {
void (*led_update)(struct weston_seat *ws, enum weston_led leds); void (*led_update)(struct weston_seat *ws, enum weston_led leds);
struct weston_xkb_info *xkb_info;
struct {
struct xkb_state *state;
enum weston_led leds;
} xkb_state;
struct xkb_keymap *pending_keymap;
struct input_method *input_method; struct input_method *input_method;
char *seat_name; char *seat_name;
}; };

@ -513,11 +513,25 @@ weston_keyboard_create(void)
return keyboard; return keyboard;
} }
static void
weston_xkb_info_destroy(struct weston_xkb_info *xkb_info);
WL_EXPORT void WL_EXPORT void
weston_keyboard_destroy(struct weston_keyboard *keyboard) weston_keyboard_destroy(struct weston_keyboard *keyboard)
{ {
/* XXX: What about keyboard->resource_list? */ /* XXX: What about keyboard->resource_list? */
#ifdef ENABLE_XKBCOMMON
if (keyboard->seat->compositor->use_xkbcommon) {
if (keyboard->xkb_state.state != NULL)
xkb_state_unref(keyboard->xkb_state.state);
if (keyboard->xkb_info)
weston_xkb_info_destroy(keyboard->xkb_info);
if (keyboard->pending_keymap)
xkb_keymap_unref(keyboard->pending_keymap);
}
#endif
wl_array_release(&keyboard->keys); wl_array_release(&keyboard->keys);
wl_list_remove(&keyboard->focus_resource_listener.link); wl_list_remove(&keyboard->focus_resource_listener.link);
free(keyboard); free(keyboard);
@ -855,16 +869,17 @@ static void
run_modifier_bindings(struct weston_seat *seat, uint32_t old, uint32_t new) run_modifier_bindings(struct weston_seat *seat, uint32_t old, uint32_t new)
{ {
struct weston_compositor *compositor = seat->compositor; struct weston_compositor *compositor = seat->compositor;
struct weston_keyboard *keyboard = seat->keyboard;
uint32_t diff; uint32_t diff;
unsigned int i; unsigned int i;
struct { struct {
uint32_t xkb; uint32_t xkb;
enum weston_keyboard_modifier weston; enum weston_keyboard_modifier weston;
} mods[] = { } mods[] = {
{ seat->xkb_info->ctrl_mod, MODIFIER_CTRL }, { keyboard->xkb_info->ctrl_mod, MODIFIER_CTRL },
{ seat->xkb_info->alt_mod, MODIFIER_ALT }, { keyboard->xkb_info->alt_mod, MODIFIER_ALT },
{ seat->xkb_info->super_mod, MODIFIER_SUPER }, { keyboard->xkb_info->super_mod, MODIFIER_SUPER },
{ seat->xkb_info->shift_mod, MODIFIER_SHIFT }, { keyboard->xkb_info->shift_mod, MODIFIER_SHIFT },
}; };
diff = new & ~old; diff = new & ~old;
@ -990,13 +1005,13 @@ notify_modifiers(struct weston_seat *seat, uint32_t serial)
/* Serialize and update our internal state, checking to see if it's /* Serialize and update our internal state, checking to see if it's
* different to the previous state. */ * different to the previous state. */
mods_depressed = xkb_state_serialize_mods(seat->xkb_state.state, mods_depressed = xkb_state_serialize_mods(keyboard->xkb_state.state,
XKB_STATE_DEPRESSED); XKB_STATE_DEPRESSED);
mods_latched = xkb_state_serialize_mods(seat->xkb_state.state, mods_latched = xkb_state_serialize_mods(keyboard->xkb_state.state,
XKB_STATE_LATCHED); XKB_STATE_LATCHED);
mods_locked = xkb_state_serialize_mods(seat->xkb_state.state, mods_locked = xkb_state_serialize_mods(keyboard->xkb_state.state,
XKB_STATE_LOCKED); XKB_STATE_LOCKED);
group = xkb_state_serialize_group(seat->xkb_state.state, group = xkb_state_serialize_group(keyboard->xkb_state.state,
XKB_STATE_EFFECTIVE); XKB_STATE_EFFECTIVE);
if (mods_depressed != seat->keyboard->modifiers.mods_depressed || if (mods_depressed != seat->keyboard->modifiers.mods_depressed ||
@ -1016,28 +1031,28 @@ notify_modifiers(struct weston_seat *seat, uint32_t serial)
/* And update the modifier_state for bindings. */ /* And update the modifier_state for bindings. */
mods_lookup = mods_depressed | mods_latched; mods_lookup = mods_depressed | mods_latched;
seat->modifier_state = 0; seat->modifier_state = 0;
if (mods_lookup & (1 << seat->xkb_info->ctrl_mod)) if (mods_lookup & (1 << keyboard->xkb_info->ctrl_mod))
seat->modifier_state |= MODIFIER_CTRL; seat->modifier_state |= MODIFIER_CTRL;
if (mods_lookup & (1 << seat->xkb_info->alt_mod)) if (mods_lookup & (1 << keyboard->xkb_info->alt_mod))
seat->modifier_state |= MODIFIER_ALT; seat->modifier_state |= MODIFIER_ALT;
if (mods_lookup & (1 << seat->xkb_info->super_mod)) if (mods_lookup & (1 << keyboard->xkb_info->super_mod))
seat->modifier_state |= MODIFIER_SUPER; seat->modifier_state |= MODIFIER_SUPER;
if (mods_lookup & (1 << seat->xkb_info->shift_mod)) if (mods_lookup & (1 << keyboard->xkb_info->shift_mod))
seat->modifier_state |= MODIFIER_SHIFT; seat->modifier_state |= MODIFIER_SHIFT;
/* Finally, notify the compositor that LEDs have changed. */ /* Finally, notify the compositor that LEDs have changed. */
if (xkb_state_led_index_is_active(seat->xkb_state.state, if (xkb_state_led_index_is_active(keyboard->xkb_state.state,
seat->xkb_info->num_led)) keyboard->xkb_info->num_led))
leds |= LED_NUM_LOCK; leds |= LED_NUM_LOCK;
if (xkb_state_led_index_is_active(seat->xkb_state.state, if (xkb_state_led_index_is_active(keyboard->xkb_state.state,
seat->xkb_info->caps_led)) keyboard->xkb_info->caps_led))
leds |= LED_CAPS_LOCK; leds |= LED_CAPS_LOCK;
if (xkb_state_led_index_is_active(seat->xkb_state.state, if (xkb_state_led_index_is_active(keyboard->xkb_state.state,
seat->xkb_info->scroll_led)) keyboard->xkb_info->scroll_led))
leds |= LED_SCROLL_LOCK; leds |= LED_SCROLL_LOCK;
if (leds != seat->xkb_state.leds && seat->led_update) if (leds != keyboard->xkb_state.leds && seat->led_update)
seat->led_update(seat, leds); seat->led_update(seat, leds);
seat->xkb_state.leds = leds; keyboard->xkb_state.leds = leds;
if (changed) { if (changed) {
grab->interface->modifiers(grab, grab->interface->modifiers(grab,
@ -1053,6 +1068,7 @@ static void
update_modifier_state(struct weston_seat *seat, uint32_t serial, uint32_t key, update_modifier_state(struct weston_seat *seat, uint32_t serial, uint32_t key,
enum wl_keyboard_key_state state) enum wl_keyboard_key_state state)
{ {
struct weston_keyboard *keyboard = seat->keyboard;
enum xkb_key_direction direction; enum xkb_key_direction direction;
/* Keyboard modifiers don't exist in raw keyboard mode */ /* Keyboard modifiers don't exist in raw keyboard mode */
@ -1066,7 +1082,7 @@ update_modifier_state(struct weston_seat *seat, uint32_t serial, uint32_t key,
/* Offset the keycode by 8, as the evdev XKB rules reflect X's /* Offset the keycode by 8, as the evdev XKB rules reflect X's
* broken keycode system, which starts at 8. */ * broken keycode system, which starts at 8. */
xkb_state_update_key(seat->xkb_state.state, key + 8, direction); xkb_state_update_key(keyboard->xkb_state.state, key + 8, direction);
notify_modifiers(seat, serial); notify_modifiers(seat, serial);
} }
@ -1092,22 +1108,21 @@ send_modifiers(struct wl_resource *resource, uint32_t serial, struct weston_keyb
static struct weston_xkb_info * static struct weston_xkb_info *
weston_xkb_info_create(struct xkb_keymap *keymap); weston_xkb_info_create(struct xkb_keymap *keymap);
static void
weston_xkb_info_destroy(struct weston_xkb_info *xkb_info);
static void static void
update_keymap(struct weston_seat *seat) update_keymap(struct weston_seat *seat)
{ {
struct weston_keyboard *keyboard = seat->keyboard;
struct wl_resource *resource; struct wl_resource *resource;
struct weston_xkb_info *xkb_info; struct weston_xkb_info *xkb_info;
struct xkb_state *state; struct xkb_state *state;
xkb_mod_mask_t latched_mods; xkb_mod_mask_t latched_mods;
xkb_mod_mask_t locked_mods; xkb_mod_mask_t locked_mods;
xkb_info = weston_xkb_info_create(seat->pending_keymap); xkb_info = weston_xkb_info_create(keyboard->pending_keymap);
xkb_keymap_unref(seat->pending_keymap); xkb_keymap_unref(keyboard->pending_keymap);
seat->pending_keymap = NULL; keyboard->pending_keymap = NULL;
if (!xkb_info) { if (!xkb_info) {
weston_log("failed to create XKB info\n"); weston_log("failed to create XKB info\n");
@ -1121,19 +1136,21 @@ update_keymap(struct weston_seat *seat)
return; return;
} }
latched_mods = xkb_state_serialize_mods(seat->xkb_state.state, XKB_STATE_MODS_LATCHED); latched_mods = xkb_state_serialize_mods(keyboard->xkb_state.state,
locked_mods = xkb_state_serialize_mods(seat->xkb_state.state, XKB_STATE_MODS_LOCKED); XKB_STATE_MODS_LATCHED);
locked_mods = xkb_state_serialize_mods(keyboard->xkb_state.state,
XKB_STATE_MODS_LOCKED);
xkb_state_update_mask(state, xkb_state_update_mask(state,
0, /* depressed */ 0, /* depressed */
latched_mods, latched_mods,
locked_mods, locked_mods,
0, 0, 0); 0, 0, 0);
weston_xkb_info_destroy(seat->xkb_info); weston_xkb_info_destroy(keyboard->xkb_info);
seat->xkb_info = xkb_info; keyboard->xkb_info = xkb_info;
xkb_state_unref(seat->xkb_state.state); xkb_state_unref(keyboard->xkb_state.state);
seat->xkb_state.state = state; keyboard->xkb_state.state = state;
wl_resource_for_each(resource, &seat->keyboard->resource_list) wl_resource_for_each(resource, &seat->keyboard->resource_list)
send_keymap(resource, xkb_info); send_keymap(resource, xkb_info);
@ -1215,7 +1232,7 @@ notify_key(struct weston_seat *seat, uint32_t time, uint32_t key,
grab->interface->key(grab, time, key, state); grab->interface->key(grab, time, key, state);
if (seat->pending_keymap && if (keyboard->pending_keymap &&
keyboard->keys.size == 0) keyboard->keys.size == 0)
update_keymap(seat); update_keymap(seat);
@ -1598,6 +1615,7 @@ seat_get_keyboard(struct wl_client *client, struct wl_resource *resource,
uint32_t id) uint32_t id)
{ {
struct weston_seat *seat = wl_resource_get_user_data(resource); struct weston_seat *seat = wl_resource_get_user_data(resource);
struct weston_keyboard *keyboard = seat->keyboard;
struct wl_resource *cr; struct wl_resource *cr;
if (!seat->keyboard) if (!seat->keyboard)
@ -1619,8 +1637,8 @@ seat_get_keyboard(struct wl_client *client, struct wl_resource *resource,
if (seat->compositor->use_xkbcommon) { if (seat->compositor->use_xkbcommon) {
wl_keyboard_send_keymap(cr, WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, wl_keyboard_send_keymap(cr, WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1,
seat->xkb_info->keymap_fd, keyboard->xkb_info->keymap_fd,
seat->xkb_info->keymap_size); keyboard->xkb_info->keymap_size);
} else { } else {
int null_fd = open("/dev/null", O_RDONLY); int null_fd = open("/dev/null", O_RDONLY);
wl_keyboard_send_keymap(cr, WL_KEYBOARD_KEYMAP_FORMAT_NO_KEYMAP, wl_keyboard_send_keymap(cr, WL_KEYBOARD_KEYMAP_FORMAT_NO_KEYMAP,
@ -1911,8 +1929,8 @@ weston_seat_update_keymap(struct weston_seat *seat, struct xkb_keymap *keymap)
if (!seat->compositor->use_xkbcommon) if (!seat->compositor->use_xkbcommon)
return; return;
xkb_keymap_unref(seat->pending_keymap); xkb_keymap_unref(seat->keyboard->pending_keymap);
seat->pending_keymap = xkb_keymap_ref(keymap); seat->keyboard->pending_keymap = xkb_keymap_ref(keymap);
if (seat->keyboard->keys.size == 0) if (seat->keyboard->keys.size == 0)
update_keymap(seat); update_keymap(seat);
@ -1931,39 +1949,39 @@ weston_seat_init_keyboard(struct weston_seat *seat, struct xkb_keymap *keymap)
return 0; return 0;
} }
keyboard = weston_keyboard_create();
if (keyboard == NULL) {
weston_log("failed to allocate weston keyboard struct\n");
return -1;
}
seat->keyboard = keyboard;
seat->keyboard_device_count = 1;
keyboard->seat = seat;
#ifdef ENABLE_XKBCOMMON #ifdef ENABLE_XKBCOMMON
if (seat->compositor->use_xkbcommon) { if (seat->compositor->use_xkbcommon) {
if (keymap != NULL) { if (keymap != NULL) {
seat->xkb_info = weston_xkb_info_create(keymap); keyboard->xkb_info = weston_xkb_info_create(keymap);
if (seat->xkb_info == NULL) if (keyboard->xkb_info == NULL)
return -1; return -1;
} else { } else {
if (weston_compositor_build_global_keymap(seat->compositor) < 0) if (weston_compositor_build_global_keymap(seat->compositor) < 0)
return -1; return -1;
seat->xkb_info = seat->compositor->xkb_info; keyboard->xkb_info = seat->compositor->xkb_info;
seat->xkb_info->ref_count++; keyboard->xkb_info->ref_count++;
} }
seat->xkb_state.state = xkb_state_new(seat->xkb_info->keymap); keyboard->xkb_state.state = xkb_state_new(keyboard->xkb_info->keymap);
if (seat->xkb_state.state == NULL) { if (keyboard->xkb_state.state == NULL) {
weston_log("failed to initialise XKB state\n"); weston_log("failed to initialise XKB state\n");
return -1; return -1;
} }
seat->xkb_state.leds = 0; keyboard->xkb_state.leds = 0;
} }
#endif #endif
keyboard = weston_keyboard_create();
if (keyboard == NULL) {
weston_log("failed to allocate weston keyboard struct\n");
return -1;
}
seat->keyboard = keyboard;
seat->keyboard_device_count = 1;
keyboard->seat = seat;
seat_send_updated_caps(seat); seat_send_updated_caps(seat);
return 0; return 0;
@ -2089,17 +2107,6 @@ weston_seat_release(struct weston_seat *seat)
{ {
wl_list_remove(&seat->link); wl_list_remove(&seat->link);
#ifdef ENABLE_XKBCOMMON
if (seat->compositor->use_xkbcommon) {
if (seat->xkb_state.state != NULL)
xkb_state_unref(seat->xkb_state.state);
if (seat->xkb_info)
weston_xkb_info_destroy(seat->xkb_info);
if (seat->pending_keymap)
xkb_keymap_unref (seat->pending_keymap);
}
#endif
if (seat->pointer) if (seat->pointer)
weston_pointer_destroy(seat->pointer); weston_pointer_destroy(seat->pointer);
if (seat->keyboard) if (seat->keyboard)

@ -598,8 +598,8 @@ input_method_context_grab_keyboard(struct wl_client *client,
context->keyboard = cr; context->keyboard = cr;
wl_keyboard_send_keymap(cr, WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, wl_keyboard_send_keymap(cr, WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1,
seat->xkb_info->keymap_fd, keyboard->xkb_info->keymap_fd,
seat->xkb_info->keymap_size); keyboard->xkb_info->keymap_size);
if (keyboard->grab != &keyboard->default_grab) { if (keyboard->grab != &keyboard->default_grab) {
weston_keyboard_end_grab(keyboard); weston_keyboard_end_grab(keyboard);

Loading…
Cancel
Save