mirror of https://github.com/snes9xgit/snes9x.git
Qt: Adapt to 6.8 changes for Wayland.
Remove parent stackwidget. Don't set native properties for the render, widget because they apply to the main window instead. Subsurfaces don't need that anyway.
This commit is contained in:
parent
fd05ca7df5
commit
a7d59843da
|
@ -3,8 +3,8 @@
|
||||||
#include <qnamespace.h>
|
#include <qnamespace.h>
|
||||||
#include <qwidget.h>
|
#include <qwidget.h>
|
||||||
|
|
||||||
EmuCanvas::EmuCanvas(EmuConfig *config, QWidget *parent, QWidget *main_window)
|
EmuCanvas::EmuCanvas(EmuConfig *config, QWidget *main_window)
|
||||||
: QWidget(parent)
|
: config(config), main_window(main_window)
|
||||||
{
|
{
|
||||||
setFocus();
|
setFocus();
|
||||||
setFocusPolicy(Qt::StrongFocus);
|
setFocusPolicy(Qt::StrongFocus);
|
||||||
|
@ -12,9 +12,6 @@ EmuCanvas::EmuCanvas(EmuConfig *config, QWidget *parent, QWidget *main_window)
|
||||||
|
|
||||||
output_data.buffer = nullptr;
|
output_data.buffer = nullptr;
|
||||||
output_data.ready = false;
|
output_data.ready = false;
|
||||||
this->config = config;
|
|
||||||
this->parent = parent;
|
|
||||||
this->main_window = main_window;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EmuCanvas::~EmuCanvas()
|
EmuCanvas::~EmuCanvas()
|
||||||
|
|
|
@ -8,7 +8,7 @@ class EmuConfig;
|
||||||
class EmuCanvas : public QWidget
|
class EmuCanvas : public QWidget
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
EmuCanvas(EmuConfig *config, QWidget *parent, QWidget *main_window);
|
EmuCanvas(EmuConfig *config, QWidget *main_window);
|
||||||
~EmuCanvas();
|
~EmuCanvas();
|
||||||
|
|
||||||
virtual void deinit() = 0;
|
virtual void deinit() = 0;
|
||||||
|
@ -71,7 +71,6 @@ class EmuCanvas : public QWidget
|
||||||
double frame_rate;
|
double frame_rate;
|
||||||
} output_data;
|
} output_data;
|
||||||
|
|
||||||
QWidget *parent{};
|
|
||||||
QWidget *main_window{};
|
QWidget *main_window{};
|
||||||
EmuConfig *config{};
|
EmuConfig *config{};
|
||||||
Throttle throttle_object;
|
Throttle throttle_object;
|
||||||
|
|
|
@ -46,12 +46,19 @@ void main()
|
||||||
}
|
}
|
||||||
)";
|
)";
|
||||||
|
|
||||||
EmuCanvasOpenGL::EmuCanvasOpenGL(EmuConfig *config, QWidget *parent, QWidget *main_window)
|
EmuCanvasOpenGL::EmuCanvasOpenGL(EmuConfig *config, QWidget *main_window)
|
||||||
: EmuCanvas(config, parent, main_window)
|
: EmuCanvas(config, main_window)
|
||||||
{
|
{
|
||||||
setMinimumSize(256 / devicePixelRatioF(), 224 / devicePixelRatioF());
|
setMinimumSize(256 / devicePixelRatioF(), 224 / devicePixelRatioF());
|
||||||
setUpdatesEnabled(false);
|
setUpdatesEnabled(false);
|
||||||
setAutoFillBackground(false);
|
setAutoFillBackground(false);
|
||||||
|
|
||||||
|
if (QGuiApplication::platformName() == "wayland")
|
||||||
|
{
|
||||||
|
main_window->createWinId();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
setAttribute(Qt::WA_NoSystemBackground, true);
|
setAttribute(Qt::WA_NoSystemBackground, true);
|
||||||
setAttribute(Qt::WA_NativeWindow, true);
|
setAttribute(Qt::WA_NativeWindow, true);
|
||||||
setAttribute(Qt::WA_PaintOnScreen, true);
|
setAttribute(Qt::WA_PaintOnScreen, true);
|
||||||
|
@ -133,12 +140,12 @@ bool EmuCanvasOpenGL::createContext()
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
if (platform == "wayland")
|
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 surface = (wl_surface *)pni->nativeResourceForWindow("surface", main_window->windowHandle());
|
||||||
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() - 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");
|
printf("Couldn't attach context to wayland surface.\n");
|
||||||
context.reset();
|
context.reset();
|
||||||
|
@ -306,12 +313,11 @@ void EmuCanvasOpenGL::resizeEvent(QResizeEvent *event)
|
||||||
if (!context)
|
if (!context)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto g = parent->geometry();
|
|
||||||
int s = devicePixelRatio();
|
int s = devicePixelRatio();
|
||||||
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() - 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")
|
else if (platform == "xcb")
|
||||||
((GTKGLXContext *)context.get())->resize();
|
((GTKGLXContext *)context.get())->resize();
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -11,7 +11,7 @@ class GLSLShader;
|
||||||
class EmuCanvasOpenGL : public EmuCanvas
|
class EmuCanvasOpenGL : public EmuCanvas
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
EmuCanvasOpenGL(EmuConfig *config, QWidget *parent, QWidget *main_window);
|
EmuCanvasOpenGL(EmuConfig *config, QWidget *main_window);
|
||||||
~EmuCanvasOpenGL();
|
~EmuCanvasOpenGL();
|
||||||
|
|
||||||
bool createContext() override;
|
bool createContext() override;
|
||||||
|
|
|
@ -5,8 +5,8 @@
|
||||||
#include <QtEvents>
|
#include <QtEvents>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
|
|
||||||
EmuCanvasQt::EmuCanvasQt(EmuConfig *config, QWidget *parent, QWidget *main_window)
|
EmuCanvasQt::EmuCanvasQt(EmuConfig *config, QWidget *main_window)
|
||||||
: EmuCanvas(config, parent, main_window)
|
: EmuCanvas(config, main_window)
|
||||||
{
|
{
|
||||||
setMinimumSize(256 / devicePixelRatioF(), 224 / devicePixelRatioF());
|
setMinimumSize(256 / devicePixelRatioF(), 224 / devicePixelRatioF());
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
class EmuCanvasQt : public EmuCanvas
|
class EmuCanvasQt : public EmuCanvas
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
EmuCanvasQt(EmuConfig *config, QWidget *parent, QWidget *main_window);
|
EmuCanvasQt(EmuConfig *config, QWidget *main_window);
|
||||||
~EmuCanvasQt();
|
~EmuCanvasQt();
|
||||||
|
|
||||||
virtual void deinit() override;
|
virtual void deinit() override;
|
||||||
|
|
|
@ -11,12 +11,20 @@
|
||||||
|
|
||||||
using namespace QNativeInterface;
|
using namespace QNativeInterface;
|
||||||
|
|
||||||
EmuCanvasVulkan::EmuCanvasVulkan(EmuConfig *config, QWidget *parent, QWidget *main_window)
|
EmuCanvasVulkan::EmuCanvasVulkan(EmuConfig *config, QWidget *main_window)
|
||||||
: EmuCanvas(config, parent, main_window)
|
: EmuCanvas(config, main_window)
|
||||||
{
|
{
|
||||||
setMinimumSize(256 / devicePixelRatioF(), 224 / devicePixelRatioF());
|
setMinimumSize(256 / devicePixelRatioF(), 224 / devicePixelRatioF());
|
||||||
setUpdatesEnabled(false);
|
setUpdatesEnabled(false);
|
||||||
setAutoFillBackground(false);
|
setAutoFillBackground(false);
|
||||||
|
|
||||||
|
if (QGuiApplication::platformName() == "wayland")
|
||||||
|
{
|
||||||
|
main_window->createWinId();
|
||||||
|
window = main_window->windowHandle();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
setAttribute(Qt::WA_NoSystemBackground, true);
|
setAttribute(Qt::WA_NoSystemBackground, true);
|
||||||
setAttribute(Qt::WA_NativeWindow, true);
|
setAttribute(Qt::WA_NativeWindow, true);
|
||||||
setAttribute(Qt::WA_PaintOnScreen, true);
|
setAttribute(Qt::WA_PaintOnScreen, true);
|
||||||
|
@ -102,7 +110,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() - main_window->x(), parent->y() - main_window->y(), width(), height(), static_cast<int>(devicePixelRatio()) });
|
wayland_surface->attach(display, surface, { x() - main_window->x(), 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();
|
||||||
|
|
||||||
context->swapchain->set_desired_size(scaled_width, scaled_height);
|
context->swapchain->set_desired_size(scaled_width, scaled_height);
|
||||||
|
@ -215,6 +223,7 @@ void EmuCanvasVulkan::draw()
|
||||||
if (retval)
|
if (retval)
|
||||||
{
|
{
|
||||||
throttle();
|
throttle();
|
||||||
|
context->swapchain->set_vsync(config->enable_vsync);
|
||||||
context->swapchain->swap();
|
context->swapchain->swap();
|
||||||
if (config->reduce_input_lag)
|
if (config->reduce_input_lag)
|
||||||
{
|
{
|
||||||
|
@ -236,8 +245,8 @@ void EmuCanvasVulkan::resizeEvent(QResizeEvent *event)
|
||||||
if (platform == "wayland")
|
if (platform == "wayland")
|
||||||
{
|
{
|
||||||
WaylandSurface::Metrics m = {
|
WaylandSurface::Metrics m = {
|
||||||
parent->x() - main_window->x(),
|
this->x() - main_window->x(),
|
||||||
parent->y() - main_window->y(),
|
this->y() - main_window->y(),
|
||||||
event->size().width(),
|
event->size().width(),
|
||||||
event->size().height(),
|
event->size().height(),
|
||||||
(int)devicePixelRatio()
|
(int)devicePixelRatio()
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
class EmuCanvasVulkan : public EmuCanvas
|
class EmuCanvasVulkan : public EmuCanvas
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
EmuCanvasVulkan(EmuConfig *config, QWidget *parent, QWidget *main_window);
|
EmuCanvasVulkan(EmuConfig *config, QWidget *main_window);
|
||||||
~EmuCanvasVulkan();
|
~EmuCanvasVulkan();
|
||||||
|
|
||||||
bool createContext() override;
|
bool createContext() override;
|
||||||
|
|
|
@ -114,43 +114,9 @@ bool EmuMainWindow::createCanvas()
|
||||||
app->config->display_driver != "qt")
|
app->config->display_driver != "qt")
|
||||||
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")
|
if (app->config->display_driver == "vulkan")
|
||||||
{
|
{
|
||||||
canvas = new EmuCanvasVulkan(app->config.get(), this, this);
|
canvas = new EmuCanvasVulkan(app->config.get(), this);
|
||||||
QGuiApplication::processEvents();
|
QGuiApplication::processEvents();
|
||||||
if (!canvas->createContext())
|
if (!canvas->createContext())
|
||||||
{
|
{
|
||||||
|
@ -160,12 +126,12 @@ bool EmuMainWindow::createCanvas()
|
||||||
}
|
}
|
||||||
else if (app->config->display_driver == "opengl")
|
else if (app->config->display_driver == "opengl")
|
||||||
{
|
{
|
||||||
canvas = new EmuCanvasOpenGL(app->config.get(), this, this);
|
canvas = new EmuCanvasOpenGL(app->config.get(), this);
|
||||||
QGuiApplication::processEvents();
|
QGuiApplication::processEvents();
|
||||||
app->emu_thread->runOnThread([&] { canvas->createContext(); }, true);
|
app->emu_thread->runOnThread([&] { canvas->createContext(); }, true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
canvas = new EmuCanvasQt(app->config.get(), this, this);
|
canvas = new EmuCanvasQt(app->config.get(), this);
|
||||||
|
|
||||||
setCentralWidget(canvas);
|
setCentralWidget(canvas);
|
||||||
using_stacked_widget = false;
|
using_stacked_widget = false;
|
||||||
|
|
Loading…
Reference in New Issue