phosh-arch/gnome-clocks-mobile/0002-Use-libfeedback-in-instead-of-GSound.patch
2024-08-13 08:17:11 -07:00

152 lines
4.7 KiB
Diff

From 91f0925ed8ffea4898840cd0c7e9c43c5487d2ca Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Guido=20G=C3=BCnther?= <agx@sigxcpu.org>
Date: Sat, 22 Feb 2020 18:51:42 +0100
Subject: [PATCH 02/16] Use libfeedback in instead of GSound
This allows to use haptic (and later led) based
feedback on top of audio.
---
meson.build | 2 +-
src/main.vala | 9 ++++++++-
src/meson.build | 3 ++-
src/utils.vala | 47 +++++++++++++++++++++--------------------------
4 files changed, 32 insertions(+), 29 deletions(-)
diff --git a/meson.build b/meson.build
index 032f16d..a5ffc9b 100644
--- a/meson.build
+++ b/meson.build
@@ -14,7 +14,7 @@ glib = dependency('glib-2.0', version: '>= 2.68')
gio = dependency('gio-2.0', version: '>= 2.58')
gobject = dependency('gobject-2.0', version: '>= 2.58')
gtk = dependency('gtk+-3.0', version: '>=3.20')
-gsound = dependency('gsound', version: '>=0.98')
+libfeedback = dependency('libfeedback-0.0', version: '>= 0.0.0')
gweather = dependency('gweather-3.0', version: '>=3.32.0')
gnomedesktop = dependency('gnome-desktop-3.0', version: '>=3.8')
geocodeglib = dependency('geocode-glib-1.0', version: '>=1.0')
diff --git a/src/main.vala b/src/main.vala
index 97d3350..905ef7f 100644
--- a/src/main.vala
+++ b/src/main.vala
@@ -24,6 +24,13 @@ int main (string[] args) {
Environment.set_application_name (_("Clocks"));
+ try {
+ Lfb.init(Config.APP_ID);
+ } catch (GLib.Error e) {
+ warning ("Couldn't init libfeedback: %s", e.message);
+ }
var app = new Clocks.Application ();
- return app.run (args);
+ var ret = app.run (args);
+ Lfb.uninit();
+ return ret;
}
diff --git a/src/meson.build b/src/meson.build
index 4c51188..e5b0edd 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -59,6 +59,7 @@ clocks_c_args = [
'-include', 'config.h',
'-DGWEATHER_I_KNOW_THIS_IS_UNSTABLE',
'-DGNOME_DESKTOP_USE_UNSTABLE_API',
+ '-DLIBFEEDBACK_USE_UNSTABLE_API',
]
clocks_dependencies = [
@@ -66,10 +67,10 @@ clocks_dependencies = [
gio,
gobject,
gtk,
- gsound,
gweather,
gnomedesktop,
geocodeglib,
+ libfeedback,
libgeoclue,
libhandy,
math
diff --git a/src/utils.vala b/src/utils.vala
index d5594e7..1b38fba 100644
--- a/src/utils.vala
+++ b/src/utils.vala
@@ -392,44 +392,31 @@ public class Weekdays {
}
public class Bell : Object {
- private GSound.Context? gsound;
private GLib.Cancellable cancellable;
+ private Lfb.Event event;
private string soundtheme;
- private string sound;
+ private string eventname;
- public Bell (string soundid) {
- try {
- gsound = new GSound.Context ();
- } catch (GLib.Error e) {
- warning ("Sound could not be initialized, error: %s", e.message);
- }
-
- var settings = new GLib.Settings ("org.gnome.desktop.sound");
+ public Bell (string eventid) {
+ var settings = new GLib.Settings("org.gnome.desktop.sound");
soundtheme = settings.get_string ("theme-name");
- sound = soundid;
- cancellable = new GLib.Cancellable ();
+ eventname = eventid;
+ cancellable = new GLib.Cancellable();
}
private async void ring_real (bool repeat) {
- if (gsound == null) {
+ if (!Lfb.is_initted())
return;
- }
-
- if (cancellable.is_cancelled ()) {
- cancellable.reset ();
- }
+ event = new Lfb.Event (eventname);
+ if (repeat)
+ event.timeout = 0;
try {
- do {
- yield ((GSound.Context) gsound).play_full (cancellable,
- GSound.Attribute.EVENT_ID, sound,
- GSound.Attribute.CANBERRA_XDG_THEME_NAME, soundtheme,
- GSound.Attribute.MEDIA_ROLE, "alarm");
- } while (repeat);
+ yield event.trigger_feedback_async (cancellable);
} catch (GLib.IOError.CANCELLED e) {
// ignore
} catch (GLib.Error e) {
- warning ("Error playing sound: %s", e.message);
+ warning ("Error triggering feedback for event %s: %s", eventname, e.message);
}
}
@@ -442,7 +429,15 @@ public class Bell : Object {
}
public void stop () {
- cancellable.cancel ();
+ event.end_feedback_async.begin (cancellable, (obj, res) => {
+ try {
+ event.end_feedback_async.end(res);
+ } catch (GLib.IOError.CANCELLED e) {
+ // ignore
+ } catch (GLib.Error e) {
+ warning ("Error ending feedback for event %s: %s", eventname, e.message);
+ }
+ });
}
}
--
2.34.1