Skip to content
This repository has been archived by the owner on Nov 4, 2023. It is now read-only.

WIP: do not merge, handle media keys #327

Draft
wants to merge 7 commits into
base: xenial
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions debian/unity8-private.install
Original file line number Diff line number Diff line change
@@ -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
Expand Down
45 changes: 45 additions & 0 deletions plugins/Broadcaster/Broadcaster.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/

#include "Broadcaster.h"
#include <QDBusConnection>
#include <QDBusConnectionInterface>
#include <QDBusInterface>
#include <QDebug>

#include <glib.h>

#define BROADCAST_SERVICE "com.ubports.Lomiri.Broadcast"
#define BROADCAST_PATH "/com/ubports/Lomiri/Broadcast"
#define BROADCAST_INTERFACE "com.ubports.Lomiri.Broadcast"

Broadcaster::Broadcaster(QObject* parent)
: QObject(parent)
{
}

void Broadcaster::notifyMediaKey(const QString &keyMsg)
{

auto connection = QDBusConnection::SM_BUSNAME();
QDBusMessage msg = QDBusMessage::createSignal(BROADCAST_PATH, BROADCAST_INTERFACE, "MediaKey");

QVariantMap args;
args.insert("key-msg", keyMsg);
msg << args;

connection.send(msg);
}
36 changes: 36 additions & 0 deletions plugins/Broadcaster/Broadcaster.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/

#ifndef LOMIRI_BROADCASTER_H
#define LOMIRI_BROADCASTER_H

#include <QObject>
#include <QString>

class QDBusInterface;

class Broadcaster: public QObject
{
Q_OBJECT

public:
explicit Broadcaster(QObject *parent = 0);

Q_INVOKABLE void notifyMediaKey(const QString &keyMsg);

};

#endif
15 changes: 15 additions & 0 deletions plugins/Broadcaster/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
34 changes: 34 additions & 0 deletions plugins/Broadcaster/plugin.cpp
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*
*/

#include "plugin.h"
#include "Broadcaster.h"

#include <QtQml/qqml.h>

static QObject *broadcast_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
{
Q_UNUSED(engine)
Q_UNUSED(scriptEngine)
return new Broadcaster();
}

void BroadcasterPlugin::registerTypes(const char *uri)
{
Q_ASSERT(uri == QLatin1String("Broadcaster"));
qmlRegisterSingletonType<Broadcaster>(uri, 0, 1, "Broadcaster", broadcast_provider);
}
32 changes: 32 additions & 0 deletions plugins/Broadcaster/plugin.h
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*
*/

#ifndef LOMIRI_BROADCASTER_PLUGIN
#define LOMIRI_BROADCASTER_PLUGIN

#include <QQmlExtensionPlugin>

class BroadcasterPlugin : public QQmlExtensionPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")

public:
void registerTypes(const char *uri) override;
};

#endif
3 changes: 3 additions & 0 deletions plugins/Broadcaster/qmldir
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module Broadcaster
plugin Broadcaster-qml
typeinfo Broadcaster.qmltypes
1 change: 1 addition & 0 deletions plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ add_subdirectory(AccountsService)
add_subdirectory(Cursor)
add_subdirectory(GlobalShortcut)
add_subdirectory(Greeter)
add_subdirectory(Broadcaster)
add_subdirectory(LightDM)
add_subdirectory(Lights)
add_subdirectory(Powerd)
Expand Down
32 changes: 32 additions & 0 deletions qml/Components/PhysicalKeysMapper.qml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Item {
signal volumeDownTriggered;
signal volumeUpTriggered;
signal screenshotTriggered;
signal mediaKey(var keyMsg);

readonly property bool altTabPressed: d.altTabPressed
readonly property bool superPressed: d.superPressed
Expand Down Expand Up @@ -130,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;
Expand Down Expand Up @@ -158,6 +186,10 @@ Item {
d.superTabPressed = false;
event.accepted = true;
}
} else {
var keyMsg = getMediaKeyBroadcastString(event)
if (keyMsg != "")
root.mediaKey(keyMsg)
}
}
}
3 changes: 3 additions & 0 deletions qml/Shell.qml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import GSettings 1.0
import Utils 0.1
import Powerd 0.1
import SessionBroadcast 0.1
import Broadcaster 0.1
import "Greeter"
import "Launcher"
import "Panel"
Expand Down Expand Up @@ -236,6 +237,8 @@ StyledItem {
onVolumeDownTriggered: volumeControl.volumeDown();
onVolumeUpTriggered: volumeControl.volumeUp();
onScreenshotTriggered: itemGrabber.capture(shell);

onMediaKey: Broadcaster.notifyMediaKey(keyMsg);
}

GlobalShortcut {
Expand Down