From 8c0b55d7f8387642c38890348d795a917378a9b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Mon, 15 Jul 2019 19:03:59 +0200 Subject: [PATCH] Play sound on key press/release This needs entries in the sound theme for button-{pressed,released} which the xdg default one doesn't provide. --- eek/config.h | 0 eek/eek-gtk-keyboard.c | 44 ++++++++++++++++++++++++++---------------- meson.build | 18 +++++++++++++++++ src/config.h.in | 6 ++++++ src/meson.build | 4 ++++ 5 files changed, 55 insertions(+), 17 deletions(-) delete mode 100644 eek/config.h create mode 100644 src/config.h.in diff --git a/eek/config.h b/eek/config.h deleted file mode 100644 index e69de29b..00000000 diff --git a/eek/eek-gtk-keyboard.c b/eek/eek-gtk-keyboard.c index f5b61447..4d2fab39 100644 --- a/eek/eek-gtk-keyboard.c +++ b/eek/eek-gtk-keyboard.c @@ -23,12 +23,10 @@ * @short_description: a #GtkWidget displaying #EekKeyboard */ -#ifdef HAVE_CONFIG_H #include "config.h" -#endif /* HAVE_CONFIG_H */ -#ifdef HAVE_LIBCANBERRA -#include +#ifdef HAVE_GSOUND +#include #endif #include @@ -58,6 +56,9 @@ typedef struct _EekGtkKeyboardPrivate EekRenderer *renderer; EekKeyboard *keyboard; EekTheme *theme; +#ifdef HAVE_GSOUND + GSoundContext *sound_ctx; +#endif GdkEventSequence *sequence; // unowned reference } EekGtkKeyboardPrivate; @@ -438,7 +439,16 @@ eek_gtk_keyboard_class_init (EekGtkKeyboardClass *klass) static void eek_gtk_keyboard_init (EekGtkKeyboard *self) { - /* void */ +#if HAVE_GSOUND + EekGtkKeyboardPrivate *priv = eek_gtk_keyboard_get_instance_private (self); + GError *err = NULL; + + priv->sound_ctx = gsound_context_new(NULL, &err); + if (!priv->sound_ctx) { + g_warning ("GSound init failed: %s", err->message); + g_clear_error (&err); + } +#endif } /** @@ -567,12 +577,12 @@ on_key_pressed (EekKey *key, render_pressed_key (GTK_WIDGET(self), key); gtk_widget_queue_draw (GTK_WIDGET(self)); -#if HAVE_LIBCANBERRA - ca_gtk_play_for_widget (widget, 0, - CA_PROP_EVENT_ID, "button-pressed", - CA_PROP_EVENT_DESCRIPTION, "virtual key pressed", - CA_PROP_APPLICATION_ID, "org.fedorahosted.Eekboard", - NULL); +#if HAVE_GSOUND + g_return_if_fail (GSOUND_IS_CONTEXT (priv->sound_ctx)); + gsound_context_play_simple(priv->sound_ctx, NULL, NULL, + GSOUND_ATTR_EVENT_ID, "button-pressed", + GSOUND_ATTR_EVENT_DESCRIPTION, "Button pressed", + NULL); #endif } @@ -589,12 +599,12 @@ on_key_released (EekKey *key, render_released_key (GTK_WIDGET(self), key); gtk_widget_queue_draw (GTK_WIDGET(self)); -#if HAVE_LIBCANBERRA - ca_gtk_play_for_widget (widget, 0, - CA_PROP_EVENT_ID, "button-released", - CA_PROP_EVENT_DESCRIPTION, "virtual key pressed", - CA_PROP_APPLICATION_ID, "org.fedorahosted.Eekboard", - NULL); +#if HAVE_GSOUND + g_return_if_fail (GSOUND_IS_CONTEXT (priv->sound_ctx)); + gsound_context_play_simple(priv->sound_ctx, NULL, NULL, + GSOUND_ATTR_EVENT_ID, "button-released", + GSOUND_ATTR_EVENT_DESCRIPTION, "Button released", + NULL); #endif } diff --git a/meson.build b/meson.build index 269a451e..529ba261 100644 --- a/meson.build +++ b/meson.build @@ -9,6 +9,8 @@ project( i18n = import('i18n') +conf_data = configuration_data() + if get_option('buildtype').startswith('debug') add_project_arguments('-DDEBUG=1', language : 'c') endif @@ -26,6 +28,22 @@ else endif dbusdir = join_paths(depdatadir, 'dbus-1/interfaces') +gsound_dep = dependency('gsound', required : false) +if gsound_dep.found() + conf_data.set10('HAVE_GSOUND', true) +endif + +summary = [ + '', + '------------------', + 'squeekboard @0@'.format(meson.project_version()), + '', + ' gsound: @0@'.format(conf_data.get('HAVE_GSOUND', false)), + '------------------', + '' +] +message('\n'.join(summary)) + subdir('data') subdir('protocols') subdir('eek') diff --git a/src/config.h.in b/src/config.h.in new file mode 100644 index 00000000..5f7f33d4 --- /dev/null +++ b/src/config.h.in @@ -0,0 +1,6 @@ +/* + * Autogenerated by the Meson build system. + * Do not edit, your changes will be lost. + */ + +#mesondefine HAVE_GSOUND diff --git a/src/meson.build b/src/meson.build index 2f19c947..7b28db1f 100644 --- a/src/meson.build +++ b/src/meson.build @@ -4,7 +4,10 @@ dbus_src = gnome.gdbus_codegen( join_paths(meson.source_root() / 'data' / 'dbus', 'sm.puri.OSK0.xml') ) +config_h = configure_file(input: 'config.h.in', output: 'config.h',configuration: conf_data) + sources = [ + config_h, 'imservice.c', 'server-context-service.c', 'server-main.c', @@ -60,6 +63,7 @@ deps = [ cc.find_library('dl'), cc.find_library('pthread'), # dependency('libxklavier'), # FIXME remove + gsound_dep, ] # Replacement for eekboard-server