diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,6 +52,7 @@ add_subdirectory(icons) add_subdirectory(kcm) add_subdirectory(kded) +add_subdirectory(plasmoid) add_subdirectory(tests) add_subdirectory(console) diff --git a/kded/CMakeLists.txt b/kded/CMakeLists.txt --- a/kded/CMakeLists.txt +++ b/kded/CMakeLists.txt @@ -9,6 +9,7 @@ device.cpp osd.cpp osdmanager.cpp + osdaction.cpp ${CMAKE_SOURCE_DIR}/kcm/src/utils.cpp ) diff --git a/kded/daemon.h b/kded/daemon.h --- a/kded/daemon.h +++ b/kded/daemon.h @@ -62,7 +62,10 @@ void showOutputIdentifier(); void applyOsdAction(KScreen::OsdAction::Action action); + // DBus + void applyLayoutPreset(const QString &presetName); Q_SIGNALS: + // DBus void outputConnected(const QString &outputName); void unknownOutputConnected(const QString &outputName); diff --git a/kded/daemon.cpp b/kded/daemon.cpp --- a/kded/daemon.cpp +++ b/kded/daemon.cpp @@ -1,6 +1,9 @@ /************************************************************************************* * Copyright (C) 2012 by Alejandro Fiestas Olivares * * Copyright 2016 by Sebastian Kügler * + * Copyright (c) 2018 Kai Uwe Broulik * + * Work sponsored by the LiMux project of * + * the city of Munich. * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License * @@ -174,6 +177,20 @@ doApplyConfig(config); } +void KScreenDaemon::applyLayoutPreset(const QString &presetName) +{ + const QMetaEnum actionEnum = QMetaEnum::fromType(); + Q_ASSERT(actionEnum.isValid()); + + bool ok; + auto action = static_cast(actionEnum.keyToValue(qPrintable(presetName), &ok)); + if (!ok) { + qCWarning(KSCREEN_KDED) << "Cannot apply unknown screen layout preset named" << presetName; + return; + } + applyOsdAction(action); +} + void KScreenDaemon::applyOsdAction(KScreen::OsdAction::Action action) { switch (action) { diff --git a/kded/org.kde.KScreen.xml b/kded/org.kde.KScreen.xml --- a/kded/org.kde.KScreen.xml +++ b/kded/org.kde.KScreen.xml @@ -2,11 +2,14 @@ "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd"> + + + \ No newline at end of file diff --git a/kded/osdaction.h b/kded/osdaction.h new file mode 100644 --- /dev/null +++ b/kded/osdaction.h @@ -0,0 +1,55 @@ +/* + * Copyright 2016 Sebastian Kügler + * Copyright (c) 2018 Kai Uwe Broulik + * Work sponsored by the LiMux project of + * the city of Munich. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#pragma once + +#include +#include +#include + +namespace KScreen { + +class OsdAction : public QObject +{ + Q_OBJECT +public: + enum Action { + NoAction, + SwitchToExternal, + SwitchToInternal, + Clone, + ExtendLeft, + ExtendRight + }; + Q_ENUM(Action) + + explicit OsdAction(QObject *parent = nullptr); + + Q_INVOKABLE QVector actionOrder() const; + Q_INVOKABLE QString actionLabel(Action action) const; + Q_INVOKABLE QString actionIconName(Action action) const; + +Q_SIGNALS: + void selected(Action action); + +}; + +} // namespace KScreen diff --git a/kded/osdaction.cpp b/kded/osdaction.cpp new file mode 100644 --- /dev/null +++ b/kded/osdaction.cpp @@ -0,0 +1,76 @@ +/* + * Copyright 2016 Sebastian Kügler + * Copyright (c) 2018 Kai Uwe Broulik + * Work sponsored by the LiMux project of + * the city of Munich. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "osdaction.h" + +#include + +using namespace KScreen; + +OsdAction::OsdAction(QObject *parent) + : QObject(parent) +{ +} + +QVector OsdAction::actionOrder() const +{ + return { + SwitchToExternal, + SwitchToInternal, + Clone, + ExtendLeft, + ExtendRight, + NoAction + }; +} + +QString OsdAction::actionLabel(OsdAction::Action action) const +{ + switch (action) { + // this is built by both daemon and plasmoid, needs explicit translation domain here + case SwitchToExternal: return i18nd("kscreen", "Switch to external screen"); + case SwitchToInternal: return i18nd("kscreen", "Switch to laptop screen"); + case Clone: return i18nd("kscreen", "Unify outputs"); + case ExtendLeft: return i18nd("kscreen", "Extend to left"); + case ExtendRight: return i18nd("kscreen", "Extend to right"); + case NoAction: return i18nd("kscreen", "Leave unchanged"); + } + + Q_UNREACHABLE(); + return QString(); +} + +QString OsdAction::actionIconName(OsdAction::Action action) const +{ + switch (action) { + case SwitchToExternal: return QStringLiteral("osd-shutd-laptop"); + case SwitchToInternal: return QStringLiteral("osd-shutd-screen"); + case Clone: return QStringLiteral("osd-duplicate"); + case ExtendLeft: return QStringLiteral("osd-sbs-left"); + case ExtendRight: return QStringLiteral("osd-sbs-sright"); + case NoAction: return QStringLiteral("dialog-cancel"); + } + + Q_UNREACHABLE(); + return QString(); +} + +#include "osdaction.moc" diff --git a/kded/osdmanager.h b/kded/osdmanager.h --- a/kded/osdmanager.h +++ b/kded/osdmanager.h @@ -24,36 +24,16 @@ #include #include +#include "osdaction.h" + class QmlObject; namespace KScreen { class ConfigOperation; class Osd; class Output; -class OsdAction : public QObject -{ - Q_OBJECT -public: - enum Action { - NoAction, - SwitchToExternal, - SwitchToInternal, - Clone, - ExtendLeft, - ExtendRight - }; - Q_ENUM(Action) - -Q_SIGNALS: - void selected(Action action); - -protected: - explicit OsdAction(QObject *parent = nullptr); -}; - - class OsdManager : public QObject { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.kde.kscreen.osdService") diff --git a/kded/osdmanager.cpp b/kded/osdmanager.cpp --- a/kded/osdmanager.cpp +++ b/kded/osdmanager.cpp @@ -30,11 +30,6 @@ namespace KScreen { -OsdAction::OsdAction(QObject *parent) - : QObject(parent) -{ -} - class OsdActionImpl : public OsdAction { Q_OBJECT @@ -56,7 +51,9 @@ : QObject(parent) , m_cleanupTimer(new QTimer(this)) { - qmlRegisterUncreatableType("org.kde.KScreen", 1, 0, "OsdAction", QStringLiteral("You cannot create OsdAction")); + qmlRegisterSingletonType("org.kde.KScreen", 1, 0, "OsdAction", [](QQmlEngine *, QJSEngine *) -> QObject* { + return new KScreen::OsdAction(); + }); // free up memory when the osd hasn't been used for more than 1 minute m_cleanupTimer->setInterval(60000); diff --git a/kded/qml/OsdSelector.qml b/kded/qml/OsdSelector.qml --- a/kded/qml/OsdSelector.qml +++ b/kded/qml/OsdSelector.qml @@ -46,38 +46,15 @@ Repeater { id: actionRepeater property int currentIndex: 0 - model: [ - { - iconSource: "osd-shutd-laptop", - label: i18n("Switch to external screen"), - action: OsdAction.SwitchToExternal - }, - { - iconSource: "osd-shutd-screen", - label: i18n("Switch to laptop screen"), - action: OsdAction.SwitchToInternal - }, - { - iconSource: "osd-duplicate", - label: i18n("Unify outputs"), - action: OsdAction.Clone - }, - { - iconSource: "osd-sbs-left", - label: i18n("Extend to left"), - action: OsdAction.ExtendLeft - }, - { - iconSource: "osd-sbs-sright", - label: i18n("Extend to right"), - action: OsdAction.ExtendRight - }, - { - iconSource: "dialog-cancel", - label: i18n("Leave unchanged"), - action: OsdAction.NoAction + model: { + return OsdAction.actionOrder().map(function (layout) { + return { + iconSource: OsdAction.actionIconName(layout), + label: OsdAction.actionLabel(layout), + action: layout } - ] + }); + } delegate: PlasmaComponents.Button { property var action: modelData.action Accessible.name: modelData.label diff --git a/plasmoid/CMakeLists.txt b/plasmoid/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/plasmoid/CMakeLists.txt @@ -0,0 +1,21 @@ +add_definitions(-DTRANSLATION_DOMAIN=\"plasma_applet_org.kde.kscreen\") + +set(kscreenapplet_SRCS + kscreenapplet.cpp + ../kded/osdaction.cpp +) + +add_library(plasma_applet_kscreen MODULE ${kscreenapplet_SRCS}) + +kcoreaddons_desktop_to_json(plasma_applet_kscreen package/metadata.desktop) + +target_link_libraries(plasma_applet_kscreen + Qt5::Qml + Qt5::DBus + KF5::I18n + KF5::Plasma + KF5::Screen) + +install(TARGETS plasma_applet_kscreen DESTINATION ${KDE_INSTALL_PLUGINDIR}/plasma/applets) + +plasma_install_package(package org.kde.kscreen) diff --git a/plasmoid/Messages.sh b/plasmoid/Messages.sh new file mode 100755 --- /dev/null +++ b/plasmoid/Messages.sh @@ -0,0 +1,2 @@ +#! /usr/bin/env bash +$XGETTEXT `find . -name \*.qml -o -name \*.cpp` -o $podir/plasma_applet_org.kde.kscreen.pot diff --git a/plasmoid/kscreenapplet.h b/plasmoid/kscreenapplet.h new file mode 100644 --- /dev/null +++ b/plasmoid/kscreenapplet.h @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2018 Kai Uwe Broulik + * Work sponsored by the LiMux project of + * the city of Munich. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License or (at your option) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#pragma once + +#include + +#include + +class KScreenApplet : public Plasma::Applet +{ + Q_OBJECT + + /** + * The number of currently connected (not neccessarily enabled) outputs + */ + Q_PROPERTY(int connectedOutputCount READ connectedOutputCount NOTIFY connectedOutputCountChanged) + +public: + explicit KScreenApplet(QObject *parent, const QVariantList &data); + ~KScreenApplet() override; + + enum Action { + SwitchToExternal, + SwitchToInternal, + Clone, + ExtendLeft, + ExtendRight + }; + Q_ENUM(Action) + + void init() override; + + int connectedOutputCount() const; + + Q_INVOKABLE void applyLayoutPreset(Action action); + +signals: + void connectedOutputCountChanged(); + +private: + void checkOutputs(); + + KScreen::ConfigPtr m_screenConfiguration; + int m_connectedOutputCount = 0; + +}; diff --git a/plasmoid/kscreenapplet.cpp b/plasmoid/kscreenapplet.cpp new file mode 100644 --- /dev/null +++ b/plasmoid/kscreenapplet.cpp @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2018 Kai Uwe Broulik + * Work sponsored by the LiMux project of + * the city of Munich. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License or (at your option) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#include "kscreenapplet.h" + +#include // for qmlRegisterType +#include + +#include +#include + +#include +#include +#include +#include + +#include "../kded/osdaction.h" + +#include + +KScreenApplet::KScreenApplet(QObject *parent, const QVariantList &data) + : Plasma::Applet(parent, data) +{ + +} + +KScreenApplet::~KScreenApplet() = default; + +void KScreenApplet::init() +{ + qmlRegisterSingletonType("org.kde.private.kscreen", 1, 0, "OsdAction", [](QQmlEngine *, QJSEngine *) -> QObject* { + return new KScreen::OsdAction(); + }); + + connect(new KScreen::GetConfigOperation(KScreen::GetConfigOperation::NoEDID), &KScreen::ConfigOperation::finished, + this, [this](KScreen::ConfigOperation *op) { + m_screenConfiguration = qobject_cast(op)->config(); + + KScreen::ConfigMonitor::instance()->addConfig(m_screenConfiguration); + connect(KScreen::ConfigMonitor::instance(), &KScreen::ConfigMonitor::configurationChanged, this, &KScreenApplet::checkOutputs); + + checkOutputs(); + }); +} + +int KScreenApplet::connectedOutputCount() const +{ + return m_connectedOutputCount; +} + +void KScreenApplet::applyLayoutPreset(Action action) +{ + const QMetaEnum actionEnum = QMetaEnum::fromType(); + Q_ASSERT(actionEnum.isValid()); + + const QString presetName = QString::fromLatin1(actionEnum.valueToKey(action)); + if (presetName.isEmpty()) { + return; + } + + QDBusMessage msg = QDBusMessage::createMethodCall( + QStringLiteral("org.kde.kded5"), + QStringLiteral("/modules/kscreen"), + QStringLiteral("org.kde.KScreen"), + QStringLiteral("applyLayoutPreset") + ); + + msg.setArguments({presetName}); + + QDBusConnection::sessionBus().call(msg, QDBus::NoBlock); +} + +void KScreenApplet::checkOutputs() +{ + if (!m_screenConfiguration) { + return; + } + + const int oldConnectedOutputCount = m_connectedOutputCount; + + const auto outputs = m_screenConfiguration->outputs(); + m_connectedOutputCount = std::count_if(outputs.begin(), outputs.end(), [](const KScreen::OutputPtr &output) { + return output->isConnected(); + }); + + if (m_connectedOutputCount != oldConnectedOutputCount) { + emit connectedOutputCountChanged(); + } +} + +K_EXPORT_PLASMA_APPLET_WITH_JSON(kscreen, KScreenApplet, "metadata.json") + +#include "kscreenapplet.moc" diff --git a/plasmoid/package/contents/ui/PresentationModeItem.qml b/plasmoid/package/contents/ui/PresentationModeItem.qml new file mode 100644 --- /dev/null +++ b/plasmoid/package/contents/ui/PresentationModeItem.qml @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2018 Kai Uwe Broulik + * Work sponsored by the LiMux project of + * the city of Munich. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License or (at your option) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +import QtQuick 2.8 +import QtQuick.Layouts 1.1 + +import org.kde.plasma.core 2.0 as PlasmaCore +import org.kde.plasma.components 2.0 as PlasmaComponents +import org.kde.plasma.extras 2.0 as PlasmaExtras + +ColumnLayout { + spacing: units.smallSpacing + + PlasmaExtras.Heading { + Layout.fillWidth: true + level: 2 + text: i18n("Presentation Mode") + } + + PlasmaExtras.DescriptiveLabel { + Layout.fillWidth: true + // remove spacing between heading and this descriptive label + Layout.topMargin: -parent.spacing + font.pointSize: theme.smallestFont.pointSize + text: i18n("This will prevent your screen and computer from turning off automatically.") + wrapMode: Text.WordWrap + } + + PlasmaComponents.CheckBox { + id: checkBox + Layout.fillWidth: true + text: i18n("Enable Presentation Mode") + + onCheckedChanged: { + if (checked === root.presentationModeEnabled) { + return; + } + + // disable CheckBox while job is running + checkBox.enabled = false; + + var service = pmSource.serviceForSource("PowerDevil"); + + if (checked) { + var op = service.operationDescription("beginSuppressingScreenPowerManagement"); + op.reason = i18n("User enabled presentation mode"); + + var job = service.startOperationCall(op); + job.finished.connect(function (job) { + presentationModeCookie = job.result; + checkBox.enabled = true; + }); + } else { + var op = service.operationDescription("stopSuppressingScreenPowerManagement"); + op.cookie = presentationModeCookie; + + var job = service.startOperationCall(op); + job.finished.connect(function (job) { + presentationModeCookie = -1; + checkBox.enabled = true; + }); + } + } + } + + RowLayout { + Layout.fillWidth: true + spacing: units.smallSpacing + + PlasmaCore.IconItem { + Layout.preferredWidth: units.iconSizes.medium + Layout.preferredHeight: units.iconSizes.medium + source: pmSource.inhibitions[0] ? pmSource.inhibitions[0].Icon || "" : "" + visible: valid + } + + PlasmaComponents.Label { + Layout.fillWidth: true + Layout.maximumWidth: Math.min(units.gridUnit * 20, implicitWidth) + font.pointSize: theme.smallestFont.pointSize + wrapMode: Text.WordWrap + elide: Text.ElideRight + textFormat: Text.PlainText + text: { + var inhibitions = pmSource.inhibitions; + if (inhibitions.length > 1) { + return i18ncp("Some Application and n others enforce presentation mode", + "%2 and %1 other application are enforcing presentation mode.", + "%2 and %1 other applications are enforcing presentation mode.", + inhibitions.length - 1, inhibitions[0].Name) // plural only works on %1 + } else if (inhibitions.length === 1) { + if (!inhibitions[0].Reason) { + return i18nc("Some Application enforce presentation mode", + "%1 is enforcing presentation mode.", inhibitions[0].Name) + } else { + return i18nc("Some Application enforce presentation mode: Reason provided by the app", + "%1 is enforcing presentation mode: %2", inhibitions[0].Name, inhibitions[0].Reason) + } + } else { + return ""; + } + } + } + } +} diff --git a/plasmoid/package/contents/ui/ScreenLayoutSelection.qml b/plasmoid/package/contents/ui/ScreenLayoutSelection.qml new file mode 100644 --- /dev/null +++ b/plasmoid/package/contents/ui/ScreenLayoutSelection.qml @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2018 Kai Uwe Broulik + * Work sponsored by the LiMux project of + * the city of Munich. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License or (at your option) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +import QtQuick 2.8 +import QtQuick.Layouts 1.1 + +import org.kde.plasma.plasmoid 2.0 +import org.kde.plasma.core 2.0 as PlasmaCore +import org.kde.plasma.components 2.0 as PlasmaComponents +import org.kde.plasma.extras 2.0 as PlasmaExtras + +ColumnLayout { + spacing: 0 + + states: [ + State { + // only makes sense to offer screen layout setup if there's more than one screen connected + when: plasmoid.nativeInterface.connectedOutputCount < 2 + + PropertyChanges { + target: screenLayoutRow + enabled: false + } + PropertyChanges { + target: noScreenLabel + visible: true + } + } + ] + + PlasmaExtras.Heading { + Layout.fillWidth: true + level: 2 + text: i18n("Screen Layout") + } + + // Screen layout selector section + Row { + id: screenLayoutRow + readonly property int buttonSize: Math.floor((width - spacing * (screenLayoutRepeater.count - 1)) / screenLayoutRepeater.count) + Layout.fillWidth: true + spacing: units.smallSpacing + + Repeater { + id: screenLayoutRepeater + model: root.screenLayouts + + PlasmaComponents.Button { + width: screenLayoutRow.buttonSize + height: width + tooltip: modelData.label + Accessible.name: tooltip + onClicked: plasmoid.nativeInterface.applyLayoutPreset(modelData.action) + + // HACK otherwise the icon won't expand to full button size + PlasmaCore.IconItem { + anchors.centerIn: parent + width: height + // FIXME use proper FrameSvg margins and stuff + height: parent.height - units.smallSpacing + source: modelData.iconName + active: parent.hovered + } + } + } + } + + PlasmaExtras.DescriptiveLabel { + id: noScreenLabel + Layout.fillWidth: true + Layout.maximumWidth: Math.min(units.gridUnit * 20, implicitWidth) + wrapMode: Text.Wrap + text: i18n("You can only apply a different screen layout when there is more than one display device plugged in.") + font.pointSize: theme.smallestFont.pointSize + visible: false + } +} diff --git a/plasmoid/package/contents/ui/main.qml b/plasmoid/package/contents/ui/main.qml new file mode 100644 --- /dev/null +++ b/plasmoid/package/contents/ui/main.qml @@ -0,0 +1,131 @@ +/* + * Copyright (c) 2018 Kai Uwe Broulik + * Work sponsored by the LiMux project of + * the city of Munich. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License or (at your option) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +import QtQuick 2.8 +import QtQuick.Layouts 1.1 + +import org.kde.plasma.plasmoid 2.0 +import org.kde.plasma.core 2.0 as PlasmaCore +import org.kde.plasma.components 2.0 as PlasmaComponents +import org.kde.plasma.extras 2.0 as PlasmaExtras +import org.kde.kquickcontrolsaddons 2.0 + +import org.kde.private.kscreen 1.0 + +Item { + id: root + + // Only show if there's screen layouts available or the user enabled presentation mode + Plasmoid.status: presentationModeEnabled || plasmoid.nativeInterface.connectedOutputCount > 1 ? PlasmaCore.Types.ActiveStatus : PlasmaCore.Types.PassiveStatus + Plasmoid.toolTipSubText: presentationModeEnabled ? i18n("Presentation mode is enabled") : "" + + readonly property string kcmName: "kcm_kscreen" + // does this need an ellipsis? + readonly property string kcmLabel: i18nc("Open the full display settings module", "Advanced Display Settings...") + readonly property string kcmIconName: "preferences-desktop-display-randr" + readonly property bool kcmAllowed: KCMShell.authorize(kcmName + ".desktop").length > 0 + + readonly property bool presentationModeEnabled: presentationModeCookie > 0 + property int presentationModeCookie: -1 + + readonly property var screenLayouts: { + var layouts = OsdAction.actionOrder().filter(function (layout) { + // We don't want the "No action" item in the plasmoid + return layout !== OsdAction.NoAction; + }); + + layouts.map(function (layout) { + return { + iconName: OsdAction.actionIconName(layout), + label: OsdAction.actionLabel(layout), + action: layout + } + }); + } + + PlasmaCore.DataSource { + id: pmSource + engine: "powermanagement" + connectedSources: ["PowerDevil", "Inhibitions"] + + onSourceAdded: { + disconnectSource(source); + connectSource(source); + } + onSourceRemoved: { + disconnectSource(source); + } + + readonly property var inhibitions: { + var inhibitions = []; + + var data = pmSource.data.Inhibitions; + if (data) { + for (var key in data) { + if (key === "plasmashell" || key === "plasmoidviewer") { // ignore our own inhibition + continue; + } + + inhibitions.push(data[key]); + } + } + + return inhibitions; + } + } + + function action_openKcm() { + KCMShell.open(kcmName); + } + + Component.onCompleted: { + if (kcmAllowed) { + plasmoid.setAction("openKcm", root.kcmLabel, root.kcmIconName) + } + } + + Plasmoid.fullRepresentation: ColumnLayout { + spacing: units.smallSpacing + Layout.preferredWidth: units.gridUnit * 15 + + ScreenLayoutSelection { + Layout.fillWidth: true + } + + PresentationModeItem { + Layout.fillWidth: true + } + + // compact the layout, push settings button to the bottom + Item { + Layout.fillHeight: true + } + + PlasmaComponents.Button { + Layout.alignment: Qt.AlignRight + text: root.kcmLabel + iconName: root.kcmIconName + onClicked: action_openKcm() + } + } +} diff --git a/plasmoid/package/metadata.desktop b/plasmoid/package/metadata.desktop new file mode 100644 --- /dev/null +++ b/plasmoid/package/metadata.desktop @@ -0,0 +1,21 @@ +[Desktop Entry] +Name=Display Configuration +Comment=Quickly switch between screen layouts and presentation mode +Icon=preferences-desktop-display + +X-KDE-ServiceTypes=Plasma/Applet +Type=Service + +X-Plasma-API=declarativeappletscript +X-Plasma-MainScript=ui/main.qml + +X-KDE-PluginInfo-Author=Kai Uwe Broulik +X-KDE-PluginInfo-Email=kde@broulik.de +X-KDE-PluginInfo-Name=org.kde.kscreen +X-KDE-PluginInfo-Version=1.0 +X-KDE-PluginInfo-Website=http://plasma.kde.org/ +X-KDE-PluginInfo-Category=Utilities +X-KDE-PluginInfo-License=GPL + +X-Plasma-NotificationArea=true +X-Plasma-NotificationAreaCategory=Hardware diff --git a/tests/osd/CMakeLists.txt b/tests/osd/CMakeLists.txt --- a/tests/osd/CMakeLists.txt +++ b/tests/osd/CMakeLists.txt @@ -7,6 +7,7 @@ osdtest.cpp ../../kded/osd.cpp ../../kded/osdmanager.cpp + ../../kded/osdaction.cpp ../../kcm/src/utils.cpp )