From 032d8723225e0151ae801a852a11a52e9f909d91 Mon Sep 17 00:00:00 2001 From: Leonardo Robol Date: Sat, 7 May 2011 15:32:55 +0200 Subject: [PATCH] Ora ci sono le notifiche, anche se sarebbe ancora da rifinire. --- Makefile | 6 ++++++ robolmute.c | 47 ++++++++++++++++++++++++++++------------------- 2 files changed, 34 insertions(+), 19 deletions(-) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..73f8d02 --- /dev/null +++ b/Makefile @@ -0,0 +1,6 @@ +LDFLAGS=$(shell pkg-config --libs glib-2.0 gdk-2.0) +CFLAGS=$(shell pkg-config --cflags glib-2.0 gdk-2.0) +LDFLAGS+= -lpulse -lnotify + +robolmute: robolmute.c + cc -o robolmute $(CFLAGS) $(LDFLAGS) robolmute.c diff --git a/robolmute.c b/robolmute.c index 12088d6..41c4078 100644 --- a/robolmute.c +++ b/robolmute.c @@ -1,14 +1,29 @@ #include -#include #include +#include +#include +#include +/* Global variable to keep track of the main pulse audio loop */ pa_mainloop* mainloop; -pa_operation* operation; - void -success_callback(pa_context *c, int success, void* userdata) +success_callback(pa_context *c, int success, char* new_output) { + /* Notify to the user that the switch was successful */ + GError* error = NULL; + char body[255]; + if (strlen(new_output) < 200) + sprintf(body, "New active output: %s", new_output); + else + strncpy(body, new_output, 255); + NotifyNotification *notification = notify_notification_new ("Audio switched", + body, + "gnome-mixer"); + notify_notification_show (notification, + &error); + + /* Exit the pulseaudio mainloop */ pa_mainloop_quit(mainloop, success); } @@ -18,23 +33,15 @@ toggle_mute(pa_context *c, pa_sink_info *i, void* user_data) { int j; if (i) { - printf("Name: %s\n", i->name); - if (i->active_port) - printf("Active port: %s\n", i->active_port->description); - printf("Available ports:\n"); - for(j = 0; j < i->n_ports; j++) { - printf(" - %s: %s\n", i->ports[j]->name, - i->ports[j]->description); - } - - /* Cycle through available active ports */ + /* Cycle through available active ports. This should + * rotate between headphones and/or analog output. */ for(j = 0; j < i->n_ports; j++) { if (i->active_port == i->ports[j]) { pa_context_set_sink_port_by_index(c, i->index, i->ports[(j + 1) % i->n_ports]->name, (pa_context_success_cb_t) success_callback, - NULL); + (char*) i->ports[(j+1) % i->n_ports]->description); } } } @@ -45,9 +52,9 @@ void context_connected_cb(pa_context *c, void* user_data) { if (pa_context_get_state(c) == PA_CONTEXT_READY) { - operation = pa_context_get_sink_info_list(c, - (pa_sink_info_cb_t) toggle_mute, - NULL); + pa_context_get_sink_info_list(c, + (pa_sink_info_cb_t) toggle_mute, + NULL); } } @@ -62,6 +69,8 @@ main() int retval; pa_proplist *proplist; + notify_init ("AudioSwitch"); + proplist = pa_proplist_new(); pa_proplist_sets(proplist, PA_PROP_DEVICE_API, "alsa"); c = pa_context_new_with_proplist(api, "RobolMute", @@ -75,5 +84,5 @@ main() /* Loop :) */ pa_mainloop_run(mainloop, &retval); - return 0; + return retval; } -- 2.1.4