Use libcanberra to play system bell and workspace switch sounds
Patch by Lennart Poettering * configure.in: Require libcanberra-gtk * src/core/bell.c (meta_bell_notify): Play the alert sound from the sound theme instead of the dreaded system bell. * src/core/workspace.c (meta_workspace_activate_with_focus): Play a sound on workspace switch. https://bugzilla.gnome.org/show_bug.cgi?id=557921 https://bugzilla.gnome.org/show_bug.cgi?id=609585
This commit is contained in:
parent
e7751e170e
commit
5aab9e878f
@ -124,7 +124,7 @@ if test "x$GCC" = "xyes"; then
|
||||
fi
|
||||
changequote([,])dnl
|
||||
|
||||
MUTTER_PC_MODULES='gtk+-2.0 >= 2.10.0 pango >= 1.2.0'
|
||||
MUTTER_PC_MODULES='gtk+-2.0 >= 2.10.0 pango >= 1.2.0 libcanberra-gtk'
|
||||
|
||||
AC_ARG_ENABLE(gconf,
|
||||
AC_HELP_STRING([--disable-gconf],
|
||||
|
@ -1,5 +1,6 @@
|
||||
# List of source files containing translatable strings.
|
||||
# Please keep this file sorted alphabetically.
|
||||
src/core/bell.c
|
||||
src/core/core.c
|
||||
src/core/delete.c
|
||||
src/core/display.c
|
||||
|
@ -52,6 +52,7 @@
|
||||
#include "bell.h"
|
||||
#include "screen-private.h"
|
||||
#include "prefs.h"
|
||||
#include <canberra-gtk.h>
|
||||
|
||||
/**
|
||||
* Flashes one entire screen. This is done by making a window the size of the
|
||||
@ -228,7 +229,7 @@ bell_flash_window_frame (MetaWindow *window)
|
||||
*/
|
||||
static void
|
||||
bell_flash_frame (MetaDisplay *display,
|
||||
XkbAnyEvent *xkb_ev)
|
||||
XkbAnyEvent *xkb_ev)
|
||||
{
|
||||
XkbBellNotifyEvent *xkb_bell_event = (XkbBellNotifyEvent *) xkb_ev;
|
||||
MetaWindow *window;
|
||||
@ -285,6 +286,46 @@ meta_bell_notify (MetaDisplay *display,
|
||||
/* flash something */
|
||||
if (meta_prefs_get_visual_bell ())
|
||||
bell_visual_notify (display, xkb_ev);
|
||||
|
||||
if (meta_prefs_bell_is_audible ())
|
||||
{
|
||||
ca_proplist *p;
|
||||
XkbBellNotifyEvent *xkb_bell_event = (XkbBellNotifyEvent*) xkb_ev;
|
||||
MetaWindow *window;
|
||||
int res;
|
||||
|
||||
ca_proplist_create (&p);
|
||||
ca_proplist_sets (p, CA_PROP_EVENT_ID, "bell-window-system");
|
||||
ca_proplist_sets (p, CA_PROP_EVENT_DESCRIPTION, _("Bell event"));
|
||||
ca_proplist_sets (p, CA_PROP_CANBERRA_ENABLE, "1");
|
||||
|
||||
window = meta_display_lookup_x_window (display, xkb_bell_event->window);
|
||||
if (!window && (display->focus_window) && (display->focus_window->frame))
|
||||
window = display->focus_window;
|
||||
|
||||
if (window)
|
||||
{
|
||||
ca_proplist_sets (p, CA_PROP_WINDOW_NAME, window->title);
|
||||
ca_proplist_setf (p, CA_PROP_WINDOW_X11_XID, "%lu", (unsigned long)window->xwindow);
|
||||
ca_proplist_sets (p, CA_PROP_APPLICATION_NAME, window->res_name);
|
||||
ca_proplist_setf (p, CA_PROP_APPLICATION_PROCESS_ID, "%d", window->net_wm_pid);
|
||||
}
|
||||
|
||||
/* First, we try to play a real sound ... */
|
||||
res = ca_context_play_full (ca_gtk_context_get (), 1, p, NULL, NULL);
|
||||
|
||||
ca_proplist_destroy (p);
|
||||
|
||||
if (res != CA_SUCCESS && res != CA_ERROR_DISABLED)
|
||||
{
|
||||
/* ...and in case that failed we use the classic X11 bell. */
|
||||
XkbForceDeviceBell (display->xdisplay,
|
||||
xkb_bell_event->device,
|
||||
xkb_bell_event->bell_class,
|
||||
xkb_bell_event->bell_id,
|
||||
xkb_bell_event->percent);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* HAVE_XKB */
|
||||
|
||||
@ -326,8 +367,7 @@ meta_bell_init (MetaDisplay *display)
|
||||
XkbChangeEnabledControls (display->xdisplay,
|
||||
XkbUseCoreKbd,
|
||||
XkbAudibleBellMask,
|
||||
meta_prefs_bell_is_audible ()
|
||||
? XkbAudibleBellMask : 0);
|
||||
0);
|
||||
if (visual_bell_auto_reset) {
|
||||
XkbSetAutoResetControls (display->xdisplay,
|
||||
XkbAudibleBellMask,
|
||||
|
@ -33,6 +33,7 @@
|
||||
|
||||
#include <X11/Xatom.h>
|
||||
#include <string.h>
|
||||
#include <canberra-gtk.h>
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
@ -439,6 +440,66 @@ meta_workspace_queue_calc_showing (MetaWorkspace *workspace)
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
workspace_switch_sound(MetaWorkspace *from,
|
||||
MetaWorkspace *to)
|
||||
{
|
||||
MetaWorkspaceLayout layout;
|
||||
int i, nw, x, y, fi, ti;
|
||||
const char *e;
|
||||
|
||||
nw = meta_screen_get_n_workspaces(from->screen);
|
||||
fi = meta_workspace_index(from);
|
||||
ti = meta_workspace_index(to);
|
||||
|
||||
meta_screen_calc_workspace_layout(from->screen,
|
||||
nw,
|
||||
fi,
|
||||
&layout);
|
||||
|
||||
for (i = 0; i < nw; i++)
|
||||
if (layout.grid[i] == ti)
|
||||
break;
|
||||
|
||||
if (i >= nw)
|
||||
{
|
||||
meta_bug("Failed to find destination workspace in layout\n");
|
||||
goto finish;
|
||||
}
|
||||
|
||||
y = i / layout.cols;
|
||||
x = i % layout.cols;
|
||||
|
||||
/* We priorize horizontal over vertical movements here. The
|
||||
rationale for this is that horizontal movements are probably more
|
||||
interesting for sound effects because speakers are usually
|
||||
positioned on a horizontal and not a vertical axis. i.e. your
|
||||
spatial "Woosh!" effects will easily be able to encode horizontal
|
||||
movement but not such much vertical movement. */
|
||||
|
||||
if (x < layout.current_col)
|
||||
e = "desktop-switch-left";
|
||||
else if (x > layout.current_col)
|
||||
e = "desktop-switch-right";
|
||||
else if (y < layout.current_row)
|
||||
e = "desktop-switch-up";
|
||||
else if (y > layout.current_row)
|
||||
e = "desktop-switch-down";
|
||||
else
|
||||
{
|
||||
meta_bug("Uh, origin and destination workspace at same logic position!\n");
|
||||
goto finish;
|
||||
}
|
||||
|
||||
ca_context_play(ca_gtk_context_get(), 1,
|
||||
CA_PROP_EVENT_ID, e,
|
||||
CA_PROP_EVENT_DESCRIPTION, "Desktop switched",
|
||||
NULL);
|
||||
|
||||
finish:
|
||||
meta_screen_free_workspace_layout (&layout);
|
||||
}
|
||||
|
||||
/**
|
||||
* meta_workspace_activate_with_focus:
|
||||
* @workspace: a #MetaWorkspace
|
||||
@ -482,6 +543,9 @@ meta_workspace_activate_with_focus (MetaWorkspace *workspace,
|
||||
* a current resize or move operation */
|
||||
meta_display_cleanup_edges (workspace->screen->display);
|
||||
|
||||
if (workspace->screen->active_workspace)
|
||||
workspace_switch_sound (workspace->screen->active_workspace, workspace);
|
||||
|
||||
/* Note that old can be NULL; e.g. when starting up */
|
||||
old = workspace->screen->active_workspace;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user