Try to fix issues with multiple screens #149

This commit is contained in:
Alex Spataru 2024-11-10 01:58:04 -05:00
parent 3c6e2a1b0c
commit 7c9cc7a1e9
7 changed files with 34 additions and 6 deletions

View File

@ -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)

View File

@ -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());

View File

@ -20,6 +20,8 @@
* THE SOFTWARE.
*/
#include <QScreen>
#include <QApplication>
#include <QTimerEvent>
#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);
}

View File

@ -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

View File

@ -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;

View File

@ -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;

View File

@ -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!";
}