diff --git a/app/qml/Widgets/SmartWindow.qml b/app/qml/Widgets/SmartWindow.qml index 8ba78406..3ff08f54 100644 --- a/app/qml/Widgets/SmartWindow.qml +++ b/app/qml/Widgets/SmartWindow.qml @@ -70,6 +70,8 @@ Window { // // Save previous values for maximize/unmaximize cycle with delay // + x: 100 + y: 100 onXChanged: savePreviousDimensions() onYChanged: savePreviousDimensions() onWidthChanged: savePreviousDimensions() @@ -132,6 +134,19 @@ Window { // Ensure that window size stays within minimum size // Component.onCompleted: { + // Set initial window position within the primary screen bounds + const screenGeometry = Cpp_PrimaryScreen.geometry + if (root.x < screenGeometry.x || root.x > screenGeometry.x + screenGeometry.width - root.width) + root.x = screenGeometry.x + (screenGeometry.width - root.width) / 2 + if (root.y < screenGeometry.y || root.y > screenGeometry.y + screenGeometry.height - root.height) + root.y = screenGeometry.y + (screenGeometry.height - root.height) / 2 + + // Ensure minimum width and height + if (width < minimumWidth) + width = minimumWidth + if (height < minimumHeight) + height = minimumHeight + if (width < minimumWidth) width = minimumWidth if (height < minimumHeight) diff --git a/app/src/Misc/ModuleManager.cpp b/app/src/Misc/ModuleManager.cpp index b9287d61..e3b99d81 100644 --- a/app/src/Misc/ModuleManager.cpp +++ b/app/src/Misc/ModuleManager.cpp @@ -292,6 +292,7 @@ void Misc::ModuleManager::initializeQmlInterface() c->setContextProperty("Cpp_ModuleManager", this); c->setContextProperty("Cpp_BuildDate", buildDate); c->setContextProperty("Cpp_BuildTime", buildTime); + c->setContextProperty("Cpp_PrimaryScreen", qApp->primaryScreen()); // Register app info with QML c->setContextProperty("Cpp_AppName", qApp->applicationDisplayName()); diff --git a/app/src/Misc/TimerEvents.cpp b/app/src/Misc/TimerEvents.cpp index 87b7648d..15221d2d 100644 --- a/app/src/Misc/TimerEvents.cpp +++ b/app/src/Misc/TimerEvents.cpp @@ -20,6 +20,8 @@ * THE SOFTWARE. */ +#include +#include #include #include "Misc/TimerEvents.h" @@ -59,6 +61,9 @@ void Misc::TimerEvents::timerEvent(QTimerEvent *event) else if (event->timerId() == m_timer24Hz.timerId()) Q_EMIT timeout24Hz(); + + else if (event->timerId() == m_screenTimer.timerId()) + Q_EMIT timeoutScreen(); } /** @@ -66,8 +71,13 @@ void Misc::TimerEvents::timerEvent(QTimerEvent *event) */ void Misc::TimerEvents::startTimers() { + int screenHz = 32; + if (qApp->primaryScreen()) + screenHz = qMin(screenHz, qFloor(qApp->primaryScreen()->refreshRate())); + m_timer1Hz.start(1000, Qt::PreciseTimer, this); m_timer20Hz.start(1000 / 20, Qt::PreciseTimer, this); m_timer24Hz.start(1000 / 24, Qt::PreciseTimer, this); m_timer10Hz.start(1000 / 10, Qt::PreciseTimer, this); + m_screenTimer.start(1000 / screenHz, Qt::PreciseTimer, this); } diff --git a/app/src/Misc/TimerEvents.h b/app/src/Misc/TimerEvents.h index 9d4fdc32..60828418 100644 --- a/app/src/Misc/TimerEvents.h +++ b/app/src/Misc/TimerEvents.h @@ -42,6 +42,7 @@ signals: void timeout10Hz(); void timeout20Hz(); void timeout24Hz(); + void timeoutScreen(); private: TimerEvents() {}; @@ -65,5 +66,6 @@ private: QBasicTimer m_timer10Hz; QBasicTimer m_timer20Hz; QBasicTimer m_timer24Hz; + QBasicTimer m_screenTimer; }; } // namespace Misc diff --git a/app/src/UI/Dashboard.cpp b/app/src/UI/Dashboard.cpp index 3262ab27..4bbb645b 100644 --- a/app/src/UI/Dashboard.cpp +++ b/app/src/UI/Dashboard.cpp @@ -43,8 +43,8 @@ UI::Dashboard::Dashboard() connect(&JSON::FrameBuilder::instance(), &JSON::FrameBuilder::frameChanged, this, &UI::Dashboard::processFrame); // clang-format on - connect(&Misc::TimerEvents::instance(), &Misc::TimerEvents::timeout24Hz, this, - [=] { + connect(&Misc::TimerEvents::instance(), &Misc::TimerEvents::timeoutScreen, + this, [=] { if (m_updateRequired) { m_updateRequired = false; diff --git a/app/src/UI/Widgets/Terminal.cpp b/app/src/UI/Widgets/Terminal.cpp index d1a4ee3c..5319082d 100644 --- a/app/src/UI/Widgets/Terminal.cpp +++ b/app/src/UI/Widgets/Terminal.cpp @@ -124,10 +124,10 @@ Widgets::Terminal::Terminal(QQuickItem *parent) connect(&m_cursorTimer, &QTimer::timeout, this, &Widgets::Terminal::toggleCursor); - // Redraw the widget at 24 Hz and only when necessary + // Redraw the widget only when necessary m_stateChanged = true; - connect(&Misc::TimerEvents::instance(), &Misc::TimerEvents::timeout24Hz, this, - [=] { + connect(&Misc::TimerEvents::instance(), &Misc::TimerEvents::timeoutScreen, + this, [=] { if (isVisible() && m_stateChanged) { m_stateChanged = false; diff --git a/app/src/main.cpp b/app/src/main.cpp index f513136f..92098777 100644 --- a/app/src/main.cpp +++ b/app/src/main.cpp @@ -168,7 +168,7 @@ static void cliShowVersion() */ static void cliResetSettings() { - QSettings(APP_DEVELOPER, APP_NAME).clear(); + QSettings(APP_SUPPORT_URL, APP_NAME).clear(); qDebug() << APP_NAME << "settings cleared!"; }