mirror of
				https://gitlab.freedesktop.org/wlroots/wlroots.git
				synced 2025-11-03 09:01:40 -05:00 
			
		
		
		
	backend/libinput: use wl_array for wlr_libinput_tablet.tools
Instead of using a single-field wl_list, let's just use a wl_array.
This commit is contained in:
		
							parent
							
								
									a38baec1f8
								
							
						
					
					
						commit
						0a522cb798
					
				
					 1 changed files with 19 additions and 33 deletions
				
			
		| 
						 | 
					@ -11,6 +11,7 @@
 | 
				
			||||||
#include <wlr/types/wlr_input_device.h>
 | 
					#include <wlr/types/wlr_input_device.h>
 | 
				
			||||||
#include <wlr/util/log.h>
 | 
					#include <wlr/util/log.h>
 | 
				
			||||||
#include "backend/libinput.h"
 | 
					#include "backend/libinput.h"
 | 
				
			||||||
 | 
					#include "util/array.h"
 | 
				
			||||||
#include "util/signal.h"
 | 
					#include "util/signal.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static const struct wlr_tablet_impl tablet_impl;
 | 
					static const struct wlr_tablet_impl tablet_impl;
 | 
				
			||||||
| 
						 | 
					@ -29,18 +30,9 @@ struct wlr_libinput_tablet_tool {
 | 
				
			||||||
	size_t pad_refs;
 | 
						size_t pad_refs;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// TODO: Maybe this should be a wlr_list? Do we keep it, or want to get rid of
 | 
					 | 
				
			||||||
// it?
 | 
					 | 
				
			||||||
struct tablet_tool_list_elem {
 | 
					 | 
				
			||||||
	struct wl_list link;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	struct wlr_libinput_tablet_tool *tool;
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
struct wlr_libinput_tablet {
 | 
					struct wlr_libinput_tablet {
 | 
				
			||||||
	struct wlr_tablet wlr_tablet;
 | 
						struct wlr_tablet wlr_tablet;
 | 
				
			||||||
 | 
						struct wl_array tools; // struct wlr_libinput_tablet_tool *
 | 
				
			||||||
	struct wl_list tools; // tablet_tool_list_elem::link
 | 
					 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void destroy_tool(struct wlr_libinput_tablet_tool *tool) {
 | 
					static void destroy_tool(struct wlr_libinput_tablet_tool *tool) {
 | 
				
			||||||
| 
						 | 
					@ -56,17 +48,13 @@ static void destroy_tablet(struct wlr_tablet *wlr_tablet) {
 | 
				
			||||||
	struct wlr_libinput_tablet *tablet =
 | 
						struct wlr_libinput_tablet *tablet =
 | 
				
			||||||
		wl_container_of(wlr_tablet, tablet, wlr_tablet);
 | 
							wl_container_of(wlr_tablet, tablet, wlr_tablet);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	struct tablet_tool_list_elem *pos;
 | 
						struct wlr_libinput_tablet_tool *tool;
 | 
				
			||||||
	struct tablet_tool_list_elem *tmp;
 | 
						wl_array_for_each(tool, &tablet->tools) {
 | 
				
			||||||
	wl_list_for_each_safe(pos, tmp, &tablet->tools, link) {
 | 
					 | 
				
			||||||
		struct wlr_libinput_tablet_tool *tool = pos->tool;
 | 
					 | 
				
			||||||
		wl_list_remove(&pos->link);
 | 
					 | 
				
			||||||
		free(pos);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		if (--tool->pad_refs == 0) {
 | 
							if (--tool->pad_refs == 0) {
 | 
				
			||||||
			destroy_tool(tool);
 | 
								destroy_tool(tool);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						wl_array_release(&tablet->tools);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	free(tablet);
 | 
						free(tablet);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -94,7 +82,7 @@ struct wlr_tablet *create_libinput_tablet(
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	wlr_tablet->name = strdup(libinput_device_get_name(libinput_dev));
 | 
						wlr_tablet->name = strdup(libinput_device_get_name(libinput_dev));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	wl_list_init(&libinput_tablet->tools);
 | 
						wl_array_init(&libinput_tablet->tools);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return wlr_tablet;
 | 
						return wlr_tablet;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -163,9 +151,9 @@ static void ensure_tool_reference(struct wlr_libinput_tablet_tool *tool,
 | 
				
			||||||
	struct wlr_libinput_tablet *tablet =
 | 
						struct wlr_libinput_tablet *tablet =
 | 
				
			||||||
		wl_container_of(wlr_dev, tablet, wlr_tablet);
 | 
							wl_container_of(wlr_dev, tablet, wlr_tablet);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	struct tablet_tool_list_elem *pos;
 | 
						struct wlr_libinput_tablet_tool *iter;
 | 
				
			||||||
	wl_list_for_each(pos, &tablet->tools, link) {
 | 
						wl_array_for_each(iter, &tablet->tools) {
 | 
				
			||||||
		if (pos->tool == tool) { // We already have a ref
 | 
							if (iter == tool) { // We already have a ref
 | 
				
			||||||
			// XXX: We *could* optimize the tool to the front of
 | 
								// XXX: We *could* optimize the tool to the front of
 | 
				
			||||||
			// the list here, since we will probably get the next
 | 
								// the list here, since we will probably get the next
 | 
				
			||||||
			// couple of events from the same tool.
 | 
								// couple of events from the same tool.
 | 
				
			||||||
| 
						 | 
					@ -176,15 +164,13 @@ static void ensure_tool_reference(struct wlr_libinput_tablet_tool *tool,
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	struct tablet_tool_list_elem *new =
 | 
						struct wlr_libinput_tablet_tool **dst =
 | 
				
			||||||
		calloc(1, sizeof(struct tablet_tool_list_elem));
 | 
							wl_array_add(&tablet->tools, sizeof(tool));
 | 
				
			||||||
	if (!new) {
 | 
						if (!dst) {
 | 
				
			||||||
		wlr_log(WLR_ERROR, "Failed to allocate memory for tracking tablet tool");
 | 
							wlr_log(WLR_ERROR, "Failed to allocate memory for tracking tablet tool");
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						*dst = tool;
 | 
				
			||||||
	new->tool = tool;
 | 
					 | 
				
			||||||
	wl_list_insert(&tablet->tools, &new->link);
 | 
					 | 
				
			||||||
	++tool->pad_refs;
 | 
						++tool->pad_refs;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -297,15 +283,15 @@ void handle_tablet_tool_proximity(struct libinput_event *event,
 | 
				
			||||||
		assert(tablet_is_libinput(wlr_dev->tablet));
 | 
							assert(tablet_is_libinput(wlr_dev->tablet));
 | 
				
			||||||
		struct wlr_libinput_tablet *tablet =
 | 
							struct wlr_libinput_tablet *tablet =
 | 
				
			||||||
			wl_container_of(wlr_dev->tablet, tablet, wlr_tablet);
 | 
								wl_container_of(wlr_dev->tablet, tablet, wlr_tablet);
 | 
				
			||||||
		struct tablet_tool_list_elem *pos;
 | 
					 | 
				
			||||||
		struct tablet_tool_list_elem *tmp;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		wl_list_for_each_safe(pos, tmp, &tablet->tools, link) {
 | 
							size_t i = 0;
 | 
				
			||||||
			if (pos->tool == tool) {
 | 
							struct wlr_libinput_tablet_tool *iter;
 | 
				
			||||||
				wl_list_remove(&pos->link);
 | 
							wl_array_for_each(iter, &tablet->tools) {
 | 
				
			||||||
				free(pos);
 | 
								if (iter == tool) {
 | 
				
			||||||
 | 
									array_remove_at(&tablet->tools, i * sizeof(tool), sizeof(tool));
 | 
				
			||||||
				break;
 | 
									break;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
								i++;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		destroy_tool(tool);
 | 
							destroy_tool(tool);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue