Wayland: Simplify decoration side detection

This commit simplifies the detection of which element of a fallback
decorated window the pointer has entered.  Instead of looping through
the list of windows, the user pointer of fallback decoration surfaces is
set to the GLFW window object.
This commit is contained in:
Camilla Löwy 2022-12-28 16:40:00 +01:00
parent 39f0e86228
commit cd466cf9fd

View File

@ -192,13 +192,15 @@ static struct wl_buffer* createShmBuffer(const GLFWimage* image)
return buffer; return buffer;
} }
static void createFallbackDecoration(_GLFWdecorationWayland* decoration, static void createFallbackDecoration(_GLFWwindow* window,
_GLFWdecorationWayland* decoration,
struct wl_surface* parent, struct wl_surface* parent,
struct wl_buffer* buffer, struct wl_buffer* buffer,
int x, int y, int x, int y,
int width, int height) int width, int height)
{ {
decoration->surface = wl_compositor_create_surface(_glfw.wl.compositor); decoration->surface = wl_compositor_create_surface(_glfw.wl.compositor);
wl_surface_set_user_data(decoration->surface, window);
wl_proxy_set_tag((struct wl_proxy*) decoration->surface, &_glfw.wl.tag); wl_proxy_set_tag((struct wl_proxy*) decoration->surface, &_glfw.wl.tag);
decoration->subsurface = decoration->subsurface =
wl_subcompositor_get_subsurface(_glfw.wl.subcompositor, wl_subcompositor_get_subsurface(_glfw.wl.subcompositor,
@ -229,19 +231,19 @@ static void createFallbackDecorations(_GLFWwindow* window)
if (!window->wl.decorations.buffer) if (!window->wl.decorations.buffer)
return; return;
createFallbackDecoration(&window->wl.decorations.top, window->wl.surface, createFallbackDecoration(window, &window->wl.decorations.top, window->wl.surface,
window->wl.decorations.buffer, window->wl.decorations.buffer,
0, -GLFW_CAPTION_HEIGHT, 0, -GLFW_CAPTION_HEIGHT,
window->wl.width, GLFW_CAPTION_HEIGHT); window->wl.width, GLFW_CAPTION_HEIGHT);
createFallbackDecoration(&window->wl.decorations.left, window->wl.surface, createFallbackDecoration(window, &window->wl.decorations.left, window->wl.surface,
window->wl.decorations.buffer, window->wl.decorations.buffer,
-GLFW_BORDER_SIZE, -GLFW_CAPTION_HEIGHT, -GLFW_BORDER_SIZE, -GLFW_CAPTION_HEIGHT,
GLFW_BORDER_SIZE, window->wl.height + GLFW_CAPTION_HEIGHT); GLFW_BORDER_SIZE, window->wl.height + GLFW_CAPTION_HEIGHT);
createFallbackDecoration(&window->wl.decorations.right, window->wl.surface, createFallbackDecoration(window, &window->wl.decorations.right, window->wl.surface,
window->wl.decorations.buffer, window->wl.decorations.buffer,
window->wl.width, -GLFW_CAPTION_HEIGHT, window->wl.width, -GLFW_CAPTION_HEIGHT,
GLFW_BORDER_SIZE, window->wl.height + GLFW_CAPTION_HEIGHT); GLFW_BORDER_SIZE, window->wl.height + GLFW_CAPTION_HEIGHT);
createFallbackDecoration(&window->wl.decorations.bottom, window->wl.surface, createFallbackDecoration(window, &window->wl.decorations.bottom, window->wl.surface,
window->wl.decorations.buffer, window->wl.decorations.buffer,
-GLFW_BORDER_SIZE, window->wl.height, -GLFW_BORDER_SIZE, window->wl.height,
window->wl.width + GLFW_BORDER_SIZE * 2, GLFW_BORDER_SIZE); window->wl.width + GLFW_BORDER_SIZE * 2, GLFW_BORDER_SIZE);
@ -1029,40 +1031,6 @@ static char* readDataOfferAsString(struct wl_data_offer* offer, const char* mime
return string; return string;
} }
static _GLFWwindow* findWindowFromDecorationSurface(struct wl_surface* surface,
_GLFWdecorationSideWayland* which)
{
_GLFWdecorationSideWayland focus;
_GLFWwindow* window = _glfw.windowListHead;
if (!which)
which = &focus;
while (window)
{
if (surface == window->wl.decorations.top.surface)
{
*which = GLFW_TOP_DECORATION;
break;
}
if (surface == window->wl.decorations.left.surface)
{
*which = GLFW_LEFT_DECORATION;
break;
}
if (surface == window->wl.decorations.right.surface)
{
*which = GLFW_RIGHT_DECORATION;
break;
}
if (surface == window->wl.decorations.bottom.surface)
{
*which = GLFW_BOTTOM_DECORATION;
break;
}
window = window->next;
}
return window;
}
static void pointerHandleEnter(void* userData, static void pointerHandleEnter(void* userData,
struct wl_pointer* pointer, struct wl_pointer* pointer,
uint32_t serial, uint32_t serial,
@ -1077,16 +1045,19 @@ static void pointerHandleEnter(void* userData,
if (wl_proxy_get_tag((struct wl_proxy*) surface) != &_glfw.wl.tag) if (wl_proxy_get_tag((struct wl_proxy*) surface) != &_glfw.wl.tag)
return; return;
_GLFWdecorationSideWayland focus = GLFW_MAIN_WINDOW;
_GLFWwindow* window = wl_surface_get_user_data(surface); _GLFWwindow* window = wl_surface_get_user_data(surface);
if (!window)
{
window = findWindowFromDecorationSurface(surface, &focus);
if (!window)
return;
}
window->wl.decorations.focus = focus; if (surface == window->wl.decorations.top.surface)
window->wl.decorations.focus = GLFW_TOP_DECORATION;
else if (surface == window->wl.decorations.left.surface)
window->wl.decorations.focus = GLFW_LEFT_DECORATION;
else if (surface == window->wl.decorations.right.surface)
window->wl.decorations.focus = GLFW_RIGHT_DECORATION;
else if (surface == window->wl.decorations.bottom.surface)
window->wl.decorations.focus = GLFW_BOTTOM_DECORATION;
else
window->wl.decorations.focus = GLFW_MAIN_WINDOW;
_glfw.wl.serial = serial; _glfw.wl.serial = serial;
_glfw.wl.pointerEnterSerial = serial; _glfw.wl.pointerEnterSerial = serial;
_glfw.wl.pointerFocus = window; _glfw.wl.pointerFocus = window;
@ -1447,13 +1418,12 @@ static void keyboardHandleEnter(void* userData,
if (!surface) if (!surface)
return; return;
if (wl_proxy_get_tag((struct wl_proxy*) surface) != &_glfw.wl.tag)
return;
_GLFWwindow* window = wl_surface_get_user_data(surface); _GLFWwindow* window = wl_surface_get_user_data(surface);
if (!window) if (surface != window->wl.surface)
{ return;
window = findWindowFromDecorationSurface(surface, NULL);
if (!window)
return;
}
_glfw.wl.serial = serial; _glfw.wl.serial = serial;
_glfw.wl.keyboardFocus = window; _glfw.wl.keyboardFocus = window;
@ -1706,7 +1676,7 @@ static void dataDeviceHandleEnter(void* userData,
window = wl_surface_get_user_data(surface); window = wl_surface_get_user_data(surface);
} }
if (window && _glfw.wl.offers[i].text_uri_list) if (surface == window->wl.surface && _glfw.wl.offers[i].text_uri_list)
{ {
_glfw.wl.dragOffer = offer; _glfw.wl.dragOffer = offer;
_glfw.wl.dragFocus = window; _glfw.wl.dragFocus = window;