[PATCH weston 2/6] input: Use a client id indexed array for input device resources

Rob Bradford robert.bradford at intel.com
Tue Aug 13 11:53:11 PDT 2013


From: Rob Bradford <rob at linux.intel.com>

Replace the list of resources per pointer/keyboard/touch with an array
of pointers to lists of resources from that client.

For compatability with the existing code find_resource_for_surface has
been modified to return the resource associated with the first entry in
the list and this is used to fill the focussed resource member on
pointer, keyboard and touch.
---
 src/compositor.h |  6 +++---
 src/input.c      | 66 ++++++++++++++++++++++++++++++++++++++++++++------------
 2 files changed, 55 insertions(+), 17 deletions(-)

diff --git a/src/compositor.h b/src/compositor.h
index 7600ce3..6d5ba62 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -299,7 +299,7 @@ struct weston_data_source {
 struct weston_pointer {
 	struct weston_seat *seat;
 
-	struct wl_list resource_list;
+	struct wl_array resources;
 	struct weston_surface *focus;
 	struct wl_resource *focus_resource;
 	struct wl_listener focus_listener;
@@ -325,7 +325,7 @@ struct weston_pointer {
 struct weston_touch {
 	struct weston_seat *seat;
 
-	struct wl_list resource_list;
+	struct wl_array resources;
 	struct weston_surface *focus;
 	struct wl_resource *focus_resource;
 	struct wl_listener focus_listener;
@@ -414,7 +414,7 @@ struct weston_xkb_info {
 struct weston_keyboard {
 	struct weston_seat *seat;
 
-	struct wl_list resource_list;
+	struct wl_array resources;
 	struct weston_surface *focus;
 	struct wl_resource *focus_resource;
 	struct wl_listener focus_listener;
diff --git a/src/input.c b/src/input.c
index cc2b417..45c21f1 100644
--- a/src/input.c
+++ b/src/input.c
@@ -229,15 +229,30 @@ default_grab_key(struct weston_keyboard_grab *grab,
 }
 
 static struct wl_resource *
-find_resource_for_surface(struct wl_list *list, struct weston_surface *surface)
+find_resource_for_surface(struct wl_array *array, struct weston_surface *surface)
 {
+	struct wl_client *client;
+	struct wl_list *list;
+	uint32_t id;
+
 	if (!surface)
 		return NULL;
 
 	if (!surface->resource)
 		return NULL;
-	
-	return wl_resource_find_for_client(list, wl_resource_get_client(surface->resource));
+
+	client = wl_resource_get_client(surface->resource);
+	id = wl_client_get_id(client);
+
+	if (array->size < (id + 1) * sizeof(struct wl_list *))
+		return NULL;
+
+	list = ((struct wl_list **)array->data)[id];
+
+	if (wl_list_empty(list))
+		return NULL;
+	else
+		return wl_resource_from_link(list->next);
 }
 
 static void
@@ -257,7 +272,7 @@ default_grab_modifiers(struct weston_keyboard_grab *grab, uint32_t serial,
 				   mods_latched, mods_locked, group);
 
 	if (pointer && pointer->focus && pointer->focus != keyboard->focus) {
-		pr = find_resource_for_surface(&keyboard->resource_list,
+		pr = find_resource_for_surface(&keyboard->resources,
 					       pointer->focus);
 		if (pr) {
 			wl_keyboard_send_modifiers(pr,
@@ -307,7 +322,7 @@ weston_pointer_create(void)
 	if (pointer == NULL)
 		return NULL;
 
-	wl_list_init(&pointer->resource_list);
+	wl_array_init(&pointer->resources);
 	pointer->focus_listener.notify = lose_pointer_focus;
 	pointer->default_grab.interface = &default_pointer_grab_interface;
 	pointer->default_grab.pointer = pointer;
@@ -344,7 +359,7 @@ weston_keyboard_create(void)
 	if (keyboard == NULL)
 	    return NULL;
 
-	wl_list_init(&keyboard->resource_list);
+	wl_array_init(&keyboard->resources);
 	wl_array_init(&keyboard->keys);
 	keyboard->focus_listener.notify = lose_keyboard_focus;
 	keyboard->default_grab.interface = &default_keyboard_grab_interface;
@@ -374,7 +389,7 @@ weston_touch_create(void)
 	if (touch == NULL)
 		return NULL;
 
-	wl_list_init(&touch->resource_list);
+	wl_array_init(&touch->resources);
 	touch->focus_listener.notify = lose_touch_focus;
 	touch->default_grab.interface = &default_touch_grab_interface;
 	touch->default_grab.touch = touch;
@@ -430,14 +445,14 @@ weston_pointer_set_focus(struct weston_pointer *pointer,
 		wl_list_remove(&pointer->focus_listener.link);
 	}
 
-	resource = find_resource_for_surface(&pointer->resource_list,
+	resource = find_resource_for_surface(&pointer->resources,
 					     surface);
 	if (resource &&
 	    (pointer->focus != surface ||
 	     pointer->focus_resource != resource)) {
 		serial = wl_display_next_serial(display);
 		if (kbd) {
-			kr = find_resource_for_surface(&kbd->resource_list,
+			kr = find_resource_for_surface(&kbd->resources,
 						       surface);
 			if (kr) {
 				wl_keyboard_send_modifiers(kr,
@@ -476,7 +491,7 @@ weston_keyboard_set_focus(struct weston_keyboard *keyboard,
 		wl_list_remove(&keyboard->focus_listener.link);
 	}
 
-	resource = find_resource_for_surface(&keyboard->resource_list,
+	resource = find_resource_for_surface(&keyboard->resources,
 					     surface);
 	if (resource &&
 	    (keyboard->focus != surface ||
@@ -987,7 +1002,7 @@ weston_touch_set_focus(struct weston_seat *seat, struct weston_surface *surface)
 
 	if (surface) {
 		resource =
-			find_resource_for_surface(&seat->touch->resource_list,
+			find_resource_for_surface(&seat->touch->resources,
 						  surface);
 		if (!resource) {
 			weston_log("couldn't find resource\n");
@@ -1163,6 +1178,29 @@ static const struct wl_pointer_interface pointer_interface = {
 };
 
 static void
+add_client_resource(struct wl_array *array, struct wl_client *client,
+		    struct wl_resource *resource)
+{
+	struct wl_list *list;
+	uint32_t id;
+	struct wl_list **p;
+
+	id = wl_client_get_id(client);
+
+	while (array->size < ((id + 1) * sizeof(struct wl_list *)))
+	{
+		p = wl_array_add(array, sizeof(struct wl_list *));
+		list = malloc(sizeof(struct wl_list));
+		wl_list_init(list);
+		*p = list;
+	}
+
+	list = ((struct wl_list **)array->data)[id];
+
+	wl_list_insert(list, wl_resource_get_link(resource));
+}
+
+static void
 seat_get_pointer(struct wl_client *client, struct wl_resource *resource,
 		 uint32_t id)
 {
@@ -1179,7 +1217,7 @@ seat_get_pointer(struct wl_client *client, struct wl_resource *resource,
 		return;
 	}
 
-	wl_list_insert(&seat->pointer->resource_list, wl_resource_get_link(cr));
+	add_client_resource(&seat->pointer->resources, client, cr);
 	wl_resource_set_implementation(cr, &pointer_interface, seat->pointer,
 				       unbind_resource);
 
@@ -1218,7 +1256,7 @@ seat_get_keyboard(struct wl_client *client, struct wl_resource *resource,
 		return;
 	}
 
-	wl_list_insert(&seat->keyboard->resource_list, wl_resource_get_link(cr));
+	add_client_resource(&seat->keyboard->resources, client, cr);
 	wl_resource_set_implementation(cr, NULL, seat, unbind_resource);
 
 	if (seat->compositor->use_xkbcommon) {
@@ -1258,7 +1296,7 @@ seat_get_touch(struct wl_client *client, struct wl_resource *resource,
 		return;
 	}
 
-	wl_list_insert(&seat->touch->resource_list, wl_resource_get_link(cr));
+	add_client_resource(&seat->touch->resources, client, cr);
 	wl_resource_set_implementation(cr, NULL, seat, unbind_resource);
 }
 
-- 
1.8.3.1



More information about the wayland-devel mailing list