~ubuntu-branches/ubuntu/wily/libx11/wily-proposed

« back to all changes in this revision

Viewing changes to specs/libX11/CH16.xml

  • Committer: Bazaar Package Importer
  • Author(s): Timo Aaltonen
  • Date: 2011-02-24 12:02:14 UTC
  • mfrom: (1.1.12 upstream) (2.1.12 sid)
  • Revision ID: james.westby@ubuntu.com-20110224120214-a86d0lv48wk8itl6
Tags: 2:1.4.1-5ubuntu1
* Merge from debian unstable.  Remaining changes:
  - Add Latin locale.
  - Add Klingon locale.
  - Add 102_double_arrows_Compose.patch: compose keys for double arrows
    (LP: 680143)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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="application_utility_functions">
 
5
<title>Application Utility Functions</title>
 
6
<!-- .sp 2 -->
 
7
<!-- .nr H1 16 -->
 
8
<!-- .nr H2 0 -->
 
9
<!-- .nr H3 0 -->
 
10
<!-- .nr H4 0 -->
 
11
<!-- .nr H5 0 -->
 
12
<!-- .na -->
 
13
<para>
 
14
<!-- .LP -->
 
15
<!-- .XS -->
 
16
<!-- Chapter 16: Application Utility Functions  -->
 
17
<!-- .XE -->
 
18
Once you have initialized the X system,
 
19
you can use the Xlib utility functions to:
 
20
</para>
 
21
<itemizedlist>
 
22
  <listitem>
 
23
    <para>
 
24
Use keyboard utility functions
 
25
    </para>
 
26
  </listitem>
 
27
  <listitem>
 
28
    <para>
 
29
Use Latin-1 keyboard event functions
 
30
    </para>
 
31
  </listitem>
 
32
  <listitem>
 
33
    <para>
 
34
Allocate permanent storage
 
35
    </para>
 
36
  </listitem>
 
37
  <listitem>
 
38
    <para>
 
39
Parse the window geometry
 
40
    </para>
 
41
  </listitem>
 
42
  <listitem>
 
43
    <para>
 
44
Manipulate regions
 
45
    </para>
 
46
  </listitem>
 
47
  <listitem>
 
48
    <para>
 
49
Use cut buffers
 
50
    </para>
 
51
  </listitem>
 
52
  <listitem>
 
53
    <para>
 
54
Determine the appropriate visual type
 
55
    </para>
 
56
  </listitem>
 
57
  <listitem>
 
58
    <para>
 
59
Manipulate images
 
60
    </para>
 
61
  </listitem>
 
62
  <listitem>
 
63
    <para>
 
64
Manipulate bitmaps
 
65
    </para>
 
66
  </listitem>
 
67
  <listitem>
 
68
    <para>
 
69
Use the context manager
 
70
    </para>
 
71
  </listitem>
 
72
</itemizedlist>
 
73
<para>
 
74
<!-- .LP -->
 
75
As a group,
 
76
the functions discussed in this chapter provide the functionality that 
 
77
is frequently needed and that spans toolkits.
 
78
Many of these functions do not generate actual protocol requests to the server.
 
79
</para>
 
80
<sect1 id="Using_Keyboard_Utility_Functions">
 
81
<title>Using Keyboard Utility Functions</title>
 
82
<!-- .XS -->
 
