Qt: Fix Wayland support
Qt will only create a Wayland surface when show() is called on the main window and on the ScreenWidget. Thus, call the function before creating the GL context. Doesn't cause regressions on XWayland, untested in other platforms. Fixes #586
This commit is contained in:
@@ -7,6 +7,5 @@ int main(int argc, char *argv[]) {
|
|||||||
QApplication app(argc, argv);
|
QApplication app(argc, argv);
|
||||||
MainWindow window(&app);
|
MainWindow window(&app);
|
||||||
|
|
||||||
window.show();
|
|
||||||
return app.exec();
|
return app.exec();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ MainWindow::MainWindow(QApplication* app, QWidget* parent) : QMainWindow(parent)
|
|||||||
// Enable drop events for loading ROMs
|
// Enable drop events for loading ROMs
|
||||||
setAcceptDrops(true);
|
setAcceptDrops(true);
|
||||||
resize(800, 240 * 4);
|
resize(800, 240 * 4);
|
||||||
|
show();
|
||||||
|
|
||||||
// We pass a callback to the screen widget that will be triggered every time we resize the screen
|
// We pass a callback to the screen widget that will be triggered every time we resize the screen
|
||||||
screen = new ScreenWidget([this](u32 width, u32 height) { handleScreenResize(width, height); }, this);
|
screen = new ScreenWidget([this](u32 width, u32 height) { handleScreenResize(width, height); }, this);
|
||||||
@@ -699,4 +700,4 @@ void MainWindow::setupControllerSensors(SDL_GameController* controller) {
|
|||||||
if (haveAccelerometer) {
|
if (haveAccelerometer) {
|
||||||
SDL_GameControllerSetSensorEnabled(controller, SDL_SENSOR_ACCEL, SDL_TRUE);
|
SDL_GameControllerSetSensorEnabled(controller, SDL_SENSOR_ACCEL, SDL_TRUE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ ScreenWidget::ScreenWidget(ResizeCallback resizeCallback, QWidget* parent) : QWi
|
|||||||
setAttribute(Qt::WA_KeyCompression, false);
|
setAttribute(Qt::WA_KeyCompression, false);
|
||||||
setFocusPolicy(Qt::StrongFocus);
|
setFocusPolicy(Qt::StrongFocus);
|
||||||
setMouseTracking(true);
|
setMouseTracking(true);
|
||||||
|
show();
|
||||||
|
|
||||||
if (!createGLContext()) {
|
if (!createGLContext()) {
|
||||||
Helpers::panic("Failed to create GL context for display");
|
Helpers::panic("Failed to create GL context for display");
|
||||||
@@ -84,7 +85,7 @@ bool ScreenWidget::createGLContext() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
qreal ScreenWidget::devicePixelRatioFromScreen() const {
|
qreal ScreenWidget::devicePixelRatioFromScreen() const {
|
||||||
const QScreen* screenForRatio = window()->windowHandle()->screen();
|
const QScreen* screenForRatio = windowHandle()->screen();
|
||||||
if (!screenForRatio) {
|
if (!screenForRatio) {
|
||||||
screenForRatio = QGuiApplication::primaryScreen();
|
screenForRatio = QGuiApplication::primaryScreen();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user