Skip to content

Commit

Permalink
Qt: Fix Wayland support
Browse files Browse the repository at this point in the history
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
  • Loading branch information
DaniElectra committed Dec 28, 2024
1 parent 3eb8984 commit 5f48028
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
1 change: 0 additions & 1 deletion src/panda_qt/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ int main(int argc, char *argv[]) {
QApplication app(argc, argv);
MainWindow window(&app);

window.show();
return app.exec();
}
3 changes: 2 additions & 1 deletion src/panda_qt/main_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ MainWindow::MainWindow(QApplication* app, QWidget* parent) : QMainWindow(parent)
// Enable drop events for loading ROMs
setAcceptDrops(true);
resize(800, 240 * 4);
show();

// 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);
Expand Down Expand Up @@ -699,4 +700,4 @@ void MainWindow::setupControllerSensors(SDL_GameController* controller) {
if (haveAccelerometer) {
SDL_GameControllerSetSensorEnabled(controller, SDL_SENSOR_ACCEL, SDL_TRUE);
}
}
}
3 changes: 2 additions & 1 deletion src/panda_qt/screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ ScreenWidget::ScreenWidget(ResizeCallback resizeCallback, QWidget* parent) : QWi
setAttribute(Qt::WA_KeyCompression, false);
setFocusPolicy(Qt::StrongFocus);
setMouseTracking(true);
show();

if (!createGLContext()) {
Helpers::panic("Failed to create GL context for display");
Expand Down Expand Up @@ -84,7 +85,7 @@ bool ScreenWidget::createGLContext() {
}

qreal ScreenWidget::devicePixelRatioFromScreen() const {
const QScreen* screenForRatio = window()->windowHandle()->screen();
const QScreen* screenForRatio = windowHandle()->screen();
if (!screenForRatio) {
screenForRatio = QGuiApplication::primaryScreen();
}
Expand Down

0 comments on commit 5f48028

Please sign in to comment.