mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-12-23 10:29:49 +01:00
Fix wlr_cursor_destroy, handle device remove in examples/multi-cursor
This commit is contained in:
parent
044173d1df
commit
6a74a3586f
2 changed files with 43 additions and 26 deletions
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue