~ubuntu-branches/debian/lenny/italc/lenny

« back to all changes in this revision

Viewing changes to ica/x11/x11vnc/xkb_bell.c

  • Committer: Bazaar Package Importer
  • Author(s): Patrick Winnertz
  • Date: 2008-06-17 13:46:54 UTC
  • mto: This revision was merged to the branch mainline in revision 5.
  • Revision ID: james.westby@ubuntu.com-20080617134654-2y5m7ki93r5c1ysf
Tags: upstream-1.0.9~rc3
ImportĀ upstreamĀ versionĀ 1.0.9~rc3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -- xkb_bell.c -- */
 
2
 
 
3
#include "x11vnc.h"
 
4
#include "xwrappers.h"
 
5
#include "connections.h"
 
6
 
 
7
/*
 
8
 * Bell event handling.  Requires XKEYBOARD extension.
 
9
 */
 
10
int xkb_base_event_type = 0;
 
11
 
 
12
void initialize_xkb(void);
 
13
void initialize_watch_bell(void);
 
14
void check_bell_event(void);
 
15
 
 
16
 
 
17
#if LIBVNCSERVER_HAVE_XKEYBOARD
 
18
 
 
19
/*
 
20
 * check for XKEYBOARD, set up xkb_base_event_type
 
21
 */
 
22
void initialize_xkb(void) {
 
23
        int ir, reason;
 
24
        int op, ev, er, maj, min;
 
25
        
 
26
        RAWFB_RET_VOID
 
27
 
 
28
        if (xkbcompat) {
 
29
                xkb_present = 0;
 
30
        } else if (! XkbQueryExtension(dpy, &op, &ev, &er, &maj, &min)) {
 
31
                if (! quiet) {
 
32
                        rfbLog("warning: XKEYBOARD extension not present.\n");
 
33
                }
 
34
                xkb_present = 0;
 
35
        } else {
 
36
                xkb_present = 1;
 
37
        }
 
38
 
 
39
        if (! xkb_present) {
 
40
                return;
 
41
        }
 
42
 
 
43
        if (! xauth_raw(1)) {
 
44
                return;
 
45
        }
 
46
 
 
47
        if (! XkbOpenDisplay(DisplayString(dpy), &xkb_base_event_type, &ir,
 
48
            NULL, NULL, &reason) ) {
 
49
                if (! quiet) {
 
50
                        rfbLog("warning: disabling XKEYBOARD. XkbOpenDisplay"
 
51
                            " failed.\n");
 
52
                }
 
53
                xkb_base_event_type = 0;
 
54
                xkb_present = 0;
 
55
        }
 
56
        xauth_raw(0);
 
57
}
 
58
 
 
59
void initialize_watch_bell(void) {
 
60
        if (! xkb_present) {
 
61
                if (! quiet) {
 
62
                        rfbLog("warning: disabling bell. XKEYBOARD ext. "
 
63
                            "not present.\n");
 
64
                }
 
65
                watch_bell = 0;
 
66
                sound_bell = 0;
 
67
                return;
 
68
        }
 
69
 
 
70
        RAWFB_RET_VOID
 
71
 
 
72
        XkbSelectEvents(dpy, XkbUseCoreKbd, XkbBellNotifyMask, 0);
 
73
 
 
74
        if (! watch_bell) {
 
75
                return;
 
76
        }
 
77
        if (! XkbSelectEvents(dpy, XkbUseCoreKbd, XkbBellNotifyMask,
 
78
            XkbBellNotifyMask) ) {
 
79
                if (! quiet) {
 
80
                        rfbLog("warning: disabling bell. XkbSelectEvents"
 
81
                            " failed.\n");
 
82
                }
 
83
                watch_bell = 0;
 
84
                sound_bell = 0;
 
85
        }
 
86
}
 
87
 
 
88
/*
 
89
 * We call this periodically to process any bell events that have 
 
90
 * taken place.
 
91
 */
 
92
void check_bell_event(void) {
 
93
        XEvent xev;
 
94
        XkbAnyEvent *xkb_ev;
 
95
        int got_bell = 0;
 
96
 
 
97
        if (! xkb_base_event_type) {
 
98
                return;
 
99
        }
 
100
        RAWFB_RET_VOID
 
101
 
 
102
        /* caller does X_LOCK */
 
103
        if (! XCheckTypedEvent(dpy, xkb_base_event_type, &xev)) {
 
104
                return;
 
105
        }
 
106
        if (! watch_bell) {
 
107
                /* we return here to avoid xkb events piling up */
 
108
                return;
 
109
        }
 
110
 
 
111
        xkb_ev = (XkbAnyEvent *) &xev;
 
112
        if (xkb_ev->xkb_type == XkbBellNotify) {
 
113
                got_bell = 1;
 
114
        }
 
115
 
 
116
        if (got_bell && sound_bell) {
 
117
                if (! all_clients_initialized()) {
 
118
                        rfbLog("check_bell_event: not sending bell: "
 
119
                            "uninitialized clients\n");
 
120
                } else {
 
121
                        if (screen && client_count) {
 
122
                                rfbSendBell(screen);
 
123
                        }
 
124
                }
 
125
        }
 
126
}
 
127
#else
 
128
void initialize_watch_bell(void) {
 
129
        watch_bell = 0;
 
130
        sound_bell = 0;
 
131
}
 
132
void check_bell_event(void) {}
 
133
#endif
 
134
 
 
135