Add external screenshotter support

for wayland!!
This commit is contained in:
ArsenArsen 2017-12-17 19:59:16 +01:00
parent 70bba2cbbb
commit 87f765245d
No known key found for this signature in database
GPG Key ID: 683D2F43B0CA4BD2
6 changed files with 150 additions and 44 deletions

View File

@ -8,11 +8,18 @@
#include <platformbackend.hpp> #include <platformbackend.hpp>
#include <settings.hpp> #include <settings.hpp>
void screenshotter::area() { void areaScreenshotCallback(QPixmap p) {
CropEditor *editor = new CropEditor(utils::fullscreen(settings::settings().value("captureCursor", true).toBool())); CropEditor *editor = new CropEditor(p);
QObject::connect(editor, &CropEditor::cropped, [&](QPixmap pixmap) { UploaderSingleton::inst().upload(pixmap); }); QObject::connect(editor, &CropEditor::cropped, [&](QPixmap pixmap) { UploaderSingleton::inst().upload(pixmap); });
} }
void screenshotter::area() {
if (!settings::settings().value("command/fullscreenCommand", "").toString().isEmpty())
utils::externalScreenshot(areaScreenshotCallback);
else
areaScreenshotCallback(utils::fullscreen(settings::settings().value("captureCursor", true).toBool()));
}
void screenshotter::fullscreen() { void screenshotter::fullscreen() {
UploaderSingleton::inst().upload(utils::fullscreen(settings::settings().value("captureCursor", true).toBool())); UploaderSingleton::inst().upload(utils::fullscreen(settings::settings().value("captureCursor", true).toBool()));
} }
@ -31,6 +38,9 @@ void screenshotter::activeDelayed() {
void screenshotter::active() { void screenshotter::active() {
#ifdef PLATFORM_CAPABILITY_ACTIVEWINDOW #ifdef PLATFORM_CAPABILITY_ACTIVEWINDOW
UploaderSingleton::inst().upload(utils::window(PlatformBackend::inst().getActiveWID())); if (!settings::settings().value("command/activeCommand", "").toString().isEmpty())
utils::externalScreenshotActive([](QPixmap p) { UploaderSingleton::inst().upload(p); });
else
UploaderSingleton::inst().upload(utils::window(PlatformBackend::inst().getActiveWID()));
#endif #endif
} }

View File

@ -84,6 +84,8 @@ SettingsDialog::SettingsDialog(QWidget *parent) : QDialog(parent), ui(new Ui::Se
ui->captureCursor->setText(tr("Capture cursor (disabled: implementation missing)")); ui->captureCursor->setText(tr("Capture cursor (disabled: implementation missing)"));
#endif #endif
ui->fpsMax->setValue(settings::settings().value("recording/framerate", 30).toInt()); ui->fpsMax->setValue(settings::settings().value("recording/framerate", 30).toInt());
ui->focusedCapture->setText(settings::settings().value("command/activeCommand", "").toString());
ui->fullscreenCapture->setText(settings::settings().value("command/fullscreenCommand", 0).toString());
} }
void SettingsDialog::setScheme(QString scheme) { void SettingsDialog::setScheme(QString scheme) {
@ -173,6 +175,14 @@ void SettingsDialog::on_cropY_valueChanged(int arg1) {
settings::settings().setValue("cropy", arg1); settings::settings().setValue("cropy", arg1);
} }
void SettingsDialog::on_focusedCapture_textChanged(QString arg1) {
settings::settings().setValue("command/activeCommand", arg1);
}
void SettingsDialog::on_fullscreenCapture_textChanged(QString arg1) {
settings::settings().setValue("command/fullscreenCommand", arg1);
}
void SettingsDialog::on_fpsMax_valueChanged(int arg1) { void SettingsDialog::on_fpsMax_valueChanged(int arg1) {
settings::settings().setValue("recording/framerate", arg1); settings::settings().setValue("recording/framerate", arg1);
} }

View File

@ -33,13 +33,11 @@ private slots:
void newUploader(Uploader *u); void newUploader(Uploader *u);
void uploaderChanged(QString newName); void uploaderChanged(QString newName);
void on_saveLocation_currentIndexChanged(int index); void on_saveLocation_currentIndexChanged(int index);
void on_cropX_valueChanged(int arg1); void on_cropX_valueChanged(int arg1);
void on_cropY_valueChanged(int arg1); void on_cropY_valueChanged(int arg1);
void on_fpsMax_valueChanged(int arg1); void on_fpsMax_valueChanged(int arg1);
void on_fullscreenCapture_textChanged(QString newVal);
void on_focusedCapture_textChanged(QString newVal);
private: private:
Ui::SettingsDialog *ui; Ui::SettingsDialog *ui;
}; };

