mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-04-26 14:23:09 +00:00
Quicksettings: add toggle for enabling/disabling screen rotation
This commit is contained in:
parent
6db9537dd3
commit
9cbb53744f
5 changed files with 70 additions and 1 deletions
|
|
@ -1,4 +1,5 @@
|
|||
qt5_add_dbus_interfaces(DBUS_SRCS dbus/org.kde.KWin.Screenshot.xml)
|
||||
qt5_add_dbus_interfaces(DBUS_SRCS dbus/org.kde.KWin.Screenshot.xml
|
||||
dbus/org.kde.KScreen.xml)
|
||||
|
||||
set(phonepanel_SRCS
|
||||
phonepanel.cpp
|
||||
|
|
|
|||
21
containments/panel/dbus/org.kde.KScreen.xml
Normal file
21
containments/panel/dbus/org.kde.KScreen.xml
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
<!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.KScreen">
|
||||
<method name="applyLayoutPreset">
|
||||
<arg type="s" name="presetName" direction="in" />
|
||||
</method>
|
||||
<method name="getAutoRotate">
|
||||
<arg type="b" direction="out" />
|
||||
</method>
|
||||
<method name="setAutoRotate">
|
||||
<arg type="b" name="value" direction="in" />
|
||||
</method>
|
||||
<signal name="outputConnected">
|
||||
<arg type="s" name="outputName" direction="out" />
|
||||
</signal>
|
||||
<signal name="unknownOutputConnected">
|
||||
<arg type="s" name="outputName" direction="out" />
|
||||
</signal>
|
||||
</interface>
|
||||
</node>
|
||||
|
|
@ -60,6 +60,12 @@ Item {
|
|||
settingsModel.get(2).enabled = !enabledConnections.wwanEnabled
|
||||
}
|
||||
|
||||
function toggleRotation() {
|
||||
const enable = !plasmoid.nativeInterface.autoRotateEnabled
|
||||
plasmoid.nativeInterface.autoRotateEnabled = enable
|
||||
settingsModel.get(8).enabled = enable
|
||||
}
|
||||
|
||||
function requestShutdown() {
|
||||
print("Shutdown requested, depends on ksmserver running");
|
||||
var service = pmSource.serviceForSource("PowerDevil");
|
||||
|
|
@ -199,6 +205,14 @@ Item {
|
|||
"toggleFunction": "requestScreenshot",
|
||||
"applet": null
|
||||
});
|
||||
settingsModel.append({
|
||||
"text": i18n("Auto-rotate"),
|
||||
"icon": "rotation-allowed",
|
||||
"enabled": plasmoid.nativeInterface.autoRotateEnabled,
|
||||
"settingsCommand": "",
|
||||
"toggleFunction": "toggleRotation",
|
||||
"applet": null
|
||||
});
|
||||
|
||||
brightnessSlider.moved.connect(function() {
|
||||
root.screenBrightness = brightnessSlider.value;
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ PhonePanel::PhonePanel(QObject *parent, const QVariantList &args)
|
|||
: Plasma::Containment(parent, args)
|
||||
{
|
||||
//setHasConfigurationInterface(true);
|
||||
m_kscreenInterface = new org::kde::KScreen(QStringLiteral("org.kde.kded5"), QStringLiteral("/modules/kscreen"), QDBusConnection::sessionBus(), this);
|
||||
m_screenshotInterface = new org::kde::kwin::Screenshot(QStringLiteral("org.kde.KWin"), QStringLiteral("/Screenshot"), QDBusConnection::sessionBus(), this);
|
||||
}
|
||||
|
||||
|
|
@ -79,6 +80,29 @@ void PhonePanel::toggleTorch()
|
|||
}
|
||||
}
|
||||
|
||||
bool PhonePanel::autoRotate()
|
||||
{
|
||||
QDBusPendingReply<bool> reply = m_kscreenInterface->getAutoRotate();
|
||||
reply.waitForFinished();
|
||||
if (reply.isError()) {
|
||||
qWarning() << "Getting auto rotate failed:" << reply.error().name() << reply.error().message();
|
||||
return false;
|
||||
} else {
|
||||
return reply.value();
|
||||
}
|
||||
}
|
||||
|
||||
void PhonePanel::setAutoRotate(bool value)
|
||||
{
|
||||
QDBusPendingReply<> reply = m_kscreenInterface->setAutoRotate(value);
|
||||
reply.waitForFinished();
|
||||
if (reply.isError()) {
|
||||
qWarning() << "Setting auto rotate failed:" << reply.error().name() << reply.error().message();
|
||||
} else {
|
||||
emit autoRotateChanged(value);
|
||||
}
|
||||
}
|
||||
|
||||
void PhonePanel::takeScreenshot()
|
||||
{
|
||||
// wait ~200 ms to wait for rest of animations
|
||||
|
|
|
|||
|
|
@ -26,11 +26,13 @@
|
|||
|
||||
#include <gst/gst.h>
|
||||
|
||||
#include "kscreeninterface.h"
|
||||
#include "screenshotinterface.h"
|
||||
|
||||
class PhonePanel : public Plasma::Containment
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(bool autoRotateEnabled READ autoRotate WRITE setAutoRotate NOTIFY autoRotateChanged);
|
||||
|
||||
public:
|
||||
PhonePanel( QObject *parent, const QVariantList &args );
|
||||
|
|
@ -41,12 +43,19 @@ public Q_SLOTS:
|
|||
void toggleTorch();
|
||||
void takeScreenshot();
|
||||
|
||||
bool autoRotate();
|
||||
void setAutoRotate(bool value);
|
||||
|
||||
signals:
|
||||
void autoRotateChanged(bool value);
|
||||
|
||||
private:
|
||||
GstElement* m_pipeline;
|
||||
GstElement* m_sink;
|
||||
GstElement* m_source;
|
||||
bool m_running = false;
|
||||
|
||||
org::kde::KScreen *m_kscreenInterface;
|
||||
org::kde::kwin::Screenshot *m_screenshotInterface;
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue