CH07.xml revision 9e7bcd65
1<chapter id='Event_Management'>
2<title>Event Management</title>
3<para>
4While Xlib allows the reading and processing of events anywhere in an application,
5widgets in the X Toolkit neither directly read events
6nor grab the server or pointer.
7Widgets register procedures that are to be called
8when an event or class of events occurs in that widget.
9</para>
10
11<para>
12A typical application consists of startup code followed by an event loop
13that reads events and dispatches them by calling
14the procedures that widgets have registered.
15The default event loop provided by the Intrinsics is
16<xref linkend='XtAppMainLoop' xrefstyle='select: title'/>.
17</para>
18
19<para>
20The event manager is a collection of functions to perform the following tasks:
21</para>
22<itemizedlist spacing='compact'>
23  <listitem>
24    <para>
25Add or remove event sources other than X server events (in particular,
26timer interrupts, file input, or POSIX signals).
27    </para>
28  </listitem>
29  <listitem>
30    <para>
31Query the status of event sources.
32    </para>
33  </listitem>
34  <listitem>
35    <para>
36Add or remove procedures to be called when an event occurs for a particular
37widget.
38    </para>
39  </listitem>
40  <listitem>
41    <para>
42Enable and
43disable the dispatching of user-initiated events (keyboard and pointer events)
44for a particular widget.
45    </para>
46  </listitem>
47  <listitem>
48    <para>
49Constrain the dispatching of events to a cascade of pop-up widgets.
50    </para>
51  </listitem>
52  <listitem>
53    <para>
54Register procedures to be called when specific events arrive.
55    </para>
56  </listitem>
57  <listitem>
58    <para>
59Register procedures to be called when the Intrinsics will block.
60    </para>
61  </listitem>
62  <listitem>
63    <para>
64Enable safe operation in a multi-threaded environment.
65    </para>
66  </listitem>
67</itemizedlist>
68<para>
69Most widgets do not need to call any of the event handler functions explicitly.
70The normal interface to X events is through the higher-level
71translation manager,
72which maps sequences of X events, with modifiers, into procedure calls.
73Applications rarely use any of the event manager routines besides
74<xref linkend='XtAppMainLoop' xrefstyle='select: title'/>.
75</para>
76<sect1 id="Adding_and_Deleting_Additional_Event_Sources">
77<title>Adding and Deleting Additional Event Sources</title>
78<para>
79While most applications are driven only by X events,
80some applications need to incorporate other sources of input
81into the Intrinsics event-handling mechanism.
82The event manager provides routines to integrate notification of timer events
83and file data pending into this mechanism.
84</para>
85
86<para>
87The next section describes functions that provide input gathering from files.
88The application registers the files with the Intrinsics read routine.
89When input is pending on one of the files,
90the registered callback procedures are invoked.
91</para>
92<sect2 id="Adding_and_Removing_Input_Sources">
93<title>Adding and Removing Input Sources</title>
94<para>
95To register a new file as an input source for a given application context, use
96<xref linkend='XtAppAddInput' xrefstyle='select: title'/>.
97</para>
98
99<funcsynopsis id='XtAppAddInput'>
100<funcprototype>
101<funcdef>XtInputId <function>XtAppAddInput</function></funcdef>
102   <paramdef>XtAppContext <parameter>app_context</parameter></paramdef>
103   <paramdef>int <parameter>source</parameter></paramdef>
104   <paramdef>XtPointer <parameter>condition</parameter></paramdef>
105   <paramdef>XtInputCallbackProc <parameter>proc</parameter></paramdef>
106   <paramdef>XtPointer <parameter>client_data</parameter></paramdef>
107</funcprototype>
108</funcsynopsis>
109
110<variablelist>
111  <varlistentry>
112    <term>
113      <emphasis remap='I'>app_context</emphasis>
114    </term>
115    <listitem>
116      <para>
117Specifies the application context that identifies the application.
118      </para>
119    </listitem>
120  </varlistentry>
121  <varlistentry>
122    <term>
123      <emphasis remap='I'>source</emphasis>
124    </term>
125    <listitem>
126      <para>
127Specifies the source file descriptor on a POSIX-based system
128or other operating-system-dependent device specification.
129      </para>
130    </listitem>
131  </varlistentry>
132  <varlistentry>
133    <term>
134      <emphasis remap='I'>condition</emphasis>
135    </term>
136    <listitem>
137      <para>
138Specifies the mask that indicates a read, write, or exception condition
139or some other operating-system-dependent condition.
140      </para>
141    </listitem>
142  </varlistentry>
143  <varlistentry>
144    <term>
145      <emphasis remap='I'>proc</emphasis>
146    </term>
147    <listitem>
148      <para>
149Specifies the procedure to be called when the condition is found.
150      </para>
151    </listitem>
152  </varlistentry>
153  <varlistentry>
154    <term>
155      <emphasis remap='I'>client_data</emphasis>
156    </term>
157    <listitem>
158      <para>
159Specifies an argument passed to the specified procedure
160when it is called.
161    </para>
162  </listitem>
163  </varlistentry>
164</variablelist>
165
166<para>
167The
168<xref linkend='XtAppAddInput' xrefstyle='select: title'/>
169function registers with the Intrinsics read routine a new source of events,
170which is usually file input but can also be file output.
171Note that <emphasis remap='I'>file</emphasis> should be loosely interpreted to mean any sink
172or source of data.
173<xref linkend='XtAppAddInput' xrefstyle='select: title'/>
174also specifies the conditions under which the source can generate events.
175When an event is pending on this source,
176the callback procedure is called.
177</para>
178
179<para>
180The legal values for the <emphasis remap='I'>condition</emphasis> argument are operating-system-dependent.
181On a POSIX-based system,
182<emphasis remap='I'>source</emphasis> is a file number and the condition is some union of the following:
183<variablelist>
184  <varlistentry>
185    <term>
186      <emphasis role='strong'>XtInputReadMask</emphasis>
187    </term>
188    <listitem>
189      <para>
190Specifies that <emphasis remap='I'>proc</emphasis> is to be called when <emphasis remap='I'>source</emphasis> has data to be read.
191      </para>
192    </listitem>
193  </varlistentry>
194  <varlistentry>
195    <term>
196      <emphasis role='strong'>XtInputWriteMask</emphasis>
197    </term>
198    <listitem>
199      <para>
200Specifies that <emphasis remap='I'>proc</emphasis> is to be called when <emphasis remap='I'>source</emphasis> is ready
201for writing.
202      </para>
203    </listitem>
204  </varlistentry>
205  <varlistentry>
206    <term>
207      <emphasis role='strong'>XtInputExceptMask</emphasis>
208    </term>
209    <listitem>
210      <para>
211Specifies that <emphasis remap='I'>proc</emphasis> is to be called when <emphasis remap='I'>source</emphasis> has
212exception data.
213    </para>
214  </listitem>
215  </varlistentry>
216</variablelist>
217</para>
218
219<para>
220Callback procedure pointers used to handle file events are of
221type
222<xref linkend='XtInputCallbackProc' xrefstyle='select: title'/>.
223</para>
224
225<funcsynopsis id='XtInputCallbackProc'>
226<funcprototype>
227<funcdef>typedef void <function>(*XtInputCallbackProc)</function></funcdef>
228   <paramdef>XtPointer <parameter>client_data</parameter></paramdef>
229   <paramdef>int *<parameter>source</parameter></paramdef>
230   <paramdef>XtInputId *<parameter>id</parameter></paramdef>
231</funcprototype>
232</funcsynopsis>
233
234<variablelist>
235  <varlistentry>
236    <term>
237      <emphasis remap='I'>client_data</emphasis>
238    </term>
239    <listitem>
240      <para>
241Passes the client data argument that was registered for this procedure in
242<function>XtApp\%AddInput</function>.
243      </para>
244    </listitem>
245  </varlistentry>
246  <varlistentry>
247    <term>
248      <emphasis remap='I'>source</emphasis>
249    </term>
250    <listitem>
251      <para>
252Passes the source file descriptor generating the event.
253      </para>
254    </listitem>
255  </varlistentry>
256  <varlistentry>
257    <term>
258      <emphasis remap='I'>id</emphasis>
259    </term>
260    <listitem>
261      <para>
262Passes the id returned from the corresponding
263<xref linkend='XtAppAddInput' xrefstyle='select: title'/>
264call.
265    </para>
266  </listitem>
267  </varlistentry>
268</variablelist>
269
270<para>
271See <xref linkend='Using_the_Intrinsics_in_a_Multi_Threaded_Environment' />
272for information regarding the use of
273<xref linkend='XtAppAddInput' xrefstyle='select: title'/>
274in multiple threads.
275</para>
276
277<para>
278To discontinue a source of input, use
279<xref linkend='XtRemoveInput' xrefstyle='select: title'/>.
280</para>
281
282<funcsynopsis id='XtRemoveInput'>
283<funcprototype>
284<funcdef>void <function>XtRemoveInput</function></funcdef>
285   <paramdef>XtInputId <parameter>id</parameter></paramdef>
286</funcprototype>
287</funcsynopsis>
288
289<variablelist>
290  <varlistentry>
291    <term>
292      <emphasis remap='I'>id</emphasis>
293    </term>
294    <listitem>
295      <para>
296Specifies the id returned from the corresponding
297<xref linkend='XtAppAddInput' xrefstyle='select: title'/>
298call.
299    </para>
300  </listitem>
301  </varlistentry>
302</variablelist>
303
304<para>
305The
306<xref linkend='XtRemoveInput' xrefstyle='select: title'/>
307function causes the Intrinsics read routine to stop watching for events
308from the file source specified by <emphasis remap='I'>id</emphasis>.
309</para>
310
311<para>
312See <xref linkend='Using_the_Intrinsics_in_a_Multi_Threaded_Environment' />
313for information regarding the use of
314<xref linkend='XtRemoveInput' xrefstyle='select: title'/>
315in multiple threads.
316</para>
317</sect2>
318
319<sect2 id="Adding_and_Removing_Blocking_Notifications">
320<title>Adding and Removing Blocking Notifications</title>
321<para>
322Occasionally it is desirable for an application to receive notification
323when the Intrinsics event manager detects no pending input from file sources
324and no pending input from X server event sources and is about to block
325in an operating system call.
326</para>
327
328<para>
329To register a hook that is called immediately prior to event blocking, use
330<xref linkend='XtAppAddBlockHook' xrefstyle='select: title'/>.
331</para>
332
333<funcsynopsis id='XtAppAddBlockHook'>
334<funcprototype>
335<funcdef>XtBlockHookId <function>XtAppAddBlockHook</function></funcdef>
336   <paramdef>XtAppContext <parameter>app_context</parameter></paramdef>
337   <paramdef>XtBlockHookProc <parameter>proc</parameter></paramdef>
338   <paramdef>XtPointer <parameter>client_data</parameter></paramdef>
339</funcprototype>
340</funcsynopsis>
341
342<variablelist>
343  <varlistentry>
344    <term>
345      <emphasis remap='I'>app_context</emphasis>
346    </term>
347    <listitem>
348      <para>
349Specifies the application context that identifies the application.
350      </para>
351    </listitem>
352  </varlistentry>
353  <varlistentry>
354    <term>
355      <emphasis remap='I'>proc</emphasis>
356    </term>
357    <listitem>
358      <para>
359Specifies the procedure to be called before blocking.
360      </para>
361    </listitem>
362  </varlistentry>
363  <varlistentry>
364    <term>
365      <emphasis remap='I'>client_data</emphasis>
366    </term>
367    <listitem>
368      <para>
369Specifies an argument passed to the specified procedure when it is called.
370    </para>
371  </listitem>
372  </varlistentry>
373</variablelist>
374
375<para>
376The
377<xref linkend='XtAppAddBlockHook' xrefstyle='select: title'/>
378function registers the specified procedure and returns an identifier for it.
379The hook procedure <emphasis remap='I'>proc</emphasis> is called at any time in the future when
380the Intrinsics are about to block pending some input.
381</para>
382
383<para>
384The procedure pointers used to provide notification of event blocking
385are of type
386<xref linkend='XtBlockHookProc' xrefstyle='select: title'/>.
387</para>
388
389<funcsynopsis id='XtBlockHookProc'>
390<funcprototype>
391<funcdef>void <function>*XtBlockHookProc</function></funcdef>
392   <paramdef>XtPointer <parameter>client_data</parameter></paramdef>
393</funcprototype>
394</funcsynopsis>
395
396<variablelist>
397  <varlistentry>
398    <term>
399      <emphasis remap='I'>client_data</emphasis>
400    </term>
401    <listitem>
402      <para>
403Passes the client data argument that was registered for this procedure in
404<function>XtApp\%AddBlockHook</function>.
405    </para>
406  </listitem>
407  </varlistentry>
408</variablelist>
409
410<para>
411To discontinue the use of a procedure for blocking notification, use
412<xref linkend='XtRemoveBlockHook' xrefstyle='select: title'/>.
413</para>
414
415<funcsynopsis id='XtRemoveBlockHook'>
416<funcprototype>
417<funcdef>void <function>XtRemoveBlockHook</function></funcdef>
418   <paramdef>XtBlockHookId <parameter>id</parameter></paramdef>
419</funcprototype>
420</funcsynopsis>
421
422<variablelist>
423  <varlistentry>
424    <term>
425      <emphasis remap='I'>id</emphasis>
426    </term>
427    <listitem>
428      <para>
429Specifies the identifier returned from the corresponding call to
430<xref linkend='XtAppAddBlockHook' xrefstyle='select: title'/>.
431    </para>
432  </listitem>
433  </varlistentry>
434</variablelist>
435
436<para>
437The
438<xref linkend='XtRemoveBlockHook' xrefstyle='select: title'/>
439function removes the specified procedure from the list of procedures
440that are called by the Intrinsics read routine before blocking on event sources.
441</para>
442</sect2>
443
444<sect2 id="Adding_and_Removing_Timeouts">
445<title>Adding and Removing Timeouts</title>
446<para>
447The timeout facility notifies the application or the widget
448through a callback procedure that a specified time interval has elapsed.
449Timeout values are uniquely identified by an interval id.
450</para>
451
452<para>
453To register a timeout callback, use
454<xref linkend='XtAppAddTimeOut' xrefstyle='select: title'/>.
455</para>
456
457<funcsynopsis id='XtAppAddTimeOut'>
458<funcprototype>
459<funcdef>XtIntervalId <function>XtAppAddTimeOut</function></funcdef>
460   <paramdef>XtAppContext <parameter>app_context</parameter></paramdef>
461   <paramdef>unsigned long <parameter>interval</parameter></paramdef>
462   <paramdef>XtTimerCallbackProc <parameter>proc</parameter></paramdef>
463   <paramdef>XtPointer <parameter>client_data</parameter></paramdef>
464</funcprototype>
465</funcsynopsis>
466
467<variablelist>
468  <varlistentry>
469    <term>
470      <emphasis remap='I'>app_context</emphasis>
471    </term>
472    <listitem>
473      <para>
474Specifies the application context for which the timer is to be set.
475      </para>
476    </listitem>
477  </varlistentry>
478  <varlistentry>
479    <term>
480      <emphasis remap='I'>interval</emphasis>
481    </term>
482    <listitem>
483      <para>
484Specifies the time interval in milliseconds.
485      </para>
486    </listitem>
487  </varlistentry>
488  <varlistentry>
489    <term>
490      <emphasis remap='I'>proc</emphasis>
491    </term>
492    <listitem>
493      <para>
494Specifies the procedure to be called when the time expires.
495      </para>
496    </listitem>
497  </varlistentry>
498  <varlistentry>
499    <term>
500      <emphasis remap='I'>client_data</emphasis>
501    </term>
502    <listitem>
503      <para>
504Specifies an argument passed to the specified procedure
505when it is called.
506    </para>
507  </listitem>
508  </varlistentry>
509</variablelist>
510
511<para>
512The
513<xref linkend='XtAppAddTimeOut' xrefstyle='select: title'/>
514function creates a timeout and returns an identifier for it.
515The timeout value is set to <emphasis remap='I'>interval</emphasis>.
516The callback procedure <emphasis remap='I'>proc</emphasis> is called when
517<xref linkend='XtAppNextEvent' xrefstyle='select: title'/>
518or
519<xref linkend='XtAppProcessEvent' xrefstyle='select: title'/>
520is next called after the time interval elapses,
521and then the timeout is removed.
522</para>
523
524<para>
525Callback procedure pointers used with timeouts are of
526type
527<xref linkend='XtTimerCallbackProc' xrefstyle='select: title'/>.
528</para>
529
530<funcsynopsis id='XtTimerCallbackProc'>
531<funcprototype>
532<funcdef>void <function>*XtTimerCallbackProc</function></funcdef>
533   <paramdef>XtPointer <parameter>client_data</parameter></paramdef>
534   <paramdef>XtIntervalId *<parameter>timer</parameter></paramdef>
535</funcprototype>
536</funcsynopsis>
537
538<variablelist>
539  <varlistentry>
540    <term>
541      <emphasis remap='I'>client_data</emphasis>
542    </term>
543    <listitem>
544      <para>
545Passes the client data argument that was registered for this procedure in
546<function>XtApp\%AddTimeOut</function>.
547      </para>
548    </listitem>
549  </varlistentry>
550  <varlistentry>
551    <term>
552      <emphasis remap='I'>timer</emphasis>
553    </term>
554    <listitem>
555      <para>
556Passes the id returned from the corresponding
557<xref linkend='XtAppAddTimeOut' xrefstyle='select: title'/>
558call.
559    </para>
560  </listitem>
561  </varlistentry>
562</variablelist>
563
564<para>
565See <xref linkend='Using_the_Intrinsics_in_a_Multi_Threaded_Environment' />
566for information regarding the use of
567<xref linkend='XtAppAddTimeOut' xrefstyle='select: title'/>
568in multiple threads.
569</para>
570
571<para>
572To clear a timeout value, use
573<xref linkend='XtRemoveTimeOut' xrefstyle='select: title'/>.
574</para>
575
576<funcsynopsis id='XtRemoveTimeOut'>
577<funcprototype>
578<funcdef>void <function>XtRemoveTimeOut</function></funcdef>
579   <paramdef>XtIntervalId <parameter>timer</parameter></paramdef>
580</funcprototype>
581</funcsynopsis>
582
583<variablelist>
584  <varlistentry>
585    <term>
586      <emphasis remap='I'>timer</emphasis>
587    </term>
588    <listitem>
589      <para>
590Specifies the id for the timeout request to be cleared.
591    </para>
592  </listitem>
593  </varlistentry>
594</variablelist>
595
596<para>
597The
598<xref linkend='XtRemoveTimeOut' xrefstyle='select: title'/>
599function removes the pending timeout.
600Note that timeouts are automatically removed once they trigger.
601</para>
602
603<para>
604Please refer to Section 7.12 for information regarding the use of
605<xref linkend='XtRemoveTimeOut' xrefstyle='select: title'/>
606in multiple threads.
607</para>
608</sect2>
609
610<sect2 id="Adding_and_Removing_Signal_Callbacks">
611<title>Adding and Removing Signal Callbacks</title>
612<para>
613The signal facility notifies the application or the widget through a
614callback procedure that a signal or other external asynchronous event
615has occurred.  The registered callback procedures are uniquely identified
616by a signal id.
617</para>
618
619<para>
620Prior to establishing a signal handler, the application or widget should
621call
622<xref linkend='XtAppAddSignal' xrefstyle='select: title'/>
623and store the resulting identifier in a place accessible to the signal
624handler.  When a signal arrives, the signal handler should call
625<xref linkend='XtNoticeSignal' xrefstyle='select: title'/>
626to notify the Intrinsics that a signal has occured.  To register a signal
627callback use
628<xref linkend='XtAppAddSignal' xrefstyle='select: title'/>.
629</para>
630
631<funcsynopsis id='XtAppAddSignal'>
632<funcprototype>
633<funcdef>XtSignalId <function>XtAppAddSignal</function></funcdef>
634   <paramdef>XtAppContext <parameter>app_context</parameter></paramdef>
635   <paramdef>XtSignalCallbackProc <parameter>proc</parameter></paramdef>
636   <paramdef>XtPointer <parameter>client_data</parameter></paramdef>
637</funcprototype>
638</funcsynopsis>
639
640<variablelist>
641  <varlistentry>
642    <term>
643      <emphasis remap='I'>app_context</emphasis>
644    </term>
645    <listitem>
646      <para>
647Specifies the application context that identifies the application.
648      </para>
649    </listitem>
650  </varlistentry>
651  <varlistentry>
652    <term>
653      <emphasis remap='I'>proc</emphasis>
654    </term>
655    <listitem>
656      <para>
657Specifies the procedure to be called when the signal is noticed.
658      </para>
659    </listitem>
660  </varlistentry>
661  <varlistentry>
662    <term>
663      <emphasis remap='I'>client_data</emphasis>
664    </term>
665    <listitem>
666      <para>
667Specifies an argument passed to the specified procedure when it is called.
668    </para>
669  </listitem>
670  </varlistentry>
671</variablelist>
672
673<para>
674The callback procedure pointers used to handle signal events are of type
675<xref linkend='XtSignalCallbackProc' xrefstyle='select: title'/>.
676</para>
677
678<funcsynopsis id='XtSignalCallbackProc'>
679<funcprototype>
680<funcdef>typedef void <function>(*XtSignalCallbackProc)</function></funcdef>
681   <paramdef>XtPointer <parameter>client_data</parameter></paramdef>
682   <paramdef>XtSignalId *<parameter>id</parameter></paramdef>
683</funcprototype>
684</funcsynopsis>
685
686<variablelist>
687  <varlistentry>
688    <term>
689      <emphasis remap='I'>client_data</emphasis>
690    </term>
691    <listitem>
692      <para>
693Passes the client data argument that was registered for this procedure in
694<xref linkend='XtAppAddSignal' xrefstyle='select: title'/>.
695      </para>
696    </listitem>
697  </varlistentry>
698  <varlistentry>
699    <term>
700      <emphasis remap='I'>id</emphasis>
701    </term>
702    <listitem>
703      <para>
704Passes the id returned from the corresponding
705<xref linkend='XtAppAddSignal' xrefstyle='select: title'/>
706call.
707    </para>
708  </listitem>
709  </varlistentry>
710</variablelist>
711
712<para>
713To notify the Intrinsics that a signal has occured, use
714<xref linkend='XtNoticeSignal' xrefstyle='select: title'/>.
715</para>
716
717<funcsynopsis id='XtNoticeSignal'>
718<funcprototype>
719<funcdef>void <function>XtNoticeSignal</function></funcdef>
720   <paramdef>XtSignalId <parameter>id</parameter></paramdef>
721</funcprototype>
722</funcsynopsis>
723
724<variablelist>
725  <varlistentry>
726    <term>
727      <emphasis remap='I'>id</emphasis>
728    </term>
729    <listitem>
730      <para>
731Specifies the id returned from the corresponding
732<xref linkend='XtAppAddSignal' xrefstyle='select: title'/>
733call.
734    </para>
735  </listitem>
736  </varlistentry>
737</variablelist>
738
739<para>
740On a POSIX-based system,
741<xref linkend='XtNoticeSignal' xrefstyle='select: title'/>
742is the only Intrinsics function that can safely be called from a signal handler.
743If
744<xref linkend='XtNoticeSignal' xrefstyle='select: title'/>
745is invoked multiple times before the Intrinsics are able to invoke the
746registered callback, the callback is only called once.
747Logically, the Intrinsics maintain ``pending'' flag for each registered callback.
748This flag is initially
749<function>False</function>
750and is set to
751<function>True</function>
752by
753<xref linkend='XtNoticeSignal' xrefstyle='select: title'/>.
754When
755<xref linkend='XtAppNextEvent' xrefstyle='select: title'/>
756or
757<xref linkend='XtAppProcessEvent' xrefstyle='select: title'/>
758(with a mask including
759<function>XtIMSignal</function>)
760is called, all registered callbacks with ``pending''
761<function>True</function>
762are invoked and the flags are reset to
763<function>False</function>.
764</para>
765
766<para>
767If the signal handler wants to track how many times the signal has been
768raised, it can keep its own private counter.  Typically the handler would
769not do any other work; the callback does the actual processing for the
770signal. The Intrinsics never block signals from being raised, so if a given
771signal can be raised multiple times before the Intrinsics can invoke the
772callback for that signal, the callback must be designed to deal with
773this.  In another case, a signal might be raised just after the Intrinsics
774sets the pending flag to
775<function>False</function>
776but before the callback can get control, in which case the pending flag
777will still be
778<function>True</function>
779after the callback returns, and the Intrinsics will invoke the callback
780again, even though all of the signal raises have been handled.  The
781callback must also be prepared to handle this case.
782</para>
783
784<para>
785To remove a registered signal callback, call
786<xref linkend='XtRemoveSignal' xrefstyle='select: title'/>.
787</para>
788
789<funcsynopsis id='XtRemoveSignal'>
790<funcprototype>
791<funcdef>void <function>XtRemoveSignal</function></funcdef>
792   <paramdef>XtSignalId <parameter>id</parameter></paramdef>
793</funcprototype>
794</funcsynopsis>
795
796<variablelist>
797  <varlistentry>
798    <term>
799      <emphasis remap='I'>id</emphasis>
800    </term>
801    <listitem>
802      <para>
803Specifies the id returned by the corresponding call to
804<xref linkend='XtAppAddSignal' xrefstyle='select: title'/>.
805    </para>
806  </listitem>
807  </varlistentry>
808</variablelist>
809
810<para>
811The client should typically disable the source of the signal before calling
812<xref linkend='XtRemoveSignal' xrefstyle='select: title'/>.
813If the signal could have been raised again before the source was disabled
814and the client wants to process it, then after disabling the source but
815before calling
816<xref linkend='XtRemoveSignal' xrefstyle='select: title'/>
817the client can test for signals with
818<xref linkend='XtAppPending' xrefstyle='select: title'/>
819and process them by calling
820<xref linkend='XtAppProcessEvent' xrefstyle='select: title'/>
821with the mask
822<function>XtIMSignal</function>.
823</para>
824</sect2>
825</sect1>
826
827<sect1 id="Constraining_Events_to_a_Cascade_of_Widgets">
828<title>Constraining Events to a Cascade of Widgets</title>
829<para>
830Modal widgets are widgets that, except for the input directed to them,
831lock out user input to the application.
832</para>
833
834<para>
835When a modal menu or modal dialog box is popped up using
836<xref linkend='XtPopup' xrefstyle='select: title'/>,
837user events (keyboard and pointer events) that occur outside the modal
838widget should be delivered to the modal widget or ignored.
839In no case will user events be delivered to a widget outside
840the modal widget.
841</para>
842
843<para>
844Menus can pop up submenus, and dialog boxes can pop up further dialog
845boxes to create a pop-up cascade.
846In this case,
847user events may be delivered to one of several modal widgets in the cascade.
848</para>
849
850<para>
851Display-related events should be delivered outside the modal cascade so that
852exposure events and the like keep the application's display up-to-date.
853Any event that occurs within the cascade is delivered as usual.
854The user events delivered to the most recent spring-loaded shell
855in the cascade when they occur outside the cascade are called remap events
856and are
857<function>KeyPress</function>,
858<function>KeyRelease</function>,
859<function>ButtonPress</function>,
860and
861<function>ButtonRelease</function>.
862The user events ignored when they occur outside the cascade are
863<function>MotionNotify</function>
864and
865<function>EnterNotify</function>.
866All other events are delivered normally.
867In particular, note that this is one
868way in which widgets can receive
869<function>LeaveNotify</function>
870events without first receiving
871<function>EnterNotify</function>
872events; they should be prepared to deal with
873this, typically by ignoring any unmatched
874<function>LeaveNotify</function>
875events.
876</para>
877
878<para>
879<xref linkend='XtPopup' xrefstyle='select: title'/>
880uses the
881<xref linkend='XtAddGrab' xrefstyle='select: title'/>
882and
883<xref linkend='XtRemoveGrab' xrefstyle='select: title'/>
884functions to constrain user events to a modal cascade
885and subsequently to remove a grab when the modal widget is popped down.
886</para>
887
888<para>
889To constrain or redirect user input to a modal widget, use
890<xref linkend='XtAddGrab' xrefstyle='select: title'/>.
891</para>
892
893<funcsynopsis id='XtAddGrab'>
894<funcprototype>
895<funcdef>void <function>XtAddGrab</function></funcdef>
896   <paramdef>Widget <parameter>w</parameter></paramdef>
897   <paramdef>Boolean <parameter>exclusive</parameter></paramdef>
898   <paramdef>Boolean <parameter>spring_loaded</parameter></paramdef>
899</funcprototype>
900</funcsynopsis>
901
902<variablelist>
903  <varlistentry>
904    <term>
905      <emphasis remap='I'>w</emphasis>
906    </term>
907    <listitem>
908      <para>
909Specifies the widget to add to the modal cascade. Must be of class Core or any subclass thereof.
910      </para>
911    </listitem>
912  </varlistentry>
913  <varlistentry>
914    <term>
915      <emphasis remap='I'>exclusive</emphasis>
916    </term>
917    <listitem>
918      <para>
919Specifies whether user events should be dispatched exclusively to this widget
920or also to previous widgets in the cascade.
921      </para>
922    </listitem>
923  </varlistentry>
924  <varlistentry>
925    <term>
926      <emphasis remap='I'>spring_loaded</emphasis>
927    </term>
928    <listitem>
929      <para>
930Specifies whether this widget was popped up because the user pressed
931a pointer button.
932    </para>
933  </listitem>
934  </varlistentry>
935</variablelist>
936
937<para>
938The
939<xref linkend='XtAddGrab' xrefstyle='select: title'/>
940function appends the widget to the modal cascade
941and checks that <emphasis remap='I'>exclusive</emphasis> is
942<function>True</function>
943if <emphasis remap='I'>spring_loaded</emphasis> is
944<function>True</function>.
945If this condition is not met,
946<xref linkend='XtAddGrab' xrefstyle='select: title'/>
947generates a warning message.
948</para>
949
950<para>
951The modal cascade is used by
952<xref linkend='XtDispatchEvent' xrefstyle='select: title'/>
953when it tries to dispatch a user event.
954When at least one modal widget is in the widget cascade,
955<xref linkend='XtDispatchEvent' xrefstyle='select: title'/>
956first determines if the event should be delivered.
957It starts at the most recent cascade entry and follows the cascade up to and
958including the most recent cascade entry added with the <emphasis remap='I'>exclusive</emphasis> parameter
959<function>True</function>.
960</para>
961
962<para>
963This subset of the modal cascade along with all descendants of these widgets
964comprise the active subset.
965User events that occur outside the widgets in this subset are ignored
966or remapped.
967Modal menus with submenus generally add a submenu widget to the cascade
968with <emphasis remap='I'>exclusive</emphasis>
969<function>False</function>.
970Modal dialog boxes that need to restrict user input to the most deeply nested
971dialog box add a subdialog widget to the cascade with <emphasis remap='I'>exclusive</emphasis>
972<function>True</function>.
973User events that occur within the active subset are delivered to the
974appropriate widget, which is usually a child or further descendant of the modal
975widget.
976</para>
977
978<para>
979Regardless of where in the application they occur,
980remap events are always delivered to the most recent widget in the active
981subset of the cascade registered with <emphasis remap='I'>spring_loaded</emphasis>
982<function>True</function>,
983if any such widget exists.
984If the event
985occurred in the active subset of the cascade but outside the
986spring-loaded widget, it is delivered normally before being
987delivered also to the spring-loaded widget.
988Regardless of where it is dispatched, the Intrinsics do not modify
989the contents of the event.
990</para>
991
992<para>
993To remove the redirection of user input to a modal widget, use
994<xref linkend='XtRemoveGrab' xrefstyle='select: title'/>.
995</para>
996
997<funcsynopsis id='XtRemoveGrab'>
998<funcprototype>
999<funcdef>void <function>XtRemoveGrab</function></funcdef>
1000   <paramdef>Widget <parameter>w</parameter></paramdef>
1001</funcprototype>
1002</funcsynopsis>
1003
1004<variablelist>
1005  <varlistentry>
1006    <term>
1007      <emphasis remap='I'>w</emphasis>
1008    </term>
1009    <listitem>
1010      <para>
1011Specifies the widget to remove from the modal cascade.
1012    </para>
1013  </listitem>
1014  </varlistentry>
1015</variablelist>
1016
1017<para>
1018The
1019<xref linkend='XtRemoveGrab' xrefstyle='select: title'/>
1020function removes widgets from the modal cascade starting
1021at the most recent widget up to and including the specified widget.
1022It issues a warning if the specified widget is not on the modal cascade.
1023</para>
1024<sect2 id="Requesting_Key_and_Button_Grabs">
1025<title>Requesting Key and Button Grabs</title>
1026<para>
1027The Intrinsics provide a set of key and button grab interfaces that
1028are parallel to those provided by Xlib and that allow the Intrinsics
1029to modify event dispatching when necessary.  X Toolkit applications and
1030widgets that need to passively grab keys or buttons or actively grab
1031the keyboard or pointer should use the
1032following Intrinsics routines rather than the corresponding Xlib
1033routines.
1034</para>
1035
1036<para>
1037To passively grab a single key of the keyboard, use
1038<xref linkend='XtGrabKey' xrefstyle='select: title'/>.
1039</para>
1040
1041<funcsynopsis id='XtGrabKey'>
1042<funcprototype>
1043<funcdef>void <function>XtGrabKey</function></funcdef>
1044   <paramdef>Widget <parameter>widget</parameter></paramdef>
1045   <paramdef>KeyCode <parameter>keycode</parameter></paramdef>
1046   <paramdef>Modifiers <parameter>modifiers</parameter></paramdef>
1047   <paramdef>Boolean <parameter>owner_events</parameter></paramdef>
1048   <paramdef>int <parameter>pointer_mode</parameter></paramdef>
1049</funcprototype>
1050</funcsynopsis>
1051
1052<variablelist>
1053  <varlistentry>
1054    <term>
1055      <emphasis remap='I'>widget</emphasis>
1056    </term>
1057    <listitem>
1058      <para>
1059Specifies the widget in whose window the key is to be grabbed.  Must be of class Core or any subclass thereof.
1060      </para>
1061    </listitem>
1062  </varlistentry>
1063  <varlistentry>
1064    <term>
1065      <emphasis remap='I'>keycode</emphasis>
1066    </term>
1067    <term>
1068      <emphasis remap='I'>modifiers</emphasis>
1069    </term>
1070    <term>
1071      <emphasis remap='I'>owner_events</emphasis>
1072    </term>
1073    <term>
1074      <emphasis remap='I'>pointer_mode</emphasis>
1075    </term>
1076    <term>
1077      <emphasis remap='I'>keyboard_mode</emphasis>
1078    </term>
1079    <listitem>
1080      <para>
1081Specify arguments to
1082<function>XGrabKey</function>;
1083see <olink targetdoc='libX11' targetptr='Keyboard_Grabbing'>Section 12.2</olink>
1084in <olink targetdoc='libX11' targetptr='libX11'>Xlib — C Language X Interface</olink>.
1085
1086    </para>
1087  </listitem>
1088  </varlistentry>
1089</variablelist>
1090
1091<para>
1092<xref linkend='XtGrabKey' xrefstyle='select: title'/>
1093calls
1094<function>XGrabKey</function>
1095specifying the widget's window as the grab
1096window if the widget is realized.  The remaining arguments are exactly
1097as for
1098<function>XGrabKey</function>.
1099If the widget is not realized, or is later unrealized, the call to
1100<function>XGrabKey</function>
1101is performed (again) when
1102the widget is realized and its window becomes mapped.  In the future,
1103if
1104<xref linkend='XtDispatchEvent' xrefstyle='select: title'/>
1105is called with a
1106<function>KeyPress</function>
1107event matching the specified keycode and modifiers (which may be
1108<function>AnyKey</function>
1109or
1110<function>AnyModifier</function>,
1111respectively) for the
1112widget's window, the Intrinsics will call
1113<xref linkend='XtUngrabKeyboard' xrefstyle='select: title'/>
1114with the timestamp from the
1115<function>KeyPress</function>
1116event if either of the following conditions is true:
1117</para>
1118<itemizedlist spacing='compact'>
1119  <listitem>
1120    <para>
1121There is a modal cascade and the widget is not in
1122the active subset of the cascade and the keyboard was not previously
1123grabbed, or
1124    </para>
1125  </listitem>
1126  <listitem>
1127    <para>
1128<function>XFilterEvent</function>
1129returns
1130<function>True</function>.
1131    </para>
1132  </listitem>
1133</itemizedlist>
1134<para>
1135To cancel a passive key grab, use
1136<xref linkend='XtUngrabKey' xrefstyle='select: title'/>.
1137</para>
1138
1139<funcsynopsis id='XtUngrabKey'>
1140<funcprototype>
1141<funcdef>void <function>XtUngrabKey</function></funcdef>
1142   <paramdef>Widget <parameter>widget</parameter></paramdef>
1143   <paramdef>KeyCode <parameter>keycode</parameter></paramdef>
1144   <paramdef>Modifiers <parameter>modifiers</parameter></paramdef>
1145</funcprototype>
1146</funcsynopsis>
1147
1148<variablelist>
1149  <varlistentry>
1150    <term>
1151      <emphasis remap='I'>widget</emphasis>
1152    </term>
1153    <listitem>
1154      <para>
1155Specifies the widget in whose window the key was grabbed.
1156      </para>
1157    </listitem>
1158  </varlistentry>
1159  <varlistentry>
1160    <term>
1161      <emphasis remap='I'>keycode</emphasis>
1162    </term>
1163    <term>
1164      <emphasis remap='I'>modifiers</emphasis>
1165    </term>
1166    <listitem>
1167      <para>
1168Specify arguments to
1169<function>XUngrabKey</function>;
1170see <olink targetdoc='libX11' targetptr='Keyboard_Grabbing'>Section 12.2</olink>
1171in <olink targetdoc='libX11' targetptr='libX11'>Xlib — C Language X Interface</olink>.
1172    </para>
1173  </listitem>
1174  </varlistentry>
1175</variablelist>
1176
1177<para>
1178The
1179<xref linkend='XtUngrabKey' xrefstyle='select: title'/>
1180procedure calls
1181<function>XUngrabKey</function>
1182specifying the widget's
1183window as the ungrab window if the widget is realized.  The remaining
1184arguments are exactly as for
1185<function>XUngrabKey</function>.
1186If the widget is not realized,
1187<xref linkend='XtUngrabKey' xrefstyle='select: title'/>
1188removes a deferred
1189<xref linkend='XtGrabKey' xrefstyle='select: title'/>
1190request, if any, for the specified widget, keycode, and modifiers.
1191</para>
1192
1193<para>
1194To actively grab the keyboard, use
1195<xref linkend='XtGrabKeyboard' xrefstyle='select: title'/>.
1196</para>
1197
1198<funcsynopsis id='XtGrabKeyboard'>
1199<funcprototype>
1200<funcdef>int <function>XtGrabKeyboard</function></funcdef>
1201   <paramdef>Widget <parameter>widget</parameter></paramdef>
1202   <paramdef>Boolean <parameter>owner_events</parameter></paramdef>
1203   <paramdef>int <parameter>pointer_mode</parameter></paramdef>
1204   <paramdef>Time <parameter>time</parameter></paramdef>
1205</funcprototype>
1206</funcsynopsis>
1207
1208<variablelist>
1209  <varlistentry>
1210    <term>
1211      <emphasis remap='I'>widget</emphasis>
1212    </term>
1213    <listitem>
1214      <para>
1215Specifies the widget for whose window the keyboard is to be grabbed.
1216Must be of class Core or any subclass thereof.
1217      </para>
1218    </listitem>
1219  </varlistentry>
1220  <varlistentry>
1221    <term>
1222      <emphasis remap='I'>owner_events</emphasis>
1223    </term>
1224    <term>
1225      <emphasis remap='I'>pointer_mode</emphasis>
1226    </term>
1227    <term>
1228      <emphasis remap='I'>keyboard_mode</emphasis>
1229    </term>
1230    <term>
1231      <emphasis remap='I'>time</emphasis>
1232    </term>
1233    <listitem>
1234      <para>
1235Specify arguments to
1236<function>XGrabKeyboard</function>;
1237see <olink targetdoc='libX11' targetptr='Keyboard_Grabbing'>Section 12.2</olink>
1238in <olink targetdoc='libX11' targetptr='libX11'>Xlib — C Language X Interface</olink>.
1239    </para>
1240  </listitem>
1241  </varlistentry>
1242</variablelist>
1243
1244<para>
1245If the specified widget is realized,
1246<xref linkend='XtGrabKeyboard' xrefstyle='select: title'/>
1247calls
1248<function>XGrabKeyboard</function>
1249specifying the widget's window as the grab window.  The remaining
1250arguments and return value are exactly as for
1251<function>XGrabKeyboard</function>.
1252If the widget is not realized,
1253<xref linkend='XtGrabKeyboard' xrefstyle='select: title'/>
1254immediately returns
1255<function>GrabNotViewable</function>.
1256No future automatic ungrab is implied by
1257<xref linkend='XtGrabKeyboard' xrefstyle='select: title'/>.
1258</para>
1259
1260<para>
1261To cancel an active keyboard grab, use
1262<xref linkend='XtUngrabKeyboard' xrefstyle='select: title'/>.
1263</para>
1264
1265<funcsynopsis id='XtUngrabKeyboard'>
1266<funcprototype>
1267<funcdef>void <function>XtUngrabKeyboard</function></funcdef>
1268   <paramdef>Widget <parameter>widget</parameter></paramdef>
1269   <paramdef>Time <parameter>time</parameter></paramdef>
1270</funcprototype>
1271</funcsynopsis>
1272
1273<variablelist>
1274  <varlistentry>
1275    <term>
1276      <emphasis remap='I'>widget</emphasis>
1277    </term>
1278    <listitem>
1279      <para>
1280Specifies the widget that has the active keyboard grab.
1281      </para>
1282    </listitem>
1283  </varlistentry>
1284  <varlistentry>
1285    <term>
1286      <emphasis remap='I'>time</emphasis>
1287    </term>
1288    <listitem>
1289      <para>
1290Specifies the additional argument to
1291<function>XUngrabKeyboard</function>;
1292see <olink targetdoc='libX11' targetptr='Keyboard_Grabbing'>Section 12.2</olink>
1293in <olink targetdoc='libX11' targetptr='libX11'>Xlib — C Language X Interface</olink>.
1294    </para>
1295  </listitem>
1296  </varlistentry>
1297</variablelist>
1298
1299<para>
1300<xref linkend='XtUngrabKeyboard' xrefstyle='select: title'/>
1301calls
1302<function>XUngrabKeyboard</function>
1303with the specified time.
1304</para>
1305
1306<para>
1307To passively grab a single pointer button, use
1308<xref linkend='XtGrabButton' xrefstyle='select: title'/>.
1309</para>
1310
1311<funcsynopsis id='XtGrabButton'>
1312<funcprototype>
1313<funcdef>void <function>XtGrabButton</function></funcdef>
1314   <paramdef>Widget <parameter>widget</parameter></paramdef>
1315   <paramdef>int <parameter>button</parameter></paramdef>
1316   <paramdef>Modifiers <parameter>modifiers</parameter></paramdef>
1317   <paramdef>Boolean <parameter>owner_events</parameter></paramdef>
1318   <paramdef>unsigned int <parameter>event_mask</parameter></paramdef>
1319   <paramdef>int <parameter>pointer_mode</parameter></paramdef>
1320   <paramdef>Window <parameter>confine_to</parameter></paramdef>
1321   <paramdef>Cursor <parameter>cursor</parameter></paramdef>
1322</funcprototype>
1323</funcsynopsis>
1324
1325<variablelist>
1326  <varlistentry>
1327    <term>
1328      <emphasis remap='I'>widget</emphasis>
1329    </term>
1330    <listitem>
1331      <para>
1332Specifies the widget in whose window the button is to be grabbed.  Must be of class Core or any subclass thereof.
1333      </para>
1334    </listitem>
1335  </varlistentry>
1336  <varlistentry>
1337    <term>
1338      <emphasis remap='I'>button</emphasis>
1339    </term>
1340    <term>
1341      <emphasis remap='I'>modifiers</emphasis>
1342    </term>
1343    <term>
1344      <emphasis remap='I'>owner_events</emphasis>
1345    </term>
1346    <term>
1347      <emphasis remap='I'>event_mask</emphasis>
1348    </term>
1349    <term>
1350      <emphasis remap='I'>pointer_mode</emphasis>
1351    </term>
1352    <term>
1353      <emphasis remap='I'>keyboard_mode</emphasis>
1354    </term>
1355    <term>
1356      <emphasis remap='I'>confine_to</emphasis>
1357    </term>
1358    <term>
1359      <emphasis remap='I'>cursor</emphasis>
1360    </term>
1361    <listitem>
1362      <para>
1363Specify arguments to
1364<function>XGrabButton</function>;
1365see <olink targetdoc='libX11' targetptr='Pointer_Grabbing'>Section 12.1</olink>
1366in <olink targetdoc='libX11' targetptr='libX11'>Xlib — C Language X Interface</olink>.
1367    </para>
1368  </listitem>
1369  </varlistentry>
1370</variablelist>
1371
1372<para>
1373<xref linkend='XtGrabButton' xrefstyle='select: title'/>
1374calls
1375<function>XGrabButton</function>
1376specifying the widget's window as the
1377grab window if the widget is realized.  The remaining arguments are
1378exactly as for
1379<function>XGrabButton</function>.
1380If the widget is not realized, or is later unrealized, the call to
1381<function>XGrabButton</function>
1382is performed (again)
1383when the widget is realized and its window becomes mapped.  In the
1384future, if
1385<xref linkend='XtDispatchEvent' xrefstyle='select: title'/>
1386is called with a
1387<function>ButtonPress</function>
1388event matching the specified button and modifiers (which may be
1389<function>AnyButton</function>
1390or
1391<function>AnyModifier</function>,
1392respectively)
1393for the widget's window, the Intrinsics will call
1394<xref linkend='XtUngrabPointer' xrefstyle='select: title'/>
1395with the timestamp from the
1396<function>ButtonPress</function>
1397event if either of the following conditions is true:
1398</para>
1399<itemizedlist spacing='compact'>
1400  <listitem>
1401    <para>
1402There is a modal cascade and the
1403widget is not in the active subset of the cascade and the pointer was
1404not previously grabbed, or
1405    </para>
1406  </listitem>
1407  <listitem>
1408    <para>
1409<function>XFilterEvent</function>
1410returns
1411<function>True</function>.
1412    </para>
1413  </listitem>
1414</itemizedlist>
1415<para>
1416To cancel a passive button grab, use
1417<xref linkend='XtUngrabButton' xrefstyle='select: title'/>.
1418</para>
1419
1420<funcsynopsis id='XtUngrabButton'>
1421<funcprototype>
1422<funcdef>void <function>XtUngrabButton</function></funcdef>
1423   <paramdef>Widget <parameter>widget</parameter></paramdef>
1424   <paramdef>unsigned int <parameter>button</parameter></paramdef>
1425   <paramdef>Modifiers <parameter>modifiers</parameter></paramdef>
1426</funcprototype>
1427</funcsynopsis>
1428
1429<variablelist>
1430  <varlistentry>
1431    <term>
1432      <emphasis remap='I'>widget</emphasis>
1433    </term>
1434    <listitem>
1435      <para>
1436Specifies the widget in whose window the button was grabbed.
1437      </para>
1438    </listitem>
1439  </varlistentry>
1440  <varlistentry>
1441    <term>
1442      <emphasis remap='I'>button</emphasis>
1443    </term>
1444    <term>
1445      <emphasis remap='I'>modifiers</emphasis>
1446    </term>
1447    <listitem>
1448      <para>
1449Specify arguments to
1450<function>XUngrabButton</function>;
1451see <olink targetdoc='libX11' targetptr='Pointer_Grabbing'>Section 12.1</olink>
1452in <olink targetdoc='libX11' targetptr='libX11'>Xlib — C Language X Interface</olink>.
1453    </para>
1454  </listitem>
1455  </varlistentry>
1456</variablelist>
1457
1458<para>
1459The
1460<xref linkend='XtUngrabButton' xrefstyle='select: title'/>
1461procedure calls
1462<function>XUngrabButton</function>
1463specifying the
1464widget's window as the ungrab window if the widget is realized.  The
1465remaining arguments are exactly as for
1466<function>XUngrabButton</function>.
1467If the widget is not realized,
1468<xref linkend='XtUngrabButton' xrefstyle='select: title'/>
1469removes a deferred
1470<xref linkend='XtGrabButton' xrefstyle='select: title'/>
1471request, if any, for the specified widget, button, and modifiers.
1472</para>
1473
1474<para>
1475To actively grab the pointer, use
1476<xref linkend='XtGrabPointer' xrefstyle='select: title'/>.
1477</para>
1478
1479<funcsynopsis id='XtGrabPointer'>
1480<funcprototype>
1481<funcdef>int <function>XtGrabPointer</function></funcdef>
1482   <paramdef>Widget <parameter>widget</parameter></paramdef>
1483   <paramdef>Boolean <parameter>owner_events</parameter></paramdef>
1484   <paramdef>unsigned int <parameter>event_mask</parameter></paramdef>
1485   <paramdef>int <parameter>pointer_mode</parameter></paramdef>
1486   <paramdef>Window <parameter>confine_to</parameter></paramdef>
1487   <paramdef>Cursor <parameter>cursor</parameter></paramdef>
1488   <paramdef>Time <parameter>time</parameter></paramdef>
1489</funcprototype>
1490</funcsynopsis>
1491
1492<variablelist>
1493  <varlistentry>
1494    <term>
1495      <emphasis remap='I'>widget</emphasis>
1496    </term>
1497    <listitem>
1498      <para>
1499Specifies the widget for whose window the pointer is to be grabbed.  Must be of class Core or any subclass thereof.
1500      </para>
1501    </listitem>
1502  </varlistentry>
1503  <varlistentry>
1504    <term>
1505      <emphasis remap='I'>owner_events</emphasis>
1506    </term>
1507    <term>
1508      <emphasis remap='I'>event_mask</emphasis>
1509    </term>
1510    <term>
1511      <emphasis remap='I'>pointer_mode</emphasis>
1512    </term>
1513    <term>
1514      <emphasis remap='I'>keyboard_mode</emphasis>
1515    </term>
1516    <term>
1517      <emphasis remap='I'>confine_to</emphasis>
1518    </term>
1519    <term>
1520      <emphasis remap='I'>cursor</emphasis>
1521    </term>
1522    <term>
1523      <emphasis remap='I'>time</emphasis>
1524    </term>
1525    <listitem>
1526      <para>
1527Specify arguments to
1528<function>XGrabPointer</function>;
1529see <olink targetdoc='libX11' targetptr='Pointer_Grabbing'>Section 12.1</olink>
1530in <olink targetdoc='libX11' targetptr='libX11'>Xlib — C Language X Interface</olink>.
1531    </para>
1532  </listitem>
1533  </varlistentry>
1534</variablelist>
1535
1536<para>
1537If the specified widget is realized,
1538<xref linkend='XtGrabPointer' xrefstyle='select: title'/>
1539calls
1540<function>XGrabPointer</function>,
1541specifying the widget's window as the grab window.  The remaining
1542arguments and return value are exactly as for
1543<function>XGrabPointer</function>.
1544If the widget is not realized,
1545<xref linkend='XtGrabPointer' xrefstyle='select: title'/>
1546immediately returns
1547<function>GrabNotViewable</function>.
1548No future automatic ungrab is implied by
1549<xref linkend='XtGrabPointer' xrefstyle='select: title'/>.
1550</para>
1551
1552<para>
1553To cancel an active pointer grab, use
1554<xref linkend='XtUngrabPointer' xrefstyle='select: title'/>.
1555</para>
1556
1557<funcsynopsis id='XtUngrabPointer'>
1558<funcprototype>
1559<funcdef>void <function>XtUngrabPointer</function></funcdef>
1560   <paramdef>Widget <parameter>widget</parameter></paramdef>
1561   <paramdef>Time <parameter>time</parameter></paramdef>
1562</funcprototype>
1563</funcsynopsis>
1564
1565<variablelist>
1566  <varlistentry>
1567    <term>
1568      <emphasis remap='I'>widget</emphasis>
1569    </term>
1570    <listitem>
1571      <para>
1572Specifies the widget that has the active pointer grab.
1573      </para>
1574    </listitem>
1575  </varlistentry>
1576  <varlistentry>
1577    <term>
1578      <emphasis remap='I'>time</emphasis>
1579    </term>
1580    <listitem>
1581      <para>
1582Specifies the time argument to
1583<function>XUngrabPointer</function>;
1584see <olink targetdoc='libX11' targetptr='Pointer_Grabbing'>Section 12.1</olink>
1585in <olink targetdoc='libX11' targetptr='libX11'>Xlib — C Language X Interface</olink>.
1586    </para>
1587  </listitem>
1588  </varlistentry>
1589</variablelist>
1590
1591<para>
1592<xref linkend='XtUngrabPointer' xrefstyle='select: title'/>
1593calls
1594<function>XUngrabPointer</function>
1595with the specified time.
1596</para>
1597</sect2>
1598</sect1>
1599
1600<sect1 id="Focusing_Events_on_a_Child">
1601<title>Focusing Events on a Child</title>
1602<para>
1603To redirect keyboard input to a normal descendant of a
1604widget without calling
1605<function>XSetInputFocus</function>,
1606use
1607<xref linkend='XtSetKeyboardFocus' xrefstyle='select: title'/>.
1608</para>
1609
1610<funcsynopsis id='XtSetKeyboardFocus'>
1611<funcprototype>
1612<funcdef>void <function>XtSetKeyboardFocus</function></funcdef>
1613   <paramdef>Widget <parameter>subtree</parameter></paramdef>
1614</funcprototype>
1615</funcsynopsis>
1616
1617<variablelist>
1618  <varlistentry>
1619    <term>
1620      <emphasis remap='I'>subtree</emphasis>
1621    </term>
1622    <listitem>
1623      <para>
1624Specifies the subtree of the hierarchy for which the keyboard focus is
1625to be set.  Must be of class Core or any subclass thereof.
1626      </para>
1627    </listitem>
1628  </varlistentry>
1629  <varlistentry>
1630    <term>
1631      <emphasis remap='I'>descendant</emphasis>
1632    </term>
1633    <listitem>
1634      <para>
1635Specifies either the normal (non-pop-up) descendant of <emphasis remap='I'>subtree</emphasis> to which
1636keyboard events are logically directed, or
1637<function>None</function>.
1638It is not an error to specify
1639<function>None</function>
1640when no input focus was previously set.  Must be of class Object or any subclass thereof.
1641    </para>
1642  </listitem>
1643  </varlistentry>
1644</variablelist>
1645
1646<para>
1647<xref linkend='XtSetKeyboardFocus' xrefstyle='select: title'/>
1648causes
1649<xref linkend='XtDispatchEvent' xrefstyle='select: title'/>
1650to remap keyboard events occurring within the specified subtree
1651and dispatch them to the specified descendant widget or to an ancestor.
1652If the descendant's class is not a subclass of Core, the descendant is
1653replaced by its closest windowed ancestor.
1654</para>
1655
1656<para>
1657When there is no modal cascade, keyboard events can be dispatched
1658to a widget in one of five ways.  Assume the server delivered the
1659event to the window for widget E (because of X input focus, key or
1660keyboard grabs, or pointer position).
1661</para>
1662<itemizedlist spacing='compact'>
1663  <listitem>
1664    <para>
1665If neither E nor any of E's ancestors have redirected the keyboard
1666focus, or if the event activated a grab for E as specified by a call
1667to
1668<xref linkend='XtGrabKey' xrefstyle='select: title'/>
1669with any value of <emphasis remap='I'>owner_events</emphasis>, or
1670if the keyboard is actively grabbed by E with <emphasis remap='I'>owner_events</emphasis>
1671<function>False</function>
1672via
1673<xref linkend='XtGrabKeyboard' xrefstyle='select: title'/>
1674or
1675<xref linkend='XtGrabKey' xrefstyle='select: title'/>
1676on a previous key press, the event is dispatched to E.
1677    </para>
1678  </listitem>
1679  <listitem>
1680    <para>
1681Beginning with the ancestor of E closest to the root that has
1682redirected the keyboard focus or E if no such ancestor exists, if
1683the target of that focus redirection has in turn redirected the
1684keyboard focus, recursively follow this focus chain to find a widget
1685F that has not redirected focus.
1686    </para>
1687  </listitem>
1688  <listitem>
1689    <itemizedlist spacing='compact'>
1690      <listitem>
1691        <para>
1692If E is the final focus target widget F or a descendant of F, the
1693event is dispatched to E.
1694        </para>
1695      </listitem>
1696      <listitem>
1697        <para>
1698If E is not F, an ancestor of F, or a descendant of F, and the event
1699activated a grab for E as specified by a call to
1700<xref linkend='XtGrabKey' xrefstyle='select: title'/>
1701for E,
1702<xref linkend='XtUngrabKeyboard' xrefstyle='select: title'/>
1703is called.
1704        </para>
1705      </listitem>
1706      <listitem>
1707        <para>
1708If E is an ancestor of F, and the event is a key press, and either
1709        </para>
1710      </listitem>
1711      <listitem>
1712        <itemizedlist spacing='compact'>
1713          <listitem>
1714            <para>
1715E has grabbed the key with
1716<xref linkend='XtGrabKey' xrefstyle='select: title'/>
1717and <emphasis remap='I'>owner_events</emphasis>
1718<function>False</function>,
1719or
1720            </para>
1721          </listitem>
1722          <listitem>
1723            <para>
1724E has grabbed the key with
1725<xref linkend='XtGrabKey' xrefstyle='select: title'/>
1726and <emphasis remap='I'>owner_events</emphasis>
1727<function>True</function>,
1728and the coordinates of the event are outside the rectangle specified
1729by E's geometry,
1730then the event is dispatched to E.
1731            </para>
1732          </listitem>
1733        </itemizedlist>
1734      </listitem>
1735      <listitem>
1736        <para>
1737Otherwise, define A as the closest common ancestor of E and F:
1738        </para>
1739      </listitem>
1740      <listitem>
1741        <itemizedlist spacing='compact'>
1742          <listitem>
1743            <para>
1744If there is an active keyboard grab for any widget via either
1745<xref linkend='XtGrabKeyboard' xrefstyle='select: title'/>
1746or
1747<xref linkend='XtGrabKey' xrefstyle='select: title'/>
1748on a previous key press, or
1749if no widget between F and A (noninclusive) has grabbed
1750the key and modifier combination with
1751<xref linkend='XtGrabKey' xrefstyle='select: title'/>
1752and any value of <emphasis remap='I'>owner_events</emphasis>, the event is dispatched to F.
1753            </para>
1754          </listitem>
1755          <listitem>
1756            <para>
1757Else, the event is dispatched to the ancestor of F closest to A
1758that has grabbed the key and modifier combination with
1759<xref linkend='XtGrabKey' xrefstyle='select: title'/>.
1760            </para>
1761          </listitem>
1762        </itemizedlist>
1763      </listitem>
1764    </itemizedlist>
1765  </listitem>
1766</itemizedlist>
1767<para>
1768When there is a modal cascade, if the final destination widget as
1769identified above is in the active subset of the cascade, the event is
1770dispatched; otherwise the event is remapped to a spring-loaded shell
1771or discarded.
1772Regardless of where it is dispatched, the Intrinsics do not modify
1773the contents of the event.
1774</para>
1775
1776<para>
1777When <emphasis remap='I'>subtree</emphasis> or one of its descendants acquires the X input focus
1778or the pointer moves into the subtree such that keyboard events would
1779now be delivered to the subtree, a
1780<function>FocusIn</function>
1781event is generated for the descendant if
1782<function>FocusChange</function>
1783events have been selected by the descendant.
1784Similarly, when <emphasis remap='I'>subtree</emphasis> loses the X input focus
1785or the keyboard focus for one of its ancestors, a
1786<function>FocusOut</function>
1787event is generated for descendant if
1788<function>FocusChange</function>
1789events have been selected by the descendant.
1790</para>
1791
1792<para>
1793A widget tree may also actively manage the X server input focus.  To
1794do so, a widget class specifies an accept_focus procedure.
1795</para>
1796
1797<para>
1798The accept_focus procedure pointer is of type
1799<xref linkend='XtAcceptFocusProc' xrefstyle='select: title'/>.
1800</para>
1801
1802<funcsynopsis id='XtAcceptFocusProc'>
1803<funcprototype>
1804<funcdef>Boolean <function>*XtAcceptFocusProc</function></funcdef>
1805
1806   <paramdef>Widget <parameter>w</parameter></paramdef>
1807   <paramdef>Time *<parameter>time</parameter></paramdef>
1808</funcprototype>
1809</funcsynopsis>
1810
1811<variablelist>
1812  <varlistentry>
1813    <term>
1814      <emphasis remap='I'>w</emphasis>
1815    </term>
1816    <listitem>
1817      <para>
1818Specifies the widget.
1819      </para>
1820    </listitem>
1821  </varlistentry>
1822  <varlistentry>
1823    <term>
1824      <emphasis remap='I'>time</emphasis>
1825    </term>
1826    <listitem>
1827      <para>
1828Specifies the X time of the event causing the accept focus.
1829    </para>
1830  </listitem>
1831  </varlistentry>
1832</variablelist>
1833
1834<para>
1835Widgets that need the input focus can call
1836<function>XSetInputFocus</function>
1837explicitly, pursuant to the restrictions of the <emphasis remap='I'>Inter-Client Communication Conventions Manual.</emphasis>.
1838To allow outside agents, such as the parent,
1839to cause a widget to take the input focus,
1840every widget exports an accept_focus procedure.
1841The widget returns a value indicating
1842whether it actually took the focus or not,
1843so that the parent can give the focus to another widget.
1844Widgets that need to know when they lose the input focus must use
1845the Xlib focus notification mechanism explicitly
1846(typically by specifying translations for
1847<function>FocusIn</function>
1848and
1849<function>FocusOut</function>
1850events).
1851Widgets classes that never want the input focus should set the
1852<emphasis remap='I'>accept_focus</emphasis> field to NULL.
1853</para>
1854
1855<para>
1856To call a widget's accept_focus procedure, use
1857<xref linkend='XtCallAcceptFocus' xrefstyle='select: title'/>.
1858</para>
1859
1860<funcsynopsis id='XtCallAcceptFocus'>
1861<funcprototype>
1862<funcdef>Boolean <function>XtCallAcceptFocus</function></funcdef>
1863   <paramdef>Widget <parameter>w</parameter></paramdef>
1864   <paramdef>Time *<parameter>time</parameter></paramdef>
1865</funcprototype>
1866</funcsynopsis>
1867
1868<variablelist>
1869  <varlistentry>
1870    <term>
1871      <emphasis remap='I'>w</emphasis>
1872    </term>
1873    <listitem>
1874      <para>
1875Specifies the widget.  Must be of class Core or any subclass thereof.
1876      </para>
1877    </listitem>
1878  </varlistentry>
1879  <varlistentry>
1880    <term>
1881      <emphasis remap='I'>time</emphasis>
1882    </term>
1883    <listitem>
1884      <para>
1885Specifies the X time of the event that is causing the focus change.
1886    </para>
1887  </listitem>
1888  </varlistentry>
1889</variablelist>
1890
1891<para>
1892The
1893<xref linkend='XtCallAcceptFocus' xrefstyle='select: title'/>
1894function calls the specified widget's accept_focus procedure,
1895passing it the specified widget and time, and returns what the accept_focus
1896procedure returns.
1897If <emphasis remap='I'>accept_focus</emphasis> is NULL,
1898<xref linkend='XtCallAcceptFocus' xrefstyle='select: title'/>
1899returns
1900<function>False</function>.
1901</para>
1902<sect2 id="Events_for_Drawables_That_Are_Not_a_Widget_s_Window">
1903<title>Events for Drawables That Are Not a Widget's Window</title>
1904<para>
1905Sometimes an application must handle events for drawables that are not
1906associated with widgets in its widget tree.  Examples include handling
1907<function>GraphicsExpose</function>
1908and
1909<function>NoExpose</function>
1910events on Pixmaps, and handling
1911<function>PropertyNotify</function>
1912events on the root window.
1913</para>
1914
1915<para>
1916To register a drawable with the Intrinsics event dispatching, use
1917<xref linkend='XtRegisterDrawable' xrefstyle='select: title'/>.
1918</para>
1919
1920<funcsynopsis id='XtRegisterDrawable'>
1921<funcprototype>
1922<funcdef>void <function>XtRegisterDrawable</function></funcdef>
1923   <paramdef>Display *<parameter>display</parameter></paramdef>
1924   <paramdef>Drawable <parameter>drawable</parameter></paramdef>
1925   <paramdef>Widget <parameter>widget</parameter></paramdef>
1926</funcprototype>
1927</funcsynopsis>
1928
1929<variablelist>
1930  <varlistentry>
1931    <term>
1932      <emphasis remap='I'>display</emphasis>
1933    </term>
1934    <listitem>
1935      <para>
1936Specifies the drawable's display.
1937      </para>
1938    </listitem>
1939  </varlistentry>
1940  <varlistentry>
1941    <term>
1942      <emphasis remap='I'>drawable</emphasis>
1943    </term>
1944    <listitem>
1945      <para>
1946Specifies the drawable to register.
1947      </para>
1948    </listitem>
1949  </varlistentry>
1950  <varlistentry>
1951    <term>
1952      <emphasis remap='I'>widget</emphasis>
1953    </term>
1954    <listitem>
1955      <para>
1956Specifies the widget to register the drawable for.
1957    </para>
1958  </listitem>
1959  </varlistentry>
1960</variablelist>
1961
1962<para>
1963<xref linkend='XtRegisterDrawable' xrefstyle='select: title'/>
1964associates the specified drawable with the specified widget
1965so that future calls to
1966<xref linkend='XtWindowToWidget' xrefstyle='select: title'/>
1967with the drawable will return the widget.
1968The default event dispatcher will dispatch future events that
1969arrive for the drawable to the widget in the same manner as
1970events that contain the widget's window.
1971</para>
1972
1973<para>
1974If the drawable is already registered with another widget, or if the
1975drawable is the window of a widget in the client's widget tree, the
1976results of calling
1977<xref linkend='XtRegisterDrawable' xrefstyle='select: title'/>
1978are undefined.
1979</para>
1980
1981<para>
1982To unregister a drawable with the Intrinsics event dispatching, use
1983<xref linkend='XtUnregisterDrawable' xrefstyle='select: title'/>.
1984</para>
1985
1986<funcsynopsis id='XtUnregisterDrawable'>
1987<funcprototype>
1988<funcdef>void <function>XtUnregisterDrawable</function></funcdef>
1989   <paramdef>Display *<parameter>display</parameter></paramdef>
1990   <paramdef>Drawable <parameter>drawable</parameter></paramdef>
1991</funcprototype>
1992</funcsynopsis>
1993
1994<variablelist>
1995  <varlistentry>
1996    <term>
1997      <emphasis remap='I'>display</emphasis>
1998    </term>
1999    <listitem>
2000      <para>
2001Specifies the drawable's display.
2002      </para>
2003    </listitem>
2004  </varlistentry>
2005  <varlistentry>
2006    <term>
2007      <emphasis remap='I'>drawable</emphasis>
2008    </term>
2009    <listitem>
2010      <para>
2011Specifies the drawable to unregister.
2012    </para>
2013  </listitem>
2014  </varlistentry>
2015</variablelist>
2016
2017<para>
2018<xref linkend='XtUnregisterDrawable' xrefstyle='select: title'/>
2019removes an association created with
2020<xref linkend='XtRegisterDrawable' xrefstyle='select: title'/>.
2021If the drawable is the window of a widget in the client's widget tree
2022the results of calling
2023<xref linkend='XtUnregisterDrawable' xrefstyle='select: title'/>
2024are undefined.
2025</para>
2026</sect2>
2027</sect1>
2028
2029<sect1 id="Querying_Event_Sources">
2030<title>Querying Event Sources</title>
2031<para>
2032The event manager provides several functions to examine and read events
2033(including file and timer events) that are in the queue.
2034The next three functions are Intrinsics equivalents of the
2035<function>XPending</function>,
2036<function>XPeekEvent</function>,
2037and
2038<function>XNextEvent</function>
2039Xlib calls.
2040</para>
2041
2042<para>
2043To determine if there are any events on the input queue for a given application,
2044use
2045<xref linkend='XtAppPending' xrefstyle='select: title'/>.
2046</para>
2047
2048<funcsynopsis id='XtAppPending'>
2049<funcprototype>
2050<funcdef>XtInputMask <function>XtAppPending</function></funcdef>
2051   <paramdef>XtAppContext <parameter>app_context</parameter></paramdef>
2052</funcprototype>
2053</funcsynopsis>
2054
2055<variablelist>
2056  <varlistentry>
2057    <term>
2058      <emphasis remap='I'>app_context</emphasis>
2059    </term>
2060    <listitem>
2061      <para>
2062Specifies the application context that identifies the application to check.
2063    </para>
2064  </listitem>
2065  </varlistentry>
2066</variablelist>
2067
2068<para>
2069The
2070<xref linkend='XtAppPending' xrefstyle='select: title'/>
2071function returns a nonzero value if there are
2072events pending from the X server, timer pending, other input sources
2073pending, or signal sources pending.  The
2074value returned is a bit mask that is the OR of
2075<function>XtIMXEvent</function>,
2076<function>XtIMTimer</function>,
2077<function>XtIMAlternateInput</function>,
2078and
2079<function>XtIMSignal</function>
2080(see
2081<function>XtAppProcessEvent ).</function>
2082If there are no events pending,
2083<xref linkend='XtAppPending' xrefstyle='select: title'/>
2084flushes the output buffers of each Display in the application context
2085and returns zero.
2086</para>
2087
2088<para>
2089To return the event from the head of a given application's input queue
2090without removing input from the queue, use
2091<xref linkend='XtAppPeekEvent' xrefstyle='select: title'/>.
2092</para>
2093
2094<funcsynopsis id='XtAppPeekEvent'>
2095<funcprototype>
2096<funcdef>Boolean <function>XtAppPeekEvent</function></funcdef>
2097   <paramdef>XtAppContext <parameter>app_context</parameter></paramdef>
2098   <paramdef>XEvent *<parameter>event_return</parameter></paramdef>
2099</funcprototype>
2100</funcsynopsis>
2101
2102<variablelist>
2103  <varlistentry>
2104    <term>
2105      <emphasis remap='I'>app_context</emphasis>
2106    </term>
2107    <listitem>
2108      <para>
2109Specifies the application context that identifies the application.
2110      </para>
2111    </listitem>
2112  </varlistentry>
2113  <varlistentry>
2114    <term>
2115      <emphasis remap='I'>event_return</emphasis>
2116    </term>
2117    <listitem>
2118      <para>
2119Returns the event information to the specified event structure.
2120    </para>
2121  </listitem>
2122  </varlistentry>
2123</variablelist>
2124
2125<para>
2126If there is an X event in the queue,
2127<xref linkend='XtAppPeekEvent' xrefstyle='select: title'/>
2128copies it into <emphasis remap='I'>event_return</emphasis> and returns
2129<function>True</function>.
2130If no X input is on the queue,
2131<xref linkend='XtAppPeekEvent' xrefstyle='select: title'/>
2132flushes the output buffers of each Display in the application context
2133and blocks until some input is available
2134(possibly calling some timeout callbacks in the interim).
2135If the next available input is an X event,
2136<xref linkend='XtAppPeekEvent' xrefstyle='select: title'/>
2137fills in <emphasis remap='I'>event_return</emphasis> and returns
2138<function>True</function>.
2139Otherwise, the input is for an input source
2140registered with
2141<xref linkend='XtAppAddInput' xrefstyle='select: title'/>,
2142and
2143<xref linkend='XtAppPeekEvent' xrefstyle='select: title'/>
2144returns
2145<function>False</function>.
2146The sample implementations provides XtAppPeekEvent as described.  Timeout callbacks
2147are called while blocking for input.  If some input for an input source is
2148available,
2149<xref linkend='XtAppPeekEvent' xrefstyle='select: title'/>
2150will return
2151<function>True</function>
2152without returning an event.
2153</para>
2154
2155<para>
2156To remove and return the event
2157from the head of a given application's X event queue,
2158use
2159<xref linkend='XtAppNextEvent' xrefstyle='select: title'/>.
2160</para>
2161
2162<funcsynopsis id='XtAppNextEvent'>
2163<funcprototype>
2164<funcdef>void <function>XtAppNextEvent</function></funcdef>
2165   <paramdef>XtAppContext <parameter>app_context</parameter></paramdef>
2166   <paramdef>XEvent *<parameter>event_return</parameter></paramdef>
2167</funcprototype>
2168</funcsynopsis>
2169
2170<variablelist>
2171  <varlistentry>
2172    <term>
2173      <emphasis remap='I'>app_context</emphasis>
2174    </term>
2175    <listitem>
2176      <para>
2177Specifies the application context that identifies the application.
2178      </para>
2179    </listitem>
2180  </varlistentry>
2181  <varlistentry>
2182    <term>
2183      <emphasis remap='I'>event_return</emphasis>
2184    </term>
2185    <listitem>
2186      <para>
2187Returns the event information to the specified event structure.
2188    </para>
2189  </listitem>
2190  </varlistentry>
2191</variablelist>
2192
2193<para>
2194If the X event queue is empty,
2195<xref linkend='XtAppNextEvent' xrefstyle='select: title'/>
2196flushes the X output buffers of each Display in the application context
2197and waits for an X event while looking at the other input sources
2198and timeout values and calling any callback procedures triggered by them.
2199This wait time can be used for background processing;
2200see <xref linkend='Adding_Background_Work_Procedures' />.
2201</para>
2202</sect1>
2203
2204<sect1 id="Dispatching_Events">
2205<title>Dispatching Events</title>
2206<para>
2207The Intrinsics provide functions that dispatch events
2208to widgets or other application code.
2209Every client interested in X events on a widget uses
2210<xref linkend='XtAddEventHandler' xrefstyle='select: title'/>
2211to register which events it is
2212interested in and a procedure (event handler) to be called
2213when the event happens in that window.
2214The translation manager automatically registers event handlers for widgets
2215that use translation tables; see <xref linkend='Translation_Management' />.
2216</para>
2217
2218<para>
2219Applications that need direct control of the processing of different types
2220of input should use
2221<xref linkend='XtAppProcessEvent' xrefstyle='select: title'/>.
2222</para>
2223
2224<funcsynopsis id='XtAppProcessEvent'>
2225<funcprototype>
2226<funcdef>void <function>XtAppProcessEvent</function></funcdef>
2227   <paramdef>XtAppContext <parameter>app_context</parameter></paramdef>
2228   <paramdef>XtInputMask <parameter>mask</parameter></paramdef>
2229</funcprototype>
2230</funcsynopsis>
2231
2232<variablelist>
2233  <varlistentry>
2234    <term>
2235      <emphasis remap='I'>app_context</emphasis>
2236    </term>
2237    <listitem>
2238      <para>
2239Specifies the application context that identifies the
2240application for which to process input.
2241      </para>
2242    </listitem>
2243  </varlistentry>
2244  <varlistentry>
2245    <term>
2246      <emphasis remap='I'>mask</emphasis>
2247    </term>
2248    <listitem>
2249      <para>
2250Specifies what types of events to process.
2251The mask is the bitwise inclusive OR of any combination of
2252<function>XtIMXEvent</function>,
2253<function>XtIMTimer</function>,
2254<function>XtIMAlternateInput</function>,
2255and
2256<function>XtIMSignal</function>.
2257As a convenience,
2258<function>Intrinsic.h</function>
2259defines the symbolic name
2260<function>XtIMAll</function>
2261to be the bitwise inclusive OR of these four event types.
2262    </para>
2263  </listitem>
2264  </varlistentry>
2265</variablelist>
2266
2267<para>
2268The
2269<xref linkend='XtAppProcessEvent' xrefstyle='select: title'/>
2270function processes one timer, input source, signal source, or X event.
2271If there is no event or input of the appropriate type to process, then
2272<xref linkend='XtAppProcessEvent' xrefstyle='select: title'/>
2273blocks until there is.
2274If there is more than one type of input available to process,
2275it is undefined which will get processed.
2276Usually, this procedure is not called by client applications; see
2277<xref linkend='XtAppMainLoop' xrefstyle='select: title'/>.
2278<xref linkend='XtAppProcessEvent' xrefstyle='select: title'/>
2279processes timer events by calling any appropriate timer callbacks,
2280input sources by calling any appropriate input callbacks,
2281signal source by calling any appropriate signal callbacks,
2282and X events by
2283calling
2284<xref linkend='XtDispatchEvent' xrefstyle='select: title'/>.
2285</para>
2286
2287<para>
2288When an X event is received,
2289it is passed to
2290<xref linkend='XtDispatchEvent' xrefstyle='select: title'/>,
2291which calls the appropriate event handlers
2292and passes them the widget, the event, and client-specific data
2293registered with each procedure.
2294If no handlers for that event are registered,
2295the event is ignored and the dispatcher simply returns.
2296</para>
2297
2298<para>
2299To dispatch an event returned by
2300<xref linkend='XtAppNextEvent' xrefstyle='select: title'/>,
2301retrieved directly from the Xlib queue, or synthetically constructed,
2302to any registered event filters or event handlers, call
2303<xref linkend='XtDispatchEvent' xrefstyle='select: title'/>.
2304</para>
2305
2306<funcsynopsis id='XtDispatchEvent'>
2307<funcprototype>
2308<funcdef>Boolean <function>XtDispatchEvent</function></funcdef>
2309   <paramdef>XEvent *<parameter>event</parameter></paramdef>
2310</funcprototype>
2311</funcsynopsis>
2312
2313<variablelist>
2314  <varlistentry>
2315    <term>
2316      <emphasis remap='I'>event</emphasis>
2317    </term>
2318    <listitem>
2319      <para>
2320Specifies a pointer to the event structure to be dispatched
2321to the appropriate event handlers.
2322    </para>
2323  </listitem>
2324  </varlistentry>
2325</variablelist>
2326
2327<para>
2328The
2329<xref linkend='XtDispatchEvent' xrefstyle='select: title'/>
2330function first calls
2331<function>XFilterEvent</function>
2332with the <emphasis remap='I'>event</emphasis> and the window of the widget to which the
2333Intrinsics intend to dispatch the event, or the event window if
2334the Intrinsics would not dispatch the event to any handlers.
2335If
2336<function>XFilterEvent</function>
2337returns
2338<function>True</function>
2339and the event activated a server grab as identified
2340by a previous call to
2341<xref linkend='XtGrabKey' xrefstyle='select: title'/>
2342or
2343<xref linkend='XtGrabButton' xrefstyle='select: title'/>,
2344<xref linkend='XtDispatchEvent' xrefstyle='select: title'/>
2345calls
2346<xref linkend='XtUngrabKeyboard' xrefstyle='select: title'/>
2347or
2348<xref linkend='XtUngrabPointer' xrefstyle='select: title'/>
2349with the timestamp from the event and immediately returns
2350<function>True</function>.
2351If
2352<function>XFilterEvent</function>
2353returns
2354<function>True</function>
2355and a grab was not activated,
2356<xref linkend='XtDispatchEvent' xrefstyle='select: title'/>
2357just immediately returns
2358<function>True</function>.
2359Otherwise,
2360<xref linkend='XtDispatchEvent' xrefstyle='select: title'/>
2361sends the event to the event handler functions that
2362have been previously registered with the dispatch routine.
2363<xref linkend='XtDispatchEvent' xrefstyle='select: title'/>
2364returns
2365<function>True</function>
2366if
2367<function>XFilterEvent</function>
2368returned
2369<function>True</function>,
2370or if the event was dispatched to some handler, and
2371<function>False</function>
2372if it found no handler to which to dispatch the event.
2373<xref linkend='XtDispatchEvent' xrefstyle='select: title'/>
2374records the last timestamp in any event that
2375contains a timestamp (see
2376<function>XtLastTimestampProcessed ),</function>
2377regardless of whether it was filtered or dispatched.
2378If a modal cascade is active with <emphasis remap='I'>spring_loaded</emphasis>
2379<function>True</function>,
2380and if the event is a remap event as defined by
2381<xref linkend='XtAddGrab' xrefstyle='select: title'/>,
2382<xref linkend='XtDispatchEvent' xrefstyle='select: title'/>
2383may dispatch the event a second time.  If it does so,
2384<xref linkend='XtDispatchEvent' xrefstyle='select: title'/>
2385will call
2386<function>XFilterEvent</function>
2387again with the window of the spring-loaded widget prior to the second
2388dispatch, and if
2389<function>XFilterEvent</function>
2390returns
2391<function>True</function>,
2392the second dispatch will not be performed.
2393</para>
2394</sect1>
2395
2396<sect1 id="The_Application_Input_Loop">
2397<title>The Application Input Loop</title>
2398<para>
2399To process all input from a given application in a continuous loop,
2400use the convenience procedure
2401<xref linkend='XtAppMainLoop' xrefstyle='select: title'/>.
2402</para>
2403
2404<funcsynopsis id='XtAppMainLoop'>
2405<funcprototype>
2406<funcdef>void <function>XtAppMainLoop</function></funcdef>
2407   <paramdef>XtAppContext <parameter>app_context</parameter></paramdef>
2408</funcprototype>
2409</funcsynopsis>
2410
2411<variablelist>
2412  <varlistentry>
2413    <term>
2414      <emphasis remap='I'>app_context</emphasis>
2415    </term>
2416    <listitem>
2417      <para>
2418Specifies the application context that identifies the application.
2419    </para>
2420  </listitem>
2421  </varlistentry>
2422</variablelist>
2423
2424<para>
2425The
2426<xref linkend='XtAppMainLoop' xrefstyle='select: title'/>
2427function first reads the next incoming X event by calling
2428<xref linkend='XtAppNextEvent' xrefstyle='select: title'/>
2429and then dispatches the event to the appropriate registered procedure
2430by calling
2431<xref linkend='XtDispatchEvent' xrefstyle='select: title'/>.
2432This constitutes the main loop of X Toolkit applications.
2433There is nothing special about
2434<xref linkend='XtAppMainLoop' xrefstyle='select: title'/>;
2435it simply calls
2436<xref linkend='XtAppNextEvent' xrefstyle='select: title'/>
2437and then
2438<xref linkend='XtDispatchEvent' xrefstyle='select: title'/>
2439in a conditional loop.
2440At the bottom of the loop, it checks to see if the specified
2441application context's destroy flag is set.
2442If the flag is set, the loop breaks.
2443The whole loop is enclosed between a matching
2444<xref linkend='XtAppLock' xrefstyle='select: title'/>
2445and
2446<xref linkend='XtAppUnlock' xrefstyle='select: title'/>.
2447</para>
2448
2449<para>
2450Applications can provide their own version of this loop,
2451which tests some global termination flag or tests that the number
2452of top-level widgets is larger than zero before circling back to the call to
2453<xref linkend='XtAppNextEvent' xrefstyle='select: title'/>.
2454</para>
2455</sect1>
2456
2457<sect1 id="Setting_and_Checking_the_Sensitivity_State_of_a_Widget">
2458<title>Setting and Checking the Sensitivity State of a Widget</title>
2459<para>
2460Many widgets have a mode in which they assume a different appearance
2461(for example, are grayed out or stippled), do not respond to user events,
2462and become dormant.
2463</para>
2464
2465<para>
2466When dormant,
2467a widget is considered to be insensitive.
2468If a widget is insensitive,
2469the event manager does not dispatch any events to the widget
2470with an event type of
2471<function>KeyPress</function>,
2472<function>KeyRelease</function>,
2473<function>ButtonPress</function>,
2474<function>ButtonRelease</function>,
2475<function>MotionNotify</function>,
2476<function>EnterNotify</function>,
2477<function>LeaveNotify</function>,
2478<function>FocusIn</function>,
2479or
2480<function>FocusOut</function>.
2481</para>
2482
2483<para>
2484A widget can be insensitive because its <emphasis remap='I'>sensitive</emphasis> field is
2485<function>False</function>
2486or because one of its ancestors is insensitive and thus the widget's
2487<emphasis remap='I'>ancestor_sensitive</emphasis> field also is
2488<function>False</function>.
2489A widget can but does not need to distinguish these two cases visually.
2490</para>
2491
2492<note>
2493<para>
2494Pop-up shells will have
2495<emphasis remap='I'>ancestor_sensitive</emphasis>
2496<function>False</function>
2497if the parent was insensitive when the shell
2498was created.  Since
2499<xref linkend='XtSetSensitive' xrefstyle='select: title'/>
2500on the parent will not
2501modify the resource of the pop-up child, clients are advised to include
2502a resource specification of the form
2503``*TransientShell.ancestorSensitive: True''
2504in the application defaults resource file or to
2505otherwise ensure that the parent is
2506sensitive when creating pop-up shells.
2507</para>
2508</note>
2509
2510<para>
2511To set the sensitivity state of a widget, use
2512<xref linkend='XtSetSensitive' xrefstyle='select: title'/>.
2513</para>
2514
2515<funcsynopsis id='XtSetSensitive'>
2516<funcprototype>
2517<funcdef>void <function>XtSetSensitive</function></funcdef>
2518   <paramdef>Widget <parameter>w</parameter></paramdef>
2519   <paramdef>Boolean <parameter>sensitive</parameter></paramdef>
2520</funcprototype>
2521</funcsynopsis>
2522
2523<variablelist>
2524  <varlistentry>
2525    <term>
2526      <emphasis remap='I'>w</emphasis>
2527    </term>
2528    <listitem>
2529      <para>
2530Specifies the widget.  Must be of class RectObj or any subclass thereof.
2531      </para>
2532    </listitem>
2533  </varlistentry>
2534  <varlistentry>
2535    <term>
2536      <emphasis remap='I'>sensitive</emphasis>
2537    </term>
2538    <listitem>
2539      <para>
2540Specifies whether the widget should receive
2541keyboard, pointer, and focus events.
2542    </para>
2543  </listitem>
2544  </varlistentry>
2545</variablelist>
2546
2547<para>
2548The
2549<xref linkend='XtSetSensitive' xrefstyle='select: title'/>
2550function first calls
2551<xref linkend='XtSetValues' xrefstyle='select: title'/>
2552on the current widget with an argument list specifying the
2553XtNsensitive resource and the new value.
2554If <emphasis remap='I'>sensitive</emphasis> is
2555<function>False</function>
2556and the widget's class is a subclass of
2557Composite,
2558<xref linkend='XtSetSensitive' xrefstyle='select: title'/>
2559recursively propagates the new value
2560down the child tree by calling
2561<xref linkend='XtSetValues' xrefstyle='select: title'/>
2562on each child to set <emphasis remap='I'>ancestor_sensitive</emphasis> to
2563<function>False</function>.
2564If <emphasis remap='I'>sensitive</emphasis> is
2565<function>True</function>
2566and the widget's class is a subclass of
2567Composite
2568and the widget's <emphasis remap='I'>ancestor_sensitive</emphasis> field is
2569<function>True</function>,
2570<xref linkend='XtSetSensitive' xrefstyle='select: title'/>
2571sets the <emphasis remap='I'>ancestor_sensitive</emphasis> of each child to
2572<function>True</function>
2573and then recursively calls
2574<xref linkend='XtSetValues' xrefstyle='select: title'/>
2575on each normal descendant that is now sensitive to set
2576<emphasis remap='I'>ancestor_sensitive</emphasis> to
2577<function>True</function>.
2578</para>
2579
2580<para>
2581<xref linkend='XtSetSensitive' xrefstyle='select: title'/>
2582calls
2583<xref linkend='XtSetValues' xrefstyle='select: title'/>
2584to change the <emphasis remap='I'>sensitive</emphasis> and <emphasis remap='I'>ancestor_sensitive</emphasis> fields
2585of each affected widget.
2586Therefore, when one of these changes,
2587the widget's set_values procedure should
2588take whatever display actions are needed
2589(for example, graying out or stippling the widget).
2590</para>
2591
2592<para>
2593<xref linkend='XtSetSensitive' xrefstyle='select: title'/>
2594maintains the invariant that, if the parent has either <emphasis remap='I'>sensitive</emphasis>
2595or <emphasis remap='I'>ancestor_sensitive</emphasis>
2596<function>False</function>,
2597then all children have <emphasis remap='I'>ancestor_sensitive</emphasis>
2598<function>False</function>.
2599</para>
2600
2601<para>
2602To check the current sensitivity state of a widget,
2603use
2604<xref linkend='XtIsSensitive' xrefstyle='select: title'/>.
2605</para>
2606
2607<funcsynopsis id='XtIsSensitive'>
2608<funcprototype>
2609<funcdef>Boolean <function>XtIsSensitive</function></funcdef>
2610   <paramdef>Widget <parameter>w</parameter></paramdef>
2611</funcprototype>
2612</funcsynopsis>
2613
2614<variablelist>
2615  <varlistentry>
2616    <term>
2617      <emphasis remap='I'>w</emphasis>
2618    </term>
2619    <listitem>
2620      <para>
2621Specifies the object.  Must be of class Object or any subclass thereof.
2622    </para>
2623  </listitem>
2624  </varlistentry>
2625</variablelist>
2626
2627<para>
2628The
2629<xref linkend='XtIsSensitive' xrefstyle='select: title'/>
2630function returns
2631<function>True</function>
2632or
2633<function>False</function>
2634to indicate whether user input events are being dispatched.
2635If object's class is a subclass of RectObj and
2636both <emphasis remap='I'>sensitive</emphasis> and <emphasis remap='I'>ancestor_sensitive</emphasis> are
2637<function>True</function>,
2638<xref linkend='XtIsSensitive' xrefstyle='select: title'/>
2639returns
2640<function>True</function>;
2641otherwise, it returns
2642<function>False</function>.
2643</para>
2644</sect1>
2645
2646<sect1 id="Adding_Background_Work_Procedures">
2647<title>Adding Background Work Procedures</title>
2648<para>
2649The Intrinsics have some limited support for background processing.
2650Because most applications spend most of their time waiting for input,
2651you can register an idle-time work procedure
2652that is called when the toolkit would otherwise block in
2653<xref linkend='XtAppNextEvent' xrefstyle='select: title'/>
2654or
2655<xref linkend='XtAppProcessEvent' xrefstyle='select: title'/>.
2656Work procedure pointers are of type
2657<xref linkend='XtWorkProc' xrefstyle='select: title'/>.
2658</para>
2659
2660<funcsynopsis id='XtWorkProc'>
2661<funcprototype>
2662<funcdef>typedef Boolean <function>(*XtWorkProc)</function></funcdef>
2663
2664   <paramdef>XtPointer <parameter>client_data</parameter></paramdef>
2665</funcprototype>
2666</funcsynopsis>
2667
2668<variablelist>
2669  <varlistentry>
2670    <term>
2671      <emphasis remap='I'>client_data</emphasis>
2672    </term>
2673    <listitem>
2674      <para>
2675Passes the client data specified when the work procedure was registered.
2676    </para>
2677  </listitem>
2678  </varlistentry>
2679</variablelist>
2680
2681<para>
2682This procedure should return
2683<function>True</function>
2684when it is done to indicate that it
2685should be removed.
2686If the procedure returns
2687<function>False</function>,
2688it will remain registered and called again when the
2689application is next idle.
2690Work procedures should be very judicious about how much they do.
2691If they run for more than a small part of a second,
2692interactive feel is likely to suffer.
2693</para>
2694
2695<para>
2696To register a work procedure for a given application, use
2697<xref linkend='XtAppAddWorkProc' xrefstyle='select: title'/>.
2698</para>
2699
2700<funcsynopsis id='XtAppAddWorkProc'>
2701<funcprototype>
2702<funcdef>XtWorkProcId <function>XtAppAddWorkProc</function></funcdef>
2703   <paramdef>XtAppContext <parameter>app_context</parameter></paramdef>
2704   <paramdef>XtWorkProc <parameter>proc</parameter></paramdef>
2705   <paramdef>XtPointer <parameter>client_data</parameter></paramdef>
2706</funcprototype>
2707</funcsynopsis>
2708
2709<variablelist>
2710  <varlistentry>
2711    <term>
2712      <emphasis remap='I'>app_context</emphasis>
2713    </term>
2714    <listitem>
2715      <para>
2716Specifies the application context that identifies the application.
2717      </para>
2718    </listitem>
2719  </varlistentry>
2720  <varlistentry>
2721    <term>
2722      <emphasis remap='I'>proc</emphasis>
2723    </term>
2724    <listitem>
2725      <para>
2726Specifies the procedure to be called when the application is idle.
2727      </para>
2728    </listitem>
2729  </varlistentry>
2730  <varlistentry>
2731    <term>
2732      <emphasis remap='I'>client_data</emphasis>
2733    </term>
2734    <listitem>
2735      <para>
2736Specifies the argument passed to the specified procedure
2737when it is called.
2738    </para>
2739  </listitem>
2740  </varlistentry>
2741</variablelist>
2742
2743<para>
2744The
2745<xref linkend='XtAppAddWorkProc' xrefstyle='select: title'/>
2746function adds the specified work procedure for the application identified
2747by <emphasis remap='I'>app_context</emphasis>
2748and returns an opaque unique identifier for this work procedure.
2749Multiple work procedures can be registered,
2750and the most recently added one is always the one that is called.
2751However, if a work procedure adds another work procedure,
2752the newly added one has lower priority than the current one.
2753</para>
2754
2755<para>
2756To remove a work procedure, either return
2757<function>True</function>
2758from the procedure when it is called or use
2759<xref linkend='XtRemoveWorkProc' xrefstyle='select: title'/>
2760outside of the procedure.
2761</para>
2762
2763<funcsynopsis id='XtRemoveWorkProc'>
2764<funcprototype>
2765<funcdef>void <function>XtRemoveWorkProc</function></funcdef>
2766   <paramdef>XtWorkProcId <parameter>id</parameter></paramdef>
2767</funcprototype>
2768</funcsynopsis>
2769
2770<variablelist>
2771  <varlistentry>
2772    <term>
2773      <emphasis remap='I'>id</emphasis>
2774    </term>
2775    <listitem>
2776      <para>
2777Specifies which work procedure to remove.
2778    </para>
2779  </listitem>
2780  </varlistentry>
2781</variablelist>
2782
2783<para>
2784The
2785<xref linkend='XtRemoveWorkProc' xrefstyle='select: title'/>
2786function explicitly removes the specified background work procedure.
2787</para>
2788</sect1>
2789
2790<sect1 id="X_Event_Filters">
2791<title>X Event Filters</title>
2792<para>
2793The event manager provides filters that can be applied to
2794specific X events.
2795The filters, which screen out events that are redundant or are temporarily
2796unwanted, handle
2797pointer motion compression,
2798enter/leave compression, and
2799exposure compression.
2800</para>
2801<sect2 id="Pointer_Motion_Compression">
2802<title>Pointer Motion Compression</title>
2803<para>
2804Widgets can have a hard time keeping up with a rapid stream of
2805pointer motion events.  Furthermore,
2806they usually do not care about every motion event.  To throw out
2807redundant motion events, the widget class field <emphasis remap='I'>compress_motion</emphasis> should be
2808<function>True</function>.
2809When a request for an event would return a motion event,
2810the Intrinsics check if there are any other motion events
2811for the same widget immediately
2812following the current one and, if so, skip all but the last of them.
2813</para>
2814</sect2>
2815
2816<sect2 id="Enter_Leave_Compression">
2817<title>Enter/Leave Compression</title>
2818<para>
2819To throw out pairs of enter and leave events that have no intervening events,
2820as can happen when the user moves the pointer across a widget
2821without stopping in it,
2822the widget class field <emphasis remap='I'>compress_enterleave</emphasis> should be
2823<function>True</function>.
2824These enter and leave events are not delivered to the client
2825if they are found together in the input queue.
2826</para>
2827</sect2>
2828
2829<sect2 id="Exposure_Compression">
2830<title>Exposure Compression</title>
2831<para>
2832Many widgets prefer to process a series of exposure events as a
2833single expose region rather than as individual rectangles.  Widgets
2834with complex displays might use the expose region as a clip list
2835in a graphics context, and widgets with simple displays might
2836ignore the region entirely and redisplay their whole window or
2837might get the bounding box from the region and redisplay only that
2838rectangle.
2839</para>
2840
2841<para>
2842In either case, these widgets do not care about getting partial exposure events.
2843The <emphasis remap='I'>compress_exposure</emphasis> field in the widget class
2844structure specifies the type and number of exposure events that are
2845dispatched to the widget's expose procedure.  This field must be
2846initialized to one of the following values:
2847</para>
2848
2849<literallayout >
2850#define XtExposeNoCompress	((XtEnum)False)
2851#define XtExposeCompressSeries	((XtEnum)True)
2852#define XtExposeCompressMultiple	&lt;implementation-defined&gt;
2853#define XtExposeCompressMaximal	&lt;implementation-defined&gt;
2854</literallayout>
2855
2856<para>
2857optionally ORed with any combination of the following flags (all with
2858implementation-defined values):
2859<function>XtExposeGraphicsExpose</function>,
2860<function>XtExposeGraphicsExposeMerged</function>,
2861<function>XtExposeNoExpose</function>,
2862and
2863<function>XtExposeNoRegion</function>.
2864</para>
2865
2866<para>
2867If the <emphasis remap='I'>compress_exposure</emphasis> field in the widget class structure does not
2868specify
2869<function>XtExposeNoCompress</function>,
2870the event manager calls the widget's expose procedure only
2871once for a series of exposure events.
2872In this case, all
2873<function>Expose</function>
2874or
2875<function>GraphicsExpose</function>
2876events are accumulated into a region.
2877When the final event is received,
2878the event manager replaces the rectangle in the event with the
2879bounding box for the region
2880and calls the widget's expose procedure,
2881passing the modified exposure event and (unless
2882<function>XtExposeNoRegion</function>
2883is specified) the region.
2884For more information on regions, see
2885<olink targetdoc='libX11' targetptr='Manipulating_Regions'>Section 16.5</olink> in
2886<olink targetdoc='libX11' targetptr='libX11'>Xlib — C Language X Interface.</olink>.)
2887</para>
2888
2889<para>
2890The values have the following interpretation:
2891</para>
2892
2893<para>
2894<function>XtExposeNoCompress</function>
2895</para>
2896<itemizedlist spacing='compact'>
2897  <listitem>
2898    <para>
2899No exposure compression is performed; every selected event is
2900individually dispatched to the expose procedure with a <emphasis remap='I'>region</emphasis>
2901argument of NULL.
2902    </para>
2903  </listitem>
2904</itemizedlist>
2905<para>
2906<function>XtExposeCompressSeries</function>
2907</para>
2908<itemizedlist spacing='compact'>
2909  <listitem>
2910    <para>
2911Each series of exposure events is coalesced into a single event,
2912which is dispatched
2913when an exposure event with count equal to zero is reached.
2914    </para>
2915  </listitem>
2916</itemizedlist>
2917<para>
2918<function>XtExposeCompressMultiple</function>
2919</para>
2920<itemizedlist spacing='compact'>
2921  <listitem>
2922    <para>
2923Consecutive series of exposure events are coalesced into a single
2924event, which is dispatched
2925when an exposure event with count equal to zero is reached and either
2926the event queue is empty or the next event is not an exposure event
2927for the same widget.
2928    </para>
2929  </listitem>
2930</itemizedlist>
2931<para>
2932<function>XtExposeCompressMaximal</function>
2933</para>
2934<itemizedlist spacing='compact'>
2935  <listitem>
2936    <para>
2937All expose series currently in the queue for the widget
2938are coalesced into a single
2939event without regard to intervening nonexposure events.  If a
2940partial series is in the end of the queue, the Intrinsics will
2941block until the end of the series is received.
2942    </para>
2943  </listitem>
2944</itemizedlist>
2945<para>
2946The additional flags have the following meaning:
2947</para>
2948
2949<para>
2950<function>XtExposeGraphicsExpose</function>
2951</para>
2952<itemizedlist spacing='compact'>
2953  <listitem>
2954    <para>
2955Specifies that
2956<function>GraphicsExpose</function>
2957events are also to be dispatched to
2958the expose procedure.
2959<function>GraphicsExpose</function>
2960events are compressed, if specified, in the same manner as
2961<function>Expose</function>
2962events.
2963    </para>
2964  </listitem>
2965</itemizedlist>
2966<para>
2967<function>XtExposeGraphicsExposeMerged</function>
2968</para>
2969<itemizedlist spacing='compact'>
2970  <listitem>
2971    <para>
2972Specifies in the case of
2973<function>XtExposeCompressMultiple</function>
2974and
2975<function>XtExposeCompressMaximal</function>
2976that series of
2977<function>GraphicsExpose</function>
2978and
2979<function>Expose</function>
2980events are to be compressed together, with the final event type
2981determining the type of the event passed to the expose procedure.
2982If this flag is not set, then only series of the same event type
2983as the event at the head of the queue are coalesced.  This flag
2984also implies
2985<function>XtExposeGraphicsExpose</function>.
2986    </para>
2987  </listitem>
2988</itemizedlist>
2989<para>
2990<function>XtExposeNoExpose</function>
2991</para>
2992<itemizedlist spacing='compact'>
2993  <listitem>
2994    <para>
2995Specifies that
2996<function>NoExpose</function>
2997events are also to be dispatched to the expose procedure.
2998<function>NoExpose</function>
2999events are never coalesced with
3000other exposure events or with each other.
3001    </para>
3002  </listitem>
3003</itemizedlist>
3004<para>
3005<function>XtExposeNoRegion</function>
3006</para>
3007<itemizedlist spacing='compact'>
3008  <listitem>
3009    <para>
3010Specifies that the final region argument passed to the expose
3011procedure is NULL.  The rectangle in the event will still
3012contain bounding box information for the entire series of
3013compressed exposure events.  This option saves processing time when the
3014region is not needed by the widget.
3015    </para>
3016  </listitem>
3017</itemizedlist>
3018</sect2>
3019</sect1>
3020
3021<sect1 id="Widget_Exposure_and_Visibility">
3022<title>Widget Exposure and Visibility</title>
3023<para>
3024Every primitive widget and some composite widgets display data on the screen
3025by means of direct Xlib calls.
3026Widgets cannot simply write to the screen and forget what they have done.
3027They must keep enough state to redisplay the window or parts
3028of it if a portion is obscured and then reexposed.
3029</para>
3030
3031<sect2 id="Redisplay_of_a_Widget_The_expose_Procedure">
3032<title>Redisplay of a Widget: The expose Procedure</title>
3033<para>
3034The expose procedure pointer in a widget class is of type
3035<xref linkend='XtExposeProc' xrefstyle='select: title'/>.
3036</para>
3037
3038<funcsynopsis id='XtExposeProc'>
3039<funcprototype>
3040<funcdef>typedef void <function>(*XtExposeProc)</function></funcdef>
3041   <paramdef>Widget <parameter>w</parameter></paramdef>
3042   <paramdef>XEvent *<parameter>event</parameter></paramdef>
3043   <paramdef>Region <parameter>region</parameter></paramdef>
3044</funcprototype>
3045</funcsynopsis>
3046
3047<variablelist>
3048  <varlistentry>
3049    <term>
3050      <emphasis remap='I'>w</emphasis>
3051    </term>
3052    <listitem>
3053      <para>
3054Specifies the widget instance requiring redisplay.
3055      </para>
3056    </listitem>
3057  </varlistentry>
3058  <varlistentry>
3059    <term>
3060      <emphasis remap='I'>event</emphasis>
3061    </term>
3062    <listitem>
3063      <para>
3064Specifies the exposure event giving the rectangle requiring redisplay.
3065      </para>
3066    </listitem>
3067  </varlistentry>
3068  <varlistentry>
3069    <term>
3070      <emphasis remap='I'>region</emphasis>
3071    </term>
3072    <listitem>
3073      <para>
3074Specifies the union of all rectangles in this exposure sequence.
3075    </para>
3076  </listitem>
3077  </varlistentry>
3078</variablelist>
3079
3080<para>
3081The redisplay of a widget upon exposure is the responsibility of the
3082expose procedure in the widget's class record.
3083If a widget has no display semantics,
3084it can specify NULL for the <emphasis remap='I'>expose</emphasis> field.
3085Many composite widgets serve only as containers for their children
3086and have no expose procedure.
3087</para>
3088
3089<note>
3090<para>
3091If the <emphasis remap='I'>expose</emphasis> procedure is NULL,
3092<xref linkend='XtRealizeWidget' xrefstyle='select: title'/>
3093fills in a default bit gravity of
3094<function>NorthWestGravity</function>
3095before it calls the widget's realize procedure.
3096</para>
3097</note>
3098
3099<para>
3100If the widget's <emphasis remap='I'>compress_exposure</emphasis> class field specifies
3101<function>XtExposeNoCompress</function>
3102or
3103<function>XtExposeNoRegion</function>,
3104or if the event type is
3105<function>NoExpose</function>
3106(see <xref linkend='Exposure_Compression' />),
3107<emphasis remap='I'>region</emphasis> is NULL.  If
3108<function>XtExposeNoCompress</function>
3109is not specified and the event type is not
3110<function>NoExpose</function>,
3111the event is the final event in the compressed series
3112but <emphasis remap='I'>x</emphasis>, <emphasis remap='I'>y</emphasis>, <emphasis remap='I'>width</emphasis>, and <emphasis remap='I'>height</emphasis> contain
3113the bounding box for all the compressed events.
3114The region is created and destroyed by the Intrinsics, but
3115the widget is permitted to modify the region contents.
3116</para>
3117
3118<para>
3119A small simple widget (for example, Label) can ignore the bounding box
3120information in the event and redisplay the entire window.
3121A more complicated widget (for example, Text) can use the bounding box
3122information to minimize the amount of calculation and redisplay it does.
3123A very complex widget uses the region as a clip list in a GC and
3124ignores the event information.
3125The expose procedure is not chained and is therefore
3126responsible for exposure of all superclass data
3127as well as its own.
3128</para>
3129
3130<para>
3131However,
3132it often is possible to anticipate the display needs of several levels
3133of subclassing.
3134For example, rather than implement separate display procedures for
3135the widgets Label, Pushbutton, and Toggle,
3136you could write a single display routine in Label that uses display state
3137fields like
3138</para>
3139<literallayout >
3140Boolean invert;
3141Boolean highlight;
3142Dimension highlight_width;
3143</literallayout>
3144<para>
3145Label would have <emphasis remap='I'>invert</emphasis> and <emphasis remap='I'>highlight</emphasis> always
3146<function>False</function>
3147and <emphasis remap='I'>highlight_width</emphasis> zero.
3148Pushbutton would dynamically set <emphasis remap='I'>highlight</emphasis> and <emphasis remap='I'>highlight_width</emphasis>,
3149but it would leave <emphasis remap='I'>invert</emphasis> always
3150<function>False</function>.
3151Finally, Toggle would dynamically set all three.
3152In this case,
3153the expose procedures for Pushbutton and Toggle inherit
3154their superclass's expose procedure;
3155see <xref linkend='Inheritance_of_Superclass_Operations' />.
3156</para>
3157</sect2>
3158
3159<sect2 id="Widget_Visibility">
3160<title>Widget Visibility</title>
3161<para>
3162Some widgets may use substantial computing resources to produce the
3163data they will display.
3164However, this effort is wasted if the widget is not actually visible
3165on the screen, that is, if the widget is obscured by another application
3166or is iconified.
3167</para>
3168
3169<para>
3170The <emphasis remap='I'>visible</emphasis> field in the
3171core
3172widget structure provides a hint to the widget that it need not compute
3173display data.
3174This field is guaranteed to be
3175<function>True</function>
3176by the time an
3177exposure
3178event is processed if any part of the widget is visible,
3179but is
3180<function>False</function>
3181if the widget is fully obscured.
3182</para>
3183
3184<para>
3185Widgets can use or ignore the <emphasis remap='I'>visible</emphasis> hint.
3186If they ignore it,
3187they should have <emphasis remap='I'>visible_interest</emphasis> in their widget class record set
3188<function>False</function>.
3189In such cases,
3190the <emphasis remap='I'>visible</emphasis> field is initialized
3191<function>True</function>
3192and never changes.
3193If <emphasis remap='I'>visible_interest</emphasis> is
3194<function>True</function>,
3195the event manager asks for
3196<function>VisibilityNotify</function>
3197events for the widget and sets <emphasis remap='I'>visible</emphasis> to
3198<function>True</function>
3199on
3200<function>VisibilityUnobscured</function>
3201or
3202<function>VisibilityPartiallyObscured</function>
3203events and
3204<function>False</function>
3205on
3206<function>VisibilityFullyObscured</function>
3207events.
3208</para>
3209</sect2>
3210</sect1>
3211
3212<sect1 id="X_Event_Handlers">
3213<title>X Event Handlers</title>
3214<para>
3215Event handlers are procedures called when specified events
3216occur in a widget.
3217Most widgets need not use event handlers explicitly.
3218Instead, they use the Intrinsics translation manager.
3219Event handler procedure pointers are of the type
3220<xref linkend='XtEventHandler' xrefstyle='select: title'/>.
3221</para>
3222
3223<funcsynopsis id='XtEventHandler'>
3224<funcprototype>
3225<funcdef>typedef void <function>(*XtEventHandler)</function></funcdef>
3226
3227   <paramdef>Widget <parameter>w</parameter></paramdef>
3228   <paramdef>XtPointer <parameter>client_data</parameter></paramdef>
3229   <paramdef>XEvent *<parameter>event</parameter></paramdef>
3230   <paramdef>Boolean *<parameter>continue_to_dispatch</parameter></paramdef>
3231</funcprototype>
3232</funcsynopsis>
3233
3234<variablelist>
3235  <varlistentry>
3236    <term>
3237      <emphasis remap='I'>w</emphasis>
3238    </term>
3239    <listitem>
3240      <para>
3241Specifies the widget for which the event arrived.
3242      </para>
3243    </listitem>
3244  </varlistentry>
3245  <varlistentry>
3246    <term>
3247      <emphasis remap='I'>client_data</emphasis>
3248    </term>
3249    <listitem>
3250      <para>
3251Specifies any client-specific information registered with the event handler.
3252      </para>
3253    </listitem>
3254  </varlistentry>
3255  <varlistentry>
3256    <term>
3257      <emphasis remap='I'>event</emphasis>
3258    </term>
3259    <listitem>
3260      <para>
3261Specifies the triggering event.
3262      </para>
3263    </listitem>
3264  </varlistentry>
3265  <varlistentry>
3266    <term>
3267      <emphasis remap='I'>continue_to_dispatch</emphasis>
3268    </term>
3269    <listitem>
3270      <para>
3271Specifies whether the remaining event
3272handlers registered for the current event
3273should be called.
3274    </para>
3275  </listitem>
3276  </varlistentry>
3277</variablelist>
3278
3279<para>
3280After receiving an event and before calling any event handlers, the
3281Boolean pointed to by <emphasis remap='I'>continue_to_dispatch</emphasis> is initialized to
3282<function>True</function>.
3283When an event handler is called, it may decide that further processing
3284of the event is not desirable and may store
3285<function>False</function>
3286in this Boolean, in
3287which case any handlers remaining to be called for the event are
3288ignored.
3289</para>
3290
3291<para>
3292The circumstances under which the Intrinsics may add event handlers
3293to a widget are currently implementation-dependent.  Clients must
3294therefore be aware that storing
3295<function>False</function>
3296into the <emphasis remap='I'>continue_to_dispatch</emphasis> argument can lead to portability problems.
3297</para>
3298<sect2 id="Event_Handlers_That_Select_Events">
3299<title>Event Handlers That Select Events</title>
3300<para>
3301To register an event handler procedure with the dispatch mechanism, use
3302<xref linkend='XtAddEventHandler' xrefstyle='select: title'/>.
3303</para>
3304
3305<funcsynopsis id='XtAddEventHandler'>
3306<funcprototype>
3307<funcdef>void <function>XtAddEventHandler</function></funcdef>
3308   <paramdef>Widget <parameter>w</parameter></paramdef>
3309   <paramdef>EventMask <parameter>event_mask</parameter></paramdef>
3310   <paramdef>Boolean <parameter>nonmaskable</parameter></paramdef>
3311   <paramdef>XtEventHandler <parameter>proc</parameter></paramdef>
3312   <paramdef>XtPointer <parameter>client_data</parameter></paramdef>
3313</funcprototype>
3314</funcsynopsis>
3315
3316<variablelist>
3317  <varlistentry>
3318    <term>
3319      <emphasis remap='I'>w</emphasis>
3320    </term>
3321    <listitem>
3322      <para>
3323Specifies the widget for which this event handler is being registered.  Must be of class Core or any subclass thereof.
3324      </para>
3325    </listitem>
3326  </varlistentry>
3327  <varlistentry>
3328    <term>
3329      <emphasis remap='I'>event_mask</emphasis>
3330    </term>
3331    <listitem>
3332      <para>
3333Specifies the event mask for which to call this procedure.
3334      </para>
3335    </listitem>
3336  </varlistentry>
3337  <varlistentry>
3338    <term>
3339      <emphasis remap='I'>nonmaskable</emphasis>
3340    </term>
3341    <listitem>
3342      <para>
3343Specifies whether this procedure should be
3344called on the nonmaskable events
3345<function>( GraphicsExpose</function>,
3346<function>NoExpose</function>,
3347<function>SelectionClear</function>,
3348<function>SelectionRequest</function>,
3349<function>SelectionNotify</function>,
3350<function>ClientMessage</function>,
3351and
3352<function>MappingNotify ).</function>
3353      </para>
3354    </listitem>
3355  </varlistentry>
3356  <varlistentry>
3357    <term>
3358      <emphasis remap='I'>proc</emphasis>
3359    </term>
3360    <listitem>
3361      <para>
3362Specifies the procedure to be called.
3363      </para>
3364    </listitem>
3365  </varlistentry>
3366  <varlistentry>
3367    <term>
3368      <emphasis remap='I'>client_data</emphasis>
3369    </term>
3370    <listitem>
3371      <para>
3372Specifies additional data to be passed to the event handler.
3373    </para>
3374  </listitem>
3375  </varlistentry>
3376</variablelist>
3377
3378<para>
3379The
3380<xref linkend='XtAddEventHandler' xrefstyle='select: title'/>
3381function registers a procedure with the dispatch mechanism that is
3382to be called when an event that matches the mask occurs on the specified
3383widget.
3384Each widget has a single registered event handler list, which will
3385contain any procedure/client_data pair exactly once regardless of
3386the manner in which it is registered.
3387If the procedure is already registered with the same <emphasis remap='I'>client_data</emphasis>
3388value,
3389the specified mask augments the existing mask.
3390If the widget is realized,
3391<xref linkend='XtAddEventHandler' xrefstyle='select: title'/>
3392calls
3393<function>XSelectInput</function>,
3394if necessary.
3395The order in which this procedure is called relative to other handlers
3396registered for the same event is not defined.
3397</para>
3398
3399<para>
3400To remove a previously registered event handler, use
3401<xref linkend='XtRemoveEventHandler' xrefstyle='select: title'/>.
3402</para>
3403
3404<funcsynopsis id='XtRemoveEventHandler'>
3405<funcprototype>
3406<funcdef>void <function>XtRemoveEventHandler</function></funcdef>
3407   <paramdef>Widget <parameter>w</parameter></paramdef>
3408   <paramdef>EventMask <parameter>event_mask</parameter></paramdef>
3409   <paramdef>Boolean <parameter>nonmaskable</parameter></paramdef>
3410   <paramdef>XtEventHandler <parameter>proc</parameter></paramdef>
3411   <paramdef>XtPointer <parameter>client_data</parameter></paramdef>
3412</funcprototype>
3413</funcsynopsis>
3414
3415<variablelist>
3416  <varlistentry>
3417    <term>
3418      <emphasis remap='I'>w</emphasis>
3419    </term>
3420    <listitem>
3421      <para>
3422Specifies the widget for which this procedure is registered.  Must be of class Core or any subclass thereof.
3423      </para>
3424    </listitem>
3425  </varlistentry>
3426  <varlistentry>
3427    <term>
3428      <emphasis remap='I'>event_mask</emphasis>
3429    </term>
3430    <listitem>
3431      <para>
3432Specifies the event mask for which to unregister this procedure.
3433      </para>
3434    </listitem>
3435  </varlistentry>
3436  <varlistentry>
3437    <term>
3438      <emphasis remap='I'>nonmaskable</emphasis>
3439    </term>
3440    <listitem>
3441      <para>
3442Specifies whether this procedure should be
3443removed on the nonmaskable events
3444<function>( GraphicsExpose</function>,
3445<function>NoExpose</function>,
3446<function>SelectionClear</function>,
3447<function>SelectionRequest</function>,
3448<function>SelectionNotify</function>,
3449<function>ClientMessage</function>,
3450and
3451<function>MappingNotify ).</function>
3452      </para>
3453    </listitem>
3454  </varlistentry>
3455  <varlistentry>
3456    <term>
3457      <emphasis remap='I'>proc</emphasis>
3458    </term>
3459    <listitem>
3460      <para>
3461Specifies the procedure to be removed.
3462      </para>
3463    </listitem>
3464  </varlistentry>
3465  <varlistentry>
3466    <term>
3467      <emphasis remap='I'>client_data</emphasis>
3468    </term>
3469    <listitem>
3470      <para>
3471Specifies the registered client data.
3472    </para>
3473  </listitem>
3474  </varlistentry>
3475</variablelist>
3476
3477<para>
3478The
3479<xref linkend='XtRemoveEventHandler' xrefstyle='select: title'/>
3480function unregisters an event handler registered with
3481<xref linkend='XtAddEventHandler' xrefstyle='select: title'/>
3482or
3483<xref linkend='XtInsertEventHandler' xrefstyle='select: title'/>
3484for the specified events.
3485The request is ignored if <emphasis remap='I'>client_data</emphasis> does not match the value given
3486when the handler was registered.
3487If the widget is realized and no other event handler requires the event,
3488<xref linkend='XtRemoveEventHandler' xrefstyle='select: title'/>
3489calls
3490<function>XSelectInput</function>.
3491If the specified procedure has not been registered
3492or if it has been registered with a different value of <emphasis remap='I'>client_data</emphasis>,
3493<xref linkend='XtRemoveEventHandler' xrefstyle='select: title'/>
3494returns without reporting an error.
3495</para>
3496
3497<para>
3498To stop a procedure registered with
3499<xref linkend='XtAddEventHandler' xrefstyle='select: title'/>
3500or
3501<xref linkend='XtInsertEventHandler' xrefstyle='select: title'/>
3502from receiving all selected events, call
3503<xref linkend='XtRemoveEventHandler' xrefstyle='select: title'/>
3504with an <emphasis remap='I'>event_mask</emphasis> of
3505<function>XtAllEvents</function>
3506and <emphasis remap='I'>nonmaskable</emphasis>
3507<function>True</function>.
3508The procedure will continue to receive any events
3509that have been specified in calls to
3510<xref linkend='XtAddRawEventHandler' xrefstyle='select: title'/>
3511or
3512<xref linkend='XtInsertRawEventHandler' xrefstyle='select: title'/>.
3513</para>
3514
3515<para>
3516To register an event handler procedure that receives events before or
3517after all previously registered event handlers, use
3518<xref linkend='XtInsertEventHandler' xrefstyle='select: title'/>.
3519</para>
3520<literallayout >
3521typedef enum {XtListHead, XtListTail} XtListPosition;
3522</literallayout>
3523
3524<funcsynopsis id='XtInsertEventHandler'>
3525<funcprototype>
3526<funcdef>void <function>XtInsertEventHandler</function></funcdef>
3527   <paramdef>Widget <parameter>w</parameter></paramdef>
3528   <paramdef>EventMask <parameter>event_mask</parameter></paramdef>
3529   <paramdef>Boolean <parameter>nonmaskable</parameter></paramdef>
3530   <paramdef>XtEventHandler <parameter>proc</parameter></paramdef>
3531   <paramdef>XtPointer <parameter>client_data</parameter></paramdef>
3532   <paramdef>XtListPosition <parameter>position</parameter></paramdef>
3533</funcprototype>
3534</funcsynopsis>
3535
3536<variablelist>
3537  <varlistentry>
3538    <term>
3539      <emphasis remap='I'>w</emphasis>
3540    </term>
3541    <listitem>
3542      <para>
3543Specifies the widget for which this event handler is being registered. Must be of class Core or any subclass thereof.
3544      </para>
3545    </listitem>
3546  </varlistentry>
3547  <varlistentry>
3548    <term>
3549      <emphasis remap='I'>event_mask</emphasis>
3550    </term>
3551    <listitem>
3552      <para>
3553Specifies the event mask for which to call this procedure.
3554      </para>
3555    </listitem>
3556  </varlistentry>
3557  <varlistentry>
3558    <term>
3559      <emphasis remap='I'>nonmaskable</emphasis>
3560    </term>
3561    <listitem>
3562      <para>
3563Specifies whether this procedure should be
3564called on the nonmaskable events
3565<function>( GraphicsExpose</function>,
3566<function>NoExpose</function>,
3567<function>SelectionClear</function>,
3568<function>SelectionRequest</function>,
3569<function>SelectionNotify</function>,
3570<function>ClientMessage</function>,
3571and
3572<function>MappingNotify ).</function>
3573      </para>
3574    </listitem>
3575  </varlistentry>
3576  <varlistentry>
3577    <term>
3578      <emphasis remap='I'>proc</emphasis>
3579    </term>
3580    <listitem>
3581      <para>
3582Specifies the procedure to be called.
3583      </para>
3584    </listitem>
3585  </varlistentry>
3586  <varlistentry>
3587    <term>
3588      <emphasis remap='I'>client_data</emphasis>
3589    </term>
3590    <listitem>
3591      <para>
3592Specifies additional data to be passed to the client's event handler.
3593      </para>
3594    </listitem>
3595  </varlistentry>
3596  <varlistentry>
3597    <term>
3598      <emphasis remap='I'>position</emphasis>
3599    </term>
3600    <listitem>
3601      <para>
3602Specifies when the event handler is to be called
3603relative to other previously registered handlers.
3604    </para>
3605  </listitem>
3606  </varlistentry>
3607</variablelist>
3608
3609<para>
3610<xref linkend='XtInsertEventHandler' xrefstyle='select: title'/>
3611is identical to
3612<xref linkend='XtAddEventHandler' xrefstyle='select: title'/>
3613with the additional <emphasis remap='I'>position</emphasis> argument.  If <emphasis remap='I'>position</emphasis> is
3614<function>XtListHead</function>,
3615the event
3616handler is registered so that it is called before any event
3617handlers that were previously registered for the same widget.  If
3618<emphasis remap='I'>position</emphasis> is
3619<function>XtListTail</function>,
3620the event handler is registered to be called
3621after any previously registered event handlers.  If the procedure is
3622already registered with the same <emphasis remap='I'>client_data</emphasis> value, the specified mask
3623augments the existing mask and the procedure is repositioned in
3624the list.
3625</para>
3626</sect2>
3627
3628<sect2 id="Event_Handlers_That_Do_Not_Select_Events">
3629<title>Event Handlers That Do Not Select Events</title>
3630<para>
3631On occasion,
3632clients need to register an event handler procedure with the
3633dispatch mechanism without explicitly
3634causing the X server to select for that event.
3635To do this, use
3636<xref linkend='XtAddRawEventHandler' xrefstyle='select: title'/>.
3637</para>
3638
3639<funcsynopsis id='XtAddRawEventHandler'>
3640<funcprototype>
3641<funcdef>void <function>XtAddRawEventHandler</function></funcdef>
3642   <paramdef>Widget <parameter>w</parameter></paramdef>
3643   <paramdef>EventMask <parameter>event_mask</parameter></paramdef>
3644   <paramdef>Boolean <parameter>nonmaskable</parameter></paramdef>
3645   <paramdef>XtEventHandler <parameter>proc</parameter></paramdef>
3646   <paramdef>XtPointer <parameter>client_data</parameter></paramdef>
3647</funcprototype>
3648</funcsynopsis>
3649
3650<variablelist>
3651  <varlistentry>
3652    <term>
3653      <emphasis remap='I'>w</emphasis>
3654    </term>
3655    <listitem>
3656      <para>
3657Specifies the widget for which this event handler is being registered. Must be of class Core or any subclass thereof.
3658      </para>
3659    </listitem>
3660  </varlistentry>
3661  <varlistentry>
3662    <term>
3663      <emphasis remap='I'>event_mask</emphasis>
3664    </term>
3665    <listitem>
3666      <para>
3667Specifies the event mask for which to call this procedure.
3668      </para>
3669    </listitem>
3670  </varlistentry>
3671  <varlistentry>
3672    <term>
3673      <emphasis remap='I'>nonmaskable</emphasis>
3674    </term>
3675    <listitem>
3676      <para>
3677Specifies whether this procedure should be
3678called on the nonmaskable events
3679<function>( GraphicsExpose</function>,
3680<function>NoExpose</function>,
3681<function>SelectionClear</function>,
3682<function>SelectionRequest</function>,
3683<function>SelectionNotify</function>,
3684<function>ClientMessage</function>,
3685and
3686<function>MappingNotify ).</function>
3687      </para>
3688    </listitem>
3689  </varlistentry>
3690  <varlistentry>
3691    <term>
3692      <emphasis remap='I'>proc</emphasis>
3693    </term>
3694    <listitem>
3695      <para>
3696Specifies the procedure to be called.
3697      </para>
3698    </listitem>
3699  </varlistentry>
3700  <varlistentry>
3701    <term>
3702      <emphasis remap='I'>client_data</emphasis>
3703    </term>
3704    <listitem>
3705      <para>
3706Specifies additional data to be passed to the client's event handler.
3707    </para>
3708  </listitem>
3709  </varlistentry>
3710</variablelist>
3711
3712<para>
3713The
3714<xref linkend='XtAddRawEventHandler' xrefstyle='select: title'/>
3715function is similar to
3716<xref linkend='XtAddEventHandler' xrefstyle='select: title'/>
3717except that it does not affect the widget's event mask and never causes an
3718<function>XSelectInput</function>
3719for its events.
3720Note that the widget might already have those mask bits set
3721because of other nonraw event handlers registered on it.
3722If the procedure is already registered with the same <emphasis remap='I'>client_data</emphasis>,
3723the specified mask augments the existing mask.
3724The order in which this procedure is called relative to other handlers
3725registered for the same event is not defined.
3726</para>
3727
3728<para>
3729To remove a previously registered raw event handler, use
3730<xref linkend='XtRemoveRawEventHandler' xrefstyle='select: title'/>.
3731</para>
3732
3733<funcsynopsis id='XtRemoveRawEventHandler'>
3734<funcprototype>
3735<funcdef>void <function>XtRemoveRawEventHandler</function></funcdef>
3736   <paramdef>Widget <parameter>w</parameter></paramdef>
3737   <paramdef>EventMask <parameter>event_mask</parameter></paramdef>
3738   <paramdef>Boolean <parameter>nonmaskable</parameter></paramdef>
3739   <paramdef>XtEventHandler <parameter>proc</parameter></paramdef>
3740   <paramdef>XtPointer <parameter>client_data</parameter></paramdef>
3741</funcprototype>
3742</funcsynopsis>
3743
3744<variablelist>
3745  <varlistentry>
3746    <term>
3747      <emphasis remap='I'>w</emphasis>
3748    </term>
3749    <listitem>
3750      <para>
3751Specifies the widget for which this procedure is registered.  Must be of class Core or any subclass thereof.
3752      </para>
3753    </listitem>
3754  </varlistentry>
3755  <varlistentry>
3756    <term>
3757      <emphasis remap='I'>event_mask</emphasis>
3758    </term>
3759    <listitem>
3760      <para>
3761Specifies the event mask for which to unregister this procedure.
3762      </para>
3763    </listitem>
3764  </varlistentry>
3765  <varlistentry>
3766    <term>
3767      <emphasis remap='I'>nonmaskable</emphasis>
3768    </term>
3769    <listitem>
3770      <para>
3771Specifies whether this procedure should be
3772removed on the nonmaskable events
3773<function>( GraphicsExpose</function>,
3774<function>NoExpose</function>,
3775<function>SelectionClear</function>,
3776<function>SelectionRequest</function>,
3777<function>SelectionNotify</function>,
3778<function>ClientMessage</function>,
3779and
3780<function>MappingNotify ).</function>
3781      </para>
3782    </listitem>
3783  </varlistentry>
3784  <varlistentry>
3785    <term>
3786      <emphasis remap='I'>proc</emphasis>
3787    </term>
3788    <listitem>
3789      <para>
3790Specifies the procedure to be registered.
3791      </para>
3792    </listitem>
3793  </varlistentry>
3794  <varlistentry>
3795    <term>
3796      <emphasis remap='I'>client_data</emphasis>
3797    </term>
3798    <listitem>
3799      <para>
3800Specifies the registered client data.
3801    </para>
3802  </listitem>
3803  </varlistentry>
3804</variablelist>
3805
3806<para>
3807The
3808<xref linkend='XtRemoveRawEventHandler' xrefstyle='select: title'/>
3809function unregisters an event handler registered with
3810<xref linkend='XtAddRawEventHandler' xrefstyle='select: title'/>
3811or
3812<xref linkend='XtInsertRawEventHandler' xrefstyle='select: title'/>
3813for the specified events without changing
3814the window event mask.
3815The request is ignored if <emphasis remap='I'>client_data</emphasis> does not match the value given
3816when the handler was registered.
3817If the specified procedure has not been registered
3818or if it has been registered with a different value of <emphasis remap='I'>client_data</emphasis>,
3819<xref linkend='XtRemoveRawEventHandler' xrefstyle='select: title'/>
3820returns without reporting an error.
3821</para>
3822
3823<para>
3824To stop a procedure
3825registered with
3826<xref linkend='XtAddRawEventHandler' xrefstyle='select: title'/>
3827or
3828<xref linkend='XtInsertRawEventHandler' xrefstyle='select: title'/>
3829from receiving all nonselected events, call
3830<xref linkend='XtRemoveRawEventHandler' xrefstyle='select: title'/>
3831with an <emphasis remap='I'>event_mask</emphasis> of
3832<function>XtAllEvents</function>
3833and <emphasis remap='I'>nonmaskable</emphasis>
3834<function>True</function>.
3835The procedure
3836will continue to receive any events that have been specified in calls to
3837<xref linkend='XtAddEventHandler' xrefstyle='select: title'/>
3838or
3839<xref linkend='XtInsertEventHandler' xrefstyle='select: title'/>.
3840</para>
3841
3842<para>
3843To register an event handler procedure that receives events before or
3844after all previously registered event handlers without selecting for
3845the events, use
3846<xref linkend='XtInsertRawEventHandler' xrefstyle='select: title'/>.
3847</para>
3848
3849<funcsynopsis id='XtInsertRawEventHandler'>
3850<funcprototype>
3851<funcdef>void <function>XtInsertRawEventHandler</function></funcdef>
3852   <paramdef>Widget <parameter>w</parameter></paramdef>
3853   <paramdef>EventMask <parameter>event_mask</parameter></paramdef>
3854   <paramdef>Boolean <parameter>nonmaskable</parameter></paramdef>
3855   <paramdef>XtEventHandler <parameter>proc</parameter></paramdef>
3856   <paramdef>XtPointer <parameter>client_data</parameter></paramdef>
3857   <paramdef>XtListPosition <parameter>position</parameter></paramdef>
3858</funcprototype>
3859</funcsynopsis>
3860
3861<variablelist>
3862  <varlistentry>
3863    <term>
3864      <emphasis remap='I'>w</emphasis>
3865    </term>
3866    <listitem>
3867      <para>
3868Specifies the widget for which this event handler is being registered. Must be of class Core or any subclass thereof.
3869      </para>
3870    </listitem>
3871  </varlistentry>
3872  <varlistentry>
3873    <term>
3874      <emphasis remap='I'>event_mask</emphasis>
3875    </term>
3876    <listitem>
3877      <para>
3878Specifies the event mask for which to call this procedure.
3879      </para>
3880    </listitem>
3881  </varlistentry>
3882  <varlistentry>
3883    <term>
3884      <emphasis remap='I'>nonmaskable</emphasis>
3885    </term>
3886    <listitem>
3887      <para>
3888Specifies whether this procedure should be
3889called on the nonmaskable events
3890<function>( GraphicsExpose</function>,
3891<function>NoExpose</function>,
3892<function>SelectionClear</function>,
3893<function>SelectionRequest</function>,
3894<function>SelectionNotify</function>,
3895<function>ClientMessage</function>,
3896and
3897<function>MappingNotify ).</function>
3898      </para>
3899    </listitem>
3900  </varlistentry>
3901  <varlistentry>
3902    <term>
3903      <emphasis remap='I'>proc</emphasis>
3904    </term>
3905    <listitem>
3906      <para>
3907Specifies the procedure to be registered.
3908      </para>
3909    </listitem>
3910  </varlistentry>
3911  <varlistentry>
3912    <term>
3913      <emphasis remap='I'>client_data</emphasis>
3914    </term>
3915    <listitem>
3916      <para>
3917Specifies additional data to be passed to the client's event handler.
3918      </para>
3919    </listitem>
3920  </varlistentry>
3921  <varlistentry>
3922    <term>
3923      <emphasis remap='I'>position</emphasis>
3924    </term>
3925    <listitem>
3926      <para>
3927Specifies when the event handler is to be called
3928relative to other previously registered handlers.
3929    </para>
3930  </listitem>
3931  </varlistentry>
3932</variablelist>
3933
3934<para>
3935The
3936<xref linkend='XtInsertRawEventHandler' xrefstyle='select: title'/>
3937function is similar to
3938<xref linkend='XtInsertEventHandler' xrefstyle='select: title'/>
3939except that it does not modify the widget's event
3940mask and never causes an
3941<function>XSelectInput</function>
3942for the specified events.  If
3943the procedure is already registered with the same <emphasis remap='I'>client_data</emphasis>
3944value, the
3945specified mask augments the existing mask and the procedure is
3946repositioned in the list.
3947</para>
3948</sect2>
3949
3950<sect2 id="Current_Event_Mask">
3951<title>Current Event Mask</title>
3952<para>
3953To retrieve the event mask for a given widget, use
3954<xref linkend='XtBuildEventMask' xrefstyle='select: title'/>.
3955</para>
3956
3957<funcsynopsis id='XtBuildEventMask'>
3958<funcprototype>
3959<funcdef>EventMask <function>XtBuildEventMask</function></funcdef>
3960   <paramdef>Widget <parameter>w</parameter></paramdef>
3961</funcprototype>
3962</funcsynopsis>
3963
3964<variablelist>
3965  <varlistentry>
3966    <term>
3967      <emphasis remap='I'>w</emphasis>
3968    </term>
3969    <listitem>
3970      <para>
3971Specifies the widget.  Must be of class Core or any subclass thereof.
3972    </para>
3973  </listitem>
3974  </varlistentry>
3975</variablelist>
3976
3977<para>
3978The
3979<xref linkend='XtBuildEventMask' xrefstyle='select: title'/>
3980function returns the event mask representing the logical OR
3981of all event masks for event handlers registered on the widget with
3982<xref linkend='XtAddEventHandler' xrefstyle='select: title'/>
3983and
3984<xref linkend='XtInsertEventHandler' xrefstyle='select: title'/>
3985and all event translations, including accelerators,
3986installed on the widget.
3987This is the same event mask stored into the
3988<function>XSetWindowAttributes</function>
3989structure by
3990<xref linkend='XtRealizeWidget' xrefstyle='select: title'/>
3991and sent to the server when event handlers and translations are installed or
3992removed on the realized widget.
3993</para>
3994</sect2>
3995
3996<sect2 id="Event_Handlers_for_X_Protocol_Extensions">
3997<title>Event Handlers for X11 Protocol Extensions</title>
3998<para>
3999To register an event handler procedure with the Intrinsics dispatch
4000mechanism according to an event type, use
4001<xref linkend='XtInsertEventTypeHandler' xrefstyle='select: title'/>.
4002</para>
4003
4004<funcsynopsis id='XtInsertEventTypeHandler'>
4005<funcprototype>
4006<funcdef>void <function>XtInsertEventTypeHandler</function></funcdef>
4007   <paramdef>Widget <parameter>widget</parameter></paramdef>
4008   <paramdef>int <parameter>event_type</parameter></paramdef>
4009   <paramdef>XtPointer <parameter>select_data</parameter></paramdef>
4010   <paramdef>XtEventHandler <parameter>proc</parameter></paramdef>
4011   <paramdef>XtPointer <parameter>client_data</parameter></paramdef>
4012   <paramdef>XtListPosition <parameter>position</parameter></paramdef>
4013</funcprototype>
4014</funcsynopsis>
4015
4016<variablelist>
4017  <varlistentry>
4018    <term>
4019      <emphasis remap='I'>widget</emphasis>
4020    </term>
4021    <listitem>
4022      <para>
4023Specifies the widget for which this event handler is being registered.  Must be of class Core or any subclass thereof.
4024      </para>
4025    </listitem>
4026  </varlistentry>
4027  <varlistentry>
4028    <term>
4029      <emphasis remap='I'>event_type</emphasis>
4030    </term>
4031    <listitem>
4032      <para>
4033Specifies the event type for which to call this event handler.
4034      </para>
4035    </listitem>
4036  </varlistentry>
4037  <varlistentry>
4038    <term>
4039      <emphasis remap='I'>select_data</emphasis>
4040    </term>
4041    <listitem>
4042      <para>
4043Specifies data used to request events of the specified type from the server,
4044or NULL.
4045      </para>
4046    </listitem>
4047  </varlistentry>
4048  <varlistentry>
4049    <term>
4050      <emphasis remap='I'>proc</emphasis>
4051    </term>
4052    <listitem>
4053      <para>
4054Specifies the event handler to be called.
4055      </para>
4056    </listitem>
4057  </varlistentry>
4058  <varlistentry>
4059    <term>
4060      <emphasis remap='I'>client_data</emphasis>
4061    </term>
4062    <listitem>
4063      <para>
4064Specifies additional data to be passed to the event handler.
4065      </para>
4066    </listitem>
4067  </varlistentry>
4068  <varlistentry>
4069    <term>
4070      <emphasis remap='I'>position</emphasis>
4071    </term>
4072    <listitem>
4073      <para>
4074Specifies when the event handler is to be called relative to other
4075previously registered handlers.
4076    </para>
4077  </listitem>
4078  </varlistentry>
4079</variablelist>
4080
4081<para>
4082<xref linkend='XtInsertEventTypeHandler' xrefstyle='select: title'/>
4083registers a procedure with the
4084dispatch mechanism that is to be called when an event that matches the
4085specified <emphasis remap='I'>event_type</emphasis> is dispatched to the specified <emphasis remap='I'>widget</emphasis>.
4086</para>
4087
4088<para>
4089If <emphasis remap='I'>event_type</emphasis> specifies one of the core X protocol events, then
4090<emphasis remap='I'>select_data</emphasis> must be a pointer to a value of type
4091<function>EventMask</function>,
4092indicating
4093the event mask to be used to select for the desired event.  This event
4094mask is included in the value returned by
4095<xref linkend='XtBuildEventMask' xrefstyle='select: title'/>.
4096If the widget is realized,
4097<xref linkend='XtInsertEventTypeHandler' xrefstyle='select: title'/>
4098calls
4099<function>XSelectInput</function>
4100if necessary.  Specifying NULL for <emphasis remap='I'>select_data</emphasis> is equivalent to
4101specifying a pointer to an event mask containing 0.  This is similar
4102to the
4103<xref linkend='XtInsertRawEventHandler' xrefstyle='select: title'/>
4104function.
4105</para>
4106
4107<para>
4108If <emphasis remap='I'>event_type</emphasis> specifies an extension event type, then the semantics of
4109the data pointed to by <emphasis remap='I'>select_data</emphasis> are defined by the extension
4110selector registered for the specified event type.
4111</para>
4112
4113<para>
4114In either case the Intrinsics are not required to copy the data
4115pointed to by <emphasis remap='I'>select_data</emphasis>, so the caller must ensure that it remains
4116valid as long as the event handler remains registered with this value
4117of <emphasis remap='I'>select_data</emphasis>.
4118</para>
4119
4120<para>
4121The <emphasis remap='I'>position</emphasis> argument allows the client to control the order of
4122invocation of event handlers registered for the same event type.  If
4123the client does not care about the order, it should normally specify
4124<function>XtListTail</function>,
4125which registers this event handler after any previously
4126registered handlers for this event type.
4127</para>
4128
4129<para>
4130Each widget has a single registered event handler list, which will
4131contain any procedure/client_data pair exactly once if it is
4132registered with
4133<xref linkend='XtInsertEventTypeHandler' xrefstyle='select: title'/>,
4134regardless of the manner
4135in which it is registered and regardless of the value(s)
4136of <emphasis remap='I'>select_data</emphasis>.  If the procedure is already registered with the
4137same <emphasis remap='I'>client_data</emphasis> value, the specified mask augments the existing
4138mask and the procedure is repositioned in the list.
4139</para>
4140
4141<para>
4142To remove an event handler registered with
4143<xref linkend='XtInsertEventTypeHandler' xrefstyle='select: title'/>,
4144use
4145<xref linkend='XtRemoveEventTypeHandler' xrefstyle='select: title'/>.
4146</para>
4147
4148<funcsynopsis id='XtRemoveEventTypeHandler'>
4149<funcprototype>
4150<funcdef>void <function>XtRemoveEventTypeHandler</function></funcdef>
4151   <paramdef>Widget <parameter>widget</parameter></paramdef>
4152   <paramdef>int <parameter>event_type</parameter></paramdef>
4153   <paramdef>XtPointer <parameter>select_data</parameter></paramdef>
4154   <paramdef>XtEventHandler <parameter>proc</parameter></paramdef>
4155   <paramdef>XtPointer <parameter>client_data</parameter></paramdef>
4156</funcprototype>
4157</funcsynopsis>
4158
4159<variablelist>
4160  <varlistentry>
4161    <term>
4162      <emphasis remap='I'>widget</emphasis>
4163    </term>
4164    <listitem>
4165      <para>
4166Specifies the widget for which the event handler was registered.  Must be of class Core or any subclass thereof.
4167      </para>
4168    </listitem>
4169  </varlistentry>
4170  <varlistentry>
4171    <term>
4172      <emphasis remap='I'>event_type</emphasis>
4173    </term>
4174    <listitem>
4175      <para>
4176Specifies the event type for which the handler was registered.
4177      </para>
4178    </listitem>
4179  </varlistentry>
4180  <varlistentry>
4181    <term>
4182      <emphasis remap='I'>select_data</emphasis>
4183    </term>
4184    <listitem>
4185      <para>
4186Specifies data used to deselect events of the specified type
4187from the server, or NULL.
4188      </para>
4189    </listitem>
4190  </varlistentry>
4191  <varlistentry>
4192    <term>
4193      <emphasis remap='I'>proc</emphasis>
4194    </term>
4195    <listitem>
4196      <para>
4197Specifies the event handler to be removed.
4198      </para>
4199    </listitem>
4200  </varlistentry>
4201  <varlistentry>
4202    <term>
4203      <emphasis remap='I'>client_data</emphasis>
4204    </term>
4205    <listitem>
4206      <para>
4207Specifies the additional client data with which the procedure was registered.
4208    </para>
4209  </listitem>
4210  </varlistentry>
4211</variablelist>
4212
4213<para>
4214The
4215<xref linkend='XtRemoveEventTypeHandler' xrefstyle='select: title'/>
4216function unregisters an event handler
4217registered with
4218<xref linkend='XtInsertEventTypeHandler' xrefstyle='select: title'/>
4219for the specified event type.
4220The request is ignored if <emphasis remap='I'>client_data</emphasis> does not match the value given
4221when the handler was registered.
4222</para>
4223
4224<para>
4225If <emphasis remap='I'>event_type</emphasis> specifies one of the core X protocol events,
4226<emphasis remap='I'>select_data</emphasis> must be a pointer to a value of type
4227<function>EventMask, indicating the event</function>
4228mask to be used to deselect for the appropriate event.  If the widget
4229is realized,
4230<xref linkend='XtRemoveEventTypeHandler' xrefstyle='select: title'/>
4231calls
4232<function>XSelectInput</function>
4233if necessary.
4234Specifying NULL for <emphasis remap='I'>select_data</emphasis> is equivalent to specifying a pointer
4235to an event mask containing 0.  This is similar to the
4236<xref linkend='XtRemoveRawEventHandler' xrefstyle='select: title'/>
4237function.
4238</para>
4239
4240<para>
4241If <emphasis remap='I'>event_type</emphasis> specifies an extension event type, then the semantics of
4242the data pointed to by <emphasis remap='I'>select_data</emphasis> are defined by the extension
4243selector registered for the specified event type.
4244</para>
4245
4246<para>
4247To register a procedure to select extension events for a widget, use
4248<xref linkend='XtRegisterExtensionSelector' xrefstyle='select: title'/>.
4249</para>
4250
4251<funcsynopsis id='XtRegisterExtensionSelector'>
4252<funcprototype>
4253<funcdef>void <function>XtRegisterExtensionSelector</function></funcdef>
4254   <paramdef>Display <parameter>*display</parameter></paramdef>
4255   <paramdef>int <parameter>min_event_type</parameter></paramdef>
4256   <paramdef>int <parameter>max_event_type</parameter></paramdef>
4257   <paramdef>XtExtensionSelectProc <parameter>proc</parameter></paramdef>
4258   <paramdef>XtPointer <parameter>client_data</parameter></paramdef>
4259</funcprototype>
4260</funcsynopsis>
4261
4262<variablelist>
4263  <varlistentry>
4264    <term>
4265      <emphasis remap='I'>display</emphasis>
4266    </term>
4267    <listitem>
4268      <para>
4269Specifies the display for which the extension selector is to be registered.
4270      </para>
4271    </listitem>
4272  </varlistentry>
4273  <varlistentry>
4274    <term>
4275      <emphasis remap='I'>min_event_type</emphasis>
4276    </term>
4277    <listitem>
4278      <para></para>
4279    </listitem>
4280  </varlistentry>
4281  <varlistentry>
4282    <term>
4283      <emphasis remap='I'>max_event_type</emphasis>
4284    </term>
4285    <listitem>
4286      <para>
4287Specifies the range of event types for the extension.
4288      </para>
4289    </listitem>
4290  </varlistentry>
4291  <varlistentry>
4292    <term>
4293      <emphasis remap='I'>proc</emphasis>
4294    </term>
4295    <listitem>
4296      <para>
4297Specifies the extension selector procedure.
4298      </para>
4299    </listitem>
4300  </varlistentry>
4301  <varlistentry>
4302    <term>
4303      <emphasis remap='I'>client_data</emphasis>
4304    </term>
4305    <listitem>
4306      <para>
4307Specifies additional data to be passed to the extension selector.
4308    </para>
4309  </listitem>
4310  </varlistentry>
4311</variablelist>
4312
4313<para>
4314The
4315<xref linkend='XtRegisterExtensionSelector' xrefstyle='select: title'/>
4316function registers a procedure to arrange
4317for the delivery of extension events to widgets.
4318</para>
4319
4320<para>
4321If <emphasis remap='I'>min_event_type</emphasis> and <emphasis remap='I'>max_event_type</emphasis> match the parameters
4322to a previous call to
4323<xref linkend='XtRegisterExtensionSelector' xrefstyle='select: title'/>
4324for the same <emphasis remap='I'>display</emphasis>, then <emphasis remap='I'>proc</emphasis> and <emphasis remap='I'>client_data</emphasis>
4325replace the previously
4326registered values.  If the range specified by <emphasis remap='I'>min_event_type</emphasis>
4327and <emphasis remap='I'>max_event_type</emphasis> overlaps the range of the parameters to a
4328previous call for the same display in any other way, an error results.
4329</para>
4330
4331<para>
4332When a widget is realized,
4333after the <emphasis remap='I'>core.realize</emphasis> method is called,
4334the Intrinsics check to see if any event
4335handler specifies an event type within the range of a registered
4336extension selector.  If so, the Intrinsics call each such selector.
4337If an event type handler is added or removed, the Intrinsics check to
4338see if the event type falls within the range of a registered extension
4339selector, and if it does, calls the selector.  In either case the Intrinsics
4340pass a list of all the widget's event types that are within the
4341selector's range.  The corresponding select data are also passed.  The
4342selector is responsible for enabling the delivery of extension events
4343required by the widget.
4344</para>
4345
4346<para>
4347An extension selector is of type
4348<xref linkend='XtExtensionSelectProc' xrefstyle='select: title'/>.
4349</para>
4350
4351<funcsynopsis id='XtExtensionSelectProc'>
4352<funcprototype>
4353<funcdef>typedef void <function>(*XtExtensionSelectProc)</function></funcdef>
4354
4355   <paramdef>Widget <parameter>widget</parameter></paramdef>
4356   <paramdef>int *<parameter>event_types</parameter></paramdef>
4357   <paramdef>XtPointer *<parameter>select_data</parameter></paramdef>
4358   <paramdef>int <parameter>count</parameter></paramdef>
4359   <paramdef>XtPointer <parameter>client_data</parameter></paramdef>
4360</funcprototype>
4361</funcsynopsis>
4362
4363<variablelist>
4364  <varlistentry>
4365    <term>
4366      <emphasis remap='I'>widget</emphasis>
4367    </term>
4368    <listitem>
4369      <para>
4370Specifies the widget that is being realized or is having
4371an event handler added or removed.
4372      </para>
4373    </listitem>
4374  </varlistentry>
4375  <varlistentry>
4376    <term>
4377      <emphasis remap='I'>event_types</emphasis>
4378    </term>
4379    <listitem>
4380      <para>
4381Specifies a list of event types that the widget has
4382registered event handlers for.
4383      </para>
4384    </listitem>
4385  </varlistentry>
4386  <varlistentry>
4387    <term>
4388      <emphasis remap='I'>select_data</emphasis>
4389    </term>
4390    <listitem>
4391      <para>
4392Specifies a list of the select_data parameters specified in
4393<xref linkend='XtInsertEventTypeHandler' xrefstyle='select: title'/>.
4394      </para>
4395    </listitem>
4396  </varlistentry>
4397  <varlistentry>
4398    <term>
4399      <emphasis remap='I'>count</emphasis>
4400    </term>
4401    <listitem>
4402      <para>
4403Specifies the number of entries in the <emphasis remap='I'>event_types</emphasis> and <emphasis remap='I'>select_data</emphasis>
4404lists.
4405      </para>
4406    </listitem>
4407  </varlistentry>
4408  <varlistentry>
4409    <term>
4410      <emphasis remap='I'>client_data</emphasis>
4411    </term>
4412    <listitem>
4413      <para>
4414Specifies the additional client data with which the procedure was registered.
4415    </para>
4416  </listitem>
4417  </varlistentry>
4418</variablelist>
4419
4420<para>
4421The <emphasis remap='I'>event_types</emphasis> and <emphasis remap='I'>select_data</emphasis> lists will always have the
4422same number of elements, specified by <emphasis remap='I'>count</emphasis>.
4423Each event type/select data pair represents one call to
4424<xref linkend='XtInsertEventTypeHandler' xrefstyle='select: title'/>.
4425</para>
4426
4427<para>
4428To register a procedure to dispatch events of a specific type within
4429<xref linkend='XtDispatchEvent' xrefstyle='select: title'/>,
4430use
4431<xref linkend='XtSetEventDispatcher' xrefstyle='select: title'/>.
4432</para>
4433
4434<funcsynopsis id='XtSetEventDispatcher'>
4435<funcprototype>
4436<funcdef>XtEventDispatchProc <function>XtSetEventDispatcher</function></funcdef>
4437   <paramdef>Display *<parameter>display</parameter></paramdef>
4438   <paramdef>int <parameter>event_type</parameter></paramdef>
4439   <paramdef>XtEventDispatchProc <parameter>proc</parameter></paramdef>
4440</funcprototype>
4441</funcsynopsis>
4442
4443<variablelist>
4444  <varlistentry>
4445    <term>
4446      <emphasis remap='I'>display</emphasis>
4447    </term>
4448    <listitem>
4449      <para>
4450Specifies the display for which the event dispatcher is to be registered.
4451      </para>
4452    </listitem>
4453  </varlistentry>
4454  <varlistentry>
4455    <term>
4456      <emphasis remap='I'>event_type</emphasis>
4457    </term>
4458    <listitem>
4459      <para>
4460Specifies the event type for which the dispatcher should be invoked.
4461      </para>
4462    </listitem>
4463  </varlistentry>
4464  <varlistentry>
4465    <term>
4466      <emphasis remap='I'>proc</emphasis>
4467    </term>
4468    <listitem>
4469      <para>
4470Specifies the event dispatcher procedure.
4471    </para>
4472  </listitem>
4473  </varlistentry>
4474</variablelist>
4475
4476<para>
4477The
4478<xref linkend='XtSetEventDispatcher' xrefstyle='select: title'/>
4479function registers the event dispatcher procedure specified by <emphasis remap='I'>proc</emphasis>
4480for events with the type <emphasis remap='I'>event_type</emphasis>.  The previously registered
4481dispatcher (or the default dispatcher if there was no previously registered
4482dispatcher) is returned.  If <emphasis remap='I'>proc</emphasis> is NULL, the default procedure is
4483restored for the specified type.
4484</para>
4485
4486<para>
4487In the future, when
4488<xref linkend='XtDispatchEvent' xrefstyle='select: title'/>
4489is called with an event type of <emphasis remap='I'>event_type</emphasis>, the specified <emphasis remap='I'>proc</emphasis>
4490(or the default dispatcher) is invoked to determine a widget
4491to which to dispatch the event.
4492</para>
4493
4494<para>
4495The default dispatcher handles the Intrinsics modal cascade and keyboard
4496focus mechanisms, handles the semantics of <emphasis remap='I'>compress_enterleave</emphasis>
4497and <emphasis remap='I'>compress_motion</emphasis>, and discards all extension events.
4498</para>
4499
4500<para>
4501An event dispatcher procedure pointer is of type
4502<xref linkend='XtEventDispatchProc' xrefstyle='select: title'/>.
4503</para>
4504
4505<funcsynopsis id='XtEventDispatchProc'>
4506<funcprototype>
4507<funcdef>typedef Boolean <function>(*XtEventDispatchProc)</function></funcdef>
4508   <paramdef>XEvent *<parameter>event</parameter></paramdef>
4509</funcprototype>
4510</funcsynopsis>
4511
4512<variablelist>
4513  <varlistentry>
4514    <term>
4515      <emphasis remap='I'>event</emphasis>
4516    </term>
4517    <listitem>
4518      <para>
4519Passes the event to be dispatched.
4520    </para>
4521  </listitem>
4522  </varlistentry>
4523</variablelist>
4524
4525<para>
4526The event dispatcher procedure should determine whether this event is of
4527a type that should be dispatched to a widget.
4528</para>
4529
4530<para>
4531If the event should be dispatched to a widget, the event dispatcher
4532procedure should determine the appropriate widget to receive the
4533event, call
4534<function>XFilterEvent</function>
4535with the window of this widget, or
4536<function>None</function>
4537if the event is to be discarded, and if
4538<function>XFilterEvent</function>
4539returns
4540<function>False</function>,
4541dispatch the event to the widget using
4542<xref linkend='XtDispatchEventToWidget' xrefstyle='select: title'/>.
4543The procedure should return
4544<function>True</function>
4545if either
4546<function>XFilterEvent</function>
4547or
4548<xref linkend='XtDispatchEventToWidget' xrefstyle='select: title'/>
4549returned
4550<function>True</function>
4551and
4552<function>False</function>
4553otherwise.
4554</para>
4555
4556<para>
4557If the event should not be dispatched to a widget, the event
4558dispatcher procedure should attempt to dispatch the event elsewhere as
4559appropriate and return
4560<function>True</function>
4561if it successfully dispatched the event and
4562<function>False</function>
4563otherwise.
4564</para>
4565
4566<para>
4567Some dispatchers for extension events may wish to forward events
4568according to the Intrinsics' keyboard focus mechanism.  To determine
4569which widget is the end result of keyboard event forwarding, use
4570<xref linkend='XtGetKeyboardFocusWidget' xrefstyle='select: title'/>.
4571</para>
4572
4573<funcsynopsis id='XtGetKeyboardFocusWidget'>
4574<funcprototype>
4575<funcdef>Widget <function>XtGetKeyboardFocusWidget</function></funcdef>
4576   <paramdef>Widget <parameter>widget</parameter></paramdef>
4577</funcprototype>
4578</funcsynopsis>
4579
4580<variablelist>
4581  <varlistentry>
4582    <term>
4583      <emphasis remap='I'>widget</emphasis>
4584    </term>
4585    <listitem>
4586      <para>
4587Specifies the widget to get forwarding information for.
4588    </para>
4589  </listitem>
4590  </varlistentry>
4591</variablelist>
4592
4593<para>
4594The
4595<xref linkend='XtGetKeyboardFocusWidget' xrefstyle='select: title'/>
4596function returns the widget that would be the end result of keyboard
4597event forwarding for a keyboard event for the specified widget.
4598</para>
4599
4600<para>
4601To dispatch an event to a specified widget, use
4602<xref linkend='XtDispatchEventToWidget' xrefstyle='select: title'/>.
4603</para>
4604
4605<funcsynopsis id='XtDispatchEventToWidget'>
4606<funcprototype>
4607<funcdef>Boolean <function>XtDispatchEventToWidget</function></funcdef>
4608   <paramdef>Widget <parameter>widget</parameter></paramdef>
4609   <paramdef>XEvent *<parameter>event</parameter></paramdef>
4610</funcprototype>
4611</funcsynopsis>
4612
4613<variablelist>
4614  <varlistentry>
4615    <term>
4616      <emphasis remap='I'>widget</emphasis>
4617    </term>
4618    <listitem>
4619      <para>
4620Specifies the widget to which to dispatch the event.
4621      </para>
4622    </listitem>
4623  </varlistentry>
4624  <varlistentry>
4625    <term>
4626      <emphasis remap='I'>event</emphasis>
4627    </term>
4628    <listitem>
4629      <para>
4630Specifies a pointer to the event to be dispatched.
4631    </para>
4632  </listitem>
4633  </varlistentry>
4634</variablelist>
4635
4636<para>
4637The
4638<xref linkend='XtDispatchEventToWidget' xrefstyle='select: title'/>
4639function scans the list of registered event handlers for the
4640specified widget and calls each handler that has been registered
4641for the specified event type, subject to the <emphasis remap='I'>continue_to_dispatch</emphasis>
4642value returned by each handler.
4643The Intrinsics behave as if event handlers were registered at the head
4644of the list for
4645<function>Expose</function>,
4646<function>NoExpose</function>,
4647<function>GraphicsExpose</function>,
4648and
4649<function>VisibilityNotify</function>
4650events to invoke the widget's expose procedure according to the exposure
4651compression rules and to update the widget's <emphasis remap='I'>visible</emphasis> field
4652if <emphasis remap='I'>visible_interest</emphasis> is
4653<function>True</function>.
4654These internal event handlers never set <emphasis remap='I'>continue_to_dispatch</emphasis> to
4655<function>False</function>.
4656</para>
4657
4658<para>
4659<xref linkend='XtDispatchEventToWidget' xrefstyle='select: title'/>
4660returns
4661<function>True</function>
4662if any event handler was called and
4663<function>False</function>
4664otherwise.
4665</para>
4666</sect2>
4667</sect1>
4668
4669<sect1 id="Using_the_Intrinsics_in_a_Multi_Threaded_Environment">
4670<title>Using the Intrinsics in a Multi-Threaded Environment</title>
4671<para>
4672The Intrinsics may be used in environments that offer multiple threads
4673of execution within the context of a single process.  A multi-threaded
4674application using the Intrinsics must explicitly initialize the toolkit
4675for mutually exclusive access by calling
4676<xref linkend='XtToolkitThreadInitialize' xrefstyle='select: title'/>.
4677</para>
4678<sect2 id="Initializing_a_Multi_Threaded_Intrinsics_Application">
4679<title>Initializing a Multi-Threaded Intrinsics Application</title>
4680<para>
4681To test and initialize Intrinsics support for mutually exclusive thread
4682access, call
4683<xref linkend='XtToolkitThreadInitialize' xrefstyle='select: title'/>.
4684</para>
4685
4686<funcsynopsis id='XtToolkitThreadInitialize'>
4687<funcprototype>
4688<funcdef>Boolean <function>XtToolkitThreadInitialize</function></funcdef>
4689   <paramdef><parameter></parameter></paramdef>
4690</funcprototype>
4691</funcsynopsis>
4692
4693<para>
4694<xref linkend='XtToolkitThreadInitialize' xrefstyle='select: title'/>
4695returns <function>True</function> if the Intrinsics support mutually exclusive thread
4696access, otherwise it returns <function>False</function>. <xref linkend='XtToolkitThreadInitialize' xrefstyle='select: title'/>
4697must be called before
4698<xref linkend='XtCreateApplicationContext' xrefstyle='select: title'/>,
4699<xref linkend='XtAppInitialize' xrefstyle='select: title'/>,
4700<xref linkend='XtOpenApplication' xrefstyle='select: title'/>,
4701or
4702<function>XtSetLanguageProc</function>
4703is called. <xref linkend='XtToolkitThreadInitialize' xrefstyle='select: title'/> may be called more than once;
4704however, the application writer must ensure that it is not called
4705simultaneously by two or more threads.
4706</para>
4707</sect2>
4708
4709<sect2 id="Locking_tk_Data_Structures">
4710<title>Locking X Toolkit Data Structures</title>
4711<para>
4712The Intrinsics employs two levels of locking: application context and
4713process.  Locking an application context ensures mutually exclusive
4714access by a thread to the state associated with the application context,
4715including all displays and widgets associated with it.  Locking a
4716process ensures mutually exclusive access by a thread to Intrinsics process
4717global data.
4718</para>
4719
4720<para>
4721A client may acquire a lock multiple times and the effect is cumulative.
4722The client must ensure that the lock is released an equal number of times in
4723order for the lock to be acquired by another thread.
4724</para>
4725
4726<para>
4727Most application writers will have little need to use locking as the
4728Intrinsics performs the necessary locking internally.
4729Resource converters are an exception.
4730They require the application context or process to be locked
4731before the application can safely call them directly, for example:
4732</para>
4733<literallayout >
4734	...
4735	XtAppLock(app_context);
4736	XtCvtStringToPixel(dpy, args, num_args, fromVal, toVal, closure_ret);
4737	XtAppUnlock(app_context);
4738	...
4739</literallayout>
4740<para>
4741When the application relies upon
4742<xref linkend='XtConvertAndStore' xrefstyle='select: title'/>
4743or a converter to provide the storage for the results of a
4744conversion, the application should acquire the process lock before
4745calling out and hold the lock until the results have been copied.
4746</para>
4747
4748<para>
4749Application writers who write their own
4750utility functions, such as one which retrieves the being_destroyed field from
4751a widget instance, must lock the application context before accessing
4752widget internal data.  For example:
4753</para>
4754<literallayout >
4755#include &lt;X11/CoreP.h&gt;
4756Boolean BeingDestroyed (widget)
4757	Widget widget;
4758{
4759	Boolean ret;
4760	XtAppLock(XtWidgetToApplicationContext(widget));
4761	ret = widget-&gt;core.being_destroyed;
4762	XtAppUnlock(XtWidgetToApplicationContext(widget));
4763	return ret;
4764}
4765</literallayout>
4766<para>
4767A client that wishes to atomically call two or more Intrinsics functions
4768must lock the application context.  For example:
4769</para>
4770<literallayout >
4771	...
4772	XtAppLock(XtWidgetToApplicationContext(widget));
4773	XtUnmanageChild (widget1);
4774	XtManageChild (widget2);
4775	XtAppUnlock(XtWidgetToApplicationContext(widget));
4776	...
4777</literallayout>
4778<sect3 id="Locking_the_Application_Context">
4779<title>Locking the Application Context</title>
4780<para>
4781To ensure mutual exclusion of application context, display, or
4782widget internal state, use
4783<function>XtAppLock.</function>
4784</para>
4785
4786<funcsynopsis id='XtAppLock'>
4787<funcprototype>
4788<funcdef>void <function>XtAppLock</function></funcdef>
4789   <paramdef>XtAppContext <parameter>app_context</parameter></paramdef>
4790</funcprototype>
4791</funcsynopsis>
4792
4793<variablelist>
4794  <varlistentry>
4795    <term>
4796      <emphasis remap='I'>app_context</emphasis>
4797    </term>
4798    <listitem>
4799      <para>
4800Specifies the application context to lock.
4801    </para>
4802  </listitem>
4803  </varlistentry>
4804</variablelist>
4805
4806<para>
4807<xref linkend='XtAppLock' xrefstyle='select: title'/> blocks until it is able to acquire the lock.  Locking the
4808application context also ensures that only the thread holding the lock
4809makes Xlib calls from within Xt.  An application that makes its own
4810direct Xlib calls must either lock the application context around every
4811call or enable thread locking in Xlib.
4812</para>
4813
4814<para>
4815To unlock a locked application context, use
4816<function>XtAppUnlock.</function>
4817</para>
4818
4819<funcsynopsis id='XtAppUnlock'>
4820<funcprototype>
4821<funcdef>void <function>XtAppUnlock</function></funcdef>
4822   <paramdef>XtAppContext <parameter>app_context</parameter></paramdef>
4823</funcprototype>
4824</funcsynopsis>
4825
4826<variablelist>
4827  <varlistentry>
4828    <term>
4829      <emphasis remap='I'>app_context</emphasis>
4830    </term>
4831    <listitem>
4832      <para>
4833Specifies the application context that was previously locked.
4834    </para>
4835  </listitem>
4836  </varlistentry>
4837</variablelist>
4838
4839
4840</sect3>
4841<sect3 id="Locking_the_Process">
4842<title>Locking the Process</title>
4843<para>
4844To ensure mutual exclusion of X Toolkit process global data, a
4845widget writer must use
4846<function>XtProcessLock.</function>
4847</para>
4848
4849<funcsynopsis id='XtProcessLock'>
4850<funcprototype>
4851<funcdef>void <function>XtProcessLock</function></funcdef>
4852   <paramdef><parameter></parameter></paramdef>
4853</funcprototype>
4854</funcsynopsis>
4855
4856<para>
4857<xref linkend='XtProcessLock' xrefstyle='select: title'/> blocks until it is able to acquire the lock.
4858Widget writers may use XtProcessLock to guarantee mutually exclusive
4859access to widget static data.
4860</para>
4861
4862<para>
4863To unlock a locked process, use
4864<xref linkend='XtProcessUnlock' xrefstyle='select: title'/>.
4865</para>
4866
4867<funcsynopsis id='XtProcessUnlock'>
4868<funcprototype>
4869<funcdef>void <function>XtProcessUnlock</function></funcdef>
4870   <paramdef><parameter></parameter></paramdef>
4871</funcprototype>
4872</funcsynopsis>
4873
4874<para>
4875To lock both an application context and the process at the same
4876time, call
4877<xref linkend='XtAppLock' xrefstyle='select: title'/>
4878first and then
4879<xref linkend='XtProcessLock' xrefstyle='select: title'/>.
4880To release both locks, call
4881<xref linkend='XtProcessUnlock' xrefstyle='select: title'/>
4882first and then
4883<xref linkend='XtAppUnlock' xrefstyle='select: title'/>.
4884The order is important to avoid deadlock.
4885</para>
4886</sect3>
4887</sect2>
4888
4889<sect2 id="Event_Management_in_a_Multi_Threaded_Environment">
4890<title>Event Management in a Multi-Threaded Environment</title>
4891<para>
4892In a nonthreaded environment an application writer could reasonably
4893assume that it is safe to exit the application from a quit callback.
4894This assumption may no longer hold true in a multi-threaded environment;
4895therefore it is desirable to provide a mechanism to terminate an
4896event-processing loop without necessarily terminating its thread.
4897</para>
4898
4899<para>
4900To indicate that the event loop should terminate after the current
4901event dispatch has completed, use
4902<xref linkend='XtAppSetExitFlag' xrefstyle='select: title'/>.
4903</para>
4904
4905<funcsynopsis id='XtAppSetExitFlag'>
4906<funcprototype>
4907<funcdef>void <function>XtAppSetExitFlag</function></funcdef>
4908   <paramdef>XtAppContext <parameter>app_context</parameter></paramdef>
4909</funcprototype>
4910</funcsynopsis>
4911
4912<variablelist>
4913  <varlistentry>
4914    <term>
4915      <emphasis remap='I'>app_context</emphasis>
4916    </term>
4917    <listitem>
4918      <para>
4919Specifies the application context.
4920    </para>
4921  </listitem>
4922  </varlistentry>
4923</variablelist>
4924
4925<para>
4926<xref linkend='XtAppMainLoop' xrefstyle='select: title'/>
4927tests the value of the flag and will return if the flag is <function>True</function>.
4928</para>
4929
4930<para>
4931Application writers who implement their own main loop may test the
4932value of the exit flag with
4933<xref linkend='XtAppGetExitFlag' xrefstyle='select: title'/>.
4934</para>
4935
4936<funcsynopsis id='XtAppGetExitFlag'>
4937<funcprototype>
4938<funcdef>Boolean <function>XtAppGetExitFlag</function></funcdef>
4939   <paramdef>XtAppContext <parameter>app_context</parameter></paramdef>
4940</funcprototype>
4941</funcsynopsis>
4942
4943<variablelist>
4944  <varlistentry>
4945    <term>
4946      <emphasis remap='I'>app_context</emphasis>
4947    </term>
4948    <listitem>
4949      <para>
4950Specifies the application context.
4951    </para>
4952  </listitem>
4953  </varlistentry>
4954</variablelist>
4955
4956<para>
4957<xref linkend='XtAppGetExitFlag' xrefstyle='select: title'/>
4958will normally return <function>False</function>, indicating that event processing
4959may continue.  When
4960<xref linkend='XtAppGetExitFlag' xrefstyle='select: title'/>
4961returns <function>True</function>, the loop must terminate and return to the caller,
4962which might then destroy the application context.
4963</para>
4964
4965<para>
4966Application writers should be aware that, if a thread is blocked in
4967<xref linkend='XtAppNextEvent' xrefstyle='select: title'/>,
4968<xref linkend='XtAppPeekEvent' xrefstyle='select: title'/>,
4969or
4970<xref linkend='XtAppProcessEvent' xrefstyle='select: title'/>
4971and another thread in the same application context opens a new display,
4972adds an alternate input, or a timeout, any new source(s) will not
4973normally be "noticed" by the blocked thread.  Any new sources are
4974"noticed" the next time one of these functions is called.
4975</para>
4976
4977<para>
4978The Intrinsics manage access to events on a last-in, first-out basis.  If
4979multiple threads in the same application context block in
4980<xref linkend='XtAppNextEvent' xrefstyle='select: title'/>,
4981<xref linkend='XtAppPeekEvent' xrefstyle='select: title'/>,
4982or
4983<xref linkend='XtAppProcessEvent' xrefstyle='select: title'/>,
4984the last thread to call one of these functions is the first
4985thread to return.
4986</para>
4987</sect2>
4988</sect1>
4989</chapter>
4990