Qt/Wayland: Fix case when window is reparented for server-side decoration.

Apparently the top-level window surface can start at negative coordinates, so the subsurface needs to be offset by that much more.
This commit is contained in:
BearOso 2023-10-11 15:02:08 -05:00
parent 953de52465
commit bd918f60fb
2 changed files with 4 additions and 4 deletions

View File

@ -138,7 +138,7 @@ bool EmuCanvasOpenGL::createContext()
auto wayland_egl_context = new WaylandEGLContext(); auto wayland_egl_context = new WaylandEGLContext();
int s = devicePixelRatio(); int s = devicePixelRatio();
if (!wayland_egl_context->attach(display, surface, { parent->x(), parent->y(), parent->width(), parent->height(), s })) if (!wayland_egl_context->attach(display, surface, { parent->x() - main_window->x(), parent->y() - main_window->y(), parent->width(), parent->height(), s }))
{ {
printf("Couldn't attach context to wayland surface.\n"); printf("Couldn't attach context to wayland surface.\n");
context.reset(); context.reset();
@ -311,7 +311,7 @@ void EmuCanvasOpenGL::resizeEvent(QResizeEvent *event)
auto platform = QGuiApplication::platformName(); auto platform = QGuiApplication::platformName();
#ifndef _WIN32 #ifndef _WIN32
if (QGuiApplication::platformName() == "wayland") if (QGuiApplication::platformName() == "wayland")
((WaylandEGLContext *)context.get())->resize({ g.x(), g.y(), g.width(), g.height(), s }); ((WaylandEGLContext *)context.get())->resize({ g.x() - main_window->x(), g.y() - main_window->y(), g.width(), g.height(), s });
else if (platform == "xcb") else if (platform == "xcb")
((GTKGLXContext *)context.get())->resize(); ((GTKGLXContext *)context.get())->resize();
#else #else

View File

@ -100,7 +100,7 @@ bool EmuCanvasVulkan::createContext()
wayland_surface = std::make_unique<WaylandSurface>(); wayland_surface = std::make_unique<WaylandSurface>();
auto display = (wl_display *)pni->nativeResourceForWindow("display", window); auto display = (wl_display *)pni->nativeResourceForWindow("display", window);
auto surface = (wl_surface *)pni->nativeResourceForWindow("surface", main_window->windowHandle()); auto surface = (wl_surface *)pni->nativeResourceForWindow("surface", main_window->windowHandle());
wayland_surface->attach(display, surface, { parent->x(), parent->y(), width(), height(), static_cast<int>(devicePixelRatio()) }); wayland_surface->attach(display, surface, { parent->x() - main_window->x(), parent->y() - main_window->y(), width(), height(), static_cast<int>(devicePixelRatio()) });
auto [scaled_width, scaled_height] = wayland_surface->get_size(); auto [scaled_width, scaled_height] = wayland_surface->get_size();
if (!context->init_wayland(display, wayland_surface->child, scaled_width, scaled_height, config->display_device_index)) if (!context->init_wayland(display, wayland_surface->child, scaled_width, scaled_height, config->display_device_index))
{ {
@ -228,7 +228,7 @@ void EmuCanvasVulkan::resizeEvent(QResizeEvent *event)
#ifndef _WIN32 #ifndef _WIN32
if (platform == "wayland") if (platform == "wayland")
{ {
wayland_surface->resize({ parent->x(), parent->y(), width, height, (int)devicePixelRatio() }); wayland_surface->resize({ parent->x() - main_window->x(), parent->y() - main_window->y(), width, height, (int)devicePixelRatio() });
std::tie(width, height) = wayland_surface->get_size(); std::tie(width, height) = wayland_surface->get_size();
// On Wayland, Vulkan WSI provides the buffer for the subsurface, // On Wayland, Vulkan WSI provides the buffer for the subsurface,
// so we have to specify a width and height instead of polling the parent. // so we have to specify a width and height instead of polling the parent.