View File

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>485</width> <width>650</width>
<height>655</height> <height>759</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -17,19 +17,8 @@
<item row="1" column="1"> <item row="1" column="1">
<widget class="QListWidget" name="uploaderList"/> <widget class="QListWidget" name="uploaderList"/>
</item> </item>
<item row="8" column="1"> <item row="12" column="2">
<widget class="QCheckBox" name="quickMode"> <widget class="QComboBox" name="imageFormatBox"/>
<property name="text">
<string>Quick mode (mouse release screenshots)</string>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Delay before taking a screenshot</string>
</property>
</widget>
</item> </item>
<item row="7" column="1"> <item row="7" column="1">
<widget class="QDoubleSpinBox" name="delay"> <widget class="QDoubleSpinBox" name="delay">
@ -44,11 +33,19 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="2" rowspan="7"> <item row="8" column="1">
<widget class="QListWidget" name="hotkeys"/> <widget class="QCheckBox" name="quickMode">
<property name="text">
<string>Quick mode (mouse release screenshots)</string>
</property>
</widget>
</item> </item>
<item row="12" column="2"> <item row="15" column="1">
<widget class="QComboBox" name="imageFormatBox"/> <widget class="QLabel" name="label_10">
<property name="text">
<string>Fullscreen capture command (save to %FILE_PATH or print to stdout)</string>
</property>
</widget>
</item> </item>
<item row="0" column="2"> <item row="0" column="2">
<widget class="QLabel" name="label_5"> <widget class="QLabel" name="label_5">
@ -64,6 +61,16 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="2" rowspan="7">
<widget class="QListWidget" name="hotkeys"/>
</item>
<item row="6" column="1">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Delay before taking a screenshot</string>
</property>
</widget>
</item>
<item row="11" column="1"> <item row="11" column="1">
<widget class="QLabel" name="label_4"> <widget class="QLabel" name="label_4">
<property name="text"> <property name="text">
@ -109,20 +116,6 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="8" column="2">
<widget class="QPushButton" name="settingsButton">
<property name="text">
<string>Open settings directory</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="label">
<property name="text">
<string>Destination:</string>
</property>
</widget>
</item>
<item row="5" column="1"> <item row="5" column="1">
<widget class="QComboBox" name="saveLocation"> <widget class="QComboBox" name="saveLocation">
<item> <item>
@ -137,7 +130,21 @@
</item> </item>
</widget> </widget>
</item> </item>
<item row="15" column="1" colspan="2"> <item row="8" column="2">
<widget class="QPushButton" name="settingsButton">
<property name="text">
<string>Open settings directory</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="label">
<property name="text">
<string>Destination:</string>
</property>
</widget>
</item>
<item row="18" column="1" colspan="2">
<widget class="QDialogButtonBox" name="buttonBox"> <widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
@ -154,7 +161,7 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="14" column="1" colspan="2"> <item row="17" column="1" colspan="2">
<widget class="QGroupBox" name="groupBox"> <widget class="QGroupBox" name="groupBox">
<property name="title"> <property name="title">
<string>Advanced</string> <string>Advanced</string>
@ -223,6 +230,19 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="15" column="2">
<widget class="QLineEdit" name="fullscreenCapture"/>
</item>
<item row="16" column="1">
<widget class="QLabel" name="label_11">
<property name="text">
<string>Focused capture command (save to %FILE_PATH or print to stdout)</string>
</property>
</widget>
</item>
<item row="16" column="2">
<widget class="QLineEdit" name="focusedCapture"/>
</item>
</layout> </layout>
</widget> </widget>
<resources/> <resources/>

