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