Changeset View
Changeset View
Standalone View
Standalone View
src/BackendPlugins/XcbKWinScreenshotPlugin.h
- This file was added.
1 | /* This file is part of Spectacle, the KDE screenshot utility | ||||
---|---|---|---|---|---|
2 | * Copyright (C) 2019 Leon De Andrade <leondeandrade@hotmail.com> | ||||
3 | * | ||||
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 | ||||
6 | * the Free Software Foundation; either version 2 of the License, or | ||||
7 | * (at your option) any later version. | ||||
8 | * | ||||
9 | * This program is distributed in the hope that it will be useful, | ||||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
12 | * GNU General Public License for more details. | ||||
13 | * | ||||
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 | ||||
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||||
17 | * Boston, MA 02110-1301, USA. | ||||
18 | * | ||||
19 | * SPDX-License-Identifier: LGPL-2.0-or-later | ||||
20 | */ | ||||
21 | | ||||
22 | #ifndef XCB_KWIN_SCREENSHOT_PLUGIN_H | ||||
23 | #define XCB_KWIN_SCREENSHOT_PLUGIN_H | ||||
24 | | ||||
25 | #include "BackendInterfaces/ScreenshotInterface.h" | ||||
26 | | ||||
27 | #include <QAbstractNativeEventFilter> | ||||
28 | #include <QDBusInterface> | ||||
29 | | ||||
30 | typedef uint32_t xcb_window_t; | ||||
31 | typedef uint32_t xcb_drawable_t; | ||||
32 | | ||||
33 | class xcb_image_t; | ||||
34 | | ||||
35 | class XcbKWinScreenshotPlugin : public ScreenshotInterface { | ||||
36 | Q_OBJECT | ||||
37 | Q_PLUGIN_METADATA(IID "org.kde.spectacle.XcbKWinScreenshotPlugin" FILE "XcbKWinScreenshotPlugin.json") | ||||
38 | Q_INTERFACES(ScreenshotInterface) | ||||
39 | | ||||
40 | public: | ||||
41 | explicit XcbKWinScreenshotPlugin(QObject *parent = nullptr); | ||||
42 | virtual ~XcbKWinScreenshotPlugin(); | ||||
43 | | ||||
44 | //Meta Data | ||||
45 | virtual QString name() const override; | ||||
46 | virtual Platform platform() const override; | ||||
47 | virtual GrabModes supportedGrabModes() const override; | ||||
48 | virtual ShutterModes supportedShutterModes() const override; | ||||
49 | | ||||
50 | virtual bool requirementsComplied() const override; | ||||
51 | | ||||
52 | virtual void doGrab(ShutterMode shutterMode, GrabMode grabMode, bool includePointer, bool includeDecorations) override; | ||||
53 | | ||||
54 | private Q_SLOTS: | ||||
55 | void doGrabNow(const GrabMode &grabMode, bool includePointer, bool includeDecorations); | ||||
56 | void doGrabOnClick(const GrabMode &grabMode, bool includePointer, bool includeDecorations); | ||||
57 | | ||||
58 | void handleKWinScreenshotReply(quint64 theDrawable); | ||||
59 | | ||||
60 | private: | ||||
61 | QRect getDrawableGeometry(xcb_drawable_t drawable); | ||||
62 | QPixmap getPixmapFromDrawable(xcb_drawable_t xcbDrawable, const QRect &rect); | ||||
63 | QPixmap convertFromNative(xcb_image_t *xcbImage); | ||||
64 | | ||||
65 | void updateWindowTitle(xcb_window_t window); | ||||
66 | | ||||
67 | void grabAllScreens(bool includePointer); | ||||
68 | void grabCurrentScreen(bool includePointer); | ||||
69 | void grabActiveWindow(bool includePointer, bool includeDecorations); | ||||
70 | void grabWindowUnderCursor(bool includePointer, bool includeDecorations); | ||||
71 | | ||||
72 | void callDBus(const QString &method, const QList<QVariant> &args); | ||||
73 | | ||||
74 | // On-click screenshot shutter support needs a native event filter in xcb | ||||
75 | class OnClickEventFilter; | ||||
76 | OnClickEventFilter *mNativeEventFilter; | ||||
77 | }; | ||||
78 | | ||||
79 | class XcbKWinScreenshotPlugin::OnClickEventFilter : public QAbstractNativeEventFilter { | ||||
80 | | ||||
81 | public: | ||||
82 | OnClickEventFilter(XcbKWinScreenshotPlugin *platformPtr); | ||||
83 | | ||||
84 | void setCaptureOptions(const GrabMode &grabMode, bool includePointer, bool includeDecorations); | ||||
85 | bool nativeEventFilter(const QByteArray &eventType, void *message, long *result) override; | ||||
86 | | ||||
87 | private: | ||||
88 | XcbKWinScreenshotPlugin *mPlatformPtr; | ||||
89 | GrabMode mGrabMode { GrabMode::AllScreens }; | ||||
90 | bool mIncludePointer { true }; | ||||
91 | bool mIncludeDecorations { true }; | ||||
92 | }; | ||||
93 | | ||||
94 | #endif //XCB_KWIN_SCREENSHOT_PLUGIN_H | ||||
95 | No newline at end of file |