Changeset View
Changeset View
Standalone View
Standalone View
effects/screenshot/screenshot.cpp
Show All 35 Lines | |||||
36 | bool ScreenShotEffect::supported() | 36 | bool ScreenShotEffect::supported() | ||
37 | { | 37 | { | ||
38 | return effects->compositingType() == XRenderCompositing || | 38 | return effects->compositingType() == XRenderCompositing || | ||
39 | (effects->isOpenGLCompositing() && GLRenderTarget::supported()); | 39 | (effects->isOpenGLCompositing() && GLRenderTarget::supported()); | ||
40 | } | 40 | } | ||
41 | 41 | | |||
42 | ScreenShotEffect::ScreenShotEffect() | 42 | ScreenShotEffect::ScreenShotEffect() | ||
43 | : m_scheduledScreenshot(0) | 43 | : m_scheduledScreenshot(0) | ||
44 | , m_replyConnection(QDBusConnection::sessionBus()) | ||||
44 | { | 45 | { | ||
45 | connect ( effects, SIGNAL(windowClosed(KWin::EffectWindow*)), SLOT(windowClosed(KWin::EffectWindow*)) ); | 46 | connect ( effects, SIGNAL(windowClosed(KWin::EffectWindow*)), SLOT(windowClosed(KWin::EffectWindow*)) ); | ||
46 | QDBusConnection::sessionBus().registerObject(QStringLiteral("/Screenshot"), this, QDBusConnection::ExportScriptableContents); | 47 | QDBusConnection::sessionBus().registerObject(QStringLiteral("/Screenshot"), this, QDBusConnection::ExportScriptableContents); | ||
47 | QDBusConnection::sessionBus().registerService(QStringLiteral("org.kde.kwin.Screenshot")); | 48 | QDBusConnection::sessionBus().registerService(QStringLiteral("org.kde.kwin.Screenshot")); | ||
48 | } | 49 | } | ||
49 | 50 | | |||
50 | ScreenShotEffect::~ScreenShotEffect() | 51 | ScreenShotEffect::~ScreenShotEffect() | ||
51 | { | 52 | { | ||
▲ Show 20 Lines • Show All 120 Lines • ▼ Show 20 Line(s) | |||||
172 | #ifdef KWIN_HAVE_XRENDER_COMPOSITING | 173 | #ifdef KWIN_HAVE_XRENDER_COMPOSITING | ||
173 | if (xImage) { | 174 | if (xImage) { | ||
174 | xcb_image_destroy(xImage); | 175 | xcb_image_destroy(xImage); | ||
175 | } | 176 | } | ||
176 | #endif | 177 | #endif | ||
177 | } | 178 | } | ||
178 | m_scheduledScreenshot = NULL; | 179 | m_scheduledScreenshot = NULL; | ||
179 | } | 180 | } | ||
181 | | ||||
182 | if (!m_scheduledGeometry.isNull()) { | ||||
183 | m_replyConnection.send(m_replyMessage.createReply(blitScreenshot(m_scheduledGeometry))); | ||||
184 | m_scheduledGeometry = QRect(); | ||||
185 | } | ||||
180 | } | 186 | } | ||
181 | 187 | | |||
182 | void ScreenShotEffect::screenshotWindowUnderCursor(int mask) | 188 | void ScreenShotEffect::screenshotWindowUnderCursor(int mask) | ||
183 | { | 189 | { | ||
184 | m_type = (ScreenShotType)mask; | 190 | m_type = (ScreenShotType)mask; | ||
185 | const QPoint cursor = effects->cursorPos(); | 191 | const QPoint cursor = effects->cursorPos(); | ||
186 | EffectWindowList order = effects->stackingOrder(); | 192 | EffectWindowList order = effects->stackingOrder(); | ||
187 | EffectWindowList::const_iterator it = order.constEnd(), first = order.constBegin(); | 193 | EffectWindowList::const_iterator it = order.constEnd(), first = order.constBegin(); | ||
Show All 17 Lines | 208 | { | |||
205 | if(w && !w->isMinimized() && !w->isDeleted()) { | 211 | if(w && !w->isMinimized() && !w->isDeleted()) { | ||
206 | m_scheduledScreenshot = w; | 212 | m_scheduledScreenshot = w; | ||
207 | m_scheduledScreenshot->addRepaintFull(); | 213 | m_scheduledScreenshot->addRepaintFull(); | ||
208 | } | 214 | } | ||
209 | } | 215 | } | ||
210 | 216 | | |||
211 | QString ScreenShotEffect::screenshotFullscreen() | 217 | QString ScreenShotEffect::screenshotFullscreen() | ||
212 | { | 218 | { | ||
213 | return blitScreenshot(effects->virtualScreenGeometry()); | 219 | if (!calledFromDBus()) { | ||
220 | return QString(); | ||||
221 | } | ||||
222 | if (!m_scheduledGeometry.isNull()) { | ||||
223 | sendErrorReply(QDBusError::Failed, "A screenshot is already been taken"); | ||||
224 | return QString(); | ||||
225 | } | ||||
226 | m_replyConnection = connection(); | ||||
227 | m_replyMessage = message(); | ||||
228 | setDelayedReply(true); | ||||
229 | m_scheduledGeometry = effects->virtualScreenGeometry(); | ||||
230 | effects->addRepaintFull(); | ||||
231 | return QString(); | ||||
214 | } | 232 | } | ||
215 | 233 | | |||
216 | QString ScreenShotEffect::screenshotScreen(int screen) | 234 | QString ScreenShotEffect::screenshotScreen(int screen) | ||
217 | { | 235 | { | ||
218 | return blitScreenshot(effects->clientArea(FullScreenArea, screen, 0)); | 236 | if (!calledFromDBus()) { | ||
237 | return QString(); | ||||
238 | } | ||||
239 | if (!m_scheduledGeometry.isNull()) { | ||||
240 | sendErrorReply(QDBusError::Failed, "A screenshot is already been taken"); | ||||
241 | return QString(); | ||||
242 | } | ||||
243 | m_scheduledGeometry = effects->clientArea(FullScreenArea, screen, 0); | ||||
244 | if (m_scheduledGeometry.isNull()) { | ||||
245 | sendErrorReply(QDBusError::Failed, "Invalid screen requested"); | ||||
246 | return QString(); | ||||
247 | } | ||||
248 | m_replyConnection = connection(); | ||||
249 | m_replyMessage = message(); | ||||
250 | setDelayedReply(true); | ||||
251 | effects->addRepaint(m_scheduledGeometry); | ||||
252 | return QString(); | ||||
219 | } | 253 | } | ||
220 | 254 | | |||
221 | QString ScreenShotEffect::screenshotArea(int x, int y, int width, int height) | 255 | QString ScreenShotEffect::screenshotArea(int x, int y, int width, int height) | ||
222 | { | 256 | { | ||
223 | return blitScreenshot(QRect(x, y, width, height)); | 257 | if (!calledFromDBus()) { | ||
258 | return QString(); | ||||
259 | } | ||||
260 | if (!m_scheduledGeometry.isNull()) { | ||||
261 | sendErrorReply(QDBusError::Failed, "A screenshot is already been taken"); | ||||
262 | return QString(); | ||||
263 | } | ||||
264 | m_scheduledGeometry = QRect(x, y, width, height); | ||||
265 | if (m_scheduledGeometry.isNull() || m_scheduledGeometry.isEmpty()) { | ||||
266 | m_scheduledGeometry = QRect(); | ||||
267 | sendErrorReply(QDBusError::Failed, "Invalid area requested"); | ||||
268 | return QString(); | ||||
269 | } | ||||
270 | m_replyConnection = connection(); | ||||
271 | m_replyMessage = message(); | ||||
272 | setDelayedReply(true); | ||||
273 | effects->addRepaint(m_scheduledGeometry); | ||||
274 | return QString(); | ||||
224 | } | 275 | } | ||
225 | 276 | | |||
226 | QString ScreenShotEffect::blitScreenshot(const QRect &geometry) | 277 | QString ScreenShotEffect::blitScreenshot(const QRect &geometry) | ||
227 | { | 278 | { | ||
228 | QImage img; | 279 | QImage img; | ||
229 | if (effects->isOpenGLCompositing()) | 280 | if (effects->isOpenGLCompositing()) | ||
230 | { | 281 | { | ||
231 | if (!GLRenderTarget::blitSupported()) { | 282 | if (!GLRenderTarget::blitSupported()) { | ||
▲ Show 20 Lines • Show All 84 Lines • ▼ Show 20 Line(s) | 356 | } else { | |||
316 | } | 367 | } | ||
317 | 368 | | |||
318 | } | 369 | } | ||
319 | img = img.mirrored(); | 370 | img = img.mirrored(); | ||
320 | } | 371 | } | ||
321 | 372 | | |||
322 | bool ScreenShotEffect::isActive() const | 373 | bool ScreenShotEffect::isActive() const | ||
323 | { | 374 | { | ||
324 | return m_scheduledScreenshot != NULL && !effects->isScreenLocked(); | 375 | return (m_scheduledScreenshot != NULL || !m_scheduledGeometry.isNull()) && !effects->isScreenLocked(); | ||
325 | } | 376 | } | ||
326 | 377 | | |||
327 | void ScreenShotEffect::windowClosed( EffectWindow* w ) | 378 | void ScreenShotEffect::windowClosed( EffectWindow* w ) | ||
328 | { | 379 | { | ||
329 | if (w == m_scheduledScreenshot) { | 380 | if (w == m_scheduledScreenshot) { | ||
330 | m_scheduledScreenshot = NULL; | 381 | m_scheduledScreenshot = NULL; | ||
331 | screenshotWindowUnderCursor(m_type); | 382 | screenshotWindowUnderCursor(m_type); | ||
332 | } | 383 | } | ||
333 | } | 384 | } | ||
334 | 385 | | |||
335 | } // namespace | 386 | } // namespace |