From 8c9e0469f3512acb8c1df288f87e32febaed85ce Mon Sep 17 00:00:00 2001 From: Marc MAURICE Date: Mon, 24 Feb 2014 19:55:24 +0100 Subject: [PATCH 1/2] Add pop sound on volume change with libcanberra --- configure.ac | 1 + src/Makefile.am | 4 ++++ src/main.c | 7 +++++++ src/popsound.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ src/popsound.h | 15 +++++++++++++++ 5 files changed, 75 insertions(+) create mode 100644 src/popsound.c create mode 100644 src/popsound.h diff --git a/configure.ac b/configure.ac index 17b9035..757c0d7 100644 --- a/configure.ac +++ b/configure.ac @@ -17,6 +17,7 @@ PKG_CHECK_MODULES([LIBPULSE], [libpulse]) PKG_CHECK_MODULES([LIBPULSE_GLIB], [libpulse-mainloop-glib]) PKG_CHECK_MODULES([LIBNOTIFY], [libnotify]) PKG_CHECK_MODULES([XLIB], [x11]) +PKG_CHECK_MODULES([LIBCANBERRA], [libcanberra]) AC_CONFIG_FILES([Makefile man/Makefile src/Makefile]) AC_OUTPUT diff --git a/src/Makefile.am b/src/Makefile.am index e3df2d7..179bab1 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -8,6 +8,8 @@ pa_applet_SOURCES = \ main.c \ notifications.h \ notifications.c \ + popsound.h \ + popsound.c \ popup_menu.c \ popup_menu.h \ pulse_glue.c \ @@ -24,6 +26,7 @@ pa_applet_CPPFLAGS = \ $(LIBPULSE_CFLAGS) \ $(LIBPULSE_GLIB_CFLAGS) \ $(LIBNOTIFY_CFLAGS) \ + $(LIBCANBERRA_CFLAGS) \ $(XLIB_CFLAGS) pa_applet_LDADD = \ @@ -32,4 +35,5 @@ pa_applet_LDADD = \ $(LIBPULSE_LIBS) \ $(LIBPULSE_GLIB_LIBS) \ $(LIBNOTIFY_LIBS) \ + $(LIBCANBERRA_LIBS) \ $(XLIB_LIBS) diff --git a/src/main.c b/src/main.c index e957d13..af1cdd8 100644 --- a/src/main.c +++ b/src/main.c @@ -15,6 +15,7 @@ #include "audio_status.h" #include "key_grabber.h" #include "notifications.h" +#include "popsound.h" #include "pulse_glue.h" #include "tray_icon.h" @@ -25,6 +26,7 @@ static void volume_raise_key_pressed(void) audio_status_raise_volume(); pulse_glue_sync_volume(); notifications_flash(); + popsound_play(); } static void volume_lower_key_pressed(void) @@ -32,6 +34,7 @@ static void volume_lower_key_pressed(void) audio_status_lower_volume(); pulse_glue_sync_volume(); notifications_flash(); + popsound_play(); } static void volume_mute_key_pressed(void) @@ -39,6 +42,7 @@ static void volume_mute_key_pressed(void) audio_status_toggle_muted(); pulse_glue_sync_muted(); notifications_flash(); + popsound_play(); } static void print_usage(FILE *out) @@ -93,6 +97,8 @@ int main(int argc, char **argv) if (notifications_enabled) notifications_init(); + popsound_init(); + // Grab the keys if we're configured to grab them if (key_grabbing_enabled) { key_grabber_register_volume_raise_callback(volume_raise_key_pressed); @@ -112,6 +118,7 @@ int main(int argc, char **argv) key_grabber_ungrab_keys(); if (notifications_enabled) notifications_destroy(); + popsound_destroy(); destroy_tray_icon(); pulse_glue_destroy(); audio_status_destroy(); diff --git a/src/popsound.c b/src/popsound.c new file mode 100644 index 0000000..1a99900 --- /dev/null +++ b/src/popsound.c @@ -0,0 +1,48 @@ +/* + * This file is part of pa-applet. + * + * Refer to the LICENSE file for licensing information. + * + */ + +/* +Plays a sound with libcanberra when volume is changed with keypress +Event sounds can be configured / disabled in gtk config +See also: +http://0pointer.de/lennart/projects/libcanberra/ +*/ + +#include "audio_status.h" + +#include + +ca_context * cacontext; + +void popsound_play(void) +{ + audio_status *as = shared_audio_status(); + + // play the sound if not muted, and canberra initialized correctly + if ( (! as->muted) && (cacontext != NULL) ) { + ca_context_play (cacontext, 1, + CA_PROP_EVENT_ID, "audio-volume-change", + CA_PROP_EVENT_DESCRIPTION, "volume changed through key press", + CA_PROP_CANBERRA_CACHE_CONTROL, "permanent", + NULL); + } +} + +void popsound_init(void) +{ + if (ca_context_create (&cacontext) == 0) { + ca_context_set_driver (cacontext, "pulse"); + } else { + cacontext = NULL; + g_printerr("Failed to create libcanbera context\n"); + } +} + +void popsound_destroy(void) +{ + ca_context_destroy(cacontext); +} diff --git a/src/popsound.h b/src/popsound.h new file mode 100644 index 0000000..3d55216 --- /dev/null +++ b/src/popsound.h @@ -0,0 +1,15 @@ +/* + * This file is part of pa-applet. + * + * Refer to the LICENSE file for licensing information. + * + */ + +#ifndef POPSOUND_H +#define POPSOUND_H + +void popsound_init(void); +void popsound_destroy(void); +void popsound_play(void); + +#endif From 86ba8da0388e8aac50eda4d1204241e2f4dd91dc Mon Sep 17 00:00:00 2001 From: Marc MAURICE Date: Tue, 4 Mar 2014 13:38:27 +0100 Subject: [PATCH 2/2] bugfix: wrong volumescale position relative to trayicon in dual screen --- src/volume_scale.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/volume_scale.c b/src/volume_scale.c index 7049938..911036f 100644 --- a/src/volume_scale.c +++ b/src/volume_scale.c @@ -78,10 +78,22 @@ static void do_show_volume_scale(GdkRectangle *rect_or_null) // Position the window if (rect_or_null) { + // Get monitor coordinates + GdkRectangle rectmonitor; + GdkScreen *screen = gtk_widget_get_screen(window); + gdk_screen_get_monitor_geometry(screen, gdk_screen_get_monitor_at_point(screen, rect_or_null->x, rect_or_null->y), &rectmonitor); + gint size_x, size_y; gtk_window_get_size(GTK_WINDOW(window), &size_x, &size_y); gint x = rect_or_null->x + (rect_or_null->width - size_x) / 2; - gint y = rect_or_null->y > size_y ? rect_or_null->y - size_y : rect_or_null->y + rect_or_null->height; + + // set y assuming window above tray icon (tray icon bottom of monitor) + gint y = rect_or_null->y - size_y; + // if y not in the monitor: wrong assumption --> window bellow tray icon + if (! (rectmonitor.y < y && y < rectmonitor.y+rectmonitor.height) ) { + y = rect_or_null->y + rect_or_null->height; + } + gtk_window_move(GTK_WINDOW(window), x, y); }