зеркало из https://github.com/nextcloud/desktop.git
Get rid of screenIndex
This was leading to the same logic being duplicated several times. It's fine to return the QScreen* on the QML side directly but wrapped into a QVariant. Signed-off-by: Kevin Ottens <kevin.ottens@nextcloud.com>
This commit is contained in:
Родитель
6c6dfb15a7
Коммит
40824dc427
|
@ -158,16 +158,9 @@ QScreen *Systray::currentScreen() const
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
/// Return the current screen index based on cursor position
|
||||
int Systray::screenIndex() const
|
||||
QVariant Systray::currentScreenVar() const
|
||||
{
|
||||
auto qPos = QCursor::pos();
|
||||
for (int i = 0; i < QGuiApplication::screens().count(); i++) {
|
||||
if (QGuiApplication::screens().at(i)->geometry().contains(qPos)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return QVariant::fromValue(currentScreen());
|
||||
}
|
||||
|
||||
Systray::TaskBarPosition Systray::taskbarOrientation() const
|
||||
|
@ -195,17 +188,13 @@ Systray::TaskBarPosition Systray::taskbarOrientation() const
|
|||
}
|
||||
// Probably Linux
|
||||
#else
|
||||
auto currentScreen = screenIndex();
|
||||
auto screenWidth = QGuiApplication::screens().at(currentScreen)->geometry().width();
|
||||
auto screenHeight = QGuiApplication::screens().at(currentScreen)->geometry().height();
|
||||
auto virtualY = QGuiApplication::screens().at(currentScreen)->virtualGeometry().y();
|
||||
auto virtualX = QGuiApplication::screens().at(currentScreen)->virtualGeometry().x();
|
||||
QPoint trayIconCenter = calcTrayIconCenter();
|
||||
const auto screenRect = currentScreenRect();
|
||||
const auto trayIconCenter = calcTrayIconCenter();
|
||||
|
||||
auto distBottom = screenHeight - (trayIconCenter.y() - virtualY);
|
||||
auto distRight = screenWidth - (trayIconCenter.x() - virtualX);
|
||||
auto distLeft = trayIconCenter.x() - virtualX;
|
||||
auto distTop = trayIconCenter.y() - virtualY;
|
||||
auto distBottom = screenRect.bottom() - trayIconCenter.y();
|
||||
auto distRight = screenRect.right() - trayIconCenter.x();
|
||||
auto distLeft = trayIconCenter.x() - screenRect.left();
|
||||
auto distTop = trayIconCenter.y() - screenRect.top();
|
||||
|
||||
if (distBottom < distRight && distBottom < distTop && distBottom < distLeft) {
|
||||
return TaskBarPosition::Bottom;
|
||||
|
@ -225,7 +214,7 @@ QRect Systray::taskbarGeometry() const
|
|||
#if defined(Q_OS_WIN)
|
||||
QRect tbRect = Utility::getTaskbarDimensions();
|
||||
//QML side expects effective pixels, convert taskbar dimensions if necessary
|
||||
auto pixelRatio = QGuiApplication::screens().at(screenIndex())->devicePixelRatio();
|
||||
auto pixelRatio = currentScreen()->devicePixelRatio();
|
||||
if (pixelRatio != 1) {
|
||||
tbRect.setHeight(tbRect.height() / pixelRatio);
|
||||
tbRect.setWidth(tbRect.width() / pixelRatio);
|
||||
|
@ -233,14 +222,14 @@ QRect Systray::taskbarGeometry() const
|
|||
return tbRect;
|
||||
#elif defined(Q_OS_MACOS)
|
||||
// Finder bar is always 22px height on macOS (when treating as effective pixels)
|
||||
auto screenWidth = QGuiApplication::screens().at(screenIndex())->geometry().width();
|
||||
auto screenWidth = currentScreenRect().width();
|
||||
return QRect(0, 0, screenWidth, 22);
|
||||
#else
|
||||
if (taskbarOrientation() == TaskBarPosition::Bottom || taskbarOrientation() == TaskBarPosition::Top) {
|
||||
auto screenWidth = QGuiApplication::screens().at(screenIndex())->geometry().width();
|
||||
auto screenWidth = currentScreenRect().width();
|
||||
return QRect(0, 0, screenWidth, 32);
|
||||
} else {
|
||||
auto screenHeight = QGuiApplication::screens().at(screenIndex())->geometry().height();
|
||||
auto screenHeight = currentScreenRect().height();
|
||||
return QRect(0, 0, 32, screenHeight);
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -58,7 +58,7 @@ public:
|
|||
Q_INVOKABLE bool syncIsPaused();
|
||||
Q_INVOKABLE void setOpened();
|
||||
Q_INVOKABLE void setClosed();
|
||||
Q_INVOKABLE int screenIndex() const;
|
||||
Q_INVOKABLE QVariant currentScreenVar() const;
|
||||
Q_INVOKABLE QPoint calcTrayIconCenter() const;
|
||||
Q_INVOKABLE TaskBarPosition taskbarOrientation() const;
|
||||
Q_INVOKABLE QRect taskbarGeometry() const;
|
||||
|
|
|
@ -63,7 +63,7 @@ Window {
|
|||
onShowWindow: {
|
||||
accountMenu.close();
|
||||
|
||||
trayWindow.screen = Qt.application.screens[systrayBackend.screenIndex()];
|
||||
trayWindow.screen = systrayBackend.currentScreenVar();
|
||||
|
||||
var position = systrayBackend.computeWindowPosition(trayWindow.width, trayWindow.height)
|
||||
trayWindow.x = position.x
|
||||
|
|
Загрузка…
Ссылка в новой задаче