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

Commit

Permalink
broadcast some keys on dbus
Browse files Browse the repository at this point in the history
  • Loading branch information
wdehoog committed Aug 20, 2020
1 parent 7063709 commit ea04623
Show file tree
Hide file tree
Showing 9 changed files with 192 additions and 0 deletions.
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(HandleMediaKeys)
add_subdirectory(LightDM)
add_subdirectory(Lights)
add_subdirectory(Powerd)
Expand Down
15 changes: 15 additions & 0 deletions plugins/HandleMediaKeys/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(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)
53 changes: 53 additions & 0 deletions plugins/HandleMediaKeys/HandleMediaKeys.cpp
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

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

#include <glib.h>

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);
}

44 changes: 44 additions & 0 deletions plugins/HandleMediaKeys/HandleMediaKeys.h
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

#ifndef LOMIRI_HANDLEMEDIAKEYS_H
#define LOMIRI_HANDLEMEDIAKEYS_H

#include <QObject>
#include <QString>

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
34 changes: 34 additions & 0 deletions plugins/HandleMediaKeys/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 "HandleMediaKeys.h"

#include <QtQml/qqml.h>

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<HandleMediaKeys>(uri, 0, 1, "HandleMediaKeys", broadcast_provider);
}
32 changes: 32 additions & 0 deletions plugins/HandleMediaKeys/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_HANDLEMEDIAKEYS_PLUGIN
#define LOMIRI_HANDLEMEDIAKEYS_PLUGIN

#include <QQmlExtensionPlugin>

class HandleMediaKeysPlugin : 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/HandleMediaKeys/qmldir
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module HandleMediaKeys
plugin HandleMediaKeys-qml
typeinfo HandleMediaKeys.qmltypes
7 changes: 7 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;

readonly property bool altTabPressed: d.altTabPressed
readonly property bool superPressed: d.superPressed
Expand Down Expand Up @@ -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);
}
}
}
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 HandleMediaKeys 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: HandleMediaKeys.notifyMediaKey(key);
}

GlobalShortcut {
Expand Down

0 comments on commit ea04623

Please sign in to comment.