From ea5f8163231a81e4f0769a518db819c8a1fc78f6 Mon Sep 17 00:00:00 2001 From: Robert Tari Date: Wed, 17 Nov 2021 10:19:43 +0100 Subject: Re-enable haptic using hfd-service fixes https://github.com/AyatanaIndicators/ayatana-indicator-datetime/issues/67 --- include/notifications/dbus-shared.h | 7 ++--- include/notifications/haptic.h | 8 ++--- src/haptic.cpp | 62 ++++++++++++------------------------- src/snap.cpp | 2 +- tests/manual | 2 +- tests/notification-fixture.h | 10 +++--- tests/test-notification.cpp | 4 +-- 7 files changed, 33 insertions(+), 62 deletions(-) diff --git a/include/notifications/dbus-shared.h b/include/notifications/dbus-shared.h index ea47328..931667e 100644 --- a/include/notifications/dbus-shared.h +++ b/include/notifications/dbus-shared.h @@ -31,9 +31,8 @@ #define BUS_POWERD_PATH "/com/lomiri/Repowerd" #define BUS_POWERD_INTERFACE "com.lomiri.Repowerd" -//TODO: Reimplement using hfd-service -//#define BUS_HAPTIC_NAME "" -//#define BUS_HAPTIC_PATH "" -//#define BUS_HAPTIC_INTERFACE "" +#define BUS_HAPTIC_NAME "com.lomiri.hfd" +#define BUS_HAPTIC_PATH "/com/lomiri/hfd" +#define BUS_HAPTIC_INTERFACE "com.lomiri.hfd.Vibrator" #endif /* INDICATOR_NOTIFICATIONS_DBUS_SHARED_H */ diff --git a/include/notifications/haptic.h b/include/notifications/haptic.h index 2f4008a..ccf5298 100644 --- a/include/notifications/haptic.h +++ b/include/notifications/haptic.h @@ -1,5 +1,6 @@ /* * Copyright 2014 Canonical Ltd. + * Copyright 2021 Robert Tari * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published @@ -15,6 +16,7 @@ * * Authors: * Charles Kerr + * Robert Tari */ #ifndef AYATANA_INDICATOR_NOTIFICATIONS_HAPTIC_H @@ -36,12 +38,8 @@ namespace notifications { class Haptic { public: - enum Mode - { - MODE_PULSE - }; - explicit Haptic(const Mode& mode = MODE_PULSE, bool repeat = false); + explicit Haptic(bool repeat = false); ~Haptic(); private: diff --git a/src/haptic.cpp b/src/haptic.cpp index d794ba7..7e09c24 100644 --- a/src/haptic.cpp +++ b/src/haptic.cpp @@ -39,8 +39,7 @@ class Haptic::Impl { public: - Impl(const Mode& mode, bool repeat): - m_mode(mode), + Impl(bool repeat): m_cancellable(g_cancellable_new()), m_repeat(repeat) { @@ -89,70 +88,47 @@ private: { g_return_if_fail (m_tag == 0); - switch (m_mode) - { - case MODE_PULSE: // the only mode currently supported... :) - - // one second on, one second off. - m_pattern = std::vector({1000u, 1000u}); - break; - - } - if (m_repeat) { - // Set up a loop to keep repeating the pattern - auto msec = std::accumulate(m_pattern.begin(), m_pattern.end(), 0u); - m_tag = g_timeout_add(msec, call_vibrate_pattern_static, this); + // Set up a loop to keep repeating the pattern: one second on, one second off. + m_tag = g_timeout_add(2000, call_vibrate_static, this); } - call_vibrate_pattern(); + + call_vibrate(); } - static gboolean call_vibrate_pattern_static (gpointer gself) + static gboolean call_vibrate_static (gpointer gself) { - static_cast(gself)->call_vibrate_pattern(); + static_cast(gself)->call_vibrate(); return G_SOURCE_CONTINUE; } - void call_vibrate_pattern() + void call_vibrate() { - // build the vibrate pattern GVariantBuilder builder; - g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY); - for (const auto& msec : m_pattern) - g_variant_builder_add_value (&builder, g_variant_new_uint32(msec)); - auto pattern_array = g_variant_builder_end (&builder); - - /* Use a repeat_count of 1 here because we handle looping ourselves. - NB: VibratePattern could do it for us, but doesn't let us cancel - a running loop -- we could keep vibrating even after "this" was - destructed */ - auto repeat_count = g_variant_new_uint32 (1u); - - g_variant_builder_init (&builder, G_VARIANT_TYPE_TUPLE); - g_variant_builder_add_value (&builder, pattern_array); - g_variant_builder_add_value (&builder, repeat_count); - //TODO: Reimplement using hfd-service - /*auto vibrate_pattern_args = g_variant_builder_end (&builder); + auto duration = g_variant_new_int32 (1000); + + g_variant_builder_init (&builder, G_VARIANT_TYPE_INT32); + g_variant_builder_add_value (&builder, duration); + + auto vibrate_arg = g_variant_builder_end (&builder); g_dbus_connection_call (m_bus, BUS_HAPTIC_NAME, BUS_HAPTIC_PATH, BUS_HAPTIC_INTERFACE, - "VibratePattern", - vibrate_pattern_args, + "vibrate", + vibrate_arg, nullptr, G_DBUS_CALL_FLAGS_NONE, -1, m_cancellable, nullptr, - nullptr);*/ + nullptr); } - const Mode m_mode; GCancellable * m_cancellable = nullptr; GDBusConnection * m_bus = nullptr; - std::vector m_pattern; guint m_tag = 0; bool m_repeat = false; }; @@ -161,8 +137,8 @@ private: **** ***/ -Haptic::Haptic(const Mode& mode, bool repeat): - impl(new Impl (mode, repeat)) +Haptic::Haptic(bool repeat): + impl(new Impl (repeat)) { } diff --git a/src/snap.cpp b/src/snap.cpp index 37ce741..45cd299 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -128,7 +128,7 @@ public: if (!silent_mode() || vibrate_in_silent_mode_enabled()) { const auto haptic_mode = m_settings->alarm_haptic.get(); if (haptic_mode == "pulse") - haptic = std::make_shared(ain::Haptic::MODE_PULSE, appointment.is_alarm()); + haptic = std::make_shared(appointment.is_alarm()); } } diff --git a/tests/manual b/tests/manual index d9e192c..cafc292 100644 --- a/tests/manual +++ b/tests/manual @@ -35,7 +35,7 @@ Test-case ayatana-indicator-datetime/new-alarm-wakeup
Unplug the phone from any USB connection and put it to sleep
Confirm that the alarm sounds on time even if the phone is asleep. (Note: if in doubt about sleep you can see in the syslog whether the device actually suspended or whether the suspend was aborted)
Confirm that the screen comes on when the alarm is triggered.
-
[FIXME: No haptic support right now. Remove this comment after https://github.com/AyatanaIndicators/ayatana-indicator-datetime/issues/67 is resolved] If the device supports haptic feedback, confirm the alarm vibrates.
+
If the device supports haptic feedback, confirm the alarm vibrates.
Test-case ayatana-indicator-datetime/disabled-alarms diff --git a/tests/notification-fixture.h b/tests/notification-fixture.h index acb3e63..2349bab 100644 --- a/tests/notification-fixture.h +++ b/tests/notification-fixture.h @@ -52,7 +52,7 @@ protected: static constexpr char const * NOTIFY_INTERFACE {"org.freedesktop.Notifications"}; static constexpr char const * NOTIFY_PATH {"/org/freedesktop/Notifications"}; - static constexpr char const * HAPTIC_METHOD_VIBRATE_PATTERN {"VibratePattern"}; + static constexpr char const * HAPTIC_METHOD_VIBRATE {"vibrate"}; static constexpr int SCREEN_COOKIE {8675309}; static constexpr char const * SCREEN_METHOD_KEEP_DISPLAY_ON {"keepDisplayOn"}; @@ -279,8 +279,6 @@ protected: g_assert_no_error (error); dbus_test_service_add_task(service, DBUS_TEST_TASK(screen_mock)); - //TODO: Reimplement using hfd-service - /* /// /// Add the haptic mock /// @@ -292,13 +290,13 @@ protected: &error); dbus_test_dbus_mock_object_add_method(haptic_mock, haptic_obj, - HAPTIC_METHOD_VIBRATE_PATTERN, - G_VARIANT_TYPE("(auu)"), + HAPTIC_METHOD_VIBRATE, + G_VARIANT_TYPE("i"), nullptr, "", &error); g_assert_no_error (error); - dbus_test_service_add_task(service, DBUS_TEST_TASK(haptic_mock));*/ + dbus_test_service_add_task(service, DBUS_TEST_TASK(haptic_mock)); startDbusMock(); } diff --git a/tests/test-notification.cpp b/tests/test-notification.cpp index 80eb04c..7dccb96 100644 --- a/tests/test-notification.cpp +++ b/tests/test-notification.cpp @@ -158,9 +158,9 @@ TEST_F(NotificationFixture,Notification) // confirm that the vibration was as expected if (expected_vibrate_called) { - EXPECT_METHOD_CALLED_EVENTUALLY(haptic_mock, haptic_obj, HAPTIC_METHOD_VIBRATE_PATTERN); + EXPECT_METHOD_CALLED_EVENTUALLY(haptic_mock, haptic_obj, HAPTIC_METHOD_VIBRATE); } else { - EXPECT_METHOD_NOT_CALLED_EVENTUALLY(haptic_mock, haptic_obj, HAPTIC_METHOD_VIBRATE_PATTERN); + EXPECT_METHOD_NOT_CALLED_EVENTUALLY(haptic_mock, haptic_obj, HAPTIC_METHOD_VIBRATE); } // confirm that the notification was as expected -- cgit v1.2.3