View File

@ -5,9 +5,10 @@
#include <QDebug> #include <QDebug>
#include <QPainter> #include <QPainter>
#include <QPixmap> #include <QPixmap>
#include <QProcess>
#include <QScreen> #include <QScreen>
#include <platformbackend.hpp> #include <platformbackend.hpp>
#include <settings.hpp>
QColor utils::invertColor(QColor color) { QColor utils::invertColor(QColor color) {
return QColor(255 - color.red(), 255 - color.green(), 255 - color.blue()); return QColor(255 - color.red(), 255 - color.green(), 255 - color.blue());
@ -113,3 +114,66 @@ QPixmap utils::renderText(QString toRender, int padding, QColor background, QCol
painter.end(); painter.end();
return renderred; return renderred;
} }
QString utils::randomString(int length) {
QString str;
str.resize(length);
for (int s = 0; s < length; s++) str[s] = QChar('A' + char(qrand() % ('Z' - 'A')));
return str;
}
void utils::externalScreenshot(std::function<void(QPixmap)> callback) {
QString cmd = settings::settings().value("command/fullscreenCommand", "").toString();
QStringList args = cmd.split(' ');
QString tempPath;
for (QString &arg : args) {
if (arg == "%FILE_PATH") {
if (tempPath.isEmpty()) tempPath = "KShare-Ext-Screenshot." + randomString(5);
arg = tempPath;
}
}
QProcess *process = new QProcess;
QObject::connect(process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
[callback, process, tempPath](int code, QProcess::ExitStatus) {
if (code != 0) {
qCritical().noquote() << "Failed to take external screenshot: \n"
<< process->readAllStandardError();
return;
}
QPixmap pixmap;
if (!tempPath.isEmpty())
pixmap.load(tempPath);
else
pixmap.loadFromData(process->readAllStandardOutput());
callback(pixmap);
});
process->start(args.takeFirst(), args);
}
void utils::externalScreenshotActive(std::function<void(QPixmap)> callback) {
QString cmd = settings::settings().value("command/activeCommand", "").toString();
QStringList args = cmd.split(' ');
QString tempPath;
for (QString &arg : args) {
if (arg == "%FILE_PATH") {
if (tempPath.isEmpty()) tempPath = "KShare-Ext-Screenshot." + randomString(5);
arg = tempPath;
}
}
QProcess *process = new QProcess;
QObject::connect(process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
[callback, process, tempPath](int code, QProcess::ExitStatus) {
if (code != 0) {
qCritical().noquote() << "Failed to take external screenshot: \n"
<< process->readAllStandardError();
return;
}
QPixmap pixmap;
if (!tempPath.isEmpty())
pixmap.load(tempPath);
else
pixmap.loadFromData(process->readAllStandardOutput());
callback(pixmap);
});
process->start(args.takeFirst(), args);
}

View File

@ -3,8 +3,9 @@
#include <QApplication> #include <QApplication>
#include <QPixmap> #include <QPixmap>
#include <QWidget>
#include <QScreen> #include <QScreen>
#include <QWidget>
#include <functional>
namespace utils { namespace utils {
QColor invertColor(QColor color); QColor invertColor(QColor color);
@ -16,6 +17,9 @@ namespace utils {
QPoint smallestScreenCoordinate(); QPoint smallestScreenCoordinate();
QPixmap QPixmap
renderText(QString toRender, int padding = 5, QColor background = Qt::transparent, QColor pen = Qt::white, QFont font = QFont()); renderText(QString toRender, int padding = 5, QColor background = Qt::transparent, QColor pen = Qt::white, QFont font = QFont());
void externalScreenshot(std::function<void(QPixmap)> callback);
void externalScreenshotActive(std::function<void(QPixmap)> callback);
QString randomString(int length);
} }
#endif // UTILS_HPP #endif // UTILS_HPP