Since the role objects in the wayland_surface struct are part of a union, we first need to check whether the surface has the right role before checking the role objects themselves. Otherwise we risk using a subsurface as a toplevel or vice-versa.
The second commit introduces a helper to deduplicate the toplevel checks.
From: Alexandros Frantzis alexandros.frantzis@collabora.com
Since the role objects in the wayland_surface struct are part of a union, we first need to check whether the surface has the right role before checking the role objects themselves. Otherwise we risk using a subsurface as a toplevel or vice-versa. --- dlls/winewayland.drv/wayland_surface.c | 10 +++++++--- dlls/winewayland.drv/window.c | 10 +++++++--- 2 files changed, 14 insertions(+), 6 deletions(-)
diff --git a/dlls/winewayland.drv/wayland_surface.c b/dlls/winewayland.drv/wayland_surface.c index 39b6991a5eb..320ce9daa17 100644 --- a/dlls/winewayland.drv/wayland_surface.c +++ b/dlls/winewayland.drv/wayland_surface.c @@ -48,7 +48,9 @@ static void xdg_surface_handle_configure(void *private, struct xdg_surface *xdg_
/* Handle this event only if wayland_surface is still associated with * the target xdg_surface. */ - if ((surface = data->wayland_surface) && surface->xdg_surface == xdg_surface) + if ((surface = data->wayland_surface) && + surface->role == WAYLAND_SURFACE_ROLE_TOPLEVEL && + surface->xdg_surface == xdg_surface) { /* If we have a previously requested config, we have already sent a * WM_WAYLAND_CONFIGURE which hasn't been handled yet. In that case, @@ -116,7 +118,9 @@ static void xdg_toplevel_handle_configure(void *private,
if (!(data = wayland_win_data_get(hwnd))) return;
- if ((surface = data->wayland_surface) && surface->xdg_toplevel == xdg_toplevel) + if ((surface = data->wayland_surface) && + surface->role == WAYLAND_SURFACE_ROLE_TOPLEVEL && + surface->xdg_toplevel == xdg_toplevel) { surface->pending.width = width; surface->pending.height = height; @@ -1172,7 +1176,7 @@ void wayland_surface_set_title(struct wayland_surface *surface, LPCWSTR text) DWORD utf8_count; char *utf8 = NULL;
- assert(surface->xdg_toplevel); + assert(surface->role == WAYLAND_SURFACE_ROLE_TOPLEVEL && surface->xdg_toplevel);
TRACE("surface=%p hwnd=%p text='%s'\n", surface, surface->hwnd, wine_dbgstr_w(text)); diff --git a/dlls/winewayland.drv/window.c b/dlls/winewayland.drv/window.c index 184d09c2ed4..03dff29a4cc 100644 --- a/dlls/winewayland.drv/window.c +++ b/dlls/winewayland.drv/window.c @@ -537,7 +537,7 @@ static void wayland_configure_window(HWND hwnd) return; }
- if (!surface->xdg_toplevel) + if (surface->role != WAYLAND_SURFACE_ROLE_TOPLEVEL || !surface->xdg_toplevel) { TRACE("missing xdg_toplevel, returning\n"); wayland_win_data_release(data); @@ -721,7 +721,9 @@ void WAYLAND_SetWindowText(HWND hwnd, LPCWSTR text)
if ((data = wayland_win_data_get(hwnd))) { - if ((surface = data->wayland_surface) && surface->xdg_toplevel) + if ((surface = data->wayland_surface) && + surface->role == WAYLAND_SURFACE_ROLE_TOPLEVEL && + surface->xdg_toplevel) wayland_surface_set_title(surface, text); wayland_win_data_release(data); } @@ -755,7 +757,9 @@ LRESULT WAYLAND_SysCommand(HWND hwnd, WPARAM wparam, LPARAM lparam, const POINT { pthread_mutex_lock(&process_wayland.seat.mutex); wl_seat = process_wayland.seat.wl_seat; - if (wl_seat && (surface = data->wayland_surface) && surface->xdg_toplevel && button_serial) + if (wl_seat && (surface = data->wayland_surface) && + surface->role == WAYLAND_SURFACE_ROLE_TOPLEVEL && + surface->xdg_toplevel && button_serial) { if (command == SC_MOVE) {
From: Alexandros Frantzis alexandros.frantzis@collabora.com
--- dlls/winewayland.drv/wayland_surface.c | 11 ++++------- dlls/winewayland.drv/waylanddrv.h | 5 +++++ dlls/winewayland.drv/window.c | 16 +++++----------- 3 files changed, 14 insertions(+), 18 deletions(-)
diff --git a/dlls/winewayland.drv/wayland_surface.c b/dlls/winewayland.drv/wayland_surface.c index 320ce9daa17..8d6b73a61a9 100644 --- a/dlls/winewayland.drv/wayland_surface.c +++ b/dlls/winewayland.drv/wayland_surface.c @@ -48,8 +48,7 @@ static void xdg_surface_handle_configure(void *private, struct xdg_surface *xdg_
/* Handle this event only if wayland_surface is still associated with * the target xdg_surface. */ - if ((surface = data->wayland_surface) && - surface->role == WAYLAND_SURFACE_ROLE_TOPLEVEL && + if ((surface = data->wayland_surface) && wayland_surface_is_toplevel(surface) && surface->xdg_surface == xdg_surface) { /* If we have a previously requested config, we have already sent a @@ -118,9 +117,7 @@ static void xdg_toplevel_handle_configure(void *private,
if (!(data = wayland_win_data_get(hwnd))) return;
- if ((surface = data->wayland_surface) && - surface->role == WAYLAND_SURFACE_ROLE_TOPLEVEL && - surface->xdg_toplevel == xdg_toplevel) + if ((surface = data->wayland_surface) && wayland_surface_is_toplevel(surface)) { surface->pending.width = width; surface->pending.height = height; @@ -1176,7 +1173,7 @@ void wayland_surface_set_title(struct wayland_surface *surface, LPCWSTR text) DWORD utf8_count; char *utf8 = NULL;
- assert(surface->role == WAYLAND_SURFACE_ROLE_TOPLEVEL && surface->xdg_toplevel); + assert(wayland_surface_is_toplevel(surface));
TRACE("surface=%p hwnd=%p text='%s'\n", surface, surface->hwnd, wine_dbgstr_w(text)); @@ -1202,7 +1199,7 @@ void wayland_surface_set_icon(struct wayland_surface *surface, UINT type, ICONIN struct wayland_shm_buffer *icon_buf;
assert(ii); - assert(surface->role == WAYLAND_SURFACE_ROLE_TOPLEVEL && surface->xdg_toplevel); + assert(wayland_surface_is_toplevel(surface));
hDC = NtGdiCreateCompatibleDC(0); icon_buf = wayland_shm_buffer_from_color_bitmaps(hDC, ii->hbmColor, ii->hbmMask); diff --git a/dlls/winewayland.drv/waylanddrv.h b/dlls/winewayland.drv/waylanddrv.h index 30fc65d949a..24df4c66184 100644 --- a/dlls/winewayland.drv/waylanddrv.h +++ b/dlls/winewayland.drv/waylanddrv.h @@ -330,6 +330,11 @@ void wayland_surface_ensure_contents(struct wayland_surface *surface); void wayland_surface_set_title(struct wayland_surface *surface, LPCWSTR title); void wayland_surface_set_icon(struct wayland_surface *surface, UINT type, ICONINFO *ii);
+static inline BOOL wayland_surface_is_toplevel(struct wayland_surface *surface) +{ + return surface->role == WAYLAND_SURFACE_ROLE_TOPLEVEL && surface->xdg_toplevel; +} + /********************************************************************** * Wayland SHM buffer */ diff --git a/dlls/winewayland.drv/window.c b/dlls/winewayland.drv/window.c index 03dff29a4cc..acc34a18218 100644 --- a/dlls/winewayland.drv/window.c +++ b/dlls/winewayland.drv/window.c @@ -494,8 +494,7 @@ void WAYLAND_WindowPosChanged(HWND hwnd, HWND insert_after, HWND owner_hint, UIN }
needs_icon = data->wayland_surface && !data->wayland_surface->big_icon_buffer && - data->wayland_surface->role == WAYLAND_SURFACE_ROLE_TOPLEVEL && - data->wayland_surface->xdg_toplevel && + wayland_surface_is_toplevel(data->wayland_surface) && process_wayland.xdg_toplevel_icon_manager_v1;
wayland_win_data_release(data); @@ -537,7 +536,7 @@ static void wayland_configure_window(HWND hwnd) return; }
- if (surface->role != WAYLAND_SURFACE_ROLE_TOPLEVEL || !surface->xdg_toplevel) + if (!wayland_surface_is_toplevel(surface)) { TRACE("missing xdg_toplevel, returning\n"); wayland_win_data_release(data); @@ -700,9 +699,7 @@ void WAYLAND_SetWindowIcon(HWND hwnd, UINT type, HICON icon) icon = get_window_icon(hwnd, type, icon, &ii); if (icon && (data = wayland_win_data_get(hwnd))) { - if (data->wayland_surface && - data->wayland_surface->role == WAYLAND_SURFACE_ROLE_TOPLEVEL && - data->wayland_surface->xdg_toplevel) + if (data->wayland_surface && wayland_surface_is_toplevel(data->wayland_surface)) wayland_surface_set_icon(data->wayland_surface, type, &ii); wayland_win_data_release(data); } @@ -721,9 +718,7 @@ void WAYLAND_SetWindowText(HWND hwnd, LPCWSTR text)
if ((data = wayland_win_data_get(hwnd))) { - if ((surface = data->wayland_surface) && - surface->role == WAYLAND_SURFACE_ROLE_TOPLEVEL && - surface->xdg_toplevel) + if ((surface = data->wayland_surface) && wayland_surface_is_toplevel(surface)) wayland_surface_set_title(surface, text); wayland_win_data_release(data); } @@ -758,8 +753,7 @@ LRESULT WAYLAND_SysCommand(HWND hwnd, WPARAM wparam, LPARAM lparam, const POINT pthread_mutex_lock(&process_wayland.seat.mutex); wl_seat = process_wayland.seat.wl_seat; if (wl_seat && (surface = data->wayland_surface) && - surface->role == WAYLAND_SURFACE_ROLE_TOPLEVEL && - surface->xdg_toplevel && button_serial) + wayland_surface_is_toplevel(surface) && button_serial) { if (command == SC_MOVE) {