Functions Specific to the X Window System
*****************************************

XEmacs provides the concept of devices, which generalizes connections to an X server, a TTY device, etc.  Most information about an X server that XEmacs is connected to can be determined through general console and device functions.  See Consoles and Devices. However, there are some features of the X Window System that do not generalize well, and they are covered specially here.

X Selections
============

The X server records a set of selections which permit transfer of data between application programs.  The various selections are distinguished by selection types, represented in XEmacs by symbols.  X clients including XEmacs can read or set the selection for any given type.

 -- Function: x-own-selection data &optional type
     This function sets a ``selection'' in the X server.  It takes two arguments: a value, DATA, and the selection type TYPE to assign it to.  DATA may be a string, a cons of two markers, or an extent.  In the latter cases, the selection is considered to be the text between the markers, or between the extent's endpoints.

     Each possible TYPE has its own selection value, which changes independently.  The usual values of TYPE are PRIMARY and SECONDARY; these are symbols with upper-case names, in accord with X Windows conventions.  The default is PRIMARY.

     (In FSF Emacs, this function is called x-set-selection and takes different arguments.)

 -- Function: x-get-selection
     This function accesses selections set up by XEmacs or by other X clients.  It returns the value of the current primary selection.

 -- Function: x-disown-selection &optional secondary-p
     Assuming we own the selection, this function disowns it.  If SECONDARY-P is non-nil, the secondary selection instead of the primary selection is discarded.

The X server also has a set of numbered cut buffers which can store text or other data being moved between applications.  Cut buffers are considered obsolete, but XEmacs supports them for the sake of X clients that still use them.

 -- Function: x-get-cutbuffer &optional n
     This function returns the contents of cut buffer number N. (This function is called x-get-cut-buffer in FSF Emacs.)

 -- Function: x-store-cutbuffer string
     This function stores STRING into the first cut buffer (cut buffer 0), moving the other values down through the series of cut buffers, kill-ring-style. (This function is called x-set-cut-buffer in FSF Emacs.)

X Server
========

This section describes how to access and change the overall status of the X server XEmacs is using.

