/** * Callback for sink changes reported by PulseAudio. */ static void xvd_update_sink_callback (pa_context *c, const pa_sink_info *info, int eol, void *userdata) { XvdInstance *i = (XvdInstance *) userdata; /* detect the end of the list */ if (eol > 0) return; else { if (!c || !userdata || !info) { g_warning ("xvd_update_sink_callback: invalid argument"); return; } /* re-fetch infos from PulseAudio */ i->sink_index = info->index; old_volume = i->volume; i->volume = info->volume; old_mute = i->mute; i->mute = info->mute; #ifdef HAVE_LIBNOTIFY /* notify user of the possible changes */ if (xvd_get_readable_volume (&old_volume) != xvd_get_readable_volume (&i->volume) || old_mute != i->mute) xvd_notify_volume_callback (c, 1, i); #endif } }
/** * Decides the type of notification to show on a change. */ static void xvd_notify_volume_callback (pa_context *c, int success, void *userdata) { XvdInstance *i = (XvdInstance *) userdata; guint32 r_oldv, r_curv; if (!c || !userdata) { g_warning ("xvd_notify_volume_update: invalid argument"); return; } if (!success) { g_warning ("xvd_notify_volume_update: operation failed, %s", pa_strerror (pa_context_errno (c))); return; } /* the sink was (un)muted */ if (old_mute != i->mute) { xvd_notify_volume_notification (i); return; } r_oldv = xvd_get_readable_volume (&old_volume); r_curv = xvd_get_readable_volume (&i->volume); /* trying to go above 100 */ if (r_oldv == 100 && r_curv >= r_oldv) xvd_notify_overshoot_notification (i); /* trying to go below 0 */ else if (r_oldv == 0 && r_curv <= r_oldv) xvd_notify_undershoot_notification (i); /* normal */ else xvd_notify_volume_notification (i); }
void xvd_notify_volume_notification(XvdInstance *Inst) { gint vol = xvd_get_readable_volume (&Inst->volume); if (vol == 0) xvd_notify_notification (Inst, (Inst->mute) ? "audio-volume-muted" : "audio-volume-off", vol); else if (vol < 34) xvd_notify_notification (Inst, (Inst->mute) ? "audio-volume-muted" : "audio-volume-low", vol); else if (vol < 67) xvd_notify_notification (Inst, (Inst->mute) ? "audio-volume-muted" : "audio-volume-medium", vol); else xvd_notify_notification (Inst, (Inst->mute) ? "audio-volume-muted" : "audio-volume-high", vol); }