From 10dbb00f5ffe0f598e52e0e839a5f145822d03d7 Mon Sep 17 00:00:00 2001 From: Ilia Mirkin Date: Sat, 6 Feb 2021 16:15:46 -0500 Subject: backend/x11: clamp hotspot to texture bounds When a new texture is set, the hotspot may actually belong to the previous texture and be out of bounds. Rather than incur X errors for these, clamp the hotspot to be inside of the texture. This fixes weston examples updating their cursors (e.g. weston-eventdemo). --- backend/x11/output.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'backend/x11') diff --git a/backend/x11/output.c b/backend/x11/output.c index 788be957..ef2d1c13 100644 --- a/backend/x11/output.c +++ b/backend/x11/output.c @@ -477,6 +477,19 @@ static bool output_set_cursor(struct wlr_output *wlr_output, if (texture != NULL) { width = texture->width * wlr_output->scale / scale; height = texture->height * wlr_output->scale / scale; + + if (hotspot_x < 0) { + hotspot_x = 0; + } + if ((uint32_t)hotspot_x > texture->width) { + hotspot_x = texture->width; + } + if (hotspot_y < 0) { + hotspot_y = 0; + } + if ((uint32_t)hotspot_y > texture->height) { + hotspot_y = texture->height; + } } struct wlr_box hotspot = { .x = hotspot_x, .y = hotspot_y }; -- cgit v1.2.3