aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoremersion <contact@emersion.fr>2017-10-29 20:58:58 +0100
committeremersion <contact@emersion.fr>2017-10-31 12:30:57 +0100
commit6a74a3586fba7b8c3592d2a94d6b06190c3165b1 (patch)
tree7f40a1051b0b0468cb8451337e5f378f9d28f18c
parent044173d1dfbce7bdc3ae134a829f2bb0d88d208b (diff)
Fix wlr_cursor_destroy, handle device remove in examples/multi-cursor
-rw-r--r--examples/multi-pointer.c18
-rw-r--r--types/wlr_cursor.c51
2 files changed, 43 insertions, 26 deletions
diff --git a/examples/multi-pointer.c b/examples/multi-pointer.c
index c3a02cc7..3cfa3910 100644
--- a/examples/multi-pointer.c
+++ b/examples/multi-pointer.c
@@ -134,6 +134,7 @@ static void handle_input_add(struct compositor_state *state,
struct sample_cursor *cursor = calloc(1, sizeof(struct sample_cursor));
cursor->state = sample;
+ cursor->device = device;
cursor->cursor = wlr_cursor_create();
wlr_cursor_attach_output_layout(cursor->cursor, sample->layout);
@@ -156,6 +157,22 @@ static void handle_input_add(struct compositor_state *state,
wl_list_insert(&sample->cursors, &cursor->link);
}
+static void handle_input_remove(struct compositor_state *state,
+ struct wlr_input_device *device) {
+ struct sample_state *sample = state->data;
+ struct sample_cursor *cursor;
+ wl_list_for_each(cursor, &sample->cursors, link) {
+ if (cursor->device == device) {
+ wl_list_remove(&cursor->link);
+ wl_list_remove(&cursor->cursor_motion.link);
+ wl_list_remove(&cursor->cursor_motion_absolute.link);
+ wlr_cursor_destroy(cursor->cursor);
+ free(cursor);
+ break;
+ }
+ }
+}
+
int main(int argc, char *argv[]) {
struct sample_state state = {
.default_color = { 0.25f, 0.25f, 0.25f, 1 },
@@ -173,6 +190,7 @@ int main(int argc, char *argv[]) {
compositor.output_remove_cb = handle_output_remove;
compositor.output_frame_cb = handle_output_frame;
compositor.input_add_cb = handle_input_add;
+ compositor.input_remove_cb = handle_input_remove;
state.compositor = &compositor;
diff --git a/types/wlr_cursor.c b/types/wlr_cursor.c
index ece7973c..70ddea47 100644
--- a/types/wlr_cursor.c
+++ b/types/wlr_cursor.c
@@ -129,13 +129,36 @@ static void wlr_cursor_detach_output_layout(struct wlr_cursor *cur) {
cur->state->layout = NULL;
}
+static void wlr_cursor_device_destroy(struct wlr_cursor_device *c_device) {
+ struct wlr_input_device *dev = c_device->device;
+ if (dev->type == WLR_INPUT_DEVICE_POINTER) {
+ wl_list_remove(&c_device->motion.link);
+ wl_list_remove(&c_device->motion_absolute.link);
+ wl_list_remove(&c_device->button.link);
+ wl_list_remove(&c_device->axis.link);
+ } else if (dev->type == WLR_INPUT_DEVICE_TOUCH) {
+ wl_list_remove(&c_device->touch_down.link);
+ wl_list_remove(&c_device->touch_up.link);
+ wl_list_remove(&c_device->touch_motion.link);
+ wl_list_remove(&c_device->touch_cancel.link);
+ } else if (dev->type == WLR_INPUT_DEVICE_TABLET_TOOL) {
+ wl_list_remove(&c_device->tablet_tool_axis.link);
+ wl_list_remove(&c_device->tablet_tool_proximity.link);
+ wl_list_remove(&c_device->tablet_tool_tip.link);
+ wl_list_remove(&c_device->tablet_tool_button.link);
+ }
+
+ wl_list_remove(&c_device->link);
+ wl_list_remove(&c_device->destroy.link);
+ free(c_device);
+}
+
void wlr_cursor_destroy(struct wlr_cursor *cur) {
wlr_cursor_detach_output_layout(cur);
struct wlr_cursor_device *device, *device_tmp = NULL;
wl_list_for_each_safe(device, device_tmp, &cur->state->devices, link) {
- wl_list_remove(&device->link);
- free(device);
+ wlr_cursor_device_destroy(device);
}
free(cur);
@@ -474,30 +497,6 @@ void wlr_cursor_attach_input_device(struct wlr_cursor *cur,
wlr_cursor_device_create(cur, dev);
}
-static void wlr_cursor_device_destroy(struct wlr_cursor_device *c_device) {
- struct wlr_input_device *dev = c_device->device;
- if (dev->type == WLR_INPUT_DEVICE_POINTER) {
- wl_list_remove(&c_device->motion.link);
- wl_list_remove(&c_device->motion_absolute.link);
- wl_list_remove(&c_device->button.link);
- wl_list_remove(&c_device->axis.link);
- } else if (dev->type == WLR_INPUT_DEVICE_TOUCH) {
- wl_list_remove(&c_device->touch_down.link);
- wl_list_remove(&c_device->touch_up.link);
- wl_list_remove(&c_device->touch_motion.link);
- wl_list_remove(&c_device->touch_cancel.link);
- } else if (dev->type == WLR_INPUT_DEVICE_TABLET_TOOL) {
- wl_list_remove(&c_device->tablet_tool_axis.link);
- wl_list_remove(&c_device->tablet_tool_proximity.link);
- wl_list_remove(&c_device->tablet_tool_tip.link);
- wl_list_remove(&c_device->tablet_tool_button.link);
- }
-
- wl_list_remove(&c_device->link);
- wl_list_remove(&c_device->destroy.link);
- free(c_device);
-}
-
void wlr_cursor_detach_input_device(struct wlr_cursor *cur,
struct wlr_input_device *dev) {
struct wlr_cursor_device *c_device, *tmp = NULL;