1pod::Prima::X11(3) User Contributed Perl Documentation pod::Prima::X11(3)
2
3
4
6 Prima::X11 - usage guide for X11 environment
7
9 This document describes subtle topics one must be aware when
10 programming or using Prima programs under X11.
11
12 The document covers various aspects of the toolkit and their
13 implementation details with guidelines of the expected use. Also,
14 standard X11 user-level and programming techniques are visited.
15
17 "--help"
18 Prints the command-line arguments available and exits.
19
20 "--display"
21 Sets X display address in Xlib notation. If not set, standard Xlib
22 ( "XOpenDisplay(null)" ) behavior applies.
23
24 Example:
25
26 --display=:0.1
27
28 "--visual"
29 Sets X visual, to be used by default. Example:
30
31 --visual=0x23
32
33 "--sync"
34 Turn off X synchronization
35
36 "--bg", "--fg"
37 Set default background and foreground colors. Example:
38
39 --bg=BlanchedAlmond
40
41 "--font"
42 Sets default font. Example:
43
44 --font='adobe-helvetica-medium-r-*-*--*-120-*-*-*-*-*-*'
45
46 "--no-x11"
47 Runs Prima without X11 display initialized. This switch can be used
48 for programs that use only OS-independent parts of Prima, such as
49 image subsystem or PostScript generator, in environments where X is
50 not present, for example, a CGI script. Obviously, any attempt to
51 create instance of "Prima::Application" or otherwise access
52 X-depended code under such conditions causes the program to abort.
53
54 There are alternatives to use the command switch. First, there is
55 module "Prima::noX11" for the same purpose but more convenient to
56 use as
57
58 perl -MPrima::noX11
59
60 construct. Second, there is a technique to continue execution even
61 if connection to a X server failed:
62
63 use Prima::noX11;
64 use Prima;
65
66 my $error = Prima::XOpenDisplay();
67 if ( defined $error) {
68 print "not connected to display: $error\n";
69 } else {
70 print "connected to display\n";
71 }
72
73 The Prima::noX11 module exports a single function "XOpenDisplay"
74 into "Prima" namespace, to connect to the X display explicitly. The
75 display to be connected to is $ENV{DISPLAY}, unless started
76 otherwise on command line ( with --display option) or with
77 parameter to the "XOpenDisplay" function.
78
79 This technique may be useful to programs that use Prima imaging
80 functionality and may or may not use windowing capabilites.
81
83 X11 provides XRDB, the X resource database, a keyed list of arbitrary
84 string values stored on the X server. Each key is a combination of
85 names and classes of widgets, each in string form. The key is
86 constructed so the leftmost substring ( name or class ) corresponds to
87 the top-level item in the hierarchy, usually the application name or
88 class. Although the XRDB can be changed via native X API, it is rarely
89 done by applications. Instead, the user creates a file, usually named
90 .Xdefaults, which contains the database in the string form.
91
92 The format of .Xdefaults directly reflects XRDB capabilities, one of
93 the most important of which is globbing, manifested via * ( star )
94 character. Using globbing, the user can set up a property value that
95 corresponds to multiple targets:
96
97 *.ListBox.backColor: yellow
98
99 The string above means that all widgets of ListBox class must have
100 yellow background.
101
102 The application itself is responsible for parsing the strings and
103 querying the XRDB. Also, both class names and widget names, as well as
104 database values are fully defined in terms of the application. There
105 are some guidelines though, for example, colors and fonts best
106 described in terms, native to the X server. Also, classes and names
107 are distinguished by the case: classes must begin with the upper
108 register letter. Also, not every character can be stored in the XRDB
109 database ( space, for example, cannot) , and therefore XRDB API
110 automatically converts these to _ ( underscore ) characters.
111
112 Prima defines its all set of resources, divided in two parts: general
113 toolkit settings and per-widget settings. The general settings
114 functionality is partially overloaded by command-line arguments. Per-
115 widget settings are fonts and colors, definable for each Prima widget.
116
117 All of the general settings are applicable to the top-level item of
118 widget hierarchy, named after the application, and "Prima" class. Some
119 of these, though, are needed to be initialized before the application
120 instance itself is created, so these can be accessed via "Prima" class
121 only, for example, "Prima.Visual". Some, on the contrary, may
122 occasionally overlap with per-widget syntax. In particular, one must
123 vary not to mix
124
125 Prima.font: some-font
126
127 with
128
129 Prima*font: some-font
130
131 The former syntax is a general setting, and sets the default Prima
132 font. The latter is a per-widget assignment, and explicitly sets font
133 to all Prima widgets, effectively ruining the toolkit font inheritance
134 scheme. The same is valid for an even more oppressive
135
136 *font: some-font
137
138 record.
139
140 The allowed per-widget settings are colors and font settings only ( see
141 corresponding sections ). It is an arguably useful feature to map all
142 widget properties onto XRDB, but Prima does not implement this,
143 primarily because no one asked for it, and also because this creates
144 unnecessary latency when enumeration of all properties for each widget
145 takes place.
146
147 All global settings have identical class and name, varied in the case
148 of the first letter. For example, to set "Submenudelay" value, one can
149 do it either by
150
151 Prima.Submenudelay: 10
152
153 or
154
155 Prima.submenudelay: 10
156
157 syntax. Despite that these calls are different, in a way that one
158 reaches for the whole class and another for the name, for the majority
159 of these properties it does not matter. To avoid confusion, for all
160 properties their names and class are given as
161 "PropetyClass.propertyname" index.
162
164 Default fonts
165 Prima::Application defines set of "get_default_XXX_font" functions,
166 where each returns some user-selected font, to be displayed
167 correspondingly in menu, message, window captions, all other widgets,
168 and finally a default font. While in other OS'es these are indeed
169 standard configurable user options, raw X11 doesn't define any.
170 Nevertheless, as the high-level code relies on these, corresponding
171 resources are defined. These are:
172
173 · font - Application::get_default_font
174
175 · caption_font - Application::get_caption_font. Used in "Prima::MDI".
176
177 · menu_font - Widget::get_default_menu_font. Default font for pull-
178 down and pop-up menus.
179
180 · msg_font - Application::get_message_font. Used in "Prima::MsgBox".
181
182 · widget_font - Widget::get_default_font.
183
184 All of the global font properties can only be set via "Prima" class, no
185 application name is recognized. Also, these properties are identical to
186 "--font", "--menu-font", "--caption-font", "--msg-font", and
187 "--widget-font" command-line arguments. The per-widget properties are
188 "font" and "popupFont", of class "Font", settable via XRDB only:
189
190 Prima*Dialog.font: my-fancy-dialog-font
191 Prima.FontDialog.font: some-conservative-font
192
193 By default, Prima font is 12.Helvetica .
194
195 X core fonts
196 The values of the font entries are standard XLFD strings, the default
197 "*-*-*-*-*-*-*-*-*-*-*-*-*-*-*" pattern, where each star character can
198 be replaced by a particular font property, as name, size, charset, and
199 so on. To interactively select an appropriate font, use standard
200 "xfontsel" program from X11 distribution.
201
202 Note, that encoding part of the font is recommended to left
203 unspecified, otherwise it may clash with LANG environment variable,
204 which is used by Prima font subsystem to determine which font to select
205 when no encoding is given. This advice, though, is correct only when
206 both LANG and encoding part of a desired font match. In order to force
207 a particular font encoding, the property "Prima.font" must contain one.
208
209 Alternatively, and/or to reduce X font traffic, one may set
210 "IgnoreEncodings.ignoreEncodings" property, which is a semicolon-
211 separated list of encodings Prima must not account. This feature has
212 limited usability when for example fonts in Asian encodings result in
213 large font requests. Another drastic measure to decrease font traffic
214 is a boolean property "Noscaledfonts.noscaledfonts", which, if set to
215 1, restricts the choice of fonts to the non-scalable fonts only.
216
217 Xft fonts
218 Recently, Prima was made to compile with Xft library, which contrary to
219 core X font API, can make use of client-side fonts. Plus, Xft offers
220 appealing features as font antialiasing, unicode, and arguably a better
221 font syntax. The Xft font syntax is inherited from "fontconfig" library
222 and to be consulted from "man fonts-conf", but currently ( November
223 2003 ) basic font descriptions can be composed as follows:
224
225 Palatino-12
226
227 A font with name "Palatino" and size 12.
228
229 Arial-10:BI
230
231 A font with name "Arial", size 10, bold, italic. The "fontconfig"
232 syntax allows more than that, for example, arbitrary matrix
233 transformations, but Prima can make use only of font name, size, and
234 style flags.
235
236 "--no-xft"
237 "--no-xft" command-line argument, and boolean "UseXFT.usexft" XRDB
238 property can be used to disable use of the Xft library.
239
240 "--no-core-fonts"
241 Disables all X11 core fonts, except "fixed" fonts. The "fixed" font
242 is selected for the same reasons that X server is designed to
243 provide at least one font, which usually is "fixed".
244
245 It is valid to combine "--no-core-fonts" and "--no-xft". Moreover,
246 adding "--noscaled" to these gives Prima programs a 'classic' X
247 look.
248
249 "--font-priority"
250 Can be set to either "xft" or "core", to select a font provider
251 mechanism to match unknown or incompletely specified fonts against.
252
253 Default value: "xft" ( if compiled in ), "core" otherwise.
254
255 "--no-aa"
256 If set, turns off Xft antialiasing.
257
259 XRDB conventions
260 X traditionally contains a color names database, usually a text file
261 named rgb.txt. Check your X manual where exactly this file resides and
262 what is its format. The idea behind it is that users can benefit from
263 portable literal color names, with color values transparently
264 adjustable to displays capabilities. Thus, it is customary to write
265
266 color: green
267
268 for many applications, and these in turn call "XParseColor" to convert
269 strings into RGB values.
270
271 Prima is no exception to the scheme. Each widget can be assigned eight
272 color properties: "color", "hiliteBackColor", "disabledColor",
273 "dark3DColor" "backColor", "hiliteColor", "disabledBackColor",
274 "light3DColor" by their name:
275
276 Prima.backColor: #cccccc
277
278 Additionally, set of command-line arguments allows overriding default
279 values for these:
280
281 · "--fg" - color
282
283 · "--bg" - backColor
284
285 · "--hilite-fg" - hiliteColor
286
287 · "--hilite-bg" - hiliteBackColor
288
289 · "--disabled-fg" - disabledColor
290
291 · "--disabled-bg" - disabledBackColor
292
293 · "--light" - light3DColor
294
295 · "--dark" - dark3DColor
296
297 Visuals
298 X protocol works with explicitly defined pixel values only. A pixel
299 value, maximum 32-bit value, represents a color in a display. There are
300 two different color coding schemes - direct color and indexed color.
301 The direct color-coded pixel value can unambiguously be converted into
302 a RGB-value, without any external information. The indexed-color
303 scheme represents pixel value as an index in a palette, which resided
304 on X server. Depending on the color cell value of the palette, RGB
305 color representation can be computed. A X display can contain more than
306 one palette, and allow ( or disallow ) modification of palette color
307 cells depending on a visual, the palette is attributed to.
308
309 A visual is a X server resource, containing representation of color
310 coding scheme, color bit depth, and modificability of the palette. X
311 server can ( and usually does ) provide more than one visual, as well
312 as different bit depths. There are six classes of visuals in X
313 paradigm. In each, Prima behaves differently, also depending on display
314 bit depth available. In particular, color dithering can be used on
315 displays with less than 12-bit color depth. On displays with modifiable
316 color palette, Prima can install its own values in palettes, which may
317 result in an effect known as display flashing. To switch to a non-
318 default visual, use "Prima.Visual" XRDB property or "--visual" command-
319 line argument. List of visuals can be produced interactively by
320 standard "xdpyinfo" command from X distribution, where each class of
321 visual corresponds to one of six visual classes:
322
323 StaticGray
324 All color cells are read-only, and contain monochrome values only.
325 A typical example is a two-color, black-and-white monochrome
326 display. This visual is extremely rarely met.
327
328 GrayScale
329 Contains modifiable color palette, and capable of displaying
330 monochrome values only. Theoretically, any paletted display on a
331 monochrome monitor can be treated as a GrayScale visual. For both
332 GrayScale and StaticGray visuals Prima resorts to dithering if it
333 cannot get at least 32 evenly spaced gray values from black to
334 white.
335
336 StaticColor
337 All color cells are read-only. A typical example is a PC display
338 in a 16-color EGA mode. This visual is rarely met.
339
340 PseudoColor
341 All color cells are modifiable. Typically, 8-bit displays define
342 this class for a default visual. For both StaticColor and
343 PseudoColor visuals dithering is always used, although for
344 "PseudoColor" Prima resorts to that only if X server cannot
345 allocate another color.
346
347 On "PseudoColor" and "GrayScale" Prima allocates a small set of
348 colors, not used in palette modifications. When a bitmap is to be
349 exported via clipboard, or displayed in menu, or sent to a window
350 manager as an icon to be displayed, it is downgraded to using these
351 colors only, which are though guaranteedly to stay permanent
352 through life of the application.
353
354 TrueColor
355 Each pixel value is explicitly coded as RGB. Typical example are
356 16, 24, or 32-bit display modes. This visual class is the best in
357 terms of visual quality.
358
359 DirectColor
360 Same as TrueColor, but additionally each pixel value can be
361 reprogrammed. Not all hardware support this visual, and usually by
362 default it is not set. Prima supports this mode in exactly same
363 way as TrueColor without additional features.
364
366 As described in the previous section, X does not standardize pixel
367 memory format for TrueColor and DirectColor visuals, so there is a
368 chance that Prima wouldn't work on some bizarre hardware. Currently,
369 Prima knows how to compose pixels of 15, 16, 24, and 32 bit depth, of
370 contiguous ( not interspersed ) red-green-blue memory layout. Any other
371 pixel memory layout causes Prima to fail.
372
373 Prima supports shared memory image X extension, which speeds up image
374 display for X servers and clients running on same machine. The price
375 for this is that if Prima program aborts, the shared memory will never
376 be returned to the OS. To remove the leftover segments, use your OS
377 facilities, for example, "ipcrm" on *BSD.
378
379 To disable shared memory with images, use "--no-shmem" switch in
380 command-line arguments.
381
382 The clipboard exchange of images is incompletely implemented, since
383 Prima does not accompany ( and neither reads ) COLORMAP, FOREGROUND,
384 and BACKGROUND clipboard data, which contains pixel RGB values for a
385 paletted image. As a palliative, the clipboard-bound images are
386 downgraded to a safe set of colors, locked immutable either by X server
387 or Prima core.
388
389 On images in the clipboard: contrary to the text in the clipboard,
390 which can be used several times, images seemingly cannot. The Bitmap or
391 Pixmap descriptor, stored in the clipboard, is rendered invalid after
392 it has been read once.
393
395 The original design of X protocol did not include the notion of a
396 window manager, and latter is was implemented as an ad-hoc patch, which
397 results in race conditions when configuring widgets. The extreme
398 situation may well happen when even a non-top level widget may be
399 influenced by a window manager, when for example a top-level widget was
400 reparented into another widget, but the window manager is not aware or
401 this yet.
402
403 The consequences of this, as well as programming guidances are
404 described in "Prima::Window". Here, we describe other aspects of
405 interactions with WMs, as WM protocols, hints, and properties.
406
407 Prima was tested with alternating success under the following window
408 managers: mwm, kwin, wmaker, fvwm, fvwm2, enlightment, sawfish,
409 blackbox, 9wm, olvm, twm, and in no-WM environment.
410
411 Protocols
412 Prima makes use of "WM_DELETE_WINDOW" and "WM_TAKE_FOCUS" protocols.
413 While "WM_DELETE_WINDOW" use is straightforward and needs no further
414 attention, "WM_TAKE_FOCUS" can be tricky, since X defines several of
415 input modes for a widget, which behave differently for each WM. In
416 particular, 'focus follows pointer' gives pains under twm and mwm,
417 where navigation of drop-down combo boxes is greatly hindered by window
418 manager. The drop-down list is programmed so it is dismissed as soon
419 its focus is gone; these window managers withdraw focus even if the
420 pointer is over the focused widget's border.
421
422 Hints
423 Size, position, icons, and other standard X hints are passed to WM in a
424 standard way, and, as inter-client communication manual ( ICCCM )
425 allows, repeatedly misinterpreted by window managers. Many ( wmaker,
426 for example ) apply the coordinates given from the program not to the
427 top-level widget itself, but to its decoration. mwm defines list of
428 accepted icon sizes so these can be absurdly high, which adds confusion
429 to a client who can create icon of any size, but unable to determine
430 the best one.
431
432 Non-standard properties
433 Prima tries to use WM-specific hints, known for two window managers:
434 mwm and kwin. For mwm ( Motif window manager ) Prima sets hints of
435 decoration border width and icons only. For kwin ( and probably to
436 others, who wish to conform to specifications of
437 http://www.freedesktop.org/ ) Prima uses "NET_WM_STATE" property, in
438 particular its maximization and task-bar visibility hints.
439
440 Use of these explicitly contradicts ICCCM, and definitely may lead to
441 bugs in future ( at least with "NET_WM_STATE", since Motif interface
442 can hardly expected to be changed ). To disable the use of non-
443 standard WM properties, "--icccm" command-line argument can be set.
444
446 X does not support unicode, and number of patches were applied to X
447 servers and clients to make the situation change. Currently ( 2003 )
448 standard unicode practices are not emerged yet, so Prima copes up with
449 what ( in author's opinion ) is most promising: Xft and iconv
450 libraries.
451
452 Fonts
453 X11 supports 8-bit and 16-bit text string display, and neither can be
454 used effectively to display unicode strings. A "XCreateFontSet"
455 technique, which combines several fonts under one descriptor, or a
456 similarly implemented technique is the only way to provide correct
457 unicode display.
458
459 Also, core font transfer protocol suffers from ineffective memory
460 representation, which creates latency when fonts with large span of
461 glyphs is loaded. Such fonts, in still uncommon though standard
462 iso10646 encoding, are the only media to display multi-encoding text
463 without falling back to hacks similar to "XCreateFontSet".
464
465 These, and some other problems are efficiently solved by Xft library, a
466 superset of X core font functionality. Xft features Level 1 ( November
467 2003 ) unicode display and supports 32-bit text strings as well as
468 UTF8-coded strings. Xft does not operate with charset encodings, and
469 these are implemented in Prima using iconv charset convertor library.
470
471 Input
472 Prima does not support extended input methods ( XIM etc ), primarily
473 because the authors are not acquainted with CIJK problem domain.
474 Volunteers are welcome.
475
476 Clipboard
477 Prima supports UTF8 text in clipboard via "UTF8_STRING" transparently,
478 although not by default.
479
480 Prima::Application-> wantUnicodeInput(1)
481
482 is the easiest ( see Prima::Application ) way to initiate UTF8
483 clipboard text exchange.
484
485 Due to the fact that any application can take ownership over the
486 clipboard at any time, "open"/"close" brackets are not strictly
487 respected in X11 implementation. Practically, this means that when
488 modern X11 clipboard daemons ( KDE klipper, for example ) interfere
489 with Prima clipboard, the results may not be consistent from the
490 programmer's view, for example, clipboard contains data after "clear"
491 call, and the like. It must be noted though that this behavior is
492 expected by the users.
493
495 Timeouts
496 Raw X11 provides no such GUI helpers as double-click event, cursor, or
497 menu. Neither does it provide the related time how often, for example,
498 a cursor would blink. Therefore Prima emulates these, but allows the
499 user to reprogram the corresponding timeouts. Prima recognizes the
500 following properties, accessible either via application name or Prima
501 class key. All timeouts are integer values, representing number of
502 milliseconds for the corresponding timeout property.
503
504 Blinkinvisibletime.blinkinvisibletime: MSEC
505 Cursor stays invisible MSEC milliseconds.
506
507 Default value: 500
508
509 Blinkvisibletime.blinkvisibletime: MSEC
510 Cursor stays visible MSEC milliseconds.
511
512 Default value: 500
513
514 Clicktimeframe.clicktimeframe MSEC
515 If 'mouse down' and 'mouse up' events are follow in MSEC, 'mouse
516 click' event is synthesized.
517
518 Default value: 200
519
520 Doubleclicktimeframe.doubleclicktimeframe MSEC
521 If 'mouse click' and 'mouse down' events are follow in MSEC, 'mouse
522 double click' event is synthesized.
523
524 Default value: 200
525
526 Submenudelay.submenudelay MSEC
527 When the used clicks on a menu item, which points to a lower-level
528 menu window, the latter is displayed after MSEC milliseconds.
529
530 Default value: 200
531
532 Scrollfirst.scrollfirst MSEC
533 When an auto-repetitive action, similar to keystroke events
534 resulting from a long key press on the keyboard, is to be
535 simulated, two timeout values are used - 'first' and 'next' delay.
536 These actions are not simulated within Prima core, and the
537 corresponding timeouts are merely advisable to the programmer.
538 Prima widgets use it for automatic scrolling, either by a scrollbar
539 or by any other means. Also, "Prima::Button" in "autoRepeat" mode
540 uses these timeouts for emulation of a key press.
541
542 "Scrollfirst" is a 'first' timeout.
543
544 Default value: 200
545
546 Scrollnext.scrollnext MSEC
547 A timeout used for same reasons as "Scrollfirst", but after it is
548 expired.
549
550 Default value: 50
551
552 Miscellaneous
553 Visual.visual: VISUAL_ID
554 Selects display visual by VISUAL_ID, which is usually has a form of
555 "0x??". Various visuals provide different color depth and access
556 scheme. Some X stations have badly chosen default visuals (for
557 example, default IRIX workstation setup has 8-bit default visual
558 selected), so this property can be used to fix things. List of
559 visuals, supported by a X display can be produced interactively by
560 standard "xdpyinfo" command from X distribution.
561
562 Identical to "--visual" command-line argument.
563
564 See Color for more information.
565
566 Wheeldown.wheeldown BUTTON
567 BUTTON is a number of X mouse button event, treated as 'mouse wheel
568 down' event.
569
570 Default value: 5 ( default values for wheeldown and wheelup are
571 current de-facto most popular settings ).
572
573 Wheelup.wheelup BUTTON
574 BUTTON is a number of X mouse button event, treated as 'mouse wheel
575 up' event.
576
577 Default value: 4
578
580 The famous 'use the source' call is highly actual with Prima. However,
581 some debug information comes compiled in, and can be activated by
582 "--debug" command-line key. Combination of letters to the key activates
583 debug printouts of different subsystems:
584
585 · C - clipboard
586
587 · E - events subsystem
588
589 · F - fonts
590
591 · M - miscellaneous debug info
592
593 · P - palettes and colors
594
595 · X - XRDB
596
597 · A - all of the above
598
599 Example:
600
601 --debug=xf
602
603 Also, the built-in X API "XSynchronize" call, which enables X protocol
604 synchronization ( at expense of operation slowdown though ) is
605 activated with "--sync" command-line argument, and can be used to ease
606 the debugging.
607
608 GTK
609 Prima can be compiled with GTK, and can use its colos and font scheme,
610 and GTK file dialogs. This can be disabled with "--no-gtk" command line
611 switch.
612
613 On MacOSX, GTK usually comes with Quartz implementation, which means
614 that Prima will get into problems with remote X11 connections. Prima
615 tries to detect this condition, but if trouble persists, please use
616 "--no-gtk" switch (and please file a bug report so this can be fixed,
617 too).
618
619 Quartz
620 Prima can be compiled with Cocoa library on MacOSX, that gives access
621 to screen scraping functionality of Application.get_image, that is
622 otherwise is non-functional with XQuartz. To disable it, use
623 "--no-quartz" runtime switch.
624
626 Dmitry Karasik, <dmitry@karasik.eu.org>.
627
629 Prima, Prima::gp-problems, Prima::Widget, Nye A, Xlib programming
630 manual. O'Reilly & Associates, 1995.
631
632
633
634perl v5.32.0 2020-07-28 pod::Prima::X11(3)