[PATCH weston 26/31] Separate out weston_xkb_info struct

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


Signed-off-by: Daniel Stone <daniel at fooishbar.org>
---
 src/compositor-x11.c |    6 +++---
 src/compositor.c     |   45 +++++++++++++++++++++++++--------------------
 src/compositor.h     |   24 +++++++++++++-----------
 3 files changed, 41 insertions(+), 34 deletions(-)

diff --git a/src/compositor-x11.c b/src/compositor-x11.c
index ac914be..0599269 100644
--- a/src/compositor-x11.c
+++ b/src/compositor-x11.c
@@ -749,9 +749,9 @@ x11_compositor_get_keymap(struct x11_compositor *c)
 #define copy_prop_value(to) \
 	length_part = strlen(value_part); \
 	if (value_part + length_part > (value_all + length_all) && \
-	    length_part > 0 && c->base.xkb_info.names.to == NULL) { \
-		free((char *) c->base.xkb_info.names.to);	    \
-		c->base.xkb_info.names.to = strdup(value_part); \
+	    length_part > 0 && c->base.xkb_names.to == NULL) { \
+		free((char *) c->base.xkb_names.to);	    \
+		c->base.xkb_names.to = strdup(value_part); \
 	} \
 	value_part += length_part + 1;
 
diff --git a/src/compositor.c b/src/compositor.c
index 56094e6..8e8f348 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -2229,35 +2229,40 @@ device_handle_new_drag_icon(struct wl_listener *listener, void *data)
 static int weston_compositor_xkb_init(struct weston_compositor *ec,
 				      struct xkb_rule_names *names)
 {
-	ec->xkb_info.context = xkb_context_new(0);
-	if (ec->xkb_info.context == NULL) {
+	ec->xkb_context = xkb_context_new(0);
+	if (ec->xkb_context == NULL) {
 		fprintf(stderr, "failed to create XKB context\n");
 		return -1;
 	}
 
 	if (names)
-		ec->xkb_info.names = *names;
-	if (!ec->xkb_info.names.rules)
-		ec->xkb_info.names.rules = strdup("evdev");
-	if (!ec->xkb_info.names.model)
-		ec->xkb_info.names.model = strdup("pc105");
-	if (!ec->xkb_info.names.layout)
-		ec->xkb_info.names.layout = strdup("us");
+		ec->xkb_names = *names;
+	if (!ec->xkb_names.rules)
+		ec->xkb_names.rules = strdup("evdev");
+	if (!ec->xkb_names.model)
+		ec->xkb_names.model = strdup("pc105");
+	if (!ec->xkb_names.layout)
+		ec->xkb_names.layout = strdup("us");
 
 	return 0;
 }
 
+static void xkb_info_destroy(struct weston_xkb_info *xkb_info)
+{
+        if (xkb_info->keymap)
+                xkb_map_unref(xkb_info->keymap);
+}
+
 static void weston_compositor_xkb_destroy(struct weston_compositor *ec)
 {
-	free((char *) ec->xkb_info.names.rules);
-	free((char *) ec->xkb_info.names.model);
-	free((char *) ec->xkb_info.names.layout);
-	free((char *) ec->xkb_info.names.variant);
-	free((char *) ec->xkb_info.names.options);
+	free((char *) ec->xkb_names.rules);
+	free((char *) ec->xkb_names.model);
+	free((char *) ec->xkb_names.layout);
+	free((char *) ec->xkb_names.variant);
+	free((char *) ec->xkb_names.options);
 
-	if (ec->xkb_info.keymap)
-		xkb_map_unref(ec->xkb_info.keymap);
-	xkb_context_unref(ec->xkb_info.context);
+	xkb_info_destroy(&ec->xkb_info);
+	xkb_context_unref(ec->xkb_context);
 }
 
 static int
@@ -2266,8 +2271,8 @@ weston_compositor_build_global_keymap(struct weston_compositor *ec)
 	if (ec->xkb_info.keymap != NULL)
 		return 0;
 
-	ec->xkb_info.keymap = xkb_map_new_from_names(ec->xkb_info.context,
-	                                             &ec->xkb_info.names, 0);
+	ec->xkb_info.keymap = xkb_map_new_from_names(ec->xkb_context,
+	                                             &ec->xkb_names, 0);
 	if (ec->xkb_info.keymap == NULL) {
 		fprintf(stderr, "failed to compile XKB keymap\n");
 		return -1;
@@ -2358,7 +2363,7 @@ weston_seat_init(struct weston_seat *seat, struct weston_compositor *ec)
 	wl_signal_add(&seat->seat.drag_icon_signal,
 		      &seat->new_drag_icon_listener);
 
-	if (!ec->xkb_info.context)
+	if (!ec->xkb_context)
 		weston_compositor_xkb_init(ec, NULL);
 
 	seat->xkb_state.mods_depressed = 0;
diff --git a/src/compositor.h b/src/compositor.h
index e2a172a..9a3b254 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -236,6 +236,16 @@ 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;
@@ -311,17 +321,9 @@ struct weston_compositor {
 
 	uint32_t output_id_pool;
 
-	struct {
-		struct xkb_rule_names names;
-		struct xkb_context *context;
-		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;
-	} xkb_info;
+	struct xkb_rule_names xkb_names;
+	struct xkb_context *xkb_context;
+	struct weston_xkb_info xkb_info;
 };
 
 enum weston_output_flags {
-- 
1.7.10



More information about the wayland-devel mailing list