diff --git a/desktop/desktop.cpp b/desktop/desktop.cpp index 37757af..4ee39fc 100644 --- a/desktop/desktop.cpp +++ b/desktop/desktop.cpp @@ -18,11 +18,37 @@ */ #include "desktop.h" +#include +#include + #include +#include Desktop::Desktop(QObject *parent) : QObject(parent) + , m_dockInterface("org.cutefish.Dock", + "/Dock", + "org.cutefish.Dock", QDBusConnection::sessionBus()) + , m_leftMargin(0) + , m_rightMargin(0) + , m_bottomMargin(0) { + if (m_dockInterface.isValid()) { + updateMargins(); + connect(&m_dockInterface, SIGNAL(primaryGeometryChanged()), this, SLOT(updateMargins())); + connect(&m_dockInterface, SIGNAL(directionChanged()), this, SLOT(updateMargins())); + } else { + QDBusServiceWatcher *watcher = new QDBusServiceWatcher("org.cutefish.Dock", + QDBusConnection::sessionBus(), + QDBusServiceWatcher::WatchForUnregistration, + this); + connect(watcher, &QDBusServiceWatcher::serviceUnregistered, this, [=] { + updateMargins(); + connect(&m_dockInterface, SIGNAL(primaryGeometryChanged()), this, SLOT(updateMargins())); + connect(&m_dockInterface, SIGNAL(directionChanged()), this, SLOT(updateMargins())); + }); + } + for (QScreen *screen : QGuiApplication::screens()) { screenAdded(screen); } @@ -31,10 +57,26 @@ Desktop::Desktop(QObject *parent) connect(qApp, &QGuiApplication::screenRemoved, this, &Desktop::screenRemoved); } +int Desktop::leftMargin() const +{ + return m_leftMargin; +} + +int Desktop::rightMargin() const +{ + return m_rightMargin; +} + +int Desktop::bottomMargin() const +{ + return m_bottomMargin; +} + void Desktop::screenAdded(QScreen *screen) { if (!m_list.contains(screen)) { DesktopView *view = new DesktopView(screen); + view->engine()->rootContext()->setContextProperty("Desktop", this); view->show(); m_list.insert(screen, view); } @@ -49,3 +91,23 @@ void Desktop::screenRemoved(QScreen *screen) m_list.remove(screen); } } + +void Desktop::updateMargins() +{ + QRect dockGeometry = m_dockInterface.property("primaryGeometry").toRect(); + int dockDirection = m_dockInterface.property("direction").toInt(); + + m_leftMargin = 0; + m_rightMargin = 0; + m_bottomMargin = 0; + + if (dockDirection == 0) { + m_leftMargin = dockGeometry.width(); + } else if (dockDirection == 1) { + m_bottomMargin = dockGeometry.height(); + } else if (dockDirection == 2) { + m_rightMargin = dockGeometry.width(); + } + + emit marginsChanged(); +} diff --git a/desktop/desktop.h b/desktop/desktop.h index f11f371..996fdcf 100644 --- a/desktop/desktop.h +++ b/desktop/desktop.h @@ -22,22 +22,39 @@ #include #include +#include #include "desktopview.h" class Desktop : public QObject { Q_OBJECT + Q_PROPERTY(int leftMargin READ leftMargin NOTIFY marginsChanged) + Q_PROPERTY(int rightMargin READ rightMargin NOTIFY marginsChanged) + Q_PROPERTY(int bottomMargin READ bottomMargin NOTIFY marginsChanged) public: explicit Desktop(QObject *parent = nullptr); + int leftMargin() const; + int rightMargin() const; + int bottomMargin() const; + +signals: + void marginsChanged(); + private slots: void screenAdded(QScreen *qscreen); void screenRemoved(QScreen *qscreen); + void updateMargins(); private: QMap m_list; + QDBusInterface m_dockInterface; + + int m_leftMargin; + int m_rightMargin; + int m_bottomMargin; }; #endif // DESKTOP_H diff --git a/desktop/desktopview.cpp b/desktop/desktopview.cpp index b1d7a90..67b3bd9 100644 --- a/desktop/desktopview.cpp +++ b/desktop/desktopview.cpp @@ -34,9 +34,6 @@ DesktopView::DesktopView(QScreen *screen, QQuickView *parent) , m_screen(screen) { m_screenRect = m_screen->geometry(); - m_screenAvailableRect = m_screen->availableVirtualGeometry(); - - qDebug() << screen->name() << m_screenAvailableRect; KWindowSystem::setType(winId(), NET::Desktop); KWindowSystem::setState(winId(), NET::KeepBelow); @@ -56,8 +53,6 @@ DesktopView::DesktopView(QScreen *screen, QQuickView *parent) connect(m_screen, &QScreen::virtualGeometryChanged, this, &DesktopView::onGeometryChanged); connect(m_screen, &QScreen::geometryChanged, this, &DesktopView::onGeometryChanged); - connect(m_screen, &QScreen::availableGeometryChanged, this, &DesktopView::onAvailableGeometryChanged); - connect(m_screen, &QScreen::virtualGeometryChanged, this, &DesktopView::onAvailableGeometryChanged); } QRect DesktopView::screenRect() @@ -65,11 +60,6 @@ QRect DesktopView::screenRect() return m_screenRect; } -QRect DesktopView::screenAvailableRect() -{ - return m_screenAvailableRect; -} - void DesktopView::onPrimaryScreenChanged(QScreen *screen) { bool isPrimaryScreen = m_screen->name() == screen->name(); @@ -84,11 +74,3 @@ void DesktopView::onGeometryChanged() setGeometry(m_screenRect); emit screenRectChanged(); } - -void DesktopView::onAvailableGeometryChanged(const QRect &geometry) -{ - Q_UNUSED(geometry); - - m_screenAvailableRect = m_screen->availableVirtualGeometry(); - emit screenAvailableGeometryChanged(); -} diff --git a/desktop/desktopview.h b/desktop/desktopview.h index d9cc1a8..6bbc98d 100644 --- a/desktop/desktopview.h +++ b/desktop/desktopview.h @@ -23,31 +23,27 @@ #include #include +class Desktop; class DesktopView : public QQuickView { Q_OBJECT Q_PROPERTY(QRect screenRect READ screenRect NOTIFY screenRectChanged) - Q_PROPERTY(QRect screenAvailableRect READ screenAvailableRect NOTIFY screenAvailableGeometryChanged) public: explicit DesktopView(QScreen *screen = nullptr, QQuickView *parent = nullptr); QRect screenRect(); - QRect screenAvailableRect(); signals: void screenRectChanged(); - void screenAvailableGeometryChanged(); private slots: void onPrimaryScreenChanged(QScreen *screen); void onGeometryChanged(); - void onAvailableGeometryChanged(const QRect &geometry); private: QScreen *m_screen; QRect m_screenRect; - QRect m_screenAvailableRect; }; #endif // DESKTOPVIEW_H diff --git a/main.cpp b/main.cpp index 3af13ac..5d97dea 100644 --- a/main.cpp +++ b/main.cpp @@ -22,6 +22,7 @@ #include #include +#include #include #include @@ -49,6 +50,8 @@ int main(int argc, char *argv[]) app.setOrganizationName("cutefishos"); app.setWindowIcon(QIcon::fromTheme("file-manager")); + QPixmapCache::setCacheLimit(1024 * 10); + // Translations QLocale locale; QString qmFilePath = QString("%1/%2.qm").arg("/usr/share/cutefish-filemanager/translations/").arg(locale.name()); diff --git a/qml/Desktop/Main.qml b/qml/Desktop/Main.qml index efec338..5597e76 100644 --- a/qml/Desktop/Main.qml +++ b/qml/Desktop/Main.qml @@ -73,12 +73,12 @@ Item { ScrollBar.vertical.policy: ScrollBar.AlwaysOff // Handle for topbar - anchors.topMargin: desktopView.screenAvailableRect.y + topMargin: 28 - leftMargin: desktopView.screenAvailableRect.x - topMargin: 0 - rightMargin: desktopView.screenRect.width - (desktopView.screenAvailableRect.x + desktopView.screenAvailableRect.width) - bottomMargin: desktopView.screenRect.height - (desktopView.screenAvailableRect.y + desktopView.screenAvailableRect.height) + // From dock + leftMargin: Desktop.leftMargin + rightMargin: Desktop.rightMargin + bottomMargin: Desktop.bottomMargin flow: GridView.FlowTopToBottom