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
This commit is contained in:
parent
b9ad5f8727
commit
427750d6af
@ -93,7 +93,7 @@ PKG_CHECK_MODULES(GNOME_SHELL, gio-unix-2.0 >= $GIO_MIN_VERSION
|
|||||||
clutter-glx-1.0 >= $CLUTTER_MIN_VERSION
|
clutter-glx-1.0 >= $CLUTTER_MIN_VERSION
|
||||||
libstartup-notification-1.0 >= $STARTUP_NOTIFICATION_MIN_VERSION
|
libstartup-notification-1.0 >= $STARTUP_NOTIFICATION_MIN_VERSION
|
||||||
gobject-introspection-1.0 >= $GOBJECT_INTROSPECTION_MIN_VERSION
|
gobject-introspection-1.0 >= $GOBJECT_INTROSPECTION_MIN_VERSION
|
||||||
libcanberra
|
libcanberra libcanberra-gtk3
|
||||||
telepathy-glib >= $TELEPATHY_GLIB_MIN_VERSION
|
telepathy-glib >= $TELEPATHY_GLIB_MIN_VERSION
|
||||||
telepathy-logger-0.2 >= $TELEPATHY_LOGGER_MIN_VERSION
|
telepathy-logger-0.2 >= $TELEPATHY_LOGGER_MIN_VERSION
|
||||||
polkit-agent-1 >= $POLKIT_MIN_VERSION xfixes
|
polkit-agent-1 >= $POLKIT_MIN_VERSION xfixes
|
||||||
|
@ -88,7 +88,9 @@ const AutomountManager = new Lang.Class({
|
|||||||
if (!this._loginManager.sessionActive)
|
if (!this._loginManager.sessionActive)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
global.play_theme_sound(0, 'device-added-media');
|
global.play_theme_sound(0, 'device-added-media',
|
||||||
|
_("External drive connected"),
|
||||||
|
null);
|
||||||
},
|
},
|
||||||
|
|
||||||
_onDriveDisconnected: function() {
|
_onDriveDisconnected: function() {
|
||||||
@ -97,7 +99,9 @@ const AutomountManager = new Lang.Class({
|
|||||||
if (!this._loginManager.sessionActive)
|
if (!this._loginManager.sessionActive)
|
||||||
return;
|
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) {
|
_onDriveEjectButton: function(monitor, drive) {
|
||||||
|
@ -119,7 +119,10 @@ const StreamSlider = new Lang.Class({
|
|||||||
|
|
||||||
_notifyVolumeChange: function() {
|
_notifyVolumeChange: function() {
|
||||||
global.cancel_theme_sound(VOLUME_NOTIFY_ID);
|
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() {
|
_updateVolume: function() {
|
||||||
|
@ -13,9 +13,11 @@
|
|||||||
#ifdef HAVE_SYS_RESOURCE_H
|
#ifdef HAVE_SYS_RESOURCE_H
|
||||||
#include <sys/resource.h>
|
#include <sys/resource.h>
|
||||||
#endif
|
#endif
|
||||||
|
#include <locale.h>
|
||||||
|
|
||||||
#include <X11/extensions/Xfixes.h>
|
#include <X11/extensions/Xfixes.h>
|
||||||
#include <canberra.h>
|
#include <canberra.h>
|
||||||
|
#include <canberra-gtk.h>
|
||||||
#include <clutter/glx/clutter-glx.h>
|
#include <clutter/glx/clutter-glx.h>
|
||||||
#include <clutter/x11/clutter-x11.h>
|
#include <clutter/x11/clutter-x11.h>
|
||||||
#include <gdk/gdkx.h>
|
#include <gdk/gdkx.h>
|
||||||
@ -265,8 +267,13 @@ shell_global_init (ShellGlobal *global)
|
|||||||
|
|
||||||
global->input_mode = SHELL_STAGE_INPUT_MODE_NORMAL;
|
global->input_mode = SHELL_STAGE_INPUT_MODE_NORMAL;
|
||||||
|
|
||||||
ca_context_create (&global->sound_context);
|
global->sound_context = ca_gtk_context_get ();
|
||||||
ca_context_change_props (global->sound_context, CA_PROP_APPLICATION_NAME, PACKAGE_NAME, CA_PROP_APPLICATION_ID, "org.gnome.Shell", NULL);
|
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);
|
ca_context_open (global->sound_context);
|
||||||
|
|
||||||
if (!shell_js)
|
if (!shell_js)
|
||||||
@ -1577,11 +1584,46 @@ shell_global_run_at_leisure (ShellGlobal *global,
|
|||||||
schedule_leisure_functions (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:
|
* shell_global_play_theme_sound:
|
||||||
* @global: the #ShellGlobal
|
* @global: the #ShellGlobal
|
||||||
* @id: an id, used to cancel later (0 if not needed)
|
* @id: an id, used to cancel later (0 if not needed)
|
||||||
* @name: the sound name
|
* @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.
|
* Plays a simple sound picked according to Freedesktop sound theme.
|
||||||
* Really just a workaround for libcanberra not being introspected.
|
* Really just a workaround for libcanberra not being introspected.
|
||||||
@ -1589,9 +1631,52 @@ shell_global_run_at_leisure (ShellGlobal *global,
|
|||||||
void
|
void
|
||||||
shell_global_play_theme_sound (ShellGlobal *global,
|
shell_global_play_theme_sound (ShellGlobal *global,
|
||||||
guint id,
|
guint id,
|
||||||
const char *name)
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -123,7 +123,16 @@ GAppLaunchContext *
|
|||||||
|
|
||||||
void shell_global_play_theme_sound (ShellGlobal *global,
|
void shell_global_play_theme_sound (ShellGlobal *global,
|
||||||
guint id,
|
guint id,
|
||||||
const char *name);
|
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 *description,
|
||||||
|
ClutterEvent *for_event,
|
||||||
|
const char *application_id,
|
||||||
|
const char *application_name);
|
||||||
void shell_global_cancel_theme_sound (ShellGlobal *global,
|
void shell_global_cancel_theme_sound (ShellGlobal *global,
|
||||||
guint id);
|
guint id);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user