83
<!-- (SN Using Keyboard Utility Functions  -->
 
84
<!-- .XE -->
 
85
<para>
 
86
<!-- .LP -->
 
87
This section discusses mapping between KeyCodes and KeySyms,
 
88
classifying KeySyms, and mapping between KeySyms and string names.
 
89
The first three functions in this section operate on a cached copy of the
 
90
server keyboard mapping.
 
91
The first four KeySyms for each KeyCode
 
92
are modified according to the rules given in section 12.7.
 
93
To obtain the untransformed KeySyms defined for a key,
 
94
use the functions described in section 12.7.
 
95
</para>
 
96
<para>
 
97
<!-- .LP -->
 
98
<!-- .sp -->
 
99
To obtain a KeySym for the KeyCode of an event, use
 
100
<function>XLookupKeysym</function>.
 
101
<indexterm significance="preferred"><primary>XLookupKeysym</primary></indexterm>
 
102
<!-- .sM -->
 
103
<funcsynopsis>
 
104
<funcprototype>
 
105
  <funcdef>KeySym <function>XLookupKeysym</function></funcdef>
 
106
  <paramdef>XKeyEvent<parameter> *key_event</parameter></paramdef>
 
107
  <paramdef>int<parameter> index</parameter></paramdef>
 
108
</funcprototype>
 
109
</funcsynopsis>
 
110
<!-- .FN -->
 
111
<variablelist>
 
112
  <varlistentry>
 
113
    <term>
 
114
      <emphasis remap='I'>key_event</emphasis>
 
115
    </term>
 
116
    <listitem>
 
117
      <para>
 
118
Specifies the 
 
119
<symbol>KeyPress</symbol>
 
120
or
 
121
<symbol>KeyRelease</symbol>
 
122
event.
 
123
      </para>
 
124
    </listitem>
 
125
  </varlistentry>
 
126
  <varlistentry>
 
127
    <term>
 
128
      <emphasis remap='I'>index</emphasis>
 
129
    </term>
 
130
    <listitem>
 
131
      <para>
 
132
Specifies the index into the KeySyms list for the event's KeyCode.
 
133
    </para>
 
134
  </listitem>
 
135
  </varlistentry>
 
136
</variablelist>
 
137
</para>
 
138
<para>
 
139
<!-- .LP -->
 
140
<!-- .eM -->
 
141
The
 
142
<function>XLookupKeysym</function>
 
143
function uses a given keyboard event and the index you specified to return
 
144
the KeySym from the list that corresponds to the KeyCode member in the
 
145
<type>XKeyPressedEvent</type>
 
146
or
 
147
<type>XKeyReleasedEvent</type>
 
148
structure.
 
149
If no KeySym is defined for the KeyCode of the event,
 
150
<function>XLookupKeysym</function>
 
151
returns
 
152
<symbol>NoSymbol</symbol>.
 
153
</para>
 
154
<para>
 
155
<!-- .LP -->
 
156
<!-- .sp -->
 
157
To obtain a KeySym for a specific KeyCode, use
 
158
<function>XKeycodeToKeysym</function>.
 
159
<indexterm significance="preferred"><primary>XKeycodeToKeysym</primary></indexterm>
 
160
<!-- .sM -->
 
161
<funcsynopsis>
 
162
<funcprototype>
 
163
  <funcdef>KeySym <function>XKeycodeToKeysym</function></funcdef>
 
164
  <paramdef>Display<parameter> *display</parameter></paramdef>
 
165
  <paramdef>KeyCode<parameter> keycode</parameter></paramdef>
 
166
  <paramdef>int<parameter> index</parameter></paramdef>
 
167
</funcprototype>
 
168
</funcsynopsis>
 
169
<!-- .FN -->
 
170
<variablelist>
 
171
  <varlistentry>
 
172
    <term>
 
173
      <emphasis remap='I'>display</emphasis>
 
174
    </term>
 
175
    <listitem>
 
176
      <para>
 
177
Specifies the connection to the X server.
 
178
      </para>
 
179
    </listitem>
 
180
  </varlistentry>
 
181
  <varlistentry>
 
182
    <term>
 
183
      <emphasis remap='I'>keycode</emphasis>
 
184
    </term>
 
185
    <listitem>
 
186
      <para>
 
187
Specifies the KeyCode.
 
188
      </para>
 
189
    </listitem>
 
190
  </varlistentry>
 
191
  <varlistentry>
 
192
    <term>
 
193
      <emphasis remap='I'>index</emphasis>
 
194
    </term>
 
195
    <listitem>
 
196
      <para>
 
197
Specifies the element of KeyCode vector.
 
198
    </para>
 
199
  </listitem>
 
200
  </varlistentry>
 
201
</variablelist>
 
202
</para>
 
203
<para>
 
204
<!-- .LP -->
 
205
<!-- .eM -->
 
206
The
 
207
<function>XKeycodeToKeysym</function>
 
208
function uses internal Xlib tables
 
209
and returns the KeySym defined for the specified KeyCode and
 
210
the element of the KeyCode vector.
 
211
If no symbol is defined,
 
212
<function>XKeycodeToKeysym</function>
 
213
returns
 
214
<symbol>NoSymbol</symbol>.
 
215
</para>
 
216
<para>
 
217
<!-- .LP -->
 
218
<!-- .sp -->
 
219
To obtain a KeyCode for a key having a specific KeySym, use
 
220
<function>XKeysymToKeycode</function>.
 
221
<indexterm significance="preferred"><primary>XKeysymToKeycode</primary></indexterm>
 
222
<!-- .sM -->
 
223
<funcsynopsis>
 
224
<funcprototype>
 
225
  <funcdef>KeyCode <function>XKeysymToKeycode</function></funcdef>
 
226
  <paramdef>Display<parameter> *display</parameter></paramdef>
 
227
  <paramdef>KeySym<parameter> keysym</parameter></paramdef>
 
228
</funcprototype>
 
229
</funcsynopsis>
 
230
<!-- .FN -->
 
231
<variablelist>
 
232
  <varlistentry>
 
233
    <term>
 
234
      <emphasis remap='I'>display</emphasis>
 
235
    </term>
 
236
    <listitem>
 
237
      <para>
 
238
Specifies the connection to the X server.
 
239
      </para>
 
240
    </listitem>
 
241
  </varlistentry>
 
242
  <varlistentry>
 
243
    <term>
 
244
      <emphasis remap='I'>keysym</emphasis>
 
245
    </term>
 
246
    <listitem>
 
247
      <para>
 
248
Specifies the KeySym that is to be searched for.
 
249
    </para>
 
250
  </listitem>
 
251
  </varlistentry>
 
252
</variablelist>
 
253
</para>
 
254
<para>
 
255
<!-- .LP -->
 
256
<!-- .eM -->
 
257
If the specified KeySym is not defined for any KeyCode,
 
258
<function>XKeysymToKeycode</function>
 
259
returns zero.
 
260
</para>
 
261
<para>
 
262
<!-- .LP -->
 
263
<!-- .sp -->
 
264
The mapping between KeyCodes and KeySyms is cached internal to Xlib.
 
265
When this information is changed at the server, an Xlib function must
 
266
be called to refresh the cache.
 
267
To refresh the stored modifier and keymap information, use
 
268
<function>XRefreshKeyboardMapping</function>.
 
269
<indexterm significance="preferred"><primary>XRefreshKeyboardMapping</primary></indexterm>
 
270
<!-- .sM -->
 
271
<funcsynopsis>
 
272
<funcprototype>
 
273
  <funcdef><function>XRefreshKeyboardMapping</function></funcdef>
 
274
  <paramdef>XMappingEvent<parameter> *event_map</parameter></paramdef>
 
275
</funcprototype>
 
276
</funcsynopsis>
 
277
<!-- .FN -->
 
278
<variablelist>
 
279
  <varlistentry>
 
280
    <term>
 
281
      <emphasis remap='I'>event_map</emphasis>
 
282
    </term>
 
283
    <listitem>
 
284
      <para>
 
285
Specifies the mapping event that is to be used.
 
286
    </para>
 
287
  </listitem>
 
288
  </varlistentry>
 
289
</variablelist>
 
290
</para>
 
291
<para>
 
292
<!-- .LP -->
 
293
<!-- .eM -->
 
294
The
 
295
<function>XRefreshKeyboardMapping</function>
 
296
function refreshes the stored modifier and keymap information.
 
297
You usually call this function when a
 
298
<symbol>MappingNotify</symbol>
 
299
event with a request member of
 
300
<symbol>MappingKeyboard</symbol>
 
301
or
 
302
<symbol>MappingModifier</symbol>
 
303
occurs.
 
304
The result is to update Xlib's knowledge of the keyboard.
 
305
</para>
 
306
<para>
 
307
<!-- .LP -->
 
308
<!-- .sp -->
 
309
To obtain the uppercase and lowercase forms of a KeySym, use
 
310
<function>XConvertCase</function>.
 
311
<indexterm significance="preferred"><primary>XConvertCase</primary></indexterm>
 
312
<!-- .sM -->
 
313
<funcsynopsis>
 
314
<funcprototype>
 
315
  <funcdef>void <function>XConvertCase</function></funcdef>
 
316
  <paramdef>KeySym<parameter> keysym</parameter></paramdef>
 
317
  <paramdef>KeySym<parameter> *lower_return</parameter></paramdef>
 
318
  <paramdef>KeySym<parameter> *upper_return</parameter></paramdef>
 
319
</funcprototype>
 
320
</funcsynopsis>
 
321
<!-- .FN -->
 
322
<!-- .ds Fn converted -->
 
323
<variablelist>
 
324
  <varlistentry>
 
325
    <term>
 
326
      <emphasis remap='I'>keysym</emphasis>
 
327
    </term>
 
328
    <listitem>
 
329
      <para>
 
330
Specifies the KeySym that is to be (Fn.
 
331
      </para>
 
332
    </listitem>
 
333
  </varlistentry>
 
334
  <varlistentry>
 
335
    <term>
 
336
      <emphasis remap='I'>lower_return</emphasis>
 
337
    </term>
 
338
    <listitem>
 
339
      <para>
 
340
Returns the lowercase form of keysym, or keysym.
 
341
      </para>
 
342
    </listitem>
 
343
  </varlistentry>
 
344
  <varlistentry>
 
345
    <term>
 
346
      <emphasis remap='I'>upper_return</emphasis>
 
347
    </term>
 
348
    <listitem>
 
349
      <para>
 
350
Returns the uppercase form of keysym, or keysym.
 
351
    </para>
 
352
  </listitem>
 
353
  </varlistentry>
 
354
</variablelist>
 
355
</para>
 
356
<para>
 
357
<!-- .LP -->
 
358
<!-- .eM -->
 
359
The
 
360
<function>XConvertCase</function>
 
361
function returns the uppercase and lowercase forms of the specified Keysym,
 
362
if the KeySym is subject to case conversion;
 
363
otherwise, the specified KeySym is returned to both lower_return and
 
364
upper_return.
 
365
Support for conversion of other than Latin and Cyrillic KeySyms is
 
366
implementation-dependent.
 
367
</para>
 
368
<para>
 
369
<!-- .LP -->
 
370
<!-- .sp -->
 
371
KeySyms have string names as well as numeric codes.
 
372
To convert the name of the KeySym to the KeySym code, use
 
373
<function>XStringToKeysym</function>.
 
374
<indexterm significance="preferred"><primary>XStringToKeysym</primary></indexterm>
 
375
<!-- .sM -->
 
376
<funcsynopsis>
 
377
<funcprototype>
 
378
  <funcdef>KeySym <function>XStringToKeysym</function></funcdef>
 
379
  <paramdef>char<parameter> *string</parameter></paramdef>
 
380
</funcprototype>
 
381
</funcsynopsis>
 
382
<!-- .FN -->
 
383
<variablelist>
 
384
  <varlistentry>
 
385
    <term>
 
386
      <emphasis remap='I'>string</emphasis>
 
387
    </term>
 
388
    <listitem>
 
389
      <para>
 
390
Specifies the name of the KeySym that is to be converted.
 
391
    </para>
 
392
  </listitem>
 
393
  </varlistentry>
 
394
</variablelist>
 
395
</para>
 
396
<para>
 
397
<!-- .LP -->
 
398
<!-- .eM -->
 
399
Standard KeySym names are obtained from
 
400
<filename class="headerfile">&lt;X11/keysymdef.h&gt;</filename>
 
401
<indexterm type="file"><primary><filename class="headerfile">X11/keysymdef.h</filename></primary></indexterm>
 
402
<indexterm><primary>Files</primary><secondary><filename class="headerfile">&lt;X11/keysymdef.h&gt;</filename></secondary></indexterm>
 
403
<indexterm><primary>Headers</primary><secondary><filename class="headerfile">&lt;X11/keysymdef.h&gt;</filename></secondary></indexterm>
 
404
by removing the XK_ prefix from each name.
 
405
KeySyms that are not part of the Xlib standard also may be obtained
 
406
with this function.
 
407
The set of KeySyms that are available in this manner 
 
408
and the mechanisms by which Xlib obtains them is implementation-dependent.
 
409
</para>
 
410
<para>
 
411
<!-- .LP -->
 
412
If the KeySym name is not in the Host Portable Character Encoding,
 
413
the result is implementation-dependent.
 
414
If the specified string does not match a valid KeySym,
 
415
<function>XStringToKeysym</function>
 
416
returns
 
417
<symbol>NoSymbol</symbol>.
 
418
</para>
 
419
<para>
 
420
<!-- .LP -->
 
421
<!-- .sp -->
 
422
To convert a KeySym code to the name of the KeySym, use
 
423
<function>XKeysymToString</function>.
 
424
<indexterm significance="preferred"><primary>XKeysymToString</primary></indexterm>
 
425
<!-- .sM -->
 
426
<funcsynopsis>
 
427
<funcprototype>
 
428
  <funcdef>char *<function>XKeysymToString</function></funcdef>
 
429
  <paramdef>KeySym<parameter> keysym</parameter></paramdef>
 
430
</funcprototype>
 
431
</funcsynopsis>
 
432
<!-- .FN -->
 
433
<!-- .ds Fn converted -->
 
434
<variablelist>
 
435
  <varlistentry>
 
436
    <term>
 
437
      <emphasis remap='I'>keysym</emphasis>
 
438
    </term>
 
439
    <listitem>
 
440
      <para>
 
441
Specifies the KeySym that is to be (Fn.
 
442
    </para>
 
443
  </listitem>
 
444
  </varlistentry>
 
445
</variablelist>
 
446
</para>
 
447
<para>
 
448
<!-- .LP -->
 
449
<!-- .eM -->
 
450
The returned string is in a static area and must not be modified.
 
451
The returned string is in the Host Portable Character Encoding.
 
452
If the specified KeySym is not defined,
 
453
<function>XKeysymToString</function>
 
454
returns a NULL.
 
455
</para>
 
456
<sect2 id="KeySym_Classification_Macros">
 
457
<title>KeySym Classification Macros</title>
 
458
<!-- .XS -->
 
459
<!-- (SN KeySym Classification Macros -->
 
460
<!-- .XE -->
 
461
<para>
 
462
<!-- .LP -->
 
463
You may want to test if a KeySym is, for example, 
 
464
on the keypad or on one of the function keys.
 
465
You can use KeySym macros to perform the following tests.
 
466
</para>
 
467
<para>IsCursorKey(<emphasis remap='I'>keysym</emphasis>)</para>
 
468
<!-- .FN -->
 
469
<!-- .ds Fn tested -->
 
470
<variablelist>
 
471
  <varlistentry>
 
472
    <term>
 
473
      <emphasis remap='I'>keysym</emphasis>
 
474
    </term>
 
475
    <listitem>
 
476
      <para>
 
477
Specifies the KeySym that is to be tested.
 
478
    </para>
 
479
  </listitem>
 
480
  </varlistentry>
 
481
</variablelist>
 
482
 
 
483
<para>
 
484
<!-- .LP -->
 
485
<!-- .eM -->
 
486
<indexterm significance="preferred"><primary>IsCursorKey</primary></indexterm>
 
487
Returns
 
488
<symbol>True</symbol>
 
489
if the specified KeySym is a cursor key.
 
490
</para>
 
491
<!-- .LP -->
 
492
<!-- .sp -->
 
493
<!-- .sM -->
 
494
<para>IsFunctionKey(<emphasis remap='I'>keysym</emphasis>)</para>
 
495
<!-- .FN -->
 
496
<!-- .ds Fn tested -->
 
497
<variablelist>
 
498
  <varlistentry>
 
499
    <term>
 
500
      <emphasis remap='I'>keysym</emphasis>
 
501
    </term>
 
502
    <listitem>
 
503
      <para>
 
504
Specifies the KeySym that is to be tested.
 
505
    </para>
 
506
  </listitem>
 
507
  </varlistentry>
 
508
</variablelist>
 
509
 
 
510
<para>
 
511
<!-- .LP -->
 
512
<!-- .eM -->
 
513
<indexterm significance="preferred"><primary>IsFunctionKey</primary></indexterm>
 
514
Returns 
 
515
<symbol>True</symbol>
 
516
if the specified KeySym is a function key.
 
517
</para>
 
518
<!-- .LP -->
 
519
<!-- .sp -->
 
520
<!-- .sM -->
 
521
<para>IsKeypadKey(<emphasis remap='I'>keysym</emphasis>)</para>
 
522
<!-- .FN -->
 
523
<!-- .ds Fn tested -->
 
524
<variablelist>
 
525
  <varlistentry>
 
526
    <term>
 
527
      <emphasis remap='I'>keysym</emphasis>
 
528
    </term>
 
529
    <listitem>
 
530
      <para>
 
531
Specifies the KeySym that is to be (Fn.
 
532
    </para>
 
533
  </listitem>
 
534
  </varlistentry>
 
535
</variablelist>
 
536
 
 
537
<para>
 
538
<!-- .LP -->
 
539
<!-- .eM -->
 
540
<indexterm significance="preferred"><primary>IsKeypadKey</primary></indexterm>
 
541
Returns
 
542
<symbol>True</symbol>
 
543
if the specified KeySym is a standard keypad key.
 
544
</para>
 
545
<!-- .LP -->
 
546
<!-- .sp -->
 
547
<!-- .sM -->
 
548
<para>IsPrivateKeypadKey(<emphasis remap='I'>keysym</emphasis>)</para>
 
549
 
 
550
<variablelist>
 
551
  <varlistentry>
 
552
    <term>
 
553
      <emphasis remap='I'>keysym</emphasis>
 
554
    </term>
 
555
    <listitem>
 
556
      <para>
 
557
Specifies the KeySym that is to be (Fn.
 
558
    </para>
 
559
  </listitem>
 
560
  </varlistentry>
 
561
</variablelist>
 
562
 
 
563
<para>
 
564
<!-- .LP -->
 
565
<!-- .eM -->
 
566
<indexterm significance="preferred"><primary>IsPrivateKeypadKey</primary></indexterm>
 
567
Returns
 
568
<symbol>True</symbol>
 
569
if the specified KeySym is a vendor-private keypad key.
 
570
</para>
 
571
 
 
572
<!-- .LP -->
 
573
<!-- .sp -->
 
574
<!-- .sM -->
 
575
<para>IsMiscFunctionKey(<emphasis remap='I'>keysym</emphasis>)</para>
 
576
<!-- .FN -->
 
577
<!-- .ds Fn tested -->
 
578
<variablelist>
 
579
  <varlistentry>
 
580
    <term>
 
581
      <emphasis remap='I'>keysym</emphasis>
 
582
    </term>
 
583
    <listitem>
 
584
      <para>
 
585
Specifies the KeySym that is to be (Fn.
 
586
    </para>
 
587
  </listitem>
 
588
  </varlistentry>
 
589
</variablelist>
 
590
 
 
591
<para>
 
592
<!-- .LP -->
 
593
<!-- .eM -->
 
594
<indexterm significance="preferred"><primary>IsMiscFunctionKey</primary></indexterm>
 
595
Returns 
 
596
<symbol>True</symbol>
 
597
if the specified KeySym is a miscellaneous function key.
 
598
</para>
 
599
<!-- .LP -->
 
600
<!-- .sp -->
 
601
<!-- .sM -->
 
602
<para>IsModifierKey(<emphasis remap='I'>keysym</emphasis>)</para>
 
603
 
 
604
<variablelist>
 
605
  <varlistentry>
 
606
    <term>
 
607
      <emphasis remap='I'>keysym</emphasis>
 
608
    </term>
 
609
    <listitem>
 
610
      <para>
 
611
Specifies the KeySym that is to be tested.
 
612
    </para>
 
613
  </listitem>
 
614
  </varlistentry>
 
615
</variablelist>
 
616
 
 
617
<para>
 
618
<!-- .LP -->
 
619
<!-- .eM -->
 
620
<indexterm significance="preferred"><primary>IsModifierKey</primary></indexterm>
 
621
Returns 
 
622
<symbol>True</symbol>
 
623
if the specified KeySym is a modifier key.
 
624
</para>
 
625
 
 
626
<para>IsPFKey(<emphasis remap='I'>keysym</emphasis>)</para>
 
627
 
 
628
<variablelist>
 
629
  <varlistentry>
 
630
    <term>
 
631
      <emphasis remap='I'>keysym</emphasis>
 
632
    </term>
 
633
    <listitem>
 
634
      <para>
 
635
Specifies the KeySym that is to be tested.
 
636
    </para>
 
637
  </listitem>
 
638
  </varlistentry>
 
639
</variablelist>
 
640
 
 
641
<para>
 
642
<!-- .LP -->
 
643
<!-- .eM -->
 
644
<indexterm significance="preferred"><primary>IsPFKey</primary></indexterm>
 
645
Returns 
 
646
<symbol>True</symbol>
 
647
if the specified KeySym is a PF key.
 
648
</para>
 
649
</sect2>
 
650
</sect1>
 
651
<sect1 id="Using_Latin_Keyboard_Event_Functions">
 
652
<title>Using Latin-1 Keyboard Event Functions</title>
 
653
<!-- .XS -->
 
654
<!-- (SN Using Latin-1 Keyboard Event Functions  -->
 
655
<!-- .XE -->
 
656
<para>
 
657
<!-- .LP -->
 
658
Chapter 13 describes internationalized text input facilities,
 
659
but sometimes it is expedient to write an application that
 
660
only deals with Latin-1 characters and ASCII controls,
 
661
so Xlib provides a simple function for that purpose.
 
662
<function>XLookupString</function>
 
663
handles the standard modifier semantics described in section 12.7.
 
664
This function does not use any of the input method facilities
 
665
described in chapter 13 and does not depend on the current locale.
 
666
</para>
 
667
<para>
 
668
<!-- .LP -->
 
669
<!-- .sp -->
 
670
To map a key event to an ISO Latin-1 string, use
 
671
<function>XLookupString</function>.
 
672
<indexterm significance="preferred"><primary>XLookupString</primary></indexterm>
 
673
<!-- .sM -->
 
674
<funcsynopsis>
 
675
<funcprototype>
 
676
  <funcdef>int <function>XLookupString</function></funcdef>
 
677
  <paramdef>XKeyEvent<parameter> *event_struct</parameter></paramdef>
 
678
  <paramdef>char<parameter> *buffer_return</parameter></paramdef>
 
679
  <paramdef>int<parameter> bytes_buffer</parameter></paramdef>
 
680
  <paramdef>KeySym<parameter> *keysym_return</parameter></paramdef>
 
681
  <paramdef>XComposeStatus<parameter> *status_in_out</parameter></paramdef>
 
682
</funcprototype>
 
683
</funcsynopsis>
 
684
<!-- .FN -->
 
685
<variablelist>
 
686
  <varlistentry>
 
687
    <term>
 
688
      <emphasis remap='I'>event_struct</emphasis>
 
689
    </term>
 
690
    <listitem>
 
691
      <para>
 
692
Specifies the key event structure to be used.
 
693
You can pass
 
694
<type>XKeyPressedEvent</type>
 
695
or
 
696
<type>XKeyReleasedEvent</type>.
 
697
      </para>
 
698
    </listitem>
 
699
  </varlistentry>
 
700
  <varlistentry>
 
701
    <term>
 
702
      <emphasis remap='I'>buffer_return</emphasis>
 
703
    </term>
 
704
    <listitem>
 
705
      <para>
 
706
Returns the translated characters.
 
707
      </para>
 
708
    </listitem>
 
709
  </varlistentry>
 
710
  <varlistentry>
 
711
    <term>
 
712
      <emphasis remap='I'>bytes_buffer</emphasis>
 
713
    </term>
 
714
    <listitem>
 
715
      <para>
 
716
Specifies the length of the buffer.
 
717
No more than bytes_buffer of translation are returned.
 
718
      </para>
 
719
    </listitem>
 
720
  </varlistentry>
 
721
  <varlistentry>
 
722
    <term>
 
723
      <emphasis remap='I'>keysym_return</emphasis>
 
724
    </term>
 
725
    <listitem>
 
726
      <para>
 
727
Returns the KeySym computed from the event if this argument is not NULL.
 
728
      </para>
 
729
    </listitem>
 
730
  </varlistentry>
 
731
  <varlistentry>
 
732
    <term>
 
733
      <emphasis remap='I'>status_in_out</emphasis>
 
734
    </term>
 
735
    <listitem>
 
736
      <para>
 
737
Specifies or returns the 
 
738
<structname>XComposeStatus</structname>
 
739
structure or NULL.
 
740
    </para>
 
741
  </listitem>
 
742
  </varlistentry>
 
743
</variablelist>
 
744
</para>
 
745
<para>
 
746
<!-- .LP -->
 
747
<!-- .eM -->
 
748
The
 
749
<function>XLookupString</function>
 
750
function translates a key event to a KeySym and a string.
 
751
The KeySym is obtained by using the standard interpretation of the
 
752
<symbol>Shift</symbol>,
 
753
<symbol>Lock</symbol>,
 
754
group, and numlock modifiers as defined in the X Protocol specification.
 
755
If the KeySym has been rebound (see
 
756
<function>XRebindKeysym</function>),
 
757
the bound string will be stored in the buffer.
 
758
Otherwise, the KeySym is mapped, if possible, to an ISO Latin-1 character
 
759
or (if the Control modifier is on) to an ASCII control character,
 
760
and that character is stored in the buffer.
 
761
<function>XLookupString</function>
 
762
returns the number of characters that are stored in the buffer.
 
763
</para>
 
764
<para>
 
765
<!-- .LP -->
 
766
If present (non-NULL),
 
767
the
 
768
<structname>XComposeStatus</structname>
 
769
structure records the state,
 
770
which is private to Xlib,
 
771
that needs preservation across calls to
 
772
<function>XLookupString</function>
 
773
to implement compose processing.
 
774
The creation of
 
775
<structname>XComposeStatus</structname>
 
776
structures is implementation-dependent;
 
777
a portable program must pass NULL for this argument.
 
778
</para>
 
779
<para>
 
780
<!-- .LP -->
 
781
<function>XLookupString</function>
 
782
depends on the cached keyboard information mentioned in the
 
783
previous section, so it is necessary to use
 
784
<function>XRefreshKeyboardMapping</function>
 
785
to keep this information up-to-date.
 
786
</para>
 
787
<para>
 
788
<!-- .LP -->
 
789
<!-- .sp -->
 
790
To rebind the meaning of a KeySym for
 
791
<function>XLookupString</function>,
 
792
use
 
793
<function>XRebindKeysym</function>.
 
794
<indexterm significance="preferred"><primary>XRebindKeysym</primary></indexterm>
 
795
<!-- .sM -->
 
796
<funcsynopsis>
 
797
<funcprototype>
 
798
  <funcdef><function>XRebindKeysym</function></funcdef>
 
799
  <paramdef>Display<parameter> *display</parameter></paramdef>
 
800
  <paramdef>KeySym<parameter> keysym</parameter></paramdef>
 
801
  <paramdef>KeySym<parameter> list[&hairsp;]</parameter></paramdef>
 
802
  <paramdef>int<parameter> mod_count</parameter></paramdef>
 
803
  <paramdef>unsignedchar<parameter> *string</parameter></paramdef>
 
804
  <paramdef>int<parameter> num_bytes</parameter></paramdef>
 
805
</funcprototype>
 
806
</funcsynopsis>
 
807
<!-- .FN -->
 
808
<variablelist>
 
809
  <varlistentry>
 
810
    <term>
 
811
      <emphasis remap='I'>display</emphasis>
 
812
    </term>
 
813
    <listitem>
 
814
      <para>
 
815
Specifies the connection to the X server.
 
816
<!-- .ds Fn rebound -->
 
817
      </para>
 
818
    </listitem>
 
819
  </varlistentry>
 
820
  <varlistentry>
 
821
    <term>
 
822
      <emphasis remap='I'>keysym</emphasis>
 
823
    </term>
 
824
    <listitem>
 
825
      <para>
 
826
Specifies the KeySym that is to be (Fn.
 
827
      </para>
 
828
    </listitem>
 
829
  </varlistentry>
 
830
  <varlistentry>
 
831
    <term>
 
832
      <emphasis remap='I'>list</emphasis>
 
833
    </term>
 
834
    <listitem>
 
835
      <para>
 
836
Specifies the KeySyms to be used as modifiers.
 
837
      </para>
 
838
    </listitem>
 
839
  </varlistentry>
 
840
  <varlistentry>
 
841
    <term>
 
842
      <emphasis remap='I'>mod_count</emphasis>
 
843
    </term>
 
844
    <listitem>
 
845
      <para>
 
846
Specifies the number of modifiers in the modifier list.
 
847
      </para>
 
848
    </listitem>
 
849
  </varlistentry>
 
850
  <varlistentry>
 
851
    <term>
 
852
      <emphasis remap='I'>string</emphasis>
 
853
    </term>
 
854
    <listitem>
 
855
      <para>
 
856
Specifies the string that is copied and will be returned by 
 
857
<function>XLookupString</function>.
 
858
      </para>
 
859
    </listitem>
 
860
  </varlistentry>
 
861
  <varlistentry>
 
862
    <term>
 
863
      <emphasis remap='I'>num_bytes</emphasis>
 
864
    </term>
 
865
    <listitem>
 
866
      <para>
 
867
Specifies the number of bytes in the string argument.
 
868
    </para>
 
869
  </listitem>
 
870
  </varlistentry>
 
871
</variablelist>
 
872
</para>
 
873
<para>
 
874
<!-- .LP -->
 
875
<!-- .eM -->
 
876
The
 
877
<function>XRebindKeysym</function>
 
878
function can be used to rebind the meaning of a KeySym for the client.
 
879
It does not redefine any key in the X server but merely
 
880
provides an easy way for long strings to be attached to keys.
 
881
<function>XLookupString</function>
 
882
returns this string when the appropriate set of
 
883
modifier keys are pressed and when the KeySym would have been used for
 
884
the translation.
 
885
No text conversions are performed;
 
886
the client is responsible for supplying appropriately encoded strings.
 
887
Note that you can rebind a KeySym that may not exist.
 
888
</para>
 
889
</sect1>
 
890
<sect1 id="Allocating_Permanent_Storage">
 
891
<title>Allocating Permanent Storage</title>
 
892
<!-- .XS -->
 
893
<!-- (SN Allocating Permanent Storage -->
 
894
<!-- .XE -->
 
895
<para>
 
896
<!-- .LP -->
 
897
To allocate some memory you will never give back, use
 
898
<function>Xpermalloc</function>.
 
899
<indexterm significance="preferred"><primary>Xpermalloc</primary></indexterm>
 
900
<!-- .sM -->
 
901
<funcsynopsis>
 
902
<funcprototype>
 
903
  <funcdef>char *<function>Xpermalloc</function></funcdef>
 
904
  <paramdef>unsignedint<parameter> size</parameter></paramdef>
 
905
</funcprototype>
 
906
</funcsynopsis>
 
907
<!-- .FN -->
 
908
</para>
 
909
<para>
 
910
<!-- .LP -->
 
911
<!-- .eM -->
 
912
The
 
913
<function>Xpermalloc</function>
 
914
function allocates storage that can never be freed for the life of the
 
915
program.  The memory is allocated with alignment for the C type double.
 
916
This function may provide some performance and space savings over
 
917
the standard operating system memory allocator.
 
918
</para>
 
919
</sect1>
 
920
<sect1 id="Parsing_the_Window_Geometry">
 
921
<title>Parsing the Window Geometry</title>
 
922
<!-- .XS -->
 
923
<!-- (SN Parsing the Window Geometry  -->
 
924
<!-- .XE -->
 
925
<para>
 
926
<!-- .LP -->
 
927
To parse standard window geometry strings, use
 
928
<function>XParseGeometry</function>.
 
929
<indexterm><primary>Window</primary><secondary>determining location</secondary></indexterm>
 
930
<indexterm significance="preferred"><primary>XParseGeometry</primary></indexterm>
 
931
</para>
 
932
<para>
 
933
<!-- .LP -->
 
934
<!-- .sM -->
 
935
<funcsynopsis>
 
936
<funcprototype>
 
937
  <funcdef>int <function>XParseGeometry</function></funcdef>
 
938
  <paramdef>char<parameter> *parsestring</parameter></paramdef>
 
939
  <paramdef>int*x_return,<parameter> *y_return</parameter></paramdef>
 
940
  <paramdef>unsignedint*width_return,<parameter> *height_return</parameter></paramdef>
 
941
</funcprototype>
 
942
</funcsynopsis>
 
943
<!-- .FN -->
 
944
<variablelist>
 
945
  <varlistentry>
 
946
    <term>
 
947
      <emphasis remap='I'>parsestring</emphasis>
 
948
    </term>
 
949
    <listitem>
 
950
      <para>
 
951
Specifies the string you want to parse.
 
952
      </para>
 
953
    </listitem>
 
954
  </varlistentry>
 
955
  <varlistentry>
 
956
    <term>
 
957
      <emphasis remap='I'>x_return</emphasis>
 
958
    </term>
 
959
    <listitem>
 
960
      <para>
 
961
<!-- .br -->
 
962
<!-- .ns -->
 
963
      </para>
 
964
    </listitem>
 
965
  </varlistentry>
 
966
  <varlistentry>
 
967
    <term>
 
968
      <emphasis remap='I'>y_return</emphasis>
 
969
    </term>
 
970
    <listitem>
 
971
      <para>
 
972
Return the x and y offsets.
 
973
      </para>
 
974
    </listitem>
 
975
  </varlistentry>
 
976
  <varlistentry>
 
977
    <term>
 
978
      <emphasis remap='I'>width_return</emphasis>
 
979
    </term>
 
980
    <listitem>
 
981
      <para>
 
982
<!-- .br -->
 
983
<!-- .ns -->
 
984
      </para>
 
985
    </listitem>
 
986
  </varlistentry>
 
987
  <varlistentry>
 
988
    <term>
 
989
      <emphasis remap='I'>height_return</emphasis>
 
990
    </term>
 
991
    <listitem>
 
992
      <para>
 
993
Return the width and height determined.
 
994
    </para>
 
995
  </listitem>
 
996
  </varlistentry>
 
997
</variablelist>
 
998
</para>
 
999
<para>
 
1000
<!-- .LP -->
 
1001
<!-- .eM -->
 
1002
By convention,
 
1003
X applications use a standard string to indicate window size and placement.
 
1004
<function>XParseGeometry</function>
 
1005
makes it easier to conform to this standard because it allows you
 
1006
to parse the standard window geometry.
 
1007
Specifically, this function lets you parse strings of the form:
 
1008
</para>
 
1009
<para>
 
1010
<!-- .LP -->
 
1011
<!-- .\" Start marker code here -->
 
1012
<literallayout class="monospaced">
 
1013
[=][&lt;<emphasis remap='I'>width</emphasis>&gt;{xX}&lt;<emphasis remap='I'>height</emphasis>&gt;][{+-}&lt;<emphasis remap='I'>xoffset</emphasis>&gt;{+-}&lt;<emphasis remap='I'>yoffset</emphasis>&gt;] 
 
1014
</literallayout>
 
1015
<!-- .\" End marker code here -->
 
1016
</para>
 
1017
<para>
 
1018
<!-- .LP -->
 
1019
The fields map into the arguments associated with this function.
 
1020
(Items enclosed in &lt;&hairsp;&gt; are integers, items in [&hairsp;] are optional, and
 
1021
items enclosed in {&hairsp;} indicate ``choose one of.''
 
1022
Note that the brackets should not appear in the actual string.)
 
1023
If the string is not in the Host Portable Character Encoding,
 
1024
the result is implementation-dependent.
 
1025
</para>
 
1026
<para>
 
1027
<!-- .LP -->
 
1028
The
 
1029
<function>XParseGeometry</function>
 
1030
function returns a bitmask that indicates which of the four values (width,
 
1031
height, xoffset, and yoffset) were actually found in the string 
 
1032
and whether the x and y values are negative. 
 
1033
By convention, &minus;0 is not equal to +0, because the user needs to
 
1034
be able to say ``position the window relative to the right or bottom edge.''
 
1035
For each value found, the corresponding argument is updated.
 
1036
For each value not found, the argument is left unchanged.
 
1037
The bits are represented by
 
1038
<symbol>XValue</symbol>,
 
1039
<symbol>YValue</symbol>,
 
1040
<symbol>WidthValue</symbol>,
 
1041
<symbol>HeightValue</symbol>,
 
1042
<symbol>XNegative</symbol>,
 
1043
or
 
1044
<symbol>YNegative</symbol>
 
1045
and are defined in 
 
1046
<filename class="headerfile">&lt;X11/Xutil.h&gt;</filename>.
 
1047
<indexterm type="file"><primary><filename class="headerfile">X11/Xutil.h</filename></primary></indexterm>
 
1048
<indexterm><primary>Files</primary><secondary><filename class="headerfile">&lt;X11/Xutil.h&gt;</filename></secondary></indexterm>
 
1049
<indexterm><primary>Headers</primary><secondary><filename class="headerfile">&lt;X11/Xutil.h&gt;</filename></secondary></indexterm>
 
1050
They will be set whenever one of the values is defined 
 
1051
or one of the signs is set.
 
1052
</para>
 
1053
<para>
 
1054
<!-- .LP -->
 
1055
If the function returns either the 
 
1056
<symbol>XValue</symbol>
 
1057
or 
 
1058
<symbol>YValue</symbol>
 
1059
flag,
 
1060
you should place the window at the requested position.
 
1061
<!-- .sp -->
 
1062
</para>
 
1063
<para>
 
1064
<!-- .LP -->
 
1065
To construct a window's geometry information, use
 
1066
<function>XWMGeometry</function>.
 
1067
<indexterm significance="preferred"><primary>XWMGeometry</primary></indexterm>
 
1068
<!-- .sM -->
 
1069
<funcsynopsis>
 
1070
<funcprototype>
 
1071
  <funcdef>int <function>XWMGeometry</function></funcdef>
 
1072
  <paramdef>Display<parameter> *display</parameter></paramdef>
 
1073
  <paramdef>int<parameter> screen</parameter></paramdef>
 
1074
  <paramdef>char<parameter> *user_geom</parameter></paramdef>
 
1075
  <paramdef>char<parameter> *def_geom</parameter></paramdef>
 
1076
  <paramdef>unsignedint<parameter> bwidth</parameter></paramdef>
 
1077
  <paramdef>XSizeHints<parameter> *hints</parameter></paramdef>
 
1078
  <paramdef>int*x_return,<parameter> *y_return</parameter></paramdef>
 
1079
  <paramdef>int<parameter> *width_return</parameter></paramdef>
 
1080
  <paramdef>int<parameter> *height_return</parameter></paramdef>
 
1081
  <paramdef>int<parameter> *gravity_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>
 
1092
Specifies the connection to the X server.
 
1093
      </para>
 
1094
    </listitem>
 
1095
  </varlistentry>
 
1096
  <varlistentry>
 
1097
    <term>
 
1098
      <emphasis remap='I'>screen</emphasis>
 
1099
    </term>
 
1100
    <listitem>
 
1101
      <para>
 
1102
Specifies the screen.
 
1103
      </para>
 
1104
    </listitem>
 
1105
  </varlistentry>
 
1106
  <varlistentry>
 
1107
    <term>
 
1108
      <emphasis remap='I'>user_geom</emphasis>
 
1109
    </term>
 
1110
    <listitem>
 
1111
      <para>
 
1112
Specifies the user-specified geometry or NULL.
 
1113
      </para>
 
1114
    </listitem>
 
1115
  </varlistentry>
 
1116
  <varlistentry>
 
1117
    <term>
 
1118
      <emphasis remap='I'>def_geom</emphasis>
 
1119
    </term>
 
1120
    <listitem>
 
1121
      <para>
 
1122
Specifies the application's default geometry or NULL.
 
1123
      </para>
 
1124
    </listitem>
 
1125
  </varlistentry>
 
1126
  <varlistentry>
 
1127
    <term>
 
1128
      <emphasis remap='I'>bwidth</emphasis>
 
1129
    </term>
 
1130
    <listitem>
 
1131
      <para>
 
1132
Specifies the border width.
 
1133
      </para>
 
1134
    </listitem>
 
1135
  </varlistentry>
 
1136
  <varlistentry>
 
1137
    <term>
 
1138
      <emphasis remap='I'>hints</emphasis>
 
1139
    </term>
 
1140
    <listitem>
 
1141
      <para>
 
1142
Specifies the size hints for the window in its normal state.
 
1143
      </para>
 
1144
    </listitem>
 
1145
  </varlistentry>
 
1146
  <varlistentry>
 
1147
    <term>
 
1148
      <emphasis remap='I'>x_return</emphasis>
 
1149
    </term>
 
1150
    <listitem>
 
1151
      <para>
 
1152
<!-- .br -->
 
1153
<!-- .ns -->
 
1154
      </para>
 
1155
    </listitem>
 
1156
  </varlistentry>
 
1157
  <varlistentry>
 
1158
    <term>
 
1159
      <emphasis remap='I'>y_return</emphasis>
 
1160
    </term>
 
1161
    <listitem>
 
1162
      <para>
 
1163
Return the x and y offsets.
 
1164
      </para>
 
1165
    </listitem>
 
1166
  </varlistentry>
 
1167
  <varlistentry>
 
1168
    <term>
 
1169
      <emphasis remap='I'>width_return</emphasis>
 
1170
    </term>
 
1171
    <listitem>
 
1172
      <para>
 
1173
<!-- .br -->
 
1174
<!-- .ns -->
 
1175
      </para>
 
1176
    </listitem>
 
1177
  </varlistentry>
 
1178
  <varlistentry>
 
1179
    <term>
 
1180
      <emphasis remap='I'>height_return</emphasis>
 
1181
    </term>
 
1182
    <listitem>
 
1183
      <para>
 
1184
Return the width and height determined.
 
1185
      </para>
 
1186
    </listitem>
 
1187
  </varlistentry>
 
1188
  <varlistentry>
 
1189
    <term>
 
1190
      <emphasis remap='I'>gravity_return</emphasis>
 
1191
    </term>
 
1192
    <listitem>
 
1193
      <para>
 
1194
Returns the window gravity.
 
1195
    </para>
 
1196
  </listitem>
 
1197
  </varlistentry>
 
1198
</variablelist>
 
1199
</para>
 
1200
<para>
 
1201
<!-- .LP -->
 
1202
<!-- .eM -->
 
1203
The 
 
1204
<function>XWMGeometry</function>
 
1205
function combines any geometry information (given in the format used by 
 
1206
<function>XParseGeometry</function>)
 
1207
specified by the user and by the calling program with size hints 
 
1208
(usually the ones to be stored in <property>WM_NORMAL_HINTS</property>) and returns the position, 
 
1209
size, and gravity
 
1210
(<symbol>NorthWestGravity</symbol>,
 
1211
<symbol>NorthEastGravity</symbol>,
 
1212
<symbol>SouthEastGravity</symbol>,
 
1213
or
 
1214
<symbol>SouthWestGravity</symbol>)
 
1215
that describe the window.
 
1216
If the base size is not set in the 
 
1217
<structname>XSizeHints</structname>
 
1218
structure, 
 
1219
the minimum size is used if set.
 
1220
Otherwise, a base size of zero is assumed.
 
1221
If no minimum size is set in the hints structure, 
 
1222
the base size is used.
 
1223
A mask (in the form returned by 
 
1224
<function>XParseGeometry</function>)
 
1225
that describes which values came from the user specification 
 
1226
and whether or not the position coordinates are relative
 
1227
to the right and bottom edges is returned.
 
1228
Note that these coordinates will have already been accounted for 
 
1229
in the x_return and y_return values.
 
1230
</para>
 
1231
<para>
 
1232
<!-- .LP -->
 
1233
Note that invalid geometry specifications can cause a width or height 
 
1234
of zero to be returned.
 
1235
The caller may pass the address of the hints win_gravity field 
 
1236
as gravity_return to update the hints directly.
 
1237
</para>
 
1238
</sect1>
 
1239
 
 
1240
<sect1 id="Manipulating_Regions">
 
1241
<title>Manipulating Regions</title>
 
1242
<!-- .XS -->
 
1243
<!-- (SN Manipulating Regions  -->
 
1244
<!-- .XE -->
 
1245
<para>
 
1246
Regions are arbitrary sets of pixel locations.
 
1247
Xlib provides functions for manipulating regions.
 
1248
The opaque type 
 
1249
<structname>Region</structname>
 
1250
is defined in 
 
1251
<filename class="headerfile">&lt;X11/Xutil.h&gt;</filename>.
 
1252
<indexterm type="file"><primary><filename class="headerfile">X11/Xutil.h</filename></primary></indexterm>
 
1253
<indexterm><primary>Files</primary><secondary><filename class="headerfile">&lt;X11/Xutil.h&gt;</filename></secondary></indexterm>
 
1254
<indexterm><primary>Headers</primary><secondary><filename class="headerfile">&lt;X11/Xutil.h&gt;</filename></secondary></indexterm>
 
1255
Xlib provides functions that you can use to manipulate regions.
 
1256
This section discusses how to:
 
1257
</para>
 
1258
 
 
1259
<itemizedlist>
 
1260
  <listitem>
 
1261
    <para>
 
1262
Create, copy, or destroy regions
 
1263
    </para>
 
1264
  </listitem>
 
1265
  <listitem>
 
1266
    <para>
 
1267
Move or shrink regions
 
1268
    </para>
 
1269
  </listitem>
 
1270
  <listitem>
 
1271
    <para>
 
1272
Compute with regions
 
1273
    </para>
 
1274
  </listitem>
 
1275
  <listitem>
 
1276
    <para>
 
1277
Determine if regions are empty or equal
 
1278
    </para>
 
1279
  </listitem>
 
1280
  <listitem>
 
1281
    <para>
 
1282
Locate a point or rectangle in a region
 
1283
    </para>
 
1284
  </listitem>
 
1285
</itemizedlist>
 
1286
 
 
1287
<sect2 id="Creating_Copying_or_Destroying_Regions">
 
1288
<title>Creating, Copying, or Destroying Regions</title>
 
1289
<!-- .XS -->
 
1290
<!-- (SN Creating, Copying, or Destroying Regions  -->
 
1291
<!-- .XE -->
 
1292
<para>
 
1293
<!-- .LP -->
 
1294
To create a new empty region, use
 
1295
<function>XCreateRegion</function>.
 
1296
</para>
 
1297
<para>Region XCreateRegion()</para>
 
1298
 
 
1299
<para>
 
1300
<!-- .LP -->
 
1301
<!-- .eM -->
 
1302
<!-- .sp -->
 
1303
To generate a region from a polygon, use
 
1304
<function>XPolygonRegion</function>.
 
1305
</para>
 
1306
<indexterm significance="preferred"><primary>XPolygonRegion</primary></indexterm>
 
1307
<!-- .sM -->
 
1308
<funcsynopsis>
 
1309
<funcprototype>
 
1310
  <funcdef>Region <function>XPolygonRegion</function></funcdef>
 
1311
  <paramdef>XPoint<parameter> points[]</parameter></paramdef>
 
1312
  <paramdef>int<parameter> n</parameter></paramdef>
 
1313
  <paramdef>int<parameter> fill_rule</parameter></paramdef>
 
1314
</funcprototype>
 
1315
</funcsynopsis>
 
1316
<!-- .FN -->
 
1317
<variablelist>
 
1318
  <varlistentry>
 
1319
    <term>
 
1320
      <emphasis remap='I'>points</emphasis>
 
1321
    </term>
 
1322
    <listitem>
 
1323
      <para>
 
1324
Specifies an array of points.
 
1325
      </para>
 
1326
    </listitem>
 
1327
  </varlistentry>
 
1328
  <varlistentry>
 
1329
    <term>
 
1330
      <emphasis remap='I'>n</emphasis>
 
1331
    </term>
 
1332
    <listitem>
 
1333
      <para>
 
1334
Specifies the number of points in the polygon. 
 
1335
      </para>
 
1336
    </listitem>
 
1337
  </varlistentry>
 
1338
  <varlistentry>
 
1339
    <term>
 
1340
      <emphasis remap='I'>fill_rule</emphasis>
 
1341
    </term>
 
1342
    <listitem>
 
1343
      <para>
 
1344
Specifies the fill-rule you want to set for the specified GC.
 
1345
You can pass 
 
1346
<symbol>EvenOddRule</symbol>
 
1347
or
 
1348
<symbol>WindingRule</symbol>.
 
1349
    </para>
 
1350
  </listitem>
 
1351
  </varlistentry>
 
1352
</variablelist>
 
1353
 
 
1354
<para>
 
1355
<!-- .LP -->
 
1356
<!-- .eM  -->
 
1357
The
 
1358
<function>XPolygonRegion</function>
 
1359
function returns a region for the polygon defined by the points array.
 
1360
For an explanation of fill_rule,
 
1361
see
 
1362
<function>XCreateGC</function>.
 
1363
</para>
 
1364
<para>
 
1365
<!-- .LP -->
 
1366
<!-- .sp -->
 
1367
To set the clip-mask of a GC to a region, use
 
1368
<function>XSetRegion</function>.
 
1369
<indexterm significance="preferred"><primary>XSetRegion</primary></indexterm>
 
1370
<!-- .sM -->
 
1371
<funcsynopsis>
 
1372
<funcprototype>
 
1373
  <funcdef><function>XSetRegion</function></funcdef>
 
1374
  <paramdef>Display<parameter> *display</parameter></paramdef>
 
1375
  <paramdef>GC<parameter> gc</parameter></paramdef>
 
1376
  <paramdef>Region<parameter> r</parameter></paramdef>
 
1377
</funcprototype>
 
1378
</funcsynopsis>
 
1379
<!-- .FN -->
 
1380
<variablelist>
 
1381
  <varlistentry>
 
1382
    <term>
 
1383
      <emphasis remap='I'>display</emphasis>
 
1384
    </term>
 
1385
    <listitem>
 
1386
      <para>
 
1387
Specifies the connection to the X server.
 
1388
      </para>
 
1389
    </listitem>
 
1390
  </varlistentry>
 
1391
  <varlistentry>
 
1392
    <term>
 
1393
      <emphasis remap='I'>gc</emphasis>
 
1394
    </term>
 
1395
    <listitem>
 
1396
      <para>
 
1397
Specifies the GC.
 
1398
      </para>
 
1399
    </listitem>
 
1400
  </varlistentry>
 
1401
  <varlistentry>
 
1402
    <term>
 
1403
      <emphasis remap='I'>r</emphasis>
 
1404
    </term>
 
1405
    <listitem>
 
1406
      <para>
 
1407
Specifies the region.
 
1408
    </para>
 
1409
  </listitem>
 
1410
  </varlistentry>
 
1411
</variablelist>
 
1412
</para>
 
1413
<para>
 
1414
<!-- .LP -->
 
1415
<!-- .eM -->
 
1416
The
 
1417
<function>XSetRegion</function>
 
1418
function sets the clip-mask in the GC to the specified region.
 
1419
The region is specified relative to the drawable's origin.
 
1420
The resulting GC clip origin is implementation-dependent.
 
1421
Once it is set in the GC,
 
1422
the region can be destroyed.
 
1423
</para>
 
1424
<para>
 
1425
<!-- .LP  -->
 
1426
<!-- .sp -->
 
1427
To deallocate the storage associated with a specified region, use
 
1428
<function>XDestroyRegion</function>.
 
1429
<indexterm significance="preferred"><primary>XDestroyRegion</primary></indexterm>
 
1430
<!-- .sM -->
 
1431
<funcsynopsis>
 
1432
<funcprototype>
 
1433
  <funcdef><function>XDestroyRegion</function></funcdef>
 
1434
  <paramdef>Region<parameter> r</parameter></paramdef>
 
1435
</funcprototype>
 
1436
</funcsynopsis>
 
1437
<!-- .FN -->
 
1438
<variablelist>
 
1439
  <varlistentry>
 
1440
    <term>
 
1441
      <emphasis remap='I'>r</emphasis>
 
1442
    </term>
 
1443
    <listitem>
 
1444
      <para>
 
1445
Specifies the region.
 
1446
    </para>
 
1447
  </listitem>
 
1448
  </varlistentry>
 
1449
</variablelist>
 
1450
</para>
 
1451
<para>
 
1452
<!-- .LP -->
 
1453
<!-- .eM -->
 
1454
</para>
 
1455
</sect2>
 
1456
<sect2 id="Moving_or_Shrinking_Regions">
 
1457
<title>Moving or Shrinking Regions</title>
 
1458
<!-- .XS -->
 
1459
<!-- (SN Moving or Shrinking Regions  -->
 
1460
<!-- .XE -->
 
1461
<para>
 
1462
<!-- .LP -->
 
1463
To move a region by a specified amount, use 
 
1464
<function>XOffsetRegion</function>.
 
1465
<indexterm significance="preferred"><primary>XOffsetRegion</primary></indexterm>
 
1466
<!-- .sM -->
 
1467
<funcsynopsis>
 
1468
<funcprototype>
 
1469
  <funcdef><function>XOffsetRegion</function></funcdef>
 
1470
  <paramdef>Region<parameter> r</parameter></paramdef>
 
1471
  <paramdef>intdx,<parameter> dy</parameter></paramdef>
 
1472
</funcprototype>
 
1473
</funcsynopsis>
 
1474
<!-- .FN -->
 
1475
<variablelist>
 
1476
  <varlistentry>
 
1477
    <term>
 
1478
      <emphasis remap='I'>r</emphasis>
 
1479
    </term>
 
1480
    <listitem>
 
1481
      <para>
 
1482
Specifies the region.
 
1483
<!-- .ds Dy move -->
 
1484
      </para>
 
1485
    </listitem>
 
1486
  </varlistentry>
 
1487
  <varlistentry>
 
1488
    <term>
 
1489
      <emphasis remap='I'>dx</emphasis>
 
1490
    </term>
 
1491
    <listitem>
 
1492
      <para>
 
1493
<!-- .br -->
 
1494
<!-- .ns -->
 
1495
      </para>
 
1496
    </listitem>
 
1497
  </varlistentry>
 
1498
  <varlistentry>
 
1499
    <term>
 
1500
      <emphasis remap='I'>dy</emphasis>
 
1501
    </term>
 
1502
    <listitem>
 
1503
      <para>
 
1504
Specify the x and y coordinates,
 
1505
which define the amount you want to (Dy the specified region.
 
1506
    </para>
 
1507
  </listitem>
 
1508
  </varlistentry>
 
1509
</variablelist>
 
1510
</para>
 
1511
<para>
 
1512
<!-- .LP -->
 
1513
<!-- .eM  -->
 
1514
<!-- .sp -->
 
1515
To reduce a region by a specified amount, use
 
1516
<function>XShrinkRegion</function>.
 
1517
<indexterm significance="preferred"><primary>XShrinkRegion</primary></indexterm>
 
1518
<!-- .sM -->
 
1519
<funcsynopsis>
 
1520
<funcprototype>
 
1521
  <funcdef><function>XShrinkRegion</function></funcdef>
 
1522
  <paramdef>Region<parameter> r</parameter></paramdef>
 
1523
  <paramdef>intdx,<parameter> dy</parameter></paramdef>
 
1524
</funcprototype>
 
1525
</funcsynopsis>
 
1526
<!-- .FN -->
 
1527
<variablelist>
 
1528
  <varlistentry>
 
1529
    <term>
 
1530
      <emphasis remap='I'>r</emphasis>
 
1531
    </term>
 
1532
    <listitem>
 
1533
      <para>
 
1534
Specifies the region.
 
1535
<!-- .ds Dy shrink -->
 
1536
      </para>
 
1537
    </listitem>
 
1538
  </varlistentry>
 
1539
  <varlistentry>
 
1540
    <term>
 
1541
      <emphasis remap='I'>dx</emphasis>
 
1542
    </term>
 
1543
    <listitem>
 
1544
      <para>
 
1545
<!-- .br -->
 
1546
<!-- .ns -->
 
1547
      </para>
 
1548
    </listitem>
 
1549
  </varlistentry>
 
1550
  <varlistentry>
 
1551
    <term>
 
1552
      <emphasis remap='I'>dy</emphasis>
 
1553
    </term>
 
1554
    <listitem>
 
1555
      <para>
 
1556
Specify the x and y coordinates,
 
1557
which define the amount you want to (Dy the specified region.
 
1558
    </para>
 
1559
  </listitem>
 
1560
  </varlistentry>
 
1561
</variablelist>
 
1562
</para>
 
1563
<para>
 
1564
<!-- .LP -->
 
1565
<!-- .eM -->
 
1566
Positive values shrink the size of the region, 
 
1567
and negative values expand the region.
 
1568
</para>
 
1569
</sect2>
 
1570
<sect2 id="Computing_with_Regions">
 
1571
<title>Computing with Regions</title>
 
1572
<!-- .XS -->
 
1573
<!-- (SN Computing with Regions  -->
 
1574
<!-- .XE -->
 
1575
<para>
 
1576
<!-- .LP -->
 
1577
<!-- .sp -->
 
1578
To generate the smallest rectangle enclosing a region, use
 
1579
<function>XClipBox</function>.
 
1580
<indexterm significance="preferred"><primary>XClipBox</primary></indexterm>
 
1581
<!-- .sM -->
 
1582
<funcsynopsis>
 
1583
<funcprototype>
 
1584
  <funcdef><function>XClipBox</function></funcdef>
 
1585
  <paramdef>Region<parameter> r</parameter></paramdef>
 
1586
  <paramdef>XRectangle<parameter> *rect_return</parameter></paramdef>
 
1587
</funcprototype>
 
1588
</funcsynopsis>
 
1589
<!-- .FN -->
 
1590
<variablelist>
 
1591
  <varlistentry>
 
1592
    <term>
 
1593
      <emphasis remap='I'>r</emphasis>
 
1594
    </term>
 
1595
    <listitem>
 
1596
      <para>
 
1597
Specifies the region.
 
1598
      </para>
 
1599
    </listitem>
 
1600
  </varlistentry>
 
1601
  <varlistentry>
 
1602
    <term>
 
1603
      <emphasis remap='I'>rect_return</emphasis>
 
1604
    </term>
 
1605
    <listitem>
 
1606
      <para>
 
1607
Returns the smallest enclosing rectangle.
 
1608
    </para>
 
1609
  </listitem>
 
1610
  </varlistentry>
 
1611
</variablelist>
 
1612
</para>
 
1613
<para>
 
1614
<!-- .LP -->
 
1615
<!-- .eM -->
 
1616
The
 
1617
<function>XClipBox</function>
 
1618
function returns the smallest rectangle enclosing the specified region.
 
1619
<!-- .sp -->
 
1620
</para>
 
1621
<para>
 
1622
<!-- .LP -->
 
1623
To compute the intersection of two regions, use
 
1624
<function>XIntersectRegion</function>.
 
1625
<indexterm significance="preferred"><primary>XIntersectRegion</primary></indexterm>
 
1626
<!-- .sM -->
 
1627
<funcsynopsis>
 
1628
<funcprototype>
 
1629
  <funcdef><function>XIntersectRegion</function></funcdef>
 
1630
  <paramdef>Regionsra,srb,<parameter> dr_return</parameter></paramdef>
 
1631
</funcprototype>
 
1632
</funcsynopsis>
 
1633
<!-- .FN -->
 
1634
<variablelist>
 
1635
  <varlistentry>
 
1636
    <term>
 
1637
      <emphasis remap='I'>sra</emphasis>
 
1638
    </term>
 
1639
    <listitem>
 
1640
      <para>
 
1641
<!-- .br -->
 
1642
<!-- .ns -->
 
1643
      </para>
 
1644
    </listitem>
 
1645
  </varlistentry>
 
1646
  <varlistentry>
 
1647
    <term>
 
1648
      <emphasis remap='I'>srb</emphasis>
 
1649
    </term>
 
1650
    <listitem>
 
1651
      <para>
 
1652
Specify the two regions with which you want to perform the computation.
 
1653
      </para>
 
1654
    </listitem>
 
1655
  </varlistentry>
 
1656
  <varlistentry>
 
1657
    <term>
 
1658
      <emphasis remap='I'>dr_return</emphasis>
 
1659
    </term>
 
1660
    <listitem>
 
1661
      <para>
 
1662
Returns the result of the computation.
 
1663
    </para>
 
1664
  </listitem>
 
1665
  </varlistentry>
 
1666
</variablelist>
 
1667
</para>
 
1668
<para>
 
1669
<!-- .LP -->
 
1670
<!-- .eM -->
 
1671
<!-- .sp -->
 
1672
To compute the union of two regions, use
 
1673
<function>XUnionRegion</function>.
 
1674
<indexterm significance="preferred"><primary>XUnionRegion</primary></indexterm>
 
1675
<!-- .sM -->
 
1676
<funcsynopsis>
 
1677
<funcprototype>
 
1678
  <funcdef><function>XUnionRegion</function></funcdef>
 
1679
  <paramdef>Regionsra,srb,<parameter> dr_return</parameter></paramdef>
 
1680
</funcprototype>
 
1681
</funcsynopsis>
 
1682
<!-- .FN -->
 
1683
<variablelist>
 
1684
  <varlistentry>
 
1685
    <term>
 
1686
      <emphasis remap='I'>sra</emphasis>
 
1687
    </term>
 
1688
    <listitem>
 
1689
      <para>
 
1690
<!-- .br -->
 
1691
<!-- .ns -->
 
1692
      </para>
 
1693
    </listitem>
 
1694
  </varlistentry>
 
1695
  <varlistentry>
 
1696
    <term>
 
1697
      <emphasis remap='I'>srb</emphasis>
 
1698
    </term>
 
1699
    <listitem>
 
1700
      <para>
 
1701
Specify the two regions with which you want to perform the computation.
 
1702
      </para>
 
1703
    </listitem>
 
1704
  </varlistentry>
 
1705
  <varlistentry>
 
1706
    <term>
 
1707
      <emphasis remap='I'>dr_return</emphasis>
 
1708
    </term>
 
1709
    <listitem>
 
1710
      <para>
 
1711
Returns the result of the computation.
 
1712
    </para>
 
1713
  </listitem>
 
1714
  </varlistentry>
 
1715
</variablelist>
 
1716
</para>
 
1717
<para>
 
1718
<!-- .LP -->
 
1719
<!-- .eM -->
 
1720
<!-- .sp -->
 
1721
To create a union of a source region and a rectangle, use
 
1722
<function>XUnionRectWithRegion</function>.
 
1723
<indexterm significance="preferred"><primary>XUnionRectWithRegion</primary></indexterm>
 
1724
<!-- .sM -->
 
1725
<funcsynopsis>
 
1726
<funcprototype>
 
1727
  <funcdef><function>XUnionRectWithRegion</function></funcdef>
 
1728
  <paramdef>XRectangle<parameter> *rectangle</parameter></paramdef>
 
1729
  <paramdef>Region<parameter> src_region</parameter></paramdef>
 
1730
  <paramdef>Region<parameter> dest_region_return</parameter></paramdef>
 
1731
</funcprototype>
 
1732
</funcsynopsis>
 
1733
<!-- .FN -->
 
1734
<variablelist>
 
1735
  <varlistentry>
 
1736
    <term>
 
1737
      <emphasis remap='I'>rectangle</emphasis>
 
1738
    </term>
 
1739
    <listitem>
 
1740
      <para>
 
1741
Specifies the rectangle.
 
1742
      </para>
 
1743
    </listitem>
 
1744
  </varlistentry>
 
1745
  <varlistentry>
 
1746
    <term>
 
1747
      <emphasis remap='I'>src_region</emphasis>
 
1748
    </term>
 
1749
    <listitem>
 
1750
      <para>
 
1751
Specifies the source region to be used.
 
1752
      </para>
 
1753
    </listitem>
 
1754
  </varlistentry>
 
1755
  <varlistentry>
 
1756
    <term>
 
1757
      <emphasis remap='I'>dest_region_return</emphasis>
 
1758
    </term>
 
1759
    <listitem>
 
1760
      <para>
 
1761
Returns the destination region.
 
1762
    </para>
 
1763
  </listitem>
 
1764
  </varlistentry>
 
1765
</variablelist>
 
1766
</para>
 
1767
<para>
 
1768
<!-- .LP -->
 
1769
<!-- .eM -->
 
1770
The
 
1771
<function>XUnionRectWithRegion</function>
 
1772
function updates the destination region from a union of the specified rectangle
 
1773
and the specified source region.
 
1774
</para>
 
1775
<para>
 
1776
<!-- .LP -->
 
1777
<!-- .sp -->
 
1778
To subtract two regions, use
 
1779
<function>XSubtractRegion</function>.
 
1780
<indexterm significance="preferred"><primary>XSubtractRegion</primary></indexterm>
 
1781
<!-- .sM -->
 
1782
<funcsynopsis>
 
1783
<funcprototype>
 
1784
  <funcdef><function>XSubtractRegion</function></funcdef>
 
1785
  <paramdef>Regionsra,srb,<parameter> dr_return</parameter></paramdef>
 
1786
</funcprototype>
 
1787
</funcsynopsis>
 
1788
<!-- .FN -->
 
1789
<variablelist>
 
1790
  <varlistentry>
 
1791
    <term>
 
1792
      <emphasis remap='I'>sra</emphasis>
 
1793
    </term>
 
1794
    <listitem>
 
1795
      <para>
 
1796
<!-- .br -->
 
1797
<!-- .ns -->
 
1798
      </para>
 
1799
    </listitem>
 
1800
  </varlistentry>
 
1801
  <varlistentry>
 
1802
    <term>
 
1803
      <emphasis remap='I'>srb</emphasis>
 
1804
    </term>
 
1805
    <listitem>
 
1806
      <para>
 
1807
Specify the two regions with which you want to perform the computation.
 
1808
      </para>
 
1809
    </listitem>
 
1810
  </varlistentry>
 
1811
  <varlistentry>
 
1812
    <term>
 
1813
      <emphasis remap='I'>dr_return</emphasis>
 
1814
    </term>
 
1815
    <listitem>
 
1816
      <para>
 
1817
Returns the result of the computation.
 
1818
    </para>
 
1819
  </listitem>
 
1820
  </varlistentry>
 
1821
</variablelist>
 
1822
</para>
 
1823
<para>
 
1824
<!-- .LP -->
 
1825
<!-- .eM -->
 
1826
The
 
1827
<function>XSubtractRegion</function>
 
1828
function subtracts srb from sra and stores the results in dr_return.
 
1829
</para>
 
1830
<para>
 
1831
<!-- .LP -->
 
1832
<!-- .sp -->
 
1833
To calculate the difference between the union and intersection 
 
1834
of two regions, use
 
1835
<function>XXorRegion</function>.
 
1836
<indexterm significance="preferred"><primary>XXorRegion</primary></indexterm>
 
1837
<!-- .sM -->
 
1838
<funcsynopsis>
 
1839
<funcprototype>
 
1840
  <funcdef><function>XXorRegion</function></funcdef>
 
1841
  <paramdef>Regionsra,srb,<parameter> dr_return</parameter></paramdef>
 
1842
</funcprototype>
 
1843
</funcsynopsis>
 
1844
<!-- .FN -->
 
1845
<variablelist>
 
1846
  <varlistentry>
 
1847
    <term>
 
1848
      <emphasis remap='I'>sra</emphasis>
 
1849
    </term>
 
1850
    <listitem>
 
1851
      <para>
 
1852
<!-- .br -->
 
1853
<!-- .ns -->
 
1854
      </para>
 
1855
    </listitem>
 
1856
  </varlistentry>
 
1857
  <varlistentry>
 
1858
    <term>
 
1859
      <emphasis remap='I'>srb</emphasis>
 
1860
    </term>
 
1861
    <listitem>
 
1862
      <para>
 
1863
Specify the two regions with which you want to perform the computation.
 
1864
      </para>
 
1865
    </listitem>
 
1866
  </varlistentry>
 
1867
  <varlistentry>
 
1868
    <term>
 
1869
      <emphasis remap='I'>dr_return</emphasis>
 
1870
    </term>
 
1871
    <listitem>
 
1872
      <para>
 
1873
Returns the result of the computation.
 
1874
    </para>
 
1875
  </listitem>
 
1876
  </varlistentry>
 
1877
</variablelist>
 
1878
</para>
 
1879
<para>
 
1880
<!-- .LP -->
 
1881
<!-- .eM -->
 
1882
</para>
 
1883
</sect2>
 
1884
<sect2 id="Determining_if_Regions_Are_Empty_or_Equal">
 
1885
<title>Determining if Regions Are Empty or Equal</title>
 
1886
<!-- .XS -->
 
1887
<!-- (SN Determining if Regions Are Empty or Equal  -->
 
1888
<!-- .XE -->
 
1889
<para>
 
1890
<!-- .LP -->
 
1891
To determine if the specified region is empty, use
 
1892
<function>XEmptyRegion</function>.
 
1893
<indexterm significance="preferred"><primary>XEmptyRegion</primary></indexterm>
 
1894
<!-- .sM -->
 
1895
<funcsynopsis>
 
1896
<funcprototype>
 
1897
  <funcdef>Bool <function>XEmptyRegion</function></funcdef>
 
1898
  <paramdef>Region<parameter> r</parameter></paramdef>
 
1899
</funcprototype>
 
1900
</funcsynopsis>
 
1901
<!-- .FN -->
 
1902
<variablelist>
 
1903
  <varlistentry>
 
1904
    <term>
 
1905
      <emphasis remap='I'>r</emphasis>
 
1906
    </term>
 
1907
    <listitem>
 
1908
      <para>
 
1909
Specifies the region.
 
1910
    </para>
 
1911
  </listitem>
 
1912
  </varlistentry>
 
1913
</variablelist>
 
1914
</para>
 
1915
<para>
 
1916
<!-- .LP -->
 
1917
<!-- .eM  -->
 
1918
The
 
1919
<function>XEmptyRegion</function>
 
1920
function returns
 
1921
<symbol>True</symbol>
 
1922
if the region is empty.
 
1923
</para>
 
1924
<para>
 
1925
<!-- .LP -->
 
1926
<!-- .sp -->
 
1927
To determine if two regions have the same offset, size, and shape, use
 
1928
<function>XEqualRegion</function>.
 
1929
<indexterm significance="preferred"><primary>XEqualRegion</primary></indexterm>
 
1930
<!-- .sM -->
 
1931
<funcsynopsis>
 
1932
<funcprototype>
 
1933
  <funcdef>Bool <function>XEqualRegion</function></funcdef>
 
1934
  <paramdef>Regionr1,<parameter> r2</parameter></paramdef>
 
1935
</funcprototype>
 
1936
</funcsynopsis>
 
1937
<!-- .FN -->
 
1938
<variablelist>
 
1939
  <varlistentry>
 
1940
    <term>
 
1941
      <emphasis remap='I'>r1</emphasis>
 
1942
    </term>
 
1943
    <listitem>
 
1944
      <para>
 
1945
<!-- .br -->
 
1946
<!-- .ns -->
 
1947
      </para>
 
1948
    </listitem>
 
1949
  </varlistentry>
 
1950
  <varlistentry>
 
1951
    <term>
 
1952
      <emphasis remap='I'>r2</emphasis>
 
1953
    </term>
 
1954
    <listitem>
 
1955
      <para>
 
1956
Specify the two regions.
 
1957
    </para>
 
1958
  </listitem>
 
1959
  </varlistentry>
 
1960
</variablelist>
 
1961
</para>
 
1962
<para>
 
1963
<!-- .LP -->
 
1964
<!-- .eM -->
 
1965
The
 
1966
<function>XEqualRegion</function>
 
1967
function returns
 
1968
<symbol>True</symbol>
 
1969
if the two regions have the same offset, size, and shape.
 
1970
</para>
 
1971
</sect2>
 
1972
<sect2 id="Locating_a_Point_or_a_Rectangle_in_a_Region">
 
1973
<title>Locating a Point or a Rectangle in a Region</title>
 
1974
<!-- .XS -->
 
1975
<!-- (SN Locating a Point or a Rectangle in a Region  -->
 
1976
<!-- .XE -->
 
1977
<para>
 
1978
<!-- .LP -->
 
1979
To determine if a specified point resides in a specified region, use
 
1980
<function>XPointInRegion</function>.
 
1981
<indexterm significance="preferred"><primary>XPointInRegion</primary></indexterm>
 
1982
<!-- .sM -->
 
1983
<funcsynopsis>
 
1984
<funcprototype>
 
1985
  <funcdef>Bool <function>XPointInRegion</function></funcdef>
 
1986
  <paramdef>Region<parameter> r</parameter></paramdef>
 
1987
  <paramdef>intx,<parameter> y</parameter></paramdef>
 
1988
</funcprototype>
 
1989
</funcsynopsis>
 
1990
<!-- .FN -->
 
1991
<variablelist>
 
1992
  <varlistentry>
 
1993
    <term>
 
1994
      <emphasis remap='I'>r</emphasis>
 
1995
    </term>
 
1996
    <listitem>
 
1997
      <para>
 
1998
Specifies the region.
 
1999
<!-- .ds Xy , which define the point -->
 
2000
      </para>
 
2001
    </listitem>
 
2002
  </varlistentry>
 
2003
  <varlistentry>
 
2004
    <term>
 
2005
      <emphasis remap='I'>x</emphasis>
 
2006
    </term>
 
2007
    <listitem>
 
2008
      <para>
 
2009
<!-- .br -->
 
2010
<!-- .ns -->
 
2011
      </para>
 
2012
    </listitem>
 
2013
  </varlistentry>
 
2014
  <varlistentry>
 
2015
    <term>
 
2016
      <emphasis remap='I'>y</emphasis>
 
2017
    </term>
 
2018
    <listitem>
 
2019
      <para>
 
2020
Specify the x and y coordinates(Xy.
 
2021
    </para>
 
2022
  </listitem>
 
2023
  </varlistentry>
 
2024
</variablelist>
 
2025
</para>
 
2026
<para>
 
2027
<!-- .LP -->
 
2028
<!-- .eM -->
 
2029
The
 
2030
<function>XPointInRegion</function>
 
2031
function returns 
 
2032
<symbol>True</symbol>
 
2033
if the point (x, y) is contained in the region r.
 
2034
</para>
 
2035
<para>
 
2036
<!-- .LP -->
 
2037
<!-- .sp -->
 
2038
To determine if a specified rectangle is inside a region, use
 
2039
<function>XRectInRegion</function>.
 
2040
<indexterm significance="preferred"><primary>XRectInRegion</primary></indexterm>
 
2041
<!-- .sM -->
 
2042
<funcsynopsis>
 
2043
<funcprototype>
 
2044
  <funcdef>int <function>XRectInRegion</function></funcdef>
 
2045
  <paramdef>Region<parameter> r</parameter></paramdef>
 
2046
  <paramdef>intx,<parameter> y</parameter></paramdef>
 
2047
  <paramdef>unsignedintwidth,<parameter> height</parameter></paramdef>
 
2048
</funcprototype>
 
2049
</funcsynopsis>
 
2050
<!-- .FN -->
 
2051
<variablelist>
 
2052
  <varlistentry>
 
2053
    <term>
 
2054
      <emphasis remap='I'>r</emphasis>
 
2055
    </term>
 
2056
    <listitem>
 
2057
      <para>
 
2058
Specifies the region.
 
2059
<!-- .ds Xy , which define the coordinates of the upper-left corner of the rectangle -->
 
2060
      </para>
 
2061
    </listitem>
 
2062
  </varlistentry>
 
2063
  <varlistentry>
 
2064
    <term>
 
2065
      <emphasis remap='I'>x</emphasis>
 
2066
    </term>
 
2067
    <listitem>
 
2068
      <para>
 
2069
<!-- .br -->
 
2070
<!-- .ns -->
 
2071
      </para>
 
2072
    </listitem>
 
2073
  </varlistentry>
 
2074
  <varlistentry>
 
2075
    <term>
 
2076
      <emphasis remap='I'>y</emphasis>
 
2077
    </term>
 
2078
    <listitem>
 
2079
      <para>
 
2080
Specify the x and y coordinates(Xy.
 
2081
<!-- .ds Wh , which define the rectangle -->
 
2082
      </para>
 
2083
    </listitem>
 
2084
  </varlistentry>
 
2085
  <varlistentry>
 
2086
    <term>
 
2087
      <emphasis remap='I'>width</emphasis>
 
2088
    </term>
 
2089
    <listitem>
 
2090
      <para>
 
2091
<!-- .br -->
 
2092
<!-- .ns -->
 
2093
      </para>
 
2094
    </listitem>
 
2095
  </varlistentry>
 
2096
  <varlistentry>
 
2097
    <term>
 
2098
      <emphasis remap='I'>height</emphasis>
 
2099
    </term>
 
2100
    <listitem>
 
2101
      <para>
 
2102
Specify the width and height(Wh.
 
2103
    </para>
 
2104
  </listitem>
 
2105
  </varlistentry>
 
2106
</variablelist>
 
2107
</para>
 
2108
<para>
 
2109
<!-- .LP -->
 
2110
<!-- .eM  -->
 
2111
The
 
2112
<function>XRectInRegion</function>
 
2113
function returns
 
2114
<symbol>RectangleIn</symbol>
 
2115
if the rectangle is entirely in the specified region,
 
2116
<symbol>RectangleOut</symbol>
 
2117
if the rectangle is entirely out of the specified region,
 
2118
and
 
2119
<symbol>RectanglePart</symbol>
 
2120
if the rectangle is partially in the specified region.
 
2121
</para>
 
2122
</sect2>
 
2123
</sect1>
 
2124
<sect1 id="Using_Cut_Buffers">
 
2125
<title>Using Cut Buffers</title>
 
2126
<!-- .XS -->
 
2127
<!-- (SN Using Cut Buffers  -->
 
2128
<!-- .XE -->
 
2129
<para>
 
2130
<!-- .LP -->
 
2131
<indexterm><primary>Cut Buffers</primary></indexterm>
 
2132
Xlib provides functions to manipulate cut buffers,
 
2133
a very simple form of cut-and-paste inter-client communication.
 
2134
Selections are a much more powerful and useful mechanism for
 
2135
interchanging data between clients (see section 4.5)
 
2136
and generally should be used instead of cut buffers.
 
2137
</para>
 
2138
<para>
 
2139
<!-- .LP -->
 
2140
Cut buffers are implemented as properties on the first root window
 
2141
of the display.
 
2142
The buffers can only contain text, in the STRING encoding.
 
2143
The text encoding is not changed by Xlib when fetching or storing.
 
2144
Eight buffers are provided
 
2145
and can be accessed as a ring or as explicit buffers (numbered 0 through 7).
 
2146
</para>
 
2147
<para>
 
2148
<!-- .LP -->
 
2149
<!-- .sp -->
 
2150
To store data in cut buffer 0, use 
 
2151
<function>XStoreBytes</function>.
 
2152
<indexterm significance="preferred"><primary>XStoreBytes</primary></indexterm>
 
2153
<!-- .sM -->
 
2154
<funcsynopsis>
 
2155
<funcprototype>
 
2156
  <funcdef><function>XStoreBytes</function></funcdef>
 
2157
  <paramdef>Display<parameter> *display</parameter></paramdef>
 
2158
  <paramdef>char<parameter> *bytes</parameter></paramdef>
 
2159
  <paramdef>int<parameter> nbytes</parameter></paramdef>
 
2160
</funcprototype>
 
2161
</funcsynopsis>
 
2162
<!-- .FN  -->
 
2163
<variablelist>
 
2164
  <varlistentry>
 
2165
    <term>
 
2166
      <emphasis remap='I'>display</emphasis>
 
2167
    </term>
 
2168
    <listitem>
 
2169
      <para>
 
2170
Specifies the connection to the X server.
 
2171
      </para>
 
2172
    </listitem>
 
2173
  </varlistentry>
 
2174
  <varlistentry>
 
2175
    <term>
 
2176
      <emphasis remap='I'>bytes</emphasis>
 
2177
    </term>
 
2178
    <listitem>
 
2179
      <para>
 
2180
Specifies the bytes, which are not necessarily ASCII or null-terminated.
 
2181
      </para>
 
2182
    </listitem>
 
2183
  </varlistentry>
 
2184
  <varlistentry>
 
2185
    <term>
 
2186
      <emphasis remap='I'>nbytes</emphasis>
 
2187
    </term>
 
2188
    <listitem>
 
2189
      <para>
 
2190
Specifies the number of bytes to be stored.
 
2191
    </para>
 
2192
  </listitem>
 
2193
  </varlistentry>
 
2194
</variablelist>
 
2195
</para>
 
2196
<para>
 
2197
<!-- .LP -->
 
2198
<!-- .eM -->
 
2199
The data can have embedded null characters
 
2200
and need not be null-terminated.
 
2201
The cut buffer's contents can be retrieved later by
 
2202
any client calling
 
2203
<function>XFetchBytes</function>.
 
2204
</para>
 
2205
<para>
 
2206
<!-- .LP -->
 
2207
<function>XStoreBytes</function>
 
2208
can generate a
 
2209
<errorname>BadAlloc</errorname>
 
2210
error.
 
2211
</para>
 
2212
<para>
 
2213
<!-- .LP -->
 
2214
<!-- .sp -->
 
2215
To store data in a specified cut buffer, use
 
2216
<function>XStoreBuffer</function>.
 
2217
<indexterm significance="preferred"><primary>XStoreBuffer</primary></indexterm>
 
2218
<!-- .sM -->
 
2219
<funcsynopsis>
 
2220
<funcprototype>
 
2221
  <funcdef><function>XStoreBuffer</function></funcdef>
 
2222
  <paramdef>Display<parameter> *display</parameter></paramdef>
 
2223
  <paramdef>char<parameter> *bytes</parameter></paramdef>
 
2224
  <paramdef>int<parameter> nbytes</parameter></paramdef>
 
2225
  <paramdef>int<parameter> buffer</parameter></paramdef>
 
2226
</funcprototype>
 
2227
</funcsynopsis>
 
2228
<!-- .FN -->
 
2229
<variablelist>
 
2230
  <varlistentry>
 
2231
    <term>
 
2232
      <emphasis remap='I'>display</emphasis>
 
2233
    </term>
 
2234
    <listitem>
 
2235
      <para>
 
2236
Specifies the connection to the X server.
 
2237
      </para>
 
2238
    </listitem>
 
2239
  </varlistentry>
 
2240
  <varlistentry>
 
2241
    <term>
 
2242
      <emphasis remap='I'>bytes</emphasis>
 
2243
    </term>
 
2244
    <listitem>
 
2245
      <para>
 
2246
Specifies the bytes, which are not necessarily ASCII or null-terminated.
 
2247
      </para>
 
2248
    </listitem>
 
2249
  </varlistentry>
 
2250
  <varlistentry>
 
2251
    <term>
 
2252
      <emphasis remap='I'>nbytes</emphasis>
 
2253
    </term>
 
2254
    <listitem>
 
2255
      <para>
 
2256
Specifies the number of bytes to be stored.
 
2257
<!-- .ds Fn in which you want to store the bytes -->
 
2258
      </para>
 
2259
    </listitem>
 
2260
  </varlistentry>
 
2261
  <varlistentry>
 
2262
    <term>
 
2263
      <emphasis remap='I'>buffer</emphasis>
 
2264
    </term>
 
2265
    <listitem>
 
2266
      <para>
 
2267
Specifies the buffer (Fn.
 
2268
    </para>
 
2269
  </listitem>
 
2270
  </varlistentry>
 
2271
</variablelist>
 
2272
</para>
 
2273
<para>
 
2274
<!-- .LP -->
 
2275
<!-- .eM -->
 
2276
If an invalid buffer is specified, the call has no effect.
 
2277
The data can have embedded null characters
 
2278
and need not be null-terminated.
 
2279
</para>
 
2280
<para>
 
2281
<!-- .LP -->
 
2282
<function>XStoreBuffer</function>
 
2283
can generate a
 
2284
<errorname>BadAlloc</errorname>
 
2285
error.
 
2286
</para>
 
2287
<para>
 
2288
<!-- .LP -->
 
2289
<!-- .sp -->
 
2290
To return data from cut buffer 0, use 
 
2291
<function>XFetchBytes</function>.
 
2292
<indexterm significance="preferred"><primary>XFetchBytes</primary></indexterm>
 
2293
<!-- .sM -->
 
2294
<funcsynopsis>
 
2295
<funcprototype>
 
2296
  <funcdef>char *<function>XFetchBytes</function></funcdef>
 
2297
  <paramdef>Display<parameter> *display</parameter></paramdef>
 
2298
  <paramdef>int<parameter> *nbytes_return</parameter></paramdef>
 
2299
</funcprototype>
 
2300
</funcsynopsis>
 
2301
<!-- .FN -->
 
2302
<variablelist>
 
2303
  <varlistentry>
 
2304
    <term>
 
2305
      <emphasis remap='I'>display</emphasis>
 
2306
    </term>
 
2307
    <listitem>
 
2308
      <para>
 
2309
Specifies the connection to the X server.
 
2310
      </para>
 
2311
    </listitem>
 
2312
  </varlistentry>
 
2313
  <varlistentry>
 
2314
    <term>
 
2315
      <emphasis remap='I'>nbytes_return</emphasis>
 
2316
    </term>
 
2317
    <listitem>
 
2318
      <para>
 
2319
Returns the number of bytes in the buffer.
 
2320
    </para>
 
2321
  </listitem>
 
2322
  </varlistentry>
 
2323
</variablelist>
 
2324
</para>
 
2325
<para>
 
2326
<!-- .LP -->
 
2327
<!-- .eM -->
 
2328
The
 
2329
<function>XFetchBytes</function>
 
2330
function
 
2331
returns the number of bytes in the nbytes_return argument,
 
2332
if the buffer contains data.
 
2333
Otherwise, the function
 
2334
returns NULL and sets nbytes to 0.
 
2335
The appropriate amount of storage is allocated and the pointer returned.
 
2336
The client must free this storage when finished with it by calling
 
2337
<function>XFree</function>.
 
2338
</para>
 
2339
<para>
 
2340
<!-- .LP -->
 
2341
<!-- .sp -->
 
2342
To return data from a specified cut buffer, use 
 
2343
<function>XFetchBuffer</function>.
 
2344
<indexterm significance="preferred"><primary>XFetchBuffer</primary></indexterm>
 
2345
<!-- .sM -->
 
2346
<funcsynopsis>
 
2347
<funcprototype>
 
2348
  <funcdef>char *<function>XFetchBuffer</function></funcdef>
 
2349
  <paramdef>Display<parameter> *display</parameter></paramdef>
 
2350
  <paramdef>int<parameter> *nbytes_return</parameter></paramdef>
 
2351
  <paramdef>int<parameter> buffer</parameter></paramdef>
 
2352
</funcprototype>
 
2353
</funcsynopsis>
 
2354
<!-- .FN -->
 
2355
<variablelist>
 
2356
  <varlistentry>
 
2357
    <term>
 
2358
      <emphasis remap='I'>display</emphasis>
 
2359
    </term>
 
2360
    <listitem>
 
2361
      <para>
 
2362
Specifies the connection to the X server.
 
2363
      </para>
 
2364
    </listitem>
 
2365
  </varlistentry>
 
2366
  <varlistentry>
 
2367
    <term>
 
2368
      <emphasis remap='I'>nbytes_return</emphasis>
 
2369
    </term>
 
2370
    <listitem>
 
2371
      <para>
 
2372
Returns the number of bytes in the buffer.
 
2373
<!-- .ds Fn from which you want the stored data returned -->
 
2374
      </para>
 
2375
    </listitem>
 
2376
  </varlistentry>
 
2377
  <varlistentry>
 
2378
    <term>
 
2379
      <emphasis remap='I'>buffer</emphasis>
 
2380
    </term>
 
2381
    <listitem>
 
2382
      <para>
 
2383
Specifies the buffer (Fn.
 
2384
    </para>
 
2385
  </listitem>
 
2386
  </varlistentry>
 
2387
</variablelist>
 
2388
</para>
 
2389
<para>
 
2390
<!-- .LP -->
 
2391
<!-- .eM -->
 
2392
The
 
2393
<function>XFetchBuffer</function>
 
2394
function returns zero to the nbytes_return argument 
 
2395
if there is no data in the buffer or if an invalid
 
2396
buffer is specified.
 
2397
</para>
 
2398
<para>
 
2399
<!-- .LP -->
 
2400
<!-- .sp -->
 
2401
To rotate the cut buffers, use 
 
2402
<function>XRotateBuffers</function>.
 
2403
<indexterm significance="preferred"><primary>XRotateBuffers</primary></indexterm>
 
2404
<!-- .sM -->
 
2405
<funcsynopsis>
 
2406
<funcprototype>
 
2407
  <funcdef><function>XRotateBuffers</function></funcdef>
 
2408
  <paramdef>Display<parameter> *display</parameter></paramdef>
 
2409
  <paramdef>int<parameter> rotate</parameter></paramdef>
 
2410
</funcprototype>
 
2411
</funcsynopsis>
 
2412
<!-- .FN -->
 
2413
<variablelist>
 
2414
  <varlistentry>
 
2415
    <term>
 
2416
      <emphasis remap='I'>display</emphasis>
 
2417
    </term>
 
2418
    <listitem>
 
2419
      <para>
 
2420
Specifies the connection to the X server.
 
2421
      </para>
 
2422
    </listitem>
 
2423
  </varlistentry>
 
2424
  <varlistentry>
 
2425
    <term>
 
2426
      <emphasis remap='I'>rotate</emphasis>
 
2427
    </term>
 
2428
    <listitem>
 
2429
      <para>
 
2430
Specifies how much to rotate the cut buffers.
 
2431
    </para>
 
2432
  </listitem>
 
2433
  </varlistentry>
 
2434
</variablelist>
 
2435
</para>
 
2436
<para>
 
2437
<!-- .LP -->
 
2438
<!-- .eM  -->
 
2439
The
 
2440
<function>XRotateBuffers</function>
 
2441
function rotates the cut
 
2442
buffers, such that buffer 0 becomes buffer n, 
 
2443
buffer 1 becomes n + 1 mod 8, and so on.
 
2444
This cut buffer numbering is global to the display.
 
2445
Note that
 
2446
<function>XRotateBuffers</function>
 
2447
generates
 
2448
<errorname>BadMatch</errorname>
 
2449
errors if any of the eight buffers have not been created.
 
2450
</para>
 
2451
</sect1>
 
2452
<sect1 id="Determining_the_Appropriate_Visual_Type">
 
2453
<title>Determining the Appropriate Visual Type</title>
 
2454
<!-- .XS -->
 
2455
<!-- (SN Determining the Appropriate Visual Type -->
 
2456
<!-- .XE -->
 
2457
<para>
 
2458
<!-- .LP -->
 
2459
A single display can support multiple screens.
 
2460
Each screen can have several different visual types supported 
 
2461
at different depths.
 
2462
You can use the functions described in this section to determine
 
2463
which visual to use for your application.
 
2464
</para>
 
2465
<para>
 
2466
<!-- .LP -->
 
2467
The functions in this section use the visual information masks and the
 
2468
<structname>XVisualInfo</structname>
 
2469
structure,
 
2470
which is defined in
 
2471
<filename class="headerfile">&lt;X11/Xutil.h&gt;</filename>
 
2472
<indexterm type="file"><primary><filename class="headerfile">X11/Xutil.h</filename></primary></indexterm>
 
2473
<indexterm><primary>Files</primary><secondary><filename class="headerfile">&lt;X11/Xutil.h&gt;</filename></secondary></indexterm>
 
2474
<indexterm><primary>Headers</primary><secondary><filename class="headerfile">&lt;X11/Xutil.h&gt;</filename></secondary></indexterm>
 
2475
and contains:
 
2476
<!-- .sM -->
 
2477
</para>
 
2478
<!-- .LP -->
 
2479
<literallayout class="monospaced">
 
2480
 
 
2481
/* Visual information mask bits */
 
2482
 
 
2483
 
 
2484
#define   VisualNoMask                 0x0
 
2485
#define   VisualIDMask                 0x1
 
2486
#define   VisualScreenMask             0x2
 
2487
#define   VisualDepthMask              0x4
 
2488
#define   VisualClassMask              0x8
 
2489
#define   VisualRedMaskMask            0x10
 
2490
#define   VisualGreenMaskMask          0x20
 
2491
#define   VisualBlueMaskMask           0x40
 
2492
#define   VisualColormapSizeMask       0x80
 
2493
#define   VisualBitsPerRGBMask         0x100
 
2494
#define   VisualAllMask                0x1FF
 
2495
 
 
2496
</literallayout>
 
2497
 
 
2498
<literallayout class="monospaced">
 
2499
<!-- .TA .5i 3i -->
 
2500
<!-- .ta .5i 3i -->
 
2501
/* Values */
 
2502
 
 
2503
typedef struct {
 
2504
     Visual *visual;
 
2505
     VisualID visualid;
 
2506
     int screen;
 
2507
     unsigned int depth;
 
2508
     int class;
 
2509
     unsigned long red_mask;
 
2510
     unsigned long green_mask;
 
2511
     unsigned long blue_mask;
 
2512
     int colormap_size;
 
2513
     int bits_per_rgb;
 
2514
} XVisualInfo;
 
2515
</literallayout>
 
2516
 
 
2517
<para>
 
2518
<!-- .LP -->
 
2519
<!-- .eM -->
 
2520
To obtain a list of visual information structures that match a specified
 
2521
template, use
 
2522
<function>XGetVisualInfo</function>.
 
2523
<indexterm significance="preferred"><primary>XGetVisualInfo</primary></indexterm>
 
2524
<!-- .sM -->
 
2525
<funcsynopsis>
 
2526
<funcprototype>
 
2527
  <funcdef>XVisualInfo *<function>XGetVisualInfo</function></funcdef>
 
2528
  <paramdef>Display<parameter> *display</parameter></paramdef>
 
2529
  <paramdef>long<parameter> vinfo_mask</parameter></paramdef>
 
2530
  <paramdef>XVisualInfo<parameter> *vinfo_template</parameter></paramdef>
 
2531
  <paramdef>int<parameter> *nitems_return</parameter></paramdef>
 
2532
</funcprototype>
 
2533
</funcsynopsis>
 
2534
<!-- .FN -->
 
2535
<variablelist>
 
2536
  <varlistentry>
 
2537
    <term>
 
2538
      <emphasis remap='I'>display</emphasis>
 
2539
    </term>
 
2540
    <listitem>
 
2541
      <para>
 
2542
Specifies the connection to the X server.
 
2543
      </para>
 
2544
    </listitem>
 
2545
  </varlistentry>
 
2546
  <varlistentry>
 
2547
    <term>
 
2548
      <emphasis remap='I'>vinfo_mask</emphasis>
 
2549
    </term>
 
2550
    <listitem>
 
2551
      <para>
 
2552
Specifies the visual mask value.
 
2553
      </para>
 
2554
    </listitem>
 
2555
  </varlistentry>
 
2556
  <varlistentry>
 
2557
    <term>
 
2558
      <emphasis remap='I'>vinfo_template</emphasis>
 
2559
    </term>
 
2560
    <listitem>
 
2561
      <para>
 
2562
Specifies the visual attributes that are to be used in matching the visual
 
2563
structures.
 
2564
      </para>
 
2565
    </listitem>
 
2566
  </varlistentry>
 
2567
  <varlistentry>
 
2568
    <term>
 
2569
      <emphasis remap='I'>nitems_return</emphasis>
 
2570
    </term>
 
2571
    <listitem>
 
2572
      <para>
 
2573
Returns the number of matching visual structures.
 
2574
    </para>
 
2575
  </listitem>
 
2576
  </varlistentry>
 
2577
</variablelist>
 
2578
</para>
 
2579
<para>
 
2580
<!-- .LP -->
 
2581
<!-- .eM -->
 
2582
The
 
2583
<function>XGetVisualInfo</function>
 
2584
function returns a list of visual structures that have attributes 
 
2585
equal to the attributes specified by vinfo_template.
 
2586
If no visual structures match the template using the specified vinfo_mask,
 
2587
<function>XGetVisualInfo</function>
 
2588
returns a NULL.
 
2589
To free the data returned by this function, use
 
2590
<function>XFree</function>.
 
2591
</para>
 
2592
<para>
 
2593
<!-- .LP -->
 
2594
<!-- .sp -->
 
2595
To obtain the visual information that matches the specified depth and
 
2596
class of the screen, use
 
2597
<function>XMatchVisualInfo</function>.
 
2598
<indexterm significance="preferred"><primary>XMatchVisualInfo</primary></indexterm>
 
2599
<!-- .sM -->
 
2600
<funcsynopsis>
 
2601
<funcprototype>
 
2602
  <funcdef>Status <function>XMatchVisualInfo</function></funcdef>
 
2603
  <paramdef>Display<parameter> *display</parameter></paramdef>
 
2604
  <paramdef>int<parameter> screen</parameter></paramdef>
 
2605
  <paramdef>int<parameter> depth</parameter></paramdef>
 
2606
  <paramdef>int<parameter> class</parameter></paramdef>
 
2607
  <paramdef>XVisualInfo<parameter> *vinfo_return</parameter></paramdef>
 
2608
</funcprototype>
 
2609
</funcsynopsis>
 
2610
<!-- .FN -->
 
2611
<variablelist>
 
2612
  <varlistentry>
 
2613
    <term>
 
2614
      <emphasis remap='I'>display</emphasis>
 
2615
    </term>
 
2616
    <listitem>
 
2617
      <para>
 
2618
Specifies the connection to the X server.
 
2619
      </para>
 
2620
    </listitem>
 
2621
  </varlistentry>
 
2622
  <varlistentry>
 
2623
    <term>
 
2624
      <emphasis remap='I'>screen</emphasis>
 
2625
    </term>
 
2626
    <listitem>
 
2627
      <para>
 
2628
Specifies the screen.
 
2629
      </para>
 
2630
    </listitem>
 
2631
  </varlistentry>
 
2632
  <varlistentry>
 
2633
    <term>
 
2634
      <emphasis remap='I'>depth</emphasis>
 
2635
    </term>
 
2636
    <listitem>
 
2637
      <para>
 
2638
Specifies the depth of the screen.
 
2639
      </para>
 
2640
    </listitem>
 
2641
  </varlistentry>
 
2642
  <varlistentry>
 
2643
    <term>
 
2644
      <emphasis remap='I'>class</emphasis>
 
2645
    </term>
 
2646
    <listitem>
 
2647
      <para>
 
2648
Specifies the class of the screen.
 
2649
      </para>
 
2650
    </listitem>
 
2651
  </varlistentry>
 
2652
  <varlistentry>
 
2653
    <term>
 
2654
      <emphasis remap='I'>vinfo_return</emphasis>
 
2655
    </term>
 
2656
    <listitem>
 
2657
      <para>
 
2658
Returns the matched visual information.
 
2659
    </para>
 
2660
  </listitem>
 
2661
  </varlistentry>
 
2662
</variablelist>
 
2663
</para>
 
2664
<para>
 
2665
<!-- .LP -->
 
2666
<!-- .eM -->
 
2667
The
 
2668
<function>XMatchVisualInfo</function>
 
2669
function returns the visual information for a visual that matches the specified
 
2670
depth and class for a screen.
 
2671
Because multiple visuals that match the specified depth and class can exist,
 
2672
the exact visual chosen is undefined.
 
2673
If a visual is found,
 
2674
<function>XMatchVisualInfo</function>
 
2675
returns nonzero and the information on the visual to vinfo_return.
 
2676
Otherwise, when a visual is not found,
 
2677
<function>XMatchVisualInfo</function>
 
2678
returns zero.
 
2679
</para>
 
2680
</sect1>
 
2681
<sect1 id="Manipulating_Images">
 
2682
<title>Manipulating Images</title>
 
2683
<!-- .XS -->
 
2684
<!-- (SN Manipulating Images  -->
 
2685
<!-- .XE -->
 
2686
<para>
 
2687
<!-- .LP -->
 
2688
Xlib provides several functions that perform basic operations on images.
 
2689
All operations on images are defined using an 
 
2690
<structname>XImage</structname>
 
2691
structure, 
 
2692
as defined in
 
2693
<filename class="headerfile">&lt;X11/Xlib.h&gt;</filename>.
 
2694
<indexterm type="file"><primary><filename class="headerfile">X11/Xlib.h</filename></primary></indexterm>
 
2695
<indexterm><primary>Files</primary><secondary><filename class="headerfile">&lt;X11/Xlib.h&gt;</filename></secondary></indexterm>
 
2696
<indexterm><primary>Headers</primary><secondary><filename class="headerfile">&lt;X11/Xlib.h&gt;</filename></secondary></indexterm>
 
2697
Because the number of different types of image formats can be very large,
 
2698
this hides details of image storage properly from applications.
 
2699
</para>
 
2700
<para>
 
2701
<!-- .LP -->
 
2702
This section describes the functions for generic operations on images.
 
2703
Manufacturers can provide very fast implementations of these for the
 
2704
formats frequently encountered on their hardware.
 
2705
These functions are neither sufficient nor desirable to use for general image
 
2706
processing.
 
2707
Rather, they are here to provide minimal functions on screen format
 
2708
images.
 
2709
The basic operations for getting and putting images are
 
2710
<function>XGetImage</function>
 
2711
and 
 
2712
<function>XPutImage</function>.
 
2713
</para>
 
2714
<para>
 
2715
<!-- .LP -->
 
2716
Note that no functions have been defined, as yet, to read and write images 
 
2717
to and from disk files.
 
2718
</para>
 
2719
<para>
 
2720
<!-- .LP -->
 
2721
The
 
2722
<structname>XImage</structname>
 
2723
structure describes an image as it exists in the client's memory.  
 
2724
The user can request that some of the members such as height, width, 
 
2725
and xoffset be changed when the image is sent to the server.
 
2726
Note that bytes_per_line in concert with offset can be used to
 
2727
extract a subset of the image.
 
2728
Other members (for example, byte order, bitmap_unit, and so forth)
 
2729
are characteristics of both the image and the server.  
 
2730
If these members
 
2731
differ between the image and the server, 
 
2732
<function>XPutImage</function>
 
2733
makes the appropriate conversions.
 
2734
The first byte of the first line of
 
2735
plane n must be located at the address (data + (n * height * bytes_per_line)).
 
2736
For a description of the 
 
2737
<structname>XImage</structname>
 
2738
structure,
 
2739
see section 8.7.
 
2740
</para>
 
2741
<para>
 
2742
<!-- .LP -->
 
2743
<!-- .sp -->
 
2744
To allocate an 
 
2745
<structname>XImage</structname>
 
2746
structure and initialize it with image format values from a display, use
 
2747
<function>XCreateImage</function>.
 
2748
<indexterm significance="preferred"><primary>XCreateImage</primary></indexterm>
 
2749
<!-- .sM -->
 
2750
<funcsynopsis>
 
2751
<funcprototype>
 
2752
  <funcdef>XImage *<function>XCreateImage</function></funcdef>
 
2753
  <paramdef>Display<parameter> *display</parameter></paramdef>
 
2754
  <paramdef>Visual<parameter> *visual</parameter></paramdef>
 
2755
  <paramdef>unsignedint<parameter> depth</parameter></paramdef>
 
2756
  <paramdef>int<parameter> format</parameter></paramdef>
 
2757
  <paramdef>int<parameter> offset</parameter></paramdef>
 
2758
  <paramdef>char<parameter> *data</parameter></paramdef>
 
2759
  <paramdef>unsignedint<parameter> width</parameter></paramdef>
 
2760
  <paramdef>unsignedint<parameter> height</parameter></paramdef>
 
2761
  <paramdef>int<parameter> bitmap_pad</parameter></paramdef>
 
2762
  <paramdef>int<parameter> bytes_per_line</parameter></paramdef>
 
2763
</funcprototype>
 
2764
</funcsynopsis>
 
2765
<!-- .FN -->
 
2766
<variablelist>
 
2767
  <varlistentry>
 
2768
    <term>
 
2769
      <emphasis remap='I'>display</emphasis>
 
2770
    </term>
 
2771
    <listitem>
 
2772
      <para>
 
2773
Specifies the connection to the X server.
 
2774
      </para>
 
2775
    </listitem>
 
2776
  </varlistentry>
 
2777
  <varlistentry>
 
2778
    <term>
 
2779
      <emphasis remap='I'>visual</emphasis>
 
2780
    </term>
 
2781
    <listitem>
 
2782
      <para>
 
2783
Specifies the
 
2784
<structname>Visual</structname>
 
2785
structure.
 
2786
      </para>
 
2787
    </listitem>
 
2788
  </varlistentry>
 
2789
  <varlistentry>
 
2790
    <term>
 
2791
      <emphasis remap='I'>depth</emphasis>
 
2792
    </term>
 
2793
    <listitem>
 
2794
      <para>
 
2795
Specifies the depth of the image.
 
2796
      </para>
 
2797
    </listitem>
 
2798
  </varlistentry>
 
2799
  <varlistentry>
 
2800
    <term>
 
2801
      <emphasis remap='I'>format</emphasis>
 
2802
    </term>
 
2803
    <listitem>
 
2804
      <para>
 
2805
Specifies the format for the image.
 
2806
You can pass
 
2807
<symbol>XYBitmap</symbol>,
 
2808
<symbol>XYPixmap</symbol>,
 
2809
or 
 
2810
<symbol>ZPixmap</symbol>.
 
2811
      </para>
 
2812
    </listitem>
 
2813
  </varlistentry>
 
2814
  <varlistentry>
 
2815
    <term>
 
2816
      <emphasis remap='I'>offset</emphasis>
 
2817
    </term>
 
2818
    <listitem>
 
2819
      <para>
 
2820
Specifies the number of pixels to ignore at the beginning of the scanline.
 
2821
      </para>
 
2822
    </listitem>
 
2823
  </varlistentry>
 
2824
  <varlistentry>
 
2825
    <term>
 
2826
      <emphasis remap='I'>data</emphasis>
 
2827
    </term>
 
2828
    <listitem>
 
2829
      <para>
 
2830
Specifies the image data.
 
2831
      </para>
 
2832
    </listitem>
 
2833
  </varlistentry>
 
2834
  <varlistentry>
 
2835
    <term>
 
2836
      <emphasis remap='I'>width</emphasis>
 
2837
    </term>
 
2838
    <listitem>
 
2839
      <para>
 
2840
Specifies the width of the image, in pixels.
 
2841
      </para>
 
2842
    </listitem>
 
2843
  </varlistentry>
 
2844
  <varlistentry>
 
2845
    <term>
 
2846
      <emphasis remap='I'>height</emphasis>
 
2847
    </term>
 
2848
    <listitem>
 
2849
      <para>
 
2850
Specifies the height of the image, in pixels.
 
2851
      </para>
 
2852
    </listitem>
 
2853
  </varlistentry>
 
2854
  <varlistentry>
 
2855
    <term>
 
2856
      <emphasis remap='I'>bitmap_pad</emphasis>
 
2857
    </term>
 
2858
    <listitem>
 
2859
      <para>
 
2860
Specifies the quantum of a scanline (8, 16, or 32).
 
2861
In other words, the start of one scanline is separated in client memory from 
 
2862
the start of the next scanline by an integer multiple of this many bits.  
 
2863
      </para>
 
2864
    </listitem>
 
2865
  </varlistentry>
 
2866
  <varlistentry>
 
2867
    <term>
 
2868
      <emphasis remap='I'>bytes_per_line</emphasis>
 
2869
    </term>
 
2870
    <listitem>
 
2871
      <para>
 
2872
Specifies the number of bytes in the client image between
 
2873
the start of one scanline and the start of the next.  
 
2874
    </para>
 
2875
  </listitem>
 
2876
  </varlistentry>
 
2877
</variablelist>
 
2878
</para>
 
2879
<para>
 
2880
<!-- .LP -->
 
2881
<!-- .eM -->
 
2882
The
 
2883
<function>XCreateImage</function>
 
2884
function allocates the memory needed for an
 
2885
<structname>XImage</structname>
 
2886
structure for the
 
2887
specified display but does not allocate space for the image itself.
 
2888
Rather, it initializes the structure byte-order, bit-order, and bitmap-unit
 
2889
values from the display and returns a pointer to the 
 
2890
<structname>XImage</structname>
 
2891
structure.
 
2892
The red, green, and blue mask values are defined for Z format images only
 
2893
and are derived from the 
 
2894
<structname>Visual</structname>
 
2895
structure passed in.
 
2896
Other values also are passed in.
 
2897
The offset permits the rapid displaying of the image without requiring each 
 
2898
scanline to be shifted into position.
 
2899
If you pass a zero value in bytes_per_line,
 
2900
Xlib assumes that the scanlines are contiguous
 
2901
in memory and calculates the value of bytes_per_line itself.
 
2902
</para>
 
2903
<para>
 
2904
<!-- .LP -->
 
2905
Note that when the image is created using
 
2906
<function>XCreateImage</function>,
 
2907
<function>XGetImage</function>,
 
2908
or
 
2909
<function>XSubImage</function>,
 
2910
the destroy procedure that the 
 
2911
<function>XDestroyImage</function>
 
2912
function calls frees both the image structure 
 
2913
and the data pointed to by the image structure.
 
2914
</para>
 
2915
<para>
 
2916
<!-- .LP -->
 
2917
The basic functions used to get a pixel, set a pixel, create a subimage,
 
2918
and add a constant value to an image are defined in the image object.
 
2919
The functions in this section are really macro invocations of the functions
 
2920
in the image object and are defined in
 
2921
<filename class="headerfile">&lt;X11/Xutil.h&gt;</filename>.
 
2922
<indexterm type="file"><primary><filename class="headerfile">X11/Xutil.h</filename></primary></indexterm>
 
2923
<indexterm><primary>Files</primary><secondary><filename class="headerfile">&lt;X11/Xutil.h&gt;</filename></secondary></indexterm>
 
2924
<indexterm><primary>Headers</primary><secondary><filename class="headerfile">&lt;X11/Xutil.h&gt;</filename></secondary></indexterm>
 
2925
</para>
 
2926
<para>
 
2927
<!-- .LP -->
 
2928
<!-- .sp -->
 
2929
To obtain a pixel value in an image, use
 
2930
<function>XGetPixel</function>.
 
2931
<indexterm significance="preferred"><primary>XGetPixel</primary></indexterm>
 
2932
<!-- .sM -->
 
2933
<funcsynopsis>
 
2934
<funcprototype>
 
2935
  <funcdef>unsigned long <function>XGetPixel</function></funcdef>
 
2936
  <paramdef>XImage<parameter> *ximage</parameter></paramdef>
 
2937
  <paramdef>int<parameter> x</parameter></paramdef>
 
2938
  <paramdef>int<parameter> y</parameter></paramdef>
 
2939
</funcprototype>
 
2940
</funcsynopsis>
 
2941
<!-- .FN -->
 
2942
<variablelist>
 
2943
  <varlistentry>
 
2944
    <term>
 
2945
      <emphasis remap='I'>ximage</emphasis>
 
2946
    </term>
 
2947
    <listitem>
 
2948
      <para>
 
2949
Specifies the image.
 
2950
      </para>
 
2951
    </listitem>
 
2952
  </varlistentry>
 
2953
  <varlistentry>
 
2954
    <term>
 
2955
      <emphasis remap='I'>x</emphasis>
 
2956
    </term>
 
2957
    <listitem>
 
2958
      <para>
 
2959
<!-- .br -->
 
2960
<!-- .ns -->
 
2961
      </para>
 
2962
    </listitem>
 
2963
  </varlistentry>
 
2964
  <varlistentry>
 
2965
    <term>
 
2966
      <emphasis remap='I'>y</emphasis>
 
2967
    </term>
 
2968
    <listitem>
 
2969
      <para>
 
2970
Specify the x and y coordinates.
 
2971
    </para>
 
2972
  </listitem>
 
2973
  </varlistentry>
 
2974
</variablelist>
 
2975
</para>
 
2976
<para>
 
2977
<!-- .LP -->
 
2978
<!-- .eM -->
 
2979
The
 
2980
<function>XGetPixel</function>
 
2981
function returns the specified pixel from the named image.
 
2982
The pixel value is returned in normalized format (that is,
 
2983
the least significant byte of the long is the least significant byte
 
2984
of the pixel).
 
2985
The image must contain the x and y coordinates.
 
2986
</para>
 
2987
<para>
 
2988
<!-- .LP -->
 
2989
<!-- .sp -->
 
2990
To set a pixel value in an image, use
 
2991
<function>XPutPixel</function>.
 
2992
<indexterm significance="preferred"><primary>XPutPixel</primary></indexterm>
 
2993
<!-- .sM -->
 
2994
<funcsynopsis>
 
2995
<funcprototype>
 
2996
  <funcdef><function>XPutPixel</function></funcdef>
 
2997
  <paramdef>XImage<parameter> *ximage</parameter></paramdef>
 
2998
  <paramdef>int<parameter> x</parameter></paramdef>
 
2999
  <paramdef>int<parameter> y</parameter></paramdef>
 
3000
  <paramdef>unsignedlong<parameter> pixel</parameter></paramdef>
 
3001
</funcprototype>
 
3002
</funcsynopsis>
 
3003
<!-- .FN -->
 
3004
<variablelist>
 
3005
  <varlistentry>
 
3006
    <term>
 
3007
      <emphasis remap='I'>ximage</emphasis>
 
3008
    </term>
 
3009
    <listitem>
 
3010
      <para>
 
3011
Specifies the image.
 
3012
      </para>
 
3013
    </listitem>
 
3014
  </varlistentry>
 
3015
  <varlistentry>
 
3016
    <term>
 
3017
      <emphasis remap='I'>x</emphasis>
 
3018
    </term>
 
3019
    <listitem>
 
3020
      <para>
 
3021
<!-- .br -->
 
3022
<!-- .ns -->
 
3023
      </para>
 
3024
    </listitem>
 
3025
  </varlistentry>
 
3026
  <varlistentry>
 
3027
    <term>
 
3028
      <emphasis remap='I'>y</emphasis>
 
3029
    </term>
 
3030
    <listitem>
 
3031
      <para>
 
3032
Specify the x and y coordinates.
 
3033
      </para>
 
3034
    </listitem>
 
3035
  </varlistentry>
 
3036
  <varlistentry>
 
3037
    <term>
 
3038
      <emphasis remap='I'>pixel</emphasis>
 
3039
    </term>
 
3040
    <listitem>
 
3041
      <para>
 
3042
Specifies the new pixel value.
 
3043
    </para>
 
3044
  </listitem>
 
3045
  </varlistentry>
 
3046
</variablelist>
 
3047
</para>
 
3048
<para>
 
3049
<!-- .LP -->
 
3050
<!-- .eM -->
 
3051
The
 
3052
<function>XPutPixel</function>
 
3053
function overwrites the pixel in the named image with the specified pixel value.
 
3054
The input pixel value must be in normalized format
 
3055
(that is, the least significant byte of the long is the least significant
 
3056
byte of the pixel).
 
3057
The image must contain the x and y coordinates.
 
3058
</para>
 
3059
<para>
 
3060
<!-- .LP -->
 
3061
<!-- .sp -->
 
3062
To create a subimage, use
 
3063
<function>XSubImage</function>.
 
3064
<indexterm significance="preferred"><primary>XSubImage</primary></indexterm>
 
3065
<!-- .sM -->
 
3066
<funcsynopsis>
 
3067
<funcprototype>
 
3068
  <funcdef>XImage *<function>XSubImage</function></funcdef>
 
3069
  <paramdef>XImage<parameter> *ximage</parameter></paramdef>
 
3070
  <paramdef>int<parameter> x</parameter></paramdef>
 
3071
  <paramdef>int<parameter> y</parameter></paramdef>
 
3072
  <paramdef>unsignedint<parameter> subimage_width</parameter></paramdef>
 
3073
  <paramdef>unsignedint<parameter> subimage_height</parameter></paramdef>
 
3074
</funcprototype>
 
3075
</funcsynopsis>
 
3076
<!-- .FN -->
 
3077
<variablelist>
 
3078
  <varlistentry>
 
3079
    <term>
 
3080
      <emphasis remap='I'>ximage</emphasis>
 
3081
    </term>
 
3082
    <listitem>
 
3083
      <para>
 
3084
Specifies the image.
 
3085
      </para>
 
3086
    </listitem>
 
3087
  </varlistentry>
 
3088
  <varlistentry>
 
3089
    <term>
 
3090
      <emphasis remap='I'>x</emphasis>
 
3091
    </term>
 
3092
    <listitem>
 
3093
      <para>
 
3094
<!-- .br -->
 
3095
<!-- .ns -->
 
3096
      </para>
 
3097
    </listitem>
 
3098
  </varlistentry>
 
3099
  <varlistentry>
 
3100
    <term>
 
3101
      <emphasis remap='I'>y</emphasis>
 
3102
    </term>
 
3103
    <listitem>
 
3104
      <para>
 
3105
Specify the x and y coordinates.
 
3106
      </para>
 
3107
    </listitem>
 
3108
  </varlistentry>
 
3109
  <varlistentry>
 
3110
    <term>
 
3111
      <emphasis remap='I'>subimage_width</emphasis>
 
3112
    </term>
 
3113
    <listitem>
 
3114
      <para>
 
3115
Specifies the width of the new subimage, in pixels.
 
3116
      </para>
 
3117
    </listitem>
 
3118
  </varlistentry>
 
3119
  <varlistentry>
 
3120
    <term>
 
3121
      <emphasis remap='I'>subimage_height</emphasis>
 
3122
    </term>
 
3123
    <listitem>
 
3124
      <para>
 
3125
Specifies the height of the new subimage, in pixels.
 
3126
    </para>
 
3127
  </listitem>
 
3128
  </varlistentry>
 
3129
</variablelist>
 
3130
</para>
 
3131
<para>
 
3132
<!-- .LP -->
 
3133
<!-- .eM -->
 
3134
The
 
3135
<function>XSubImage</function>
 
3136
function creates a new image that is a subsection of an existing one.
 
3137
It allocates the memory necessary for the new
 
3138
<structname>XImage</structname>
 
3139
structure
 
3140
and returns a pointer to the new image.
 
3141
The data is copied from the source image,
 
3142
and the image must contain the rectangle defined by x, y, subimage_width,
 
3143
and subimage_height.
 
3144
</para>
 
3145
<para>
 
3146
<!-- .LP -->
 
3147
<!-- .sp -->
 
3148
To increment each pixel in an image by a constant value, use
 
3149
<function>XAddPixel</function>.
 
3150
<indexterm significance="preferred"><primary>XAddPixel</primary></indexterm>
 
3151
<!-- .sM -->
 
3152
<funcsynopsis>
 
3153
<funcprototype>
 
3154
  <funcdef><function>XAddPixel</function></funcdef>
 
3155
  <paramdef>XImage<parameter> *ximage</parameter></paramdef>
 
3156
  <paramdef>long<parameter> value</parameter></paramdef>
 
3157
</funcprototype>
 
3158
</funcsynopsis>
 
3159
<!-- .FN -->
 
3160
<variablelist>
 
3161
  <varlistentry>
 
3162
    <term>
 
3163
      <emphasis remap='I'>ximage</emphasis>
 
3164
    </term>
 
3165
    <listitem>
 
3166
      <para>
 
3167
Specifies the image.
 
3168
      </para>
 
3169
    </listitem>
 
3170
  </varlistentry>
 
3171
  <varlistentry>
 
3172
    <term>
 
3173
      <emphasis remap='I'>value</emphasis>
 
3174
    </term>
 
3175
    <listitem>
 
3176
      <para>
 
3177
Specifies the constant value that is to be added.
 
3178
    </para>
 
3179
  </listitem>
 
3180
  </varlistentry>
 
3181
</variablelist>
 
3182
</para>
 
3183
<para>
 
3184
<!-- .LP -->
 
3185
<!-- .eM -->
 
3186
The
 
3187
<function>XAddPixel</function>
 
3188
function adds a constant value to every pixel in an image.
 
3189
It is useful when you have a base pixel value from allocating
 
3190
color resources and need to manipulate the image to that form.
 
3191
</para>
 
3192
<para>
 
3193
<!-- .LP -->
 
3194
<!-- .sp -->
 
3195
To deallocate the memory allocated in a previous call to
 
3196
<function>XCreateImage</function>,
 
3197
use
 
3198
<function>XDestroyImage</function>.
 
3199
<indexterm significance="preferred"><primary>XDestroyImage</primary></indexterm>
 
3200
<!-- .sM -->
 
3201
<funcsynopsis>
 
3202
<funcprototype>
 
3203
  <funcdef><function>XDestroyImage</function></funcdef>
 
3204
  <paramdef>XImage *<parameter>ximage</parameter></paramdef>
 
3205
</funcprototype>
 
3206
</funcsynopsis>
 
3207
<!-- .FN -->
 
3208
<variablelist>
 
3209
  <varlistentry>
 
3210
    <term>
 
3211
      <emphasis remap='I'>ximage</emphasis>
 
3212
    </term>
 
3213
    <listitem>
 
3214
      <para>
 
3215
Specifies the image.
 
3216
    </para>
 
3217
  </listitem>
 
3218
  </varlistentry>
 
3219
</variablelist>
 
3220
</para>
 
3221
<para>
 
3222
<!-- .LP -->
 
3223
<!-- .eM -->
 
3224
The
 
3225
<function>XDestroyImage</function>
 
3226
function deallocates the memory associated with the
 
3227
<structname>XImage</structname>
 
3228
structure.
 
3229
</para>
 
3230
<para>
 
3231
<!-- .LP -->
 
3232
Note that when the image is created using
 
3233
<function>XCreateImage</function>,
 
3234
<function>XGetImage</function>,
 
3235
or 
 
3236
<function>XSubImage</function>,
 
3237
the destroy procedure that this macro calls
 
3238
frees both the image structure and the data pointed to by the image structure. 
 
3239
</para>
 
3240
</sect1>
 
3241
<sect1 id="Manipulating_Bitmaps">
 
3242
<title>Manipulating Bitmaps</title>
 
3243
<!-- .XS -->
 
3244
<!-- (SN Manipulating Bitmaps  -->
 
3245
<!-- .XE -->
 
3246
<para>
 
3247
<!-- .LP -->
 
3248
Xlib provides functions that you can use to read a bitmap from a file,
 
3249
save a bitmap to a file, or create a bitmap. 
 
3250
This section describes those functions that transfer bitmaps to and
 
3251
from the client's file system, thus allowing their reuse in a later
 
3252
connection (for example, from an entirely different client or to a
 
3253
different display or server).
 
3254
</para>
 
3255
<para>
 
3256
<!-- .LP -->
 
3257
The X version 11 bitmap file format is:
 
3258
</para>
 
3259
<para>
 
3260
<!-- .LP -->
 
3261
<!-- .sM -->
 
3262
<literallayout class="monospaced">
 
3263
#define <emphasis remap='I'>name</emphasis>_width <emphasis remap='I'>width</emphasis>
 
3264
#define <emphasis remap='I'>name</emphasis>_height <emphasis remap='I'>height</emphasis>
 
3265
#define <emphasis remap='I'>name</emphasis>_x_hot <emphasis remap='I'>x</emphasis>
 
3266
#define <emphasis remap='I'>name</emphasis>_y_hot <emphasis remap='I'>y</emphasis>
 
3267
static unsigned char <emphasis remap='I'>name</emphasis>_bits[] = { 0x<emphasis remap='I'>NN</emphasis>,... }
 
3268
</literallayout>
 
3269
</para>
 
3270
<para>
 
3271
<!-- .LP -->
 
3272
<!-- .eM -->
 
3273
The lines for the variables ending with _x_hot and _y_hot suffixes are optional
 
3274
because they are present only if a hotspot has been defined for this bitmap.
 
3275
The lines for the other variables are required.
 
3276
The word ``unsigned'' is optional;
 
3277
that is, the type of the _bits array can be ``char'' or ``unsigned char''.
 
3278
The _bits array must be large enough to contain the size bitmap.
 
3279
The bitmap unit is 8.
 
3280
</para>
 
3281
<para>
 
3282
<!-- .LP -->
 
3283
<!-- .sp -->
 
3284
To read a bitmap from a file and store it in a pixmap, use
 
3285
<function>XReadBitmapFile</function>.
 
3286
<indexterm significance="preferred"><primary>XReadBitmapFile</primary></indexterm>
 
3287
<!-- .sM -->
 
3288
<funcsynopsis>
 
3289
<funcprototype>
 
3290
  <funcdef>int <function>XReadBitmapFile</function></funcdef>
 
3291
  <paramdef>Display<parameter> *display</parameter></paramdef>
 
3292
  <paramdef>Drawable<parameter> d</parameter></paramdef>
 
3293
  <paramdef>char<parameter> *filename</parameter></paramdef>
 
3294
  <paramdef>unsignedint*width_return,<parameter> *height_return</parameter></paramdef>
 
3295
  <paramdef>Pixmap<parameter> *bitmap_return</parameter></paramdef>
 
3296
  <paramdef>int*x_hot_return,<parameter> *y_hot_return</parameter></paramdef>
 
3297
</funcprototype>
 
3298
</funcsynopsis>
 
3299
<!-- .FN -->
 
3300
<variablelist>
 
3301
  <varlistentry>
 
3302
    <term>
 
3303
      <emphasis remap='I'>display</emphasis>
 
3304
    </term>
 
3305
    <listitem>
 
3306
      <para>
 
3307
Specifies the connection to the X server.
 
3308
<!-- .ds Dr \ that indicates the screen -->
 
3309
      </para>
 
3310
    </listitem>
 
3311
  </varlistentry>
 
3312
  <varlistentry>
 
3313
    <term>
 
3314
      <emphasis remap='I'>d</emphasis>
 
3315
    </term>
 
3316
    <listitem>
 
3317
      <para>
 
3318
Specifies the drawable(Dr. 
 
3319
      </para>
 
3320
    </listitem>
 
3321
  </varlistentry>
 
3322
  <varlistentry>
 
3323
    <term>
 
3324
      <emphasis remap='I'>filename</emphasis>
 
3325
    </term>
 
3326
    <listitem>
 
3327
      <para>
 
3328
Specifies the file name to use.
 
3329
The format of the file name is operating-system dependent.
 
3330
      </para>
 
3331
    </listitem>
 
3332
  </varlistentry>
 
3333
  <varlistentry>
 
3334
    <term>
 
3335
      <emphasis remap='I'>width_return</emphasis>
 
3336
    </term>
 
3337
    <listitem>
 
3338
      <para>
 
3339
<!-- .br -->
 
3340
<!-- .ns -->
 
3341
      </para>
 
3342
    </listitem>
 
3343
  </varlistentry>
 
3344
  <varlistentry>
 
3345
    <term>
 
3346
      <emphasis remap='I'>height_return</emphasis>
 
3347
    </term>
 
3348
    <listitem>
 
3349
      <para>
 
3350
Return the width and height values of the read in bitmap file.
 
3351
      </para>
 
3352
    </listitem>
 
3353
  </varlistentry>
 
3354
  <varlistentry>
 
3355
    <term>
 
3356
      <emphasis remap='I'>bitmap_return</emphasis>
 
3357
    </term>
 
3358
    <listitem>
 
3359
      <para>
 
3360
Returns the bitmap that is created.
 
3361
      </para>
 
3362
    </listitem>
 
3363
  </varlistentry>
 
3364
  <varlistentry>
 
3365
    <term>
 
3366
      <emphasis remap='I'>x_hot_return</emphasis>
 
3367
    </term>
 
3368
    <listitem>
 
3369
      <para>
 
3370
<!-- .br -->
 
3371
<!-- .ns -->
 
3372
      </para>
 
3373
    </listitem>
 
3374
  </varlistentry>
 
3375
  <varlistentry>
 
3376
    <term>
 
3377
      <emphasis remap='I'>y_hot_return</emphasis>
 
3378
    </term>
 
3379
    <listitem>
 
3380
      <para>
 
3381
Return the hotspot coordinates.
 
3382
    </para>
 
3383
  </listitem>
 
3384
  </varlistentry>
 
3385
</variablelist>
 
3386
</para>
 
3387
<para>
 
3388
<!-- .LP -->
 
3389
<!-- .eM -->
 
3390
The
 
3391
<function>XReadBitmapFile</function>
 
3392
function reads in a file containing a bitmap.
 
3393
The file is parsed in the encoding of the current locale.
 
3394
The ability to read other than the standard format 
 
3395
is implementation-dependent.
 
3396
If the file cannot be opened, 
 
3397
<function>XReadBitmapFile</function>
 
3398
returns 
 
3399
<returnvalue>BitmapOpenFailed</returnvalue>.
 
3400
If the file can be opened but does not contain valid bitmap data, 
 
3401
it returns 
 
3402
<returnvalue>BitmapFileInvalid</returnvalue>.
 
3403
If insufficient working storage is allocated,
 
3404
it returns
 
3405
<returnvalue>BitmapNoMemory</returnvalue>.
 
3406
If the file is readable and valid,
 
3407
it returns 
 
3408
<returnvalue>BitmapSuccess</returnvalue>.
 
3409
</para>
 
3410
<para>
 
3411
<!-- .LP -->
 
3412
<function>XReadBitmapFile</function>
 
3413
returns the bitmap's height and width, as read
 
3414
from the file, to width_return and height_return.
 
3415
It then creates a pixmap of the appropriate size, 
 
3416
reads the bitmap data from the file into the pixmap,
 
3417
and assigns the pixmap to the caller's variable bitmap.  
 
3418
The caller must free the bitmap using 
 
3419
<function>XFreePixmap</function>
 
3420
when finished.
 
3421
If <emphasis remap='I'>name</emphasis>_x_hot and <emphasis remap='I'>name</emphasis>_y_hot exist,
 
3422
<function>XReadBitmapFile</function>
 
3423
returns them to x_hot_return and y_hot_return;
 
3424
otherwise, it returns &minus;1,&minus;1.
 
3425
</para>
 
3426
<para>
 
3427
<!-- .LP -->
 
3428
<function>XReadBitmapFile</function>
 
3429
can generate
 
3430
<errorname>BadAlloc</errorname>,
 
3431
<errorname>BadDrawable</errorname>,
 
3432
and
 
3433
<errorname>BadGC</errorname>
 
3434
errors.
 
3435
</para>
 
3436
<para>
 
3437
<!-- .LP -->
 
3438
<!-- .sp -->
 
3439
To read a bitmap from a file and return it as data, use
 
3440
<function>XReadBitmapFileData</function>.
 
3441
<indexterm significance="preferred"><primary>XReadBitmapFileData</primary></indexterm>
 
3442
<!-- .sM -->
 
3443
<funcsynopsis>
 
3444
<funcprototype>
 
3445
  <funcdef>int <function>XReadBitmapFileData</function></funcdef>
 
3446
  <paramdef>char<parameter> *filename</parameter></paramdef>
 
3447
  <paramdef>unsignedint*width_return,<parameter> *height_return</parameter></paramdef>
 
3448
  <paramdef>unsignedchar<parameter> *data_return</parameter></paramdef>
 
3449
  <paramdef>int*x_hot_return,<parameter> *y_hot_return</parameter></paramdef>
 
3450
</funcprototype>
 
3451
</funcsynopsis>
 
3452
<!-- .FN -->
 
3453
<variablelist>
 
3454
  <varlistentry>
 
3455
    <term>
 
3456
      <emphasis remap='I'>filename</emphasis>
 
3457
    </term>
 
3458
    <listitem>
 
3459
      <para>
 
3460
Specifies the file name to use.
 
3461
The format of the file name is operating-system dependent.
 
3462
      </para>
 
3463
    </listitem>
 
3464
  </varlistentry>
 
3465
  <varlistentry>
 
3466
    <term>
 
3467
      <emphasis remap='I'>width_return</emphasis>
 
3468
    </term>
 
3469
    <listitem>
 
3470
      <para>
 
3471
<!-- .br -->
 
3472
<!-- .ns -->
 
3473
      </para>
 
3474
    </listitem>
 
3475
  </varlistentry>
 
3476
  <varlistentry>
 
3477
    <term>
 
3478
      <emphasis remap='I'>height_return</emphasis>
 
3479
    </term>
 
3480
    <listitem>
 
3481
      <para>
 
3482
Return the width and height values of the read in bitmap file.
 
3483
      </para>
 
3484
    </listitem>
 
3485
  </varlistentry>
 
3486
  <varlistentry>
 
3487
    <term>
 
3488
      <emphasis remap='I'>data_return</emphasis>
 
3489
    </term>
 
3490
    <listitem>
 
3491
      <para>
 
3492
Returns the bitmap data.
 
3493
      </para>
 
3494
    </listitem>
 
3495
  </varlistentry>
 
3496
  <varlistentry>
 
3497
    <term>
 
3498
      <emphasis remap='I'>x_hot_return</emphasis>
 
3499
    </term>
 
3500
    <listitem>
 
3501
      <para>
 
3502
<!-- .br -->
 
3503
<!-- .ns -->
 
3504
      </para>
 
3505
    </listitem>
 
3506
  </varlistentry>
 
3507
  <varlistentry>
 
3508
    <term>
 
3509
      <emphasis remap='I'>y_hot_return</emphasis>
 
3510
    </term>
 
3511
    <listitem>
 
3512
      <para>
 
3513
Return the hotspot coordinates.
 
3514
    </para>
 
3515
  </listitem>
 
3516
  </varlistentry>
 
3517
</variablelist>
 
3518
</para>
 
3519
<para>
 
3520
<!-- .LP -->
 
3521
<!-- .eM -->
 
3522
The
 
3523
<function>XReadBitmapFileData</function>
 
3524
function reads in a file containing a bitmap, in the same manner as
 
3525
<function>XReadBitmapFile</function>,
 
3526
but returns the data directly rather than creating a pixmap in the server.
 
3527
The bitmap data is returned in data_return; the client must free this
 
3528
storage when finished with it by calling
 
3529
<function>XFree</function>.
 
3530
The status and other return values are the same as for
 
3531
<function>XReadBitmapFile</function>.
 
3532
</para>
 
3533
<para>
 
3534
<!-- .LP -->
 
3535
<!-- .sp -->
 
3536
To write out a bitmap from a pixmap to a file, use
 
3537
<function>XWriteBitmapFile</function>.
 
3538
<indexterm significance="preferred"><primary>XWriteBitmapFile</primary></indexterm>
 
3539
<!-- .sM -->
 
3540
<funcsynopsis>
 
3541
<funcprototype>
 
3542
  <funcdef>int <function>XWriteBitmapFile</function></funcdef>
 
3543
  <paramdef>Display<parameter> *display</parameter></paramdef>
 
3544
  <paramdef>char<parameter> *filename</parameter></paramdef>
 
3545
  <paramdef>Pixmap<parameter> bitmap</parameter></paramdef>
 
3546
  <paramdef>unsignedintwidth,<parameter> height</parameter></paramdef>
 
3547
  <paramdef>intx_hot,<parameter> y_hot</parameter></paramdef>
 
3548
</funcprototype>
 
3549
</funcsynopsis>
 
3550
<!-- .FN -->
 
3551
<variablelist>
 
3552
  <varlistentry>
 
3553
    <term>
 
3554
      <emphasis remap='I'>display</emphasis>
 
3555
    </term>
 
3556
    <listitem>
 
3557
      <para>
 
3558
Specifies the connection to the X server.
 
3559
      </para>
 
3560
    </listitem>
 
3561
  </varlistentry>
 
3562
  <varlistentry>
 
3563
    <term>
 
3564
      <emphasis remap='I'>filename</emphasis>
 
3565
    </term>
 
3566
    <listitem>
 
3567
      <para>
 
3568
Specifies the file name to use.
 
3569
The format of the file name is operating-system dependent.
 
3570
      </para>
 
3571
    </listitem>
 
3572
  </varlistentry>
 
3573
  <varlistentry>
 
3574
    <term>
 
3575
      <emphasis remap='I'>bitmap</emphasis>
 
3576
    </term>
 
3577
    <listitem>
 
3578
      <para>
 
3579
Specifies the bitmap.
 
3580
      </para>
 
3581
    </listitem>
 
3582
  </varlistentry>
 
3583
  <varlistentry>
 
3584
    <term>
 
3585
      <emphasis remap='I'>width</emphasis>
 
3586
    </term>
 
3587
    <listitem>
 
3588
      <para>
 
3589
<!-- .br -->
 
3590
<!-- .ns -->
 
3591
      </para>
 
3592
    </listitem>
 
3593
  </varlistentry>
 
3594
  <varlistentry>
 
3595
    <term>
 
3596
      <emphasis remap='I'>height</emphasis>
 
3597
    </term>
 
3598
    <listitem>
 
3599
      <para>
 
3600
Specify the width and height.
 
3601
      </para>
 
3602
    </listitem>
 
3603
  </varlistentry>
 
3604
  <varlistentry>
 
3605
    <term>
 
3606
      <emphasis remap='I'>x_hot</emphasis>
 
3607
    </term>
 
3608
    <listitem>
 
3609
      <para>
 
3610
<!-- .br -->
 
3611
<!-- .ns -->
 
3612
      </para>
 
3613
    </listitem>
 
3614
  </varlistentry>
 
3615
  <varlistentry>
 
3616
    <term>
 
3617
      <emphasis remap='I'>y_hot</emphasis>
 
3618
    </term>
 
3619
    <listitem>
 
3620
      <para>
 
3621
Specify where to place the hotspot coordinates (or &minus;1,&minus;1 if none are present)
 
3622
in the file.
 
3623
    </para>
 
3624
  </listitem>
 
3625
  </varlistentry>
 
3626
</variablelist>
 
3627
</para>
 
3628
<para>
 
3629
<!-- .LP -->
 
3630
<!-- .eM -->
 
3631
The
 
3632
<function>XWriteBitmapFile</function>
 
3633
function writes a bitmap out to a file in the X Version 11 format.
 
3634
The name used in the output file is derived from the file name
 
3635
by deleting the directory prefix.
 
3636
The file is written in the encoding of the current locale.
 
3637
If the file cannot be opened for writing, 
 
3638
it returns 
 
3639
<returnvalue>BitmapOpenFailed</returnvalue>.
 
3640
If insufficient memory is allocated,
 
3641
<function>XWriteBitmapFile</function>
 
3642
returns
 
3643
<returnvalue>BitmapNoMemory</returnvalue>;
 
3644
otherwise, on no error,
 
3645
it returns
 
3646
<returnvalue>BitmapSuccess</returnvalue>.
 
3647
If x_hot and y_hot are not &minus;1, &minus;1,
 
3648
<function>XWriteBitmapFile</function>
 
3649
writes them out as the hotspot coordinates for the bitmap.
 
3650
</para>
 
3651
<para>
 
3652
<!-- .LP -->
 
3653
<function>XWriteBitmapFile</function>
 
3654
can generate
 
3655
<errorname>BadDrawable</errorname>
 
3656
and
 
3657
<errorname>BadMatch</errorname>
 
3658
errors.
 
3659
</para>
 
3660
<para>
 
3661
<!-- .LP -->
 
3662
<!-- .sp -->
 
3663
To create a pixmap and then store bitmap-format data into it, use
 
3664
<function>XCreatePixmapFromBitmapData</function>.
 
3665
<indexterm significance="preferred"><primary>XCreatePixmapFromBitmapData</primary></indexterm>
 
3666
<!-- .sM -->
 
3667
<funcsynopsis>
 
3668
<funcprototype>
 
3669
  <funcdef>Pixmap <function>XCreatePixmapFromBitmapData</function></funcdef>
 
3670
  <paramdef>Display<parameter> *display</parameter></paramdef>
 
3671
  <paramdef>Drawable<parameter> d</parameter></paramdef>
 
3672
  <paramdef>char<parameter> *data</parameter></paramdef>
 
3673
  <paramdef>unsignedintwidth,<parameter> height</parameter></paramdef>
 
3674
  <paramdef>unsignedlongfg,<parameter> bg</parameter></paramdef>
 
3675
  <paramdef>unsignedint<parameter> depth</parameter></paramdef>
 
3676
</funcprototype>
 
3677
</funcsynopsis>
 
3678
<!-- .FN -->
 
3679
<variablelist>
 
3680
  <varlistentry>
 
3681
    <term>
 
3682
      <emphasis remap='I'>display</emphasis>
 
3683
    </term>
 
3684
    <listitem>
 
3685
      <para>
 
3686
Specifies the connection to the X server.
 
3687
<!-- .ds Dr \ that indicates the screen -->
 
3688
      </para>
 
3689
    </listitem>
 
3690
  </varlistentry>
 
3691
  <varlistentry>
 
3692
    <term>
 
3693
      <emphasis remap='I'>d</emphasis>
 
3694
    </term>
 
3695
    <listitem>
 
3696
      <para>
 
3697
Specifies the drawable(Dr. 
 
3698
      </para>
 
3699
    </listitem>
 
3700
  </varlistentry>
 
3701
  <varlistentry>
 
3702
    <term>
 
3703
      <emphasis remap='I'>data</emphasis>
 
3704
    </term>
 
3705
    <listitem>
 
3706
      <para>
 
3707
Specifies the data in bitmap format.
 
3708
      </para>
 
3709
    </listitem>
 
3710
  </varlistentry>
 
3711
  <varlistentry>
 
3712
    <term>
 
3713
      <emphasis remap='I'>width</emphasis>
 
3714
    </term>
 
3715
    <listitem>
 
3716
      <para>
 
3717
<!-- .br -->
 
3718
<!-- .ns -->
 
3719
      </para>
 
3720
    </listitem>
 
3721
  </varlistentry>
 
3722
  <varlistentry>
 
3723
    <term>
 
3724
      <emphasis remap='I'>height</emphasis>
 
3725
    </term>
 
3726
    <listitem>
 
3727
      <para>
 
3728
Specify the width and height.
 
3729
      </para>
 
3730
    </listitem>
 
3731
  </varlistentry>
 
3732
  <varlistentry>
 
3733
    <term>
 
3734
      <emphasis remap='I'>fg</emphasis>
 
3735
    </term>
 
3736
    <listitem>
 
3737
      <para>
 
3738
<!-- .br -->
 
3739
<!-- .ns -->
 
3740
      </para>
 
3741
    </listitem>
 
3742
  </varlistentry>
 
3743
  <varlistentry>
 
3744
    <term>
 
3745
      <emphasis remap='I'>bg</emphasis>
 
3746
    </term>
 
3747
    <listitem>
 
3748
      <para>
 
3749
Specify the foreground and background pixel values to use.
 
3750
      </para>
 
3751
    </listitem>
 
3752
  </varlistentry>
 
3753
  <varlistentry>
 
3754
    <term>
 
3755
      <emphasis remap='I'>depth</emphasis>
 
3756
    </term>
 
3757
    <listitem>
 
3758
      <para>
 
3759
Specifies the depth of the pixmap.
 
3760
    </para>
 
3761
  </listitem>
 
3762
  </varlistentry>
 
3763
</variablelist>
 
3764
</para>
 
3765
<para>
 
3766
<!-- .LP -->
 
3767
<!-- .eM -->
 
3768
The
 
3769
<function>XCreatePixmapFromBitmapData</function>
 
3770
function creates a pixmap of the given depth and then does a bitmap-format
 
3771
<function>XPutImage</function>
 
3772
of the data into it.
 
3773
The depth must be supported by the screen of the specified drawable,
 
3774
or a
 
3775
<errorname>BadMatch</errorname>
 
3776
error results.
 
3777
</para>
 
3778
<para>
 
3779
<!-- .LP -->
 
3780
<function>XCreatePixmapFromBitmapData</function>
 
3781
can generate
 
3782
<errorname>BadAlloc</errorname>,
 
3783
<errorname>BadDrawable</errorname>,
 
3784
<errorname>BadGC</errorname>,
 
3785
and
 
3786
<errorname>BadValue</errorname>
 
3787
errors.
 
3788
</para>
 
3789
<para>
 
3790
<!-- .LP -->
 
3791
<!-- .sp -->
 
3792
To include a bitmap written out by 
 
3793
<function>XWriteBitmapFile</function>
 
3794
<indexterm><primary>XWriteBitmapFile</primary></indexterm>
 
3795
in a program directly, as opposed to reading it in every time at run time, use
 
3796
<function>XCreateBitmapFromData</function>.
 
3797
<indexterm significance="preferred"><primary>XCreateBitmapFromData</primary></indexterm>
 
3798
<!-- .sM -->
 
3799
<funcsynopsis>
 
3800
<funcprototype>
 
3801
  <funcdef>Pixmap <function>XCreateBitmapFromData</function></funcdef>
 
3802
  <paramdef>Display<parameter> *display</parameter></paramdef>
 
3803
  <paramdef>Drawable<parameter> d</parameter></paramdef>
 
3804
  <paramdef>char<parameter> *data</parameter></paramdef>
 
3805
  <paramdef>unsignedintwidth,<parameter> height</parameter></paramdef>
 
3806
</funcprototype>
 
3807
</funcsynopsis>
 
3808
<!-- .FN -->
 
3809
<variablelist>
 
3810
  <varlistentry>
 
3811
    <term>
 
3812
      <emphasis remap='I'>display</emphasis>
 
3813
    </term>
 
3814
    <listitem>
 
3815
      <para>
 
3816
Specifies the connection to the X server.
 
3817
<!-- .ds Dr \ that indicates the screen -->
 
3818
      </para>
 
3819
    </listitem>
 
3820
  </varlistentry>
 
3821
  <varlistentry>
 
3822
    <term>
 
3823
      <emphasis remap='I'>d</emphasis>
 
3824
    </term>
 
3825
    <listitem>
 
3826
      <para>
 
3827
Specifies the drawable(Dr. 
 
3828
      </para>
 
3829
    </listitem>
 
3830
  </varlistentry>
 
3831
  <varlistentry>
 
3832
    <term>
 
3833
      <emphasis remap='I'>data</emphasis>
 
3834
    </term>
 
3835
    <listitem>
 
3836
      <para>
 
3837
Specifies the location of the bitmap data.
 
3838
      </para>
 
3839
    </listitem>
 
3840
  </varlistentry>
 
3841
  <varlistentry>
 
3842
    <term>
 
3843
      <emphasis remap='I'>width</emphasis>
 
3844
    </term>
 
3845
    <listitem>
 
3846
      <para>
 
3847
<!-- .br -->
 
3848
<!-- .ns -->
 
3849
      </para>
 
3850
    </listitem>
 
3851
  </varlistentry>
 
3852
  <varlistentry>
 
3853
    <term>
 
3854
      <emphasis remap='I'>height</emphasis>
 
3855
    </term>
 
3856
    <listitem>
 
3857
      <para>
 
3858
Specify the width and height.
 
3859
    </para>
 
3860
  </listitem>
 
3861
  </varlistentry>
 
3862
</variablelist>
 
3863
</para>
 
3864
<para>
 
3865
<!-- .LP -->
 
3866
<!-- .eM -->
 
3867
The
 
3868
<function>XCreateBitmapFromData</function>
 
3869
function allows you to include in your C program (using
 
3870
<code>#include</code>)
 
3871
a bitmap file that was written out by
 
3872
<function>XWriteBitmapFile</function>
 
3873
(X version 11 format only) without reading in the bitmap file.
 
3874
The following example creates a gray bitmap:
 
3875
</para>
 
3876
<para>
 
3877
<!-- .LP -->
 
3878
<literallayout class="monospaced">
 
3879
#include "gray.bitmap"
 
3880
<!-- .sp 6p -->
 
3881
Pixmap bitmap;
 
3882
bitmap = XCreateBitmapFromData(display, window, gray_bits, gray_width, gray_height);
 
3883
</literallayout>
 
3884
</para>
 
3885
<para>
 
3886
<!-- .LP -->
 
3887
If insufficient working storage was allocated,
 
3888
<function>XCreateBitmapFromData</function>
 
3889
returns
 
3890
<symbol>None</symbol>.
 
3891
It is your responsibility to free the
 
3892
bitmap using
 
3893
<function>XFreePixmap</function>
 
3894
when finished.
 
3895
</para>
 
3896
<para>
 
3897
<!-- .LP -->
 
3898
<function>XCreateBitmapFromData</function>
 
3899
can generate
 
3900
<errorname>BadAlloc</errorname>
 
3901
and
 
3902
<errorname>BadGC</errorname>
 
3903
errors.
 
3904
</para>
 
3905
</sect1>
 
3906
<sect1 id="Using_the_Context_Manager">
 
3907
<title>Using the Context Manager</title>
 
3908
<!-- .XS -->
 
3909
<!-- (SN Using the Context Manager  -->
 
3910
<!-- .XE -->
 
3911
<para>
 
3912
<!-- .LP -->
 
3913
The context manager provides a way of associating data with an X resource ID
 
3914
(mostly typically a window) in your program.  
 
3915
Note that this is local to your program;
 
3916
the data is not stored in the server on a property list.
 
3917
Any amount of data in any number of pieces can be associated with a
 
3918
resource ID,
 
3919
and each piece of data has a type associated with it.  
 
3920
The context manager requires knowledge of the resource ID
 
3921
and type to store or retrieve data.
 
3922
</para>
 
3923
<para>
 
3924
<!-- .LP -->
 
3925
Essentially, the context manager can be viewed as a two-dimensional, 
 
3926
sparse array:  one dimension is subscripted by the X resource ID
 
3927
and the other by a context type field.
 
3928
Each entry in the array contains a pointer to the data.
 
3929
Xlib provides context management functions with which you can
 
3930
save data values, get data values, delete entries, and create a unique
 
3931
context type.
 
3932
The symbols used are in
 
3933
<filename class="headerfile">&lt;X11/Xutil.h&gt;</filename>.
 
3934
<indexterm type="file"><primary><filename class="headerfile">X11/Xutil.h</filename></primary></indexterm>
 
3935
<indexterm><primary>Files</primary><secondary><filename class="headerfile">&lt;X11/Xutil.h&gt;</filename></secondary></indexterm>
 
3936
<indexterm><primary>Headers</primary><secondary><filename class="headerfile">&lt;X11/Xutil.h&gt;</filename></secondary></indexterm>
 
3937
</para>
 
3938
<para>
 
3939
<!-- .LP -->
 
3940
<!-- .sp -->
 
3941
To save a data value that corresponds to a resource ID and context type, use
 
3942
<function>XSaveContext</function>.
 
3943
<indexterm significance="preferred"><primary>XSaveContext</primary></indexterm>
 
3944
<!-- .sM -->
 
3945
<funcsynopsis>
 
3946
<funcprototype>
 
3947
  <funcdef>int <function>XSaveContext</function></funcdef>
 
3948
  <paramdef>Display<parameter> *display</parameter></paramdef>
 
3949
  <paramdef>XID<parameter> rid</parameter></paramdef>
 
3950
  <paramdef>XContext<parameter> context</parameter></paramdef>
 
3951
  <paramdef>XPointer<parameter> data</parameter></paramdef>
 
3952
</funcprototype>
 
3953
</funcsynopsis>
 
3954
<!-- .FN -->
 
3955
<variablelist>
 
3956
  <varlistentry>
 
3957
    <term>
 
3958
      <emphasis remap='I'>display</emphasis>
 
3959
    </term>
 
3960
    <listitem>
 
3961
      <para>
 
3962
Specifies the connection to the X server.
 
3963
      </para>
 
3964
    </listitem>
 
3965
  </varlistentry>
 
3966
  <varlistentry>
 
3967
    <term>
 
3968
      <emphasis remap='I'>rid</emphasis>
 
3969
    </term>
 
3970
    <listitem>
 
3971
      <para>
 
3972
Specifies the resource ID with which the data is associated.
 
3973
      </para>
 
3974
    </listitem>
 
3975
  </varlistentry>
 
3976
  <varlistentry>
 
3977
    <term>
 
3978
      <emphasis remap='I'>context</emphasis>
 
3979
    </term>
 
3980
    <listitem>
 
3981
      <para>
 
3982
Specifies the context type to which the data belongs.
 
3983
      </para>
 
3984
    </listitem>
 
3985
  </varlistentry>
 
3986
  <varlistentry>
 
3987
    <term>
 
3988
      <emphasis remap='I'>data</emphasis>
 
3989
    </term>
 
3990
    <listitem>
 
3991
      <para>
 
3992
Specifies the data to be associated with the window and type.
 
3993
    </para>
 
3994
  </listitem>
 
3995
  </varlistentry>
 
3996
</variablelist>
 
3997
</para>
 
3998
<para>
 
3999
<!-- .LP -->
 
4000
<!-- .eM -->
 
4001
If an entry with the specified resource ID and type already exists,
 
4002
<function>XSaveContext</function>
 
4003
overrides it with the specified context.
 
4004
The
 
4005
<function>XSaveContext</function>
 
4006
function returns a nonzero error code if an error has occurred
 
4007
and zero otherwise.
 
4008
Possible errors are
 
4009
<symbol>XCNOMEM</symbol>
 
4010
(out of memory).
 
4011
</para>
 
4012
<para>
 
4013
<!-- .LP -->
 
4014
<!-- .sp -->
 
4015
To get the data associated with a resource ID and type, use
 
4016
<function>XFindContext</function>.
 
4017
<indexterm significance="preferred"><primary>XFindContext</primary></indexterm>
 
4018
<!-- .sM -->
 
4019
<funcsynopsis>
 
4020
<funcprototype>
 
4021
  <funcdef>int <function>XFindContext</function></funcdef>
 
4022
  <paramdef>Display<parameter> *display</parameter></paramdef>
 
4023
  <paramdef>XID<parameter> rid</parameter></paramdef>
 
4024
  <paramdef>XContext<parameter> context</parameter></paramdef>
 
4025
  <paramdef>XPointer<parameter> *data_return</parameter></paramdef>
 
4026
</funcprototype>
 
4027
</funcsynopsis>
 
4028
<!-- .FN -->
 
4029
<variablelist>
 
4030
  <varlistentry>
 
4031
    <term>
 
4032
      <emphasis remap='I'>display</emphasis>
 
4033
    </term>
 
4034
    <listitem>
 
4035
      <para>
 
4036
Specifies the connection to the X server.
 
4037
      </para>
 
4038
    </listitem>
 
4039
  </varlistentry>
 
4040
  <varlistentry>
 
4041
    <term>
 
4042
      <emphasis remap='I'>rid</emphasis>
 
4043
    </term>
 
4044
    <listitem>
 
4045
      <para>
 
4046
Specifies the resource ID with which the data is associated.
 
4047
      </para>
 
4048
    </listitem>
 
4049
  </varlistentry>
 
4050
  <varlistentry>
 
4051
    <term>
 
4052
      <emphasis remap='I'>context</emphasis>
 
4053
    </term>
 
4054
    <listitem>
 
4055
      <para>
 
4056
Specifies the context type to which the data belongs.
 
4057
      </para>
 
4058
    </listitem>
 
4059
  </varlistentry>
 
4060
  <varlistentry>
 
4061
    <term>
 
4062
      <emphasis remap='I'>data_return</emphasis>
 
4063
    </term>
 
4064
    <listitem>
 
4065
      <para>
 
4066
Returns the data.
 
4067
    </para>
 
4068
  </listitem>
 
4069
  </varlistentry>
 
4070
</variablelist>
 
4071
</para>
 
4072
<para>
 
4073
<!-- .LP -->
 
4074
<!-- .eM -->
 
4075
Because it is a return value,
 
4076
the data is a pointer.
 
4077
The
 
4078
<function>XFindContext</function>
 
4079
function returns a nonzero error code if an error has occurred
 
4080
and zero otherwise.
 
4081
Possible errors are
 
4082
<symbol>XCNOENT</symbol>
 
4083
(context-not-found).
 
4084
</para>
 
4085
<para>
 
4086
<!-- .LP -->
 
4087
<!-- .sp -->
 
4088
To delete an entry for a given resource ID and type, use
 
4089
<function>XDeleteContext</function>.
 
4090
<indexterm significance="preferred"><primary>XDeleteContext</primary></indexterm>
 
4091
<!-- .sM -->
 
4092
<funcsynopsis>
 
4093
<funcprototype>
 
4094
  <funcdef>int <function>XDeleteContext</function></funcdef>
 
4095
  <paramdef>Display<parameter> *display</parameter></paramdef>
 
4096
  <paramdef>XID<parameter> rid</parameter></paramdef>
 
4097
  <paramdef>XContext<parameter> context</parameter></paramdef>
 
4098
</funcprototype>
 
4099
</funcsynopsis>
 
4100
<!-- .FN -->
 
4101
<variablelist>
 
4102
  <varlistentry>
 
4103
    <term>
 
4104
      <emphasis remap='I'>display</emphasis>
 
4105
    </term>
 
4106
    <listitem>
 
4107
      <para>
 
4108
Specifies the connection to the X server.
 
4109
      </para>
 
4110
    </listitem>
 
4111
  </varlistentry>
 
4112
  <varlistentry>
 
4113
    <term>
 
4114
      <emphasis remap='I'>rid</emphasis>
 
4115
    </term>
 
4116
    <listitem>
 
4117
      <para>
 
4118
Specifies the resource ID with which the data is associated.
 
4119
      </para>
 
4120
    </listitem>
 
4121
  </varlistentry>
 
4122
  <varlistentry>
 
4123
    <term>
 
4124
      <emphasis remap='I'>context</emphasis>
 
4125
    </term>
 
4126
    <listitem>
 
4127
      <para>
 
4128
Specifies the context type to which the data belongs.
 
4129
    </para>
 
4130
  </listitem>
 
4131
  </varlistentry>
 
4132
</variablelist>
 
4133
</para>
 
4134
<para>
 
4135
<!-- .LP -->
 
4136
<!-- .eM -->
 
4137
The
 
4138
<function>XDeleteContext</function>
 
4139
function deletes the entry for the given resource ID 
 
4140
and type from the data structure.
 
4141
This function returns the same error codes that
 
4142
<function>XFindContext</function>
 
4143
returns if called with the same arguments.
 
4144
<function>XDeleteContext</function>
 
4145
does not free the data whose address was saved.
 
4146
</para>
 
4147
<para>
 
4148
<!-- .LP -->
 
4149
<!-- .sp -->
 
4150
To create a unique context type that may be used in subsequent calls to
 
4151
<function>XSaveContext</function>
 
4152
and
 
4153
<function>XFindContext</function>,
 
4154
use
 
4155
<function>XUniqueContext</function>.
 
4156
</para>
 
4157
<para>XContext XuniqueContext()</para>
 
4158
 
 
4159
</sect1>
 
4160
</chapter>