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 "desktop.h"
|
||||||
|
#include <QQmlContext>
|
||||||
|
#include <QQmlEngine>
|
||||||
|
|
||||||
#include <QGuiApplication>
|
#include <QGuiApplication>
|
||||||
|
#include <QDBusServiceWatcher>
|
||||||
|
|
||||||
Desktop::Desktop(QObject *parent)
|
Desktop::Desktop(QObject *parent)
|
||||||
: 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()) {
|
for (QScreen *screen : QGuiApplication::screens()) {
|
||||||
screenAdded(screen);
|
screenAdded(screen);
|
||||||
}
|
}
|
||||||
|
@ -31,10 +57,26 @@ Desktop::Desktop(QObject *parent)
|
||||||
connect(qApp, &QGuiApplication::screenRemoved, this, &Desktop::screenRemoved);
|
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)
|
void Desktop::screenAdded(QScreen *screen)
|
||||||
{
|
{
|
||||||
if (!m_list.contains(screen)) {
|
if (!m_list.contains(screen)) {
|
||||||
DesktopView *view = new DesktopView(screen);
|
DesktopView *view = new DesktopView(screen);
|
||||||
|
view->engine()->rootContext()->setContextProperty("Desktop", this);
|
||||||
view->show();
|
view->show();
|
||||||
m_list.insert(screen, view);
|
m_list.insert(screen, view);
|
||||||
}
|
}
|
||||||
|
@ -49,3 +91,23 @@ void Desktop::screenRemoved(QScreen *screen)
|
||||||
m_list.remove(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 <QObject>
|
||||||
#include <QScreen>
|
#include <QScreen>
|
||||||
|
#include <QDBusInterface>
|
||||||
|
|
||||||
#include "desktopview.h"
|
#include "desktopview.h"
|
||||||
|
|
||||||
class Desktop : public QObject
|
class Desktop : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
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:
|
public:
|
||||||
explicit Desktop(QObject *parent = nullptr);
|
explicit Desktop(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
int leftMargin() const;
|
||||||
|
int rightMargin() const;
|
||||||
|
int bottomMargin() const;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void marginsChanged();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void screenAdded(QScreen *qscreen);
|
void screenAdded(QScreen *qscreen);
|
||||||
void screenRemoved(QScreen *qscreen);
|
void screenRemoved(QScreen *qscreen);
|
||||||
|
void updateMargins();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QMap<QScreen *, DesktopView *> m_list;
|
QMap<QScreen *, DesktopView *> m_list;
|
||||||
|
QDBusInterface m_dockInterface;
|
||||||
|
|
||||||
|
int m_leftMargin;
|
||||||
|
int m_rightMargin;
|
||||||
|
int m_bottomMargin;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DESKTOP_H
|
#endif // DESKTOP_H
|
||||||
|
|
|
@ -34,9 +34,6 @@ DesktopView::DesktopView(QScreen *screen, QQuickView *parent)
|
||||||
, m_screen(screen)
|
, m_screen(screen)
|
||||||
{
|
{
|
||||||
m_screenRect = m_screen->geometry();
|
m_screenRect = m_screen->geometry();
|
||||||
m_screenAvailableRect = m_screen->availableVirtualGeometry();
|
|
||||||
|
|
||||||
qDebug() << screen->name() << m_screenAvailableRect;
|
|
||||||
|
|
||||||
KWindowSystem::setType(winId(), NET::Desktop);
|
KWindowSystem::setType(winId(), NET::Desktop);
|
||||||
KWindowSystem::setState(winId(), NET::KeepBelow);
|
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::virtualGeometryChanged, this, &DesktopView::onGeometryChanged);
|
||||||
connect(m_screen, &QScreen::geometryChanged, 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()
|
QRect DesktopView::screenRect()
|
||||||
|
@ -65,11 +60,6 @@ QRect DesktopView::screenRect()
|
||||||
return m_screenRect;
|
return m_screenRect;
|
||||||
}
|
}
|
||||||
|
|
||||||
QRect DesktopView::screenAvailableRect()
|
|
||||||
{
|
|
||||||
return m_screenAvailableRect;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DesktopView::onPrimaryScreenChanged(QScreen *screen)
|
void DesktopView::onPrimaryScreenChanged(QScreen *screen)
|
||||||
{
|
{
|
||||||
bool isPrimaryScreen = m_screen->name() == screen->name();
|
bool isPrimaryScreen = m_screen->name() == screen->name();
|
||||||
|
@ -84,11 +74,3 @@ void DesktopView::onGeometryChanged()
|
||||||
setGeometry(m_screenRect);
|
setGeometry(m_screenRect);
|
||||||
emit screenRectChanged();
|
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 <QQuickView>
|
||||||
#include <QScreen>
|
#include <QScreen>
|
||||||
|
|
||||||
|
class Desktop;
|
||||||
class DesktopView : public QQuickView
|
class DesktopView : public QQuickView
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(QRect screenRect READ screenRect NOTIFY screenRectChanged)
|
Q_PROPERTY(QRect screenRect READ screenRect NOTIFY screenRectChanged)
|
||||||
Q_PROPERTY(QRect screenAvailableRect READ screenAvailableRect NOTIFY screenAvailableGeometryChanged)
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit DesktopView(QScreen *screen = nullptr, QQuickView *parent = nullptr);
|
explicit DesktopView(QScreen *screen = nullptr, QQuickView *parent = nullptr);
|
||||||
|
|
||||||
QRect screenRect();
|
QRect screenRect();
|
||||||
QRect screenAvailableRect();
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void screenRectChanged();
|
void screenRectChanged();
|
||||||
void screenAvailableGeometryChanged();
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onPrimaryScreenChanged(QScreen *screen);
|
void onPrimaryScreenChanged(QScreen *screen);
|
||||||
void onGeometryChanged();
|
void onGeometryChanged();
|
||||||
void onAvailableGeometryChanged(const QRect &geometry);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QScreen *m_screen;
|
QScreen *m_screen;
|
||||||
QRect m_screenRect;
|
QRect m_screenRect;
|
||||||
QRect m_screenAvailableRect;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DESKTOPVIEW_H
|
#endif // DESKTOPVIEW_H
|
||||||
|
|
3
main.cpp
3
main.cpp
|
@ -22,6 +22,7 @@
|
||||||
#include <QQmlApplicationEngine>
|
#include <QQmlApplicationEngine>
|
||||||
#include <QQmlContext>
|
#include <QQmlContext>
|
||||||
|
|
||||||
|
#include <QPixmapCache>
|
||||||
#include <QTranslator>
|
#include <QTranslator>
|
||||||
#include <QLocale>
|
#include <QLocale>
|
||||||
|
|
||||||
|
@ -49,6 +50,8 @@ int main(int argc, char *argv[])
|
||||||
app.setOrganizationName("cutefishos");
|
app.setOrganizationName("cutefishos");
|
||||||
app.setWindowIcon(QIcon::fromTheme("file-manager"));
|
app.setWindowIcon(QIcon::fromTheme("file-manager"));
|
||||||
|
|
||||||
|
QPixmapCache::setCacheLimit(1024 * 10);
|
||||||
|
|
||||||
// Translations
|
// Translations
|
||||||
QLocale locale;
|
QLocale locale;
|
||||||
QString qmFilePath = QString("%1/%2.qm").arg("/usr/share/cutefish-filemanager/translations/").arg(locale.name());
|
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
|
ScrollBar.vertical.policy: ScrollBar.AlwaysOff
|
||||||
|
|
||||||
// Handle for topbar
|
// Handle for topbar
|
||||||
anchors.topMargin: desktopView.screenAvailableRect.y
|
topMargin: 28
|
||||||
|
|
||||||
leftMargin: desktopView.screenAvailableRect.x
|
// From dock
|
||||||
topMargin: 0
|
leftMargin: Desktop.leftMargin
|
||||||
rightMargin: desktopView.screenRect.width - (desktopView.screenAvailableRect.x + desktopView.screenAvailableRect.width)
|
rightMargin: Desktop.rightMargin
|
||||||
bottomMargin: desktopView.screenRect.height - (desktopView.screenAvailableRect.y + desktopView.screenAvailableRect.height)
|
bottomMargin: Desktop.bottomMargin
|
||||||
|
|
||||||
flow: GridView.FlowTopToBottom
|
flow: GridView.FlowTopToBottom
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue