File indexing completed on 2024-11-10 04:57:08
0001 /* 0002 KWin - the KDE window manager 0003 This file is part of the KDE project. 0004 0005 SPDX-FileCopyrightText: 2010 Martin Gräßlin <mgraesslin@kde.org> 0006 SPDX-FileCopyrightText: 2021 Vlad Zahorodnii <vlad.zahorodnii@kde.org> 0007 0008 SPDX-License-Identifier: GPL-2.0-or-later 0009 */ 0010 0011 #pragma once 0012 0013 #include "effect/effect.h" 0014 0015 #include <QFuture> 0016 #include <QImage> 0017 #include <QObject> 0018 0019 namespace KWin 0020 { 0021 0022 /** 0023 * This enum type is used to specify how a screenshot needs to be taken. 0024 */ 0025 enum ScreenShotFlag { 0026 ScreenShotIncludeDecoration = 0x1, ///< Include window titlebar and borders 0027 ScreenShotIncludeCursor = 0x2, ///< Include the cursor 0028 ScreenShotNativeResolution = 0x4, ///< Take the screenshot at the native resolution 0029 ScreenShotIncludeShadow = 0x8, ///< Include the window shadow 0030 }; 0031 Q_DECLARE_FLAGS(ScreenShotFlags, ScreenShotFlag) 0032 0033 class ScreenShotDBusInterface2; 0034 struct ScreenShotWindowData; 0035 struct ScreenShotAreaData; 0036 struct ScreenShotScreenData; 0037 0038 /** 0039 * The ScreenShotEffect provides a convenient way to capture the contents of a given window, 0040 * screen or an area in the global coordinates. 0041 * 0042 * Use the QFutureWatcher class to get notified when the requested screenshot is ready. Note 0043 * that the screenshot QFuture object can get cancelled if the captured window or the screen is 0044 * removed. 0045 */ 0046 class ScreenShotEffect : public Effect 0047 { 0048 Q_OBJECT 0049 0050 public: 0051 ScreenShotEffect(); 0052 ~ScreenShotEffect() override; 0053 0054 /** 0055 * Schedules a screenshot of the given @a screen. The returned QFuture can be used to query 0056 * the image data. If the screen is removed before the screenshot is taken, the future will 0057 * be cancelled. 0058 */ 0059 QFuture<QImage> scheduleScreenShot(Output *screen, ScreenShotFlags flags = {}); 0060 0061 /** 0062 * Schedules a screenshot of the given @a area. The returned QFuture can be used to query the 0063 * image data. 0064 */ 0065 QFuture<QImage> scheduleScreenShot(const QRect &area, ScreenShotFlags flags = {}); 0066 0067 /** 0068 * Schedules a screenshot of the given @a window. The returned QFuture can be used to query 0069 * the image data. If the window is removed before the screenshot is taken, the future will 0070 * be cancelled. 0071 */ 0072 QFuture<QImage> scheduleScreenShot(EffectWindow *window, ScreenShotFlags flags = {}); 0073 0074 void paintScreen(const RenderTarget &renderTarget, const RenderViewport &viewport, int mask, const QRegion ®ion, Output *screen) override; 0075 bool isActive() const override; 0076 int requestedEffectChainPosition() const override; 0077 0078 static bool supported(); 0079 0080 private Q_SLOTS: 0081 void handleWindowClosed(EffectWindow *window); 0082 void handleScreenAdded(); 0083 void handleScreenRemoved(Output *screen); 0084 0085 private: 0086 void takeScreenShot(ScreenShotWindowData *screenshot); 0087 bool takeScreenShot(const RenderTarget &renderTarget, const RenderViewport &viewport, ScreenShotAreaData *screenshot); 0088 bool takeScreenShot(const RenderTarget &renderTarget, const RenderViewport &viewport, ScreenShotScreenData *screenshot); 0089 0090 void cancelWindowScreenShots(); 0091 void cancelAreaScreenShots(); 0092 void cancelScreenScreenShots(); 0093 0094 void grabPointerImage(QImage &snapshot, int xOffset, int yOffset) const; 0095 QImage blitScreenshot(const RenderTarget &renderTarget, const RenderViewport &viewport, const QRect &geometry, qreal devicePixelRatio = 1.0) const; 0096 0097 std::vector<ScreenShotWindowData> m_windowScreenShots; 0098 std::vector<ScreenShotAreaData> m_areaScreenShots; 0099 std::vector<ScreenShotScreenData> m_screenScreenShots; 0100 0101 std::unique_ptr<ScreenShotDBusInterface2> m_dbusInterface2; 0102 Output *m_paintedScreen = nullptr; 0103 }; 0104 0105 } // namespace KWin 0106 0107 Q_DECLARE_OPERATORS_FOR_FLAGS(KWin::ScreenShotFlags)