Changeset View
Changeset View
Standalone View
Standalone View
src/BackendPlugins/XcbScreenshotPlugin.h
- This file was moved from src/Platforms/PlatformXcb.h.
1 | /* This file is part of Spectacle, the KDE screenshot utility | 1 | /* This file is part of Spectacle, the KDE screenshot utility | ||
---|---|---|---|---|---|
2 | * Copyright (C) 2019 Boudhayan Gupta <bgupta@kde.org> | 2 | * Copyright (C) 2019 Leon De Andrade <leondeandrade@hotmail.com> | ||
3 | * | 3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | 4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU Lesser General Public License as published by | 5 | * it under the terms of the GNU Lesser General Public License as published by | ||
6 | * the Free Software Foundation; either version 2 of the License, or | 6 | * the Free Software Foundation; either version 2 of the License, or | ||
7 | * (at your option) any later version. | 7 | * (at your option) any later version. | ||
8 | * | 8 | * | ||
9 | * This program is distributed in the hope that it will be useful, | 9 | * This program is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | * GNU General Public License for more details. | 12 | * GNU General Public License for more details. | ||
13 | * | 13 | * | ||
14 | * You should have received a copy of the GNU Lesser General Public License | 14 | * You should have received a copy of the GNU Lesser General Public License | ||
15 | * along with this program; if not, write to the Free Software | 15 | * along with this program; if not, write to the Free Software | ||
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, | 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
17 | * Boston, MA 02110-1301, USA. | 17 | * Boston, MA 02110-1301, USA. | ||
18 | * | 18 | * | ||
19 | * SPDX-License-Identifier: LGPL-2.0-or-later | 19 | * SPDX-License-Identifier: LGPL-2.0-or-later | ||
20 | */ | 20 | */ | ||
21 | 21 | | |||
22 | #pragma once | | |||
23 | 22 | | |||
24 | #include "Platform.h" | 23 | #ifndef XCB_SCREENSHOT_PLUGIN | ||
24 | #define XCB_SCREENSHOT_PLUGIN | ||||
25 | 25 | | |||
26 | #include <xcb/xcb.h> | 26 | #include "BackendInterfaces/ScreenshotInterface.h" | ||
27 | #include <xcb/xcb_image.h> | | |||
28 | 27 | | |||
29 | #include <QPixmap> | 28 | #include <QAbstractNativeEventFilter> | ||
30 | 29 | | |||
31 | class PlatformXcb final: public Platform | 30 | typedef uint32_t xcb_window_t; | ||
32 | { | 31 | typedef uint32_t xcb_drawable_t; | ||
32 | | ||||
33 | class QPoint; | ||||
34 | class QRect; | ||||
35 | class QPixmap; | ||||
36 | class xcb_image_t; | ||||
37 | | ||||
38 | class XcbScreenshotPlugin : public ScreenshotInterface { | ||||
33 | Q_OBJECT | 39 | Q_OBJECT | ||
40 | Q_PLUGIN_METADATA(IID "org.kde.spectacle.XcbScreenshotPlugin" FILE "XcbScreenshotPlugin.json") | ||||
41 | Q_INTERFACES(ScreenshotInterface) | ||||
34 | 42 | | |||
35 | public: | 43 | public: | ||
44 | explicit XcbScreenshotPlugin(QObject *parent = nullptr); | ||||
45 | virtual ~XcbScreenshotPlugin(); | ||||
36 | 46 | | |||
37 | explicit PlatformXcb(QObject *parent = nullptr); | 47 | //Meta Data | ||
38 | virtual ~PlatformXcb(); | 48 | virtual QString name() const override; | ||
49 | virtual Platform platform() const override; | ||||
50 | virtual CaptureModes supportedCaptureModes() const override; | ||||
51 | virtual ShutterModes supportedShutterModes() const override; | ||||
39 | 52 | | |||
40 | QString platformName() const override final; | 53 | virtual bool requirementsComplied() const override; | ||
41 | GrabModes supportedGrabModes() const override final; | | |||
42 | ShutterModes supportedShutterModes() const override final; | | |||
43 | 54 | | |||
44 | public Q_SLOTS: | 55 | virtual void doGrab(ShutterMode shutterMode, CaptureMode theCaptureMode, bool theIncludePointer, bool theIncludeDecorations) override; | ||
45 | | ||||
46 | void doGrab(Platform::ShutterMode theShutterMode, Platform::GrabMode theGrabMode, bool theIncludePointer, bool theIncludeDecorations) override final; | | |||
47 | 56 | | |||
48 | private Q_SLOTS: | 57 | private Q_SLOTS: | ||
49 | | ||||
50 | void handleKWinScreenshotReply(quint64 theDrawable); | 58 | void handleKWinScreenshotReply(quint64 theDrawable); | ||
51 | void doGrabNow(const Platform::GrabMode &theGrabMode, bool theIncludePointer, bool theIncludeDecorations); | 59 | void doGrabNow(const CaptureMode &theCaptureMode, bool theIncludePointer, bool theIncludeDecorations); | ||
52 | void doGrabOnClick(const Platform::GrabMode &theGrabMode, bool theIncludePointer, bool theIncludeDecorations); | 60 | void doGrabOnClick(const CaptureMode &theCaptureMode, bool theIncludePointer, bool theIncludeDecorations); | ||
53 | 61 | | |||
54 | private: | 62 | private: | ||
55 | | ||||
56 | inline void updateWindowTitle(xcb_window_t theWindow); | 63 | inline void updateWindowTitle(xcb_window_t theWindow); | ||
57 | bool isKWinAvailable(); | 64 | bool isKWinAvailable(); | ||
58 | QPoint getCursorPosition(); | 65 | QPoint getCursorPosition(); | ||
59 | QRect getDrawableGeometry(xcb_drawable_t theDrawable); | 66 | QRect getDrawableGeometry(xcb_drawable_t theDrawable); | ||
60 | xcb_window_t getWindowUnderCursor(); | 67 | xcb_window_t getWindowUnderCursor(); | ||
61 | xcb_window_t getTransientWindowParent(xcb_window_t theChildWindow, QRect &theWindowRectOut, bool theIncludeDectorations); | 68 | xcb_window_t getTransientWindowParent(xcb_window_t theChildWindow, QRect &theWindowRectOut, bool theIncludeDectorations); | ||
62 | QPixmap convertFromNative(xcb_image_t *theXcbImage); | 69 | QPixmap convertFromNative(xcb_image_t *theXcbImage); | ||
63 | QPixmap blendCursorImage(QPixmap &thePixmap, const QRect theRect); | 70 | QPixmap blendCursorImage(QPixmap &thePixmap, const QRect theRect); | ||
64 | QPixmap postProcessPixmap(QPixmap &thePixmap, QRect theRect, bool theBlendPointer); | 71 | QPixmap postProcessPixmap(QPixmap &thePixmap, QRect theRect, bool theBlendPointer); | ||
65 | QPixmap getPixmapFromDrawable(xcb_drawable_t theXcbDrawable, const QRect &theRect); | 72 | QPixmap getPixmapFromDrawable(xcb_drawable_t theXcbDrawable, const QRect &theRect); | ||
66 | QPixmap getToplevelPixmap(QRect theRect, bool theBlendPointer); | 73 | QPixmap getToplevelPixmap(QRect theRect, bool theBlendPointer); | ||
67 | QPixmap getWindowPixmap(xcb_window_t theWindow, bool theBlendPointer); | 74 | QPixmap getWindowPixmap(xcb_window_t theWindow, bool theBlendPointer); | ||
68 | 75 | | |||
69 | void grabAllScreens(bool theIncludePointer); | 76 | void grabAllScreens(bool theIncludePointer); | ||
70 | void grabCurrentScreen(bool theIncludePointer); | 77 | void grabCurrentScreen(bool theIncludePointer); | ||
71 | void grabApplicationWindow(xcb_window_t theWindow, bool theIncludePointer, bool theIncludeDecorations); | 78 | void grabApplicationWindow(xcb_window_t theWindow, bool theIncludePointer, bool theIncludeDecorations); | ||
72 | void grabActiveWindow(bool theIncludePointer, bool theIncludeDecorations); | 79 | void grabActiveWindow(bool theIncludePointer, bool theIncludeDecorations); | ||
73 | void grabWindowUnderCursor(bool theIncludePointer, bool theIncludeDecorations); | 80 | void grabWindowUnderCursor(bool theIncludePointer, bool theIncludeDecorations); | ||
74 | void grabTransientWithParent(bool theIncludePointer, bool theIncludeDecorations); | 81 | void grabTransientWithParent(bool theIncludePointer, bool theIncludeDecorations); | ||
75 | 82 | | |||
76 | // on-click screenshot shutter support needs a native event filter in xcb | 83 | // On-click screenshot shutter support needs a native event filter in xcb | ||
77 | class OnClickEventFilter; | 84 | class OnClickEventFilter; | ||
85 | | ||||
86 | //TO DO: Do we need this a member? | ||||
78 | OnClickEventFilter *mNativeEventFilter; | 87 | OnClickEventFilter *mNativeEventFilter; | ||
79 | }; | 88 | }; | ||
89 | | ||||
90 | class XcbScreenshotPlugin::OnClickEventFilter : public QAbstractNativeEventFilter { | ||||
91 | | ||||
92 | public: | ||||
93 | OnClickEventFilter(XcbScreenshotPlugin *thePlatformPtr); | ||||
94 | | ||||
95 | void setCaptureOptions(const CaptureMode &theCaptureMode, bool theIncludePointer, bool theIncludeDecorations); | ||||
96 | bool nativeEventFilter(const QByteArray &theEventType, void *theMessage, long *theResult) override; | ||||
97 | | ||||
98 | private: | ||||
99 | XcbScreenshotPlugin *mPlatformPtr; | ||||
100 | // TO DO: Just assuming default values seems like a bad idea (AllScreen might not even be available) | ||||
101 | CaptureMode mCaptureMode { CaptureMode::AllScreens }; | ||||
102 | bool mIncludePointer { true }; | ||||
103 | bool mIncludeDecorations { true }; | ||||
104 | }; | ||||
105 | | ||||
106 | #endif //XCB_SCREENSHOT_PLUGIN | ||||
107 | No newline at end of file |