[PATCH weston 27/31] Move keymaps to weston_seat

Daniel Stone daniel at fooishbar.org
Wed May 30 08:32:05 PDT 2012


In practice this doesn't mean much right now, since they all just take
an extra reference on the global keymap.

Signed-off-by: Daniel Stone <daniel at fooishbar.org>
---
 src/compositor.c |   44 ++++++++++++++++++++++++--------------------
 src/compositor.h |   21 +++++++++++----------
 2 files changed, 35 insertions(+), 30 deletions(-)

diff --git a/src/compositor.c b/src/compositor.c
index 8e8f348..2b99200 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -1770,22 +1770,22 @@ update_modifier_state(struct weston_seat *seat, uint32_t key, uint32_t state)
 	/* And update the modifier_state for bindings. */
 	mods_lookup = mods_depressed | mods_latched;
 	seat->modifier_state = 0;
-	if ((mods_lookup & seat->compositor->xkb_info.ctrl_mod))
+	if ((mods_lookup & seat->xkb_info.ctrl_mod))
 		seat->modifier_state |= MODIFIER_CTRL;
-	if ((mods_lookup & seat->compositor->xkb_info.alt_mod))
+	if ((mods_lookup & seat->xkb_info.alt_mod))
 		seat->modifier_state |= MODIFIER_ALT;
-	if ((mods_lookup & seat->compositor->xkb_info.super_mod))
+	if ((mods_lookup & seat->xkb_info.super_mod))
 		seat->modifier_state |= MODIFIER_SUPER;
 
 	/* Finally, notify the compositor that LEDs have changed. */
 	if (xkb_state_led_index_is_active(seat->xkb_state.state,
-					  seat->compositor->xkb_info.num_led))
+					  seat->xkb_info.num_led))
 		leds |= LED_NUM_LOCK;
 	if (xkb_state_led_index_is_active(seat->xkb_state.state,
-					  seat->compositor->xkb_info.caps_led))
+					  seat->xkb_info.caps_led))
 		leds |= LED_CAPS_LOCK;
 	if (xkb_state_led_index_is_active(seat->xkb_state.state,
-					  seat->compositor->xkb_info.scroll_led))
+					  seat->xkb_info.scroll_led))
 		leds |= LED_SCROLL_LOCK;
 	if (leds != seat->xkb_state.leds && seat->led_update)
 		seat->led_update(seat, seat->xkb_state.leds);
@@ -2268,6 +2268,9 @@ static void weston_compositor_xkb_destroy(struct weston_compositor *ec)
 static int
 weston_compositor_build_global_keymap(struct weston_compositor *ec)
 {
+	if (!ec->xkb_context)
+		weston_compositor_xkb_init(ec, NULL);
+
 	if (ec->xkb_info.keymap != NULL)
 		return 0;
 
@@ -2304,6 +2307,20 @@ weston_seat_init_keyboard(struct weston_seat *seat)
 	if (weston_compositor_build_global_keymap(seat->compositor) == -1)
 		return;
 
+	seat->xkb_info = seat->compositor->xkb_info;
+	seat->xkb_info.keymap = xkb_map_ref(seat->xkb_info.keymap);
+
+	seat->xkb_state.state = xkb_state_new(seat->xkb_info.keymap);
+	if (seat->xkb_state.state == NULL) {
+		fprintf(stderr, "failed to initialise XKB state\n");
+		exit(1);
+	}
+
+	seat->xkb_state.mods_depressed = 0;
+	seat->xkb_state.mods_latched = 0;
+	seat->xkb_state.mods_locked = 0;
+	seat->xkb_state.group = 0;
+
 	wl_keyboard_init(&seat->keyboard);
 	wl_seat_set_keyboard(&seat->seat, &seat->keyboard);
 
@@ -2362,20 +2379,6 @@ weston_seat_init(struct weston_seat *seat, struct weston_compositor *ec)
 	seat->new_drag_icon_listener.notify = device_handle_new_drag_icon;
 	wl_signal_add(&seat->seat.drag_icon_signal,
 		      &seat->new_drag_icon_listener);
-
-	if (!ec->xkb_context)
-		weston_compositor_xkb_init(ec, NULL);
-
-	seat->xkb_state.mods_depressed = 0;
-	seat->xkb_state.mods_latched = 0;
-	seat->xkb_state.mods_locked = 0;
-	seat->xkb_state.group = 0;
-
-	seat->xkb_state.state = xkb_state_new(ec->xkb_info.keymap);
-	if (seat->xkb_state.state == NULL) {
-		fprintf(stderr, "failed to initialise XKB state\n");
-		exit(1);
-	}
 }
 
 WL_EXPORT void
@@ -2389,6 +2392,7 @@ weston_seat_release(struct weston_seat *seat)
 
 	if (seat->xkb_state.state != NULL)
 		xkb_state_unref(seat->xkb_state.state);
+	xkb_info_destroy(&seat->xkb_info);
 
 	wl_seat_release(&seat->seat);
 }
diff --git a/src/compositor.h b/src/compositor.h
index 9a3b254..4a5c39c 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -157,6 +157,16 @@ struct weston_output {
 	void (*set_dpms)(struct weston_output *output, enum dpms_enum level);
 };
 
+struct weston_xkb_info {
+	struct xkb_keymap *keymap;
+	xkb_mod_index_t ctrl_mod;
+	xkb_mod_index_t alt_mod;
+	xkb_mod_index_t super_mod;
+	xkb_led_index_t num_led;
+	xkb_led_index_t caps_led;
+	xkb_led_index_t scroll_led;
+};
+
 struct weston_seat {
 	struct wl_seat seat;
 	struct wl_pointer pointer;
@@ -187,6 +197,7 @@ struct weston_seat {
 
 	void (*led_update)(struct weston_seat *ws, enum weston_led leds);
 
+	struct weston_xkb_info xkb_info;
 	struct {
 		struct xkb_state *state;
 		uint32_t mods_depressed;
@@ -236,16 +247,6 @@ struct weston_layer {
 	struct wl_list link;
 };
 
-struct weston_xkb_info {
-	struct xkb_keymap *keymap;
-	xkb_mod_index_t ctrl_mod;
-	xkb_mod_index_t alt_mod;
-	xkb_mod_index_t super_mod;
-	xkb_led_index_t num_led;
-	xkb_led_index_t caps_led;
-	xkb_led_index_t scroll_led;
-};
-
 struct weston_compositor {
 	struct wl_shm *shm;
 	struct wl_signal destroy_signal;
-- 
1.7.10



More information about the wayland-devel mailing list