mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 17:33:05 +00:00
using platform window to set geometry
Change-Id: I3fcf7c9da69fccf31fa9159969bc8ff3052457b0
This commit is contained in:
parent
b82d4ac114
commit
acd2180fa8
Notes:
Deepin Code Review
2017-11-14 11:49:37 +08:00
Verified+1: Anonymous Coward #1000004 Code-Review+2: 石博文 <sbw@sbw.so> Submitted-by: 石博文 <sbw@sbw.so> Submitted-at: Tue, 14 Nov 2017 11:49:37 +0800 Reviewed-on: https://cr.deepin.io/28402 Project: dde/dde-dock Branch: refs/heads/master
@ -108,10 +108,14 @@ public:
|
|||||||
{ return qvariant_cast< QString >(property("Primary")); }
|
{ return qvariant_cast< QString >(property("Primary")); }
|
||||||
|
|
||||||
Q_PROPERTY(DisplayRect PrimaryRect READ primaryRect NOTIFY PrimaryRectChanged)
|
Q_PROPERTY(DisplayRect PrimaryRect READ primaryRect NOTIFY PrimaryRectChanged)
|
||||||
|
inline DisplayRect primaryRawRect() const {
|
||||||
|
return qvariant_cast< DisplayRect >(property("PrimaryRect"));
|
||||||
|
}
|
||||||
inline DisplayRect primaryRect() const
|
inline DisplayRect primaryRect() const
|
||||||
{
|
{
|
||||||
const qreal scale = qApp->devicePixelRatio();
|
const qreal scale = qApp->devicePixelRatio();
|
||||||
DisplayRect dr = qvariant_cast< DisplayRect >(property("PrimaryRect"));
|
|
||||||
|
DisplayRect dr = primaryRawRect();
|
||||||
dr.width = qreal(dr.width) / scale;
|
dr.width = qreal(dr.width) / scale;
|
||||||
dr.height = qreal(dr.height) / scale;
|
dr.height = qreal(dr.height) / scale;
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
include(../interfaces/interfaces.pri)
|
include(../interfaces/interfaces.pri)
|
||||||
|
|
||||||
QT += core gui widgets dbus x11extras svg
|
QT += core gui gui-private widgets dbus x11extras svg
|
||||||
|
|
||||||
TARGET = dde-dock
|
TARGET = dde-dock
|
||||||
DESTDIR = $$_PRO_FILE_PWD_/../
|
DESTDIR = $$_PRO_FILE_PWD_/../
|
||||||
|
@ -58,6 +58,7 @@ DockSettings::DockSettings(QWidget *parent)
|
|||||||
m_itemController(DockItemController::instance(this))
|
m_itemController(DockItemController::instance(this))
|
||||||
{
|
{
|
||||||
m_primaryRect = m_displayInter->primaryRect();
|
m_primaryRect = m_displayInter->primaryRect();
|
||||||
|
m_primaryRawRect = m_displayInter->primaryRawRect();
|
||||||
m_position = Dock::Position(m_dockInter->position());
|
m_position = Dock::Position(m_dockInter->position());
|
||||||
m_displayMode = Dock::DisplayMode(m_dockInter->displayMode());
|
m_displayMode = Dock::DisplayMode(m_dockInter->displayMode());
|
||||||
m_hideMode = Dock::HideMode(m_dockInter->hideMode());
|
m_hideMode = Dock::HideMode(m_dockInter->hideMode());
|
||||||
@ -208,9 +209,9 @@ const QRect DockSettings::windowRect(const Position position, const bool hide) c
|
|||||||
switch (position)
|
switch (position)
|
||||||
{
|
{
|
||||||
case Top:
|
case Top:
|
||||||
case Bottom: size.setHeight(1); break;
|
case Bottom: size.setHeight(2); break;
|
||||||
case Left:
|
case Left:
|
||||||
case Right: size.setWidth(1); break;
|
case Right: size.setWidth(2); break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -413,6 +414,7 @@ void DockSettings::primaryScreenChanged()
|
|||||||
{
|
{
|
||||||
// qDebug() << Q_FUNC_INFO;
|
// qDebug() << Q_FUNC_INFO;
|
||||||
m_primaryRect = m_displayInter->primaryRect();
|
m_primaryRect = m_displayInter->primaryRect();
|
||||||
|
m_primaryRawRect = m_displayInter->primaryRawRect();
|
||||||
|
|
||||||
calculateWindowConfig();
|
calculateWindowConfig();
|
||||||
|
|
||||||
|
@ -70,6 +70,7 @@ public:
|
|||||||
|
|
||||||
bool autoHide() const;
|
bool autoHide() const;
|
||||||
const QRect primaryRect() const;
|
const QRect primaryRect() const;
|
||||||
|
const QRect primaryRawRect() const { return m_primaryRawRect; }
|
||||||
const QSize windowSize() const;
|
const QSize windowSize() const;
|
||||||
const QRect windowRect(const Position position, const bool hide = false) const;
|
const QRect windowRect(const Position position, const bool hide = false) const;
|
||||||
|
|
||||||
@ -110,6 +111,7 @@ private:
|
|||||||
HideState m_hideState;
|
HideState m_hideState;
|
||||||
DisplayMode m_displayMode;
|
DisplayMode m_displayMode;
|
||||||
QRect m_primaryRect;
|
QRect m_primaryRect;
|
||||||
|
QRect m_primaryRawRect;
|
||||||
QSize m_mainWindowSize;
|
QSize m_mainWindowSize;
|
||||||
|
|
||||||
WhiteMenu m_settingsMenu;
|
WhiteMenu m_settingsMenu;
|
||||||
|
@ -26,6 +26,8 @@
|
|||||||
#include <QResizeEvent>
|
#include <QResizeEvent>
|
||||||
#include <QScreen>
|
#include <QScreen>
|
||||||
#include <QGuiApplication>
|
#include <QGuiApplication>
|
||||||
|
#include <qpa/qplatformwindow.h>
|
||||||
|
|
||||||
#include <DPlatformWindowHandle>
|
#include <DPlatformWindowHandle>
|
||||||
|
|
||||||
#include <X11/X.h>
|
#include <X11/X.h>
|
||||||
@ -44,7 +46,7 @@ MainWindow::MainWindow(QWidget *parent)
|
|||||||
m_positionUpdateTimer(new QTimer(this)),
|
m_positionUpdateTimer(new QTimer(this)),
|
||||||
m_expandDelayTimer(new QTimer(this)),
|
m_expandDelayTimer(new QTimer(this)),
|
||||||
m_sizeChangeAni(new QVariantAnimation(this)),
|
m_sizeChangeAni(new QVariantAnimation(this)),
|
||||||
m_posChangeAni(new QPropertyAnimation(this, "pos")),
|
m_posChangeAni(new QVariantAnimation(this)),
|
||||||
m_panelShowAni(new QPropertyAnimation(m_mainPanel, "pos")),
|
m_panelShowAni(new QPropertyAnimation(m_mainPanel, "pos")),
|
||||||
m_panelHideAni(new QPropertyAnimation(m_mainPanel, "pos")),
|
m_panelHideAni(new QPropertyAnimation(m_mainPanel, "pos")),
|
||||||
m_xcbMisc(XcbMisc::instance())
|
m_xcbMisc(XcbMisc::instance())
|
||||||
@ -70,13 +72,6 @@ MainWindow::MainWindow(QWidget *parent)
|
|||||||
m_mainPanel->setFixedSize(m_settings->windowSize());
|
m_mainPanel->setFixedSize(m_settings->windowSize());
|
||||||
|
|
||||||
updatePanelVisible();
|
updatePanelVisible();
|
||||||
connect(m_wmHelper, &DWindowManagerHelper::hasCompositeChanged, this, &MainWindow::compositeChanged, Qt::QueuedConnection);
|
|
||||||
connect(m_mainPanel, &MainPanel::geometryChanged, this, &MainWindow::panelGeometryChanged);
|
|
||||||
connect(&m_platformWindowHandle, &DPlatformWindowHandle::frameMarginsChanged, this, &MainWindow::adjustShadowMask);
|
|
||||||
connect(m_panelHideAni, &QPropertyAnimation::finished, this, &MainWindow::adjustShadowMask);
|
|
||||||
connect(m_panelShowAni, &QPropertyAnimation::finished, this, &MainWindow::adjustShadowMask);
|
|
||||||
// connect(m_posChangeAni, &QPropertyAnimation::valueChanged,
|
|
||||||
// this, [=](const QVariant &v) { const QPoint p = v.toPoint(); x11MoveWindow(p.x(), p.y()); });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
@ -153,14 +148,14 @@ void MainWindow::setFixedSize(const QSize &size)
|
|||||||
return m_sizeChangeAni->setEndValue(size);
|
return m_sizeChangeAni->setEndValue(size);
|
||||||
|
|
||||||
|
|
||||||
// qDebug() << Q_FUNC_INFO << size;
|
qDebug() << Q_FUNC_INFO << size;
|
||||||
|
|
||||||
m_sizeChangeAni->setStartValue(this->size());
|
m_sizeChangeAni->setStartValue(this->size());
|
||||||
m_sizeChangeAni->setEndValue(size);
|
m_sizeChangeAni->setEndValue(size);
|
||||||
m_sizeChangeAni->start();
|
m_sizeChangeAni->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::internalMove(int x, int y)
|
void MainWindow::internalAnimationMove(int x, int y)
|
||||||
{
|
{
|
||||||
const QPropertyAnimation::State state = m_posChangeAni->state();
|
const QPropertyAnimation::State state = m_posChangeAni->state();
|
||||||
const QPoint p = m_posChangeAni->endValue().toPoint();
|
const QPoint p = m_posChangeAni->endValue().toPoint();
|
||||||
@ -169,8 +164,8 @@ void MainWindow::internalMove(int x, int y)
|
|||||||
if (state == QPropertyAnimation::Stopped && p == tp)
|
if (state == QPropertyAnimation::Stopped && p == tp)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// if (state == QPropertyAnimation::Running && m_posChangeAni->endValue() != tp)
|
if (state == QPropertyAnimation::Running && m_posChangeAni->endValue() != tp)
|
||||||
// return m_posChangeAni->setEndValue(QPoint(x, y));
|
return m_posChangeAni->setEndValue(QPoint(x, y));
|
||||||
|
|
||||||
m_posChangeAni->setStartValue(pos());
|
m_posChangeAni->setStartValue(pos());
|
||||||
m_posChangeAni->setEndValue(tp);
|
m_posChangeAni->setEndValue(tp);
|
||||||
@ -208,6 +203,30 @@ void MainWindow::compositeChanged()
|
|||||||
m_positionUpdateTimer->start();
|
m_positionUpdateTimer->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::interalMove(const QPoint &p)
|
||||||
|
{
|
||||||
|
const auto ratio = devicePixelRatioF();
|
||||||
|
QPoint rp = p * ratio;
|
||||||
|
|
||||||
|
if (m_settings->hideMode() != HideMode::KeepShowing &&
|
||||||
|
m_settings->hideState() == HideState::Hide &&
|
||||||
|
m_posChangeAni->state() == QVariantAnimation::Stopped)
|
||||||
|
{
|
||||||
|
const QRect &r = m_settings->primaryRawRect();
|
||||||
|
rp.setY(r.bottom());
|
||||||
|
}
|
||||||
|
|
||||||
|
int h;
|
||||||
|
if (m_settings->hideMode() != HideMode::KeepShowing &&
|
||||||
|
m_settings->hideState() == HideState::Hide &&
|
||||||
|
m_panelHideAni->state() == QVariantAnimation::Stopped)
|
||||||
|
h = 2;
|
||||||
|
else
|
||||||
|
h = height() * ratio;
|
||||||
|
|
||||||
|
windowHandle()->handle()->setGeometry(QRect(rp.x(), rp.y(), width() * ratio, h));
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::initConnections()
|
void MainWindow::initConnections()
|
||||||
{
|
{
|
||||||
connect(m_settings, &DockSettings::dataChanged, m_positionUpdateTimer, static_cast<void (QTimer::*)()>(&QTimer::start));
|
connect(m_settings, &DockSettings::dataChanged, m_positionUpdateTimer, static_cast<void (QTimer::*)()>(&QTimer::start));
|
||||||
@ -220,11 +239,15 @@ void MainWindow::initConnections()
|
|||||||
|
|
||||||
connect(m_mainPanel, &MainPanel::requestRefershWindowVisible, this, &MainWindow::updatePanelVisible, Qt::QueuedConnection);
|
connect(m_mainPanel, &MainPanel::requestRefershWindowVisible, this, &MainWindow::updatePanelVisible, Qt::QueuedConnection);
|
||||||
connect(m_mainPanel, &MainPanel::requestWindowAutoHide, m_settings, &DockSettings::setAutoHide);
|
connect(m_mainPanel, &MainPanel::requestWindowAutoHide, m_settings, &DockSettings::setAutoHide);
|
||||||
|
connect(m_mainPanel, &MainPanel::geometryChanged, this, &MainWindow::panelGeometryChanged);
|
||||||
|
|
||||||
connect(m_positionUpdateTimer, &QTimer::timeout, this, &MainWindow::updatePosition, Qt::QueuedConnection);
|
connect(m_positionUpdateTimer, &QTimer::timeout, this, &MainWindow::updatePosition, Qt::QueuedConnection);
|
||||||
connect(m_expandDelayTimer, &QTimer::timeout, this, &MainWindow::expand, Qt::QueuedConnection);
|
connect(m_expandDelayTimer, &QTimer::timeout, this, &MainWindow::expand, Qt::QueuedConnection);
|
||||||
|
|
||||||
connect(m_panelHideAni, &QPropertyAnimation::finished, this, &MainWindow::updateGeometry, Qt::QueuedConnection);
|
connect(m_panelHideAni, &QPropertyAnimation::finished, this, &MainWindow::updateGeometry, Qt::QueuedConnection);
|
||||||
|
connect(m_panelHideAni, &QPropertyAnimation::finished, this, &MainWindow::adjustShadowMask);
|
||||||
|
connect(m_panelShowAni, &QPropertyAnimation::finished, this, &MainWindow::adjustShadowMask);
|
||||||
|
connect(m_posChangeAni, &QVariantAnimation::valueChanged, this, static_cast<void (MainWindow::*)()>(&MainWindow::interalMove));
|
||||||
|
|
||||||
// // to fix qt animation bug, sometimes window size not change
|
// // to fix qt animation bug, sometimes window size not change
|
||||||
connect(m_sizeChangeAni, &QPropertyAnimation::valueChanged, [this] {
|
connect(m_sizeChangeAni, &QPropertyAnimation::valueChanged, [this] {
|
||||||
@ -234,10 +257,8 @@ void MainWindow::initConnections()
|
|||||||
m_mainPanel->setFixedSize(size);
|
m_mainPanel->setFixedSize(size);
|
||||||
});
|
});
|
||||||
|
|
||||||
// connect(m_posChangeAni, &QPropertyAnimation::finished, [this] {
|
connect(m_wmHelper, &DWindowManagerHelper::hasCompositeChanged, this, &MainWindow::compositeChanged, Qt::QueuedConnection);
|
||||||
// QWidget::move(m_posChangeAni->endValue().toPoint());
|
connect(&m_platformWindowHandle, &DPlatformWindowHandle::frameMarginsChanged, this, &MainWindow::adjustShadowMask);
|
||||||
// });
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const QPoint MainWindow::x11GetWindowPos()
|
const QPoint MainWindow::x11GetWindowPos()
|
||||||
@ -322,6 +343,8 @@ void MainWindow::updateGeometry()
|
|||||||
m_mainPanel->updateDockPosition(position);
|
m_mainPanel->updateDockPosition(position);
|
||||||
m_mainPanel->updateDockDisplayMode(m_settings->displayMode());
|
m_mainPanel->updateDockDisplayMode(m_settings->displayMode());
|
||||||
|
|
||||||
|
bool animation = true;
|
||||||
|
|
||||||
if (m_settings->hideState() == Hide)
|
if (m_settings->hideState() == Hide)
|
||||||
{
|
{
|
||||||
m_sizeChangeAni->stop();
|
m_sizeChangeAni->stop();
|
||||||
@ -329,10 +352,12 @@ void MainWindow::updateGeometry()
|
|||||||
switch (position)
|
switch (position)
|
||||||
{
|
{
|
||||||
case Top:
|
case Top:
|
||||||
case Bottom: size.setHeight(1); break;
|
case Bottom: size.setHeight(2); break;
|
||||||
case Left:
|
case Left:
|
||||||
case Right: size.setWidth(1); break;
|
case Right: size.setWidth(2); break;
|
||||||
}
|
}
|
||||||
|
animation = false;
|
||||||
|
m_sizeChangeAni->setEndValue(size);
|
||||||
QWidget::setFixedSize(size);
|
QWidget::setFixedSize(size);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -340,25 +365,12 @@ void MainWindow::updateGeometry()
|
|||||||
setFixedSize(size);
|
setFixedSize(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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);
|
|
||||||
// }
|
|
||||||
const QRect windowRect = m_settings->windowRect(position, m_settings->hideState() == Hide);
|
const QRect windowRect = m_settings->windowRect(position, m_settings->hideState() == Hide);
|
||||||
internalMove(windowRect.x(), windowRect.y());
|
if (animation)
|
||||||
|
internalAnimationMove(windowRect.x(), windowRect.y());
|
||||||
|
else
|
||||||
|
interalMove(windowRect.topLeft());
|
||||||
|
|
||||||
m_mainPanel->update();
|
m_mainPanel->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -470,21 +482,21 @@ void MainWindow::expand()
|
|||||||
|
|
||||||
resetPanelEnvironment(true);
|
resetPanelEnvironment(true);
|
||||||
|
|
||||||
if (m_panelShowAni->state() == QPropertyAnimation::Running)
|
if (m_panelShowAni->state() != QPropertyAnimation::Running)
|
||||||
return m_panelShowAni->setEndValue(finishPos);
|
|
||||||
|
|
||||||
const QSize size = m_settings->windowSize();
|
|
||||||
|
|
||||||
QPoint startPos(0, 0);
|
|
||||||
switch (m_settings->position())
|
|
||||||
{
|
{
|
||||||
case Top: startPos.setY(-size.height()); break;
|
QPoint startPos(0, 0);
|
||||||
case Bottom: startPos.setY(size.height()); break;
|
const QSize &size = m_settings->windowSize();
|
||||||
case Left: startPos.setX(-size.width()); break;
|
switch (m_settings->position())
|
||||||
case Right: startPos.setX(size.width()); break;
|
{
|
||||||
|
case Top: startPos.setY(-size.height()); break;
|
||||||
|
case Bottom: startPos.setY(size.height()); break;
|
||||||
|
case Left: startPos.setX(-size.width()); break;
|
||||||
|
case Right: startPos.setX(size.width()); break;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_panelShowAni->setStartValue(startPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_panelShowAni->setStartValue(startPos);
|
|
||||||
m_panelShowAni->setEndValue(finishPos);
|
m_panelShowAni->setEndValue(finishPos);
|
||||||
m_panelShowAni->start();
|
m_panelShowAni->start();
|
||||||
}
|
}
|
||||||
@ -504,9 +516,6 @@ void MainWindow::narrow(const Position prevPos)
|
|||||||
case Right: finishPos.setX(size.width()); break;
|
case Right: finishPos.setX(size.width()); break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_panelHideAni->state() == QPropertyAnimation::Running)
|
|
||||||
return m_panelHideAni->setEndValue(finishPos);
|
|
||||||
|
|
||||||
m_panelShowAni->stop();
|
m_panelShowAni->stop();
|
||||||
m_panelHideAni->setStartValue(m_mainPanel->pos());
|
m_panelHideAni->setStartValue(m_mainPanel->pos());
|
||||||
m_panelHideAni->setEndValue(finishPos);
|
m_panelHideAni->setEndValue(finishPos);
|
||||||
@ -530,7 +539,6 @@ void MainWindow::resetPanelEnvironment(const bool visible)
|
|||||||
QWidget::setFixedSize(r.size());
|
QWidget::setFixedSize(r.size());
|
||||||
m_posChangeAni->setEndValue(r.topLeft());
|
m_posChangeAni->setEndValue(r.topLeft());
|
||||||
QWidget::move(r.topLeft());
|
QWidget::move(r.topLeft());
|
||||||
// x11MoveWindow(r.topLeft().x(), r.topLeft().y());
|
|
||||||
|
|
||||||
QPoint finishPos(0, 0);
|
QPoint finishPos(0, 0);
|
||||||
if (!visible)
|
if (!visible)
|
||||||
|
@ -54,7 +54,7 @@ private:
|
|||||||
void dragEnterEvent(QDragEnterEvent *e);
|
void dragEnterEvent(QDragEnterEvent *e);
|
||||||
|
|
||||||
void setFixedSize(const QSize &size);
|
void setFixedSize(const QSize &size);
|
||||||
void internalMove(int x, int y);
|
void internalAnimationMove(int x, int y);
|
||||||
void initComponents();
|
void initComponents();
|
||||||
void initConnections();
|
void initConnections();
|
||||||
|
|
||||||
@ -72,6 +72,8 @@ private slots:
|
|||||||
void clearStrutPartial();
|
void clearStrutPartial();
|
||||||
void setStrutPartial();
|
void setStrutPartial();
|
||||||
void compositeChanged();
|
void compositeChanged();
|
||||||
|
void interalMove() { interalMove(m_posChangeAni->currentValue().toPoint()); }
|
||||||
|
void interalMove(const QPoint &p);
|
||||||
|
|
||||||
void expand();
|
void expand();
|
||||||
void narrow(const Position prevPos);
|
void narrow(const Position prevPos);
|
||||||
@ -90,7 +92,7 @@ private:
|
|||||||
QTimer *m_positionUpdateTimer;
|
QTimer *m_positionUpdateTimer;
|
||||||
QTimer *m_expandDelayTimer;
|
QTimer *m_expandDelayTimer;
|
||||||
QVariantAnimation *m_sizeChangeAni;
|
QVariantAnimation *m_sizeChangeAni;
|
||||||
QPropertyAnimation *m_posChangeAni;
|
QVariantAnimation *m_posChangeAni;
|
||||||
QPropertyAnimation *m_panelShowAni;
|
QPropertyAnimation *m_panelShowAni;
|
||||||
QPropertyAnimation *m_panelHideAni;
|
QPropertyAnimation *m_panelHideAni;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user