[gnome-shell] ShellGlobal: improve code to emit sound events
- From: Giovanni Campagna <gcampagna src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell] ShellGlobal: improve code to emit sound events
- Date: Mon, 21 Jan 2013 17:04:04 +0000 (UTC)
commit 427750d6afd66581eb779b0702d125070e20feed
Author: Giovanni Campagna <gcampagna src gnome org>
Date: Sun Nov 4 19:53:49 2012 +0100
ShellGlobal: improve code to emit sound events
Use libcanberra-gtk3 and improve the set of context properties to correctly
associate the sounds with the shell.
https://bugzilla.gnome.org/show_bug.cgi?id=642831
configure.ac | 2 +-
js/ui/components/automountManager.js | 8 ++-
js/ui/status/volume.js | 5 ++-
src/shell-global.c | 97 +++++++++++++++++++++++++++++++--
src/shell-global.h | 13 ++++-
5 files changed, 113 insertions(+), 12 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 119b851..1ffde22 100644
--- a/configure.ac
+++ b/configure.ac
@@ -93,7 +93,7 @@ PKG_CHECK_MODULES(GNOME_SHELL, gio-unix-2.0 >= $GIO_MIN_VERSION
clutter-glx-1.0 >= $CLUTTER_MIN_VERSION
libstartup-notification-1.0 >= $STARTUP_NOTIFICATION_MIN_VERSION
gobject-introspection-1.0 >= $GOBJECT_INTROSPECTION_MIN_VERSION
- libcanberra
+ libcanberra libcanberra-gtk3
telepathy-glib >= $TELEPATHY_GLIB_MIN_VERSION
telepathy-logger-0.2 >= $TELEPATHY_LOGGER_MIN_VERSION
polkit-agent-1 >= $POLKIT_MIN_VERSION xfixes
diff --git a/js/ui/components/automountManager.js b/js/ui/components/automountManager.js
index 9081e80..e7c426d 100644
--- a/js/ui/components/automountManager.js
+++ b/js/ui/components/automountManager.js
@@ -88,7 +88,9 @@ const AutomountManager = new Lang.Class({
if (!this._loginManager.sessionActive)
return;
- global.play_theme_sound(0, 'device-added-media');
+ global.play_theme_sound(0, 'device-added-media',
+ _("External drive connected"),
+ null);
},
_onDriveDisconnected: function() {
@@ -97,7 +99,9 @@ const AutomountManager = new Lang.Class({
if (!this._loginManager.sessionActive)
return;
- global.play_theme_sound(0, 'device-removed-media');
+ global.play_theme_sound(0, 'device-removed-media',
+ _("External drive disconnected"),
+ null);
},
_onDriveEjectButton: function(monitor, drive) {
diff --git a/js/ui/status/volume.js b/js/ui/status/volume.js
index b08f3d6..b25060c 100644
--- a/js/ui/status/volume.js
+++ b/js/ui/status/volume.js
@@ -119,7 +119,10 @@ const StreamSlider = new Lang.Class({
_notifyVolumeChange: function() {
global.cancel_theme_sound(VOLUME_NOTIFY_ID);
- global.play_theme_sound(VOLUME_NOTIFY_ID, 'audio-volume-change');
+ global.play_theme_sound(VOLUME_NOTIFY_ID,
+ 'audio-volume-change',
+ _("Volume changed"),
+ Clutter.get_current_event ());
},
_updateVolume: function() {
diff --git a/src/shell-global.c b/src/shell-global.c
index af7b4ae..32da177 100644
--- a/src/shell-global.c
+++ b/src/shell-global.c
@@ -13,9 +13,11 @@
#ifdef HAVE_SYS_RESOURCE_H
#include <sys/resource.h>
#endif
+#include <locale.h>
#include <X11/extensions/Xfixes.h>
#include <canberra.h>
+#include <canberra-gtk.h>
#include <clutter/glx/clutter-glx.h>
#include <clutter/x11/clutter-x11.h>
#include <gdk/gdkx.h>
@@ -265,8 +267,13 @@ shell_global_init (ShellGlobal *global)
global->input_mode = SHELL_STAGE_INPUT_MODE_NORMAL;
- ca_context_create (&global->sound_context);
- ca_context_change_props (global->sound_context, CA_PROP_APPLICATION_NAME, PACKAGE_NAME, CA_PROP_APPLICATION_ID, "org.gnome.Shell", NULL);
+ global->sound_context = ca_gtk_context_get ();
+ ca_context_change_props (global->sound_context,
+ CA_PROP_APPLICATION_NAME, "GNOME Shell",
+ CA_PROP_APPLICATION_ID, "org.gnome.Shell",
+ CA_PROP_APPLICATION_ICON_NAME, "start-here",
+ CA_PROP_APPLICATION_LANGUAGE, setlocale (LC_MESSAGES, NULL),
+ NULL);
ca_context_open (global->sound_context);
if (!shell_js)
@@ -1577,21 +1584,99 @@ shell_global_run_at_leisure (ShellGlobal *global,
schedule_leisure_functions (global);
}
+static void
+build_ca_proplist_for_event (ca_proplist *props,
+ const char *event_id,
+ const char *event_description,
+ ClutterEvent *for_event)
+{
+ ca_proplist_sets (props, CA_PROP_EVENT_ID, event_id);
+ ca_proplist_sets (props, CA_PROP_EVENT_DESCRIPTION, event_description);
+ ca_proplist_sets (props, CA_PROP_CANBERRA_CACHE_CONTROL, "volatile");
+
+ if (for_event)
+ {
+ if (clutter_event_type (for_event) != CLUTTER_KEY_PRESS &&
+ clutter_event_type (for_event) != CLUTTER_KEY_RELEASE)
+ {
+ ClutterPoint point;
+
+ clutter_event_get_position (for_event, &point);
+
+ ca_proplist_setf (props, CA_PROP_EVENT_MOUSE_X, "%d", (int)point.x);
+ ca_proplist_setf (props, CA_PROP_EVENT_MOUSE_Y, "%d", (int)point.y);
+ }
+
+ if (clutter_event_type (for_event) == CLUTTER_BUTTON_PRESS ||
+ clutter_event_type (for_event) == CLUTTER_BUTTON_RELEASE)
+ {
+ gint button;
+
+ button = clutter_event_get_button (for_event);
+ ca_proplist_setf (props, CA_PROP_EVENT_MOUSE_BUTTON, "%d", button);
+ }
+ }
+}
+
/**
* shell_global_play_theme_sound:
* @global: the #ShellGlobal
* @id: an id, used to cancel later (0 if not needed)
* @name: the sound name
+ * @for_event: (allow-none): a #ClutterEvent in response to which the sound is played
*
* Plays a simple sound picked according to Freedesktop sound theme.
* Really just a workaround for libcanberra not being introspected.
*/
void
-shell_global_play_theme_sound (ShellGlobal *global,
- guint id,
- const char *name)
+shell_global_play_theme_sound (ShellGlobal *global,
+ guint id,
+ const char *name,
+ const char *description,
+ ClutterEvent *for_event)
{
- ca_context_play (global->sound_context, id, CA_PROP_EVENT_ID, name, NULL);
+ ca_proplist *props;
+
+ ca_proplist_create (&props);
+ build_ca_proplist_for_event (props, name, description, for_event);
+
+ ca_context_play_full (global->sound_context, id, props, NULL, NULL);
+
+ ca_proplist_destroy (props);
+}
+
+/**
+ * shell_global_play_theme_sound_full:
+ * @global: the #ShellGlobal
+ * @id: an id, used to cancel later (0 if not needed)
+ * @name: the sound name
+ * @description: the localized description of the event that triggered this alert
+ * @for_event: (allow-none): a #ClutterEvent in response to which the sound is played
+ * @application_id: application on behalf of which the sound is played
+ * @application_name:
+ *
+ * Plays a simple sound picked according to Freedesktop sound theme.
+ * Really just a workaround for libcanberra not being introspected.
+ */
+void
+shell_global_play_theme_sound_full (ShellGlobal *global,
+ guint id,
+ const char *name,
+ const char *description,
+ ClutterEvent *for_event,
+ const char *application_id,
+ const char *application_name)
+{
+ ca_proplist *props;
+
+ ca_proplist_create (&props);
+ build_ca_proplist_for_event (props, name, description, for_event);
+ ca_proplist_sets (props, CA_PROP_APPLICATION_ID, application_id);
+ ca_proplist_sets (props, CA_PROP_APPLICATION_NAME, application_name);
+
+ ca_context_play_full (global->sound_context, id, props, NULL, NULL);
+
+ ca_proplist_destroy (props);
}
/**
diff --git a/src/shell-global.h b/src/shell-global.h
index 7c14892..2dd98ef 100644
--- a/src/shell-global.h
+++ b/src/shell-global.h
@@ -121,9 +121,18 @@ void shell_global_sync_pointer (ShellGlobal *global);
GAppLaunchContext *
shell_global_create_app_launch_context (ShellGlobal *global);
-void shell_global_play_theme_sound (ShellGlobal *global,
+void shell_global_play_theme_sound (ShellGlobal *global,
+ guint id,
+ const char *name,
+ const char *description,
+ ClutterEvent *for_event);
+void shell_global_play_theme_sound_full (ShellGlobal *global,
guint id,
- const char *name);
+ const char *name,
+ const char *description,
+ ClutterEvent *for_event,
+ const char *application_id,
+ const char *application_name);
void shell_global_cancel_theme_sound (ShellGlobal *global,
guint id);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]