evmux.icn: Procedures for window event multiplexor

link evmux
August 14, 1996; Gregg M. Townsend
Requires: Version 9 graphics
See also: button.icn, slider.icn
This file is in the public domain.

These procedures implement a simple event handling package.  This
package has more recently been superseded by the vidget library.

The event multiplexor is configured by registering *sensors*, which
respond to events that occur when the mouse cursor is within a
particular region.  When a sensor fires, it calls a user procedure
that was registered when the sensor was created.

These routines interpret window events and invoke callbacks:

        sensor()        registers the events of interest.

        evhandle()      reads and responds to the next event.

        evmux()         loops forever, handling events.

Two other small procedures help build event-driven programs:

        quitsensor()    registers a standardized response to Q or q.

        argless()       is a "glue" procedure usable as a callback.
____________________________________________________________

sensor(win, ev, proc, arg, x, y, w, h) -- register an event responder.

    registers *proc* as the procedure to be called when the event[s]
    *ev* occur within the given bounds inside window *win* and returns
    a handle.  The default bounds encompass the entire window.

    The event set *ev* can be either:
        -- a cset or string specifying particular keypresses of interest
        -- one of the event keywords (&lpress, &rdrag, &resize, etc.)

    When a matching event occurs, proc(win, arg, x, y, e) is called.  proc,
    win, and arg are as recorded from the sensor call.  x and y give the
    current mouse position and e the event; for a keypress, this is the
    character.

    No event generates more than one procedure call.
    In the case of conflicting entries, the later registrant wins.

    delsensor(win, x) deletes sensor x from the specified window.
    If x is null, all sensors are deleted.


evmux(win) -- loop forever, calling event handlers as appropriate.
evhandle(win) -- wait for the next event, and handle it.

    evmux(win) is an infinite loop that calls user routines in response
    to window events.  It is for programs that don't need to do other
    work while waiting for window input.

    evhandle(win) processes one event and then returns to its caller,
    allowing external loop control.  evhandle returns the outcome of
    the handler proc, or fails if there is no handler for the event.

quitsensor(win, wait) -- standardized "quit" sensor

    quitsensor() registers a sensor that calls exit() when either
    "q" or "Q" is typed in the window.

    If wait is non-null, quitsensor does not return but just waits for
    the signal (useful in non-interactive display programs).


argless(win, proc) -- call proc with no arguments.

    Useful for registering argless procedures as in quitsensor() above.

Source code | Program Library Page | Icon Home Page