From 0cbe297d84ee05e6640c9a81ef4f8dcec4173c63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20L=C3=BCbking?= Date: Wed, 7 Dec 2011 15:04:11 +0100 Subject: [PATCH] sanitize closed screenshot windows, ignore deleted CCBUG: 288271 REVIEW: 103350 --- effects/screenshot/screenshot.cpp | 22 ++++++++++++++++++---- effects/screenshot/screenshot.h | 3 +++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/effects/screenshot/screenshot.cpp b/effects/screenshot/screenshot.cpp index 6b9fcee90c..6bd18e3e85 100644 --- a/effects/screenshot/screenshot.cpp +++ b/effects/screenshot/screenshot.cpp @@ -43,6 +43,7 @@ bool ScreenShotEffect::supported() ScreenShotEffect::ScreenShotEffect() : m_scheduledScreenshot(0) { + connect ( effects, SIGNAL(windowClosed(EffectWindow*)), SLOT(windowClosed(EffectWindow*)) ); QDBusConnection::sessionBus().registerObject("/Screenshot", this, QDBusConnection::ExportScriptableContents); QDBusConnection::sessionBus().registerService("org.kde.kwin.Screenshot"); } @@ -137,10 +138,15 @@ void ScreenShotEffect::screenshotWindowUnderCursor(int mask) { m_type = (ScreenShotType)mask; const QPoint cursor = effects->cursorPos(); - foreach (EffectWindow * w, effects->stackingOrder()) { - if (w->geometry().contains(cursor) && w->isOnCurrentDesktop() && !w->isMinimized()) { - m_scheduledScreenshot = w; - } + EffectWindowList order = effects->stackingOrder(); + EffectWindowList::const_iterator it = order.constEnd(), first = order.constBegin(); + while( it != first ) { + m_scheduledScreenshot = *(--it); + if (m_scheduledScreenshot->isOnCurrentDesktop() && + !m_scheduledScreenshot->isMinimized() && !m_scheduledScreenshot->isDeleted() && + m_scheduledScreenshot->geometry().contains(cursor)) + break; + m_scheduledScreenshot = 0; } if (m_scheduledScreenshot) { m_scheduledScreenshot->addRepaintFull(); @@ -263,4 +269,12 @@ bool ScreenShotEffect::isActive() const return m_scheduledScreenshot != NULL; } +void ScreenShotEffect::windowClosed( EffectWindow* w ) +{ + if (w == m_scheduledScreenshot) { + m_scheduledScreenshot = NULL; + screenshotWindowUnderCursor(m_type); + } +} + } // namespace diff --git a/effects/screenshot/screenshot.h b/effects/screenshot/screenshot.h index 0b9e6130a8..22385a32c6 100644 --- a/effects/screenshot/screenshot.h +++ b/effects/screenshot/screenshot.h @@ -73,6 +73,9 @@ public Q_SLOTS: Q_SIGNALS: Q_SCRIPTABLE void screenshotCreated(qulonglong handle); +private slots: + void windowClosed( EffectWindow* w ); + private: void grabPointerImage(QImage& snapshot, int offsetx, int offsety); QString blitScreenshot(const QRect &geometry);