#endif
#include <stdio.h>
-#include <assert.h>
#include <stdlib.h>
#include <string.h>
NULL
};
-static int ring_bell(struct userdata *u, int percent) {
- pa_sink *s;
- assert(u);
-
- if (!(s = pa_namereg_get(u->core, u->sink_name, PA_NAMEREG_SINK, 1))) {
- pa_log("Invalid sink: %s", u->sink_name);
- return -1;
- }
-
- pa_scache_play_item(u->core, u->scache_item, s, (percent*PA_VOLUME_NORM)/100);
- return 0;
-}
-
static int x11_event_callback(pa_x11_wrapper *w, XEvent *e, void *userdata) {
XkbBellNotifyEvent *bne;
struct userdata *u = userdata;
- assert(w && e && u && u->x11_wrapper == w);
+
+ pa_assert(w);
+ pa_assert(e);
+ pa_assert(u);
+ pa_assert(u->x11_wrapper == w);
if (((XkbEvent*) e)->any.xkb_type != XkbBellNotify)
return 0;
bne = (XkbBellNotifyEvent*) e;
- if (ring_bell(u, bne->percent) < 0) {
+ if (pa_scache_play_item_by_name(u->core, u->scache_item, u->sink_name, (bne->percent*PA_VOLUME_NORM)/100, 1) < 0) {
pa_log_info("Ringing bell failed, reverting to X11 device bell.");
XkbForceDeviceBell(pa_x11_wrapper_get_display(w), bne->device, bne->bell_class, bne->bell_id, bne->percent);
}
}
int pa__init(pa_core *c, pa_module*m) {
+
struct userdata *u = NULL;
pa_modargs *ma = NULL;
int major, minor;
unsigned int auto_ctrls, auto_values;
- assert(c && m);
+
+ pa_assert(c);
+ pa_assert(m);
if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
- pa_log("failed to parse module arguments");
+ pa_log("Failed to parse module arguments");
goto fail;
}
- m->userdata = u = pa_xmalloc(sizeof(struct userdata));
+ m->userdata = u = pa_xnew(struct userdata, 1);
u->core = c;
u->scache_item = pa_xstrdup(pa_modargs_get_value(ma, "sample", "x11-bell"));
u->sink_name = pa_xstrdup(pa_modargs_get_value(ma, "sink", NULL));
major = XkbMajorVersion;
minor = XkbMinorVersion;
-
if (!XkbQueryExtension(pa_x11_wrapper_get_display(u->x11_wrapper), NULL, &u->xkb_event_base, NULL, &major, &minor)) {
pa_log("XkbQueryExtension() failed");
goto fail;
fail:
if (ma)
pa_modargs_free(ma);
- if (m->userdata)
- pa__done(c, m);
+
+ pa__done(c, m);
+
return -1;
}
void pa__done(pa_core *c, pa_module*m) {
- struct userdata *u = m->userdata;
- assert(c && m && u);
+ struct userdata *u;
+
+ assert(c);
+ assert(m);
+
+ if (!m->userdata)
+ return;
+
+ u = m->userdata;
pa_xfree(u->scache_item);
pa_xfree(u->sink_name);