diff --git a/configure.ac b/configure.ac index 119b851ca..1ffde2257 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 9081e80e6..e7c426de1 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 b08f3d6ff..b25060cfa 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 af7b4ae80..32da177ab 100644 --- a/src/shell-global.c +++ b/src/shell-global.c @@ -13,9 +13,11 @@ #ifdef HAVE_SYS_RESOURCE_H #include #endif +#include #include #include +#include #include #include #include @@ -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 7c14892dd..2dd98ef76 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);