From b7dc7ec898b68175fbd15efd3c89cb473da849ac Mon Sep 17 00:00:00 2001 From: reionwong Date: Mon, 16 Aug 2021 08:58:33 +0800 Subject: [PATCH] Adaptation has no compositing effect --- qml/main.qml | 9 +++++++-- src/mainwindow.cpp | 28 ++++++++++++++++++++++++---- src/mainwindow.h | 2 ++ src/xwindowinterface.cpp | 10 ++++++---- src/xwindowinterface.h | 2 +- 5 files changed, 40 insertions(+), 11 deletions(-) diff --git a/qml/main.qml b/qml/main.qml index b58b5a9..e75eb54 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -31,6 +31,11 @@ Item { property bool isHorizontal: Settings.direction === DockSettings.Bottom property real windowRadius: isHorizontal ? root.height * 0.3 : root.width * 0.3 + property bool compositing: windowHelper.compositing + + onCompositingChanged: { + mainWindow.updateSize() + } DropArea { anchors.fill: parent @@ -41,9 +46,9 @@ Item { Rectangle { id: _background anchors.fill: parent - radius: windowHelper.compositing ? windowRadius : 0 + radius: root.compositing ? windowRadius : 0 color: FishUI.Theme.darkMode ? "#595959" : "#FFFFFF" - opacity: windowHelper.compositing ? FishUI.Theme.darkMode ? 0.5 : 0.4 : 1 + opacity: root.compositing ? FishUI.Theme.darkMode ? 0.5 : 0.4 : 0.9 border.width: 0 Behavior on color { diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 7b738e8..953513a 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -91,12 +91,23 @@ MainWindow::~MainWindow() { } +void MainWindow::updateSize() +{ + resizeWindow(); +} + QRect MainWindow::windowRect() const { const QRect screenGeometry = screen()->geometry(); const QRect availableGeometry = screen()->availableGeometry(); bool isHorizontal = m_settings->direction() == DockSettings::Bottom; + bool compositing = false; + QQuickItem *item = qobject_cast(rootObject()); + + if (item) { + compositing = item->property("compositing").toBool(); + } QSize newSize(0, 0); QPoint position(0, 0); @@ -114,21 +125,23 @@ QRect MainWindow::windowRect() const length = appCount * iconSize; } + int margins = compositing ? DockSettings::self()->edgeMargins() / 2 : 0; + switch (m_settings->direction()) { case DockSettings::Left: newSize = QSize(iconSize, length); - position.setX(screenGeometry.x() + DockSettings::self()->edgeMargins() / 2); + position.setX(screenGeometry.x() + margins); // Handle the top statusbar. position.setY(availableGeometry.y() + (availableGeometry.height() - newSize.height()) / 2); break; case DockSettings::Bottom: newSize = QSize(length, iconSize); position.setX(screenGeometry.x() + (screenGeometry.width() - newSize.width()) / 2); - position.setY(screenGeometry.y() + screenGeometry.height() - newSize.height() - DockSettings::self()->edgeMargins() / 2); + position.setY(screenGeometry.y() + screenGeometry.height() - newSize.height() - margins); break; case DockSettings::Right: newSize = QSize(iconSize, length); - position.setX(screenGeometry.x() + screenGeometry.width() - newSize.width() - DockSettings::self()->edgeMargins() / 2); + position.setX(screenGeometry.x() + screenGeometry.width() - newSize.width() - margins); position.setY(availableGeometry.y() + (availableGeometry.height() - newSize.height()) / 2); break; default: @@ -186,8 +199,15 @@ void MainWindow::initSlideWindow() void MainWindow::updateViewStruts() { + bool compositing = false; + QQuickItem *item = qobject_cast(rootObject()); + + if (item) { + compositing = item->property("compositing").toBool(); + } + if (m_settings->visibility() == DockSettings::AlwaysShow || m_activity->launchPad()) { - XWindowInterface::instance()->setViewStruts(this, m_settings->direction(), geometry()); + XWindowInterface::instance()->setViewStruts(this, m_settings->direction(), geometry(), compositing); } else { clearViewStruts(); } diff --git a/src/mainwindow.h b/src/mainwindow.h index ac19903..d3af43d 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -37,6 +37,8 @@ public: explicit MainWindow(QQuickView *parent = nullptr); ~MainWindow(); + Q_INVOKABLE void updateSize(); + signals: void resizingFished(); void iconSizeChanged(); diff --git a/src/xwindowinterface.cpp b/src/xwindowinterface.cpp index 8b2bdbf..0b5e962 100644 --- a/src/xwindowinterface.cpp +++ b/src/xwindowinterface.cpp @@ -143,7 +143,7 @@ bool XWindowInterface::isAcceptableWindow(quint64 wid) return !NET::typeMatchesMask(info.windowType(NET::AllTypesMask), normalFlag); } -void XWindowInterface::setViewStruts(QWindow *view, DockSettings::Direction direction, const QRect &rect) +void XWindowInterface::setViewStruts(QWindow *view, DockSettings::Direction direction, const QRect &rect, bool compositing) { NETExtendedStrut strut; @@ -151,25 +151,27 @@ void XWindowInterface::setViewStruts(QWindow *view, DockSettings::Direction dire const QRect currentScreen {screen->geometry()}; const QRect wholeScreen { {0, 0}, screen->virtualSize() }; +// const int edgeMargins = compositing ? DockSettings::self()->edgeMargins() : 0; + int edgeMargins = 0; switch (direction) { case DockSettings::Left: { const int leftOffset = { screen->geometry().left() }; - strut.left_width = rect.width() + leftOffset + DockSettings::self()->edgeMargins(); + strut.left_width = rect.width() + leftOffset + edgeMargins; strut.left_start = rect.y(); strut.left_end = rect.y() + rect.height() - 1; break; } case DockSettings::Bottom: { const int bottomOffset { wholeScreen.bottom() - currentScreen.bottom() }; - strut.bottom_width = rect.height() + bottomOffset + DockSettings::self()->edgeMargins(); + strut.bottom_width = rect.height() + bottomOffset + edgeMargins; strut.bottom_start = rect.x(); strut.bottom_end = rect.x() + rect.width(); break; } case DockSettings::Right: { const int rightOffset = {wholeScreen.right() - currentScreen.right()}; - strut.right_width = rect.width() + rightOffset + DockSettings::self()->edgeMargins(); + strut.right_width = rect.width() + rightOffset + edgeMargins; strut.right_start = rect.y(); strut.right_end = rect.y() + rect.height() - 1; break; diff --git a/src/xwindowinterface.h b/src/xwindowinterface.h index be3110f..e551837 100644 --- a/src/xwindowinterface.h +++ b/src/xwindowinterface.h @@ -47,7 +47,7 @@ public: QString requestWindowClass(quint64 wid); bool isAcceptableWindow(quint64 wid); - void setViewStruts(QWindow *view, DockSettings::Direction direction, const QRect &rect); + void setViewStruts(QWindow *view, DockSettings::Direction direction, const QRect &rect, bool compositing = false); void clearViewStruts(QWindow *view); void startInitWindows();