[ Previous | Next | Contents | Glossary | Home | Search ]
Motif 2.1 Programmer's Guide

Handling Input and Output

The X server communicates input to a client through input events associated with a window. In the simplest case, when a keyboard or pointer event occurs, the X server sends the event to the client that has expressed interest in events of that type on the window that contains the pointer. However, processing can be more complex. A client can grab a pointer button or key, the pointer or keyboard, or the entire server; the client then receives the relevant events. A client can set the input focus to some window, and the X server then reports events with respect to this window even if the pointer is outside this window.

To insulate applications from such complexities, Xt and Motif supply facilities for low-level processing of user input to an application:

  1. A VendorShell resource, XmNkeyboardFocusPolicy, allows the user or application to determine whether keyboard events go to the widget that contains the pointer or the widget in which the user presses Btn1 (a "click-to-type" policy).

  2. In the click-to-type model, the user can also use keys to navigate from widget to widget or from one group of widgets to another.

  3. Xt provides the basic event-dispatching loop used by most applications. Xt takes events out of the application's queue and dispatches them to the appropriate widget, usually the widget that has input focus. Xt usually invokes an action associated with the particular event through a table of translations from event specifications to action routines. The action, in turn, often invokes a callback list.

  4. Motif and Xt provide mnemonics and accelerators, which are shortcuts for taking actions associated with a widget when the widget does not have input focus. A mnemonic is a keysym for a key that activates a visible button in a menu. An accelerator is a description for an event that invokes an action routine through a translation.

    Most applications can use these high-level interfaces, allowing Xt and Motif to process user input at lower levels. If an application needs more control, it can also provide its own event handler, a routine invoked by the Xt dispatching loop when the widget receives events of the specified type. An application can also provide its own event-dispatching loop.

    Issues of input, focus, and keyboard navigation are discussed in more detail in Chapter 13.

    For most widgets, Xt and Motif handle low-level output processing as well. For example, in a Label or Text widget, when an application changes the text to be displayed, Motif automatically redisplays the contents of the widget. Most widgets have resources that control the appearance of the output, such as the fonts used to display text.

    Motif provides the DrawingArea widget for applications that need to produce graphic output or that need more control or flexibility in displaying text. DrawingArea is discussed in more detail in Chapter 15.

  5. [ Previous | Next | Contents | Glossary | Home | Search ]