diff --git a/src/qt/qt_main.cpp b/src/qt/qt_main.cpp index bbdbc6dc3..f011fd9f7 100644 --- a/src/qt/qt_main.cpp +++ b/src/qt/qt_main.cpp @@ -13,6 +13,7 @@ #include "SDL.h" #include "SDL_mutex.h" +#include "SDL_timer.h" #include "qt_mainwindow.hpp" #include "qt_sdl.h" #include "cocoa_mouse.hpp" @@ -76,6 +77,12 @@ main_thread_fn() is_quit = 1; } +uint32_t timer_onesec(uint32_t interval, void* param) +{ + pc_onesec(); + return interval; +} + int main(int argc, char* argv[]) { QApplication app(argc, argv); #ifdef __APPLE__ @@ -97,6 +104,7 @@ int main(int argc, char* argv[]) { /* Set the PAUSE mode depending on the renderer. */ // plat_pause(0); + SDL_AddTimer(1000, timer_onesec, nullptr); /* Initialize the rendering window, or fullscreen. */ QTimer::singleShot(50, []() { plat_resize(640, 480); } ); diff --git a/src/qt/qt_mainwindow.cpp b/src/qt/qt_mainwindow.cpp index f70e55147..9adad9656 100644 --- a/src/qt/qt_mainwindow.cpp +++ b/src/qt/qt_mainwindow.cpp @@ -48,6 +48,9 @@ MainWindow::MainWindow(QWidget *parent) : connect(this, &MainWindow::showMessageForNonQtThread, this, &MainWindow::showMessage_, Qt::BlockingQueuedConnection); + connect(this, &MainWindow::setTitleForNonQtThread, this, &MainWindow::setTitle_, Qt::BlockingQueuedConnection); + connect(this, &MainWindow::getTitleForNonQtThread, this, &MainWindow::getTitle_, Qt::BlockingQueuedConnection); + connect(this, &MainWindow::pollMouse, ui->glesWidget, &GLESWidget::qt_mouse_poll); connect(this, &MainWindow::setMouseCapture, this, [this](bool state) { @@ -641,6 +644,34 @@ void MainWindow::on_actionFullscreen_triggered() { } } +void MainWindow::setTitle_(const wchar_t *title) +{ + this->setWindowTitle(QString::fromWCharArray(title)); +} + +void MainWindow::setTitle(const wchar_t *title) +{ + if (QThread::currentThread() == this->thread()) { + setTitle_(title); + } else { + emit setTitleForNonQtThread(title); + } +} + +void MainWindow::getTitle_(wchar_t *title) +{ + this->windowTitle().toWCharArray(title); +} + +void MainWindow::getTitle(wchar_t *title) +{ + if (QThread::currentThread() == this->thread()) { + getTitle_(title); + } else { + emit getTitleForNonQtThread(title); + } +} + void MainWindow::showMessage(const QString& header, const QString& message) { if (QThread::currentThread() == this->thread()) { showMessage_(header, message); diff --git a/src/qt/qt_mainwindow.hpp b/src/qt/qt_mainwindow.hpp index 9f3dee140..ba93df369 100644 --- a/src/qt/qt_mainwindow.hpp +++ b/src/qt/qt_mainwindow.hpp @@ -20,6 +20,8 @@ public: ~MainWindow(); void showMessage(const QString& header, const QString& message); + void setTitle(const wchar_t* title); + void getTitle(wchar_t* title); signals: void paint(const QImage& image); void blitToWidget(int x, int y, int w, int h); @@ -33,6 +35,8 @@ signals: void setMouseCapture(bool state); void showMessageForNonQtThread(const QString& header, const QString& message); + void setTitleForNonQtThread(const wchar_t* title); + void getTitleForNonQtThread(wchar_t* title); private slots: void on_actionFullscreen_triggered(); void on_actionSettings_triggered(); @@ -45,6 +49,8 @@ private slots: void on_actionKeyboard_requires_capture_triggered(); void showMessage_(const QString& header, const QString& message); + void setTitle_(const wchar_t* title); + void getTitle_(wchar_t* title); protected: void keyPressEvent(QKeyEvent* event) override; void keyReleaseEvent(QKeyEvent* event) override; diff --git a/src/qt/qt_ui.cpp b/src/qt/qt_ui.cpp index 1e24ac792..c4de70282 100644 --- a/src/qt/qt_ui.cpp +++ b/src/qt/qt_ui.cpp @@ -27,11 +27,11 @@ wchar_t* ui_window_title(wchar_t* str) { if (str == nullptr) { static wchar_t title[512]; - int chars = main_window->windowTitle().toWCharArray(title); - title[chars] = 0; + memset(title, 0, sizeof(title)); + main_window->getTitle(title); str = title; } else { - main_window->setWindowTitle(QString::fromWCharArray(str)); + main_window->setTitle(str); } return str; }