From 7f38e16983e3468cad8f53c23bb4f3209fe457f7 Mon Sep 17 00:00:00 2001 From: Simon Dean Date: Thu, 21 Nov 2024 13:06:48 +0000 Subject: [PATCH] Resolve display issue where if Raspberry Pi thinks both HDMI and LCD are enabled, the display width is appearing as two side by side monitors (double width) rather than just using the physical width of the screen. --- src/autoapp/autoapp.cpp | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/autoapp/autoapp.cpp b/src/autoapp/autoapp.cpp index 154f10b..8678ced 100644 --- a/src/autoapp/autoapp.cpp +++ b/src/autoapp/autoapp.cpp @@ -87,11 +87,31 @@ int main(int argc, char* argv[]) startIOServiceWorkers(ioService, threadPool); QApplication qApplication(argc, argv); - const int width = QApplication::desktop()->width(); - const int height = QApplication::desktop()->height(); + int width = QApplication::desktop()->width(); + int height = QApplication::desktop()->height(); + + for (QScreen *screen : qApplication.screens()) { + OPENAUTO_LOG(info) << "[AutoApp] Screen name: " << screen->name().toStdString(); + OPENAUTO_LOG(info) << "[AutoApp] Screen geometry: " << screen->geometry().width(); // This includes position and size + OPENAUTO_LOG(info) << "[AutoApp] Screen physical size: " << screen->physicalSize().width(); // Size in millimeters + } + + QScreen *primaryScreen = QGuiApplication::primaryScreen(); + + // Check if a primary screen was found + if (primaryScreen) { + // Get the geometry of the primary screen + QRect screenGeometry = primaryScreen->geometry(); + width = screenGeometry.width(); + height = screenGeometry.height(); + OPENAUTO_LOG(info) << "[AutoApp] Using gemoetry from primary screen."; + } else { + OPENAUTO_LOG(info) << "[AutoApp] Unable to find primary screen, using default values."; + } + OPENAUTO_LOG(info) << "[AutoApp] Display width: " << width; OPENAUTO_LOG(info) << "[AutoApp] Display height: " << height; - + auto configuration = std::make_shared(); autoapp::ui::MainWindow mainWindow(configuration);