From 40e996a2c874724a9ef196d36386cb29f7dc95ca Mon Sep 17 00:00:00 2001 From: Petru Gurduza Date: Mon, 1 Apr 2024 01:13:59 +0300 Subject: [PATCH] Fix for side panel widget out of screen #3522 The problem was that the panel was moved relative to (0, 0) coordinates, which is not an issue in case of single display, or multiple displays in the same row. Since capture widget is placed on all screens, the point (0, 0) will be the top left corner of virtual screen instead of top left corner of the current screen concluding from QDesktopWidget documentation (*). This caused the panel to be shifted up if the height of the primary screen was smaller than the virtual one. * https://doc.qt.io/qt-5/qdesktopwidget.html#screen-geometry Signed-off-by: Petru Gurduza --- .github/workflows/Windows-pack.yml | 4 ++-- src/widgets/capture/capturewidget.cpp | 29 +++++++++++++++++---------- src/widgets/panel/sidepanelwidget.cpp | 2 +- src/widgets/panel/utilitypanel.cpp | 4 ++-- 4 files changed, 23 insertions(+), 16 deletions(-) diff --git a/.github/workflows/Windows-pack.yml b/.github/workflows/Windows-pack.yml index 9504d684bb..0b0b14ed74 100644 --- a/.github/workflows/Windows-pack.yml +++ b/.github/workflows/Windows-pack.yml @@ -24,8 +24,8 @@ jobs: VCINSTALLDIR: C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/ Qt5_DIR: ${{ github.workspace }}\build\Qt\${{ matrix.qt_ver }}\${{ matrix.config.qt_arch_install }}\lib\cmake\Qt5\ QTDIR: ${{ github.workspace }}\build\Qt\${{ matrix.qt_ver }}\${{ matrix.config.qt_arch_install }}\ - # 2022.06.15.1 - VCPKG_VERSION: cef0b3ec767df6e83806899fe9525f6cf8d7bc91 + # 2024.03.25 + VCPKG_VERSION: a34c873a9717a888f58dc05268dea15592c2f0ff VCPKG_PACKAGES: openssl-windows OPENSSL_ROOT_DIR: ${{ github.workspace }}\vcpkg\installed\${{ matrix.config.vcpkg_triplet }}\ strategy: diff --git a/src/widgets/capture/capturewidget.cpp b/src/widgets/capture/capturewidget.cpp index 49ebff9720..ba1bee4d90 100644 --- a/src/widgets/capture/capturewidget.cpp +++ b/src/widgets/capture/capturewidget.cpp @@ -1062,20 +1062,29 @@ void CaptureWidget::initContext(bool fullscreen, const CaptureRequest& req) void CaptureWidget::initPanel() { QRect panelRect = rect(); + if (m_context.fullscreen) { + QScreen* currentScreen = nullptr; + qreal devicePixelRatio = 0; + #if (defined(Q_OS_MACOS) || defined(Q_OS_LINUX)) - QScreen* currentScreen = QGuiAppCurrentScreen().currentScreen(); + currentScreen = QGuiAppCurrentScreen().currentScreen(); panelRect = currentScreen->geometry(); - auto devicePixelRatio = currentScreen->devicePixelRatio(); - panelRect.moveTo(static_cast(panelRect.x() / devicePixelRatio), - static_cast(panelRect.y() / devicePixelRatio)); + devicePixelRatio = currentScreen->devicePixelRatio(); #else - panelRect = QGuiApplication::primaryScreen()->geometry(); - auto devicePixelRatio = - QGuiApplication::primaryScreen()->devicePixelRatio(); - panelRect.moveTo(panelRect.x() / devicePixelRatio, - panelRect.y() / devicePixelRatio); + currentScreen = QGuiApplication::primaryScreen(); + panelRect = currentScreen->geometry(); + devicePixelRatio = QGuiApplication::primaryScreen()->devicePixelRatio(); #endif + QRect virtualGeometry = currentScreen->virtualGeometry(); + QPoint screenOffset = panelRect.topLeft() - virtualGeometry.topLeft(); + + // Move panelRect by the offset + // of the primary display to the virtual display + panelRect.moveTo(screenOffset); + + panelRect.moveTo(static_cast(panelRect.x() / devicePixelRatio), + static_cast(panelRect.y() / devicePixelRatio)); } if (ConfigHandler().showSidePanelButton()) { @@ -1108,11 +1117,9 @@ void CaptureWidget::initPanel() makeChild(m_panel); #if defined(Q_OS_MACOS) QScreen* currentScreen = QGuiAppCurrentScreen().currentScreen(); - panelRect.moveTo(mapFromGlobal(panelRect.topLeft())); m_panel->setFixedWidth(static_cast(m_colorPicker->width() * 1.5)); m_panel->setFixedHeight(currentScreen->geometry().height()); #else - panelRect.moveTo(mapFromGlobal(panelRect.topLeft())); panelRect.setWidth(m_colorPicker->width() * 1.5); m_panel->setGeometry(panelRect); #endif diff --git a/src/widgets/panel/sidepanelwidget.cpp b/src/widgets/panel/sidepanelwidget.cpp index 2d156a48bf..fbf7335d33 100644 --- a/src/widgets/panel/sidepanelwidget.cpp +++ b/src/widgets/panel/sidepanelwidget.cpp @@ -81,7 +81,7 @@ SidePanelWidget::SidePanelWidget(QPixmap* p, QWidget* parent) m_layout->addWidget(m_colorWheel); m_layout->addWidget(m_colorHex); - QHBoxLayout* gridHBoxLayout = new QHBoxLayout(this); + QHBoxLayout* gridHBoxLayout = new QHBoxLayout(); m_gridCheck = new QCheckBox(tr("Display grid"), this); m_gridSizeSpin = new QSpinBox(this); m_gridSizeSpin->setRange(5, 50); diff --git a/src/widgets/panel/utilitypanel.cpp b/src/widgets/panel/utilitypanel.cpp index 5fc1889e2f..4fd9310fbd 100644 --- a/src/widgets/panel/utilitypanel.cpp +++ b/src/widgets/panel/utilitypanel.cpp @@ -42,7 +42,7 @@ UtilityPanel::UtilityPanel(CaptureWidget* captureWidget) m_internalPanel, &QWidget::hide); -#if (defined(Q_OS_WIN) || defined(Q_OS_MACOS)) +#if (defined(Q_OS_MACOS)) move(0, 0); #endif hide(); @@ -87,7 +87,7 @@ void UtilityPanel::show() m_showAnimation->setEndValue(QRect(0, 0, width(), height())); m_internalPanel->show(); m_showAnimation->start(); -#if (defined(Q_OS_WIN) || defined(Q_OS_MACOS)) +#if (defined(Q_OS_MACOS)) move(0, 0); #endif QWidget::show();