Resources
---------

 -- Function: default-x-device
     This function return the default X device for resourcing.  This is the first-created X device that still exists.

 -- Function: x-get-resource name class type &optional locale device noerror
     This function retrieves a resource value from the X resource manager.

       * The first arg is the name of the resource to retrieve, such as "font".

       * The second arg is the class of the resource to retrieve, like "Font".

       * The third arg should be one of the symbols string, integer, natnum, or boolean, specifying the type of object that the database is searched for.

       * The fourth arg is the locale to search for the resources on, and can currently be a a buffer, a frame, a device, or the symbol global. If omitted, it defaults to global.

       * The fifth arg is the device to search for the resources on. (The resource database for a particular device is constructed by combining non-device- specific resources such any command-line resources specified and any app-defaults files found [or the fallback resources supplied by XEmacs, if no app-defaults file is found] with device-specific resources such as those supplied using xrdb.) If omitted, it defaults to the device of LOCALE, if a device can be derived (i.e. if LOCALE is a frame or device), and otherwise defaults to the value of default-x-device.

       * The sixth arg NOERROR, if non-nil, means do not signal an error if a bogus resource specification was retrieved (e.g. if a non-integer was given when an integer was requested).  In this case, a warning is issued instead.

     The resource names passed to this function are looked up relative to the locale.

     If you want to search for a subresource, you just need to specify the resource levels in NAME and CLASS.  For example, NAME could be "modeline.attributeFont", and CLASS "Face.AttributeFont".

     Specifically,

      1. If LOCALE is a buffer, a call

                   (x-get-resource "foreground" "Foreground" 'string SOME-BUFFER)

          is an interface to a C call something like

                   XrmGetResource (db, "xemacs.buffer.BUFFER-NAME.foreground",
                                       "Emacs.EmacsLocaleType.EmacsBuffer.Foreground",
                                       "String");

      2. If LOCALE is a frame, a call

                   (x-get-resource "foreground" "Foreground" 'string SOME-FRAME)

          is an interface to a C call something like

                   XrmGetResource (db, "xemacs.frame.FRAME-NAME.foreground",
                                       "Emacs.EmacsLocaleType.EmacsFrame.Foreground",
                                       "String");

      3. If LOCALE is a device, a call

                   (x-get-resource "foreground" "Foreground" 'string SOME-DEVICE)

          is an interface to a C call something like

                   XrmGetResource (db, "xemacs.device.DEVICE-NAME.foreground",
                                       "Emacs.EmacsLocaleType.EmacsDevice.Foreground",
                                       "String");

      4. If LOCALE is the symbol global, a call

                   (x-get-resource "foreground" "Foreground" 'string 'global)

          is an interface to a C call something like

                   XrmGetResource (db, "xemacs.foreground",
                                       "Emacs.Foreground",
                                       "String");

     Note that for global, no prefix is added other than that of the application itself; thus, you can use this locale to retrieve arbitrary application resources, if you really want to.

     The returned value of this function is nil if the queried resource is not found.  If TYPE is string, a string is returned, and if it is integer, an integer is returned.  If TYPE is boolean, then the returned value is the list (t) for true, (nil) for false, and is nil to mean ``unspecified''.

 -- Function: x-put-resource resource-line &optional device
     This function adds a resource to the resource database for DEVICE. RESOURCE-LINE specifies the resource to add and should be a standard resource specification.

 -- Variable: x-emacs-application-class
     This variable holds The X application class of the XEmacs process.  This controls, among other things, the name of the ``app-defaults'' file that XEmacs will use.  For changes to this variable to take effect, they must be made before the connection to the X server is initialized, that is, this variable may only be changed before XEmacs is dumped, or by setting it in the file lisp/term/x-win.el.

     By default, this variable is nil at startup.  When the connection to the X server is first initialized, the X resource database will be consulted and the value will be set according to whether any resources are found for the application class ``XEmacs''.

Data about the X Server
-----------------------

This section describes functions and a variable that you can use to get information about the capabilities and origin of the X server corresponding to a particular device.  The device argument is generally optional and defaults to the selected device.

 -- Function: x-server-version &optional device
     This function returns the list of version numbers of the X server DEVICE is on.  The returned value is a list of three integers: the major and minor version numbers of the X protocol in use, and the vendor-specific release number.

 -- Function: x-server-vendor &optional device
     This function returns the vendor supporting the X server DEVICE is on.

 -- Function: x-display-visual-class &optional device
     This function returns the visual class of the display DEVICE is on.  The value is one of the symbols static-gray, gray-scale, static-color, pseudo-color, true-color, and direct-color. (Note that this is different from previous versions of XEmacs, which returned StaticGray, GrayScale, etc.)

Restricting Access to the Server by Other Apps
----------------------------------------------

 -- Function: x-grab-keyboard &optional device
     This function grabs the keyboard on the given device (defaulting to the selected one).  So long as the keyboard is grabbed, all keyboard events will be delivered to XEmacs---it is not possible for other X clients to eavesdrop on them.  Ungrab the keyboard with x-ungrab-keyboard (use an unwind-protect).  Returns t if the grab was successful; nil otherwise.

 -- Function: x-ungrab-keyboard &optional device
     This function releases a keyboard grab made with x-grab-keyboard.

 -- Function: x-grab-pointer &optional device cursor ignore-keyboard
     This function grabs the pointer and restricts it to its current window. If optional DEVICE argument is nil, the selected device will be used.  If optional CURSOR argument is non-nil, change the pointer shape to that until x-ungrab-pointer is called (it should be an object returned by the make-cursor function). If the second optional argument IGNORE-KEYBOARD is non-nil, ignore all keyboard events during the grab.  Returns t if the grab is successful, nil otherwise.

 -- Function: x-ungrab-pointer &optional device
     This function releases a pointer grab made with x-grab-pointer. If optional first arg DEVICE is nil the selected device is used.  If it is t the pointer will be released on all X devices.

Miscellaneous X Functions and Variables
=======================================

 -- Variable: x-bitmap-file-path
     This variable holds a list of the directories in which X bitmap files may be found.  If nil, this is initialized from the "*bitmapFilePath" resource.  This is used by the make-image-instance function (however, note that if the environment variable XBMLANGPATH is set, it is consulted first).

 -- Variable: x-library-search-path
     This variable holds the search path used by read-color to find rgb.txt.

 -- Function: x-valid-keysym-name-p keysym
     This function returns true if KEYSYM names a keysym that the X library knows about.  Valid keysyms are listed in the files /usr/include/X11/keysymdef.h and in /usr/lib/X11/XKeysymDB, or whatever the equivalents are on your system.

 -- Function: x-window-id &optional frame
     This function returns the ID of the X11 window.  This gives us a chance to manipulate the Emacs window from within a different program.  Since the ID is an unsigned long, we return it as a string.

 -- Variable: x-allow-sendevents
     If non-nil, synthetic events are allowed.  nil means they are ignored.  Beware: allowing XEmacs to process SendEvents opens a big security hole.

 -- Function: x-debug-mode arg &optional device
     With a true arg, make the connection to the X server synchronous.  With false, make it asynchronous.  Synchronous connections are much slower, but are useful for debugging. (If you get X errors, make the connection synchronous, and use a debugger to set a breakpoint on x_error_handler.  Your backtrace of the C stack will now be useful.  In asynchronous mode, the stack above x_error_handler isn't helpful because of buffering.)  If DEVICE is not specified, the selected device is assumed.

     Calling this function is the same as calling the C function XSynchronize, or starting the program with the -sync command line argument.

 -- Variable: x-debug-events
     If non-zero, debug information about events that XEmacs sees is displayed.  Information is displayed on stderr.  Currently defined values are:

       * 1 == non-verbose output

       * 2 == verbose output