XtSetKeyboardFocus()XtSetKeyboardFocus()NameXtSetKeyboardFocus - redirect keyboard input to a widget.
Synopsis
void XtSetKeyboardFocus(subtree descendant)
Widget subtree, descendant;
Inputs
subtree Specifies the widget to be considered the root of the subtree
for which the keyboard focus is to be set. Must be of class
Core or any subclass thereof.
descendant
Specifies a normal (non-popup) descendant of subtree to which
keyboard events are to be redirected, or None. May be of
class Object or any subclass thereof.
DescriptionXtSetKeyboardFocus() causes XtDispatchEvent() to remap keyboard events
that occur within the widget hierarchy rooted at subtree and to dis‐
patch them to descendant. If descendant is not a subclass of Core, it
is replaced by its closest windowed ancestor. If descendant is None,
keyboard events within subtree will be dispatched normally.
When subtree or one of its descendants acquires the X keyboard focus,
or the pointer moves into the subtree such that keyboard events would
now be delivered to subtree, a FocusIn event is generated for descen‐
dant if FocusChange events have been selected by descendant. Simi‐
larly, when subtree loses the X keyboard focus or the keyboard focus
for one of its ancestors, a FocusOut event is generated for descendant
if FocusChange events have been selected by descendant.
For more details on how events are dispatched after a call to XtSetKey‐
boardFocus(), see XtDispatchEvent().
UsageXtSetKeyboardFocus() does not call the Xlib function XSetInputFocus();
it simply causes the Intrinsics to dispatch events differently. For
most applications, this approach is preferred over the more heavy-
handed Xlib function.
Example
If a dialog box contains a Label widget, some Button widgets, and a
single Text widget for input, it is good style to allow the user to
enter text into the dialog when the mouse is anywhere over the dialog,
not only when the mouse is over the Text widget itself. This can be
arranged with code like the following:
Widget shell, box, text, prompt, ok_button, cancel_button;
XtPopup(shell, XtGrabExclusive);
XtSetKeyboardFocus(box, text);
After this call to XtSetKeyboardFocus(), whenever the dialog box gets
the X input focus (for example, when the mouse moves into it) all key‐
board events will be redirected at the text widget.
See AlsoXtAddGrab(1), XtDispatchEvent(1).
Xt - Keyboard Handling XtSetKeyboardFocus()