Using dock margins
This commit is contained in:
parent
3c389e7950
commit
4d22dac737
6 changed files with 88 additions and 28 deletions
|
@ -18,11 +18,37 @@
|
|||
*/
|
||||
|
||||
#include "desktop.h"
|
||||
#include <QQmlContext>
|
||||
#include <QQmlEngine>
|
||||
|
||||
#include <QGuiApplication>
|
||||
#include <QDBusServiceWatcher>
|
||||
|
||||
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();
|
||||
}
|
||||
|
|
|
@ -22,22 +22,39 @@
|
|||
|
||||
#include <QObject>
|
||||
#include <QScreen>
|
||||
#include <QDBusInterface>
|
||||
|
||||
#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<QScreen *, DesktopView *> m_list;
|
||||
QDBusInterface m_dockInterface;
|
||||
|
||||
int m_leftMargin;
|
||||
int m_rightMargin;
|
||||
int m_bottomMargin;
|
||||
};
|
||||
|
||||
#endif // DESKTOP_H
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -23,31 +23,27 @@
|
|||
#include <QQuickView>
|
||||
#include <QScreen>
|
||||
|
||||
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
|
||||
|
|
3
main.cpp
3
main.cpp
|
@ -22,6 +22,7 @@
|
|||
#include <QQmlApplicationEngine>
|
||||
#include <QQmlContext>
|
||||
|
||||
#include <QPixmapCache>
|
||||
#include <QTranslator>
|
||||
#include <QLocale>
|
||||
|
||||
|
@ -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());
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue