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>
|
|
|
|
SPDX-FileCopyrightText: 2010 Nokia Corporation and /or its subsidiary(-ies)
|
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
|
|
|
#include "screenshot.h"
|
2015-10-30 09:14:55 +00:00
|
|
|
#include <kwinglplatform.h>
|
2010-07-31 20:55:48 +00:00
|
|
|
#include <kwinglutils.h>
|
2012-03-04 08:53:12 +00:00
|
|
|
#include <kwinxrenderutils.h>
|
2016-11-18 09:02:04 +00:00
|
|
|
#include <QtConcurrentRun>
|
|
|
|
#include <QDataStream>
|
2018-06-05 10:52:57 +00:00
|
|
|
#include <QTemporaryFile>
|
|
|
|
#include <QDir>
|
2020-06-16 16:59:59 +00:00
|
|
|
#include <QDBusConnectionInterface>
|
|
|
|
#include <QDBusReply>
|
2013-02-26 08:00:51 +00:00
|
|
|
#include <QVarLengthArray>
|
2018-06-05 10:52:57 +00:00
|
|
|
#include <QPainter>
|
2013-02-26 07:02:27 +00:00
|
|
|
#include <QMatrix4x4>
|
2013-02-13 07:10:55 +00:00
|
|
|
#include <xcb/xcb_image.h>
|
2020-04-22 09:31:46 +00:00
|
|
|
#include <QPoint>
|
2020-08-26 16:21:54 +00:00
|
|
|
#include <QGuiApplication>
|
|
|
|
#include <QScreen>
|
2010-07-31 20:55:48 +00:00
|
|
|
|
2016-11-16 08:50:18 +00:00
|
|
|
#include <KLocalizedString>
|
|
|
|
#include <KNotification>
|
|
|
|
|
2016-11-18 09:02:04 +00:00
|
|
|
#include <unistd.h>
|
2020-06-16 16:59:59 +00:00
|
|
|
#include "../service_utils.h"
|
2016-11-18 09:02:04 +00:00
|
|
|
|
2020-08-26 16:21:54 +00:00
|
|
|
Q_DECLARE_METATYPE(QStringList)
|
|
|
|
|
2020-04-22 09:31:46 +00:00
|
|
|
class ComparableQPoint : public QPoint
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ComparableQPoint(QPoint& point): QPoint(point.x(), point.y())
|
|
|
|
{}
|
|
|
|
|
|
|
|
ComparableQPoint(QPoint point): QPoint(point.x(), point.y())
|
|
|
|
{}
|
|
|
|
|
|
|
|
ComparableQPoint(): QPoint()
|
|
|
|
{}
|
|
|
|
|
|
|
|
// utility class that allows using QMap to sort its keys when they are QPoint
|
|
|
|
// so that the bottom and right points are after the top left ones
|
|
|
|
bool operator<(const ComparableQPoint &other) const {
|
|
|
|
return x() < other.x() || y() < other.y();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-07-31 20:55:48 +00:00
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2016-11-25 07:50:02 +00:00
|
|
|
const static QString s_errorAlreadyTaking = QStringLiteral("org.kde.kwin.Screenshot.Error.AlreadyTaking");
|
|
|
|
const static QString s_errorAlreadyTakingMsg = QStringLiteral("A screenshot is already been taken");
|
2020-06-16 16:59:59 +00:00
|
|
|
const static QString s_errorNotAuthorized = QStringLiteral("org.kde.kwin.Screenshot.Error.NoAuthorized");
|
|
|
|
const static QString s_errorNotAuthorizedMsg = QStringLiteral("The process is not authorized to take a screenshot");
|
2016-11-25 07:50:02 +00:00
|
|
|
const static QString s_errorFd = QStringLiteral("org.kde.kwin.Screenshot.Error.FileDescriptor");
|
|
|
|
const static QString s_errorFdMsg = QStringLiteral("No valid file descriptor");
|
|
|
|
const static QString s_errorCancelled = QStringLiteral("org.kde.kwin.Screenshot.Error.Cancelled");
|
|
|
|
const static QString s_errorCancelledMsg = QStringLiteral("Screenshot got cancelled");
|
|
|
|
const static QString s_errorInvalidArea = QStringLiteral("org.kde.kwin.Screenshot.Error.InvalidArea");
|
|
|
|
const static QString s_errorInvalidAreaMsg = QStringLiteral("Invalid area requested");
|
|
|
|
const static QString s_errorInvalidScreen = QStringLiteral("org.kde.kwin.Screenshot.Error.InvalidScreen");
|
|
|
|
const static QString s_errorInvalidScreenMsg = QStringLiteral("Invalid screen requested");
|
2020-06-16 16:59:59 +00:00
|
|
|
const static QString s_dbusInterfaceName = QStringLiteral("org.kde.kwin.Screenshot");
|
2020-08-26 16:21:54 +00:00
|
|
|
const static QString s_errorScreenMissing = QStringLiteral("org.kde.kwin.Screenshot.Error.ScreenMissing");
|
|
|
|
const static QString s_errorScreenMissingMsg = QStringLiteral("Screen not found");
|
2016-11-25 07:50:02 +00:00
|
|
|
|
2010-07-31 20:55:48 +00:00
|
|
|
bool ScreenShotEffect::supported()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2012-03-04 08:53:12 +00:00
|
|
|
return effects->compositingType() == XRenderCompositing ||
|
2012-09-20 09:33:32 +00:00
|
|
|
(effects->isOpenGLCompositing() && GLRenderTarget::supported());
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-07-31 20:55:48 +00:00
|
|
|
|
|
|
|
ScreenShotEffect::ScreenShotEffect()
|
Use nullptr everywhere
Summary:
Because KWin is a very old project, we use three kinds of null pointer
literals: 0, NULL, and nullptr. Since C++11, it's recommended to use
nullptr keyword.
This change converts all usages of 0 and NULL literal to nullptr. Even
though it breaks git history, we need to do it in order to have consistent
code as well to ease code reviews (it's very tempting for some people to
add unrelated changes to their patches, e.g. converting NULL to nullptr).
Test Plan: Compiles.
Reviewers: #kwin, davidedmundson, romangg
Reviewed By: #kwin, davidedmundson, romangg
Subscribers: romangg, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D23618
2019-09-19 14:46:54 +00:00
|
|
|
: m_scheduledScreenshot(nullptr)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2019-01-01 20:48:53 +00:00
|
|
|
connect(effects, &EffectsHandler::windowClosed, this, &ScreenShotEffect::windowClosed);
|
2013-07-23 05:02:52 +00:00
|
|
|
QDBusConnection::sessionBus().registerObject(QStringLiteral("/Screenshot"), this, QDBusConnection::ExportScriptableContents);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-07-31 20:55:48 +00:00
|
|
|
|
|
|
|
ScreenShotEffect::~ScreenShotEffect()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2013-07-23 05:02:52 +00:00
|
|
|
QDBusConnection::sessionBus().unregisterObject(QStringLiteral("/Screenshot"));
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2013-02-13 07:10:55 +00:00
|
|
|
|
|
|
|
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
|
|
|
|
static QImage xPictureToImage(xcb_render_picture_t srcPic, const QRect &geometry, xcb_image_t **xImage)
|
|
|
|
{
|
2014-04-16 13:58:06 +00:00
|
|
|
xcb_connection_t *c = effects->xcbConnection();
|
|
|
|
xcb_pixmap_t xpix = xcb_generate_id(c);
|
|
|
|
xcb_create_pixmap(c, 32, xpix, effects->x11RootWindow(), geometry.width(), geometry.height());
|
2013-02-13 07:10:55 +00:00
|
|
|
XRenderPicture pic(xpix, 32);
|
2014-04-16 13:58:06 +00:00
|
|
|
xcb_render_composite(c, XCB_RENDER_PICT_OP_SRC, srcPic, XCB_RENDER_PICTURE_NONE, pic,
|
2013-02-13 07:10:55 +00:00
|
|
|
geometry.x(), geometry.y(), 0, 0, 0, 0, geometry.width(), geometry.height());
|
2014-04-16 13:58:06 +00:00
|
|
|
xcb_flush(c);
|
|
|
|
*xImage = xcb_image_get(c, xpix, 0, 0, geometry.width(), geometry.height(), ~0, XCB_IMAGE_FORMAT_Z_PIXMAP);
|
2013-02-13 07:10:55 +00:00
|
|
|
QImage img((*xImage)->data, (*xImage)->width, (*xImage)->height, (*xImage)->stride, QImage::Format_ARGB32_Premultiplied);
|
|
|
|
// TODO: byte order might need swapping
|
2014-04-16 13:58:06 +00:00
|
|
|
xcb_free_pixmap(c, xpix);
|
2016-10-14 13:53:02 +00:00
|
|
|
return img.copy();
|
2013-02-13 07:10:55 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-05-23 18:21:11 +00:00
|
|
|
static QSize pickWindowSize(const QImage &image)
|
|
|
|
{
|
|
|
|
xcb_connection_t *c = effects->xcbConnection();
|
|
|
|
|
|
|
|
// This will implicitly enable BIG-REQUESTS extension.
|
|
|
|
const uint32_t maximumRequestSize = xcb_get_maximum_request_length(c);
|
|
|
|
const xcb_setup_t *setup = xcb_get_setup(c);
|
|
|
|
|
|
|
|
uint32_t requestSize = sizeof(xcb_put_image_request_t);
|
|
|
|
|
|
|
|
// With BIG-REQUESTS extension an additional 32-bit field is inserted into
|
|
|
|
// the request so we better take it into account.
|
|
|
|
if (setup->maximum_request_length < maximumRequestSize) {
|
|
|
|
requestSize += 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
const uint32_t maximumDataSize = 4 * maximumRequestSize - requestSize;
|
|
|
|
const uint32_t bytesPerPixel = image.depth() >> 3;
|
|
|
|
const uint32_t bytesPerLine = image.bytesPerLine();
|
|
|
|
|
|
|
|
if (image.sizeInBytes() <= maximumDataSize) {
|
|
|
|
return image.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (maximumDataSize < bytesPerLine) {
|
|
|
|
return QSize(maximumDataSize / bytesPerPixel, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return QSize(image.width(), maximumDataSize / bytesPerLine);
|
|
|
|
}
|
|
|
|
|
|
|
|
static xcb_pixmap_t xpixmapFromImage(const QImage &image)
|
|
|
|
{
|
|
|
|
xcb_connection_t *c = effects->xcbConnection();
|
|
|
|
|
|
|
|
xcb_pixmap_t pixmap = xcb_generate_id(c);
|
|
|
|
xcb_gcontext_t gc = xcb_generate_id(c);
|
|
|
|
|
|
|
|
xcb_create_pixmap(c, image.depth(), pixmap, effects->x11RootWindow(),
|
|
|
|
image.width(), image.height());
|
|
|
|
xcb_create_gc(c, gc, pixmap, 0, nullptr);
|
|
|
|
|
|
|
|
const int bytesPerPixel = image.depth() >> 3;
|
|
|
|
|
|
|
|
// Figure out how much data we can send with one invocation of xcb_put_image.
|
|
|
|
// In contrast to XPutImage, xcb_put_image doesn't implicitly split the data.
|
|
|
|
const QSize window = pickWindowSize(image);
|
|
|
|
|
|
|
|
for (int i = 0; i < image.height(); i += window.height()) {
|
|
|
|
const int targetHeight = qMin(image.height() - i, window.height());
|
|
|
|
const uint8_t *line = image.scanLine(i);
|
|
|
|
|
|
|
|
for (int j = 0; j < image.width(); j += window.width()) {
|
|
|
|
const int targetWidth = qMin(image.width() - j, window.width());
|
|
|
|
const uint8_t *bytes = line + j * bytesPerPixel;
|
|
|
|
const uint32_t byteCount = targetWidth * targetHeight * bytesPerPixel;
|
|
|
|
|
|
|
|
xcb_put_image(c, XCB_IMAGE_FORMAT_Z_PIXMAP, pixmap,
|
|
|
|
gc, targetWidth, targetHeight, j, i, 0, image.depth(),
|
|
|
|
byteCount, bytes);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
xcb_flush(c);
|
|
|
|
xcb_free_gc(c, gc);
|
|
|
|
|
|
|
|
return pixmap;
|
|
|
|
}
|
|
|
|
|
2019-10-29 22:04:15 +00:00
|
|
|
void ScreenShotEffect::paintScreen(int mask, const QRegion ®ion, ScreenPaintData &data)
|
2016-10-14 13:53:02 +00:00
|
|
|
{
|
|
|
|
m_cachedOutputGeometry = data.outputGeometry();
|
2020-04-22 09:31:46 +00:00
|
|
|
// When taking a non-nativeSize fullscreenshot, pretend we have a uniform 1.0 ratio
|
|
|
|
// so the screenshot size will match the virtualGeometry
|
|
|
|
m_cachedScale = m_nativeSize ? data.screenScale() : 1.0;
|
2016-10-14 13:53:02 +00:00
|
|
|
effects->paintScreen(mask, region, data);
|
|
|
|
}
|
|
|
|
|
2020-04-22 09:31:46 +00:00
|
|
|
/**
|
|
|
|
* Translates the Point coordinates in m_cacheOutputsImages keys from the virtualGeometry
|
|
|
|
* To a new geometry taking into account the real size of the images (virtualSize * dpr),
|
|
|
|
* moving the siblings images on the right bottom of the image as necessary
|
|
|
|
*/
|
|
|
|
void ScreenShotEffect::computeCoordinatesAfterScaling()
|
|
|
|
{
|
|
|
|
// prepare a translation table that will store oldPoint -> newPoint in the new coordinates
|
|
|
|
QMap<ComparableQPoint, ComparableQPoint> translationMap;
|
|
|
|
for (auto i = m_cacheOutputsImages.keyBegin(); i != m_cacheOutputsImages.keyEnd(); ++i) {
|
|
|
|
translationMap.insert(*i, *i);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto i = m_cacheOutputsImages.constBegin(); i != m_cacheOutputsImages.constEnd(); ++i) {
|
|
|
|
const auto p = i.key();
|
|
|
|
const auto img = i.value();
|
|
|
|
const auto dpr = img.devicePixelRatio();
|
|
|
|
if (!qFuzzyCompare(dpr, 1.0)) {
|
|
|
|
// must update all coordinates of next rects
|
|
|
|
const int deltaX = img.width() - (img.width() / dpr);
|
|
|
|
const int deltaY = img.height() - (img.height() / dpr);
|
|
|
|
|
|
|
|
// for the next images on the right or bottom
|
|
|
|
// thanks to ComparableQPoint
|
|
|
|
for (auto i2 = m_cacheOutputsImages.constFind(p);
|
|
|
|
i2 != m_cacheOutputsImages.constEnd(); ++i2) {
|
|
|
|
|
|
|
|
const auto point = i2.key();
|
|
|
|
auto finalPoint = translationMap.value(point);
|
|
|
|
|
|
|
|
if (point.x() >= img.width() + p.x() - deltaX) {
|
|
|
|
finalPoint.setX(finalPoint.x() + deltaX);
|
|
|
|
}
|
|
|
|
if (point.y() >= img.height() + p.y() - deltaY) {
|
|
|
|
finalPoint.setY(finalPoint.y() + deltaY);
|
|
|
|
}
|
|
|
|
// update final position point with the necessary deltas
|
|
|
|
translationMap.insert(point, finalPoint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// make the new coordinates effective
|
|
|
|
for (auto i = translationMap.keyBegin(); i != translationMap.keyEnd(); ++i) {
|
|
|
|
const auto key = *i;
|
|
|
|
const auto img = m_cacheOutputsImages.take(key);
|
|
|
|
m_cacheOutputsImages.insert(translationMap.value(key), img);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-31 20:55:48 +00:00
|
|
|
void ScreenShotEffect::postPaintScreen()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2010-07-31 20:55:48 +00:00
|
|
|
effects->postPaintScreen();
|
2011-01-30 14:34:42 +00:00
|
|
|
if (m_scheduledScreenshot) {
|
2013-01-08 09:46:10 +00:00
|
|
|
WindowPaintData d(m_scheduledScreenshot);
|
|
|
|
double left = 0;
|
|
|
|
double top = 0;
|
|
|
|
double right = m_scheduledScreenshot->width();
|
|
|
|
double bottom = m_scheduledScreenshot->height();
|
|
|
|
if (m_scheduledScreenshot->hasDecoration() && m_type & INCLUDE_DECORATION) {
|
2020-08-19 12:56:19 +00:00
|
|
|
for (const WindowQuad &quad : qAsConst(d.quads)) {
|
2013-01-08 09:46:10 +00:00
|
|
|
// we need this loop to include the decoration padding
|
|
|
|
left = qMin(left, quad.left());
|
|
|
|
top = qMin(top, quad.top());
|
|
|
|
right = qMax(right, quad.right());
|
|
|
|
bottom = qMax(bottom, quad.bottom());
|
|
|
|
}
|
|
|
|
} else if (m_scheduledScreenshot->hasDecoration()) {
|
|
|
|
WindowQuadList newQuads;
|
|
|
|
left = m_scheduledScreenshot->width();
|
|
|
|
top = m_scheduledScreenshot->height();
|
|
|
|
right = 0;
|
|
|
|
bottom = 0;
|
2020-08-19 12:56:19 +00:00
|
|
|
for (const WindowQuad &quad : qAsConst(d.quads)) {
|
2013-01-08 09:46:10 +00:00
|
|
|
if (quad.type() == WindowQuadContents) {
|
|
|
|
newQuads << quad;
|
|
|
|
left = qMin(left, quad.left());
|
|
|
|
top = qMin(top, quad.top());
|
|
|
|
right = qMax(right, quad.right());
|
|
|
|
bottom = qMax(bottom, quad.bottom());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
d.quads = newQuads;
|
|
|
|
}
|
|
|
|
const int width = right - left;
|
|
|
|
const int height = bottom - top;
|
2012-03-04 08:53:12 +00:00
|
|
|
bool validTarget = true;
|
2013-01-08 09:46:10 +00:00
|
|
|
QScopedPointer<GLTexture> offscreenTexture;
|
|
|
|
QScopedPointer<GLRenderTarget> target;
|
2012-09-20 09:33:32 +00:00
|
|
|
if (effects->isOpenGLCompositing()) {
|
2014-12-13 13:28:33 +00:00
|
|
|
offscreenTexture.reset(new GLTexture(GL_RGBA8, width, height));
|
2012-03-04 08:53:12 +00:00
|
|
|
offscreenTexture->setFilter(GL_LINEAR);
|
|
|
|
offscreenTexture->setWrapMode(GL_CLAMP_TO_EDGE);
|
2013-01-08 09:46:10 +00:00
|
|
|
target.reset(new GLRenderTarget(*offscreenTexture));
|
2012-03-04 08:53:12 +00:00
|
|
|
validTarget = target->valid();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2012-03-04 08:53:12 +00:00
|
|
|
if (validTarget) {
|
2012-05-28 12:45:46 +00:00
|
|
|
d.setXTranslation(-m_scheduledScreenshot->x() - left);
|
|
|
|
d.setYTranslation(-m_scheduledScreenshot->y() - top);
|
2012-03-04 08:53:12 +00:00
|
|
|
|
2010-07-31 20:55:48 +00:00
|
|
|
// render window into offscreen texture
|
|
|
|
int mask = PAINT_WINDOW_TRANSFORMED | PAINT_WINDOW_TRANSLUCENT;
|
2012-03-04 08:53:12 +00:00
|
|
|
QImage img;
|
2012-09-20 09:33:32 +00:00
|
|
|
if (effects->isOpenGLCompositing()) {
|
2013-01-08 09:46:10 +00:00
|
|
|
GLRenderTarget::pushRenderTarget(target.data());
|
2012-03-04 08:53:12 +00:00
|
|
|
glClearColor(0.0, 0.0, 0.0, 0.0);
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
glClearColor(0.0, 0.0, 0.0, 1.0);
|
2014-04-01 16:09:02 +00:00
|
|
|
|
|
|
|
QMatrix4x4 projection;
|
|
|
|
projection.ortho(QRect(0, 0, offscreenTexture->width(), offscreenTexture->height()));
|
|
|
|
d.setProjectionMatrix(projection);
|
|
|
|
|
2013-01-08 09:46:10 +00:00
|
|
|
effects->drawWindow(m_scheduledScreenshot, mask, infiniteRegion(), d);
|
2014-04-01 16:09:02 +00:00
|
|
|
|
2012-03-04 08:53:12 +00:00
|
|
|
// copy content from framebuffer into image
|
|
|
|
img = QImage(QSize(width, height), QImage::Format_ARGB32);
|
2019-07-09 21:10:56 +00:00
|
|
|
glReadnPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, img.sizeInBytes(), (GLvoid*)img.bits());
|
2012-03-04 08:53:12 +00:00
|
|
|
GLRenderTarget::popRenderTarget();
|
|
|
|
ScreenShotEffect::convertFromGLImage(img, width, height);
|
|
|
|
}
|
2012-03-24 07:08:12 +00:00
|
|
|
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
|
Use nullptr everywhere
Summary:
Because KWin is a very old project, we use three kinds of null pointer
literals: 0, NULL, and nullptr. Since C++11, it's recommended to use
nullptr keyword.
This change converts all usages of 0 and NULL literal to nullptr. Even
though it breaks git history, we need to do it in order to have consistent
code as well to ease code reviews (it's very tempting for some people to
add unrelated changes to their patches, e.g. converting NULL to nullptr).
Test Plan: Compiles.
Reviewers: #kwin, davidedmundson, romangg
Reviewed By: #kwin, davidedmundson, romangg
Subscribers: romangg, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D23618
2019-09-19 14:46:54 +00:00
|
|
|
xcb_image_t *xImage = nullptr;
|
2012-03-04 08:53:12 +00:00
|
|
|
if (effects->compositingType() == XRenderCompositing) {
|
|
|
|
setXRenderOffscreen(true);
|
|
|
|
effects->drawWindow(m_scheduledScreenshot, mask, QRegion(0, 0, width, height), d);
|
2013-02-11 20:01:41 +00:00
|
|
|
if (xRenderOffscreenTarget()) {
|
2013-02-13 07:10:55 +00:00
|
|
|
img = xPictureToImage(xRenderOffscreenTarget(), QRect(0, 0, width, height), &xImage);
|
2013-02-11 20:01:41 +00:00
|
|
|
}
|
2012-03-04 08:53:12 +00:00
|
|
|
setXRenderOffscreen(false);
|
|
|
|
}
|
2012-03-24 07:08:12 +00:00
|
|
|
#endif
|
2012-03-04 08:53:12 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (m_type & INCLUDE_CURSOR) {
|
|
|
|
grabPointerImage(img, m_scheduledScreenshot->x() + left, m_scheduledScreenshot->y() + top);
|
2010-07-31 20:55:48 +00:00
|
|
|
}
|
2012-03-04 08:53:12 +00:00
|
|
|
|
2016-11-15 14:40:30 +00:00
|
|
|
if (m_windowMode == WindowMode::Xpixmap) {
|
2019-05-23 18:21:11 +00:00
|
|
|
const xcb_pixmap_t xpix = xpixmapFromImage(img);
|
2016-11-15 14:40:30 +00:00
|
|
|
emit screenshotCreated(xpix);
|
|
|
|
m_windowMode = WindowMode::NoCapture;
|
2020-08-12 13:41:30 +00:00
|
|
|
} else if (m_windowMode == WindowMode::File || m_windowMode == WindowMode::FileDescriptor) {
|
2016-11-15 14:40:30 +00:00
|
|
|
sendReplyImage(img);
|
|
|
|
}
|
2013-02-13 07:10:55 +00:00
|
|
|
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
|
|
|
|
if (xImage) {
|
|
|
|
xcb_image_destroy(xImage);
|
2011-05-12 16:52:38 +00:00
|
|
|
}
|
2013-02-13 07:10:55 +00:00
|
|
|
#endif
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
Use nullptr everywhere
Summary:
Because KWin is a very old project, we use three kinds of null pointer
literals: 0, NULL, and nullptr. Since C++11, it's recommended to use
nullptr keyword.
This change converts all usages of 0 and NULL literal to nullptr. Even
though it breaks git history, we need to do it in order to have consistent
code as well to ease code reviews (it's very tempting for some people to
add unrelated changes to their patches, e.g. converting NULL to nullptr).
Test Plan: Compiles.
Reviewers: #kwin, davidedmundson, romangg
Reviewed By: #kwin, davidedmundson, romangg
Subscribers: romangg, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D23618
2019-09-19 14:46:54 +00:00
|
|
|
m_scheduledScreenshot = nullptr;
|
2010-07-31 20:55:48 +00:00
|
|
|
}
|
2016-10-14 09:34:56 +00:00
|
|
|
|
|
|
|
if (!m_scheduledGeometry.isNull()) {
|
2016-10-14 13:53:02 +00:00
|
|
|
if (!m_cachedOutputGeometry.isNull()) {
|
|
|
|
// special handling for per-output geometry rendering
|
|
|
|
const QRect intersection = m_scheduledGeometry.intersected(m_cachedOutputGeometry);
|
|
|
|
if (intersection.isEmpty()) {
|
|
|
|
// doesn't intersect, not going onto this screenshot
|
|
|
|
return;
|
|
|
|
}
|
2020-04-20 14:11:21 +00:00
|
|
|
QImage img = blitScreenshot(intersection, m_cachedScale);
|
|
|
|
if (img.size() == (m_scheduledGeometry.size() * m_cachedScale)) {
|
2016-10-14 13:53:02 +00:00
|
|
|
// we are done
|
|
|
|
sendReplyImage(img);
|
|
|
|
return;
|
|
|
|
}
|
2020-04-20 14:11:21 +00:00
|
|
|
img.setDevicePixelRatio(m_cachedScale);
|
2020-04-22 09:31:46 +00:00
|
|
|
|
|
|
|
m_cacheOutputsImages.insert(ComparableQPoint(m_cachedOutputGeometry.topLeft()), img);
|
|
|
|
|
2016-10-14 13:53:02 +00:00
|
|
|
m_multipleOutputsRendered = m_multipleOutputsRendered.united(intersection);
|
|
|
|
if (m_multipleOutputsRendered.boundingRect() == m_scheduledGeometry) {
|
2020-04-22 09:31:46 +00:00
|
|
|
|
2020-08-26 16:21:54 +00:00
|
|
|
if (m_orderImg.isEmpty()) {
|
|
|
|
// Recompute coordinates
|
|
|
|
if (m_nativeSize) {
|
|
|
|
computeCoordinatesAfterScaling();
|
|
|
|
}
|
|
|
|
|
|
|
|
// find the output image size
|
|
|
|
int width = 0;
|
|
|
|
int height = 0;
|
|
|
|
QMap<ComparableQPoint, QImage>::const_iterator i;
|
|
|
|
for (i = m_cacheOutputsImages.constBegin(); i != m_cacheOutputsImages.constEnd(); ++i) {
|
|
|
|
const auto pos = i.key();
|
|
|
|
const auto img = i.value();
|
|
|
|
|
|
|
|
width = qMax(width, pos.x() + img.width());
|
|
|
|
height = qMax(height, pos.y() + img.height());
|
|
|
|
}
|
|
|
|
|
|
|
|
QImage multipleOutputsImage = QImage(width, height, QImage::Format_ARGB32);
|
|
|
|
|
|
|
|
QPainter p;
|
|
|
|
p.begin(&multipleOutputsImage);
|
|
|
|
|
|
|
|
// reassemble images together
|
|
|
|
for (i = m_cacheOutputsImages.constBegin(); i != m_cacheOutputsImages.constEnd(); ++i) {
|
|
|
|
auto pos = i.key();
|
|
|
|
auto img = i.value();
|
|
|
|
// disable dpr rendering, we already took care of this
|
|
|
|
img.setDevicePixelRatio(1.0);
|
|
|
|
p.drawImage(pos, img);
|
|
|
|
}
|
|
|
|
p.end();
|
|
|
|
|
|
|
|
sendReplyImage(multipleOutputsImage);
|
|
|
|
} else {
|
|
|
|
sendReplyImages();
|
2020-04-22 09:31:46 +00:00
|
|
|
}
|
2016-10-14 13:53:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
const QImage img = blitScreenshot(m_scheduledGeometry);
|
|
|
|
sendReplyImage(img);
|
|
|
|
}
|
2016-10-14 09:34:56 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-07-31 20:55:48 +00:00
|
|
|
|
2016-10-14 13:53:02 +00:00
|
|
|
void ScreenShotEffect::sendReplyImage(const QImage &img)
|
|
|
|
{
|
2016-11-23 14:53:17 +00:00
|
|
|
if (m_fd != -1) {
|
|
|
|
QtConcurrent::run(
|
|
|
|
[] (int fd, const QImage &img) {
|
|
|
|
QFile file;
|
|
|
|
if (file.open(fd, QIODevice::WriteOnly, QFileDevice::AutoCloseHandle)) {
|
|
|
|
QDataStream ds(&file);
|
|
|
|
ds << img;
|
|
|
|
file.close();
|
|
|
|
} else {
|
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
}, m_fd, img);
|
|
|
|
} else {
|
2016-11-25 07:50:02 +00:00
|
|
|
QDBusConnection::sessionBus().send(m_replyMessage.createReply(saveTempImage(img)));
|
2016-11-23 14:53:17 +00:00
|
|
|
}
|
2020-08-26 16:21:54 +00:00
|
|
|
|
|
|
|
clearState();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScreenShotEffect::sendReplyImages()
|
|
|
|
{
|
|
|
|
QList<QImage> outputImages;
|
|
|
|
for (const QPoint &pos : qAsConst(m_orderImg)) {
|
2020-10-02 21:18:43 +00:00
|
|
|
auto it = m_cacheOutputsImages.constFind(pos);
|
2020-08-26 16:21:54 +00:00
|
|
|
if (it != m_cacheOutputsImages.constEnd()) {
|
|
|
|
outputImages.append(*it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
QtConcurrent::run(
|
|
|
|
[] (int fd, const QList<QImage> &outputImages) {
|
|
|
|
QFile file;
|
|
|
|
if (file.open(fd, QIODevice::WriteOnly, QFileDevice::AutoCloseHandle)) {
|
|
|
|
QDataStream ds(&file);
|
|
|
|
ds.setVersion(QDataStream::Qt_DefaultCompiledVersion);
|
|
|
|
ds << outputImages;
|
|
|
|
file.close();
|
|
|
|
} else {
|
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
}, m_fd, outputImages);
|
|
|
|
|
|
|
|
clearState();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScreenShotEffect::clearState()
|
|
|
|
{
|
|
|
|
m_fd = -1;
|
2016-10-14 13:53:02 +00:00
|
|
|
m_scheduledGeometry = QRect();
|
|
|
|
m_multipleOutputsRendered = QRegion();
|
2016-10-20 06:29:48 +00:00
|
|
|
m_captureCursor = false;
|
2016-11-15 14:40:30 +00:00
|
|
|
m_windowMode = WindowMode::NoCapture;
|
2020-04-22 09:31:46 +00:00
|
|
|
m_cacheOutputsImages.clear();
|
|
|
|
m_cachedOutputGeometry = QRect();
|
2020-08-19 10:23:39 +00:00
|
|
|
m_nativeSize = false;
|
2020-08-26 16:21:54 +00:00
|
|
|
m_orderImg.clear();
|
2016-10-14 13:53:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QString ScreenShotEffect::saveTempImage(const QImage &img)
|
|
|
|
{
|
|
|
|
if (img.isNull()) {
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
QTemporaryFile temp(QDir::tempPath() + QDir::separator() + QLatin1String("kwin_screenshot_XXXXXX.png"));
|
|
|
|
temp.setAutoRemove(false);
|
|
|
|
if (!temp.open()) {
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
img.save(&temp);
|
|
|
|
temp.close();
|
2016-11-16 08:50:18 +00:00
|
|
|
KNotification::event(KNotification::Notification,
|
|
|
|
i18nc("Notification caption that a screenshot got saved to file", "Screenshot"),
|
|
|
|
i18nc("Notification with path to screenshot file", "Screenshot saved to %1", temp.fileName()),
|
|
|
|
QStringLiteral("spectacle"));
|
2016-10-14 13:53:02 +00:00
|
|
|
return temp.fileName();
|
|
|
|
}
|
|
|
|
|
2010-09-14 19:52:44 +00:00
|
|
|
void ScreenShotEffect::screenshotWindowUnderCursor(int mask)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2016-11-25 07:50:02 +00:00
|
|
|
if (isTakingScreenshot()) {
|
|
|
|
sendErrorReply(s_errorAlreadyTaking, s_errorAlreadyTakingMsg);
|
|
|
|
return;
|
|
|
|
}
|
2010-09-14 19:52:44 +00:00
|
|
|
m_type = (ScreenShotType)mask;
|
|
|
|
const QPoint cursor = effects->cursorPos();
|
2011-12-07 14:04:11 +00:00
|
|
|
EffectWindowList order = effects->stackingOrder();
|
|
|
|
EffectWindowList::const_iterator it = order.constEnd(), first = order.constBegin();
|
|
|
|
while( it != first ) {
|
|
|
|
m_scheduledScreenshot = *(--it);
|
|
|
|
if (m_scheduledScreenshot->isOnCurrentDesktop() &&
|
|
|
|
!m_scheduledScreenshot->isMinimized() && !m_scheduledScreenshot->isDeleted() &&
|
|
|
|
m_scheduledScreenshot->geometry().contains(cursor))
|
|
|
|
break;
|
Use nullptr everywhere
Summary:
Because KWin is a very old project, we use three kinds of null pointer
literals: 0, NULL, and nullptr. Since C++11, it's recommended to use
nullptr keyword.
This change converts all usages of 0 and NULL literal to nullptr. Even
though it breaks git history, we need to do it in order to have consistent
code as well to ease code reviews (it's very tempting for some people to
add unrelated changes to their patches, e.g. converting NULL to nullptr).
Test Plan: Compiles.
Reviewers: #kwin, davidedmundson, romangg
Reviewed By: #kwin, davidedmundson, romangg
Subscribers: romangg, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D23618
2019-09-19 14:46:54 +00:00
|
|
|
m_scheduledScreenshot = nullptr;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
if (m_scheduledScreenshot) {
|
2019-03-05 21:59:44 +00:00
|
|
|
m_windowMode = WindowMode::Xpixmap;
|
2010-09-14 19:52:44 +00:00
|
|
|
m_scheduledScreenshot->addRepaintFull();
|
2010-07-31 20:55:48 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2011-08-17 17:20:15 +00:00
|
|
|
|
2012-04-12 11:13:49 +00:00
|
|
|
void ScreenShotEffect::screenshotForWindow(qulonglong winid, int mask)
|
|
|
|
{
|
|
|
|
m_type = (ScreenShotType) mask;
|
|
|
|
EffectWindow* w = effects->findWindow(winid);
|
|
|
|
if(w && !w->isMinimized() && !w->isDeleted()) {
|
2016-11-15 14:40:30 +00:00
|
|
|
m_windowMode = WindowMode::Xpixmap;
|
2012-04-12 11:13:49 +00:00
|
|
|
m_scheduledScreenshot = w;
|
|
|
|
m_scheduledScreenshot->addRepaintFull();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-16 16:59:59 +00:00
|
|
|
bool ScreenShotEffect::checkCall() const
|
2016-11-15 14:40:30 +00:00
|
|
|
{
|
|
|
|
if (!calledFromDBus()) {
|
2020-06-16 16:59:59 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QDBusReply<uint> reply = connection().interface()->servicePid(message().service());
|
|
|
|
if (reply.isValid()) {
|
|
|
|
const uint pid = reply.value();
|
|
|
|
const auto interfaces = KWin::fetchRestrictedDBusInterfacesFromPid(pid);
|
|
|
|
if (!interfaces.contains(s_dbusInterfaceName)) {
|
|
|
|
sendErrorReply(s_errorNotAuthorized, s_errorNotAuthorizedMsg);
|
|
|
|
qCWarning(KWINEFFECTS) << "Process " << pid << " tried to take a screenshot without being granted to DBus interface" << s_dbusInterfaceName;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return false;
|
2016-11-15 14:40:30 +00:00
|
|
|
}
|
2020-06-16 16:59:59 +00:00
|
|
|
|
2016-11-25 07:50:02 +00:00
|
|
|
if (isTakingScreenshot()) {
|
|
|
|
sendErrorReply(s_errorAlreadyTaking, s_errorAlreadyTakingMsg);
|
2020-06-16 16:59:59 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString ScreenShotEffect::interactive(int mask)
|
|
|
|
{
|
2020-10-22 09:58:36 +00:00
|
|
|
if (!calledFromDBus()) {
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
if (isTakingScreenshot()) {
|
|
|
|
sendErrorReply(s_errorAlreadyTaking, s_errorAlreadyTakingMsg);
|
2016-11-15 14:40:30 +00:00
|
|
|
return QString();
|
|
|
|
}
|
2020-10-22 09:58:36 +00:00
|
|
|
|
2016-11-15 14:40:30 +00:00
|
|
|
m_type = (ScreenShotType) mask;
|
|
|
|
m_windowMode = WindowMode::File;
|
|
|
|
m_replyMessage = message();
|
|
|
|
setDelayedReply(true);
|
|
|
|
effects->startInteractiveWindowSelection(
|
|
|
|
[this] (EffectWindow *w) {
|
2016-11-18 09:02:04 +00:00
|
|
|
hideInfoMessage();
|
2016-11-15 14:40:30 +00:00
|
|
|
if (!w) {
|
2016-11-25 07:50:02 +00:00
|
|
|
QDBusConnection::sessionBus().send(m_replyMessage.createErrorReply(s_errorCancelled, s_errorCancelledMsg));
|
2016-11-15 14:40:30 +00:00
|
|
|
m_windowMode = WindowMode::NoCapture;
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
m_scheduledScreenshot = w;
|
|
|
|
m_scheduledScreenshot->addRepaintFull();
|
|
|
|
}
|
|
|
|
});
|
2016-11-17 15:12:28 +00:00
|
|
|
|
2016-11-23 14:53:17 +00:00
|
|
|
showInfoMessage(InfoMessageMode::Window);
|
2016-11-18 09:02:04 +00:00
|
|
|
return QString();
|
|
|
|
}
|
2016-11-17 15:12:28 +00:00
|
|
|
|
2016-11-18 09:02:04 +00:00
|
|
|
void ScreenShotEffect::interactive(QDBusUnixFileDescriptor fd, int mask)
|
|
|
|
{
|
2020-10-22 09:58:36 +00:00
|
|
|
if (!calledFromDBus()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (isTakingScreenshot()) {
|
|
|
|
sendErrorReply(s_errorAlreadyTaking, s_errorAlreadyTakingMsg);
|
2016-11-18 09:02:04 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-10-22 09:58:36 +00:00
|
|
|
|
2016-11-18 09:02:04 +00:00
|
|
|
m_fd = dup(fd.fileDescriptor());
|
|
|
|
if (m_fd == -1) {
|
2016-11-25 07:50:02 +00:00
|
|
|
sendErrorReply(s_errorFd, s_errorFdMsg);
|
2016-11-18 09:02:04 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_type = (ScreenShotType) mask;
|
|
|
|
m_windowMode = WindowMode::FileDescriptor;
|
|
|
|
|
|
|
|
effects->startInteractiveWindowSelection(
|
|
|
|
[this] (EffectWindow *w) {
|
|
|
|
hideInfoMessage();
|
|
|
|
if (!w) {
|
|
|
|
close(m_fd);
|
|
|
|
m_fd = -1;
|
|
|
|
m_windowMode = WindowMode::NoCapture;
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
m_scheduledScreenshot = w;
|
|
|
|
m_scheduledScreenshot->addRepaintFull();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-11-23 14:53:17 +00:00
|
|
|
showInfoMessage(InfoMessageMode::Window);
|
2016-11-18 09:02:04 +00:00
|
|
|
}
|
|
|
|
|
2016-11-23 14:53:17 +00:00
|
|
|
void ScreenShotEffect::showInfoMessage(InfoMessageMode mode)
|
2016-11-18 09:02:04 +00:00
|
|
|
{
|
2017-01-11 19:14:36 +00:00
|
|
|
QString text;
|
2016-11-23 14:53:17 +00:00
|
|
|
switch (mode) {
|
|
|
|
case InfoMessageMode::Window:
|
2017-01-11 19:14:36 +00:00
|
|
|
text = i18n("Select window to screen shot with left click or enter.\nEscape or right click to cancel.");
|
2016-11-23 14:53:17 +00:00
|
|
|
break;
|
|
|
|
case InfoMessageMode::Screen:
|
2017-01-11 19:14:36 +00:00
|
|
|
text = i18n("Create screen shot with left click or enter.\nEscape or right click to cancel.");
|
2016-11-23 14:53:17 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-01-11 19:14:36 +00:00
|
|
|
effects->showOnScreenMessage(text, QStringLiteral("spectacle"));
|
2016-11-18 09:02:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScreenShotEffect::hideInfoMessage()
|
|
|
|
{
|
2017-01-11 19:14:36 +00:00
|
|
|
effects->hideOnScreenMessage(EffectsHandler::OnScreenMessageHideFlag::SkipsCloseAnimation);
|
2016-11-15 14:40:30 +00:00
|
|
|
}
|
|
|
|
|
2016-10-20 06:29:48 +00:00
|
|
|
QString ScreenShotEffect::screenshotFullscreen(bool captureCursor)
|
2011-08-17 17:20:15 +00:00
|
|
|
{
|
2020-06-16 16:59:59 +00:00
|
|
|
if (!checkCall()) {
|
2016-10-14 09:34:56 +00:00
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
m_replyMessage = message();
|
|
|
|
setDelayedReply(true);
|
|
|
|
m_scheduledGeometry = effects->virtualScreenGeometry();
|
2016-10-20 06:29:48 +00:00
|
|
|
m_captureCursor = captureCursor;
|
2016-10-14 09:34:56 +00:00
|
|
|
effects->addRepaintFull();
|
|
|
|
return QString();
|
2011-08-17 17:20:15 +00:00
|
|
|
}
|
|
|
|
|
2020-04-22 09:31:46 +00:00
|
|
|
void ScreenShotEffect::screenshotFullscreen(QDBusUnixFileDescriptor fd, bool captureCursor, bool shouldReturnNativeSize)
|
2016-11-23 14:53:17 +00:00
|
|
|
{
|
2020-06-16 16:59:59 +00:00
|
|
|
if (!checkCall()) {
|
2016-11-23 14:53:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_fd = dup(fd.fileDescriptor());
|
|
|
|
if (m_fd == -1) {
|
2016-11-25 07:50:02 +00:00
|
|
|
sendErrorReply(s_errorFd, s_errorFdMsg);
|
2016-11-23 14:53:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_captureCursor = captureCursor;
|
2020-04-22 09:31:46 +00:00
|
|
|
m_nativeSize = shouldReturnNativeSize;
|
2016-11-23 14:53:17 +00:00
|
|
|
|
2020-06-16 16:59:59 +00:00
|
|
|
m_scheduledGeometry = effects->virtualScreenGeometry();
|
|
|
|
effects->addRepaint(m_scheduledGeometry);
|
2016-11-23 14:53:17 +00:00
|
|
|
}
|
|
|
|
|
2016-10-20 06:29:48 +00:00
|
|
|
QString ScreenShotEffect::screenshotScreen(int screen, bool captureCursor)
|
2011-08-17 17:20:15 +00:00
|
|
|
{
|
2020-06-16 16:59:59 +00:00
|
|
|
if (!checkCall()) {
|
2016-10-14 09:34:56 +00:00
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
m_scheduledGeometry = effects->clientArea(FullScreenArea, screen, 0);
|
|
|
|
if (m_scheduledGeometry.isNull()) {
|
2016-11-25 07:50:02 +00:00
|
|
|
sendErrorReply(s_errorInvalidScreen, s_errorInvalidScreenMsg);
|
2016-10-14 09:34:56 +00:00
|
|
|
return QString();
|
|
|
|
}
|
2016-10-20 06:29:48 +00:00
|
|
|
m_captureCursor = captureCursor;
|
2020-08-19 10:23:39 +00:00
|
|
|
m_nativeSize = true;
|
2016-10-14 09:34:56 +00:00
|
|
|
m_replyMessage = message();
|
|
|
|
setDelayedReply(true);
|
|
|
|
effects->addRepaint(m_scheduledGeometry);
|
|
|
|
return QString();
|
2011-08-17 17:20:15 +00:00
|
|
|
}
|
|
|
|
|
2016-11-23 14:53:17 +00:00
|
|
|
void ScreenShotEffect::screenshotScreen(QDBusUnixFileDescriptor fd, bool captureCursor)
|
|
|
|
{
|
2020-06-16 16:59:59 +00:00
|
|
|
if (!checkCall()) {
|
2016-11-23 14:53:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_fd = dup(fd.fileDescriptor());
|
|
|
|
if (m_fd == -1) {
|
2016-11-25 07:50:02 +00:00
|
|
|
sendErrorReply(s_errorFd, s_errorFdMsg);
|
2016-11-23 14:53:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_captureCursor = captureCursor;
|
2020-09-07 08:00:29 +00:00
|
|
|
m_nativeSize = true;
|
2016-11-23 14:53:17 +00:00
|
|
|
|
|
|
|
showInfoMessage(InfoMessageMode::Screen);
|
|
|
|
effects->startInteractivePositionSelection(
|
|
|
|
[this] (const QPoint &p) {
|
|
|
|
hideInfoMessage();
|
|
|
|
if (p == QPoint(-1, -1)) {
|
|
|
|
// error condition
|
|
|
|
close(m_fd);
|
|
|
|
m_fd = -1;
|
|
|
|
} else {
|
|
|
|
m_scheduledGeometry = effects->clientArea(FullScreenArea, effects->screenNumber(p), 0);
|
|
|
|
if (m_scheduledGeometry.isNull()) {
|
|
|
|
close(m_fd);
|
|
|
|
m_fd = -1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
effects->addRepaint(m_scheduledGeometry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-08-26 16:21:54 +00:00
|
|
|
void ScreenShotEffect::screenshotScreens(QDBusUnixFileDescriptor fd, const QStringList &screensNames, bool captureCursor, bool shouldReturnNativeSize)
|
|
|
|
{
|
|
|
|
if (!checkCall()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_fd = dup(fd.fileDescriptor());
|
|
|
|
if (m_fd == -1) {
|
|
|
|
sendErrorReply(s_errorFd, s_errorFdMsg);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_captureCursor = captureCursor;
|
|
|
|
m_nativeSize = shouldReturnNativeSize;
|
|
|
|
m_orderImg = QList<QPoint>();
|
|
|
|
m_scheduledGeometry = QRect();
|
|
|
|
|
|
|
|
const QList<QScreen *> screens = QGuiApplication::screens();
|
|
|
|
|
|
|
|
for (const QScreen *screen : screens) {
|
2020-10-06 15:07:05 +00:00
|
|
|
const int indexName = screensNames.indexOf(screen->name());
|
2020-08-26 16:21:54 +00:00
|
|
|
if (indexName != -1) {
|
|
|
|
const auto screenGeom = screen->geometry();
|
|
|
|
if (!screenGeom.isValid()) {
|
|
|
|
close(m_fd);
|
|
|
|
clearState();
|
|
|
|
sendErrorReply(s_errorScreenMissing, s_errorScreenMissingMsg + " : " + screen->name());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_scheduledGeometry = m_scheduledGeometry.united(screenGeom);
|
|
|
|
m_orderImg.insert(indexName, screenGeom.topLeft());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-06 15:07:05 +00:00
|
|
|
if (m_orderImg.size() != screensNames.size()) {
|
2020-08-26 16:21:54 +00:00
|
|
|
close(m_fd);
|
|
|
|
clearState();
|
2020-10-06 15:07:05 +00:00
|
|
|
sendErrorReply(s_errorScreenMissing, s_errorScreenMissingMsg);
|
2020-08-26 16:21:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
effects->addRepaint(m_scheduledGeometry);
|
|
|
|
}
|
|
|
|
|
2016-10-20 06:29:48 +00:00
|
|
|
QString ScreenShotEffect::screenshotArea(int x, int y, int width, int height, bool captureCursor)
|
2011-08-17 17:20:15 +00:00
|
|
|
{
|
2020-06-16 16:59:59 +00:00
|
|
|
if (!checkCall()) {
|
2016-10-14 09:34:56 +00:00
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
m_scheduledGeometry = QRect(x, y, width, height);
|
|
|
|
if (m_scheduledGeometry.isNull() || m_scheduledGeometry.isEmpty()) {
|
|
|
|
m_scheduledGeometry = QRect();
|
2016-11-25 07:50:02 +00:00
|
|
|
sendErrorReply(s_errorInvalidArea, s_errorInvalidAreaMsg);
|
2016-10-14 09:34:56 +00:00
|
|
|
return QString();
|
|
|
|
}
|
2016-10-20 06:29:48 +00:00
|
|
|
m_captureCursor = captureCursor;
|
2016-10-14 09:34:56 +00:00
|
|
|
m_replyMessage = message();
|
|
|
|
setDelayedReply(true);
|
|
|
|
effects->addRepaint(m_scheduledGeometry);
|
|
|
|
return QString();
|
2011-08-17 17:20:15 +00:00
|
|
|
}
|
|
|
|
|
2020-04-20 14:11:21 +00:00
|
|
|
QImage ScreenShotEffect::blitScreenshot(const QRect &geometry, const qreal scale)
|
2011-08-17 17:20:15 +00:00
|
|
|
{
|
2012-03-04 08:53:12 +00:00
|
|
|
QImage img;
|
2012-09-20 09:33:32 +00:00
|
|
|
if (effects->isOpenGLCompositing())
|
2012-03-04 08:53:12 +00:00
|
|
|
{
|
2020-04-20 14:11:21 +00:00
|
|
|
int width = geometry.width();
|
|
|
|
int height = geometry.height();
|
2018-11-10 12:32:18 +00:00
|
|
|
if (GLRenderTarget::blitSupported() && !GLPlatform::instance()->isGLES()) {
|
2020-04-20 14:11:21 +00:00
|
|
|
|
|
|
|
width = static_cast<int>(width * scale);
|
|
|
|
height = static_cast<int>(height * scale);
|
|
|
|
|
|
|
|
img = QImage(width, height, QImage::Format_ARGB32);
|
|
|
|
GLTexture tex(GL_RGBA8, width, height);
|
2018-11-10 12:32:18 +00:00
|
|
|
GLRenderTarget target(tex);
|
|
|
|
target.blitFromFramebuffer(geometry);
|
|
|
|
// copy content from framebuffer into image
|
|
|
|
tex.bind();
|
2020-04-20 14:11:21 +00:00
|
|
|
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, static_cast<GLvoid*>(img.bits()));
|
2018-11-10 12:32:18 +00:00
|
|
|
tex.unbind();
|
|
|
|
} else {
|
2020-04-20 14:11:21 +00:00
|
|
|
img = QImage(width, height, QImage::Format_ARGB32);
|
|
|
|
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid*)img.bits());
|
2015-10-30 09:14:55 +00:00
|
|
|
}
|
2020-04-20 14:11:21 +00:00
|
|
|
ScreenShotEffect::convertFromGLImage(img, width, height);
|
2012-03-04 08:53:12 +00:00
|
|
|
}
|
|
|
|
|
2013-02-13 07:10:55 +00:00
|
|
|
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
|
2012-03-04 08:53:12 +00:00
|
|
|
if (effects->compositingType() == XRenderCompositing) {
|
Use nullptr everywhere
Summary:
Because KWin is a very old project, we use three kinds of null pointer
literals: 0, NULL, and nullptr. Since C++11, it's recommended to use
nullptr keyword.
This change converts all usages of 0 and NULL literal to nullptr. Even
though it breaks git history, we need to do it in order to have consistent
code as well to ease code reviews (it's very tempting for some people to
add unrelated changes to their patches, e.g. converting NULL to nullptr).
Test Plan: Compiles.
Reviewers: #kwin, davidedmundson, romangg
Reviewed By: #kwin, davidedmundson, romangg
Subscribers: romangg, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D23618
2019-09-19 14:46:54 +00:00
|
|
|
xcb_image_t *xImage = nullptr;
|
2013-02-13 07:10:55 +00:00
|
|
|
img = xPictureToImage(effects->xrenderBufferPicture(), geometry, &xImage);
|
2016-10-14 13:53:02 +00:00
|
|
|
if (xImage) {
|
|
|
|
xcb_image_destroy(xImage);
|
|
|
|
}
|
2013-02-13 07:10:55 +00:00
|
|
|
}
|
|
|
|
#endif
|
2016-10-14 13:53:02 +00:00
|
|
|
|
2016-10-20 06:29:48 +00:00
|
|
|
if (m_captureCursor) {
|
2020-04-20 14:11:21 +00:00
|
|
|
grabPointerImage(img, geometry.x() * scale, geometry.y() * scale);
|
2016-10-20 06:29:48 +00:00
|
|
|
}
|
|
|
|
|
2016-10-14 13:53:02 +00:00
|
|
|
return img;
|
2011-08-17 17:20:15 +00:00
|
|
|
}
|
2010-07-31 20:55:48 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void ScreenShotEffect::grabPointerImage(QImage& snapshot, int offsetx, int offsety)
|
2010-09-14 19:52:44 +00:00
|
|
|
{
|
2016-10-17 14:12:21 +00:00
|
|
|
const auto cursor = effects->cursorImage();
|
|
|
|
if (cursor.image().isNull())
|
2011-01-30 14:34:42 +00:00
|
|
|
return;
|
2010-09-14 19:52:44 +00:00
|
|
|
|
|
|
|
QPainter painter(&snapshot);
|
2016-10-17 14:12:21 +00:00
|
|
|
painter.drawImage(effects->cursorPos() - cursor.hotSpot() - QPoint(offsetx, offsety), cursor.image());
|
2010-09-14 19:52:44 +00:00
|
|
|
}
|
|
|
|
|
2010-07-31 20:55:48 +00:00
|
|
|
void ScreenShotEffect::convertFromGLImage(QImage &img, int w, int h)
|
|
|
|
{
|
|
|
|
// from QtOpenGL/qgl.cpp
|
2020-08-02 22:10:35 +00:00
|
|
|
// SPDX-FileCopyrightText: 2010 Nokia Corporation and /or its subsidiary(-ies)
|
2019-11-26 17:39:20 +00:00
|
|
|
// see https://github.com/qt/qtbase/blob/dev/src/opengl/qgl.cpp
|
2010-07-31 20:55:48 +00:00
|
|
|
if (QSysInfo::ByteOrder == QSysInfo::BigEndian) {
|
|
|
|
// OpenGL gives RGBA; Qt wants ARGB
|
2020-03-15 19:59:29 +00:00
|
|
|
uint *p = reinterpret_cast<uint *>(img.bits());
|
2011-01-30 14:34:42 +00:00
|
|
|
uint *end = p + w * h;
|
2010-07-31 20:55:48 +00:00
|
|
|
while (p < end) {
|
|
|
|
uint a = *p << 24;
|
|
|
|
*p = (*p >> 8) | a;
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// OpenGL gives ABGR (i.e. RGBA backwards); Qt wants ARGB
|
|
|
|
for (int y = 0; y < h; y++) {
|
2020-03-15 19:59:29 +00:00
|
|
|
uint *q = reinterpret_cast<uint *>(img.scanLine(y));
|
2011-01-30 14:34:42 +00:00
|
|
|
for (int x = 0; x < w; ++x) {
|
2010-07-31 20:55:48 +00:00
|
|
|
const uint pixel = *q;
|
|
|
|
*q = ((pixel << 16) & 0xff0000) | ((pixel >> 16) & 0xff)
|
2011-01-30 14:34:42 +00:00
|
|
|
| (pixel & 0xff00ff00);
|
2010-07-31 20:55:48 +00:00
|
|
|
|
|
|
|
q++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
img = img.mirrored();
|
|
|
|
}
|
|
|
|
|
2011-08-27 09:21:31 +00:00
|
|
|
bool ScreenShotEffect::isActive() const
|
|
|
|
{
|
Use nullptr everywhere
Summary:
Because KWin is a very old project, we use three kinds of null pointer
literals: 0, NULL, and nullptr. Since C++11, it's recommended to use
nullptr keyword.
This change converts all usages of 0 and NULL literal to nullptr. Even
though it breaks git history, we need to do it in order to have consistent
code as well to ease code reviews (it's very tempting for some people to
add unrelated changes to their patches, e.g. converting NULL to nullptr).
Test Plan: Compiles.
Reviewers: #kwin, davidedmundson, romangg
Reviewed By: #kwin, davidedmundson, romangg
Subscribers: romangg, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D23618
2019-09-19 14:46:54 +00:00
|
|
|
return (m_scheduledScreenshot != nullptr || !m_scheduledGeometry.isNull()) && !effects->isScreenLocked();
|
2011-08-27 09:21:31 +00:00
|
|
|
}
|
|
|
|
|
2011-12-07 14:04:11 +00:00
|
|
|
void ScreenShotEffect::windowClosed( EffectWindow* w )
|
|
|
|
{
|
|
|
|
if (w == m_scheduledScreenshot) {
|
Use nullptr everywhere
Summary:
Because KWin is a very old project, we use three kinds of null pointer
literals: 0, NULL, and nullptr. Since C++11, it's recommended to use
nullptr keyword.
This change converts all usages of 0 and NULL literal to nullptr. Even
though it breaks git history, we need to do it in order to have consistent
code as well to ease code reviews (it's very tempting for some people to
add unrelated changes to their patches, e.g. converting NULL to nullptr).
Test Plan: Compiles.
Reviewers: #kwin, davidedmundson, romangg
Reviewed By: #kwin, davidedmundson, romangg
Subscribers: romangg, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D23618
2019-09-19 14:46:54 +00:00
|
|
|
m_scheduledScreenshot = nullptr;
|
2011-12-07 14:04:11 +00:00
|
|
|
screenshotWindowUnderCursor(m_type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-25 07:50:02 +00:00
|
|
|
bool ScreenShotEffect::isTakingScreenshot() const
|
|
|
|
{
|
|
|
|
if (!m_scheduledGeometry.isNull()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (m_windowMode != WindowMode::NoCapture) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (m_fd != -1) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-07-31 20:55:48 +00:00
|
|
|
} // namespace
|