diff --git a/qt/src/EmuCanvas.cpp b/qt/src/EmuCanvas.cpp index 1198ec4b..e07791ed 100644 --- a/qt/src/EmuCanvas.cpp +++ b/qt/src/EmuCanvas.cpp @@ -3,8 +3,8 @@ #include #include -EmuCanvas::EmuCanvas(EmuConfig *config, QWidget *parent, QWidget *main_window) - : QWidget(parent) +EmuCanvas::EmuCanvas(EmuConfig *config, QWidget *main_window) + : config(config), main_window(main_window) { setFocus(); setFocusPolicy(Qt::StrongFocus); @@ -12,9 +12,6 @@ EmuCanvas::EmuCanvas(EmuConfig *config, QWidget *parent, QWidget *main_window) output_data.buffer = nullptr; output_data.ready = false; - this->config = config; - this->parent = parent; - this->main_window = main_window; } EmuCanvas::~EmuCanvas() diff --git a/qt/src/EmuCanvas.hpp b/qt/src/EmuCanvas.hpp index ef9a1138..e8ec08ef 100644 --- a/qt/src/EmuCanvas.hpp +++ b/qt/src/EmuCanvas.hpp @@ -8,7 +8,7 @@ class EmuConfig; class EmuCanvas : public QWidget { public: - EmuCanvas(EmuConfig *config, QWidget *parent, QWidget *main_window); + EmuCanvas(EmuConfig *config, QWidget *main_window); ~EmuCanvas(); virtual void deinit() = 0; @@ -71,7 +71,6 @@ class EmuCanvas : public QWidget double frame_rate; } output_data; - QWidget *parent{}; QWidget *main_window{}; EmuConfig *config{}; Throttle throttle_object; diff --git a/qt/src/EmuCanvasOpenGL.cpp b/qt/src/EmuCanvasOpenGL.cpp index 6b5d6d4f..eb41fe0f 100644 --- a/qt/src/EmuCanvasOpenGL.cpp +++ b/qt/src/EmuCanvasOpenGL.cpp @@ -46,12 +46,19 @@ void main() } )"; -EmuCanvasOpenGL::EmuCanvasOpenGL(EmuConfig *config, QWidget *parent, QWidget *main_window) - : EmuCanvas(config, parent, main_window) +EmuCanvasOpenGL::EmuCanvasOpenGL(EmuConfig *config, QWidget *main_window) + : EmuCanvas(config, main_window) { setMinimumSize(256 / devicePixelRatioF(), 224 / devicePixelRatioF()); setUpdatesEnabled(false); setAutoFillBackground(false); + + if (QGuiApplication::platformName() == "wayland") + { + main_window->createWinId(); + return; + } + setAttribute(Qt::WA_NoSystemBackground, true); setAttribute(Qt::WA_NativeWindow, true); setAttribute(Qt::WA_PaintOnScreen, true); @@ -133,12 +140,12 @@ bool EmuCanvasOpenGL::createContext() #ifndef _WIN32 if (platform == "wayland") { - auto display = (wl_display *)pni->nativeResourceForWindow("display", windowHandle()); + auto display = (wl_display *)pni->nativeResourceForWindow("display", main_window->windowHandle()); auto surface = (wl_surface *)pni->nativeResourceForWindow("surface", main_window->windowHandle()); auto wayland_egl_context = new WaylandEGLContext(); int s = devicePixelRatio(); - if (!wayland_egl_context->attach(display, surface, { parent->x() - main_window->x(), parent->y() - main_window->y(), parent->width(), parent->height(), s })) + if (!wayland_egl_context->attach(display, surface, { x() - main_window->x(), y() - main_window->y(), width(), height(), s })) { printf("Couldn't attach context to wayland surface.\n"); context.reset(); @@ -306,12 +313,11 @@ void EmuCanvasOpenGL::resizeEvent(QResizeEvent *event) if (!context) return; - auto g = parent->geometry(); int s = devicePixelRatio(); auto platform = QGuiApplication::platformName(); #ifndef _WIN32 if (QGuiApplication::platformName() == "wayland") - ((WaylandEGLContext *)context.get())->resize({ g.x() - main_window->x(), g.y() - main_window->y(), g.width(), g.height(), s }); + ((WaylandEGLContext *)context.get())->resize({ x() - main_window->x(), y() - main_window->y(), width(), height(), s }); else if (platform == "xcb") ((GTKGLXContext *)context.get())->resize(); #else diff --git a/qt/src/EmuCanvasOpenGL.hpp b/qt/src/EmuCanvasOpenGL.hpp index d8148790..68a00324 100644 --- a/qt/src/EmuCanvasOpenGL.hpp +++ b/qt/src/EmuCanvasOpenGL.hpp @@ -11,7 +11,7 @@ class GLSLShader; class EmuCanvasOpenGL : public EmuCanvas { public: - EmuCanvasOpenGL(EmuConfig *config, QWidget *parent, QWidget *main_window); + EmuCanvasOpenGL(EmuConfig *config, QWidget *main_window); ~EmuCanvasOpenGL(); bool createContext() override; diff --git a/qt/src/EmuCanvasQt.cpp b/qt/src/EmuCanvasQt.cpp index 19031c4b..cad12636 100644 --- a/qt/src/EmuCanvasQt.cpp +++ b/qt/src/EmuCanvasQt.cpp @@ -5,8 +5,8 @@ #include #include -EmuCanvasQt::EmuCanvasQt(EmuConfig *config, QWidget *parent, QWidget *main_window) - : EmuCanvas(config, parent, main_window) +EmuCanvasQt::EmuCanvasQt(EmuConfig *config, QWidget *main_window) + : EmuCanvas(config, main_window) { setMinimumSize(256 / devicePixelRatioF(), 224 / devicePixelRatioF()); } diff --git a/qt/src/EmuCanvasQt.hpp b/qt/src/EmuCanvasQt.hpp index 5638d83d..512351b6 100644 --- a/qt/src/EmuCanvasQt.hpp +++ b/qt/src/EmuCanvasQt.hpp @@ -9,7 +9,7 @@ class EmuCanvasQt : public EmuCanvas { public: - EmuCanvasQt(EmuConfig *config, QWidget *parent, QWidget *main_window); + EmuCanvasQt(EmuConfig *config, QWidget *main_window); ~EmuCanvasQt(); virtual void deinit() override; diff --git a/qt/src/EmuCanvasVulkan.cpp b/qt/src/EmuCanvasVulkan.cpp index aa48275e..c308b6bf 100644 --- a/qt/src/EmuCanvasVulkan.cpp +++ b/qt/src/EmuCanvasVulkan.cpp @@ -11,12 +11,20 @@ using namespace QNativeInterface; -EmuCanvasVulkan::EmuCanvasVulkan(EmuConfig *config, QWidget *parent, QWidget *main_window) - : EmuCanvas(config, parent, main_window) +EmuCanvasVulkan::EmuCanvasVulkan(EmuConfig *config, QWidget *main_window) + : EmuCanvas(config, main_window) { setMinimumSize(256 / devicePixelRatioF(), 224 / devicePixelRatioF()); setUpdatesEnabled(false); setAutoFillBackground(false); + + if (QGuiApplication::platformName() == "wayland") + { + main_window->createWinId(); + window = main_window->windowHandle(); + return; + } + setAttribute(Qt::WA_NoSystemBackground, true); setAttribute(Qt::WA_NativeWindow, true); setAttribute(Qt::WA_PaintOnScreen, true); @@ -102,7 +110,7 @@ bool EmuCanvasVulkan::createContext() wayland_surface = std::make_unique(); auto display = (wl_display *)pni->nativeResourceForWindow("display", window); auto surface = (wl_surface *)pni->nativeResourceForWindow("surface", main_window->windowHandle()); - wayland_surface->attach(display, surface, { parent->x() - main_window->x(), parent->y() - main_window->y(), width(), height(), static_cast(devicePixelRatio()) }); + wayland_surface->attach(display, surface, { x() - main_window->x(), y() - main_window->y(), width(), height(), static_cast(devicePixelRatio()) }); auto [scaled_width, scaled_height] = wayland_surface->get_size(); context->swapchain->set_desired_size(scaled_width, scaled_height); @@ -215,6 +223,7 @@ void EmuCanvasVulkan::draw() if (retval) { throttle(); + context->swapchain->set_vsync(config->enable_vsync); context->swapchain->swap(); if (config->reduce_input_lag) { @@ -236,8 +245,8 @@ void EmuCanvasVulkan::resizeEvent(QResizeEvent *event) if (platform == "wayland") { WaylandSurface::Metrics m = { - parent->x() - main_window->x(), - parent->y() - main_window->y(), + this->x() - main_window->x(), + this->y() - main_window->y(), event->size().width(), event->size().height(), (int)devicePixelRatio() diff --git a/qt/src/EmuCanvasVulkan.hpp b/qt/src/EmuCanvasVulkan.hpp index ec20828a..fbb72be4 100644 --- a/qt/src/EmuCanvasVulkan.hpp +++ b/qt/src/EmuCanvasVulkan.hpp @@ -13,7 +13,7 @@ class EmuCanvasVulkan : public EmuCanvas { public: - EmuCanvasVulkan(EmuConfig *config, QWidget *parent, QWidget *main_window); + EmuCanvasVulkan(EmuConfig *config, QWidget *main_window); ~EmuCanvasVulkan(); bool createContext() override; diff --git a/qt/src/EmuMainWindow.cpp b/qt/src/EmuMainWindow.cpp index 0f372998..1e063a40 100644 --- a/qt/src/EmuMainWindow.cpp +++ b/qt/src/EmuMainWindow.cpp @@ -114,43 +114,9 @@ bool EmuMainWindow::createCanvas() app->config->display_driver != "qt") app->config->display_driver = "qt"; -#ifndef _WIN32 - if (QGuiApplication::platformName() == "wayland" && app->config->display_driver != "qt") - { - auto central_widget = new QStackedWidget(); - setVisible(true); - QGuiApplication::processEvents(); - - if (app->config->display_driver == "vulkan") - { - canvas = new EmuCanvasVulkan(app->config.get(), central_widget, this); - QGuiApplication::processEvents(); - if (!canvas->createContext()) - { - delete canvas; - return fallback(); - } - } - else if (app->config->display_driver == "opengl") - { - canvas = new EmuCanvasOpenGL(app->config.get(), central_widget, this); - QGuiApplication::processEvents(); - app->emu_thread->runOnThread([&] { canvas->createContext(); }, true); - } - - central_widget->addWidget(canvas); - central_widget->setCurrentWidget(canvas); - setCentralWidget(central_widget); - using_stacked_widget = true; - QGuiApplication::processEvents(); - - return true; - } -#endif - if (app->config->display_driver == "vulkan") { - canvas = new EmuCanvasVulkan(app->config.get(), this, this); + canvas = new EmuCanvasVulkan(app->config.get(), this); QGuiApplication::processEvents(); if (!canvas->createContext()) { @@ -160,12 +126,12 @@ bool EmuMainWindow::createCanvas() } else if (app->config->display_driver == "opengl") { - canvas = new EmuCanvasOpenGL(app->config.get(), this, this); + canvas = new EmuCanvasOpenGL(app->config.get(), this); QGuiApplication::processEvents(); app->emu_thread->runOnThread([&] { canvas->createContext(); }, true); } else - canvas = new EmuCanvasQt(app->config.get(), this, this); + canvas = new EmuCanvasQt(app->config.get(), this); setCentralWidget(canvas); using_stacked_widget = false;