1<?xml version="1.0" encoding="UTF-8" ?> 2<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN" 3 "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd"> 4<chapter id='Event_Handling_Functions'> 5<title>Event Handling Functions</title> 6 7<para> 8This chapter discusses the Xlib functions you can use to: 9</para> 10<itemizedlist> 11 <listitem><para>Select events</para></listitem> 12 <listitem><para>Handle the output buffer and the event queue</para></listitem> 13 <listitem><para>Select events from the event queue</para></listitem> 14 <listitem><para>Send and get events</para></listitem> 15 <listitem><para>Handle protocol errors</para></listitem> 16</itemizedlist> 17<note><para> 18Some toolkits use their own event-handling functions and do not allow you to 19interchange these event-handling functions with those in Xlib. For further 20information, see the documentation supplied with the toolkit. 21</para></note> 22 23<para> 24Most applications simply are event loops: they wait for an event, decide what to do with it, 25execute some amount of code that results in changes to the display, and then wait for the next 26event. 27</para> 28 29<sect1 id="Selecting_Events"> 30<title>Selecting Events</title> 31<!-- .XS --> 32<!-- (SN Selecting Events --> 33<!-- .XE --> 34<para> 35<!-- .LP --> 36There are two ways to select the events you want reported to your client 37application. 38One way is to set the event_mask member of the 39<structname>XSetWindowAttributes</structname> 40structure when you call 41<xref linkend='XCreateWindow' xrefstyle='select: title'/> 42and 43<xref linkend='XChangeWindowAttributes' xrefstyle='select: title'/>. 44Another way is to use 45<xref linkend='XSelectInput' xrefstyle='select: title'/>. 46</para> 47<indexterm significance="preferred"><primary>XSelectInput</primary></indexterm> 48<!-- .sM --> 49<funcsynopsis id='XSelectInput'> 50<funcprototype> 51 <funcdef><function>XSelectInput</function></funcdef> 52 <paramdef>Display *<parameter>display</parameter></paramdef> 53 <paramdef>Window <parameter>w</parameter></paramdef> 54 <paramdef>long <parameter>event_mask</parameter></paramdef> 55</funcprototype> 56</funcsynopsis> 57<!-- .FN --> 58<variablelist> 59 <varlistentry> 60 <term> 61 <emphasis remap='I'>display</emphasis> 62 </term> 63 <listitem> 64 <para> 65Specifies the connection to the X server. 66 </para> 67 </listitem> 68 </varlistentry> 69 <varlistentry> 70 <term> 71 <emphasis remap='I'>w</emphasis> 72 </term> 73 <listitem> 74 <para> 75Specifies the window whose events you are interested in. 76 </para> 77 </listitem> 78 </varlistentry> 79 <varlistentry> 80 <term> 81 <emphasis remap='I'>event_mask</emphasis> 82 </term> 83 <listitem> 84 <para> 85Specifies the event mask. 86 </para> 87 </listitem> 88 </varlistentry> 89</variablelist> 90<para> 91<!-- .LP --> 92<!-- .eM --> 93The 94<xref linkend='XSelectInput' xrefstyle='select: title'/> 95function requests that the X server report the events associated with the 96specified event mask. 97Initially, X will not report any of these events. 98Events are reported relative to a window. 99If a window is not interested in a device event, it usually propagates to 100the closest ancestor that is interested, 101unless the do_not_propagate mask prohibits it. 102<indexterm><primary>Event</primary><secondary>propagation</secondary></indexterm> 103</para> 104<para> 105<!-- .LP --> 106Setting the event-mask attribute of a window overrides any previous call 107for the same window but not for other clients. 108Multiple clients can select for the same events on the same window 109with the following restrictions: 110</para> 111<itemizedlist> 112 <listitem> 113 <para> 114Multiple clients can select events on the same window because their event masks 115are disjoint. 116When the X server generates an event, it reports it 117to all interested clients. 118 </para> 119 </listitem> 120 <listitem> 121 <para> 122Only one client at a time can select 123<symbol>CirculateRequest</symbol>, 124<symbol>ConfigureRequest</symbol>, 125or 126<symbol>MapRequest</symbol> 127events, which are associated with 128the event mask 129<symbol>SubstructureRedirectMask</symbol>. 130 </para> 131 </listitem> 132 <listitem> 133 <para> 134Only one client at a time can select 135a 136<symbol>ResizeRequest</symbol> 137event, which is associated with 138the event mask 139<symbol>ResizeRedirectMask</symbol>. 140 </para> 141 </listitem> 142 <listitem> 143 <para> 144Only one client at a time can select a 145<symbol>ButtonPress</symbol> 146event, which is associated with 147the event mask 148<symbol>ButtonPressMask</symbol>. 149 </para> 150 </listitem> 151</itemizedlist> 152<para> 153<!-- .LP --> 154The server reports the event to all interested clients. 155</para> 156<para> 157<!-- .LP --> 158<xref linkend='XSelectInput' xrefstyle='select: title'/> 159can generate a 160<errorname>BadWindow</errorname> 161error. 162</para> 163</sect1> 164<sect1 id="Handling_the_Output_Buffer"> 165<title>Handling the Output Buffer</title> 166<!-- .XS --> 167<!-- (SN Handling the Output Buffer --> 168<!-- .XE --> 169<para> 170<!-- .LP --> 171The output buffer is an area used by Xlib to store requests. 172The functions described in this section flush the output buffer 173if the function would block or not return an event. 174That is, all requests residing in the output buffer that 175have not yet been sent are transmitted to the X server. 176These functions differ in the additional tasks they might perform. 177</para> 178<para> 179<!-- .LP --> 180<!-- .sp --> 181To flush the output buffer, use 182<xref linkend='XFlush' xrefstyle='select: title'/>. 183</para> 184<indexterm significance="preferred"><primary>XFlush</primary></indexterm> 185<!-- .sM --> 186<funcsynopsis id='XFlush'> 187<funcprototype> 188 <funcdef><function>XFlush</function></funcdef> 189 <paramdef>Display *<parameter>display</parameter></paramdef> 190</funcprototype> 191</funcsynopsis> 192<!-- .FN --> 193<variablelist> 194 <varlistentry> 195 <term> 196 <emphasis remap='I'>display</emphasis> 197 </term> 198 <listitem> 199 <para> 200Specifies the connection to the X server. 201 </para> 202 </listitem> 203 </varlistentry> 204</variablelist> 205<para> 206<!-- .LP --> 207<!-- .eM --> 208The 209<xref linkend='XFlush' xrefstyle='select: title'/> 210function 211flushes the output buffer. 212Most client applications need not use this function because the output 213buffer is automatically flushed as needed by calls to 214<xref linkend='XPending' xrefstyle='select: title'/>, 215<xref linkend='XNextEvent' xrefstyle='select: title'/>, 216and 217<xref linkend='XWindowEvent' xrefstyle='select: title'/>. 218<indexterm><primary>XPending</primary></indexterm> 219<indexterm><primary>XNextEvent</primary></indexterm> 220<indexterm><primary>XWindowEvent</primary></indexterm> 221Events generated by the server may be enqueued into the library's event queue. 222</para> 223<para> 224<!-- .LP --> 225<!-- .sp --> 226To flush the output buffer and then wait until all requests have been processed, 227use 228<xref linkend='XSync' xrefstyle='select: title'/>. 229</para> 230<indexterm significance="preferred"><primary>XSync</primary></indexterm> 231<!-- .sM --> 232<funcsynopsis id='XSync'> 233<funcprototype> 234 <funcdef><function>XSync</function></funcdef> 235 <paramdef>Display *<parameter>display</parameter></paramdef> 236 <paramdef>Bool <parameter>discard</parameter></paramdef> 237</funcprototype> 238</funcsynopsis> 239<!-- .FN --> 240<variablelist> 241 <varlistentry> 242 <term> 243 <emphasis remap='I'>display</emphasis> 244 </term> 245 <listitem> 246 <para> 247Specifies the connection to the X server. 248 </para> 249 </listitem> 250 </varlistentry> 251 <varlistentry> 252 <term> 253 <emphasis remap='I'>discard</emphasis> 254 </term> 255 <listitem> 256 <para> 257Specifies a Boolean value that indicates whether 258<xref linkend='XSync' xrefstyle='select: title'/> 259discards all events on the event queue. 260 </para> 261 </listitem> 262 </varlistentry> 263</variablelist> 264<para> 265<!-- .LP --> 266<!-- .eM --> 267The 268<xref linkend='XSync' xrefstyle='select: title'/> 269function 270flushes the output buffer and then waits until all requests have been received 271and processed by the X server. 272Any errors generated must be handled by the error handler. 273For each protocol error received by Xlib, 274<xref linkend='XSync' xrefstyle='select: title'/> 275calls the client application's error handling routine 276(see <link linkend="Using_the_Default_Error_Handlers">section 11.8.2</link>). 277Any events generated by the server are enqueued into the library's 278event queue. 279</para> 280<para> 281<!-- .LP --> 282Finally, if you passed 283<symbol>False</symbol>, 284<xref linkend='XSync' xrefstyle='select: title'/> 285does not discard the events in the queue. 286If you passed 287<symbol>True</symbol>, 288<xref linkend='XSync' xrefstyle='select: title'/> 289discards all events in the queue, 290including those events that were on the queue before 291<xref linkend='XSync' xrefstyle='select: title'/> 292was called. 293Client applications seldom need to call 294<xref linkend='XSync' xrefstyle='select: title'/>. 295</para> 296</sect1> 297<sect1 id="Event_Queue_Management"> 298<title>Event Queue Management</title> 299<!-- .XS --> 300<!-- (SN Event Queue Management --> 301<!-- .XE --> 302<para> 303<!-- .LP --> 304Xlib maintains an event queue. 305However, the operating system also may be buffering data 306in its network connection that is not yet read into the event queue. 307</para> 308<para> 309<!-- .LP --> 310<!-- .sp --> 311To check the number of events in the event queue, use 312<xref linkend='XEventsQueued' xrefstyle='select: title'/>. 313</para> 314<indexterm significance="preferred"><primary>XEventsQueued</primary></indexterm> 315<!-- .sM --> 316<funcsynopsis id='XEventsQueued'> 317<funcprototype> 318 <funcdef>int <function>XEventsQueued</function></funcdef> 319 <paramdef>Display *<parameter>display</parameter></paramdef> 320 <paramdef>int <parameter>mode</parameter></paramdef> 321</funcprototype> 322</funcsynopsis> 323<!-- .FN --> 324<variablelist> 325 <varlistentry> 326 <term> 327 <emphasis remap='I'>display</emphasis> 328 </term> 329 <listitem> 330 <para> 331Specifies the connection to the X server. 332 </para> 333 </listitem> 334 </varlistentry> 335 <varlistentry> 336 <term> 337 <emphasis remap='I'>mode</emphasis> 338 </term> 339 <listitem> 340 <para> 341Specifies the mode. 342You can pass 343<symbol>QueuedAlready</symbol>, 344<symbol>QueuedAfterFlush</symbol>, 345or 346<symbol>QueuedAfterReading</symbol>. 347 </para> 348 </listitem> 349 </varlistentry> 350</variablelist> 351<para> 352<!-- .LP --> 353<!-- .eM --> 354If mode is 355<symbol>QueuedAlready</symbol>, 356<xref linkend='XEventsQueued' xrefstyle='select: title'/> 357returns the number of events 358already in the event queue (and never performs a system call). 359If mode is 360<symbol>QueuedAfterFlush</symbol>, 361<xref linkend='XEventsQueued' xrefstyle='select: title'/> 362returns the number of events already in the queue if the number is nonzero. 363If there are no events in the queue, 364<xref linkend='XEventsQueued' xrefstyle='select: title'/> 365flushes the output buffer, 366attempts to read more events out of the application's connection, 367and returns the number read. 368If mode is 369<symbol>QueuedAfterReading</symbol>, 370<xref linkend='XEventsQueued' xrefstyle='select: title'/> 371returns the number of events already in the queue if the number is nonzero. 372If there are no events in the queue, 373<xref linkend='XEventsQueued' xrefstyle='select: title'/> 374attempts to read more events out of the application's connection 375without flushing the output buffer and returns the number read. 376</para> 377<para> 378<!-- .LP --> 379<xref linkend='XEventsQueued' xrefstyle='select: title'/> 380always returns immediately without I/O if there are events already in the 381queue. 382<xref linkend='XEventsQueued' xrefstyle='select: title'/> 383with mode 384<symbol>QueuedAfterFlush</symbol> 385is identical in behavior to 386<xref linkend='XPending' xrefstyle='select: title'/>. 387<xref linkend='XEventsQueued' xrefstyle='select: title'/> 388with mode 389<symbol>QueuedAlready</symbol> 390is identical to the 391<xref linkend='XQLength' xrefstyle='select: title'/> 392function. 393</para> 394<para> 395<!-- .LP --> 396<!-- .sp --> 397To return the number of events that are pending, use 398<xref linkend='XPending' xrefstyle='select: title'/>. 399</para> 400<indexterm significance="preferred"><primary>XPending</primary></indexterm> 401<!-- .sM --> 402<funcsynopsis id='XPending'> 403<funcprototype> 404 <funcdef>int <function>XPending</function></funcdef> 405 <paramdef>Display *<parameter>display</parameter></paramdef> 406</funcprototype> 407</funcsynopsis> 408<!-- .FN --> 409<variablelist> 410 <varlistentry> 411 <term> 412 <emphasis remap='I'>display</emphasis> 413 </term> 414 <listitem> 415 <para> 416Specifies the connection to the X server. 417 </para> 418 </listitem> 419 </varlistentry> 420</variablelist> 421<para> 422<!-- .LP --> 423<!-- .eM --> 424The 425<xref linkend='XPending' xrefstyle='select: title'/> 426function returns the number of events that have been received from the 427X server but have not been removed from the event queue. 428<xref linkend='XPending' xrefstyle='select: title'/> 429is identical to 430<xref linkend='XEventsQueued' xrefstyle='select: title'/> 431with the mode 432<symbol>QueuedAfterFlush</symbol> 433specified. 434</para> 435</sect1> 436<sect1 id="Manipulating_the_Event_Queue"> 437<title>Manipulating the Event Queue</title> 438<!-- .XS --> 439<!-- (SN Manipulating the Event Queue --> 440<!-- .XE --> 441<para> 442<!-- .LP --> 443Xlib provides functions that let you manipulate the event queue. 444This section discusses how to: 445</para> 446<itemizedlist> 447 <listitem> 448 <para> 449Obtain events, in order, and remove them from the queue 450 </para> 451 </listitem> 452 <listitem> 453 <para> 454Peek at events in the queue without removing them 455 </para> 456 </listitem> 457 <listitem> 458 <para> 459Obtain events that match the event mask or the arbitrary 460predicate procedures that you provide 461 </para> 462 </listitem> 463</itemizedlist> 464<sect2 id="Returning_the_Next_Event"> 465<title>Returning the Next Event</title> 466<!-- .XS --> 467<!-- (SN Returning the Next Event --> 468<!-- .XE --> 469<para> 470<!-- .LP --> 471To get the next event and remove it from the queue, use 472<xref linkend='XNextEvent' xrefstyle='select: title'/>. 473</para> 474<indexterm significance="preferred"><primary>XNextEvent</primary></indexterm> 475<!-- .sM --> 476<funcsynopsis id='XNextEvent'> 477<funcprototype> 478 <funcdef><function>XNextEvent</function></funcdef> 479 <paramdef>Display *<parameter>display</parameter></paramdef> 480 <paramdef>XEvent *<parameter>event_return</parameter></paramdef> 481</funcprototype> 482</funcsynopsis> 483<!-- .FN --> 484<variablelist> 485 <varlistentry> 486 <term> 487 <emphasis remap='I'>display</emphasis> 488 </term> 489 <listitem> 490 <para> 491Specifies the connection to the X server. 492 </para> 493 </listitem> 494 </varlistentry> 495 <varlistentry> 496 <term> 497 <emphasis remap='I'>event_return</emphasis> 498 </term> 499 <listitem> 500 <para> 501Returns the next event in the queue. 502 </para> 503 </listitem> 504 </varlistentry> 505</variablelist> 506<para> 507<!-- .LP --> 508<!-- .eM --> 509The 510<xref linkend='XNextEvent' xrefstyle='select: title'/> 511function copies the first event from the event queue into the specified 512<structname>XEvent</structname> 513structure and then removes it from the queue. 514If the event queue is empty, 515<xref linkend='XNextEvent' xrefstyle='select: title'/> 516flushes the output buffer and blocks until an event is received. 517</para> 518<para> 519<!-- .LP --> 520<!-- .sp --> 521To peek at the event queue, use 522<xref linkend='XPeekEvent' xrefstyle='select: title'/>. 523</para> 524<indexterm significance="preferred"><primary>XPeekEvent</primary></indexterm> 525<!-- .sM --> 526<funcsynopsis id='XPeekEvent'> 527<funcprototype> 528 <funcdef><function>XPeekEvent</function></funcdef> 529 <paramdef>Display *<parameter>display</parameter></paramdef> 530 <paramdef>XEvent *<parameter>event_return</parameter></paramdef> 531</funcprototype> 532</funcsynopsis> 533<!-- .FN --> 534<variablelist> 535 <varlistentry> 536 <term> 537 <emphasis remap='I'>display</emphasis> 538 </term> 539 <listitem> 540 <para> 541Specifies the connection to the X server. 542 </para> 543 </listitem> 544 </varlistentry> 545 <varlistentry> 546 <term> 547 <emphasis remap='I'>event_return</emphasis> 548 </term> 549 <listitem> 550 <para> 551Returns a copy of the matched event's associated structure. 552 </para> 553 </listitem> 554 </varlistentry> 555</variablelist> 556<para> 557<!-- .LP --> 558<!-- .eM --> 559The 560<xref linkend='XPeekEvent' xrefstyle='select: title'/> 561function returns the first event from the event queue, 562but it does not remove the event from the queue. 563If the queue is empty, 564<xref linkend='XPeekEvent' xrefstyle='select: title'/> 565flushes the output buffer and blocks until an event is received. 566It then copies the event into the client-supplied 567<structname>XEvent</structname> 568structure without removing it from the event queue. 569</para> 570</sect2> 571<sect2 id="Selecting_Events_Using_a_Predicate_Procedure"> 572<title>Selecting Events Using a Predicate Procedure</title> 573<!-- .XS --> 574<!-- (SN Selecting Events Using a Predicate Procedure --> 575<!-- .XE --> 576<para> 577<!-- .LP --> 578Each of the functions discussed in this section requires you to 579pass a predicate procedure that determines if an event matches 580what you want. 581Your predicate procedure must decide if the event is useful 582without calling any Xlib functions. 583If the predicate directly or indirectly causes the state of the event queue 584to change, the result is not defined. 585If Xlib has been initialized for threads, the predicate is called with 586the display locked and the result of a call by the predicate to any 587Xlib function that locks the display is not defined unless the caller 588has first called 589<function>XLockDisplay</function>. 590</para> 591<para> 592<!-- .LP --> 593The predicate procedure and its associated arguments are: 594</para> 595<!-- .sM --> 596<funcsynopsis> 597<funcprototype> 598 <funcdef><type>Bool</type></funcdef> 599 <paramdef>Display *<parameter>display</parameter></paramdef> 600 <paramdef>XEvent *<parameter>event</parameter></paramdef> 601 <paramdef>XPointer <parameter>arg</parameter></paramdef> 602</funcprototype> 603</funcsynopsis> 604<!-- .FN --> 605<variablelist> 606 <varlistentry> 607 <term> 608 <emphasis remap='I'>display</emphasis> 609 </term> 610 <listitem> 611 <para> 612Specifies the connection to the X server. 613 </para> 614 </listitem> 615 </varlistentry> 616 <varlistentry> 617 <term> 618 <emphasis remap='I'>event</emphasis> 619 </term> 620 <listitem> 621 <para> 622Specifies the 623<structname>XEvent</structname> 624structure. 625 </para> 626 </listitem> 627 </varlistentry> 628 <varlistentry> 629 <term> 630 <emphasis remap='I'>arg</emphasis> 631 </term> 632 <listitem> 633 <para> 634Specifies the argument passed in from the 635<xref linkend='XIfEvent' xrefstyle='select: title'/>, 636<xref linkend='XCheckIfEvent' xrefstyle='select: title'/>, 637or 638<xref linkend='XPeekIfEvent' xrefstyle='select: title'/> 639function. 640 </para> 641 </listitem> 642 </varlistentry> 643</variablelist> 644<para> 645<!-- .LP --> 646<!-- .eM --> 647The predicate procedure is called once for each 648event in the queue until it finds a match. 649After finding a match, the predicate procedure must return 650<symbol>True</symbol>. 651If it did not find a match, it must return 652<symbol>False</symbol>. 653</para> 654<para> 655<!-- .LP --> 656<!-- .sp --> 657To check the event queue for a matching event 658and, if found, remove the event from the queue, use 659<xref linkend='XIfEvent' xrefstyle='select: title'/>. 660</para> 661<indexterm significance="preferred"><primary>XIfEvent</primary></indexterm> 662<!-- .sM --> 663<funcsynopsis id='XIfEvent'> 664<funcprototype> 665 <funcdef><function>XIfEvent</function></funcdef> 666 <paramdef>Display *<parameter>display</parameter></paramdef> 667 <paramdef>XEvent *<parameter>event_return</parameter></paramdef> 668 <paramdef>Bool <parameter>(*predicate)()</parameter></paramdef> 669 <paramdef>XPointer <parameter>arg</parameter></paramdef> 670</funcprototype> 671</funcsynopsis> 672<!-- .FN --> 673<variablelist> 674 <varlistentry> 675 <term> 676 <emphasis remap='I'>display</emphasis> 677 </term> 678 <listitem> 679 <para> 680Specifies the connection to the X server. 681 </para> 682 </listitem> 683 </varlistentry> 684 <varlistentry> 685 <term> 686 <emphasis remap='I'>event_return</emphasis> 687 </term> 688 <listitem> 689 <para> 690Returns the matched event's associated structure. 691 </para> 692 </listitem> 693 </varlistentry> 694 <varlistentry> 695 <term> 696 <emphasis remap='I'>predicate</emphasis> 697 </term> 698 <listitem> 699 <para> 700Specifies the procedure that is to be called to determine 701if the next event in the queue matches what you want. 702 </para> 703 </listitem> 704 </varlistentry> 705 <varlistentry> 706 <term> 707 <emphasis remap='I'>arg</emphasis> 708 </term> 709 <listitem> 710 <para> 711Specifies the user-supplied argument that will be passed to the predicate procedure. 712 </para> 713 </listitem> 714 </varlistentry> 715</variablelist> 716<para> 717<!-- .LP --> 718<!-- .eM --> 719The 720<xref linkend='XIfEvent' xrefstyle='select: title'/> 721function completes only when the specified predicate 722procedure returns 723<symbol>True</symbol> 724for an event, 725which indicates an event in the queue matches. 726<xref linkend='XIfEvent' xrefstyle='select: title'/> 727flushes the output buffer if it blocks waiting for additional events. 728<xref linkend='XIfEvent' xrefstyle='select: title'/> 729removes the matching event from the queue 730and copies the structure into the client-supplied 731<structname>XEvent</structname> 732structure. 733</para> 734<para> 735<!-- .LP --> 736<!-- .sp --> 737To check the event queue for a matching event without blocking, use 738<xref linkend='XCheckIfEvent' xrefstyle='select: title'/>. 739</para> 740<indexterm significance="preferred"><primary>XCheckIfEvent</primary></indexterm> 741<!-- .sM --> 742<funcsynopsis id='XCheckIfEvent'> 743<funcprototype> 744 <funcdef>Bool <function>XCheckIfEvent</function></funcdef> 745 <paramdef>Display *<parameter>display</parameter></paramdef> 746 <paramdef>XEvent *<parameter>event_return</parameter></paramdef> 747 <paramdef>Bool <parameter>(*predicate)()</parameter></paramdef> 748 <paramdef>XPointer <parameter>arg</parameter></paramdef> 749</funcprototype> 750</funcsynopsis> 751<!-- .FN --> 752<variablelist> 753 <varlistentry> 754 <term> 755 <emphasis remap='I'>display</emphasis> 756 </term> 757 <listitem> 758 <para> 759Specifies the connection to the X server. 760 </para> 761 </listitem> 762 </varlistentry> 763 <varlistentry> 764 <term> 765 <emphasis remap='I'>event_return</emphasis> 766 </term> 767 <listitem> 768 <para> 769Returns a copy of the matched event's associated structure. 770 </para> 771 </listitem> 772 </varlistentry> 773 <varlistentry> 774 <term> 775 <emphasis remap='I'>predicate</emphasis> 776 </term> 777 <listitem> 778 <para> 779Specifies the procedure that is to be called to determine 780if the next event in the queue matches what you want. 781 </para> 782 </listitem> 783 </varlistentry> 784 <varlistentry> 785 <term> 786 <emphasis remap='I'>arg</emphasis> 787 </term> 788 <listitem> 789 <para> 790Specifies the user-supplied argument that will be passed to the predicate procedure. 791 </para> 792 </listitem> 793 </varlistentry> 794</variablelist> 795<para> 796<!-- .LP --> 797<!-- .eM --> 798When the predicate procedure finds a match, 799<xref linkend='XCheckIfEvent' xrefstyle='select: title'/> 800copies the matched event into the client-supplied 801<structname>XEvent</structname> 802structure and returns 803<symbol>True</symbol>. 804(This event is removed from the queue.) 805If the predicate procedure finds no match, 806<xref linkend='XCheckIfEvent' xrefstyle='select: title'/> 807returns 808<symbol>False</symbol>, 809and the output buffer will have been flushed. 810All earlier events stored in the queue are not discarded. 811</para> 812<para> 813<!-- .LP --> 814<!-- .sp --> 815To check the event queue for a matching event 816without removing the event from the queue, use 817<xref linkend='XPeekIfEvent' xrefstyle='select: title'/>. 818</para> 819<indexterm significance="preferred"><primary>XPeekIfEvent</primary></indexterm> 820<!-- .sM --> 821<funcsynopsis id='XPeekIfEvent'> 822<funcprototype> 823 <funcdef><function>XPeekIfEvent</function></funcdef> 824 <paramdef>Display *<parameter>display</parameter></paramdef> 825 <paramdef>XEvent *<parameter>event_return</parameter></paramdef> 826 <paramdef>Bool <parameter>(*predicate)()</parameter></paramdef> 827 <paramdef>XPointer <parameter>arg</parameter></paramdef> 828</funcprototype> 829</funcsynopsis> 830<!-- .FN --> 831<variablelist> 832 <varlistentry> 833 <term> 834 <emphasis remap='I'>display</emphasis> 835 </term> 836 <listitem> 837 <para> 838Specifies the connection to the X server. 839 </para> 840 </listitem> 841 </varlistentry> 842 <varlistentry> 843 <term> 844 <emphasis remap='I'>event_return</emphasis> 845 </term> 846 <listitem> 847 <para> 848Returns a copy of the matched event's associated structure. 849 </para> 850 </listitem> 851 </varlistentry> 852 <varlistentry> 853 <term> 854 <emphasis remap='I'>predicate</emphasis> 855 </term> 856 <listitem> 857 <para> 858Specifies the procedure that is to be called to determine 859if the next event in the queue matches what you want. 860 </para> 861 </listitem> 862 </varlistentry> 863 <varlistentry> 864 <term> 865 <emphasis remap='I'>arg</emphasis> 866 </term> 867 <listitem> 868 <para> 869Specifies the user-supplied argument that will be passed to the predicate procedure. 870 </para> 871 </listitem> 872 </varlistentry> 873</variablelist> 874<para> 875<!-- .LP --> 876<!-- .eM --> 877The 878<xref linkend='XPeekIfEvent' xrefstyle='select: title'/> 879function returns only when the specified predicate 880procedure returns 881<symbol>True</symbol> 882for an event. 883After the predicate procedure finds a match, 884<xref linkend='XPeekIfEvent' xrefstyle='select: title'/> 885copies the matched event into the client-supplied 886<structname>XEvent</structname> 887structure without removing the event from the queue. 888<xref linkend='XPeekIfEvent' xrefstyle='select: title'/> 889flushes the output buffer if it blocks waiting for additional events. 890</para> 891</sect2> 892<sect2 id="Selecting_Events_Using_a_Window_or_Event_Mask"> 893<title>Selecting Events Using a Window or Event Mask</title> 894<!-- .XS --> 895<!-- (SN Selecting Events Using a Window or Event Mask --> 896<!-- .XE --> 897<para> 898<!-- .LP --> 899The functions discussed in this section let you select events by window 900or event types, allowing you to process events out of order. 901</para> 902<para> 903<!-- .LP --> 904<!-- .sp --> 905To remove the next event that matches both a window and an event mask, use 906<xref linkend='XWindowEvent' xrefstyle='select: title'/>. 907</para> 908<indexterm significance="preferred"><primary>XWindowEvent</primary></indexterm> 909<!-- .sM --> 910<funcsynopsis id='XWindowEvent'> 911<funcprototype> 912 <funcdef><function>XWindowEvent</function></funcdef> 913 <paramdef>Display *<parameter>display</parameter></paramdef> 914 <paramdef>Window <parameter>w</parameter></paramdef> 915 <paramdef>long <parameter>event_mask</parameter></paramdef> 916 <paramdef>XEvent *<parameter>event_return</parameter></paramdef> 917</funcprototype> 918</funcsynopsis> 919<!-- .FN --> 920<variablelist> 921 <varlistentry> 922 <term> 923 <emphasis remap='I'>display</emphasis> 924 </term> 925 <listitem> 926 <para> 927Specifies the connection to the X server. 928 </para> 929 </listitem> 930 </varlistentry> 931 <varlistentry> 932 <term> 933 <emphasis remap='I'>w</emphasis> 934 </term> 935 <listitem> 936 <para> 937Specifies the window whose events you are interested in. 938 </para> 939 </listitem> 940 </varlistentry> 941 <varlistentry> 942 <term> 943 <emphasis remap='I'>event_mask</emphasis> 944 </term> 945 <listitem> 946 <para> 947Specifies the event mask. 948 </para> 949 </listitem> 950 </varlistentry> 951 <varlistentry> 952 <term> 953 <emphasis remap='I'>event_return</emphasis> 954 </term> 955 <listitem> 956 <para> 957Returns the matched event's associated structure. 958 </para> 959 </listitem> 960 </varlistentry> 961</variablelist> 962<para> 963<!-- .LP --> 964<!-- .eM --> 965The 966<xref linkend='XWindowEvent' xrefstyle='select: title'/> 967function searches the event queue for an event that matches both the specified 968window and event mask. 969When it finds a match, 970<xref linkend='XWindowEvent' xrefstyle='select: title'/> 971removes that event from the queue and copies it into the specified 972<structname>XEvent</structname> 973structure. 974The other events stored in the queue are not discarded. 975If a matching event is not in the queue, 976<xref linkend='XWindowEvent' xrefstyle='select: title'/> 977flushes the output buffer and blocks until one is received. 978</para> 979<para> 980<!-- .LP --> 981<!-- .sp --> 982To remove the next event that matches both a window and an event mask (if any), 983use 984<xref linkend='XCheckWindowEvent' xrefstyle='select: title'/>. 985<indexterm><primary>XCheckWindowEvent</primary></indexterm> 986This function is similar to 987<xref linkend='XWindowEvent' xrefstyle='select: title'/> 988except that it never blocks and it returns a 989<type>Bool</type> 990indicating if the event was returned. 991</para> 992<indexterm significance="preferred"><primary>XCheckWindowEvent</primary></indexterm> 993<!-- .sM --> 994<funcsynopsis id='XCheckWindowEvent'> 995<funcprototype> 996 <funcdef>Bool <function>XCheckWindowEvent</function></funcdef> 997 <paramdef>Display *<parameter>display</parameter></paramdef> 998 <paramdef>Window <parameter>w</parameter></paramdef> 999 <paramdef>long <parameter>event_mask</parameter></paramdef> 1000 <paramdef>XEvent *<parameter>event_return</parameter></paramdef> 1001</funcprototype> 1002</funcsynopsis> 1003<!-- .FN --> 1004<variablelist> 1005 <varlistentry> 1006 <term> 1007 <emphasis remap='I'>display</emphasis> 1008 </term> 1009 <listitem> 1010 <para> 1011Specifies the connection to the X server. 1012 </para> 1013 </listitem> 1014 </varlistentry> 1015 <varlistentry> 1016 <term> 1017 <emphasis remap='I'>w</emphasis> 1018 </term> 1019 <listitem> 1020 <para> 1021Specifies the window whose events you are interested in. 1022 </para> 1023 </listitem> 1024 </varlistentry> 1025 <varlistentry> 1026 <term> 1027 <emphasis remap='I'>event_mask</emphasis> 1028 </term> 1029 <listitem> 1030 <para> 1031Specifies the event mask. 1032 </para> 1033 </listitem> 1034 </varlistentry> 1035 <varlistentry> 1036 <term> 1037 <emphasis remap='I'>event_return</emphasis> 1038 </term> 1039 <listitem> 1040 <para> 1041Returns the matched event's associated structure. 1042 </para> 1043 </listitem> 1044 </varlistentry> 1045</variablelist> 1046<para> 1047<!-- .LP --> 1048<!-- .eM --> 1049The 1050<xref linkend='XCheckWindowEvent' xrefstyle='select: title'/> 1051function searches the event queue and then the events available 1052on the server connection for the first event that matches the specified window 1053and event mask. 1054If it finds a match, 1055<xref linkend='XCheckWindowEvent' xrefstyle='select: title'/> 1056removes that event, copies it into the specified 1057<structname>XEvent</structname> 1058structure, and returns 1059<symbol>True</symbol>. 1060The other events stored in the queue are not discarded. 1061If the event you requested is not available, 1062<xref linkend='XCheckWindowEvent' xrefstyle='select: title'/> 1063returns 1064<symbol>False</symbol>, 1065and the output buffer will have been flushed. 1066</para> 1067<para> 1068<!-- .LP --> 1069<!-- .sp --> 1070To remove the next event that matches an event mask, use 1071<xref linkend='XMaskEvent' xrefstyle='select: title'/>. 1072</para> 1073<indexterm significance="preferred"><primary>XMaskEvent</primary></indexterm> 1074<!-- .sM --> 1075<funcsynopsis id='XMaskEvent'> 1076<funcprototype> 1077 <funcdef><function>XMaskEvent</function></funcdef> 1078 <paramdef>Display *<parameter>display</parameter></paramdef> 1079 <paramdef>long <parameter>event_mask</parameter></paramdef> 1080 <paramdef>XEvent *<parameter>event_return</parameter></paramdef> 1081</funcprototype> 1082</funcsynopsis> 1083<!-- .FN --> 1084<variablelist> 1085 <varlistentry> 1086 <term> 1087 <emphasis remap='I'>display</emphasis> 1088 </term> 1089 <listitem> 1090 <para> 1091Specifies the connection to the X server. 1092 </para> 1093 </listitem> 1094 </varlistentry> 1095 <varlistentry> 1096 <term> 1097 <emphasis remap='I'>event_mask</emphasis> 1098 </term> 1099 <listitem> 1100 <para> 1101Specifies the event mask. 1102 </para> 1103 </listitem> 1104 </varlistentry> 1105 <varlistentry> 1106 <term> 1107 <emphasis remap='I'>event_return</emphasis> 1108 </term> 1109 <listitem> 1110 <para> 1111Returns the matched event's associated structure. 1112 </para> 1113 </listitem> 1114 </varlistentry> 1115</variablelist> 1116<para> 1117<!-- .LP --> 1118<!-- .eM --> 1119The 1120<xref linkend='XMaskEvent' xrefstyle='select: title'/> 1121function searches the event queue for the events associated with the 1122specified mask. 1123When it finds a match, 1124<xref linkend='XMaskEvent' xrefstyle='select: title'/> 1125removes that event and copies it into the specified 1126<structname>XEvent</structname> 1127structure. 1128The other events stored in the queue are not discarded. 1129If the event you requested is not in the queue, 1130<xref linkend='XMaskEvent' xrefstyle='select: title'/> 1131flushes the output buffer and blocks until one is received. 1132</para> 1133<para> 1134<!-- .LP --> 1135<!-- .sp --> 1136To return and remove the next event that matches an event mask (if any), use 1137<xref linkend='XCheckMaskEvent' xrefstyle='select: title'/>. 1138This function is similar to 1139<xref linkend='XMaskEvent' xrefstyle='select: title'/> 1140except that it never blocks and it returns a 1141<type>Bool</type> 1142indicating if the event was returned. 1143</para> 1144<indexterm significance="preferred"><primary>XCheckMaskEvent</primary></indexterm> 1145<!-- .sM --> 1146<funcsynopsis id='XCheckMaskEvent'> 1147<funcprototype> 1148 <funcdef>Bool <function>XCheckMaskEvent</function></funcdef> 1149 <paramdef>Display *<parameter>display</parameter></paramdef> 1150 <paramdef>long <parameter>event_mask</parameter></paramdef> 1151 <paramdef>XEvent *<parameter>event_return</parameter></paramdef> 1152</funcprototype> 1153</funcsynopsis> 1154<!-- .FN --> 1155<variablelist> 1156 <varlistentry> 1157 <term> 1158 <emphasis remap='I'>display</emphasis> 1159 </term> 1160 <listitem> 1161 <para> 1162Specifies the connection to the X server. 1163 </para> 1164 </listitem> 1165 </varlistentry> 1166 <varlistentry> 1167 <term> 1168 <emphasis remap='I'>event_mask</emphasis> 1169 </term> 1170 <listitem> 1171 <para> 1172Specifies the event mask. 1173 </para> 1174 </listitem> 1175 </varlistentry> 1176 <varlistentry> 1177 <term> 1178 <emphasis remap='I'>event_return</emphasis> 1179 </term> 1180 <listitem> 1181 <para> 1182Returns the matched event's associated structure. 1183 </para> 1184 </listitem> 1185 </varlistentry> 1186</variablelist> 1187<para> 1188<!-- .LP --> 1189<!-- .eM --> 1190The 1191<xref linkend='XCheckMaskEvent' xrefstyle='select: title'/> 1192function searches the event queue and then any events available on the 1193server connection for the first event that matches the specified mask. 1194If it finds a match, 1195<xref linkend='XCheckMaskEvent' xrefstyle='select: title'/> 1196removes that event, copies it into the specified 1197<structname>XEvent</structname> 1198structure, and returns 1199<symbol>True</symbol>. 1200The other events stored in the queue are not discarded. 1201If the event you requested is not available, 1202<xref linkend='XCheckMaskEvent' xrefstyle='select: title'/> 1203returns 1204<symbol>False</symbol>, 1205and the output buffer will have been flushed. 1206</para> 1207<para> 1208<!-- .LP --> 1209<!-- .sp --> 1210To return and remove the next event in the queue that matches an event type, use 1211<xref linkend='XCheckTypedEvent' xrefstyle='select: title'/>. 1212</para> 1213<indexterm significance="preferred"><primary>XCheckTypedEvent</primary></indexterm> 1214<!-- .sM --> 1215<funcsynopsis id='XCheckTypedEvent'> 1216<funcprototype> 1217 <funcdef>Bool <function>XCheckTypedEvent</function></funcdef> 1218 <paramdef>Display *<parameter>display</parameter></paramdef> 1219 <paramdef>int <parameter>event_type</parameter></paramdef> 1220 <paramdef>XEvent *<parameter>event_return</parameter></paramdef> 1221</funcprototype> 1222</funcsynopsis> 1223<!-- .FN --> 1224<variablelist> 1225 <varlistentry> 1226 <term> 1227 <emphasis remap='I'>display</emphasis> 1228 </term> 1229 <listitem> 1230 <para> 1231Specifies the connection to the X server. 1232 </para> 1233 </listitem> 1234 </varlistentry> 1235 <varlistentry> 1236 <term> 1237 <emphasis remap='I'>event_type</emphasis> 1238 </term> 1239 <listitem> 1240 <para> 1241Specifies the event type to be compared. 1242 1243 </para> 1244 </listitem> 1245 </varlistentry> 1246 <varlistentry> 1247 <term> 1248 <emphasis remap='I'>event_return</emphasis> 1249 </term> 1250 <listitem> 1251 <para> 1252Returns the matched event's associated structure. 1253 </para> 1254 </listitem> 1255 </varlistentry> 1256</variablelist> 1257<para> 1258<!-- .LP --> 1259<!-- .eM --> 1260The 1261<xref linkend='XCheckTypedEvent' xrefstyle='select: title'/> 1262function searches the event queue and then any events available 1263on the server connection for the first event that matches the specified type. 1264If it finds a match, 1265<xref linkend='XCheckTypedEvent' xrefstyle='select: title'/> 1266removes that event, copies it into the specified 1267<structname>XEvent</structname> 1268structure, and returns 1269<symbol>True</symbol>. 1270The other events in the queue are not discarded. 1271If the event is not available, 1272<xref linkend='XCheckTypedEvent' xrefstyle='select: title'/> 1273returns 1274<symbol>False</symbol>, 1275and the output buffer will have been flushed. 1276</para> 1277<para> 1278<!-- .LP --> 1279<!-- .sp --> 1280To return and remove the next event in the queue that matches an event type 1281and a window, use 1282<xref linkend='XCheckTypedWindowEvent' xrefstyle='select: title'/>. 1283</para> 1284<indexterm significance="preferred"><primary>XCheckTypedWindowEvent</primary></indexterm> 1285<!-- .sM --> 1286<funcsynopsis id='XCheckTypedWindowEvent'> 1287<funcprototype> 1288 <funcdef>Bool <function>XCheckTypedWindowEvent</function></funcdef> 1289 <paramdef>Display *<parameter>display</parameter></paramdef> 1290 <paramdef>Window <parameter>w</parameter></paramdef> 1291 <paramdef>int <parameter>event_type</parameter></paramdef> 1292 <paramdef>XEvent *<parameter>event_return</parameter></paramdef> 1293</funcprototype> 1294</funcsynopsis> 1295<!-- .FN --> 1296<variablelist> 1297 <varlistentry> 1298 <term> 1299 <emphasis remap='I'>display</emphasis> 1300 </term> 1301 <listitem> 1302 <para> 1303Specifies the connection to the X server. 1304 </para> 1305 </listitem> 1306 </varlistentry> 1307 <varlistentry> 1308 <term> 1309 <emphasis remap='I'>w</emphasis> 1310 </term> 1311 <listitem> 1312 <para> 1313Specifies the window. 1314 </para> 1315 </listitem> 1316 </varlistentry> 1317 <varlistentry> 1318 <term> 1319 <emphasis remap='I'>event_type</emphasis> 1320 </term> 1321 <listitem> 1322 <para> 1323Specifies the event type to be compared. 1324 1325 </para> 1326 </listitem> 1327 </varlistentry> 1328 <varlistentry> 1329 <term> 1330 <emphasis remap='I'>event_return</emphasis> 1331 </term> 1332 <listitem> 1333 <para> 1334Returns the matched event's associated structure. 1335 </para> 1336 </listitem> 1337 </varlistentry> 1338</variablelist> 1339<para> 1340<!-- .LP --> 1341<!-- .eM --> 1342The 1343<xref linkend='XCheckTypedWindowEvent' xrefstyle='select: title'/> 1344function searches the event queue and then any events available 1345on the server connection for the first event that matches the specified 1346type and window. 1347If it finds a match, 1348<xref linkend='XCheckTypedWindowEvent' xrefstyle='select: title'/> 1349removes the event from the queue, copies it into the specified 1350<structname>XEvent</structname> 1351structure, and returns 1352<symbol>True</symbol>. 1353The other events in the queue are not discarded. 1354If the event is not available, 1355<xref linkend='XCheckTypedWindowEvent' xrefstyle='select: title'/> 1356returns 1357<symbol>False</symbol>, 1358and the output buffer will have been flushed. 1359</para> 1360</sect2> 1361</sect1> 1362<sect1 id="Putting_an_Event_Back_into_the_Queue"> 1363<title>Putting an Event Back into the Queue</title> 1364<!-- .XS --> 1365<!-- (SN Putting an Event Back into the Queue --> 1366<!-- .XE --> 1367<para> 1368<!-- .LP --> 1369To push an event back into the event queue, use 1370<xref linkend='XPutBackEvent' xrefstyle='select: title'/>. 1371</para> 1372<indexterm significance="preferred"><primary>XPutBackEvent</primary></indexterm> 1373<!-- .sM --> 1374<funcsynopsis id='XPutBackEvent'> 1375<funcprototype> 1376 <funcdef><function>XPutBackEvent</function></funcdef> 1377 <paramdef>Display *<parameter>display</parameter></paramdef> 1378 <paramdef>XEvent *<parameter>event</parameter></paramdef> 1379</funcprototype> 1380</funcsynopsis> 1381<!-- .FN --> 1382<variablelist> 1383 <varlistentry> 1384 <term> 1385 <emphasis remap='I'>display</emphasis> 1386 </term> 1387 <listitem> 1388 <para> 1389Specifies the connection to the X server. 1390 </para> 1391 </listitem> 1392 </varlistentry> 1393 <varlistentry> 1394 <term> 1395 <emphasis remap='I'>event</emphasis> 1396 </term> 1397 <listitem> 1398 <para> 1399Specifies the event. 1400 </para> 1401 </listitem> 1402 </varlistentry> 1403</variablelist> 1404<para> 1405<!-- .LP --> 1406<!-- .eM --> 1407The 1408<xref linkend='XPutBackEvent' xrefstyle='select: title'/> 1409function pushes an event back onto the head of the display's event queue 1410by copying the event into the queue. 1411This can be useful if you read an event and then decide that you 1412would rather deal with it later. 1413There is no limit to the number of times in succession that you can call 1414<xref linkend='XPutBackEvent' xrefstyle='select: title'/>. 1415</para> 1416</sect1> 1417<sect1 id="Sending_Events_to_Other_Applications"> 1418<title>Sending Events to Other Applications</title> 1419<!-- .XS --> 1420<!-- (SN Sending Events to Other Applications --> 1421<!-- .XE --> 1422<para> 1423<!-- .LP --> 1424To send an event to a specified window, use 1425<xref linkend='XSendEvent' xrefstyle='select: title'/>. 1426<indexterm><primary>XSendEvent</primary></indexterm> 1427This function is often used in selection processing. 1428For example, the owner of a selection should use 1429<xref linkend='XSendEvent' xrefstyle='select: title'/> 1430to send a 1431<symbol>SelectionNotify</symbol> 1432event to a requestor when a selection has been converted 1433and stored as a property. 1434</para> 1435<indexterm significance="preferred"><primary>XSendEvent</primary></indexterm> 1436<!-- .sM --> 1437<funcsynopsis id='XSendEvent'> 1438<funcprototype> 1439 <funcdef>Status <function>XSendEvent</function></funcdef> 1440 <paramdef>Display *<parameter>display</parameter></paramdef> 1441 <paramdef>Window <parameter>w</parameter></paramdef> 1442 <paramdef>Bool <parameter>propagate</parameter></paramdef> 1443 <paramdef>long <parameter>event_mask</parameter></paramdef> 1444 <paramdef>XEvent *<parameter>event_send</parameter></paramdef> 1445</funcprototype> 1446</funcsynopsis> 1447<!-- .FN --> 1448<variablelist> 1449 <varlistentry> 1450 <term> 1451 <emphasis remap='I'>display</emphasis> 1452 </term> 1453 <listitem> 1454 <para> 1455Specifies the connection to the X server. 1456 </para> 1457 </listitem> 1458 </varlistentry> 1459 <varlistentry> 1460 <term> 1461 <emphasis remap='I'>w</emphasis> 1462 </term> 1463 <listitem> 1464 <para> 1465Specifies the window the event is to be sent to, or 1466<symbol>PointerWindow</symbol>, 1467or 1468<symbol>InputFocus</symbol>. 1469 </para> 1470 </listitem> 1471 </varlistentry> 1472 <varlistentry> 1473 <term> 1474 <emphasis remap='I'>propagate</emphasis> 1475 </term> 1476 <listitem> 1477 <para> 1478Specifies a Boolean value. 1479 </para> 1480 </listitem> 1481 </varlistentry> 1482 <varlistentry> 1483 <term> 1484 <emphasis remap='I'>event_mask</emphasis> 1485 </term> 1486 <listitem> 1487 <para> 1488Specifies the event mask. 1489 </para> 1490 </listitem> 1491 </varlistentry> 1492 <varlistentry> 1493 <term> 1494 <emphasis remap='I'>event_send</emphasis> 1495 </term> 1496 <listitem> 1497 <para> 1498Specifies the event that is to be sent. 1499 </para> 1500 </listitem> 1501 </varlistentry> 1502</variablelist> 1503<para> 1504<!-- .LP --> 1505<!-- .eM --> 1506The 1507<xref linkend='XSendEvent' xrefstyle='select: title'/> 1508function identifies the destination window, 1509determines which clients should receive the specified events, 1510and ignores any active grabs. 1511This function requires you to pass an event mask. 1512For a discussion of the valid event mask names, 1513see <link linkend="Event_Masks">section 10.3</link>. 1514This function uses the w argument to identify the destination window as follows: 1515</para> 1516<itemizedlist> 1517 <listitem> 1518 <para> 1519If w is 1520<symbol>PointerWindow</symbol>, 1521the destination window is the window that contains the pointer. 1522 </para> 1523 </listitem> 1524 <listitem> 1525 <para> 1526If w is 1527<symbol>InputFocus</symbol> 1528and if the focus window contains the pointer, 1529the destination window is the window that contains the pointer; 1530otherwise, the destination window is the focus window. 1531 </para> 1532 </listitem> 1533</itemizedlist> 1534<para> 1535<!-- .LP --> 1536To determine which clients should receive the specified events, 1537<xref linkend='XSendEvent' xrefstyle='select: title'/> 1538uses the propagate argument as follows: 1539</para> 1540<itemizedlist> 1541 <listitem> 1542 <para> 1543If event_mask is the empty set, 1544the event is sent to the client that created the destination window. 1545If that client no longer exists, 1546no event is sent. 1547 </para> 1548 </listitem> 1549 <listitem> 1550 <para> 1551If propagate is 1552<symbol>False</symbol>, 1553the event is sent to every client selecting on destination any of the event 1554types in the event_mask argument. 1555 </para> 1556 </listitem> 1557 <listitem> 1558 <para> 1559If propagate is 1560<symbol>True</symbol> 1561and no clients have selected on destination any of 1562the event types in event-mask, the destination is replaced with the 1563closest ancestor of destination for which some client has selected a 1564type in event-mask and for which no intervening window has that type in its 1565do-not-propagate-mask. 1566If no such window exists or if the window is 1567an ancestor of the focus window and 1568<symbol>InputFocus</symbol> 1569was originally specified 1570as the destination, the event is not sent to any clients. 1571Otherwise, the event is reported to every client selecting on the final 1572destination any of the types specified in event_mask. 1573 </para> 1574 </listitem> 1575</itemizedlist> 1576<para> 1577<!-- .LP --> 1578The event in the 1579<structname>XEvent</structname> 1580structure must be one of the core events or one of the events 1581defined by an extension (or a 1582<errorname>BadValue</errorname> 1583error results) so that the X server can correctly byte-swap 1584the contents as necessary. 1585The contents of the event are 1586otherwise unaltered and unchecked by the X server except to force send_event to 1587<symbol>True</symbol> 1588in the forwarded event and to set the serial number in the event correctly; 1589therefore these fields 1590and the display field are ignored by 1591<xref linkend='XSendEvent' xrefstyle='select: title'/>. 1592</para> 1593<para> 1594<!-- .LP --> 1595<xref linkend='XSendEvent' xrefstyle='select: title'/> 1596returns zero if the conversion to wire protocol format failed 1597and returns nonzero otherwise. 1598</para> 1599<para> 1600<!-- .LP --> 1601<xref linkend='XSendEvent' xrefstyle='select: title'/> 1602can generate 1603<errorname>BadValue</errorname> 1604and 1605<errorname>BadWindow</errorname> 1606errors. 1607</para> 1608</sect1> 1609<sect1 id="Getting_Pointer_Motion_History"> 1610<title>Getting Pointer Motion History</title> 1611<!-- .XS --> 1612<!-- (SN Getting Pointer Motion History --> 1613<!-- .XE --> 1614<para> 1615<!-- .LP --> 1616Some X server implementations will maintain a more complete 1617history of pointer motion than is reported by event notification. 1618The pointer position at each pointer hardware interrupt may be 1619stored in a buffer for later retrieval. 1620This buffer is called the motion history buffer. 1621For example, a few applications, such as paint programs, 1622want to have a precise history of where the pointer 1623traveled. 1624However, this historical information is highly excessive for most applications. 1625</para> 1626<para> 1627<!-- .LP --> 1628<!-- .sp --> 1629To determine the approximate maximum number of elements in the motion buffer, 1630use 1631<function>XDisplayMotionBufferSize</function>. 1632</para> 1633<indexterm significance="preferred"><primary>XDisplayMotionBufferSize</primary></indexterm> 1634<!-- .sM --> 1635<funcsynopsis id='XGetMotionEvents'> 1636<funcprototype> 1637 <funcdef>unsigned <type>long</type></funcdef> 1638 <paramdef>Display *<parameter>display</parameter></paramdef> 1639</funcprototype> 1640</funcsynopsis> 1641<!-- .FN --> 1642<variablelist> 1643 <varlistentry> 1644 <term> 1645 <emphasis remap='I'>display</emphasis> 1646 </term> 1647 <listitem> 1648 <para> 1649Specifies the connection to the X server. 1650 </para> 1651 </listitem> 1652 </varlistentry> 1653</variablelist> 1654<para> 1655<!-- .LP --> 1656<!-- .eM --> 1657The server may retain the recent history of the pointer motion 1658and do so to a finer granularity than is reported by 1659<symbol>MotionNotify</symbol> 1660events. 1661The 1662<xref linkend='XGetMotionEvents' xrefstyle='select: title'/> 1663function makes this history available. 1664</para> 1665<para> 1666<!-- .LP --> 1667<!-- .sp --> 1668To get the motion history for a specified window and time, use 1669<xref linkend='XGetMotionEvents' xrefstyle='select: title'/>. 1670</para> 1671<indexterm significance="preferred"><primary>XGetMotionEvents</primary></indexterm> 1672<!-- .sM --> 1673<funcsynopsis id='xgetmotionevents'> 1674<funcprototype> 1675 <funcdef>XTimeCoord *<function>XGetMotionEvents</function></funcdef> 1676 <paramdef>Display *<parameter>display</parameter></paramdef> 1677 <paramdef>Window <parameter>w</parameter></paramdef> 1678 <paramdef>Time <parameter>start</parameter></paramdef> 1679 <paramdef>Time <parameter>stop</parameter></paramdef> 1680 <paramdef>int *<parameter>nevents_return</parameter></paramdef> 1681</funcprototype> 1682</funcsynopsis> 1683<!-- .FN --> 1684<variablelist> 1685 <varlistentry> 1686 <term> 1687 <emphasis remap='I'>display</emphasis> 1688 </term> 1689 <listitem> 1690 <para> 1691Specifies the connection to the X server. 1692 </para> 1693 </listitem> 1694 </varlistentry> 1695 <varlistentry> 1696 <term> 1697 <emphasis remap='I'>w</emphasis> 1698 </term> 1699 <listitem> 1700 <para> 1701Specifies the window. 1702 </para> 1703 </listitem> 1704 </varlistentry> 1705 <varlistentry> 1706 <term> 1707 <emphasis remap='I'>start</emphasis> 1708 </term> 1709 <listitem> 1710 <para> 1711<!-- .br --> 1712<!-- .ns --> 1713 </para> 1714 </listitem> 1715 </varlistentry> 1716 <varlistentry> 1717 <term> 1718 <emphasis remap='I'>stop</emphasis> 1719 </term> 1720 <listitem> 1721 <para> 1722Specify the time interval in which the events are returned from the motion 1723history buffer. 1724You can pass a timestamp or 1725<symbol>CurrentTime</symbol>. 1726 </para> 1727 </listitem> 1728 </varlistentry> 1729 <varlistentry> 1730 <term> 1731 <emphasis remap='I'>nevents_return</emphasis> 1732 </term> 1733 <listitem> 1734 <para> 1735Returns the number of events from the motion history buffer. 1736 </para> 1737 </listitem> 1738 </varlistentry> 1739</variablelist> 1740<para> 1741<!-- .LP --> 1742<!-- .eM --> 1743The 1744<xref linkend='XGetMotionEvents' xrefstyle='select: title'/> 1745function returns all events in the motion history buffer that fall between the 1746specified start and stop times, inclusive, and that have coordinates 1747that lie within the specified window (including its borders) at its present 1748placement. 1749If the server does not support motion history, 1750if the start time is later than the stop time, 1751or if the start time is in the future, 1752no events are returned; 1753<xref linkend='XGetMotionEvents' xrefstyle='select: title'/> 1754returns NULL. 1755If the stop time is in the future, it is equivalent to specifying 1756<symbol>CurrentTime</symbol>. 1757The return type for this function is a structure defined as follows: 1758</para> 1759<para> 1760<!-- .LP --> 1761<indexterm significance="preferred"><primary>XTimeCoord</primary></indexterm> 1762<!-- .sM --> 1763<literallayout class="monospaced"> 1764<!-- .TA .5i --> 1765<!-- .ta .5i --> 1766typedef struct { 1767 Time time; 1768 short x, y; 1769} XTimeCoord; 1770</literallayout> 1771</para> 1772<para> 1773<!-- .LP --> 1774<!-- .eM --> 1775The time member is set to the time, in milliseconds. 1776The x and y members are set to the coordinates of the pointer and 1777are reported relative to the origin 1778of the specified window. 1779To free the data returned from this call, use 1780<xref linkend='XFree' xrefstyle='select: title'/>. 1781</para> 1782<para> 1783<!-- .LP --> 1784<xref linkend='XGetMotionEvents' xrefstyle='select: title'/> 1785can generate a 1786<errorname>BadWindow</errorname> 1787error. 1788</para> 1789</sect1> 1790<sect1 id="Handling_Protocol_Errors"> 1791<title>Handling Protocol Errors</title> 1792<!-- .XS --> 1793<!-- (SN Handling Protocol Errors --> 1794<!-- .XE --> 1795<para> 1796<!-- .LP --> 1797Xlib provides functions that you can use to enable or disable synchronization 1798and to use the default error handlers. 1799</para> 1800<sect2 id="Enabling_or_Disabling_Synchronization"> 1801<title>Enabling or Disabling Synchronization</title> 1802<!-- .XS --> 1803<!-- (SN Enabling or Disabling Synchronization --> 1804<!-- .XE --> 1805<para> 1806<!-- .LP --> 1807When debugging X applications, 1808it often is very convenient to require Xlib to behave synchronously 1809so that errors are reported as they occur. 1810The following function lets you disable or enable synchronous behavior. 1811Note that graphics may occur 30 or more times more slowly when 1812synchronization is enabled. 1813<indexterm><primary>_Xdebug</primary></indexterm> 1814On <acronym>POSIX</acronym>-conformant systems, 1815there is also a global variable 1816<varname>_Xdebug</varname> 1817that, if set to nonzero before starting a program under a debugger, will force 1818synchronous library behavior. 1819</para> 1820<para> 1821<!-- .LP --> 1822After completing their work, 1823all Xlib functions that generate protocol requests call what is known as 1824an after function. 1825<xref linkend='XSetAfterFunction' xrefstyle='select: title'/> 1826sets which function is to be called. 1827</para> 1828<indexterm significance="preferred"><primary>XSetAfterFunction</primary></indexterm> 1829<!-- .sM --> 1830<funcsynopsis id='XSetAfterFunction'> 1831<funcprototype> 1832 <funcdef><type>int</type></funcdef> 1833 <paramdef>Display *<parameter>display</parameter></paramdef> 1834 <paramdef>int <parameter>(*procedure)()</parameter></paramdef> 1835</funcprototype> 1836</funcsynopsis> 1837<!-- .FN --> 1838<variablelist> 1839 <varlistentry> 1840 <term> 1841 <emphasis remap='I'>display</emphasis> 1842 </term> 1843 <listitem> 1844 <para> 1845Specifies the connection to the X server. 1846 </para> 1847 </listitem> 1848 </varlistentry> 1849 <varlistentry> 1850 <term> 1851 <emphasis remap='I'>procedure</emphasis> 1852 </term> 1853 <listitem> 1854 <para> 1855Specifies the procedure to be called. 1856 </para> 1857 </listitem> 1858 </varlistentry> 1859</variablelist> 1860<para> 1861<!-- .LP --> 1862<!-- .eM --> 1863The specified procedure is called with only a display pointer. 1864<xref linkend='XSetAfterFunction' xrefstyle='select: title'/> 1865returns the previous after function. 1866</para> 1867<para> 1868<!-- .LP --> 1869To enable or disable synchronization, use 1870<function>XSynchronize</function>. 1871</para> 1872<indexterm><primary>Debugging</primary><secondary>synchronous mode</secondary></indexterm> 1873<indexterm significance="preferred"><primary>XSynchronize</primary></indexterm> 1874<!-- .sM --> 1875<funcsynopsis id='xsynchronize'> 1876<funcprototype> 1877 <funcdef><type>int</type></funcdef> 1878 <paramdef>Display *<parameter>display</parameter></paramdef> 1879 <paramdef>Bool <parameter>onoff</parameter></paramdef> 1880</funcprototype> 1881</funcsynopsis> 1882<!-- .FN --> 1883<variablelist> 1884 <varlistentry> 1885 <term> 1886 <emphasis remap='I'>display</emphasis> 1887 </term> 1888 <listitem> 1889 <para> 1890Specifies the connection to the X server. 1891 </para> 1892 </listitem> 1893 </varlistentry> 1894 <varlistentry> 1895 <term> 1896 <emphasis remap='I'>onoff</emphasis> 1897 </term> 1898 <listitem> 1899 <para> 1900Specifies a Boolean value that indicates whether to enable 1901or disable synchronization. 1902 </para> 1903 </listitem> 1904 </varlistentry> 1905</variablelist> 1906<para> 1907<!-- .LP --> 1908<!-- .eM --> 1909The 1910<function>XSynchronize</function> 1911function returns 1912the previous after function. 1913If onoff is 1914<symbol>True</symbol>, 1915<function>XSynchronize</function> 1916turns on synchronous behavior. 1917If onoff is 1918<symbol>False</symbol>, 1919<function>XSynchronize</function> 1920turns off synchronous behavior. 1921</para> 1922</sect2> 1923<sect2 id="Using_the_Default_Error_Handlers"> 1924<title>Using the Default Error Handlers</title> 1925<!-- .XS --> 1926<!-- (SN Using the Default Error Handlers --> 1927<!-- .XE --> 1928<para> 1929<!-- .LP --> 1930<indexterm><primary>Debugging</primary><secondary>error handlers</secondary></indexterm> 1931<indexterm><primary>Error</primary><secondary>handlers</secondary></indexterm> 1932There are two default error handlers in Xlib: 1933one to handle typically fatal conditions (for example, 1934the connection to a display server dying because a machine crashed) 1935and one to handle protocol errors from the X server. 1936These error handlers can be changed to user-supplied routines if you 1937prefer your own error handling and can be changed as often as you like. 1938If either function is passed a NULL pointer, it will 1939reinvoke the default handler. 1940The action of the default handlers is to print an explanatory 1941message and exit. 1942</para> 1943<para> 1944<!-- .LP --> 1945<!-- .sp --> 1946To set the error handler, use 1947<xref linkend='XSetErrorHandler' xrefstyle='select: title'/>. 1948</para> 1949<indexterm significance="preferred"><primary>XSetErrorHandler</primary></indexterm> 1950<!-- .sM --> 1951<funcsynopsis id='XSetErrorHandler'> 1952<funcprototype> 1953 <funcdef>int *<function>XSetErrorHandler</function></funcdef> 1954 <paramdef>int *<parameter>handler</parameter></paramdef> 1955</funcprototype> 1956</funcsynopsis> 1957<!-- .FN --> 1958<variablelist> 1959 <varlistentry> 1960 <term> 1961 <emphasis remap='I'>handler</emphasis> 1962 </term> 1963 <listitem> 1964 <para> 1965Specifies the program's supplied error handler. 1966 </para> 1967 </listitem> 1968 </varlistentry> 1969</variablelist> 1970<para> 1971<!-- .LP --> 1972<!-- .eM --> 1973Xlib generally calls the program's 1974supplied error handler whenever an error is received. 1975It is not called on 1976<errorname>BadName</errorname> 1977errors from 1978<systemitem>OpenFont</systemitem>, 1979<systemitem>LookupColor</systemitem>, 1980or 1981<systemitem>AllocNamedColor</systemitem> 1982protocol requests or on 1983<errorname>BadFont</errorname> 1984errors from a 1985<systemitem>QueryFont</systemitem> 1986protocol request. 1987These errors generally are reflected back to the program through the 1988procedural interface. 1989Because this condition is not assumed to be fatal, 1990it is acceptable for your error handler to return; 1991the returned value is ignored. 1992However, the error handler should not 1993call any functions (directly or indirectly) on the display 1994that will generate protocol requests or that will look for input events. 1995The previous error handler is returned. 1996</para> 1997<para> 1998<!-- .LP --> 1999The 2000<structname>XErrorEvent</structname> 2001structure contains: 2002<indexterm><primary>Debugging</primary><secondary>error event</secondary></indexterm> 2003</para> 2004<para> 2005<!-- .LP --> 2006<indexterm significance="preferred"><primary>XErrorEvent</primary></indexterm> 2007<literallayout class="monospaced"> 2008<!-- .TA .5i 2.5i --> 2009<!-- .ta .5i 2.5i --> 2010typedef struct { 2011 int type; 2012 Display *display; /* Display the event was read from */ 2013 unsigned long serial; /* serial number of failed request */ 2014 unsigned char error_code; /* error code of failed request */ 2015 unsigned char request_code; /* Major op-code of failed request */ 2016 unsigned char minor_code; /* Minor op-code of failed request */ 2017 XID resourceid; /* resource id */ 2018} XErrorEvent; 2019</literallayout> 2020</para> 2021<para> 2022<!-- .LP --> 2023<indexterm><primary>Serial Number</primary></indexterm> 2024The serial member is the number of requests, starting from one, 2025sent over the network connection since it was opened. 2026It is the number that was the value of 2027<function>NextRequest</function> 2028immediately before the failing call was made. 2029The request_code member is a protocol request 2030of the procedure that failed, as defined in 2031<filename class="headerfile"><X11/Xproto.h></filename>. 2032The following error codes can be returned by the functions described in this 2033chapter: 2034</para> 2035<!-- .br --> 2036<!-- .ne 13 --> 2037<indexterm><primary>Debugging</primary><secondary>error numbers</secondary></indexterm> 2038<indexterm><primary>Error</primary><secondary>codes</secondary></indexterm> 2039<!-- .\".CP T 3 --> 2040<!-- .\"Error Codes --> 2041<indexterm significance="preferred"><primary>BadAccess</primary></indexterm> 2042<indexterm significance="preferred"><primary>BadAlloc</primary></indexterm> 2043<indexterm significance="preferred"><primary>BadAtom</primary></indexterm> 2044<indexterm significance="preferred"><primary>BadColor</primary></indexterm> 2045<indexterm significance="preferred"><primary>BadCursor</primary></indexterm> 2046<indexterm significance="preferred"><primary>BadDrawable</primary></indexterm> 2047<indexterm significance="preferred"><primary>BadFont</primary></indexterm> 2048<indexterm significance="preferred"><primary>BadGC</primary></indexterm> 2049<indexterm significance="preferred"><primary>BadIDChoice</primary></indexterm> 2050<informaltable frame='topbot'> 2051 <?dbfo keep-together="auto" ?> 2052 <tgroup cols='2' align='left' colsep='0' rowsep='0'> 2053 <colspec colname='c1' colwidth='1.0*'/> 2054 <colspec colname='c2' colwidth='3.5*'/> 2055 <thead> 2056 <row rowsep='1'> 2057 <entry>Error Code</entry> 2058 <entry>Description</entry> 2059 </row> 2060 </thead> 2061 <tbody> 2062 <row> 2063 <entry><errorname id='BadAccess'>BadAccess</errorname></entry> 2064 <entry> 2065 <para>A client attempts to grab a key/button combination already grabbed 2066 by another client.</para> 2067 <para>A client attempts to free a colormap entry that it had not already allocated 2068 or to free an entry in a colormap that was created with all entries writable.</para> 2069 <para>A client attempts to store into a read-only or unallocated colormap entry.</para> 2070 <para>A client attempts to modify the access control list from other than the local 2071 (or otherwise authorized) host.</para> 2072 <para>A client attempts to select an event type that another client 2073 has already selected.</para> 2074 </entry> 2075 </row> 2076 <row> 2077 <entry><errorname id='BadAlloc'>BadAlloc</errorname></entry> 2078 <entry>The server fails to allocate the requested resource. 2079 Note that the explicit listing of 2080 <errorname>BadAlloc</errorname> 2081 errors in requests only covers allocation errors at a very coarse level 2082 and is not intended to (nor can it in practice hope to) cover all cases of 2083 a server running out of allocation space in the middle of service. 2084 The semantics when a server runs out of allocation space are left unspecified, 2085 but a server may generate a 2086 <errorname>BadAlloc</errorname> 2087 error on any request for this reason, 2088 and clients should be prepared to receive such errors and handle or discard 2089 them.</entry> 2090 </row> 2091 <row> 2092 <entry><errorname id='BadAtom'>BadAtom</errorname></entry> 2093 <entry>A value for an atom argument does not name a defined atom.</entry> 2094 </row> 2095 <row> 2096 <entry><errorname id='BadColor'>BadColor</errorname></entry> 2097 <entry>A value for a colormap argument does not name a defined colormap.</entry> 2098 </row> 2099 <row> 2100 <entry><errorname id='BadCursor'>BadCursor</errorname></entry> 2101 <entry>A value for a cursor argument does not name a defined cursor.</entry> 2102 </row> 2103 <row> 2104 <entry><errorname id='BadDrawable'>BadDrawable</errorname></entry> 2105 <entry>A value for a drawable argument does not name a defined window or pixmap.</entry> 2106 </row> 2107 <row> 2108 <entry><errorname id='BadFont'>BadFont</errorname></entry> 2109 <entry>A value for a font argument does not name a defined font (or, in some cases, 2110 <type>GContext</type>).</entry> 2111 </row> 2112 <row> 2113 <entry><errorname id='BadGC'>BadGC</errorname></entry> 2114 <entry>A value for a 2115 <type>GContext</type> 2116 argument does not name a defined 2117 <type>GContext</type>.</entry> 2118 </row> 2119 <row> 2120 <entry><errorname id='BadIDChoice'>BadIDChoice</errorname></entry> 2121 <entry>The value chosen for a resource identifier either is not included in the 2122 range assigned to the client or is already in use. 2123 Under normal circumstances, 2124 this cannot occur and should be considered a server or Xlib error.</entry> 2125 </row> 2126 <row> 2127 <entry><errorname id='BadImplementation'>BadImplementation</errorname></entry> 2128 <entry>The server does not implement some aspect of the request. 2129 A server that generates this error for a core request is deficient. 2130 As such, this error is not listed for any of the requests, 2131 but clients should be prepared to receive such errors 2132 and handle or discard them.</entry> 2133 </row> 2134 <row> 2135 <entry><errorname id='BadLength'>BadLength</errorname></entry> 2136 <entry><para>The length of a request is shorter or longer than that required to 2137 contain the arguments. 2138 This is an internal Xlib or server error.</para> 2139 <para>The length of a request exceeds the maximum length accepted by the server.</para> 2140 </entry> 2141 </row> 2142 <row> 2143 <entry><errorname id='BadMatch'>BadMatch</errorname></entry> 2144 <entry><para>In a graphics request, 2145 the root and depth of the graphics context do not match those of the drawable.</para> 2146 <para>An <symbol>InputOnly</symbol> window is used as a drawable.</para> 2147 <para>Some argument or pair of arguments has the correct type and range, 2148 but it fails to match in some other way required by the request.</para> 2149 <para>An <symbol>InputOnly</symbol> 2150 window lacks this attribute.</para> 2151 </entry> 2152 </row> 2153 <row> 2154 <entry><errorname id='BadName'>BadName</errorname></entry> 2155 <entry>A font or color of the specified name does not exist.</entry> 2156 </row> 2157 <row> 2158 <entry><errorname id='BadPixmap'>BadPixmap</errorname></entry> 2159 <entry>A value for a pixmap argument does not name a defined pixmap.</entry> 2160 </row> 2161 <row> 2162 <entry><errorname id='BadRequest'>BadRequest</errorname></entry> 2163 <entry>The major or minor opcode does not specify a valid request. 2164 This usually is an Xlib or server error.</entry> 2165 </row> 2166 <row> 2167 <entry><errorname id='BadValue'>BadValue</errorname></entry> 2168 <entry>Some numeric value falls outside of the range of values accepted 2169 by the request. 2170 Unless a specific range is specified for an argument, 2171 the full range defined by the argument's type is accepted. 2172 Any argument defined as a set of alternatives typically can generate 2173 this error (due to the encoding).</entry> 2174 </row> 2175 <row> 2176 <entry><errorname id='BadWindow'>BadWindow</errorname></entry> 2177 <entry>A value for a window argument does not name a defined window.</entry> 2178 </row> 2179 </tbody> 2180 </tgroup> 2181</informaltable> 2182 2183<indexterm significance="preferred"><primary>BadImplementation</primary></indexterm> 2184<indexterm significance="preferred"><primary>BadLength</primary></indexterm> 2185<indexterm significance="preferred"><primary>BadMatch</primary></indexterm> 2186<indexterm significance="preferred"><primary>BadName</primary></indexterm> 2187<indexterm significance="preferred"><primary>BadPixmap</primary></indexterm> 2188<indexterm significance="preferred"><primary>BadRequest</primary></indexterm> 2189<indexterm significance="preferred"><primary>BadValue</primary></indexterm> 2190<indexterm significance="preferred"><primary>BadWindow</primary></indexterm> 2191<!-- .NT Note --> 2192 2193<note> 2194<para> 2195The 2196<errorname>BadAtom</errorname>, 2197<errorname>BadColor</errorname>, 2198<errorname>BadCursor</errorname>, 2199<errorname>BadDrawable</errorname>, 2200<errorname>BadFont</errorname>, 2201<errorname>BadGC</errorname>, 2202<errorname>BadPixmap</errorname>, 2203and 2204<errorname>BadWindow</errorname> 2205errors are also used when the argument type is extended by a set of 2206fixed alternatives. 2207</para> 2208</note> 2209 2210<!-- .NE --> 2211<!-- .sp --> 2212<para> 2213<!-- .LP --> 2214To obtain textual descriptions of the specified error code, use 2215<xref linkend='XGetErrorText' xrefstyle='select: title'/>. 2216</para> 2217<indexterm significance="preferred"><primary>XGetErrorText</primary></indexterm> 2218<indexterm><primary>Debugging</primary><secondary>error message strings</secondary></indexterm> 2219<!-- .sM --> 2220<funcsynopsis id='XGetErrorText'> 2221<funcprototype> 2222 <funcdef><function>XGetErrorText</function></funcdef> 2223 <paramdef>Display *<parameter>display</parameter></paramdef> 2224 <paramdef>int <parameter>code</parameter></paramdef> 2225 <paramdef>char *<parameter>buffer_return</parameter></paramdef> 2226 <paramdef>int <parameter>length</parameter></paramdef> 2227</funcprototype> 2228</funcsynopsis> 2229<!-- .FN --> 2230<variablelist> 2231 <varlistentry> 2232 <term> 2233 <emphasis remap='I'>display</emphasis> 2234 </term> 2235 <listitem> 2236 <para> 2237Specifies the connection to the X server. 2238 </para> 2239 </listitem> 2240 </varlistentry> 2241 <varlistentry> 2242 <term> 2243 <emphasis remap='I'>code</emphasis> 2244 </term> 2245 <listitem> 2246 <para> 2247Specifies the error code for which you want to obtain a description. 2248 </para> 2249 </listitem> 2250 </varlistentry> 2251 <varlistentry> 2252 <term> 2253 <emphasis remap='I'>buffer_return</emphasis> 2254 </term> 2255 <listitem> 2256 <para> 2257Returns the error description. 2258 </para> 2259 </listitem> 2260 </varlistentry> 2261 <varlistentry> 2262 <term> 2263 <emphasis remap='I'>length</emphasis> 2264 </term> 2265 <listitem> 2266 <para> 2267Specifies the size of the buffer. 2268 </para> 2269 </listitem> 2270 </varlistentry> 2271</variablelist> 2272<para> 2273<!-- .LP --> 2274<!-- .eM --> 2275The 2276<xref linkend='XGetErrorText' xrefstyle='select: title'/> 2277function copies a null-terminated string describing the specified error code 2278into the specified buffer. 2279The returned text is in the encoding of the current locale. 2280It is recommended that you use this function to obtain an error description 2281because extensions to Xlib may define their own error codes 2282and error strings. 2283</para> 2284<para> 2285<!-- .LP --> 2286<!-- .sp --> 2287To obtain error messages from the error database, use 2288<xref linkend='XGetErrorDatabaseText' xrefstyle='select: title'/>. 2289</para> 2290<indexterm significance="preferred"><primary>XGetErrorDatabaseText</primary></indexterm> 2291<!-- .sM --> 2292<funcsynopsis id='XGetErrorDatabaseText'> 2293<funcprototype> 2294 <funcdef><function>XGetErrorDatabaseText</function></funcdef> 2295 <paramdef>Display *<parameter>display</parameter></paramdef> 2296 <paramdef>char *<parameter>name</parameter></paramdef> 2297 <paramdef>char *<parameter>message</parameter></paramdef> 2298 <paramdef>char *<parameter>default_string</parameter></paramdef> 2299 <paramdef>char *<parameter>buffer_return</parameter></paramdef> 2300 <paramdef>int <parameter>length</parameter></paramdef> 2301</funcprototype> 2302</funcsynopsis> 2303<!-- .FN --> 2304<variablelist> 2305 <varlistentry> 2306 <term> 2307 <emphasis remap='I'>display</emphasis> 2308 </term> 2309 <listitem> 2310 <para> 2311Specifies the connection to the X server. 2312 </para> 2313 </listitem> 2314 </varlistentry> 2315 <varlistentry> 2316 <term> 2317 <emphasis remap='I'>name</emphasis> 2318 </term> 2319 <listitem> 2320 <para> 2321Specifies the name of the application. 2322 </para> 2323 </listitem> 2324 </varlistentry> 2325 <varlistentry> 2326 <term> 2327 <emphasis remap='I'>message</emphasis> 2328 </term> 2329 <listitem> 2330 <para> 2331Specifies the type of the error message. 2332 </para> 2333 </listitem> 2334 </varlistentry> 2335 <varlistentry> 2336 <term> 2337 <emphasis remap='I'>default_string</emphasis> 2338 </term> 2339 <listitem> 2340 <para> 2341Specifies the default error message if none is found in the database. 2342 </para> 2343 </listitem> 2344 </varlistentry> 2345 <varlistentry> 2346 <term> 2347 <emphasis remap='I'>buffer_return</emphasis> 2348 </term> 2349 <listitem> 2350 <para> 2351Returns the error description. 2352 </para> 2353 </listitem> 2354 </varlistentry> 2355 <varlistentry> 2356 <term> 2357 <emphasis remap='I'>length</emphasis> 2358 </term> 2359 <listitem> 2360 <para> 2361Specifies the size of the buffer. 2362 </para> 2363 </listitem> 2364 </varlistentry> 2365</variablelist> 2366<para> 2367<!-- .LP --> 2368<!-- .eM --> 2369The 2370<xref linkend='XGetErrorDatabaseText' xrefstyle='select: title'/> 2371function returns a null-terminated message 2372(or the default message) from the error message 2373database. 2374Xlib uses this function internally to look up its error messages. 2375The text in the default_string argument is assumed 2376to be in the encoding of the current locale, 2377and the text stored in the buffer_return argument 2378is in the encoding of the current locale. 2379</para> 2380<para> 2381<!-- .LP --> 2382The name argument should generally be the name of your application. 2383The message argument should indicate which type of error message you want. 2384If the name and message are not in the Host Portable Character Encoding, 2385the result is implementation-dependent. 2386Xlib uses three predefined ``application names'' to report errors. 2387In these names, 2388uppercase and lowercase matter. 2389<variablelist> 2390 <varlistentry> 2391 <term> 2392 XProtoError 2393 </term> 2394 <listitem> 2395 <para> 2396The protocol error number is used as a string for the message argument. 2397 </para> 2398 </listitem> 2399 </varlistentry> 2400 <varlistentry> 2401 <term> 2402 XlibMessage 2403 </term> 2404 <listitem> 2405 <para> 2406These are the message strings that are used internally by the library. 2407 </para> 2408 </listitem> 2409 </varlistentry> 2410 <varlistentry> 2411 <term> 2412 XRequest 2413 </term> 2414 <listitem> 2415 <para> 2416For a core protocol request, 2417the major request protocol number is used for the message argument. 2418For an extension request, 2419the extension name (as given by 2420<function>InitExtension</function>) 2421followed by a period (.) and the minor request protocol number 2422is used for the message argument. 2423If no string is found in the error database, 2424the default_string is returned to the buffer argument. 2425 </para> 2426 </listitem> 2427 </varlistentry> 2428</variablelist> 2429</para> 2430<para> 2431<!-- .LP --> 2432<!-- .sp --> 2433To report an error to the user when the requested display does not exist, use 2434<xref linkend='XDisplayName' xrefstyle='select: title'/>. 2435</para> 2436<indexterm significance="preferred"><primary>XDisplayName</primary></indexterm> 2437<!-- .sM --> 2438<funcsynopsis id='XDisplayName'> 2439<funcprototype> 2440 <funcdef>char *<function>XDisplayName</function></funcdef> 2441 <paramdef>char *<parameter>string</parameter></paramdef> 2442</funcprototype> 2443</funcsynopsis> 2444<!-- .FN --> 2445<variablelist> 2446 <varlistentry> 2447 <term> 2448 <emphasis remap='I'>string</emphasis> 2449 </term> 2450 <listitem> 2451 <para> 2452Specifies the character string. 2453 </para> 2454 </listitem> 2455 </varlistentry> 2456</variablelist> 2457<para> 2458<!-- .LP --> 2459<!-- .eM --> 2460The 2461<xref linkend='XDisplayName' xrefstyle='select: title'/> 2462function returns the name of the display that 2463<xref linkend='XOpenDisplay' xrefstyle='select: title'/> 2464would attempt to use. 2465If a NULL string is specified, 2466<xref linkend='XDisplayName' xrefstyle='select: title'/> 2467looks in the environment for the display and returns the display name that 2468<xref linkend='XOpenDisplay' xrefstyle='select: title'/> 2469would attempt to use. 2470This makes it easier to report to the user precisely which display the 2471program attempted to open when the initial connection attempt failed. 2472</para> 2473<para> 2474<!-- .LP --> 2475<!-- .sp --> 2476To handle fatal I/O errors, use 2477<function>XSetIOErrorHandler</function>. 2478</para> 2479<indexterm significance="preferred"><primary>XSetIOErrorHandler</primary></indexterm> 2480<!-- .sM --> 2481<funcsynopsis id='xsetioerrorhandler'> 2482<funcprototype> 2483 <funcdef><type>int</type></funcdef> 2484 <paramdef>int(*handler)(Display *<parameter>)</parameter></paramdef> 2485</funcprototype> 2486</funcsynopsis> 2487<!-- .FN --> 2488<variablelist> 2489 <varlistentry> 2490 <term> 2491 <emphasis remap='I'>handler</emphasis> 2492 </term> 2493 <listitem> 2494 <para> 2495Specifies the program's supplied error handler. 2496 </para> 2497 </listitem> 2498 </varlistentry> 2499</variablelist> 2500<para> 2501<!-- .LP --> 2502<!-- .eM --> 2503The 2504<function>XSetIOErrorHandler</function> 2505sets the fatal I/O error handler. 2506Xlib calls the program's supplied error handler if any sort of system call 2507error occurs (for example, the connection to the server was lost). 2508This is assumed to be a fatal condition, 2509and the called routine should not return. 2510If the I/O error handler does return, 2511the client process exits. 2512</para> 2513<para> 2514<!-- .LP --> 2515Note that the previous error handler is returned. 2516<!-- .bp --> 2517 2518</para> 2519</sect2> 2520</sect1> 2521</chapter> 2522