mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 09:23:03 +00:00
add dbus interface
Change-Id: I624e5fe2aeec27e622fdc4e68e990c0e2ef79a29
This commit is contained in:
parent
0c597c6597
commit
6e92f5ed4c
Notes:
Deepin Code Review
2016-10-27 10:37:06 +08:00
Code-Review+2: 石博文 <sbw@sbw.so> Verified+1: Anonymous Coward #1000004 Submitted-by: Hualet Wang <mr.asianwang@gmail.com> Submitted-at: Thu, 27 Oct 2016 10:37:06 +0800 Reviewed-on: https://cr.deepin.io/16660 Project: dde/dde-dock Branch: refs/heads/master
34
frame/dbus/dbusdockadaptors.cpp
Normal file
34
frame/dbus/dbusdockadaptors.cpp
Normal file
@ -0,0 +1,34 @@
|
||||
/**
|
||||
* Copyright (C) 2016 Deepin Technology Co., Ltd.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
**/
|
||||
|
||||
#include "dbusdockadaptors.h"
|
||||
#include <QScreen>
|
||||
|
||||
DBusDockAdaptors::DBusDockAdaptors(MainWindow* parent): QDBusAbstractAdaptor(parent)
|
||||
{
|
||||
connect(parent, &MainWindow::panelGeometryChanged, this, [this] {
|
||||
emit DBusDockAdaptors::geometryChanged(geometry());
|
||||
});
|
||||
}
|
||||
|
||||
DBusDockAdaptors::~DBusDockAdaptors()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
MainWindow *DBusDockAdaptors::parent() const
|
||||
{
|
||||
return static_cast<MainWindow *>(QObject::parent());
|
||||
}
|
||||
|
||||
QRect DBusDockAdaptors::geometry() const
|
||||
{
|
||||
return parent()->panelGeometry();
|
||||
}
|
||||
|
47
frame/dbus/dbusdockadaptors.h
Normal file
47
frame/dbus/dbusdockadaptors.h
Normal file
@ -0,0 +1,47 @@
|
||||
/**
|
||||
* Copyright (C) 2016 Deepin Technology Co., Ltd.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
**/
|
||||
|
||||
#ifndef DBUSDOCKADAPTORS_H
|
||||
#define DBUSDOCKADAPTORS_H
|
||||
|
||||
#include <QtDBus/QtDBus>
|
||||
#include "window/mainwindow.h"
|
||||
class MainWindow;
|
||||
/*
|
||||
* Adaptor class for interface com.deepin.dde.Dock
|
||||
*/
|
||||
|
||||
class DBusDockAdaptors: public QDBusAbstractAdaptor
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_CLASSINFO("D-Bus Interface", "com.deepin.dde.Dock")
|
||||
Q_CLASSINFO("D-Bus Introspection", ""
|
||||
" <interface name=\"com.deepin.dde.Dock\">\n"
|
||||
" <property access=\"read\" type=\"(iiii)\" name=\"geometry\"/>\n"
|
||||
" <signal name=\"geometryChanged\">"
|
||||
"<arg name=\"geometry\" type=\"(iiii)\"/>"
|
||||
"</signal>"
|
||||
" </interface>\n"
|
||||
"")
|
||||
|
||||
public:
|
||||
DBusDockAdaptors(MainWindow *parent);
|
||||
virtual ~DBusDockAdaptors();
|
||||
|
||||
MainWindow *parent() const;
|
||||
|
||||
public: // PROPERTIES
|
||||
Q_PROPERTY(QRect geometry READ geometry NOTIFY geometryChanged)
|
||||
QRect geometry() const;
|
||||
|
||||
signals:
|
||||
void geometryChanged(QRect geometry);
|
||||
};
|
||||
|
||||
#endif //DBUSDOCKADAPTORS
|
@ -35,7 +35,8 @@ SOURCES += main.cpp \
|
||||
item/placeholderitem.cpp \
|
||||
controller/dockpluginloader.cpp \
|
||||
item/containeritem.cpp \
|
||||
item/components/containerwidget.cpp
|
||||
item/components/containerwidget.cpp \
|
||||
dbus/dbusdockadaptors.cpp
|
||||
|
||||
HEADERS += \
|
||||
window/mainwindow.h \
|
||||
@ -62,7 +63,8 @@ HEADERS += \
|
||||
item/placeholderitem.h \
|
||||
controller/dockpluginloader.h \
|
||||
item/containeritem.h \
|
||||
item/components/containerwidget.h
|
||||
item/components/containerwidget.h \
|
||||
dbus/dbusdockadaptors.h
|
||||
|
||||
dbus_service.files += com.deepin.dde.dock.service
|
||||
dbus_service.path = /usr/share/dbus-1/services
|
||||
|
@ -7,7 +7,7 @@
|
||||
#include <QDir>
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#include "dbus/dbusdockadaptors.h"
|
||||
DWIDGET_USE_NAMESPACE
|
||||
DUTIL_USE_NAMESPACE
|
||||
|
||||
@ -53,8 +53,10 @@ int main(int argc, char *argv[])
|
||||
ThemeAppIcon::gtkInit();
|
||||
|
||||
MainWindow mw;
|
||||
QDBusConnection::sessionBus().registerService("com.deepin.dde.dock");
|
||||
QDBusConnection::sessionBus().registerObject("/com/deepin/dde/dock", "com.deepin.dde.dock", &mw);
|
||||
DBusDockAdaptors adaptor(&mw);
|
||||
QDBusConnection::sessionBus().registerService("com.deepin.dde.Dock");
|
||||
QDBusConnection::sessionBus().registerObject("/com/deepin/dde/Dock", "com.deepin.dde.Dock", &mw);
|
||||
|
||||
RegisterDdeSession();
|
||||
|
||||
QTimer::singleShot(500, &mw, &MainWindow::show);
|
||||
|
@ -130,7 +130,7 @@ void MainPanel::updateDockDisplayMode(const DisplayMode displayMode)
|
||||
/// \brief MainPanel::displayMode interface for Q_PROPERTY, never use this func.
|
||||
/// \return
|
||||
///
|
||||
int MainPanel::displayMode()
|
||||
int MainPanel::displayMode() const
|
||||
{
|
||||
return int(m_displayMode);
|
||||
}
|
||||
@ -139,11 +139,18 @@ int MainPanel::displayMode()
|
||||
/// \brief MainPanel::position interface for Q_PROPERTY, never use this func.
|
||||
/// \return
|
||||
///
|
||||
int MainPanel::position()
|
||||
int MainPanel::position() const
|
||||
{
|
||||
return int(m_position);
|
||||
}
|
||||
|
||||
void MainPanel::moveEvent(QMoveEvent* e)
|
||||
{
|
||||
QFrame::moveEvent(e);
|
||||
|
||||
emit geometryChanged();
|
||||
}
|
||||
|
||||
void MainPanel::paintEvent(QPaintEvent *e)
|
||||
{
|
||||
QWidget::paintEvent(e);
|
||||
@ -200,6 +207,8 @@ void MainPanel::resizeEvent(QResizeEvent *e)
|
||||
QWidget::resizeEvent(e);
|
||||
|
||||
m_itemAdjustTimer->start();
|
||||
|
||||
emit geometryChanged();
|
||||
}
|
||||
|
||||
void MainPanel::dragEnterEvent(QDragEnterEvent *e)
|
||||
|
@ -24,14 +24,16 @@ public:
|
||||
|
||||
void updateDockPosition(const Position dockPosition);
|
||||
void updateDockDisplayMode(const Dock::DisplayMode displayMode);
|
||||
int displayMode();
|
||||
int position();
|
||||
int displayMode() const;
|
||||
int position() const;
|
||||
|
||||
signals:
|
||||
void requestWindowAutoHide(const bool autoHide) const;
|
||||
void requestRefershWindowVisible() const;
|
||||
void geometryChanged();
|
||||
|
||||
private:
|
||||
void moveEvent(QMoveEvent *e);
|
||||
void paintEvent(QPaintEvent *e);
|
||||
void resizeEvent(QResizeEvent *e);
|
||||
void dragEnterEvent(QDragEnterEvent *e);
|
||||
|
@ -17,6 +17,7 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
m_panelShowAni(new QPropertyAnimation(m_mainPanel, "pos")),
|
||||
m_panelHideAni(new QPropertyAnimation(m_mainPanel, "pos")),
|
||||
m_xcbMisc(XcbMisc::instance())
|
||||
|
||||
{
|
||||
setAccessibleName("dock-mainwindow");
|
||||
setWindowFlags(Qt::FramelessWindowHint | Qt::WindowDoesNotAcceptFocus);
|
||||
@ -31,8 +32,8 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
m_mainPanel->setFixedSize(m_settings->windowSize());
|
||||
|
||||
updatePanelVisible();
|
||||
|
||||
// setStyleSheet("background-color:red;");
|
||||
// setStyleSheet("background-color:red;");
|
||||
connect(m_mainPanel, &MainPanel::geometryChanged, this, &MainWindow::panelGeometryChanged);
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
@ -40,6 +41,18 @@ MainWindow::~MainWindow()
|
||||
delete m_xcbMisc;
|
||||
}
|
||||
|
||||
QRect MainWindow::panelGeometry()
|
||||
{
|
||||
QRect rect = m_mainPanel->geometry();
|
||||
rect.moveTopLeft(m_mainPanel->mapToGlobal(QPoint(0,0)));
|
||||
return rect;
|
||||
}
|
||||
|
||||
void MainWindow::moveEvent(QMoveEvent* e)
|
||||
{
|
||||
QWidget::moveEvent(e);
|
||||
}
|
||||
|
||||
void MainWindow::resizeEvent(QResizeEvent *e)
|
||||
{
|
||||
QWidget::resizeEvent(e);
|
||||
@ -157,9 +170,11 @@ void MainWindow::initConnections()
|
||||
QWidget::setFixedSize(size);
|
||||
m_mainPanel->setFixedSize(size);
|
||||
});
|
||||
|
||||
connect(m_posChangeAni, &QPropertyAnimation::finished, [this] {
|
||||
QWidget::move(m_posChangeAni->endValue().toPoint());
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
void MainWindow::positionChanged(const Position prevPos)
|
||||
@ -225,26 +240,25 @@ void MainWindow::updateGeometry()
|
||||
setFixedSize(size);
|
||||
}
|
||||
|
||||
// const QRect primaryRect = m_settings->primaryRect();
|
||||
// const int offsetX = (primaryRect.width() - size.width()) / 2;
|
||||
// const int offsetY = (primaryRect.height() - size.height()) / 2;
|
||||
// const QRect primaryRect = m_settings->primaryRect();
|
||||
// const int offsetX = (primaryRect.width() - size.width()) / 2;
|
||||
// const int offsetY = (primaryRect.height() - size.height()) / 2;
|
||||
|
||||
// switch (position)
|
||||
// {
|
||||
// case Top:
|
||||
// move(primaryRect.topLeft().x() + offsetX, primaryRect.y()); break;
|
||||
// case Left:
|
||||
// move(primaryRect.topLeft().x(), primaryRect.y() + offsetY); break;
|
||||
// case Right:
|
||||
// move(primaryRect.right() - size.width() + 1, primaryRect.y() + offsetY); break;
|
||||
// case Bottom:
|
||||
// move(primaryRect.x() + offsetX, primaryRect.bottom() - size.height() + 1); break;
|
||||
// default:
|
||||
// Q_ASSERT(false);
|
||||
// }
|
||||
// switch (position)
|
||||
// {
|
||||
// case Top:
|
||||
// move(primaryRect.topLeft().x() + offsetX, primaryRect.y()); break;
|
||||
// case Left:
|
||||
// move(primaryRect.topLeft().x(), primaryRect.y() + offsetY); break;
|
||||
// case Right:
|
||||
// move(primaryRect.right() - size.width() + 1, primaryRect.y() + offsetY); break;
|
||||
// case Bottom:
|
||||
// move(primaryRect.x() + offsetX, primaryRect.bottom() - size.height() + 1); break;
|
||||
// default:
|
||||
// Q_ASSERT(false);
|
||||
// }
|
||||
const QRect windowRect = m_settings->windowRect(position, m_settings->hideState() == Hide);
|
||||
move(windowRect.x(), windowRect.y());
|
||||
|
||||
m_mainPanel->update();
|
||||
}
|
||||
|
||||
@ -301,13 +315,12 @@ void MainWindow::setStrutPartial()
|
||||
default:
|
||||
Q_ASSERT(false);
|
||||
}
|
||||
|
||||
m_xcbMisc->set_strut_partial(winId(), orientation, strut, strutStart, strutEnd);
|
||||
}
|
||||
|
||||
void MainWindow::expand()
|
||||
{
|
||||
// qDebug() << "expand";
|
||||
// qDebug() << "expand";
|
||||
const QPoint finishPos(0, 0);
|
||||
|
||||
if (m_mainPanel->pos() == finishPos && m_mainPanel->size() == this->size())
|
||||
@ -337,8 +350,8 @@ void MainWindow::expand()
|
||||
|
||||
void MainWindow::narrow(const Position prevPos)
|
||||
{
|
||||
// qDebug() << "narrow";
|
||||
// const QSize size = m_settings->windowSize();
|
||||
// qDebug() << "narrow";
|
||||
// const QSize size = m_settings->windowSize();
|
||||
const QSize size = m_mainPanel->size();
|
||||
|
||||
QPoint finishPos(0, 0);
|
||||
@ -399,7 +412,7 @@ void MainWindow::updatePanelVisible()
|
||||
|
||||
const Dock::HideState state = m_settings->hideState();
|
||||
|
||||
// qDebug() << state;
|
||||
// qDebug() << state;
|
||||
|
||||
do
|
||||
{
|
||||
|
@ -7,8 +7,10 @@
|
||||
|
||||
#include <QWidget>
|
||||
#include <QTimer>
|
||||
|
||||
#include <QRect>
|
||||
#include "dbus/dbusdockadaptors.h"
|
||||
class MainPanel;
|
||||
class DBusDockAdaptors;
|
||||
class MainWindow : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -16,8 +18,10 @@ class MainWindow : public QWidget
|
||||
public:
|
||||
explicit MainWindow(QWidget *parent = 0);
|
||||
~MainWindow();
|
||||
QRect panelGeometry();
|
||||
|
||||
private:
|
||||
void moveEvent(QMoveEvent *e);
|
||||
void resizeEvent(QResizeEvent *e);
|
||||
void mousePressEvent(QMouseEvent *e);
|
||||
void keyPressEvent(QKeyEvent *e);
|
||||
@ -29,6 +33,9 @@ private:
|
||||
void initComponents();
|
||||
void initConnections();
|
||||
|
||||
signals:
|
||||
void panelGeometryChanged();
|
||||
|
||||
private slots:
|
||||
void positionChanged(const Position prevPos);
|
||||
void updatePosition();
|
||||
|
Loading…
x
Reference in New Issue
Block a user