File indexing completed on 2025-02-02 04:26:13
0001 /* This file is part of Spectacle, the KDE screenshot utility 0002 * SPDX-FileCopyrightText: 2019 Boudhayan Gupta <bgupta@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 <xcb/xcb.h> 0012 #include <xcb/xcb_image.h> 0013 0014 #include <QPixmap> 0015 0016 class ImagePlatformXcb final : public ImagePlatform 0017 { 0018 Q_OBJECT 0019 0020 public: 0021 explicit ImagePlatformXcb(QObject *parent = nullptr); 0022 ~ImagePlatformXcb() override; 0023 0024 GrabModes supportedGrabModes() const override final; 0025 ShutterModes supportedShutterModes() const override final; 0026 0027 public Q_SLOTS: 0028 void doGrab(ImagePlatform::ShutterMode shutterMode, 0029 ImagePlatform::GrabMode grabMode, 0030 bool includePointer, 0031 bool includeDecorations, 0032 bool includeShadow) override final; 0033 0034 private Q_SLOTS: 0035 void updateSupportedGrabModes(); 0036 void handleKWinScreenshotReply(quint64 drawable); 0037 void doGrabNow(ImagePlatform::GrabMode grabMode, bool includePointer, bool includeDecorations, bool includeShadow); 0038 void doGrabOnClick(ImagePlatform::GrabMode grabMode, bool includePointer, bool includeDecorations, bool includeShadow); 0039 0040 private: 0041 inline void updateWindowTitle(xcb_window_t window); 0042 bool isKWinAvailable(); 0043 0044 QPoint getCursorPosition(); 0045 QRect getDrawableGeometry(xcb_drawable_t drawable); 0046 xcb_window_t getWindowUnderCursor(); 0047 xcb_window_t getTransientWindowParent(xcb_window_t childWindow, QRect &windowRectOut, bool includeDecorations); 0048 0049 /* ----------------------- Image Processing Utilities ----------------------- */ 0050 0051 /** 0052 * @brief Adds a drop shadow to the given image. 0053 * @param image The image to add a drop shadow to. 0054 * @return The image with a drop shadow. 0055 */ 0056 QImage addDropShadow(QImage &image); 0057 0058 QList<QRect> getScreenRects(); 0059 QImage convertFromNative(xcb_image_t *xcbImage); 0060 QImage blendCursorImage(QImage &image, const QRect rect); 0061 QImage postProcessImage(QImage &image, QRect rect, bool blendPointer); 0062 QImage getImageFromDrawable(xcb_drawable_t xcbDrawable, const QRect &rect); 0063 QImage getToplevelImage(QRect rect, bool blendPointer); 0064 QImage getWindowImage(xcb_window_t window, bool blendPointer); 0065 0066 void grabAllScreens(bool includePointer, bool crop = false); 0067 void grabCurrentScreen(bool includePointer); 0068 void grabApplicationWindow(xcb_window_t window, bool includePointer, bool includeDecorations); 0069 void grabActiveWindow(bool includePointer, bool includeDecorations, bool includeShadow); 0070 void grabWindowUnderCursor(bool includePointer, bool includeDecorations, bool includeShadow); 0071 void grabTransientWithParent(bool includePointer, bool includeDecorations, bool includeShadow); 0072 0073 // on-click screenshot shutter support needs a native event filter in xcb 0074 class OnClickEventFilter; 0075 std::unique_ptr<OnClickEventFilter> m_nativeEventFilter; 0076 0077 GrabModes m_grabModes; 0078 };