close window when click close button

Change-Id: I32d84bac99c900d54c6c120f8889f8fbd7a09940
This commit is contained in:
石博文 2017-05-23 15:32:03 +08:00
parent d7c4656dee
commit 2933cf5233
Notes: Deepin Code Review 2017-05-23 15:37:40 +08:00
Verified+1: Anonymous Coward #1000004
Code-Review+2: 石博文 <sbw@sbw.so>
Submitted-by: 石博文 <sbw@sbw.so>
Submitted-at: Tue, 23 May 2017 15:37:38 +0800
Reviewed-on: https://cr.deepin.io/23352
Project: dde/dde-dock
Branch: refs/heads/master
4 changed files with 35 additions and 0 deletions

View File

@ -24,6 +24,24 @@ AppSnapshot::AppSnapshot(const WId wid, QWidget *parent)
QTimer::singleShot(1, this, &AppSnapshot::fetchSnapshot); QTimer::singleShot(1, this, &AppSnapshot::fetchSnapshot);
} }
void AppSnapshot::closeWindow() const
{
const auto display = QX11Info::display();
XEvent e;
memset(&e, 0, sizeof(e));
e.xclient.type = ClientMessage;
e.xclient.window = m_wid;
e.xclient.message_type = XInternAtom(display, "WM_PROTOCOLS", true);
e.xclient.format = 32;
e.xclient.data.l[0] = XInternAtom(display, "WM_DELETE_WINDOW", false);
e.xclient.data.l[1] = CurrentTime;
XSendEvent(display, m_wid, false, NoEventMask, &e);
XFlush(display);
}
void AppSnapshot::fetchSnapshot() void AppSnapshot::fetchSnapshot()
{ {
if (!isVisible()) if (!isVisible())

View File

@ -12,10 +12,15 @@ class AppSnapshot : public QWidget
public: public:
explicit AppSnapshot(const WId wid, QWidget *parent = 0); explicit AppSnapshot(const WId wid, QWidget *parent = 0);
WId wid() const { return m_wid; }
signals: signals:
void entered(const WId wid) const; void entered(const WId wid) const;
void clicked(const WId wid) const; void clicked(const WId wid) const;
public slots:
void closeWindow() const;
private slots: private slots:
void fetchSnapshot(); void fetchSnapshot();

View File

@ -23,6 +23,8 @@ FloatingPreview::FloatingPreview(QWidget *parent)
setLayout(centralLayout); setLayout(centralLayout);
setFixedSize(SNAP_WIDTH, SNAP_HEIGHT); setFixedSize(SNAP_WIDTH, SNAP_HEIGHT);
connect(m_closeBtn, &DImageButton::clicked, this, &FloatingPreview::onCloseBtnClicked);
} }
void FloatingPreview::trackWindow(AppSnapshot * const snap) void FloatingPreview::trackWindow(AppSnapshot * const snap)
@ -44,3 +46,10 @@ void FloatingPreview::paintEvent(QPaintEvent *e)
painter.fillRect(rect(), Qt::red); painter.fillRect(rect(), Qt::red);
} }
void FloatingPreview::onCloseBtnClicked()
{
Q_ASSERT(!m_tracked.isNull());
m_tracked->closeWindow();
}

View File

@ -25,6 +25,9 @@ public slots:
private: private:
void paintEvent(QPaintEvent *e); void paintEvent(QPaintEvent *e);
private slots:
void onCloseBtnClicked();
private: private:
QPointer<AppSnapshot> m_tracked; QPointer<AppSnapshot> m_tracked;