Skip to content

Commit

Permalink
Rewrite of screen selection logic, plus synamic screen selection Wind…
Browse files Browse the repository at this point in the history
…ow.qml

Signed-off-by: Dominique Fuchs <[email protected]>
  • Loading branch information
DominiqueFuchs committed Jan 21, 2020
1 parent 77be672 commit 0697c81
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 45 deletions.
60 changes: 19 additions & 41 deletions src/gui/systray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,17 @@ bool Systray::isOpen()
return _isOpen;
}

Q_INVOKABLE int Systray::screenIndex()
{
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;
}

Q_INVOKABLE void Systray::setOpened()
{
_isOpen = true;
Expand Down Expand Up @@ -142,29 +153,13 @@ int Systray::calcTrayWindowX()
int trayIconTopCenterX = (topRight - ((topRight - topLeft) * 0.5)).x();
return trayIconTopCenterX - (400 * 0.5);
#else
QScreen* trayScreen = nullptr;
#if (QT_VERSION >= QT_VERSION_CHECK(5,10,0))
if (this->geometry().left() == 0 || this->geometry().top() == 0) {
trayScreen = QGuiApplication::screenAt(QCursor::pos());
QScreen* trayScreen = nullptr;
if (QGuiApplication::screens().count() > 1) {
trayScreen = QGuiApplication::screens().at(screenIndex());
} else {
trayScreen = QGuiApplication::screenAt(this->geometry().topLeft());
}
#else
foreach (QScreen* screen, QGuiApplication::screens()) {
if (this->geometry().left() == 0 || this->geometry().top() == 0) {
if (screen->geometry().contains(QCursor::pos())) {
trayScreen = screen;
}
} else {
if (screen->geometry().contains(this->geometry().topLeft())) {
trayScreen = screen;
}
}
}
if (trayScreen == nullptr) {
trayScreen = QGuiApplication::primaryScreen();
}
#endif

int screenWidth = trayScreen->geometry().width();
int screenHeight = trayScreen->geometry().height();
int availableWidth = trayScreen->availableGeometry().width();
Expand Down Expand Up @@ -210,30 +205,13 @@ int Systray::calcTrayWindowY()
// don't use availableGeometry() here, because this also excludes the dock
return 22+6;
#else
QScreen* trayScreen = nullptr;
#if (QT_VERSION >= QT_VERSION_CHECK(5,10,0))
if (this->geometry().left() == 0 || this->geometry().top() == 0) {
trayScreen = QGuiApplication::screenAt(QCursor::pos());
QScreen* trayScreen = nullptr;
if (QGuiApplication::screens().count() > 1) {
trayScreen = QGuiApplication::screens().at(screenIndex());
} else {
trayScreen = QGuiApplication::screenAt(this->geometry().topLeft());
}
#else
foreach (QScreen* screen, QGuiApplication::screens()) {
if (this->geometry().left() == 0 || this->geometry().top() == 0) {
if (screen->geometry().contains(QCursor::pos())) {
trayScreen = screen;
}
} else {
if (screen->geometry().contains(this->geometry().topLeft())) {
trayScreen = screen;
}
}
}
if (trayScreen == nullptr) {
trayScreen = QGuiApplication::primaryScreen();
}
#endif
int screenWidth = trayScreen->geometry().width();

int screenHeight = trayScreen->geometry().height();
int availableHeight = trayScreen->availableGeometry().height();

Expand Down
1 change: 1 addition & 0 deletions src/gui/systray.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class Systray
Q_INVOKABLE bool syncIsPaused();
Q_INVOKABLE void setOpened();
Q_INVOKABLE void setClosed();
Q_INVOKABLE int screenIndex();

signals:
void currentUserChanged();
Expand Down
2 changes: 1 addition & 1 deletion src/gui/tray/UserLine.qml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import QtQuick 2.9
import QtQuick.Window 2.2
import QtQuick.Window 2.3
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.2

Expand Down
6 changes: 3 additions & 3 deletions src/gui/tray/Window.qml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import QtQml 2.1
import QtQml.Models 2.1
import QtQuick 2.9
import QtQuick.Window 2.2
import QtQuick.Window 2.3
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.2
import QtGraphicalEffects 1.0
Expand Down Expand Up @@ -58,8 +58,8 @@ Window {
trayWindow.show();
trayWindow.raise();
trayWindow.requestActivate();
trayWindow.setX( systrayBackend.calcTrayWindowX());
trayWindow.setY( systrayBackend.calcTrayWindowY());
trayWindow.setX( Qt.application.screens[systrayBackend.screenIndex()].virtualX + systrayBackend.calcTrayWindowX());
trayWindow.setY( Qt.application.screens[systrayBackend.screenIndex()].virtualY + systrayBackend.calcTrayWindowY());
systrayBackend.setOpened();
userModelBackend.fetchCurrentActivityModel();
}
Expand Down

0 comments on commit 0697c81

Please sign in to comment.