Wand updates from Evgeny
[sxemacs] / info / lispref / x-windows.texi
1 @c -*-texinfo-*-
2 @c This is part of the SXEmacs Lisp Reference Manual.
3 @c Copyright (C) 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
4 @c Copyright (C) 2005 Sebastian Freundt <hroptatyr@sxemacs.org>
5 @c See the file lispref.texi for copying conditions.
6 @setfilename ../../info/x-windows.texinfo
7
8 @node X-Windows, LDAP Support, System Interface, Top
9 @chapter Functions Specific to the X Window System
10 @cindex X
11 @cindex X-Windows
12
13 @c This section is largely different from the one in FSF Emacs.
14
15 SXEmacs provides the concept of @dfn{devices}, which generalizes
16 connections to an X server, a TTY device, etc.  Most information about
17 an X server that SXEmacs is connected to can be determined through
18 general console and device functions.  @xref{Consoles and Devices}.
19 However, there are some features of the X Window System that do not
20 generalize well, and they are covered specially here.
21
22 @menu
23 * X Selections::                Transferring text to and from other X clients.
24 * X Server::                    Information about the X server connected to
25                                   a particular device.
26 * X Miscellaneous::             Other X-specific functions and variables.
27 @end menu
28
29
30 @node X Selections
31 @section X Selections
32 @cindex selection (for X windows)
33
34 The X server records a set of @dfn{selections} which permit transfer of
35 data between application programs.  The various selections are
36 distinguished by @dfn{selection types}, represented in SXEmacs by
37 symbols.  X clients including SXEmacs can read or set the selection for
38 any given type.
39
40 @defun x-own-selection data &optional type
41 This function sets a ``selection'' in the X server.  It takes two
42 arguments: a value, @var{data}, and the selection type @var{type} to
43 assign it to.  @var{data} may be a string, a cons of two markers, or an
44 extent.  In the latter cases, the selection is considered to be the text
45 between the markers, or between the extent's endpoints.
46
47 Each possible @var{type} has its own selection value, which changes
48 independently.  The usual values of @var{type} are @code{PRIMARY} and
49 @code{SECONDARY}; these are symbols with upper-case names, in accord
50 with X Windows conventions.  The default is @code{PRIMARY}.
51
52 (In FSF Emacs, this function is called @code{x-set-selection} and
53 takes different arguments.)
54 @end defun
55
56 @defun x-get-selection
57 This function accesses selections set up by SXEmacs or by other X
58 clients.  It returns the value of the current primary selection.
59 @end defun
60
61 @defun x-disown-selection &optional secondary-p
62 Assuming we own the selection, this function disowns it.  If
63 @var{secondary-p} is non-@code{nil}, the secondary selection instead of
64 the primary selection is discarded.
65 @end defun
66
67 @cindex cut buffer
68 The X server also has a set of numbered @dfn{cut buffers} which can
69 store text or other data being moved between applications.  Cut buffers
70 are considered obsolete, but SXEmacs supports them for the sake of X
71 clients that still use them.
72
73 @defun x-get-cutbuffer &optional n
74 This function returns the contents of cut buffer number @var{n}. (This
75 function is called @code{x-get-cut-buffer} in FSF Emacs.)
76 @end defun
77
78 @defun x-store-cutbuffer string &optional push
79 This function stores @var{string} into the first cut buffer (cut buffer
80 0).
81
82 Normally, the contents of the first cut buffer are simply replaced by
83 @var{string}.  However, if optional argument @var{push} is
84 non-@code{nil}, the cut buffers are rotated.  This means that the
85 previous value of the first cut buffer moves to the second cut buffer,
86 and the second to the third, and so on, moving the other values down
87 through the series of cut buffers, kill-ring-style.  There are 8 cut
88 buffers altogether.
89
90 Cut buffers are considered obsolete; you should use selections instead.
91
92 This function has no effect if support for cut buffers was not compiled in.
93
94 This function is called @code{x-set-cut-buffer} in FSF Emacs.
95 @end defun
96
97
98 @node X Server
99 @section X Server
100
101 This section describes how to access and change the overall status of
102 the X server SXEmacs is using.
103
104 @menu
105 * Resources::                   Getting resource values from the server.
106 * Server Data::                 Getting info about the X server.
107 * Grabs::                       Restricting access to the server by other apps.
108 @end menu
109
110
111 @node Resources
112 @subsection Resources
113
114 @defun default-x-device
115 This function return the default X device for resourcing.  This is the
116 first-created X device that still exists.
117 @end defun
118
119 @defun x-get-resource name class type &optional locale device noerror
120 This function retrieves a resource value from the X resource manager.
121
122 @itemize @bullet
123 @item
124 The first arg is the name of the resource to retrieve, such as
125 @samp{"font"}.
126
127 @item
128 The second arg is the class of the resource to retrieve, like
129 @samp{"Font"}.
130
131 @item
132 The third arg should be one of the symbols @code{string},
133 @code{integer}, @code{natnum}, or @code{boolean}, specifying the type of
134 object that the database is searched for.
135
136 @item
137 The fourth arg is the locale to search for the resources on, and can
138 currently be a buffer, a frame, a device, or the symbol @code{global}.
139 If omitted, it defaults to @code{global}.
140
141 @item
142 The fifth arg is the device to search for the resources on. (The
143 resource database for a particular device is constructed by combining
144 non-device- specific resources such any command-line resources specified
145 and any app-defaults files found [or the fallback resources supplied by
146 SXEmacs, if no app-defaults file is found] with device-specific resources
147 such as those supplied using @samp{xrdb}.) If omitted, it defaults to
148 the device of @var{locale}, if a device can be derived (i.e. if
149 @var{locale} is a frame or device), and otherwise defaults to the value
150 of @code{default-x-device}.
151
152 @item
153 The sixth arg @var{noerror}, if non-@code{nil}, means do not signal an
154 error if a bogus resource specification was retrieved (e.g. if a
155 non-integer was given when an integer was requested).  In this case, a
156 warning is issued instead.
157 @end itemize
158
159 The resource names passed to this function are looked up relative to the
160 locale.
161
162 If you want to search for a subresource, you just need to specify the
163 resource levels in @var{name} and @var{class}.  For example, @var{name}
164 could be @samp{"modeline.attributeFont"}, and @var{class}
165 @samp{"Face.AttributeFont"}.
166
167 Specifically,
168
169 @enumerate
170 @item
171 If @var{locale} is a buffer, a call
172
173 @example
174     @code{(x-get-resource "foreground" "Foreground" 'string @var{some-buffer})}
175 @end example
176
177 is an interface to a C call something like
178
179 @example
180     @code{XrmGetResource (db, "sxemacs.buffer.@var{buffer-name}.foreground",
181                         "Emacs.EmacsLocaleType.EmacsBuffer.Foreground",
182                         "String");}
183 @end example
184
185 @item
186 If @var{locale} is a frame, a call
187
188 @example
189     @code{(x-get-resource "foreground" "Foreground" 'string @var{some-frame})}
190 @end example
191
192 is an interface to a C call something like
193 @example
194
195     @code{XrmGetResource (db, "sxemacs.frame.@var{frame-name}.foreground",
196                         "Emacs.EmacsLocaleType.EmacsFrame.Foreground",
197                         "String");}
198 @end example
199
200 @item
201 If @var{locale} is a device, a call
202
203 @example
204     @code{(x-get-resource "foreground" "Foreground" 'string @var{some-device})}
205 @end example
206
207 is an interface to a C call something like
208
209 @example
210     @code{XrmGetResource (db, "sxemacs.device.@var{device-name}.foreground",
211                         "Emacs.EmacsLocaleType.EmacsDevice.Foreground",
212                         "String");}
213 @end example
214
215 @item
216 If @var{locale} is the symbol @code{global}, a call
217
218 @example
219     @code{(x-get-resource "foreground" "Foreground" 'string 'global)}
220 @end example
221
222 is an interface to a C call something like
223
224 @c erm, do we have these Xresource identifiers?
225 @example
226     @code{XrmGetResource (db, "sxemacs.foreground",
227                         "Emacs.Foreground",
228                         "String");}
229 @end example
230 @end enumerate
231
232 Note that for @code{global}, no prefix is added other than that of the
233 application itself; thus, you can use this locale to retrieve arbitrary
234 application resources, if you really want to.
235
236 The returned value of this function is @code{nil} if the queried
237 resource is not found.  If @var{type} is @code{string}, a string is
238 returned, and if it is @code{integer}, an integer is returned.  If
239 @var{type} is @code{boolean}, then the returned value is the list
240 @code{(t)} for true, @code{(nil)} for false, and is @code{nil} to mean
241 ``unspecified''.
242 @end defun
243
244 @defun x-put-resource resource-line &optional device
245 This function adds a resource to the resource database for @var{device}.
246 @var{resource-line} specifies the resource to add and should be a
247 standard resource specification.
248 @end defun
249
250 @defvar x-emacs-application-class
251 This variable holds The X application class of the SXEmacs process.  This
252 controls, among other things, the name of the ``app-defaults'' file that
253 SXEmacs will use.  For changes to this variable to take effect, they must
254 be made before the connection to the X server is initialized, that is,
255 this variable may only be changed before SXEmacs is dumped, or by setting
256 it in the file @file{lisp/term/x-win.el}.
257
258 By default, this variable is @code{nil} at startup.  When the connection
259 to the X server is first initialized, the X resource database will
260 be consulted and the value will be set according to whether any
261 resources are found for the application class ``SXEmacs''.
262 @end defvar
263
264
265 @node Server Data
266 @subsection Data about the X Server
267
268   This section describes functions and a variable that you can use to
269 get information about the capabilities and origin of the X server
270 corresponding to a particular device.  The device argument is generally
271 optional and defaults to the selected device.
272
273 @defun x-server-version &optional device
274 This function returns the list of version numbers of the X server
275 @var{device} is on.  The returned value is a list of three integers: the
276 major and minor version numbers of the X protocol in use, and the
277 vendor-specific release number.
278 @end defun
279
280 @defun x-server-vendor &optional device
281 This function returns the vendor supporting the X server @var{device} is
282 on.
283 @end defun
284
285 @defun x-display-visual-class &optional device
286 This function returns the visual class of the display @var{device} is
287 on.  The value is one of the symbols @code{static-gray},
288 @code{gray-scale}, @code{static-color}, @code{pseudo-color},
289 @code{true-color}, and @code{direct-color}. (Note that this is different
290 from previous versions of SXEmacs, which returned @code{StaticGray},
291 @code{GrayScale}, etc.)
292 @end defun
293
294
295 @node Grabs
296 @subsection Restricting Access to the Server by Other Apps
297
298 @defun x-grab-keyboard &optional device
299 This function grabs the keyboard on the given device (defaulting to the
300 selected one).  So long as the keyboard is grabbed, all keyboard events
301 will be delivered to SXEmacs---it is not possible for other X clients to
302 eavesdrop on them.  Ungrab the keyboard with @code{x-ungrab-keyboard}
303 (use an @code{unwind-protect}).  Returns @code{t} if the grab was
304 successful; @code{nil} otherwise.
305 @end defun
306
307 @defun x-ungrab-keyboard &optional device
308 This function releases a keyboard grab made with @code{x-grab-keyboard}.
309 @end defun
310
311 @defun x-grab-pointer &optional device cursor ignore-keyboard
312 This function grabs the pointer and restricts it to its current window.
313 If optional @var{device} argument is @code{nil}, the selected device
314 will be used.  If optional @var{cursor} argument is non-@code{nil},
315 change the pointer shape to that until @code{x-ungrab-pointer} is called
316 (it should be an object returned by the @code{make-cursor} function).
317 If the second optional argument @var{ignore-keyboard} is non-@code{nil},
318 ignore all keyboard events during the grab.  Returns @code{t} if the
319 grab is successful, @code{nil} otherwise.
320 @end defun
321
322 @defun x-ungrab-pointer &optional device
323 This function releases a pointer grab made with @code{x-grab-pointer}.
324 If optional first arg @var{device} is @code{nil} the selected device is
325 used.  If it is @code{t} the pointer will be released on all X devices.
326 @end defun
327
328
329 @node X Miscellaneous
330 @section Miscellaneous X Functions and Variables
331
332 @defvar x-bitmap-file-path
333 This variable holds a list of the directories in which X bitmap files
334 may be found.  If @code{nil}, this is initialized from the
335 @samp{"*bitmapFilePath"} resource.  This is used by the
336 @code{make-image-instance} function (however, note that if the
337 environment variable @samp{XBMLANGPATH} is set, it is consulted first).
338 @end defvar
339
340 @defvar x-library-search-path
341 This variable holds the search path used by @code{read-color} to find
342 @file{rgb.txt}.
343 @end defvar
344
345 @defun x-valid-keysym-name-p keysym
346 This function returns true if @var{keysym} names a keysym that the X
347 library knows about.  Valid keysyms are listed in the files
348 @file{/usr/include/X11/keysymdef.h} and in
349 @file{/usr/lib/X11/XKeysymDB}, or whatever the equivalents are on your
350 system.
351 @end defun
352
353 @defun x-window-id &optional frame
354 This function returns the ID of the X11 window.  This gives us a chance
355 to manipulate the SXEmacs window from within a different program.  Since
356 the ID is an unsigned long, we return it as a string.
357 @end defun
358
359 @defvar x-allow-sendevents
360 If non-@code{nil}, synthetic events are allowed.  @code{nil} means
361 they are ignored.  Beware: allowing SXEmacs to process SendEvents opens a
362 big security hole.
363 @end defvar
364
365 @defun x-debug-mode arg &optional device
366 With a true arg, make the connection to the X server synchronous.  With
367 false, make it asynchronous.  Synchronous connections are much slower,
368 but are useful for debugging. (If you get X errors, make the connection
369 synchronous, and use a debugger to set a breakpoint on
370 @code{x_error_handler}.  Your backtrace of the C stack will now be
371 useful.  In asynchronous mode, the stack above @code{x_error_handler}
372 isn't helpful because of buffering.)  If @var{device} is not specified,
373 the selected device is assumed.
374
375 Calling this function is the same as calling the C function
376 @code{XSynchronize}, or starting the program with the @samp{-sync}
377 command line argument.
378 @end defun
379
380 @defvar x-debug-events
381 If non-zero, debug information about events that SXEmacs sees is
382 displayed.  Information is displayed on stderr.  Currently defined
383 values are:
384
385 @itemize @bullet
386 @item
387 1 == non-verbose output
388 @item
389 2 == verbose output
390 @end itemize
391 @end defvar