From 71f2ec79180185a6c3db0c87f9d53c491dc31e76 Mon Sep 17 00:00:00 2001 From: runge Date: Mon, 9 Jan 2006 01:54:38 +0000 Subject: x11vnc: the big split. --- x11vnc/xkb_bell.c | 125 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 x11vnc/xkb_bell.c (limited to 'x11vnc/xkb_bell.c') diff --git a/x11vnc/xkb_bell.c b/x11vnc/xkb_bell.c new file mode 100644 index 0000000..2476390 --- /dev/null +++ b/x11vnc/xkb_bell.c @@ -0,0 +1,125 @@ +/* -- xkb_bell.c -- */ + +#include "x11vnc.h" +#include "xwrappers.h" +#include "connections.h" + +/* + * Bell event handling. Requires XKEYBOARD extension. + */ +int xkb_base_event_type = 0; + +void initialize_xkb(void); +void initialize_watch_bell(void); +void check_bell_event(void); + + +#if LIBVNCSERVER_HAVE_XKEYBOARD + +/* + * check for XKEYBOARD, set up xkb_base_event_type + */ +void initialize_xkb(void) { + int ir, reason; + int op, ev, er, maj, min; + + if (xkbcompat) { + xkb_present = 0; + } else if (! XkbQueryExtension(dpy, &op, &ev, &er, &maj, &min)) { + if (! quiet) { + rfbLog("warning: XKEYBOARD extension not present.\n"); + } + xkb_present = 0; + } else { + xkb_present = 1; + } + + if (! xkb_present) { + return; + } + + if (! XkbOpenDisplay(DisplayString(dpy), &xkb_base_event_type, &ir, + NULL, NULL, &reason) ) { + if (! quiet) { + rfbLog("warning: disabling XKEYBOARD. XkbOpenDisplay" + " failed.\n"); + } + xkb_base_event_type = 0; + xkb_present = 0; + } +} + +void initialize_watch_bell(void) { + if (! xkb_present) { + if (! quiet) { + rfbLog("warning: disabling bell. XKEYBOARD ext. " + "not present.\n"); + } + watch_bell = 0; + sound_bell = 0; + return; + } + + XkbSelectEvents(dpy, XkbUseCoreKbd, XkbBellNotifyMask, 0); + + if (! watch_bell) { + return; + } + if (! XkbSelectEvents(dpy, XkbUseCoreKbd, XkbBellNotifyMask, + XkbBellNotifyMask) ) { + if (! quiet) { + rfbLog("warning: disabling bell. XkbSelectEvents" + " failed.\n"); + } + watch_bell = 0; + sound_bell = 0; + } +} + +/* + * We call this periodically to process any bell events that have + * taken place. + */ +void check_bell_event(void) { + XEvent xev; + XkbAnyEvent *xkb_ev; + int got_bell = 0; + + if (! xkb_base_event_type) { + return; + } + + /* caller does X_LOCK */ + if (! XCheckTypedEvent(dpy, xkb_base_event_type, &xev)) { + return; + } + if (! watch_bell) { + /* we return here to avoid xkb events piling up */ + return; + } + + xkb_ev = (XkbAnyEvent *) &xev; + if (xkb_ev->xkb_type == XkbBellNotify) { + got_bell = 1; + } + + if (got_bell && sound_bell) { + if (! all_clients_initialized()) { + rfbLog("check_bell_event: not sending bell: " + "uninitialized clients\n"); + } else { + if (screen && client_count) { + rfbSendBell(screen); + } + } + } +} +#else +void initialize_watch_bell(void) { + watch_bell = 0; + sound_bell = 0; +} +void check_bell_event(void) {} +#endif + + -- cgit v1.2.1