File indexing completed on 2025-02-02 04:26:13
0001 /* 0002 SPDX-FileCopyrightText: 2021 Vlad Zahorodnii <vlad.zahorodnii@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include "ImagePlatform.h" 0010 0011 #include <QImage> 0012 class QScreen; 0013 0014 #include <memory> 0015 0016 class ScreenShotSource2; 0017 class ScreenShotSourceWorkspace2; 0018 0019 /** 0020 * The PlatformKWin class uses the org.kde.KWin.ScreenShot2 dbus interface 0021 * for taking screenshots of screens and windows. 0022 */ 0023 class ImagePlatformKWin final : public ImagePlatform 0024 { 0025 Q_OBJECT 0026 0027 public: 0028 explicit ImagePlatformKWin(QObject *parent = nullptr); 0029 ~ImagePlatformKWin() override = default; 0030 0031 enum class ScreenShotFlag : uint { 0032 IncludeCursor = 0x1, 0033 IncludeDecoration = 0x2, 0034 NativeSize = 0x4, 0035 IncludeShadow = 0x8, 0036 }; 0037 Q_DECLARE_FLAGS(ScreenShotFlags, ScreenShotFlag) 0038 0039 enum class InteractiveKind : uint { 0040 Window = 0, 0041 Screen = 1, 0042 }; 0043 0044 GrabModes supportedGrabModes() const override; 0045 ShutterModes supportedShutterModes() const override; 0046 0047 public Q_SLOTS: 0048 void 0049 doGrab(ImagePlatform::ShutterMode shutterMode, ImagePlatform::GrabMode grabMode, bool includePointer, bool includeDecorations, bool includeShadow) override; 0050 0051 private Q_SLOTS: 0052 void updateSupportedGrabModes(); 0053 0054 private: 0055 void takeScreenShotInteractive(InteractiveKind kind, ScreenShotFlags flags); 0056 void takeScreenShotArea(const QRect &area, ScreenShotFlags flags); 0057 void takeScreenShotActiveWindow(ScreenShotFlags flags); 0058 void takeScreenShotActiveScreen(ScreenShotFlags flags); 0059 void takeScreenShotWorkspace(ScreenShotFlags flags); 0060 void takeScreenShotCroppable(ScreenShotFlags flags); 0061 0062 void trackSource(ScreenShotSource2 *source); 0063 void trackCroppableSource(ScreenShotSourceWorkspace2 *source); 0064 0065 int m_apiVersion = 1; 0066 GrabModes m_grabModes; 0067 }; 0068 0069 /** 0070 * The ScreenShotSource2 class is the base class for screenshot sources that use the 0071 * org.kde.KWin.ScreenShot2 dbus interface. 0072 */ 0073 class ScreenShotSource2 : public QObject 0074 { 0075 Q_OBJECT 0076 0077 public: 0078 template<typename... ArgType> 0079 explicit ScreenShotSource2(const QString &methodName, ArgType... arguments); 0080 ~ScreenShotSource2() override; 0081 0082 QImage result() const; 0083 0084 Q_SIGNALS: 0085 void finished(const QImage &image); 0086 void errorOccurred(); 0087 0088 private Q_SLOTS: 0089 void handleMetaDataReceived(const QVariantMap &metadata); 0090 0091 private: 0092 QImage m_result; 0093 int m_pipeFileDescriptor = -1; 0094 }; 0095 0096 /** 0097 * The ScreenShotSourceArea2 class provides a convenient way to take a screenshot of the 0098 * specified area using the org.kde.KWin.ScreenShot2 dbus interface. 0099 */ 0100 class ScreenShotSourceArea2 final : public ScreenShotSource2 0101 { 0102 Q_OBJECT 0103 0104 public: 0105 ScreenShotSourceArea2(const QRect &area, ImagePlatformKWin::ScreenShotFlags flags); 0106 }; 0107 0108 /** 0109 * The ScreenShotSourceInteractive2 class provides a convenient way to take a screenshot 0110 * of a screen or a window as selected by the user. This uses the org.kde.KWin.ScreenShot2 0111 * dbus interface. 0112 */ 0113 class ScreenShotSourceInteractive2 final : public ScreenShotSource2 0114 { 0115 Q_OBJECT 0116 0117 public: 0118 ScreenShotSourceInteractive2(ImagePlatformKWin::InteractiveKind kind, ImagePlatformKWin::ScreenShotFlags flags); 0119 }; 0120 0121 /** 0122 * The ScreenShotSourceScreen2 class provides a convenient way to take a screenshot of 0123 * the specified screen using the org.kde.KWin.ScreenShot2 dbus interface. 0124 */ 0125 class ScreenShotSourceScreen2 final : public ScreenShotSource2 0126 { 0127 Q_OBJECT 0128 0129 public: 0130 ScreenShotSourceScreen2(const QScreen *screen, ImagePlatformKWin::ScreenShotFlags flags); 0131 }; 0132 0133 /** 0134 * The ScreenShotSourceActiveWindow2 class provides a convenient way to take a screenshot 0135 * of the active window. This uses the org.kde.KWin.ScreenShot2 dbus interface. 0136 */ 0137 class ScreenShotSourceActiveWindow2 final : public ScreenShotSource2 0138 { 0139 Q_OBJECT 0140 0141 public: 0142 ScreenShotSourceActiveWindow2(ImagePlatformKWin::ScreenShotFlags flags); 0143 }; 0144 0145 /** 0146 * The ScreenShotSourceActiveScreen2 class provides a convenient way to take a screenshot 0147 * of the active screen. This uses the org.kde.KWin.ScreenShot2 dbus interface. 0148 */ 0149 class ScreenShotSourceActiveScreen2 final : public ScreenShotSource2 0150 { 0151 Q_OBJECT 0152 0153 public: 0154 ScreenShotSourceActiveScreen2(ImagePlatformKWin::ScreenShotFlags flags); 0155 }; 0156 0157 /** 0158 * The ScreenShotSourceWorkspace2 class provides a convenient way to take a screenshot 0159 * of the whole workspace. This uses the org.kde.KWin.ScreenShot2 dbus interface. 0160 */ 0161 class ScreenShotSourceWorkspace2 final : public ScreenShotSource2 0162 { 0163 Q_OBJECT 0164 0165 public: 0166 ScreenShotSourceWorkspace2(ImagePlatformKWin::ScreenShotFlags flags); 0167 }; 0168 0169 Q_DECLARE_OPERATORS_FOR_FLAGS(ImagePlatformKWin::ScreenShotFlags)