2004-08-17 19:47:42 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
|
|
/***
|
2006-06-19 21:53:48 +00:00
|
|
|
This file is part of PulseAudio.
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2007-02-13 15:35:19 +00:00
|
|
|
Copyright 2004-2006 Lennart Poettering
|
|
|
|
|
|
2006-06-19 21:53:48 +00:00
|
|
|
PulseAudio is free software; you can redistribute it and/or modify
|
2004-11-14 14:58:54 +00:00
|
|
|
it under the terms of the GNU Lesser General Public License as published
|
2004-08-17 19:47:42 +00:00
|
|
|
by the Free Software Foundation; either version 2 of the License,
|
|
|
|
|
or (at your option) any later version.
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2006-06-19 21:53:48 +00:00
|
|
|
PulseAudio is distributed in the hope that it will be useful, but
|
2004-08-17 19:47:42 +00:00
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
General Public License for more details.
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2004-11-14 14:58:54 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
2006-06-19 21:53:48 +00:00
|
|
|
along with PulseAudio; if not, write to the Free Software
|
2004-08-17 19:47:42 +00:00
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
|
USA.
|
|
|
|
|
***/
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
#include <config.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2004-08-02 16:24:14 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
|
#include <X11/XKBlib.h>
|
|
|
|
|
|
2006-06-19 21:53:48 +00:00
|
|
|
#include <pulse/xmalloc.h>
|
2006-05-17 16:34:18 +00:00
|
|
|
|
2006-06-19 21:53:48 +00:00
|
|
|
#include <pulsecore/iochannel.h>
|
|
|
|
|
#include <pulsecore/sink.h>
|
|
|
|
|
#include <pulsecore/core-scache.h>
|
|
|
|
|
#include <pulsecore/modargs.h>
|
|
|
|
|
#include <pulsecore/namereg.h>
|
|
|
|
|
#include <pulsecore/log.h>
|
|
|
|
|
#include <pulsecore/x11wrap.h>
|
2006-02-16 19:19:58 +00:00
|
|
|
|
2004-10-30 01:55:16 +00:00
|
|
|
#include "module-x11-bell-symdef.h"
|
2004-08-02 16:24:14 +00:00
|
|
|
|
2004-09-11 23:17:38 +00:00
|
|
|
PA_MODULE_AUTHOR("Lennart Poettering")
|
|
|
|
|
PA_MODULE_DESCRIPTION("X11 Bell interceptor")
|
|
|
|
|
PA_MODULE_VERSION(PACKAGE_VERSION)
|
|
|
|
|
PA_MODULE_USAGE("sink=<sink to connect to> sample=<sample name> display=<X11 display>")
|
|
|
|
|
|
2004-08-02 16:24:14 +00:00
|
|
|
struct userdata {
|
2006-01-11 01:17:39 +00:00
|
|
|
pa_core *core;
|
2004-08-02 16:24:14 +00:00
|
|
|
int xkb_event_base;
|
2004-08-04 16:39:30 +00:00
|
|
|
char *sink_name;
|
2004-08-02 16:24:14 +00:00
|
|
|
char *scache_item;
|
2004-10-30 01:55:16 +00:00
|
|
|
|
2006-01-11 01:17:39 +00:00
|
|
|
pa_x11_wrapper *x11_wrapper;
|
|
|
|
|
pa_x11_client *x11_client;
|
2004-08-02 16:24:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const char* const valid_modargs[] = {
|
|
|
|
|
"sink",
|
|
|
|
|
"sample",
|
|
|
|
|
"display",
|
|
|
|
|
NULL
|
|
|
|
|
};
|
|
|
|
|
|
2006-01-11 01:17:39 +00:00
|
|
|
static int x11_event_callback(pa_x11_wrapper *w, XEvent *e, void *userdata) {
|
2004-10-30 01:55:16 +00:00
|
|
|
XkbBellNotifyEvent *bne;
|
2004-08-02 16:24:14 +00:00
|
|
|
struct userdata *u = userdata;
|
2007-10-28 19:13:50 +00:00
|
|
|
|
|
|
|
|
pa_assert(w);
|
|
|
|
|
pa_assert(e);
|
|
|
|
|
pa_assert(u);
|
|
|
|
|
pa_assert(u->x11_wrapper == w);
|
2004-10-30 01:55:16 +00:00
|
|
|
|
|
|
|
|
if (((XkbEvent*) e)->any.xkb_type != XkbBellNotify)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
bne = (XkbBellNotifyEvent*) e;
|
2004-08-02 16:24:14 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
if (pa_scache_play_item_by_name(u->core, u->scache_item, u->sink_name, (bne->percent*PA_VOLUME_NORM)/100, 1) < 0) {
|
2006-08-18 21:38:40 +00:00
|
|
|
pa_log_info("Ringing bell failed, reverting to X11 device bell.");
|
2004-10-30 01:55:16 +00:00
|
|
|
XkbForceDeviceBell(pa_x11_wrapper_get_display(w), bne->device, bne->bell_class, bne->bell_id, bne->percent);
|
|
|
|
|
}
|
2004-08-02 16:24:14 +00:00
|
|
|
|
2004-10-30 01:55:16 +00:00
|
|
|
return 1;
|
2004-08-02 16:24:14 +00:00
|
|
|
}
|
|
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
int pa__init(pa_module*m) {
|
|
|
|
|
|
2004-08-02 16:24:14 +00:00
|
|
|
struct userdata *u = NULL;
|
2006-01-11 01:17:39 +00:00
|
|
|
pa_modargs *ma = NULL;
|
2004-08-02 16:24:14 +00:00
|
|
|
int major, minor;
|
|
|
|
|
unsigned int auto_ctrls, auto_values;
|
2007-10-28 19:13:50 +00:00
|
|
|
|
|
|
|
|
pa_assert(m);
|
2004-08-02 16:24:14 +00:00
|
|
|
|
|
|
|
|
if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
|
2007-10-28 19:13:50 +00:00
|
|
|
pa_log("Failed to parse module arguments");
|
2004-08-02 16:24:14 +00:00
|
|
|
goto fail;
|
|
|
|
|
}
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
m->userdata = u = pa_xnew(struct userdata, 1);
|
|
|
|
|
u->core = m->core;
|
2004-08-04 16:39:30 +00:00
|
|
|
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));
|
2004-10-30 01:55:16 +00:00
|
|
|
u->x11_client = NULL;
|
2004-08-02 16:24:14 +00:00
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
if (!(u->x11_wrapper = pa_x11_wrapper_get(m->core, pa_modargs_get_value(ma, "display", NULL))))
|
2004-08-02 16:24:14 +00:00
|
|
|
goto fail;
|
|
|
|
|
|
|
|
|
|
major = XkbMajorVersion;
|
|
|
|
|
minor = XkbMinorVersion;
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2004-08-02 16:24:14 +00:00
|
|
|
if (!XkbLibraryVersion(&major, &minor)) {
|
2006-08-18 21:38:40 +00:00
|
|
|
pa_log("XkbLibraryVersion() failed");
|
2004-08-02 16:24:14 +00:00
|
|
|
goto fail;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
major = XkbMajorVersion;
|
|
|
|
|
minor = XkbMinorVersion;
|
|
|
|
|
|
2006-04-22 21:51:30 +00:00
|
|
|
if (!XkbQueryExtension(pa_x11_wrapper_get_display(u->x11_wrapper), NULL, &u->xkb_event_base, NULL, &major, &minor)) {
|
2006-08-18 21:38:40 +00:00
|
|
|
pa_log("XkbQueryExtension() failed");
|
2004-08-02 16:24:14 +00:00
|
|
|
goto fail;
|
|
|
|
|
}
|
|
|
|
|
|
2006-04-22 21:51:30 +00:00
|
|
|
XkbSelectEvents(pa_x11_wrapper_get_display(u->x11_wrapper), XkbUseCoreKbd, XkbBellNotifyMask, XkbBellNotifyMask);
|
2004-08-02 16:24:14 +00:00
|
|
|
auto_ctrls = auto_values = XkbAudibleBellMask;
|
2006-04-22 21:51:30 +00:00
|
|
|
XkbSetAutoResetControls(pa_x11_wrapper_get_display(u->x11_wrapper), XkbAudibleBellMask, &auto_ctrls, &auto_values);
|
|
|
|
|
XkbChangeEnabledControls(pa_x11_wrapper_get_display(u->x11_wrapper), XkbUseCoreKbd, XkbAudibleBellMask, 0);
|
2004-08-02 16:24:14 +00:00
|
|
|
|
2004-10-30 01:55:16 +00:00
|
|
|
u->x11_client = pa_x11_client_new(u->x11_wrapper, x11_event_callback, u);
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2004-08-02 16:24:14 +00:00
|
|
|
pa_modargs_free(ma);
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2004-08-02 16:24:14 +00:00
|
|
|
return 0;
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2004-08-02 16:24:14 +00:00
|
|
|
fail:
|
|
|
|
|
if (ma)
|
|
|
|
|
pa_modargs_free(ma);
|
2007-10-28 19:13:50 +00:00
|
|
|
|
|
|
|
|
pa__done(m);
|
|
|
|
|
|
2004-08-02 16:24:14 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2007-10-28 19:13:50 +00:00
|
|
|
void pa__done(pa_module*m) {
|
|
|
|
|
struct userdata *u;
|
|
|
|
|
|
|
|
|
|
pa_assert(m);
|
|
|
|
|
|
|
|
|
|
if (!m->userdata)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
u = m->userdata;
|
2004-08-02 16:24:14 +00:00
|
|
|
|
2004-08-04 16:39:30 +00:00
|
|
|
pa_xfree(u->scache_item);
|
2004-08-15 00:02:26 +00:00
|
|
|
pa_xfree(u->sink_name);
|
2004-10-30 01:55:16 +00:00
|
|
|
|
|
|
|
|
if (u->x11_client)
|
|
|
|
|
pa_x11_client_free(u->x11_client);
|
|
|
|
|
|
|
|
|
|
if (u->x11_wrapper)
|
|
|
|
|
pa_x11_wrapper_unref(u->x11_wrapper);
|
|
|
|
|
|
2004-08-04 16:39:30 +00:00
|
|
|
pa_xfree(u);
|
2004-08-02 16:24:14 +00:00
|
|
|
}
|