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

Rob Bradford robert.bradford at intel.com
Mon Jul 22 09:31:40 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 84f39e2..8429b9b 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -296,7 +296,7 @@ struct wl_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;
@@ -322,7 +322,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;
@@ -408,7 +408,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 7e308d6..3cf3f3f 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,
@@ -308,7 +323,7 @@ weston_pointer_create(void)
 		return NULL;
 
 	memset(pointer, 0, sizeof *pointer);
-	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;
@@ -346,7 +361,7 @@ weston_keyboard_create(void)
 	    return NULL;
 
 	memset(keyboard, 0, sizeof *keyboard);
-	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;
@@ -377,7 +392,7 @@ weston_touch_create(void)
 		return NULL;
 
 	memset(touch, 0, sizeof *touch);
-	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;
@@ -433,14 +448,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,
@@ -479,7 +494,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 ||
@@ -990,7 +1005,7 @@ 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");
@@ -1158,6 +1173,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)
 {
@@ -1169,7 +1207,7 @@ seat_get_pointer(struct wl_client *client, struct wl_resource *resource,
 
         cr = wl_resource_create(client, &wl_pointer_interface,
 				wl_resource_get_version(resource), id);
-	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);
 
@@ -1203,7 +1241,7 @@ seat_get_keyboard(struct wl_client *client, struct wl_resource *resource,
 
         cr = wl_resource_create(client, &wl_keyboard_interface,
 				wl_resource_get_version(resource), id);
-	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) {
@@ -1238,7 +1276,7 @@ seat_get_touch(struct wl_client *client, struct wl_resource *resource,
 
         cr = wl_resource_create(client, &wl_touch_interface,
 				wl_resource_get_version(resource), id);
-	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