Commit 8c163f2b authored by Martin Flöser's avatar Martin Flöser

[effects] Support capture cursor image in Screenshot effect

Summary:
The screenshot methods to blit the screen so far did not capture the
cursor image. But sometimes it is useful to also capture the cursor
image.

This change extends the exported methods to take an optional bool
argument whether to capture the screen. The default is not changed and
still not captures the cursor.

Reviewers: #kwin, #plasma_on_wayland

Subscribers: plasma-devel, kwin

Tags: #plasma_on_wayland, #kwin

Differential Revision: https://phabricator.kde.org/D3118
parent 288cf06b
......@@ -225,6 +225,7 @@ void ScreenShotEffect::sendReplyImage(const QImage &img)
m_scheduledGeometry = QRect();
m_multipleOutputsImage = QImage();
m_multipleOutputsRendered = QRegion();
m_captureCursor = false;
}
QString ScreenShotEffect::saveTempImage(const QImage &img)
......@@ -271,7 +272,7 @@ void ScreenShotEffect::screenshotForWindow(qulonglong winid, int mask)
}
}
QString ScreenShotEffect::screenshotFullscreen()
QString ScreenShotEffect::screenshotFullscreen(bool captureCursor)
{
if (!calledFromDBus()) {
return QString();
......@@ -284,11 +285,12 @@ QString ScreenShotEffect::screenshotFullscreen()
m_replyMessage = message();
setDelayedReply(true);
m_scheduledGeometry = effects->virtualScreenGeometry();
m_captureCursor = captureCursor;
effects->addRepaintFull();
return QString();
}
QString ScreenShotEffect::screenshotScreen(int screen)
QString ScreenShotEffect::screenshotScreen(int screen, bool captureCursor)
{
if (!calledFromDBus()) {
return QString();
......@@ -302,6 +304,7 @@ QString ScreenShotEffect::screenshotScreen(int screen)
sendErrorReply(QDBusError::Failed, "Invalid screen requested");
return QString();
}
m_captureCursor = captureCursor;
m_replyConnection = connection();
m_replyMessage = message();
setDelayedReply(true);
......@@ -309,7 +312,7 @@ QString ScreenShotEffect::screenshotScreen(int screen)
return QString();
}
QString ScreenShotEffect::screenshotArea(int x, int y, int width, int height)
QString ScreenShotEffect::screenshotArea(int x, int y, int width, int height, bool captureCursor)
{
if (!calledFromDBus()) {
return QString();
......@@ -324,6 +327,7 @@ QString ScreenShotEffect::screenshotArea(int x, int y, int width, int height)
sendErrorReply(QDBusError::Failed, "Invalid area requested");
return QString();
}
m_captureCursor = captureCursor;
m_replyConnection = connection();
m_replyMessage = message();
setDelayedReply(true);
......@@ -365,6 +369,10 @@ QImage ScreenShotEffect::blitScreenshot(const QRect &geometry)
}
#endif
if (m_captureCursor) {
grabPointerImage(img, geometry.x(), geometry.y());
}
return img;
}
......
......@@ -58,16 +58,18 @@ public Q_SLOTS:
/**
* 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.
* @param captureCursor Whether to include the cursor in the image
* @returns Path to stored screenshot, or null string in failure case.
**/
Q_SCRIPTABLE QString screenshotFullscreen();
Q_SCRIPTABLE QString screenshotFullscreen(bool captureCursor = false);
/**
* 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.
* @param screen Number of screen as numbered by QDesktopWidget
* @param captureCursor Whether to include the cursor in the image
* @returns Path to stored screenshot, or null string in failure case.
**/
Q_SCRIPTABLE QString screenshotScreen(int screen);
Q_SCRIPTABLE QString screenshotScreen(int screen, bool captureCursor = false);
/**
* 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.
......@@ -75,9 +77,10 @@ public Q_SLOTS:
* @param y Left upper y coord of region
* @param width Width of the region to screenshot
* @param height Height of the region to screenshot
* @param captureCursor Whether to include the cursor in the image
* @returns Path to stored screenshot, or null string in failure case.
**/
Q_SCRIPTABLE QString screenshotArea(int x, int y, int width, int height);
Q_SCRIPTABLE QString screenshotArea(int x, int y, int width, int height, bool captureCursor = false);
Q_SIGNALS:
Q_SCRIPTABLE void screenshotCreated(qulonglong handle);
......@@ -98,6 +101,7 @@ private:
QRect m_cachedOutputGeometry;
QImage m_multipleOutputsImage;
QRegion m_multipleOutputsRendered;
bool m_captureCursor = false;
};
} // namespace
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment