2 * AT-SPI - Assistive Technology Service Provider Interface
3 * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
5 * Copyright 2001, 2002 Sun Microsystems Inc.,
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
27 #include <X11/Xutil.h>
28 #include <X11/XKBlib.h>
30 static Display *display;
31 static Window flash_window = None;
34 visual_bell_notify (XkbAnyEvent *xkb_ev)
38 root = RootWindow (display, DefaultScreen (display));
39 width = DisplayWidth (display, DefaultScreen (display));
40 height = DisplayHeight (display, DefaultScreen (display));
41 if (flash_window == None)
43 Visual *visual = CopyFromParent;
44 XVisualInfo info_return;
45 XSetWindowAttributes xswa;
46 int depth = CopyFromParent;
47 xswa.save_under = True;
48 xswa.override_redirect = True;
49 /* TODO: use XGetVisualInfo and determine which is an
50 overlay, if one is present. Not sure how to tell
52 if (XMatchVisualInfo (display,
53 DefaultScreen (display),
58 visual = info_return.visual;
62 fprintf (stderr, "could not create overlay visual, using default root visual type\n");
64 flash_window = XCreateWindow (display, root,
69 CWSaveUnder | CWOverrideRedirect,
71 XSelectInput (display, flash_window, ExposureMask);
72 XMapWindow (display, flash_window);
76 /* just draw something in the window */
77 GC gc = XCreateGC (display, flash_window, 0, NULL);
78 XMapWindow (display, flash_window);
79 XSetForeground (display, gc,
80 WhitePixel (display, DefaultScreen (display)));
81 XFillRectangle (display, flash_window, gc,
83 XSetForeground (display, gc,
84 BlackPixel (display, DefaultScreen (display)));
85 XFillRectangle (display, flash_window, gc,
91 int main (int argc, char **argv)
94 int ir, xkb_base_event_type, reason_return;
95 char *display_name = getenv ("DISPLAY");
97 if (!display_name) display_name = ":0.0";
99 display = XkbOpenDisplay (display_name,
100 &xkb_base_event_type,
101 &ir, NULL, NULL, &reason_return);
104 fprintf (stderr, "Could not connect to display! (%d)\n",
109 XkbSelectEvents (display,
114 /* comment this out to prevent bell on startup */
115 XkbBell (display, None, 100, None);
119 XNextEvent (display, &xev);
120 if (xev.type == Expose)
122 XExposeEvent *exev = (XExposeEvent *) &xev;
123 if (exev->window == flash_window)
125 XUnmapWindow (display, flash_window);
126 /* discard pending bells */
127 XSync (display, True);
131 else if (xev.type == xkb_base_event_type)
133 XkbAnyEvent *xkb_ev = (XkbAnyEvent *) &xev;
135 switch (xkb_ev->xkb_type)
138 /* flash something */
139 visual_bell_notify (xkb_ev);