mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-04-26 14:23:09 +00:00
Add screenshot option to panel
This commit is contained in:
parent
3d426d5ced
commit
30471d4148
5 changed files with 194 additions and 0 deletions
|
|
@ -1,5 +1,8 @@
|
|||
qt5_add_dbus_interfaces(DBUS_SRCS dbus/org.kde.KWin.Screenshot.xml)
|
||||
|
||||
set(phonepanel_SRCS
|
||||
phonepanel.cpp
|
||||
${DBUS_SRCS}
|
||||
)
|
||||
|
||||
add_library(plasma_applet_phonepanel MODULE ${phonepanel_SRCS})
|
||||
|
|
@ -8,6 +11,7 @@ kcoreaddons_desktop_to_json(plasma_applet_phonepanel package/metadata.desktop)
|
|||
|
||||
target_link_libraries(plasma_applet_phonepanel
|
||||
Qt5::Gui
|
||||
Qt5::DBus
|
||||
KF5::Plasma
|
||||
KF5::I18n
|
||||
${GSTREAMER_LIBRARIES} GLIB2::GLIB2 ${GOBJECT_LIBRARIES})
|
||||
|
|
|
|||
114
containments/panel/dbus/org.kde.KWin.Screenshot.xml
Normal file
114
containments/panel/dbus/org.kde.KWin.Screenshot.xml
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
|
||||
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
|
||||
<node>
|
||||
<interface name="org.kde.kwin.Screenshot">
|
||||
<signal name="screenshotCreated">
|
||||
<arg name="handle" type="t" direction="out"/>
|
||||
</signal>
|
||||
<method name="screenshotForWindow">
|
||||
<arg name="winid" type="t" direction="in"/>
|
||||
<arg name="mask" type="i" direction="in"/>
|
||||
</method>
|
||||
<method name="screenshotForWindow">
|
||||
<arg name="winid" type="t" direction="in"/>
|
||||
</method>
|
||||
<method name="interactive">
|
||||
<arg type="s" direction="out"/>
|
||||
<arg name="mask" type="i" direction="in"/>
|
||||
</method>
|
||||
<method name="interactive">
|
||||
<arg type="s" direction="out"/>
|
||||
</method>
|
||||
<method name="interactive">
|
||||
<arg name="fd" type="h" direction="in"/>
|
||||
<arg name="mask" type="i" direction="in"/>
|
||||
</method>
|
||||
<method name="interactive">
|
||||
<arg name="fd" type="h" direction="in"/>
|
||||
</method>
|
||||
<method name="screenshotWindowUnderCursor">
|
||||
<arg name="mask" type="i" direction="in"/>
|
||||
</method>
|
||||
<method name="screenshotWindowUnderCursor">
|
||||
</method>
|
||||
<method name="screenshotFullscreen">
|
||||
<arg type="s" direction="out"/>
|
||||
<arg name="captureCursor" type="b" direction="in"/>
|
||||
</method>
|
||||
<method name="screenshotFullscreen">
|
||||
<arg type="s" direction="out"/>
|
||||
</method>
|
||||
<method name="screenshotFullscreen">
|
||||
<arg name="fd" type="h" direction="in"/>
|
||||
<arg name="captureCursor" type="b" direction="in"/>
|
||||
</method>
|
||||
<method name="screenshotFullscreen">
|
||||
<arg name="fd" type="h" direction="in"/>
|
||||
</method>
|
||||
<method name="screenshotScreen">
|
||||
<arg type="s" direction="out"/>
|
||||
<arg name="screen" type="i" direction="in"/>
|
||||
<arg name="captureCursor" type="b" direction="in"/>
|
||||
</method>
|
||||
<method name="screenshotScreen">
|
||||
<arg type="s" direction="out"/>
|
||||
<arg name="screen" type="i" direction="in"/>
|
||||
</method>
|
||||
<method name="screenshotScreen">
|
||||
<arg name="fd" type="h" direction="in"/>
|
||||
<arg name="captureCursor" type="b" direction="in"/>
|
||||
</method>
|
||||
<method name="screenshotScreen">
|
||||
<arg name="fd" type="h" direction="in"/>
|
||||
</method>
|
||||
<method name="screenshotArea">
|
||||
<arg type="s" direction="out"/>
|
||||
<arg name="x" type="i" direction="in"/>
|
||||
<arg name="y" type="i" direction="in"/>
|
||||
<arg name="width" type="i" direction="in"/>
|
||||
<arg name="height" type="i" direction="in"/>
|
||||
<arg name="captureCursor" type="b" direction="in"/>
|
||||
</method>
|
||||
<method name="screenshotArea">
|
||||
<arg type="s" direction="out"/>
|
||||
<arg name="x" type="i" direction="in"/>
|
||||
<arg name="y" type="i" direction="in"/>
|
||||
<arg name="width" type="i" direction="in"/>
|
||||
<arg name="height" type="i" direction="in"/>
|
||||
</method>
|
||||
</interface>
|
||||
<interface name="org.freedesktop.DBus.Properties">
|
||||
<method name="Get">
|
||||
<arg name="interface_name" type="s" direction="in"/>
|
||||
<arg name="property_name" type="s" direction="in"/>
|
||||
<arg name="value" type="v" direction="out"/>
|
||||
</method>
|
||||
<method name="Set">
|
||||
<arg name="interface_name" type="s" direction="in"/>
|
||||
<arg name="property_name" type="s" direction="in"/>
|
||||
<arg name="value" type="v" direction="in"/>
|
||||
</method>
|
||||
<method name="GetAll">
|
||||
<arg name="interface_name" type="s" direction="in"/>
|
||||
<arg name="values" type="a{sv}" direction="out"/>
|
||||
<annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QVariantMap"/>
|
||||
</method>
|
||||
<signal name="PropertiesChanged">
|
||||
<arg name="interface_name" type="s" direction="out"/>
|
||||
<arg name="changed_properties" type="a{sv}" direction="out"/>
|
||||
<annotation name="org.qtproject.QtDBus.QtTypeName.Out1" value="QVariantMap"/>
|
||||
<arg name="invalidated_properties" type="as" direction="out"/>
|
||||
</signal>
|
||||
</interface>
|
||||
<interface name="org.freedesktop.DBus.Introspectable">
|
||||
<method name="Introspect">
|
||||
<arg name="xml_data" type="s" direction="out"/>
|
||||
</method>
|
||||
</interface>
|
||||
<interface name="org.freedesktop.DBus.Peer">
|
||||
<method name="Ping"/>
|
||||
<method name="GetMachineId">
|
||||
<arg name="machine_uuid" type="s" direction="out"/>
|
||||
</method>
|
||||
</interface>
|
||||
</node>
|
||||
|
|
@ -31,6 +31,8 @@ Item {
|
|||
signal closeRequested
|
||||
signal closed
|
||||
|
||||
property bool screenshotRequested: false
|
||||
|
||||
function toggleAirplane() {
|
||||
print("toggle airplane mode")
|
||||
}
|
||||
|
|
@ -73,6 +75,18 @@ Item {
|
|||
}
|
||||
}
|
||||
|
||||
function requestScreenshot() {
|
||||
screenshotRequested = true;
|
||||
root.closeRequested();
|
||||
}
|
||||
|
||||
onClosed: {
|
||||
if (screenshotRequested) {
|
||||
plasmoid.nativeInterface.takeScreenshot();
|
||||
screenshotRequested = false;
|
||||
}
|
||||
}
|
||||
|
||||
PlasmaCore.DataSource {
|
||||
id: pmSource
|
||||
engine: "powermanagement"
|
||||
|
|
@ -160,6 +174,14 @@ Item {
|
|||
"settingsCommand": "",
|
||||
"applet": null
|
||||
});
|
||||
settingsModel.append({
|
||||
"text": i18n("Screenshot"),
|
||||
"icon": "spectacle",
|
||||
"enabled": false,
|
||||
"settingsCommand": "",
|
||||
"toggleFunction": "requestScreenshot",
|
||||
"applet": null
|
||||
});
|
||||
|
||||
brightnessSlider.moved.connect(function() {
|
||||
root.screenBrightness = brightnessSlider.value;
|
||||
|
|
|
|||
|
|
@ -20,8 +20,15 @@
|
|||
|
||||
#include "phonepanel.h"
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QDBusPendingReply>
|
||||
#include <QFile>
|
||||
#include <QDebug>
|
||||
#include <QStandardPaths>
|
||||
#include <QProcess>
|
||||
#include <QtConcurrent/QtConcurrent>
|
||||
|
||||
#include "screenshotinterface.h"
|
||||
|
||||
PhonePanel::PhonePanel(QObject *parent, const QVariantList &args)
|
||||
: Plasma::Containment(parent, args)
|
||||
|
|
@ -71,6 +78,52 @@ void PhonePanel::toggleTorch()
|
|||
}
|
||||
}
|
||||
|
||||
void PhonePanel::takeScreenshot()
|
||||
{
|
||||
auto *interface = new org::kde::kwin::Screenshot(QStringLiteral("org.kde.KWin"), QStringLiteral("/Screenshot"), QDBusConnection::sessionBus(), this);
|
||||
QDBusPendingReply<QString> reply = interface->screenshotFullscreen();
|
||||
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this);
|
||||
|
||||
connect(watcher, &QDBusPendingCallWatcher::finished, this, [=](QDBusPendingCallWatcher *watcher) {
|
||||
QDBusPendingReply<QString> reply = *watcher;
|
||||
|
||||
if (reply.isError()) {
|
||||
qWarning() << "Creating the screenshot failed:" << reply.error().name() << reply.error().message();
|
||||
} else {
|
||||
QString filePath = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation);
|
||||
if (filePath.isEmpty()) {
|
||||
qWarning() << "Couldn't find a writable location for the screenshot! The screenshot is in /tmp.";
|
||||
return;
|
||||
}
|
||||
|
||||
QDir picturesDir(filePath);
|
||||
if (!picturesDir.mkpath(QStringLiteral("Screenshots"))) {
|
||||
qWarning() << "Couldn't create folder at"
|
||||
<< picturesDir.path() + QStringLiteral("/Screenshots")
|
||||
<< "to take screenshot.";
|
||||
return;
|
||||
}
|
||||
|
||||
filePath += QStringLiteral("/Screenshots/Screenshot_%1.png")
|
||||
.arg(QDateTime::currentDateTime().toString(QStringLiteral("yyyyMMdd_hhmmss")));
|
||||
|
||||
const QString currentPath = reply.argumentAt<0>();
|
||||
QtConcurrent::run(QThreadPool::globalInstance(), [=]() {
|
||||
QFile screenshotFile(currentPath);
|
||||
if (!screenshotFile.rename(filePath)) {
|
||||
qWarning() << "Couldn't move screenshot into Pictures folder:"
|
||||
<< screenshotFile.errorString();
|
||||
}
|
||||
|
||||
qDebug() << "Successfully saved screenshot at" << filePath;
|
||||
});
|
||||
}
|
||||
|
||||
watcher->deleteLater();
|
||||
interface->deleteLater();
|
||||
});
|
||||
}
|
||||
|
||||
K_EXPORT_PLASMA_APPLET_WITH_JSON(quicksettings, PhonePanel, "metadata.json")
|
||||
|
||||
#include "phonepanel.moc"
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ public:
|
|||
public Q_SLOTS:
|
||||
void executeCommand(const QString &command);
|
||||
void toggleTorch();
|
||||
void takeScreenshot();
|
||||
|
||||
private:
|
||||
GstElement* m_pipeline;
|
||||
|
|
|
|||
Loading…
Reference in a new issue