From b84293cf722e7338e5ea2133d5e1491ae3535083 Mon Sep 17 00:00:00 2001 From: Willem-Jan de Hoog Date: Thu, 20 Aug 2020 16:20:08 -0400 Subject: [PATCH 1/7] broadcast some keys on dbus --- plugins/CMakeLists.txt | 1 + plugins/HandleMediaKeys/CMakeLists.txt | 15 ++++++ plugins/HandleMediaKeys/HandleMediaKeys.cpp | 53 +++++++++++++++++++++ plugins/HandleMediaKeys/HandleMediaKeys.h | 44 +++++++++++++++++ plugins/HandleMediaKeys/plugin.cpp | 34 +++++++++++++ plugins/HandleMediaKeys/plugin.h | 32 +++++++++++++ plugins/HandleMediaKeys/qmldir | 3 ++ qml/Components/PhysicalKeysMapper.qml | 7 +++ qml/Shell.qml | 3 ++ 9 files changed, 192 insertions(+) create mode 100644 plugins/HandleMediaKeys/CMakeLists.txt create mode 100644 plugins/HandleMediaKeys/HandleMediaKeys.cpp create mode 100644 plugins/HandleMediaKeys/HandleMediaKeys.h create mode 100644 plugins/HandleMediaKeys/plugin.cpp create mode 100644 plugins/HandleMediaKeys/plugin.h create mode 100644 plugins/HandleMediaKeys/qmldir diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 4841bcc529..003d3eb2e2 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -15,6 +15,7 @@ add_subdirectory(AccountsService) add_subdirectory(Cursor) add_subdirectory(GlobalShortcut) add_subdirectory(Greeter) +add_subdirectory(HandleMediaKeys) add_subdirectory(LightDM) add_subdirectory(Lights) add_subdirectory(Powerd) diff --git a/plugins/HandleMediaKeys/CMakeLists.txt b/plugins/HandleMediaKeys/CMakeLists.txt new file mode 100644 index 0000000000..55a2a8f86d --- /dev/null +++ b/plugins/HandleMediaKeys/CMakeLists.txt @@ -0,0 +1,15 @@ +include_directories(${GLIB_INCLUDE_DIRS}) +add_definitions(-DSM_BUSNAME=sessionBus) + +add_library(HandleMediaKeys-qml MODULE + HandleMediaKeys.cpp + plugin.cpp + ) + +qt5_use_modules(HandleMediaKeys-qml DBus Qml) + +target_link_libraries(HandleMediaKeys-qml + ${GLIB_LIBRARIES} + ) + +add_unity8_plugin(HandleMediaKeys 0.1 HandleMediaKeys TARGETS HandleMediaKeys-qml) diff --git a/plugins/HandleMediaKeys/HandleMediaKeys.cpp b/plugins/HandleMediaKeys/HandleMediaKeys.cpp new file mode 100644 index 0000000000..273c54ee84 --- /dev/null +++ b/plugins/HandleMediaKeys/HandleMediaKeys.cpp @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2020 UBports Foundation + * + * 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; version 3. + * + * 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 "HandleMediaKeys.h" +#include +#include +#include +#include + +#include + +HandleMediaKeys::HandleMediaKeys(QObject* parent) + : QObject(parent) +{ + + auto connection = QDBusConnection::SM_BUSNAME(); + auto interface = connection.interface(); + interface->startService(QStringLiteral("com.ubports.Lomiri.Broadcast")); + + m_broadcaster = new QDBusInterface(QStringLiteral("com.ubports.Lomiri.Broadcast"), + QStringLiteral("/com/ubports/Lomiri/Broadcast"), + QStringLiteral("com.ubports.Lomiri.Broadcast"), + connection, this); + + connect(m_broadcaster, SIGNAL(MediaKey(int key)), + this, SLOT(onMediaKey(int key))); + +} + +void HandleMediaKeys::notifyMediaKey(int key) +{ + qDebug() << "notifyMediaKey(" << key << ")"; + m_broadcaster->asyncCall(QStringLiteral("MediaKey"), key); +} + +void HandleMediaKeys::onMediaKey(int key) +{ + Q_EMIT mediaKey(key); +} + diff --git a/plugins/HandleMediaKeys/HandleMediaKeys.h b/plugins/HandleMediaKeys/HandleMediaKeys.h new file mode 100644 index 0000000000..e21e2d3c71 --- /dev/null +++ b/plugins/HandleMediaKeys/HandleMediaKeys.h @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2020 UBports Foundation + * + * 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; version 3. + * + * 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 . + */ + +#ifndef LOMIRI_HANDLEMEDIAKEYS_H +#define LOMIRI_HANDLEMEDIAKEYS_H + +#include +#include + +class QDBusInterface; + +class HandleMediaKeys: public QObject +{ + Q_OBJECT + +public: + explicit HandleMediaKeys(QObject *parent = 0); + + Q_INVOKABLE void notifyMediaKey(int key); + +Q_SIGNALS: + void mediaKey(int key); + +private Q_SLOTS: + void onMediaKey(int key); + +private: + QDBusInterface *m_broadcaster; +}; + +#endif diff --git a/plugins/HandleMediaKeys/plugin.cpp b/plugins/HandleMediaKeys/plugin.cpp new file mode 100644 index 0000000000..8c51dfebd4 --- /dev/null +++ b/plugins/HandleMediaKeys/plugin.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2020 UBports Foundation + * + * 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; version 3. + * + * 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 "plugin.h" +#include "HandleMediaKeys.h" + +#include + +static QObject *broadcast_provider(QQmlEngine *engine, QJSEngine *scriptEngine) +{ + Q_UNUSED(engine) + Q_UNUSED(scriptEngine) + return new HandleMediaKeys(); +} + +void HandleMediaKeysPlugin::registerTypes(const char *uri) +{ + Q_ASSERT(uri == QLatin1String("HandleMediaKeys")); + qmlRegisterSingletonType(uri, 0, 1, "HandleMediaKeys", broadcast_provider); +} diff --git a/plugins/HandleMediaKeys/plugin.h b/plugins/HandleMediaKeys/plugin.h new file mode 100644 index 0000000000..8c693082d6 --- /dev/null +++ b/plugins/HandleMediaKeys/plugin.h @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2020 UBports Foundation + * + * 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; version 3. + * + * 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 . + * + */ + +#ifndef LOMIRI_HANDLEMEDIAKEYS_PLUGIN +#define LOMIRI_HANDLEMEDIAKEYS_PLUGIN + +#include + +class HandleMediaKeysPlugin : public QQmlExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface") + +public: + void registerTypes(const char *uri) override; +}; + +#endif diff --git a/plugins/HandleMediaKeys/qmldir b/plugins/HandleMediaKeys/qmldir new file mode 100644 index 0000000000..c44748daf0 --- /dev/null +++ b/plugins/HandleMediaKeys/qmldir @@ -0,0 +1,3 @@ +module HandleMediaKeys +plugin HandleMediaKeys-qml +typeinfo HandleMediaKeys.qmltypes diff --git a/qml/Components/PhysicalKeysMapper.qml b/qml/Components/PhysicalKeysMapper.qml index b3f8417061..9252917afc 100644 --- a/qml/Components/PhysicalKeysMapper.qml +++ b/qml/Components/PhysicalKeysMapper.qml @@ -40,6 +40,7 @@ Item { signal volumeDownTriggered; signal volumeUpTriggered; signal screenshotTriggered; + signal mediaKey; readonly property bool altTabPressed: d.altTabPressed readonly property bool superPressed: d.superPressed @@ -158,6 +159,12 @@ Item { d.superTabPressed = false; event.accepted = true; } + } else if ( event.key == Qt.Key_MediaNext + || event.key == Qt.Key_MediaPrevious + || event.key == Qt.Key_MediaPlay + || event.key == Qt.Key_WebCam +) { + root.mediaKey(event.key); } } } diff --git a/qml/Shell.qml b/qml/Shell.qml index 75414bebd1..050e2ccd0d 100644 --- a/qml/Shell.qml +++ b/qml/Shell.qml @@ -30,6 +30,7 @@ import GSettings 1.0 import Utils 0.1 import Powerd 0.1 import SessionBroadcast 0.1 +import HandleMediaKeys 0.1 import "Greeter" import "Launcher" import "Panel" @@ -236,6 +237,8 @@ StyledItem { onVolumeDownTriggered: volumeControl.volumeDown(); onVolumeUpTriggered: volumeControl.volumeUp(); onScreenshotTriggered: itemGrabber.capture(shell); + + onMediaKey: HandleMediaKeys.notifyMediaKey(key); } GlobalShortcut { From b0ea8845e019c364fd97611507066cb50c3db4fe Mon Sep 17 00:00:00 2001 From: Willem-Jan de Hoog Date: Fri, 21 Aug 2020 01:55:45 -0400 Subject: [PATCH 2/7] fix ws --- plugins/HandleMediaKeys/HandleMediaKeys.cpp | 1 - qml/Components/PhysicalKeysMapper.qml | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/plugins/HandleMediaKeys/HandleMediaKeys.cpp b/plugins/HandleMediaKeys/HandleMediaKeys.cpp index 273c54ee84..4deb3486cb 100644 --- a/plugins/HandleMediaKeys/HandleMediaKeys.cpp +++ b/plugins/HandleMediaKeys/HandleMediaKeys.cpp @@ -50,4 +50,3 @@ void HandleMediaKeys::onMediaKey(int key) { Q_EMIT mediaKey(key); } - diff --git a/qml/Components/PhysicalKeysMapper.qml b/qml/Components/PhysicalKeysMapper.qml index 9252917afc..26faf066ba 100644 --- a/qml/Components/PhysicalKeysMapper.qml +++ b/qml/Components/PhysicalKeysMapper.qml @@ -159,8 +159,8 @@ Item { d.superTabPressed = false; event.accepted = true; } - } else if ( event.key == Qt.Key_MediaNext - || event.key == Qt.Key_MediaPrevious + } else if ( event.key == Qt.Key_MediaNext + || event.key == Qt.Key_MediaPrevious || event.key == Qt.Key_MediaPlay || event.key == Qt.Key_WebCam ) { From 65c3447bf3d424358f2507aa77e798bdee1b50b8 Mon Sep 17 00:00:00 2001 From: Willem-Jan de Hoog Date: Fri, 21 Aug 2020 13:34:59 -0400 Subject: [PATCH 3/7] install plugin --- debian/unity8-private.install | 1 + 1 file changed, 1 insertion(+) diff --git a/debian/unity8-private.install b/debian/unity8-private.install index 23f86ab8ac..018f9bf64e 100644 --- a/debian/unity8-private.install +++ b/debian/unity8-private.install @@ -1,5 +1,6 @@ usr/lib/*/libunity8-private.* usr/lib/*/unity8/qml/AccountsService +usr/lib/*/unity8/qml/Broadcaster usr/lib/*/unity8/qml/Cursor usr/lib/*/unity8/qml/GlobalShortcut usr/lib/*/unity8/qml/Greeter From 7e6c25c62dc8020f160dadd3c9c42bbbf9ba7365 Mon Sep 17 00:00:00 2001 From: Willem-Jan de Hoog Date: Sun, 17 Jan 2021 16:19:06 +0100 Subject: [PATCH 4/7] - now all mapping is done in Limiri so plugin is only for broadcasting over dbus - use nativeScanCode if Mir/QtMir does not map the input event to a known key --- .../Broadcaster.cpp} | 17 ++------ .../Broadcaster.h} | 16 +++----- plugins/Broadcaster/CMakeLists.txt | 15 +++++++ .../plugin.cpp | 10 ++--- .../{HandleMediaKeys => Broadcaster}/plugin.h | 6 +-- plugins/Broadcaster/qmldir | 3 ++ plugins/HandleMediaKeys/CMakeLists.txt | 15 ------- plugins/HandleMediaKeys/qmldir | 3 -- qml/Components/PhysicalKeysMapper.qml | 39 +++++++++++++++---- qml/Shell.qml | 4 +- 10 files changed, 69 insertions(+), 59 deletions(-) rename plugins/{HandleMediaKeys/HandleMediaKeys.cpp => Broadcaster/Broadcaster.cpp} (75%) rename plugins/{HandleMediaKeys/HandleMediaKeys.h => Broadcaster/Broadcaster.h} (72%) create mode 100644 plugins/Broadcaster/CMakeLists.txt rename plugins/{HandleMediaKeys => Broadcaster}/plugin.cpp (74%) rename plugins/{HandleMediaKeys => Broadcaster}/plugin.h (86%) create mode 100644 plugins/Broadcaster/qmldir delete mode 100644 plugins/HandleMediaKeys/CMakeLists.txt delete mode 100644 plugins/HandleMediaKeys/qmldir diff --git a/plugins/HandleMediaKeys/HandleMediaKeys.cpp b/plugins/Broadcaster/Broadcaster.cpp similarity index 75% rename from plugins/HandleMediaKeys/HandleMediaKeys.cpp rename to plugins/Broadcaster/Broadcaster.cpp index 4deb3486cb..b45107aa7b 100644 --- a/plugins/HandleMediaKeys/HandleMediaKeys.cpp +++ b/plugins/Broadcaster/Broadcaster.cpp @@ -14,7 +14,7 @@ * along with this program. If not, see . */ -#include "HandleMediaKeys.h" +#include "Broadcaster.h" #include #include #include @@ -22,7 +22,7 @@ #include -HandleMediaKeys::HandleMediaKeys(QObject* parent) +Broadcaster::Broadcaster(QObject* parent) : QObject(parent) { @@ -35,18 +35,9 @@ HandleMediaKeys::HandleMediaKeys(QObject* parent) QStringLiteral("com.ubports.Lomiri.Broadcast"), connection, this); - connect(m_broadcaster, SIGNAL(MediaKey(int key)), - this, SLOT(onMediaKey(int key))); - -} - -void HandleMediaKeys::notifyMediaKey(int key) -{ - qDebug() << "notifyMediaKey(" << key << ")"; - m_broadcaster->asyncCall(QStringLiteral("MediaKey"), key); } -void HandleMediaKeys::onMediaKey(int key) +void Broadcaster::notifyMediaKey(const QString &keyMsg) { - Q_EMIT mediaKey(key); + m_broadcaster->asyncCall(QStringLiteral("MediaKey"), keyMsg); } diff --git a/plugins/HandleMediaKeys/HandleMediaKeys.h b/plugins/Broadcaster/Broadcaster.h similarity index 72% rename from plugins/HandleMediaKeys/HandleMediaKeys.h rename to plugins/Broadcaster/Broadcaster.h index e21e2d3c71..b869719546 100644 --- a/plugins/HandleMediaKeys/HandleMediaKeys.h +++ b/plugins/Broadcaster/Broadcaster.h @@ -14,28 +14,22 @@ * along with this program. If not, see . */ -#ifndef LOMIRI_HANDLEMEDIAKEYS_H -#define LOMIRI_HANDLEMEDIAKEYS_H +#ifndef LOMIRI_BROADCASTER_H +#define LOMIRI_BROADCASTER_H #include #include class QDBusInterface; -class HandleMediaKeys: public QObject +class Broadcaster: public QObject { Q_OBJECT public: - explicit HandleMediaKeys(QObject *parent = 0); + explicit Broadcaster(QObject *parent = 0); - Q_INVOKABLE void notifyMediaKey(int key); - -Q_SIGNALS: - void mediaKey(int key); - -private Q_SLOTS: - void onMediaKey(int key); + Q_INVOKABLE void notifyMediaKey(const QString &keyMsg); private: QDBusInterface *m_broadcaster; diff --git a/plugins/Broadcaster/CMakeLists.txt b/plugins/Broadcaster/CMakeLists.txt new file mode 100644 index 0000000000..e3576fc3a0 --- /dev/null +++ b/plugins/Broadcaster/CMakeLists.txt @@ -0,0 +1,15 @@ +include_directories(${GLIB_INCLUDE_DIRS}) +add_definitions(-DSM_BUSNAME=sessionBus) + +add_library(Broadcaster-qml MODULE + Broadcaster.cpp + plugin.cpp + ) + +qt5_use_modules(Broadcaster-qml DBus Qml) + +target_link_libraries(Broadcaster-qml + ${GLIB_LIBRARIES} + ) + +add_unity8_plugin(Broadcaster 0.1 Broadcaster TARGETS Broadcaster-qml) diff --git a/plugins/HandleMediaKeys/plugin.cpp b/plugins/Broadcaster/plugin.cpp similarity index 74% rename from plugins/HandleMediaKeys/plugin.cpp rename to plugins/Broadcaster/plugin.cpp index 8c51dfebd4..8d43f96a23 100644 --- a/plugins/HandleMediaKeys/plugin.cpp +++ b/plugins/Broadcaster/plugin.cpp @@ -16,7 +16,7 @@ */ #include "plugin.h" -#include "HandleMediaKeys.h" +#include "Broadcaster.h" #include @@ -24,11 +24,11 @@ static QObject *broadcast_provider(QQmlEngine *engine, QJSEngine *scriptEngine) { Q_UNUSED(engine) Q_UNUSED(scriptEngine) - return new HandleMediaKeys(); + return new Broadcaster(); } -void HandleMediaKeysPlugin::registerTypes(const char *uri) +void BroadcasterPlugin::registerTypes(const char *uri) { - Q_ASSERT(uri == QLatin1String("HandleMediaKeys")); - qmlRegisterSingletonType(uri, 0, 1, "HandleMediaKeys", broadcast_provider); + Q_ASSERT(uri == QLatin1String("Broadcaster")); + qmlRegisterSingletonType(uri, 0, 1, "Broadcaster", broadcast_provider); } diff --git a/plugins/HandleMediaKeys/plugin.h b/plugins/Broadcaster/plugin.h similarity index 86% rename from plugins/HandleMediaKeys/plugin.h rename to plugins/Broadcaster/plugin.h index 8c693082d6..7d9d7e71b8 100644 --- a/plugins/HandleMediaKeys/plugin.h +++ b/plugins/Broadcaster/plugin.h @@ -15,12 +15,12 @@ * */ -#ifndef LOMIRI_HANDLEMEDIAKEYS_PLUGIN -#define LOMIRI_HANDLEMEDIAKEYS_PLUGIN +#ifndef LOMIRI_BROADCASTER_PLUGIN +#define LOMIRI_BROADCASTER_PLUGIN #include -class HandleMediaKeysPlugin : public QQmlExtensionPlugin +class BroadcasterPlugin : public QQmlExtensionPlugin { Q_OBJECT Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface") diff --git a/plugins/Broadcaster/qmldir b/plugins/Broadcaster/qmldir new file mode 100644 index 0000000000..2301cd91e9 --- /dev/null +++ b/plugins/Broadcaster/qmldir @@ -0,0 +1,3 @@ +module Broadcaster +plugin Broadcaster-qml +typeinfo Broadcaster.qmltypes diff --git a/plugins/HandleMediaKeys/CMakeLists.txt b/plugins/HandleMediaKeys/CMakeLists.txt deleted file mode 100644 index 55a2a8f86d..0000000000 --- a/plugins/HandleMediaKeys/CMakeLists.txt +++ /dev/null @@ -1,15 +0,0 @@ -include_directories(${GLIB_INCLUDE_DIRS}) -add_definitions(-DSM_BUSNAME=sessionBus) - -add_library(HandleMediaKeys-qml MODULE - HandleMediaKeys.cpp - plugin.cpp - ) - -qt5_use_modules(HandleMediaKeys-qml DBus Qml) - -target_link_libraries(HandleMediaKeys-qml - ${GLIB_LIBRARIES} - ) - -add_unity8_plugin(HandleMediaKeys 0.1 HandleMediaKeys TARGETS HandleMediaKeys-qml) diff --git a/plugins/HandleMediaKeys/qmldir b/plugins/HandleMediaKeys/qmldir deleted file mode 100644 index c44748daf0..0000000000 --- a/plugins/HandleMediaKeys/qmldir +++ /dev/null @@ -1,3 +0,0 @@ -module HandleMediaKeys -plugin HandleMediaKeys-qml -typeinfo HandleMediaKeys.qmltypes diff --git a/qml/Components/PhysicalKeysMapper.qml b/qml/Components/PhysicalKeysMapper.qml index 26faf066ba..9469da3d73 100644 --- a/qml/Components/PhysicalKeysMapper.qml +++ b/qml/Components/PhysicalKeysMapper.qml @@ -40,7 +40,7 @@ Item { signal volumeDownTriggered; signal volumeUpTriggered; signal screenshotTriggered; - signal mediaKey; + signal mediaKey(var keyMsg); readonly property bool altTabPressed: d.altTabPressed readonly property bool superPressed: d.superPressed @@ -131,7 +131,34 @@ Item { } } + function getMediaKeyBroadcastString(event) { + var keyStr = "" + switch(event.key) { + case Qt.Key_MediaNext: + keyStr = "next-track" + break + case Qt.Key_MediaPrevious: + keyStr = "previous-track" + break + case Qt.Key_MediaPlay: + keyStr = "play-pause" + break + case Qt.Key_WebCam: + keyStr = "camera" + break + default: + switch(event.nativeScanCode) { + case 541: // KEY_ATTENDANT_TOGGLE + keyStr = "toggle-flash" + break + } + break + } + return keyStr + } + function onKeyReleased(event, currentEventTimestamp) { + console.log("onKeyReleased key: " + event.key + ", scan code: " + event.nativeScanCode) if (event.key == Qt.Key_PowerDown || event.key == Qt.Key_PowerOff) { d.powerButtonPressStart = 0; event.accepted = true; @@ -159,12 +186,10 @@ Item { d.superTabPressed = false; event.accepted = true; } - } else if ( event.key == Qt.Key_MediaNext - || event.key == Qt.Key_MediaPrevious - || event.key == Qt.Key_MediaPlay - || event.key == Qt.Key_WebCam -) { - root.mediaKey(event.key); + } else { + var keyMsg = getMediaKeyBroadcastString(event) + if (keyMsg != "") + root.mediaKey(keyMsg) } } } diff --git a/qml/Shell.qml b/qml/Shell.qml index 050e2ccd0d..e849b26f91 100644 --- a/qml/Shell.qml +++ b/qml/Shell.qml @@ -30,7 +30,7 @@ import GSettings 1.0 import Utils 0.1 import Powerd 0.1 import SessionBroadcast 0.1 -import HandleMediaKeys 0.1 +import Broadcaster 0.1 import "Greeter" import "Launcher" import "Panel" @@ -238,7 +238,7 @@ StyledItem { onVolumeUpTriggered: volumeControl.volumeUp(); onScreenshotTriggered: itemGrabber.capture(shell); - onMediaKey: HandleMediaKeys.notifyMediaKey(key); + onMediaKey: Broadcaster.notifyMediaKey(keyMsg); } GlobalShortcut { From 6920e47c161fc3231f48c4035f0af4b769403dcf Mon Sep 17 00:00:00 2001 From: Willem-Jan de Hoog Date: Sun, 17 Jan 2021 17:04:03 +0100 Subject: [PATCH 5/7] oops --- plugins/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 003d3eb2e2..372aa076dc 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -15,7 +15,7 @@ add_subdirectory(AccountsService) add_subdirectory(Cursor) add_subdirectory(GlobalShortcut) add_subdirectory(Greeter) -add_subdirectory(HandleMediaKeys) +add_subdirectory(Broadcaster) add_subdirectory(LightDM) add_subdirectory(Lights) add_subdirectory(Powerd) From f20cb5e61ad0e7902b88f29c17faf8bd932ce39d Mon Sep 17 00:00:00 2001 From: Willem-Jan de Hoog Date: Mon, 18 Jan 2021 23:36:15 +0100 Subject: [PATCH 6/7] simpler way to send the signal --- plugins/Broadcaster/Broadcaster.cpp | 39 +++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/plugins/Broadcaster/Broadcaster.cpp b/plugins/Broadcaster/Broadcaster.cpp index b45107aa7b..ea216f5d70 100644 --- a/plugins/Broadcaster/Broadcaster.cpp +++ b/plugins/Broadcaster/Broadcaster.cpp @@ -22,22 +22,47 @@ #include +#define BROADCAST_SERVICE "com.ubports.Lomiri.Broadcast" +#define BROADCAST_PATH "/com/ubports/Lomiri/Broadcast" +#define BROADCAST_INTERFACE "com.ubports.Lomiri.Broadcast" + +//#define BROADCAST_SERVICE "com.canonical.Unity.Broadcast" +//#define BROADCAST_SERVICE "com.canonical.Unity" +//#define BROADCAST_PATH "/com/canonical/Unity/Broadcast" +//#define BROADCAST_INTERFACE "com.canonical.Unity.Broadcast" + Broadcaster::Broadcaster(QObject* parent) : QObject(parent) { auto connection = QDBusConnection::SM_BUSNAME(); - auto interface = connection.interface(); - interface->startService(QStringLiteral("com.ubports.Lomiri.Broadcast")); + //auto interface = connection.interface(); + //auto reply = interface->startService(QStringLiteral(BROADCAST_INTERFACE)); + //if(!reply.isValid()) + // qWarning() << "Failed to start DBus service " << BROADCAST_SERVICE << ": " << reply.error().message(); - m_broadcaster = new QDBusInterface(QStringLiteral("com.ubports.Lomiri.Broadcast"), - QStringLiteral("/com/ubports/Lomiri/Broadcast"), - QStringLiteral("com.ubports.Lomiri.Broadcast"), + /*m_broadcaster = new QDBusInterface(QStringLiteral(BROADCAST_SERVICE), + QStringLiteral(BROADCAST_PATH), + QStringLiteral(BROADCAST_INTERFACE), connection, this); - + */ } void Broadcaster::notifyMediaKey(const QString &keyMsg) { - m_broadcaster->asyncCall(QStringLiteral("MediaKey"), keyMsg); + + auto connection = QDBusConnection::SM_BUSNAME(); + QDBusMessage msg = QDBusMessage::createSignal("/com/ubports/Lomiri/Broadcast", "com.ubports.Lomiri.Broadcast", "MediaKey"); + + QVariantMap args; + args.insert("key-msg", keyMsg); + msg << args; // keyMsg; + + connection.send(msg); + + //m_broadcaster->asyncCall(QStringLiteral("MediaKey"), args); + /*QDBusReply reply = m_broadcaster->call(QStringLiteral("MediaKey"), args); + if(!reply.isValid()) + qWarning() << "Failed to signal MediaKey: " << reply.error().message(); + */ } From 66f9a4d0abead432e0f55c79212b2381aaee7f5d Mon Sep 17 00:00:00 2001 From: Willem-Jan de Hoog Date: Tue, 19 Jan 2021 22:28:57 +0100 Subject: [PATCH 7/7] cleanup --- plugins/Broadcaster/Broadcaster.cpp | 27 ++------------------------- plugins/Broadcaster/Broadcaster.h | 2 -- 2 files changed, 2 insertions(+), 27 deletions(-) diff --git a/plugins/Broadcaster/Broadcaster.cpp b/plugins/Broadcaster/Broadcaster.cpp index ea216f5d70..0c9720694a 100644 --- a/plugins/Broadcaster/Broadcaster.cpp +++ b/plugins/Broadcaster/Broadcaster.cpp @@ -26,43 +26,20 @@ #define BROADCAST_PATH "/com/ubports/Lomiri/Broadcast" #define BROADCAST_INTERFACE "com.ubports.Lomiri.Broadcast" -//#define BROADCAST_SERVICE "com.canonical.Unity.Broadcast" -//#define BROADCAST_SERVICE "com.canonical.Unity" -//#define BROADCAST_PATH "/com/canonical/Unity/Broadcast" -//#define BROADCAST_INTERFACE "com.canonical.Unity.Broadcast" - Broadcaster::Broadcaster(QObject* parent) : QObject(parent) { - - auto connection = QDBusConnection::SM_BUSNAME(); - //auto interface = connection.interface(); - //auto reply = interface->startService(QStringLiteral(BROADCAST_INTERFACE)); - //if(!reply.isValid()) - // qWarning() << "Failed to start DBus service " << BROADCAST_SERVICE << ": " << reply.error().message(); - - /*m_broadcaster = new QDBusInterface(QStringLiteral(BROADCAST_SERVICE), - QStringLiteral(BROADCAST_PATH), - QStringLiteral(BROADCAST_INTERFACE), - connection, this); - */ } void Broadcaster::notifyMediaKey(const QString &keyMsg) { auto connection = QDBusConnection::SM_BUSNAME(); - QDBusMessage msg = QDBusMessage::createSignal("/com/ubports/Lomiri/Broadcast", "com.ubports.Lomiri.Broadcast", "MediaKey"); + QDBusMessage msg = QDBusMessage::createSignal(BROADCAST_PATH, BROADCAST_INTERFACE, "MediaKey"); QVariantMap args; args.insert("key-msg", keyMsg); - msg << args; // keyMsg; + msg << args; connection.send(msg); - - //m_broadcaster->asyncCall(QStringLiteral("MediaKey"), args); - /*QDBusReply reply = m_broadcaster->call(QStringLiteral("MediaKey"), args); - if(!reply.isValid()) - qWarning() << "Failed to signal MediaKey: " << reply.error().message(); - */ } diff --git a/plugins/Broadcaster/Broadcaster.h b/plugins/Broadcaster/Broadcaster.h index b869719546..b3e4a7cb97 100644 --- a/plugins/Broadcaster/Broadcaster.h +++ b/plugins/Broadcaster/Broadcaster.h @@ -31,8 +31,6 @@ class Broadcaster: public QObject Q_INVOKABLE void notifyMediaKey(const QString &keyMsg); -private: - QDBusInterface *m_broadcaster; }; #endif