]>
code.delx.au - pulseaudio/blob - polyp/module-x11-bell.c
23433c8f2bbaf3c558daa4869bff2989df41d846
4 This file is part of polypaudio.
6 polypaudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published
8 by the Free Software Foundation; either version 2 of the License,
9 or (at your option) any later version.
11 polypaudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with polypaudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
32 #include <X11/XKBlib.h>
42 #include "module-x11-bell-symdef.h"
44 PA_MODULE_AUTHOR("Lennart Poettering")
45 PA_MODULE_DESCRIPTION("X11 Bell interceptor")
46 PA_MODULE_VERSION(PACKAGE_VERSION
)
47 PA_MODULE_USAGE("sink=<sink to connect to> sample=<sample name> display=<X11 display>")
56 struct pa_x11_wrapper
*x11_wrapper
;
57 struct pa_x11_client
*x11_client
;
60 static const char* const valid_modargs
[] = {
67 static int ring_bell(struct userdata
*u
, int percent
) {
71 if (!(s
= pa_namereg_get(u
->core
, u
->sink_name
, PA_NAMEREG_SINK
, 1))) {
72 pa_log(__FILE__
": Invalid sink\n");
76 pa_scache_play_item(u
->core
, u
->scache_item
, s
, percent
*2);
80 static int x11_event_callback(struct pa_x11_wrapper
*w
, XEvent
*e
, void *userdata
) {
81 XkbBellNotifyEvent
*bne
;
82 struct userdata
*u
= userdata
;
83 assert(w
&& e
&& u
&& u
->x11_wrapper
== w
);
85 if (((XkbEvent
*) e
)->any
.xkb_type
!= XkbBellNotify
)
88 bne
= (XkbBellNotifyEvent
*) e
;
90 if (ring_bell(u
, bne
->percent
) < 0) {
91 pa_log(__FILE__
": Ringing bell failed, reverting to X11 device bell.\n");
92 XkbForceDeviceBell(pa_x11_wrapper_get_display(w
), bne
->device
, bne
->bell_class
, bne
->bell_id
, bne
->percent
);
98 int pa__init(struct pa_core
*c
, struct pa_module
*m
) {
99 struct userdata
*u
= NULL
;
100 struct pa_modargs
*ma
= NULL
;
102 unsigned int auto_ctrls
, auto_values
;
105 if (!(ma
= pa_modargs_new(m
->argument
, valid_modargs
))) {
106 pa_log(__FILE__
": failed to parse module arguments\n");
110 m
->userdata
= u
= pa_xmalloc(sizeof(struct userdata
));
112 u
->scache_item
= pa_xstrdup(pa_modargs_get_value(ma
, "sample", "x11-bell"));
113 u
->sink_name
= pa_xstrdup(pa_modargs_get_value(ma
, "sink", NULL
));
114 u
->x11_client
= NULL
;
116 if (!(u
->x11_wrapper
= pa_x11_wrapper_get(c
, pa_modargs_get_value(ma
, "display", NULL
))))
119 u
->display
= pa_x11_wrapper_get_display(u
->x11_wrapper
);
121 major
= XkbMajorVersion
;
122 minor
= XkbMinorVersion
;
124 if (!XkbLibraryVersion(&major
, &minor
)) {
125 pa_log(__FILE__
": XkbLibraryVersion() failed\n");
129 major
= XkbMajorVersion
;
130 minor
= XkbMinorVersion
;
133 if (!XkbQueryExtension(u
->display
, NULL
, &u
->xkb_event_base
, NULL
, &major
, &minor
)) {
134 pa_log(__FILE__
": XkbQueryExtension() failed\n");
138 XkbSelectEvents(u
->display
, XkbUseCoreKbd
, XkbBellNotifyMask
, XkbBellNotifyMask
);
139 auto_ctrls
= auto_values
= XkbAudibleBellMask
;
140 XkbSetAutoResetControls(u
->display
, XkbAudibleBellMask
, &auto_ctrls
, &auto_values
);
141 XkbChangeEnabledControls(u
->display
, XkbUseCoreKbd
, XkbAudibleBellMask
, 0);
143 u
->x11_client
= pa_x11_client_new(u
->x11_wrapper
, x11_event_callback
, u
);
157 void pa__done(struct pa_core
*c
, struct pa_module
*m
) {
158 struct userdata
*u
= m
->userdata
;
161 pa_xfree(u
->scache_item
);
162 pa_xfree(u
->sink_name
);
165 pa_x11_client_free(u
->x11_client
);
168 pa_x11_wrapper_unref(u
->x11_wrapper
);