diff --git a/frame/item/components/appsnapshot.cpp b/frame/item/components/appsnapshot.cpp index 21cb14c09..92ccf7e72 100644 --- a/frame/item/components/appsnapshot.cpp +++ b/frame/item/components/appsnapshot.cpp @@ -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()) diff --git a/frame/item/components/appsnapshot.h b/frame/item/components/appsnapshot.h index 700ad6c79..d5164d534 100644 --- a/frame/item/components/appsnapshot.h +++ b/frame/item/components/appsnapshot.h @@ -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(); diff --git a/frame/item/components/floatingpreview.cpp b/frame/item/components/floatingpreview.cpp index 559468fd9..d5902e4a6 100644 --- a/frame/item/components/floatingpreview.cpp +++ b/frame/item/components/floatingpreview.cpp @@ -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(); +} diff --git a/frame/item/components/floatingpreview.h b/frame/item/components/floatingpreview.h index bdd4ae0e7..6e683eb71 100644 --- a/frame/item/components/floatingpreview.h +++ b/frame/item/components/floatingpreview.h @@ -25,6 +25,9 @@ public slots: private: void paintEvent(QPaintEvent *e); +private slots: + void onCloseBtnClicked(); + private: QPointer m_tracked;