mirror of
https://github.com/fergalmoran/flameshot.git
synced 2025-12-22 09:51:06 +00:00
* Replace foreach * Replace QRegExp with QRegularExpression * Replace QApplication::fontMetrics * Replace QColor::isValidColor * Replace canConvert(QVariant) * Replace QString::midRef and QCharRef * Add TODO for replacing QDesktopWidget for Qt 6 * Add TODO for replacing QTextCodec for Qt 6 * Fix QWidget::enterEvent for Qt 6 * qRegisterMetaTypeStreamOperators done automatically in Qt 6 * Fix QWidget::mapToGlobal for Qt 6 * Migrate QDesktopWidget replacement from old qt6 branch * Drop Qt 5 support
54 lines
1.7 KiB
C++
54 lines
1.7 KiB
C++
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
// SPDX-FileCopyrightText: 2021 Yuriy Puchkov <yuriy.puchkov@namecheap.com>
|
|
|
|
#include "qguiappcurrentscreen.h"
|
|
#include <QCursor>
|
|
#include <QGuiApplication>
|
|
#include <QPoint>
|
|
#include <QScreen>
|
|
|
|
QGuiAppCurrentScreen::QGuiAppCurrentScreen()
|
|
{
|
|
m_currentScreen = nullptr;
|
|
}
|
|
|
|
QScreen* QGuiAppCurrentScreen::currentScreen()
|
|
{
|
|
return currentScreen(QCursor::pos());
|
|
}
|
|
|
|
QScreen* QGuiAppCurrentScreen::currentScreen(const QPoint& pos)
|
|
{
|
|
m_currentScreen = screenAt(pos);
|
|
#if defined(Q_OS_MACOS)
|
|
// On the MacOS if mouse position is at the edge of bottom or right sides
|
|
// qGuiApp->screenAt will return nullptr, so we need to try to find current
|
|
// screen by moving 1 pixel inside to the current desktop area
|
|
if (!m_currentScreen && pos.x() > 0) {
|
|
QPoint posCorrected(pos.x() - 1, pos.y());
|
|
m_currentScreen = screenAt(posCorrected);
|
|
}
|
|
if (!m_currentScreen && pos.y() > 0) {
|
|
QPoint posCorrected(pos.x(), pos.y() - 1);
|
|
m_currentScreen = screenAt(posCorrected);
|
|
}
|
|
if (!m_currentScreen && pos.x() > 0 && pos.y() > 0) {
|
|
QPoint posCorrected(pos.x() - 1, pos.y() - 1);
|
|
m_currentScreen = screenAt(posCorrected);
|
|
}
|
|
#endif
|
|
if (!m_currentScreen) {
|
|
qCritical("Unable to get current screen, starting to use primary "
|
|
"screen. It may be a cause of logical error and working with "
|
|
"a wrong screen.");
|
|
m_currentScreen = qGuiApp->primaryScreen();
|
|
}
|
|
return m_currentScreen;
|
|
}
|
|
|
|
QScreen* QGuiAppCurrentScreen::screenAt(const QPoint& pos)
|
|
{
|
|
m_currentScreen = qGuiApp->screenAt(pos);
|
|
return m_currentScreen;
|
|
}
|