2025-05-22 15:45:44 +00:00
|
|
|
// SPDX-FileCopyrightText: 2023-2025 Devin Lin <devin@kde.org>
|
2023-11-15 07:13:05 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
|
|
|
|
|
#include "vibrationmanager.h"
|
|
|
|
|
|
2026-01-08 02:02:02 +00:00
|
|
|
#include <QPointer>
|
|
|
|
|
|
2023-11-15 07:13:05 +00:00
|
|
|
VibrationManager::VibrationManager(QObject *parent)
|
|
|
|
|
: QObject{parent}
|
|
|
|
|
{
|
2025-05-22 15:45:44 +00:00
|
|
|
qDBusRegisterMetaType<VibrationEvent>();
|
|
|
|
|
qDBusRegisterMetaType<VibrationEventList>();
|
2023-11-15 07:13:05 +00:00
|
|
|
}
|
|
|
|
|
|
2025-09-13 20:20:00 +00:00
|
|
|
QCoro::Task<void> VibrationManager::vibrateTask(int durationMs)
|
2023-11-15 07:13:05 +00:00
|
|
|
{
|
2024-10-30 05:01:04 +00:00
|
|
|
// Only create interface when needed.
|
|
|
|
|
if (!m_interface) {
|
2025-05-22 15:45:44 +00:00
|
|
|
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<quint32>(durationMs)};
|
|
|
|
|
const VibrationEventList pattern = {event};
|
2026-01-08 02:02:02 +00:00
|
|
|
|
|
|
|
|
QPointer<VibrationManager> guard(this);
|
2025-05-22 15:45:44 +00:00
|
|
|
QDBusPendingReply<bool> reply = co_await m_interface->Vibrate(appId, pattern);
|
|
|
|
|
|
2026-01-08 02:02:02 +00:00
|
|
|
if (!guard) {
|
|
|
|
|
co_return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-22 15:45:44 +00:00
|
|
|
if (!reply.isValid() || !reply.value()) {
|
|
|
|
|
qWarning() << "feedbackd vibration failed";
|
2024-10-30 05:01:04 +00:00
|
|
|
}
|
2023-11-15 07:13:05 +00:00
|
|
|
}
|
2025-09-13 20:20:00 +00:00
|
|
|
|
|
|
|
|
QCoro::QmlTask VibrationManager::vibrate(int durationMs)
|
|
|
|
|
{
|
|
|
|
|
return vibrateTask(durationMs);
|
|
|
|
|
}
|