mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 09:23:03 +00:00
using x11 func to move window
Change-Id: Ib04eea28caa4e58fabef5a9d344cb2290ec4bb7c
This commit is contained in:
parent
37509c5f11
commit
2a28205979
Notes:
Deepin Code Review
2017-06-08 15:41:56 +08:00
Verified+1: Anonymous Coward #1000004 Code-Review+2: 石博文 <sbw@sbw.so> Submitted-by: 石博文 <sbw@sbw.so> Submitted-at: Thu, 08 Jun 2017 15:41:54 +0800 Reviewed-on: https://cr.deepin.io/23705 Project: dde/dde-dock Branch: refs/heads/master
@ -7,6 +7,9 @@
|
||||
#include <QGuiApplication>
|
||||
#include <DPlatformWindowHandle>
|
||||
|
||||
#include <X11/X.h>
|
||||
#include <X11/Xutil.h>
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
: QWidget(parent),
|
||||
|
||||
@ -20,7 +23,7 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
m_positionUpdateTimer(new QTimer(this)),
|
||||
m_expandDelayTimer(new QTimer(this)),
|
||||
m_sizeChangeAni(new QPropertyAnimation(this, "size")),
|
||||
m_posChangeAni(new QPropertyAnimation(this, "pos")),
|
||||
m_posChangeAni(new QVariantAnimation(this)),
|
||||
m_panelShowAni(new QPropertyAnimation(m_mainPanel, "pos")),
|
||||
m_panelHideAni(new QPropertyAnimation(m_mainPanel, "pos")),
|
||||
m_xcbMisc(XcbMisc::instance())
|
||||
@ -50,6 +53,8 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
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()
|
||||
@ -64,11 +69,6 @@ QRect MainWindow::panelGeometry()
|
||||
return rect;
|
||||
}
|
||||
|
||||
void MainWindow::moveEvent(QMoveEvent* e)
|
||||
{
|
||||
QWidget::moveEvent(e);
|
||||
}
|
||||
|
||||
void MainWindow::resizeEvent(QResizeEvent *e)
|
||||
{
|
||||
QWidget::resizeEvent(e);
|
||||
@ -129,15 +129,17 @@ void MainWindow::setFixedSize(const QSize &size)
|
||||
void MainWindow::move(int x, int y)
|
||||
{
|
||||
const QPropertyAnimation::State state = m_posChangeAni->state();
|
||||
const QPoint p = x11GetWindowPos();
|
||||
const QPoint tp = QPoint(x, y);
|
||||
|
||||
if (state == QPropertyAnimation::Stopped && this->pos() == QPoint(x, y))
|
||||
if (state == QPropertyAnimation::Stopped && p == tp)
|
||||
return;
|
||||
|
||||
if (state == QPropertyAnimation::Running)
|
||||
if (state == QPropertyAnimation::Running && m_posChangeAni->endValue() != tp)
|
||||
return m_posChangeAni->setEndValue(QPoint(x, y));
|
||||
|
||||
m_posChangeAni->setStartValue(pos());
|
||||
m_posChangeAni->setEndValue(QPoint(x, y));
|
||||
m_posChangeAni->setStartValue(p);
|
||||
m_posChangeAni->setEndValue(tp);
|
||||
m_posChangeAni->start();
|
||||
}
|
||||
|
||||
@ -194,12 +196,43 @@ void MainWindow::initConnections()
|
||||
m_mainPanel->setFixedSize(size);
|
||||
});
|
||||
|
||||
connect(m_posChangeAni, &QPropertyAnimation::finished, [this] {
|
||||
QWidget::move(m_posChangeAni->endValue().toPoint());
|
||||
});
|
||||
// connect(m_posChangeAni, &QPropertyAnimation::finished, [this] {
|
||||
// QWidget::move(m_posChangeAni->endValue().toPoint());
|
||||
// });
|
||||
|
||||
}
|
||||
|
||||
const QPoint MainWindow::x11GetWindowPos()
|
||||
{
|
||||
const auto disp = QX11Info::display();
|
||||
|
||||
unsigned int unused;
|
||||
int x;
|
||||
int y;
|
||||
Window unused_window;
|
||||
|
||||
XGetGeometry(disp, winId(), &unused_window, &x, &y, &unused, &unused, &unused, &unused);
|
||||
XFlush(disp);
|
||||
|
||||
return QPoint(x, y);
|
||||
}
|
||||
|
||||
void MainWindow::x11MoveWindow(const int x, const int y)
|
||||
{
|
||||
const auto disp = QX11Info::display();
|
||||
|
||||
XMoveWindow(disp, winId(), x, y);
|
||||
XFlush(disp);
|
||||
}
|
||||
|
||||
void MainWindow::x11MoveResizeWindow(const int x, const int y, const int w, const int h)
|
||||
{
|
||||
const auto disp = QX11Info::display();
|
||||
|
||||
XMoveResizeWindow(disp, winId(), x, y, w, h);
|
||||
XFlush(disp);
|
||||
}
|
||||
|
||||
void MainWindow::positionChanged(const Position prevPos)
|
||||
{
|
||||
// paly hide animation and disable other animation
|
||||
@ -440,7 +473,8 @@ void MainWindow::resetPanelEnvironment(const bool visible)
|
||||
m_sizeChangeAni->setEndValue(r.size());
|
||||
QWidget::setFixedSize(r.size());
|
||||
m_posChangeAni->setEndValue(r.topLeft());
|
||||
QWidget::move(r.topLeft());
|
||||
// QWidget::move(r.topLeft());
|
||||
x11MoveWindow(r.topLeft().x(), r.topLeft().y());
|
||||
|
||||
m_mainPanel->setFixedSize(r.size());
|
||||
|
||||
@ -480,7 +514,7 @@ void MainWindow::updatePanelVisible()
|
||||
if (!m_settings->autoHide())
|
||||
break;
|
||||
|
||||
QRect r(pos(), size());
|
||||
QRect r(x11GetWindowPos(), size());
|
||||
if (r.contains(QCursor::pos()))
|
||||
break;
|
||||
|
||||
|
@ -25,7 +25,6 @@ public:
|
||||
QRect panelGeometry();
|
||||
|
||||
private:
|
||||
void moveEvent(QMoveEvent *e);
|
||||
void resizeEvent(QResizeEvent *e);
|
||||
void mousePressEvent(QMouseEvent *e);
|
||||
void keyPressEvent(QKeyEvent *e);
|
||||
@ -37,6 +36,10 @@ private:
|
||||
void initComponents();
|
||||
void initConnections();
|
||||
|
||||
const QPoint x11GetWindowPos();
|
||||
void x11MoveWindow(const int x, const int y);
|
||||
void x11MoveResizeWindow(const int x, const int y, const int w, const int h);
|
||||
|
||||
signals:
|
||||
void panelGeometryChanged();
|
||||
|
||||
@ -65,7 +68,7 @@ private:
|
||||
QTimer *m_positionUpdateTimer;
|
||||
QTimer *m_expandDelayTimer;
|
||||
QPropertyAnimation *m_sizeChangeAni;
|
||||
QPropertyAnimation *m_posChangeAni;
|
||||
QVariantAnimation *m_posChangeAni;
|
||||
QPropertyAnimation *m_panelShowAni;
|
||||
QPropertyAnimation *m_panelHideAni;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user