#  Copyright (c) 1992-1994 The Regents of the University of California.
#  Copyright (c) 1994-1996 Sun Microsystems, Inc.
#  See the file "license.terms" for information on usage and redistribution
#  of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
#

=head1 NAME

Tk_CreateGenericHandler, Tk_DeleteGenericHandler - associate procedure callback with all X events

=for category C Programming

=head1 SYNOPSIS

B<#include E<lt>tk.hE<gt>>

B<Tk_CreateGenericHandler>(I<proc, clientData>)

B<Tk_DeleteGenericHandler>(I<proc, clientData>)

=head1 ARGUMENTS

=over 4

=item Tk_GenericProc *proc (in)

Procedure to invoke whenever any X event occurs on any display.

=item ClientData clientData (in)

Arbitrary one-word value to pass to I<proc>.

=back

=head1 DESCRIPTION

B<Tk_CreateGenericHandler> arranges for I<proc> to be
invoked in the future whenever any X event occurs.  This mechanism is
I<not> intended for dispatching X events on windows managed by Tk
(you should use B<Tk_CreateEventHandler> for this purpose).
B<Tk_CreateGenericHandler> is intended for other purposes, such
as tracing X events, monitoring events on windows not owned by Tk,
accessing X-related libraries that were not originally designed for
use with Tk, and so on.

The callback to I<proc> will be made by B<Tk_HandleEvent>;
this mechanism only works in programs that dispatch events
through B<Tk_HandleEvent> (or through other Tk procedures that
call B<Tk_HandleEvent>, such as B<Tk_DoOneEvent> or
B<Tk_MainLoop>).

I<Proc> should have arguments and result that match the
type B<Tk_GenericProc>:

 typedef int Tk_GenericProc(
 	ClientData clientData,
 	XEvent *eventPtr);

The I<clientData> parameter to I<proc> is a copy of the I<clientData>
argument given to B<Tk_CreateGenericHandler> when the callback
was created.  Typically, I<clientData> points to a data
structure containing application-specific information about
how to handle events.
I<EventPtr> is a pointer to the X event.

Whenever an X event is processed by B<Tk_HandleEvent>, I<proc>
is called.  The return value from I<proc> is normally 0.
A non-zero return value indicates that the event is not to be handled
further; that is, I<proc> has done all processing that is to be
allowed for the event.

If there are multiple generic event handlers, each one is called
for each event, in the order in which they were established.

B<Tk_DeleteGenericHandler> may be called to delete a
previously-created generic event handler:  it deletes each handler
it finds that matches the I<proc> and I<clientData> arguments.  If
no such handler exists, then B<Tk_DeleteGenericHandler> returns
without doing anything.  Although Tk supports it, it's probably
a bad idea to have more than one callback with the same
I<proc> and I<clientData> arguments.

Establishing a generic event handler does nothing to ensure that the
process will actually receive the X events that the handler wants to
process.
For example, it is the caller's responsibility to invoke
B<XSelectInput> to select the desired events, if that is necessary.

=head1 KEYWORDS

bind, callback, event, handler
