From 0a633adc72868c288a5c23eea09a8953538756a9 Mon Sep 17 00:00:00 2001 From: reionwong Date: Thu, 22 Jul 2021 12:55:44 +0800 Subject: [PATCH] Fix some issues in multi-screen --- src/fakewindow.cpp | 4 ++-- src/fakewindow.h | 2 +- src/mainwindow.cpp | 46 +++++++++++++++++++++++++++++++++++++++++----- src/mainwindow.h | 2 ++ 4 files changed, 46 insertions(+), 8 deletions(-) diff --git a/src/fakewindow.cpp b/src/fakewindow.cpp index 3c75f32..1078161 100644 --- a/src/fakewindow.cpp +++ b/src/fakewindow.cpp @@ -44,8 +44,8 @@ FakeWindow::FakeWindow(QQuickView *parent) Qt::WindowStaysOnTopHint | Qt::NoDropShadowWindowHint | Qt::WindowDoesNotAcceptFocus); - setScreen(qApp->primaryScreen()); - updateGeometry(); + // setScreen(qApp->primaryScreen()); + // updateGeometry(); show(); m_delayedMouseTimer.setSingleShot(true); diff --git a/src/fakewindow.h b/src/fakewindow.h index 74521b9..b20b099 100644 --- a/src/fakewindow.h +++ b/src/fakewindow.h @@ -31,6 +31,7 @@ public: explicit FakeWindow(QQuickView *parent = nullptr); bool containsMouse() const; + void updateGeometry(); signals: void containsMouseChanged(bool contains); @@ -41,7 +42,6 @@ protected: private: void setContainsMouse(bool contains); - void updateGeometry(); private: QTimer m_delayedMouseTimer; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index d83bc8c..7b738e8 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -59,7 +59,7 @@ MainWindow::MainWindow(QQuickView *parent) setSource(QUrl(QStringLiteral("qrc:/qml/main.qml"))); setResizeMode(QQuickView::SizeRootObjectToView); - setScreen(qApp->primaryScreen()); + initScreens(); initSlideWindow(); resizeWindow(); @@ -77,8 +77,9 @@ MainWindow::MainWindow(QQuickView *parent) connect(m_activity, &Activity::launchPadChanged, this, &MainWindow::onVisibilityChanged); // Screen change. - connect(qApp->primaryScreen(), &QScreen::virtualGeometryChanged, this, &MainWindow::resizeWindow); - connect(qApp->primaryScreen(), &QScreen::geometryChanged, this, &MainWindow::resizeWindow); + connect(qGuiApp, &QGuiApplication::primaryScreenChanged, this, &MainWindow::onPrimaryScreenChanged); + connect(screen(), &QScreen::virtualGeometryChanged, this, &MainWindow::resizeWindow); + connect(screen(), &QScreen::geometryChanged, this, &MainWindow::resizeWindow); connect(m_appModel, &ApplicationModel::countChanged, this, &MainWindow::resizeWindow); connect(m_settings, &DockSettings::directionChanged, this, &MainWindow::onPositionChanged); @@ -92,8 +93,8 @@ MainWindow::~MainWindow() QRect MainWindow::windowRect() const { - const QRect screenGeometry = qApp->primaryScreen()->geometry(); - const QRect availableGeometry = qApp->primaryScreen()->availableGeometry(); + const QRect screenGeometry = screen()->geometry(); + const QRect availableGeometry = screen()->availableGeometry(); bool isHorizontal = m_settings->direction() == DockSettings::Bottom; @@ -145,6 +146,30 @@ void MainWindow::resizeWindow() emit resizingFished(); } +void MainWindow::initScreens() +{ + switch (m_settings->direction()) { +// TODO +// case DockSettings::Left: +// setScreen(qGuiApp->screens().first()); +// break; +// case DockSettings::Right: +// setScreen(qGuiApp->screens().last()); +// break; +// case DockSettings::Bottom: +// setScreen(qGuiApp->primaryScreen()); +// break; + default: + setScreen(qGuiApp->primaryScreen()); + break; + } + + if (m_fakeWindow) { + m_fakeWindow->setScreen(screen()); + m_fakeWindow->updateGeometry(); + } +} + void MainWindow::initSlideWindow() { KWindowEffects::SlideFromLocation location = KWindowEffects::NoEdge; @@ -179,6 +204,8 @@ void MainWindow::createFakeWindow() installEventFilter(this); m_fakeWindow = new FakeWindow; + m_fakeWindow->setScreen(screen()); + m_fakeWindow->updateGeometry(); connect(m_fakeWindow, &FakeWindow::containsMouseChanged, this, [=](bool contains) { switch (m_settings->visibility()) { @@ -219,8 +246,17 @@ void MainWindow::deleteFakeWindow() } } +void MainWindow::onPrimaryScreenChanged(QScreen *screen) +{ + initScreens(); + setScreen(screen); + resizeWindow(); +} + void MainWindow::onPositionChanged() { + initScreens(); + if (m_settings->visibility() == DockSettings::AlwaysHide) { setVisible(false); initSlideWindow(); diff --git a/src/mainwindow.h b/src/mainwindow.h index a35a8f5..ac19903 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -45,6 +45,7 @@ signals: private: QRect windowRect() const; void resizeWindow(); + void initScreens(); void initSlideWindow(); void updateViewStruts(); void clearViewStruts(); @@ -53,6 +54,7 @@ private: void deleteFakeWindow(); private slots: + void onPrimaryScreenChanged(QScreen *screen); void onPositionChanged(); void onIconSizeChanged(); void onVisibilityChanged();