From 32d87ca112a2b048bb294339a970a83006e0ab61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9F=B3=E5=8D=9A=E6=96=87?= Date: Wed, 24 May 2017 11:32:14 +0800 Subject: [PATCH] optimize snapshots fetch Change-Id: I56d2f74fdf0564dbfa973471dda979d794079a80 --- frame/item/appitem.cpp | 1 + frame/item/components/_previewcontainer.cpp | 6 ++++++ frame/item/components/_previewcontainer.h | 1 + frame/item/components/appsnapshot.cpp | 21 ++------------------- frame/item/components/appsnapshot.h | 7 +------ 5 files changed, 11 insertions(+), 25 deletions(-) diff --git a/frame/item/appitem.cpp b/frame/item/appitem.cpp index 98c8d7f2d..bd09d4d52 100644 --- a/frame/item/appitem.cpp +++ b/frame/item/appitem.cpp @@ -505,6 +505,7 @@ void AppItem::showPreview() // } m_appPreviewTips->setWindowInfos(m_titles); + m_appPreviewTips->updateSnapshots(); m_appPreviewTips->updateLayoutDirection(DockPosition); showPopupWindow(m_appPreviewTips, true); diff --git a/frame/item/components/_previewcontainer.cpp b/frame/item/components/_previewcontainer.cpp index ab1a5cf21..0b90f779e 100644 --- a/frame/item/components/_previewcontainer.cpp +++ b/frame/item/components/_previewcontainer.cpp @@ -61,6 +61,12 @@ void _PreviewContainer::setWindowInfos(const WindowDict &infos) } } +void _PreviewContainer::updateSnapshots() +{ + for (AppSnapshot *snap : m_snapshots) + snap->fetchSnapshot(); +} + void _PreviewContainer::updateLayoutDirection(const Dock::Position dockPos) { if (m_wmHelper->hasComposite() && (dockPos == Dock::Top || dockPos == Dock::Bottom)) diff --git a/frame/item/components/_previewcontainer.h b/frame/item/components/_previewcontainer.h index 5186ad4fb..c35a0297c 100644 --- a/frame/item/components/_previewcontainer.h +++ b/frame/item/components/_previewcontainer.h @@ -32,6 +32,7 @@ signals: public: void setWindowInfos(const WindowDict &infos); + void updateSnapshots(); public slots: void updateLayoutDirection(const Dock::Position dockPos); diff --git a/frame/item/components/appsnapshot.cpp b/frame/item/components/appsnapshot.cpp index 0ccc5d38c..b76e16099 100644 --- a/frame/item/components/appsnapshot.cpp +++ b/frame/item/components/appsnapshot.cpp @@ -12,16 +12,9 @@ AppSnapshot::AppSnapshot(const WId wid, QWidget *parent) : QWidget(parent), - m_wid(wid), - - m_fetchSnapshotTimer(new QTimer(this)) + m_wid(wid) { - m_fetchSnapshotTimer->setSingleShot(true); - m_fetchSnapshotTimer->setInterval(10); - - connect(m_fetchSnapshotTimer, &QTimer::timeout, this, &AppSnapshot::fetchSnapshot, Qt::QueuedConnection); - - QTimer::singleShot(1, this, &AppSnapshot::fetchSnapshot); +// QTimer::singleShot(1, this, &AppSnapshot::fetchSnapshot); } void AppSnapshot::closeWindow() const @@ -49,9 +42,6 @@ void AppSnapshot::setWindowTitle(const QString &title) void AppSnapshot::fetchSnapshot() { - if (!isVisible()) - return; - const auto display = QX11Info::display(); XWindowAttributes attrs; @@ -115,13 +105,6 @@ void AppSnapshot::paintEvent(QPaintEvent *e) painter.drawImage(offset.x(), offset.y(), im); } -void AppSnapshot::resizeEvent(QResizeEvent *e) -{ - QWidget::resizeEvent(e); - - m_fetchSnapshotTimer->start(); -} - void AppSnapshot::mousePressEvent(QMouseEvent *e) { QWidget::mousePressEvent(e); diff --git a/frame/item/components/appsnapshot.h b/frame/item/components/appsnapshot.h index 3335889f4..3bbe24faa 100644 --- a/frame/item/components/appsnapshot.h +++ b/frame/item/components/appsnapshot.h @@ -21,16 +21,13 @@ signals: void clicked(const WId wid) const; public slots: + void fetchSnapshot(); void closeWindow() const; void setWindowTitle(const QString &title); -private slots: - void fetchSnapshot(); - private: void enterEvent(QEvent *e); void paintEvent(QPaintEvent *e); - void resizeEvent(QResizeEvent *e); void mousePressEvent(QMouseEvent *e); private: @@ -38,8 +35,6 @@ private: QString m_title; QImage m_snapshot; - - QTimer *m_fetchSnapshotTimer; }; #endif // APPSNAPSHOT_H