From ab5d31426ab657da2981780fe752b342059a51ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Fri, 13 May 2016 10:04:28 +0200 Subject: [PATCH] [libinput] Expose all input devices through DBus Summary: The Connection exposes a new service called org.kde.KWin.InputDevice and every Device registers an own object exposing all properties. This allows an external configuration tool to change the behavior of the devices at runtime. E.g. to test configuration settings. Reviewers: #kwin, #plasma_on_wayland Subscribers: plasma-devel, kwin Tags: #plasma_on_wayland, #kwin Differential Revision: https://phabricator.kde.org/D2407 --- autotests/libinput/CMakeLists.txt | 12 ++++++------ libinput/connection.cpp | 4 ++++ libinput/device.cpp | 8 ++++++++ libinput/device.h | 1 + 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/autotests/libinput/CMakeLists.txt b/autotests/libinput/CMakeLists.txt index dc7a1b2901..225f5733ea 100644 --- a/autotests/libinput/CMakeLists.txt +++ b/autotests/libinput/CMakeLists.txt @@ -5,7 +5,7 @@ include_directories(${UDEV_INCLUDE_DIR}) ######################################################## set( testLibinputDevice_SRCS device_test.cpp mock_libinput.cpp ../../libinput/device.cpp ) add_executable(testLibinputDevice ${testLibinputDevice_SRCS}) -target_link_libraries( testLibinputDevice Qt5::Test) +target_link_libraries( testLibinputDevice Qt5::Test Qt5::DBus) add_test(kwin-testLibinputDevice testLibinputDevice) ecm_mark_as_test(testLibinputDevice) @@ -19,7 +19,7 @@ set( testLibinputKeyEvent_SRCS ../../libinput/events.cpp ) add_executable(testLibinputKeyEvent ${testLibinputKeyEvent_SRCS}) -target_link_libraries( testLibinputKeyEvent Qt5::Test Qt5::Widgets KF5::ConfigCore) +target_link_libraries( testLibinputKeyEvent Qt5::Test Qt5::DBus Qt5::Widgets KF5::ConfigCore) add_test(kwin-testLibinputKeyEvent testLibinputKeyEvent) ecm_mark_as_test(testLibinputKeyEvent) @@ -33,7 +33,7 @@ set( testLibinputPointerEvent_SRCS ../../libinput/events.cpp ) add_executable(testLibinputPointerEvent ${testLibinputPointerEvent_SRCS}) -target_link_libraries( testLibinputPointerEvent Qt5::Test Qt5::Widgets KF5::ConfigCore) +target_link_libraries( testLibinputPointerEvent Qt5::Test Qt5::DBus Qt5::Widgets KF5::ConfigCore) add_test(kwin-testLibinputPointerEvent testLibinputPointerEvent) ecm_mark_as_test(testLibinputPointerEvent) @@ -47,7 +47,7 @@ set( testLibinputTouchEvent_SRCS ../../libinput/events.cpp ) add_executable(testLibinputTouchEvent ${testLibinputTouchEvent_SRCS}) -target_link_libraries( testLibinputTouchEvent Qt5::Test Qt5::Widgets KF5::ConfigCore) +target_link_libraries( testLibinputTouchEvent Qt5::Test Qt5::DBus Qt5::Widgets KF5::ConfigCore) add_test(kwin-testLibinputTouchEvent testLibinputTouchEvent) ecm_mark_as_test(testLibinputTouchEvent) @@ -61,7 +61,7 @@ set( testLibinputGestureEvent_SRCS ../../libinput/events.cpp ) add_executable(testLibinputGestureEvent ${testLibinputGestureEvent_SRCS}) -target_link_libraries( testLibinputGestureEvent Qt5::Test Qt5::Widgets KF5::ConfigCore) +target_link_libraries( testLibinputGestureEvent Qt5::Test Qt5::DBus Qt5::Widgets KF5::ConfigCore) add_test(kwin-testLibinputGestureEvent testLibinputGestureEvent) ecm_mark_as_test(testLibinputGestureEvent) @@ -94,6 +94,6 @@ ecm_mark_as_test(testLibinputContext) ######################################################## set( testInputEvents_SRCS input_event_test.cpp mock_libinput.cpp ../../libinput/device.cpp ../../input_event.cpp ) add_executable(testInputEvents ${testInputEvents_SRCS}) -target_link_libraries( testInputEvents Qt5::Test Qt5::Gui) +target_link_libraries( testInputEvents Qt5::Test Qt5::DBus Qt5::Gui) add_test(kwin-testInputEvents testInputEvents) ecm_mark_as_test(testInputEvents) diff --git a/libinput/connection.cpp b/libinput/connection.cpp index 08e39aa2b4..e39dc1e455 100644 --- a/libinput/connection.cpp +++ b/libinput/connection.cpp @@ -88,6 +88,7 @@ Connection *Connection::create(QObject *parent) } static const QString s_touchpadComponent = QStringLiteral("kcm_touchpad"); +static const QString s_serviceName = QStringLiteral("org.kde.KWin.InputDevice"); Connection::Connection(Context *input, QObject *parent) : QObject(parent) @@ -140,10 +141,13 @@ Connection::Connection(Context *input, QObject *parent) // need to connect to KGlobalSettings as the mouse KCM does not emit a dedicated signal QDBusConnection::sessionBus().connect(QString(), QStringLiteral("/KGlobalSettings"), QStringLiteral("org.kde.KGlobalSettings"), QStringLiteral("notifyChange"), this, SLOT(slotKGlobalSettingsNotifyChange(int,int))); + + QDBusConnection::sessionBus().registerService(s_serviceName); } Connection::~Connection() { + QDBusConnection::sessionBus().unregisterService(s_serviceName); s_self = nullptr; delete s_context; s_context = nullptr; diff --git a/libinput/device.cpp b/libinput/device.cpp index 0c38ac7002..74a654db08 100644 --- a/libinput/device.cpp +++ b/libinput/device.cpp @@ -20,6 +20,8 @@ along with this program. If not, see . #include "device.h" #include +#include + #include #include @@ -143,11 +145,17 @@ Device::Device(libinput_device *device, QObject *parent) } s_devices << this; + QDBusConnection::sessionBus().registerObject(QStringLiteral("/org/kde/KWin/InputDevice/") + m_sysName, + QStringLiteral("org.kde.KWin.InputDevice"), + this, + QDBusConnection::ExportAllProperties + ); } Device::~Device() { s_devices.removeOne(this); + QDBusConnection::sessionBus().unregisterObject(QStringLiteral("/org/kde/KWin/InputDevice/") + m_sysName); libinput_device_unref(m_device); } diff --git a/libinput/device.h b/libinput/device.h index 384eeba687..a24b77afa8 100644 --- a/libinput/device.h +++ b/libinput/device.h @@ -34,6 +34,7 @@ namespace LibInput class Device : public QObject { Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "org.kde.KWin.InputDevice") Q_PROPERTY(bool keyboard READ isKeyboard CONSTANT) Q_PROPERTY(bool alphaNumericKeyboard READ isAlphaNumericKeyboard CONSTANT) Q_PROPERTY(bool pointer READ isPointer CONSTANT)