mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-03 00:15:21 +00:00
close window when click close button
Change-Id: I32d84bac99c900d54c6c120f8889f8fbd7a09940
This commit is contained in:
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
@ -24,6 +24,24 @@ AppSnapshot::AppSnapshot(const WId wid, QWidget *parent)
|
||||
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()
|
||||
{
|
||||
if (!isVisible())
|
||||
|
@ -12,10 +12,15 @@ class AppSnapshot : public QWidget
|
||||
public:
|
||||
explicit AppSnapshot(const WId wid, QWidget *parent = 0);
|
||||
|
||||
WId wid() const { return m_wid; }
|
||||
|
||||
signals:
|
||||
void entered(const WId wid) const;
|
||||
void clicked(const WId wid) const;
|
||||
|
||||
public slots:
|
||||
void closeWindow() const;
|
||||
|
||||
private slots:
|
||||
void fetchSnapshot();
|
||||
|
||||
|
@ -23,6 +23,8 @@ FloatingPreview::FloatingPreview(QWidget *parent)
|
||||
|
||||
setLayout(centralLayout);
|
||||
setFixedSize(SNAP_WIDTH, SNAP_HEIGHT);
|
||||
|
||||
connect(m_closeBtn, &DImageButton::clicked, this, &FloatingPreview::onCloseBtnClicked);
|
||||
}
|
||||
|
||||
void FloatingPreview::trackWindow(AppSnapshot * const snap)
|
||||
@ -44,3 +46,10 @@ void FloatingPreview::paintEvent(QPaintEvent *e)
|
||||
|
||||
painter.fillRect(rect(), Qt::red);
|
||||
}
|
||||
|
||||
void FloatingPreview::onCloseBtnClicked()
|
||||
{
|
||||
Q_ASSERT(!m_tracked.isNull());
|
||||
|
||||
m_tracked->closeWindow();
|
||||
}
|
||||
|
@ -25,6 +25,9 @@ public slots:
|
||||
private:
|
||||
void paintEvent(QPaintEvent *e);
|
||||
|
||||
private slots:
|
||||
void onCloseBtnClicked();
|
||||
|
||||
private:
|
||||
QPointer<AppSnapshot> m_tracked;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user