Skip to content

Commit

Permalink
Fix for side panel widget out of screen #3522
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
petrugrd committed Apr 1, 2024
1 parent f288433 commit 40e996a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 16 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/Windows-pack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
29 changes: 18 additions & 11 deletions src/widgets/capture/capturewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(panelRect.x() / devicePixelRatio),
static_cast<int>(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<int>(panelRect.x() / devicePixelRatio),
static_cast<int>(panelRect.y() / devicePixelRatio));
}

if (ConfigHandler().showSidePanelButton()) {
Expand Down Expand Up @@ -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<int>(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
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/panel/sidepanelwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/widgets/panel/utilitypanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 40e996a

Please sign in to comment.