2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2010-07-31 20:55:48 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2010 Martin Gräßlin <mgraesslin@kde.org>
|
2010-07-31 20:55:48 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2010-07-31 20:55:48 +00:00
|
|
|
|
|
|
|
#ifndef KWIN_SCREENSHOT_H
|
|
|
|
#define KWIN_SCREENSHOT_H
|
|
|
|
|
|
|
|
#include <kwineffects.h>
|
2016-10-14 09:34:56 +00:00
|
|
|
#include <QDBusContext>
|
|
|
|
#include <QDBusConnection>
|
|
|
|
#include <QDBusMessage>
|
2016-11-18 09:02:04 +00:00
|
|
|
#include <QDBusUnixFileDescriptor>
|
2010-07-31 20:55:48 +00:00
|
|
|
#include <QObject>
|
2010-09-14 19:52:44 +00:00
|
|
|
#include <QImage>
|
2010-07-31 20:55:48 +00:00
|
|
|
|
2020-04-22 09:31:46 +00:00
|
|
|
class ComparableQPoint;
|
2010-07-31 20:55:48 +00:00
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2020-08-26 16:21:54 +00:00
|
|
|
/**
|
|
|
|
* The screenshot effet allows to takes screenshot, by window, area, screen, etc...
|
|
|
|
*
|
|
|
|
* A using application must have "org.kde.kwin.Screenshot" in its X-KDE-DBUS-Restricted-Interfaces application service file field.
|
|
|
|
*/
|
2016-10-14 09:34:56 +00:00
|
|
|
class ScreenShotEffect : public Effect, protected QDBusContext
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2010-07-31 20:55:48 +00:00
|
|
|
Q_OBJECT
|
2010-09-14 19:52:44 +00:00
|
|
|
Q_CLASSINFO("D-Bus Interface", "org.kde.kwin.Screenshot")
|
2011-01-30 14:34:42 +00:00
|
|
|
public:
|
|
|
|
enum ScreenShotType {
|
|
|
|
INCLUDE_DECORATION = 1 << 0,
|
|
|
|
INCLUDE_CURSOR = 1 << 1
|
2010-07-31 20:55:48 +00:00
|
|
|
};
|
2011-01-30 14:34:42 +00:00
|
|
|
ScreenShotEffect();
|
2018-10-16 21:48:02 +00:00
|
|
|
~ScreenShotEffect() override;
|
|
|
|
|
2019-10-29 22:04:15 +00:00
|
|
|
void paintScreen(int mask, const QRegion ®ion, ScreenPaintData &data) override;
|
2018-10-16 21:48:02 +00:00
|
|
|
void postPaintScreen() override;
|
|
|
|
bool isActive() const override;
|
2011-01-30 14:34:42 +00:00
|
|
|
|
2014-03-24 10:50:09 +00:00
|
|
|
int requestedEffectChainPosition() const override {
|
|
|
|
return 50;
|
|
|
|
}
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
static bool supported();
|
|
|
|
static void convertFromGLImage(QImage &img, int w, int h);
|
2020-09-30 03:34:32 +00:00
|
|
|
void scheduleScreenshotWindowUnderCursor();
|
2011-01-30 14:34:42 +00:00
|
|
|
public Q_SLOTS:
|
2012-04-12 11:13:49 +00:00
|
|
|
Q_SCRIPTABLE void screenshotForWindow(qulonglong winid, int mask = 0);
|
2016-11-15 14:40:30 +00:00
|
|
|
/**
|
|
|
|
* Starts an interactive window screenshot session. The user can select a window to
|
|
|
|
* screenshot.
|
|
|
|
*
|
|
|
|
* Once the window is selected the screenshot is saved into a file and the path gets
|
|
|
|
* returned to the DBus peer.
|
|
|
|
*
|
|
|
|
* @param mask The mask for what to include in the screenshot
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2016-11-15 14:40:30 +00:00
|
|
|
Q_SCRIPTABLE QString interactive(int mask = 0);
|
2016-11-18 09:02:04 +00:00
|
|
|
/**
|
|
|
|
* Starts an interactive window screenshot session. The user can select a window to
|
|
|
|
* screenshot.
|
|
|
|
*
|
|
|
|
* Once the window is selected the screenshot is saved into the @p fd passed to the
|
|
|
|
* method. It is intended to be used with a pipe, so that the invoking side can just
|
|
|
|
* read from the pipe. The image gets written into the fd using a QDataStream.
|
|
|
|
*
|
|
|
|
* @param fd File descriptor into which the screenshot should be saved
|
|
|
|
* @param mask The mask for what to include in the screenshot
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2016-11-18 09:02:04 +00:00
|
|
|
Q_SCRIPTABLE void interactive(QDBusUnixFileDescriptor fd, int mask = 0);
|
2011-01-30 14:34:42 +00:00
|
|
|
Q_SCRIPTABLE void screenshotWindowUnderCursor(int mask = 0);
|
2011-08-17 17:20:15 +00:00
|
|
|
/**
|
|
|
|
* Saves a screenshot of all screen into a file and returns the path to the file.
|
|
|
|
* Functionality requires hardware support, if not available a null string is returned.
|
2016-10-20 06:29:48 +00:00
|
|
|
* @param captureCursor Whether to include the cursor in the image
|
2011-08-17 17:20:15 +00:00
|
|
|
* @returns Path to stored screenshot, or null string in failure case.
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2016-10-20 06:29:48 +00:00
|
|
|
Q_SCRIPTABLE QString screenshotFullscreen(bool captureCursor = false);
|
2016-11-23 14:53:17 +00:00
|
|
|
/**
|
2020-08-26 16:21:54 +00:00
|
|
|
* Takes a full screen screenshot in a one file format.
|
2016-11-23 14:53:17 +00:00
|
|
|
*
|
|
|
|
* Once the screenshot is taken it gets saved into the @p fd passed to the
|
|
|
|
* method. It is intended to be used with a pipe, so that the invoking side can just
|
|
|
|
* read from the pipe. The image gets written into the fd using a QDataStream.
|
|
|
|
*
|
|
|
|
* @param fd File descriptor into which the screenshot should be saved
|
|
|
|
* @param captureCursor Whether to include the mouse cursor
|
2020-04-22 09:31:46 +00:00
|
|
|
* @param shouldReturnNativeSize Whether to return an image according to the virtualGeometry, or according to pixel on screen size
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2020-04-22 09:31:46 +00:00
|
|
|
Q_SCRIPTABLE void screenshotFullscreen(QDBusUnixFileDescriptor fd, bool captureCursor = false, bool shouldReturnNativeSize = false);
|
2020-08-26 16:21:54 +00:00
|
|
|
/**
|
|
|
|
* Take a screenshot of the passed screens and return a QList<QImage> in the fd response,
|
|
|
|
* an image for each screen in pixel-on-screen size when shouldReturnNativeSize is passed, or converted to using logicale size if not
|
|
|
|
*
|
|
|
|
* @param fd
|
|
|
|
* @param screensNames the names of the screens whose screenshot to return
|
|
|
|
* @param captureCursor
|
|
|
|
* @param shouldReturnNativeSize
|
|
|
|
*/
|
|
|
|
Q_SCRIPTABLE void screenshotScreens(QDBusUnixFileDescriptor fd, const QStringList &screensNames, bool captureCursor = false, bool shouldReturnNativeSize = false);
|
2011-08-17 17:20:15 +00:00
|
|
|
/**
|
|
|
|
* Saves a screenshot of the screen identified by @p screen into a file and returns the path to the file.
|
|
|
|
* Functionality requires hardware support, if not available a null string is returned.
|
2012-03-27 17:14:53 +00:00
|
|
|
* @param screen Number of screen as numbered by QDesktopWidget
|
2016-10-20 06:29:48 +00:00
|
|
|
* @param captureCursor Whether to include the cursor in the image
|
2011-08-17 17:20:15 +00:00
|
|
|
* @returns Path to stored screenshot, or null string in failure case.
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2016-10-20 06:29:48 +00:00
|
|
|
Q_SCRIPTABLE QString screenshotScreen(int screen, bool captureCursor = false);
|
2016-11-23 14:53:17 +00:00
|
|
|
/**
|
|
|
|
* Starts an interactive screenshot of a screen session.
|
|
|
|
*
|
|
|
|
* The user is asked to select the screen to screenshot.
|
|
|
|
*
|
|
|
|
* Once the screenshot is taken it gets saved into the @p fd passed to the
|
|
|
|
* method. It is intended to be used with a pipe, so that the invoking side can just
|
|
|
|
* read from the pipe. The image gets written into the fd using a QDataStream.
|
|
|
|
*
|
|
|
|
* @param fd File descriptor into which the screenshot should be saved
|
|
|
|
* @param captureCursor Whether to include the mouse cursor
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2016-11-23 14:53:17 +00:00
|
|
|
Q_SCRIPTABLE void screenshotScreen(QDBusUnixFileDescriptor fd, bool captureCursor = false);
|
2011-08-17 17:20:15 +00:00
|
|
|
/**
|
|
|
|
* Saves a screenshot of the selected geometry into a file and returns the path to the file.
|
|
|
|
* Functionality requires hardware support, if not available a null string is returned.
|
|
|
|
* @param x Left upper x coord of region
|
|
|
|
* @param y Left upper y coord of region
|
|
|
|
* @param width Width of the region to screenshot
|
|
|
|
* @param height Height of the region to screenshot
|
2016-10-20 06:29:48 +00:00
|
|
|
* @param captureCursor Whether to include the cursor in the image
|
2011-08-17 17:20:15 +00:00
|
|
|
* @returns Path to stored screenshot, or null string in failure case.
|
2019-07-29 18:58:33 +00:00
|
|
|
*/
|
2016-10-20 06:29:48 +00:00
|
|
|
Q_SCRIPTABLE QString screenshotArea(int x, int y, int width, int height, bool captureCursor = false);
|
2011-01-30 14:34:42 +00:00
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
Q_SCRIPTABLE void screenshotCreated(qulonglong handle);
|
|
|
|
|
2013-07-22 14:07:39 +00:00
|
|
|
private Q_SLOTS:
|
2012-01-29 11:29:24 +00:00
|
|
|
void windowClosed( KWin::EffectWindow* w );
|
2011-12-07 14:04:11 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
private:
|
|
|
|
void grabPointerImage(QImage& snapshot, int offsetx, int offsety);
|
2020-04-20 14:11:21 +00:00
|
|
|
QImage blitScreenshot(const QRect &geometry, const qreal scale = 1.0);
|
2016-10-14 13:53:02 +00:00
|
|
|
QString saveTempImage(const QImage &img);
|
|
|
|
void sendReplyImage(const QImage &img);
|
2020-08-26 16:21:54 +00:00
|
|
|
void sendReplyImages();
|
|
|
|
void clearState();
|
2016-11-23 14:53:17 +00:00
|
|
|
enum class InfoMessageMode {
|
|
|
|
Window,
|
|
|
|
Screen
|
|
|
|
};
|
|
|
|
void showInfoMessage(InfoMessageMode mode);
|
2016-11-18 09:02:04 +00:00
|
|
|
void hideInfoMessage();
|
2016-11-25 07:50:02 +00:00
|
|
|
bool isTakingScreenshot() const;
|
2020-04-22 09:31:46 +00:00
|
|
|
void computeCoordinatesAfterScaling();
|
2020-06-16 16:59:59 +00:00
|
|
|
bool checkCall() const;
|
2020-04-22 09:31:46 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
EffectWindow *m_scheduledScreenshot;
|
|
|
|
ScreenShotType m_type;
|
2016-10-14 09:34:56 +00:00
|
|
|
QRect m_scheduledGeometry;
|
|
|
|
QDBusMessage m_replyMessage;
|
2016-10-14 13:53:02 +00:00
|
|
|
QRect m_cachedOutputGeometry;
|
|
|
|
QRegion m_multipleOutputsRendered;
|
2020-04-22 09:31:46 +00:00
|
|
|
QMap<ComparableQPoint, QImage> m_cacheOutputsImages;
|
2020-08-26 16:21:54 +00:00
|
|
|
QList<QPoint> m_orderImg;
|
2016-10-20 06:29:48 +00:00
|
|
|
bool m_captureCursor = false;
|
2020-04-22 09:31:46 +00:00
|
|
|
bool m_nativeSize = false;
|
2016-11-15 14:40:30 +00:00
|
|
|
enum class WindowMode {
|
|
|
|
NoCapture,
|
|
|
|
Xpixmap,
|
2016-11-18 09:02:04 +00:00
|
|
|
File,
|
|
|
|
FileDescriptor
|
2016-11-15 14:40:30 +00:00
|
|
|
};
|
|
|
|
WindowMode m_windowMode = WindowMode::NoCapture;
|
2016-11-18 09:02:04 +00:00
|
|
|
int m_fd = -1;
|
2020-04-20 14:11:21 +00:00
|
|
|
qreal m_cachedScale;
|
2011-01-30 14:34:42 +00:00
|
|
|
};
|
2010-07-31 20:55:48 +00:00
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
#endif // KWIN_SCREENSHOT_H
|