Commit 86af14e9 authored by Boudhayan Gupta's avatar Boudhayan Gupta
Browse files

Add notification, random fixes, prepare for kdereview, 1.9.96

parent f87fa50a
......@@ -47,7 +47,7 @@ find_package(
find_package(
KF5 ${KF5_MIN_VERSION} REQUIRED
CoreAddons
Declarative
Notifications
Config
I18n
KIO
......
This diff is collapsed.
KScreenGenie - The (new) KDE Screenshot Utility
README
1) What is KScreenGenie
KScreenGenie is a screenshooter utility for KDE. It is written
using the very latest KDE and Qt technologies (KDE Frameworks 5,
Qt 5 and QtQuick 2.0), and aims for a cleaner and more modular
codebase over KSnapshot (the previous screenshooter utility for
KDE) rather than adding features. KScreenGenie's codebase is
designed specifically so that it's easy to add Wayland support
once an API becomes available for it.
2) What am I giving up over KSnapshot?
* The ability to grab freeform areas of your screen
* The ability to select and grab specific widgets in a window
* No Win32 or Mac OS support yet
* The ability to take screenshots on platforms where OpenGL
is not available (QtQuick 2.0 requires OpenGL)
The last point might be a major blocker for a lot of people,
but if you're running Plasma 5, you already have OpenGL (since
Plasma 5 is built using the same QtQuick 2.0 technologies as
this). If you're running KDE apps on a platform where OpenGL
is unavailable, KSnapshot continues to be available.
Note that KScreenGenie will work even if you use KWin without
compositing, or if you use another window manager (like OpenBox).
All you need is to have the 3D drivers installed.
Also note that Qt5Gui currently mandates OpenGL.
3) What's cooler?
* More robust multimonitor screenshot support.
All the image capture code now resides in the platform backend
(currently only X11) and uses native methods (xcb_image_get_image()
for X11) rather than Qt's image capture code. This allows us fine
grained control over multimonitor setups.
The X11 backend currently captures images using xcb, and uses
KScreen (which on X11 uses a native XRandR backend) to determine
multimonitor configuration.
KScreenGenie does NOT support taking multi-screen screenshots
when every monitor is assigned a different X screen. It only
supports RandR or Xinerama based virtual destops spanning
multiple monitors. Adding support for traditional X11 multi
screen is not a priority (KWindowSystem does not even support
this scenario), but the modularity of the codebase means adding
support for this is easy enough.
* Live preview when grabbing rectangular regions of the screen.
Traditionally, KSnapshot would take a fullscreen screenshot
first and show you an interface to crop the image. With
KScreenGenie, things are different. If you're running with
compositing enabled, we render a transparent fullscreen window
over your desktop on which you draw the crop rectangle. You
get to see exactly what's happenning in the screen below the
region selector, and the actual screenshot is taken AFTER you
confirm the crop rectangle.
If compositing is disabled, KScreenGenie falls back to the
traditional behaviour. You can also force the old behaviour
by setting the KSCREENGENIE_FORCE_CROP_NONLIVE environment
variable.
* Fix any booboos I've made that I come across
# install the .desktop files in the correct place
# install the .desktop and rc files in the correct place
install(
PROGRAMS org.kde.kscreengenie.desktop
DESTINATION ${XDG_APPS_INSTALL_DIR}
)
install(
FILES kscreengenie.notifyrc
DESTINATION ${KNOTIFYRC_INSTALL_DIR}
)
\ No newline at end of file
[Global]
IconName=kscreengenie
Name=KScreenGenie
Comment=Screenshot Capture Utility
[Event/newScreenshotSaved]
Name=New Screenshot Saved
Comment=A new screenshot was captured and saved
Action=Popup
\ No newline at end of file
......@@ -54,7 +54,7 @@ target_link_libraries(
Qt5::DBus
Qt5::PrintSupport
KF5::CoreAddons
KF5::Declarative
KF5::Notifications
KF5::ConfigGui
KF5::I18n
KF5::KIOWidgets
......
......@@ -62,7 +62,7 @@ void KSImageWidget::mouseMoveEvent(QMouseEvent *event)
return;
}
if ((event->pos() - mDragStartPosition).manhattanLength() < 10) {
if ((event->pos() - mDragStartPosition).manhattanLength() < QGuiApplication::styleHints()->startDragDistance()) {
return;
}
......
......@@ -20,6 +20,8 @@
#ifndef KSIMAGEWIDGET_H
#define KSIMAGEWIDGET_H
#include <QGuiApplication>
#include <QStyleHints>
#include <QLabel>
#include <QColor>
#include <QMouseEvent>
......
......@@ -31,9 +31,10 @@
#include "KSCore.h"
KSCore::KSCore(bool backgroundMode, ImageGrabber::GrabMode grabMode, QString &saveFileName, qint64 delayMsec, bool sendToClipboard, QObject *parent) :
KSCore::KSCore(bool backgroundMode, ImageGrabber::GrabMode grabMode, QString &saveFileName, qint64 delayMsec, bool sendToClipboard, bool notifyOnGrab, QObject *parent) :
QObject(parent),
mBackgroundMode(backgroundMode),
mNotify(notifyOnGrab),
mOverwriteOnSave(true),
mBackgroundSendToClipboard(sendToClipboard),
mLocalPixmap(QPixmap()),
......@@ -172,6 +173,12 @@ void KSCore::takeNewScreenshot(ImageGrabber::GrabMode mode, int timeout, bool in
return;
}
// when compositing is enabled, we need to give it enough time for the window
// to disappear and all the effects are complete before we take the shot. there's
// no way of knowing how long the disappearing effects take, but as per default
// settings (and unless the user has set an extremely slow effect), 200
// milliseconds is a good amount of wait time.
const int msec = KWindowSystem::compositingActive() ? 200 : 50;
QTimer::singleShot(timeout + msec, mImageGrabber, &ImageGrabber::doImageGrab);
}
......@@ -196,8 +203,6 @@ void KSCore::screenshotUpdated(const QPixmap pixmap)
} else {
doAutoSave();
}
emit allDone();
return;
} else {
mMainWindow->setScreenshotAndShow(pixmap);
tempFileSave();
......@@ -230,8 +235,27 @@ void KSCore::doAutoSave()
}
if (doSave(savePath)) {
setSaveLocation(saveLocation());
emit allDone();
QDir dir(savePath.path());
dir.cdUp();
setSaveLocation(dir.absolutePath());
qDebug() << dir.absolutePath();
if (mBackgroundMode && mNotify) {
KNotification *notify = new KNotification("newScreenshotSaved");
notify->setText(i18n("A new screenshot was captured and saved to %1", savePath.toLocalFile()));
notify->setPixmap(QIcon::fromTheme("ksnapshot").pixmap(QSize(32, 32)));
notify->sendEvent();
// unfortunately we can't quit just yet, emitting allDone right away
// quits the application before the notification DBus message gets sent.
// a token timeout seems to fix this though. Any better ideas?
QTimer::singleShot(50, this, &KSCore::allDone);
} else {
emit allDone();
}
return;
}
}
......
......@@ -35,6 +35,7 @@
#include <QPrinter>
#include <QPainter>
#include <QRect>
#include <QIcon>
#include <QDir>
#include <QDrag>
#include <QMimeData>
......@@ -51,6 +52,7 @@
#include <KSharedConfig>
#include <KWindowSystem>
#include <KMessageBox>
#include <KNotification>
#include <KIO/FileCopyJob>
#include <KIO/StatJob>
......@@ -72,7 +74,7 @@ class KSCore : public QObject
public:
explicit KSCore(bool backgroundMode, ImageGrabber::GrabMode grabMode, QString &saveFileName, qint64 delayMsec, bool sendToClipboard, QObject *parent = 0);
explicit KSCore(bool backgroundMode, ImageGrabber::GrabMode grabMode, QString &saveFileName, qint64 delayMsec, bool sendToClipboard, bool notifyOnGrab, QObject *parent = 0);
~KSCore();
QString filename() const;
......@@ -123,6 +125,7 @@ class KSCore : public QObject
QUrl getTempSaveFilename() const;
bool mBackgroundMode;
bool mNotify;
bool mOverwriteOnSave;
bool mBackgroundSendToClipboard;
QPixmap mLocalPixmap;
......
......@@ -49,6 +49,7 @@ int main(int argc, char **argv)
{{"a", "activewindow"}, i18n("Capture the active window")},
{{"r", "region"}, i18n("Capture a rectangular region of the screen")},
{{"b", "background"}, i18n("Take a screenshot and exit without showing the GUI")},
{{"n", "notify"}, i18n("In background mode, pop up a notification when the screenshot is taken")},
{{"c", "clipboard"}, i18n("In background mode, send image to clipboard without saving to file")},
{{"o", "output"}, i18n("In background mode, save image to specified file"), "fileName"},
{{"d", "delay"}, i18n("In background mode, delay before taking the shot (in milliseconds)"), "delayMsec"},
......@@ -73,11 +74,17 @@ int main(int argc, char **argv)
bool backgroundMode = false;
bool sendToClipboard = false;
bool notify = false;
qint64 delayMsec = 0;
QString fileName = QString();
if (parser.isSet("background")) {
backgroundMode = true;
app.setQuitOnLastWindowClosed(false);
if (parser.isSet("notify")) {
notify = true;
}
if (parser.isSet("output")) {
fileName = parser.value("output");
......@@ -102,7 +109,7 @@ int main(int argc, char **argv)
// release the kraken
KSCore genie(backgroundMode, grabMode, fileName, delayMsec, sendToClipboard);
KSCore genie(backgroundMode, grabMode, fileName, delayMsec, sendToClipboard, notify);
QObject::connect(&genie, &KSCore::allDone, qApp, &QApplication::quit);
return app.exec();
......
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