diff --git a/include/wlr/types/wlr_cursor.h b/include/wlr/types/wlr_cursor.h index 58ce85058..e99508f81 100644 --- a/include/wlr/types/wlr_cursor.h +++ b/include/wlr/types/wlr_cursor.h @@ -150,6 +150,13 @@ void wlr_cursor_set_image(struct wlr_cursor *cur, const uint8_t *pixels, void wlr_cursor_set_surface(struct wlr_cursor *cur, struct wlr_surface *surface, int32_t hotspot_x, int32_t hotspot_y); +/** + * Returns true when the input device, dev, is attached to the cursor, cur, + * by the wlr_cursor_attach_input_device function. + */ +bool wlr_cursor_is_input_device_attached(struct wlr_cursor *cur, + struct wlr_input_device *dev); + /** * Attaches this input device to this cursor. The input device must be one of: * diff --git a/types/wlr_cursor.c b/types/wlr_cursor.c index 429acd6db..9d611805c 100644 --- a/types/wlr_cursor.c +++ b/types/wlr_cursor.c @@ -682,6 +682,20 @@ static struct wlr_cursor_device *cursor_device_create( return c_device; } +bool wlr_cursor_is_input_device_attached(struct wlr_cursor *cur, + struct wlr_input_device *dev) { + if (!cur || !dev) { + return false; + } + struct wlr_cursor_device *_dev; + wl_list_for_each(_dev, &cur->state->devices, link) { + if (_dev->device == dev) { + return true; + } + } + return false; +} + void wlr_cursor_attach_input_device(struct wlr_cursor *cur, struct wlr_input_device *dev) { if (dev->type != WLR_INPUT_DEVICE_POINTER && @@ -693,11 +707,8 @@ void wlr_cursor_attach_input_device(struct wlr_cursor *cur, } // make sure it is not already attached - struct wlr_cursor_device *_dev; - wl_list_for_each(_dev, &cur->state->devices, link) { - if (_dev->device == dev) { - return; - } + if (wlr_cursor_is_input_device_attached(cur, dev)) { + return; } cursor_device_create(cur, dev);