diff --git a/README.md b/README.md index 7e053f1f..eee6da02 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ Dependencies: * Milou (for search) * Kirigami * Kirigami Addons -* hfd-service (optional: for vibrations) +* feedbackd (optional: for vibrations) To start the shell in a window, run: diff --git a/components/hapticsplugin/CMakeLists.txt b/components/hapticsplugin/CMakeLists.txt index 36542032..d6fae7eb 100644 --- a/components/hapticsplugin/CMakeLists.txt +++ b/components/hapticsplugin/CMakeLists.txt @@ -1,12 +1,15 @@ # SPDX-FileCopyrightText: 2023 Devin Lin # SPDX-License-Identifier: GPL-2.0-or-later -qt_add_dbus_interfaces(DBUS_SRCS dbus/com.lomiri.hfd.xml) +set_source_files_properties(dbus/org.sigxcpu.Feedback.Haptic.xml PROPERTIES INCLUDE vibrationevent.h) +qt_add_dbus_interfaces(dbusinterface_SRCS + dbus/org.sigxcpu.Feedback.Haptic.xml) ecm_add_qml_module(hapticsplugin URI org.kde.plasma.private.mobileshell.hapticsplugin GENERATE_PLUGIN_SOURCE) target_sources(hapticsplugin PRIVATE + vibrationevent.h vibrationmanager.cpp - ${DBUS_SRCS} + ${dbusinterface_SRCS} ) target_link_libraries(hapticsplugin PRIVATE @@ -14,6 +17,7 @@ target_link_libraries(hapticsplugin PRIVATE Qt::DBus KF6::CoreAddons KF6::I18n + QCoro::DBus ) ecm_finalize_qml_module(hapticsplugin) diff --git a/components/hapticsplugin/dbus/com.lomiri.hfd.xml b/components/hapticsplugin/dbus/com.lomiri.hfd.xml deleted file mode 100644 index cf832964..00000000 --- a/components/hapticsplugin/dbus/com.lomiri.hfd.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/components/hapticsplugin/dbus/org.sigxcpu.Feedback.Haptic.xml b/components/hapticsplugin/dbus/org.sigxcpu.Feedback.Haptic.xml new file mode 100644 index 00000000..26765efd --- /dev/null +++ b/components/hapticsplugin/dbus/org.sigxcpu.Feedback.Haptic.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + diff --git a/components/hapticsplugin/dbus/org.sigxcpu.Feedback.xml b/components/hapticsplugin/dbus/org.sigxcpu.Feedback.xml new file mode 100644 index 00000000..225ca663 --- /dev/null +++ b/components/hapticsplugin/dbus/org.sigxcpu.Feedback.xml @@ -0,0 +1,80 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/components/hapticsplugin/vibrationevent.h b/components/hapticsplugin/vibrationevent.h new file mode 100644 index 00000000..74d411a2 --- /dev/null +++ b/components/hapticsplugin/vibrationevent.h @@ -0,0 +1,37 @@ +// SPDX-FileCopyrightText: 2025 Devin Lin +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include +#include + +class VibrationEvent +{ +public: + double amplitude; + quint32 duration; +}; + +using VibrationEventList = QList; + +Q_DECLARE_METATYPE(VibrationEvent) +Q_DECLARE_METATYPE(VibrationEventList) + +inline QDBusArgument &operator<<(QDBusArgument &argument, const VibrationEvent &e) +{ + argument.beginStructure(); + argument << e.amplitude; + argument << e.duration; + argument.endStructure(); + return argument; +} + +inline const QDBusArgument &operator>>(const QDBusArgument &argument, VibrationEvent &e) +{ + argument.beginStructure(); + argument >> e.amplitude; + argument >> e.duration; + argument.endStructure(); + return argument; +} diff --git a/components/hapticsplugin/vibrationmanager.cpp b/components/hapticsplugin/vibrationmanager.cpp index 7f8a9b67..54374d2c 100644 --- a/components/hapticsplugin/vibrationmanager.cpp +++ b/components/hapticsplugin/vibrationmanager.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2023 Devin Lin +// SPDX-FileCopyrightText: 2023-2025 Devin Lin // SPDX-License-Identifier: GPL-2.0-or-later #include "vibrationmanager.h" @@ -6,14 +6,24 @@ VibrationManager::VibrationManager(QObject *parent) : QObject{parent} { + qDBusRegisterMetaType(); + qDBusRegisterMetaType(); } -void VibrationManager::vibrate(int durationMs) +QCoro::Task VibrationManager::vibrate(int durationMs) { // Only create interface when needed. if (!m_interface) { - const auto objectPath = QStringLiteral("/com/lomiri/hfd"); - m_interface = new com::lomiri::hfd::Vibrator("com.lomiri.hfd", objectPath, QDBusConnection::systemBus(), this); + const auto objectPath = QStringLiteral("/org/sigxcpu/Feedback"); + m_interface = new OrgSigxcpuFeedbackHapticInterface("org.sigxcpu.Feedback", objectPath, QDBusConnection::sessionBus(), this); + } + + const QString appId = QStringLiteral("org.kde.plasmashell"); + const VibrationEvent event{1.0, static_cast(durationMs)}; + const VibrationEventList pattern = {event}; + QDBusPendingReply reply = co_await m_interface->Vibrate(appId, pattern); + + if (!reply.isValid() || !reply.value()) { + qWarning() << "feedbackd vibration failed"; } - m_interface->vibrate(durationMs); } diff --git a/components/hapticsplugin/vibrationmanager.h b/components/hapticsplugin/vibrationmanager.h index 2fd22ced..a4ecca9f 100644 --- a/components/hapticsplugin/vibrationmanager.h +++ b/components/hapticsplugin/vibrationmanager.h @@ -3,10 +3,14 @@ #pragma once +#include #include #include -#include "hfdinterface.h" +#include "hapticinterface.h" +#include "vibrationevent.h" + +#include class VibrationManager : public QObject { @@ -17,8 +21,8 @@ class VibrationManager : public QObject public: VibrationManager(QObject *parent = nullptr); - Q_INVOKABLE void vibrate(int durationMs); + Q_INVOKABLE QCoro::Task vibrate(int durationMs); private: - com::lomiri::hfd::Vibrator *m_interface{nullptr}; -}; \ No newline at end of file + OrgSigxcpuFeedbackHapticInterface *m_interface{nullptr}; +};