summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2016-10-08 20:16:06 (GMT)
committerPeter Wu <peter@lekensteyn.nl>2016-10-12 17:41:06 (GMT)
commite4c2e564a5b91497132d9a20d8f521af405286bd (patch)
treea5c7a9af3bf8c673c90fbc36a3ca8e0d41ee5ed4
parentc9de3b0d09a41643b56e962561f8187ac84e955e (diff)
Replace KScreen by QScreen for current window grab
libkscreen is overkill for querying purposes, rely on QScreen to find the current screen under cursor. REVIEW: 129127
-rw-r--r--CMakeLists.txt1
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/PlatformBackends/X11ImageGrabber.cpp71
-rw-r--r--src/PlatformBackends/X11ImageGrabber.h7
4 files changed, 15 insertions, 65 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index a420b6c..82f4671 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -75,7 +75,6 @@ find_package(XCB COMPONENTS XFIXES IMAGE UTIL CURSOR)
set(XCB_COMPONENTS_ERRORS FALSE)
if (XCB_FOUND)
find_package(Qt5X11Extras ${QT_MIN_VERSION} REQUIRED)
- find_package(KF5Screen ${PLASMA_MIN_VERSION} REQUIRED)
endif()
set(XCB_COMPONENTS_FOUND TRUE)
if(NOT XCB_XFIXES_FOUND)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 71143c6..7a03b95 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -83,7 +83,6 @@ if(XCB_FOUND)
XCB::CURSOR
XCB::UTIL
Qt5::X11Extras
- KF5::Screen
)
endif()
diff --git a/src/PlatformBackends/X11ImageGrabber.cpp b/src/PlatformBackends/X11ImageGrabber.cpp
index 371748c..0525ec4 100644
--- a/src/PlatformBackends/X11ImageGrabber.cpp
+++ b/src/PlatformBackends/X11ImageGrabber.cpp
@@ -38,17 +38,13 @@
#include <KWindowSystem>
#include <KWindowInfo>
-#include <KScreen/Config>
-#include <KScreen/GetConfigOperation>
-#include <KScreen/Output>
#include <xcb/xcb_cursor.h>
#include <xcb/xcb_util.h>
#include <xcb/xfixes.h>
X11ImageGrabber::X11ImageGrabber(QObject *parent) :
- ImageGrabber(parent),
- mScreenConfigOperation(nullptr)
+ ImageGrabber(parent)
{
mNativeEventFilter = new OnClickEventFilter(this);
}
@@ -85,7 +81,6 @@ bool OnClickEventFilter::nativeEventFilter(const QByteArray &eventType, void *me
{
xcb_button_release_event_t *ev2 = static_cast<xcb_button_release_event_t *>(message);
- qDebug() << ev2->detail;
if (ev2->detail == 1) {
QMetaObject::invokeMethod(mImageGrabber, "doImageGrab", Qt::QueuedConnection);
} else if (ev2->detail < 4) {
@@ -349,53 +344,6 @@ void X11ImageGrabber::KWinDBusScreenshotHelper(quint64 window)
emit pixmapChanged(mPixmap);
}
-void X11ImageGrabber::KScreenCurrentMonitorScreenshotHelper(KScreen::ConfigOperation *op)
-{
- KScreen::ConfigPtr config = qobject_cast<KScreen::GetConfigOperation *>(op)->config();
-
- if (!config) { return grabFullScreen(); }
- if (!config->screen()) { return grabFullScreen(); }
-
- // we'll store the cursor position first
-
- QPoint cursorPosition = QCursor::pos();
-
- // next, we'll get all our outputs and figure out which one has the cursor
-
- const KScreen::OutputList outputs = config->outputs();
- for (auto output: outputs) {
- if (!(output->isConnected())) { continue; }
- if (!(output->currentMode())) { continue; }
-
- QPoint screenPosition = output->pos();
- QSize screenSize = output->currentMode()->size();
- QRect screenRect = QRect(screenPosition, screenSize);
-
- if (!(screenRect.contains(cursorPosition))) {
- continue;
- }
-
- // bingo, we've found an output that contains the cursor. Now
- // to take a shot
-
- mPixmap = getWindowPixmap(QX11Info::appRootWindow(), mCapturePointer);
- mPixmap = mPixmap.copy(screenPosition.x(), screenPosition.y(), screenSize.width(), screenSize.height());
- emit pixmapChanged(mPixmap);
-
- mScreenConfigOperation->disconnect();
- mScreenConfigOperation->deleteLater();
- mScreenConfigOperation = nullptr;
-
- return;
- }
-
- mScreenConfigOperation->disconnect();
- mScreenConfigOperation->deleteLater();
- mScreenConfigOperation = nullptr;
-
- return grabFullScreen();
-}
-
void X11ImageGrabber::rectangleSelectionCancelled()
{
QObject *sender = QObject::sender();
@@ -621,9 +569,20 @@ QRect X11ImageGrabber::getApplicationWindowGeometry(xcb_window_t window)
void X11ImageGrabber::grabCurrentScreen()
{
- mScreenConfigOperation = new KScreen::GetConfigOperation;
- connect(mScreenConfigOperation, &KScreen::GetConfigOperation::finished,
- this, &X11ImageGrabber::KScreenCurrentMonitorScreenshotHelper);
+ QPoint cursorPosition = QCursor::pos();
+ for (auto screen : QGuiApplication::screens()) {
+ const QRect screenRect = screen->geometry();
+ if (!screenRect.contains(cursorPosition)) {
+ continue;
+ }
+
+ mPixmap = getWindowPixmap(QX11Info::appRootWindow(), mCapturePointer).copy(screenRect);
+ emit pixmapChanged(mPixmap);
+ return;
+ }
+
+ // No screen found with our cursor, fallback to capturing full screen
+ grabFullScreen();
}
void X11ImageGrabber::grabRectangularRegion()
diff --git a/src/PlatformBackends/X11ImageGrabber.h b/src/PlatformBackends/X11ImageGrabber.h
index 338ffee..513bf4b 100644
--- a/src/PlatformBackends/X11ImageGrabber.h
+++ b/src/PlatformBackends/X11ImageGrabber.h
@@ -28,11 +28,6 @@
#include "ImageGrabber.h"
class X11ImageGrabber;
-namespace KScreen
-{
- class GetConfigOperation;
- class ConfigOperation;
-}
class OnClickEventFilter : public QAbstractNativeEventFilter
{
@@ -70,7 +65,6 @@ class X11ImageGrabber : public ImageGrabber
private slots:
void KWinDBusScreenshotHelper(quint64 window);
- void KScreenCurrentMonitorScreenshotHelper(KScreen::ConfigOperation *op);
void rectangleSelectionConfirmed(const QPixmap &pixmap, const QRect &region);
void rectangleSelectionCancelled();
@@ -90,7 +84,6 @@ class X11ImageGrabber : public ImageGrabber
QPixmap convertFromNative(xcb_image_t *xcbImage);
OnClickEventFilter *mNativeEventFilter;
- KScreen::GetConfigOperation *mScreenConfigOperation;
};
template <typename T> using CScopedPointer = QScopedPointer<T, QScopedPointerPodDeleter>;