File: vibrationmanager.cpp

package info (click to toggle)
plasma-mobile 6.5.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 20,412 kB
  • sloc: xml: 38,474; cpp: 18,529; javascript: 139; sh: 82; makefile: 5
file content (34 lines) | stat: -rw-r--r-- 1,131 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// SPDX-FileCopyrightText: 2023-2025 Devin Lin <devin@kde.org>
// SPDX-License-Identifier: GPL-2.0-or-later

#include "vibrationmanager.h"

VibrationManager::VibrationManager(QObject *parent)
    : QObject{parent}
{
    qDBusRegisterMetaType<VibrationEvent>();
    qDBusRegisterMetaType<VibrationEventList>();
}

QCoro::Task<void> VibrationManager::vibrateTask(int durationMs)
{
    // Only create interface when needed.
    if (!m_interface) {
        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};
    QDBusPendingReply<bool> reply = co_await m_interface->Vibrate(appId, pattern);

    if (!reply.isValid() || !reply.value()) {
        qWarning() << "feedbackd vibration failed";
    }
}

QCoro::QmlTask VibrationManager::vibrate(int durationMs)
{
    return vibrateTask(durationMs);
}