Skip to content

Repository files navigation

CLIPSX11

CLIPSX11

A CLIPS X11 library

Installation

This library can be installed manually via git and make or by CLIPSenv.

To install manually, git clone this repo and run make. This will:

  1. Download the CLIPS 6.4.2 source code
  2. Untar it to the vendor/clips dir
  3. Copy the userfunctions.c file into the vendor/clips dir
  4. Run make in the vendor/clips dir

Now you have an executable vendor/clips/clips file that has X11-related functions available in it.

To take this a step further, you can install the executable CLIPSX11 system-wide by running sudo make install.

Examples

CLIPS1wm Window Manager

Check out CLIPS1wm, a minimal X11 window manager implemented using CLIPSX11.

Misc examples & Tests

All example programs and tests are in the tests directory.

There are two files program.clp program2.clp showcasing some of the other functions provided by this library.

There are a few test .bat files that you may run to see the basic library in action:

CLIPSX11 -f2 ./error_handling.bat
CLIPSX11 -f2 ./x_send_event_test.bat

Documentation

  1. Display Management
  2. Window Creation & Management
  3. Cursor, Font & Color
  4. Graphics Context & Drawing
  5. Event Handling
  6. Keyboard Utilities
  7. Screen Conversion
  8. Utility
  9. Error Handling

Display Management

x-open-display

(x-open-display [<display-name>]) → <DISPLAY-ADDRESS> | FALSE
Description

Connects to the X server.

Parameters
  • display-name (SYMBOL, optional) - hostname and display number (e.g. "localhost:0"). If omitted, uses DISPLAY env var.
Returns
  • External address wrapping Display* on success.
  • FALSE if connection fails (prints error to STDERR).
Example
(bind ?d (x-open-display ":0"))

x-close-display

(x-close-display <display pointer>) → <VOID>
Description

Closes previously opened display.


default-screen

(default-screen <display>) → <screen-number>
Description

Retrieves the default screen index for a display.

Parameters
  • display (EXTERNAL-ADDRESS) - a Display* returned by x-open-display.
Returns
  • Integer index of the default screen.

default-screen-of-display

(default-screen-of-display <display>) → <screen-address>
Description

Returns the Screen* pointer for the default screen.

Parameters
  • display (EXTERNAL-ADDRESS)
Returns
  • External address wrapping Screen*.

default-root-window

(default-root-window <display>) → <window-id>
Description

Fetches the root window ID of the default screen.

Parameters
  • display (EXTERNAL-ADDRESS)
Returns
  • Window ID (INTEGER).

root-window

(root-window <display> <screen>) → <window-id>

Description

Fetches the root window ID for a specified screen index.

Parameters

  • display (EXTERNAL-ADDRESS)
  • screen (INTEGER)

Returns

  • Window ID (INTEGER).

Window Creation & Management

x-create-simple-window

(x-create-simple-window <display> <parent> <x> <y> <width> <height> <border-width> <border> <background>) → <window-id>
Description

Creates a basic window.

Parameters
  1. display (EXTERNAL-ADDRESS) - Display*
  2. parent (INTEGER) - parent window ID
  3. x, y (INTEGER) - position
  4. width, height (INTEGER) - dimensions
  5. border-width (INTEGER)
  6. border, background (INTEGER) - pixel values
Returns
  • New window ID (INTEGER).
Example
(bind ?w (x-create-simple-window ?d ?parent 10 10 400 300 1 0 65535))

x-create-window

(x-create-window <display> <parent> <x> <y> <width> <height> <border-width> <depth> <class> <visual> <valuemask> <attributes>) → <window-id>
Description

Creates a window with full attribute control.

Parameters
  • Same as XCreateWindow: includes depth, class, visual (EXTERNAL-ADDRESS), valuemask, and pointer to XSetWindowAttributes.
Returns
  • New window ID (INTEGER).

x-destroy-window

(x-destroy-window <display> <window>)
Description

Destroys a window. Immediately unmaps it. Does nothing if is Root window.

Parameters
  • display (EXTERNAL-ADDRESS)
  • screen (INTEGER)

x-map-window

(x-map-window <display> <window>) → VOID
Description

Maps (shows) a window.

Parameters
  1. display (EXTERNAL-ADDRESS)
  2. window (INTEGER)

x-unmap-window

(x-unmap-window <display> <window>) → VOID
Description

Unmaps (hides) a window.

Parameters
  1. display (EXTERNAL-ADDRESS)
  2. window (INTEGER)

x-reparent-window

(x-reparent-window <display> <window> <parent> <x> <y>) → VOID
Description

Reparents a window and positions it within the new parent at the x, y coordinates.

Parameters
  1. display (EXTERNAL-ADDRESS)
  2. window (INTEGER)
  3. parent (INTEGER)
  4. x (INTEGER)
  5. y (INTEGER)

x-move-resize-window

(x-move-resize-window <display> <window> <x> <y> <width> <height>) → <status>
Description

Moves and resizes a window in one call.

Parameters
  1. <display> - External address to an X11 Display object. Represents the connection to the X server.
  2. <window> - Integer handle identifying the window to move/resize.
  3. <x> - Integer specifying the new X coordinate (position) of the window’s origin relative to its parent.
  4. <y> - Integer specifying the new Y coordinate of the window’s origin relative to its parent.
  5. <width> - Integer giving the new width of the window in pixels.
  6. <height> - Integer giving the new height of the window in pixels.
Returns
  • Status code (INTEGER, non-zero on success).

x-circulate-subwindows-up

(x-circulate-subwindows-up <display> <window>) → <status>
Description

Raises all child windows of window.

Arguments
  1. <display> - External address to an X11 Display object.
  2. <window> - Integer representing the X11 Window to bring to the top.

x-circulate-subwindows-down

(x-circulate-subwindows-down <display> <window>) → <status>
Description

Lowers all child windows of window.

Arguments
  1. <display> - External address to an X11 Display object.
  2. <window> - Integer representing the X11 Window to bring to the bottom.

x-raise-window

(x-raise-window <display> <window>) → <void>
Description

Raises window to the top of its siblings.

Arguments
  1. <display> - External address to an X11 Display object.
  2. <window> - Integer representing the X11 Window to bring to the top.

x-lower-window

(x-lower-window <display> <window>) → <void>
Description

Lowers window to the bottom of its siblings.

Arguments
  1. <display> - External address to an X11 Display object.
  2. <window> - Integer representing the X11 Window to lower to the bottom.

x-kill-client
clips (x-kill-client <display> <resource>) → <status>
Description

Forces the X server to close a client identified by resource (window or pixmap).


remove-hints-flags-from-window

(remove-hints-flags-from-window <display> <window> [<hint-symbol> ...])
Returns

void

Description

Clears (removes) one or more size/position-related hint flags from the WM_NORMAL_HINTS property of a given X11 window. These hints influence how window managers position, size, and interpret the window; removing flags allows the application or window manager to ignore previously set constraints.

Arguments
  1. <display> - External address to an X11 Display object.
  2. <window> - Integer representing the X11 Window whose hints are to be modified.
  3. Zero or more of the following hint symbols indicating which bits to remove from the current XSizeHints.flags:
    • USPosition - User-specified position.
    • USSize - User-specified size.
    • PPosition - Program-specified position.
    • PSize - Program-specified size.
    • PMinSize - Program-specified minimum size.
    • PMaxSize - Program-specified maximum size.
    • PResizeInc - Resize increment.
    • PAspect - Aspect ratio.
    • PBaseSize - Base size.
    • PWinGravity - Window gravity.
Example
(remove-hints-flags-from-window ?display ?window USPosition PSize)

set-window-gravity

(set-window-gravity <display> <window> <gravity-symbol>)  
Returns

void (v)

Description

Sets the window gravity in the WM_NORMAL_HINTS property for a given X11 window. Window gravity controls how the window's position is interpreted when its size or parent changes—for example, whether the origin stays fixed or is adjusted relative to a particular corner or edge.

Arguments
  1. - External address to an X11 Display object.
  2. - Integer representing the X11 Window whose gravity is to be set.
  3. - One of the supported gravity symbols:
    • ForgetGravity
    • NorthWestGravity
    • NorthGravity
    • NorthEastGravity
    • WestGravity
    • CenterGravity
    • EastGravity
    • SouthWestGravity
    • SouthGravity
    • SouthEastGravity
    • StaticGravity
Example
(set-window-gravity ?display ?window CenterGravity)

x-list-properties

(x-list-properties <display> <window>)  
Arguments
  • <display>: External address to Display *.
  • <window>: Integer window ID.
Return

A multifield of symbols: each is the string name of a property currently set on the window. If no properties or on failure, returns an empty multifield.

Behavior
  • Internally calls XListProperties.
  • Converts each returned atom to its name via XGetAtomName.
  • Returns names as CLIPS symbols.

x-get-property

(x-get-property <display> <window> <name>)
Arguments
  • <display>: External address to Display *.
  • <window>: Integer window ID.
  • <name>: Name of the property
Returns
  • MULTIFIELD containing:
    1. SYMBOL representing the actual type of the value
    2. INTEGER representing the actual format of the value
    3. A series of STRINGs or INTEGERs which are the actual values

x-change-property

(x-change-property <display> <window> <property-name> <type-name> <format> <mode> [?data])
Arguments
  • <display>: External address of the opened X display (from x-open-display).
  • <window>: Integer window ID to operate on.
  • <property-name>: Symbol/string naming the property to change (will be interned via XInternAtom).
  • <type-name>: Symbol/string naming the type of the property (interned similarly).
  • <format>: Integer; one of 8, 16, or 32. Specifies the data format bits per item.
  • <mode>: One of the symbols "Replace", "Append", or "Prepend". Determines how the new data is combined with existing property data.
  • ?data (optional): The value to set. Accepts:
    • A single integer (interpreted according to format).
    • A string or symbol (automatically coerced to format 8).
    • A multifield of integers (each mapped according to format).

If ?data is omitted, the property is updated with zero elements (effectively clearing it or setting an empty value depending on mode).

Examples
(x-change-property ?display ?window "_NET_WM_NAME" "UTF8_STRING" 8 "Replace" "MyWindow")
(x-change-property ?display ?window "_NET_WM_NAME" "UTF8_STRING" 8 Append " - more")
(x-change-property ?display ?window "MY_PROP" "CARDINAL" 32 Prepend (create$ 1 2 3 4))
(x-change-property ?display ?window "MY_PROP" "CARDINAL" 32 "Replace")

x-delete-property

(x-delete-property <display> <window> <name>)
Arguments
  • <display>: External address to Display *.
  • <window>: Integer window ID.
  • <name>: Name of the property

x-get-geometry

(x-get-geometry <display> <window>)
Arguments
  • <display>: External address to Display *.
  • <window>: Integer window ID.
Returns
  • A multifield with the following ordered values:
    1. root Window ID of the window passed
    2. x position of the Window ID relative to root's origin
    3. y position of the Window ID relative to root's origin
    4. width of the Window ID
    5. height of the Window ID
    6. border_width of the Window ID in pixels
    7. depth of the drawable (bits per pixels of the object)

x-get-window-attributes

x-get-window-attributes-to-fact

x-get-window-attributes-to-instance

Description

Returns attributes about the window as either a multifield, a fact, or an instance. For a multifield, use x-get-window-attributes. The attributes will be returned in this order:

  • x, y - location of window
  • width, height - width and height of window
  • border_width - border width of window
  • depth - depth of window
  • visual - the associated visual structure
  • root - root of screen containing window
  • class - InputOutput, InputOnly
  • bit_gravity - one of the bit gravity values
  • win_gravity - one of the window gravity values
  • backing_store - NotUseful, WhenMapped, Always
  • backing_planes - planes to be preserved if possible
  • backing_pixel - value to be used when restoring planes
  • save_under - boolean, should bits under be saved?
  • colormap - color map to be associated with window
  • map_installed - boolean, is color map currently installed
  • map_state - IsUnmapped, IsUnviewable, IsViewable
  • all_event_masks - set of events all people have interest in
  • your_event_mask - my event mask
  • do_not_propagate_mask - set of events that should not propagate
  • override_redirect - boolean value for override-redirect
  • screen - back pointer to correct screen

For x-get-window-attributes-to-fact, a fact will be asserted with the above slots. For x-get-window-attributes-to-instance, an instance will be made with the above slots.


x-configure-window

(x-configure-window <display> <window> <value-mask>
                    <x> <y> <width> <height> <border-width> <sibling> <stack-mode>)
  → <status>
Description

Wrapper for XConfigureWindow. Applies geometry/stacking changes to a window.

Arguments
  • <display> — EXTERNAL-ADDRESS (Xlib Display*).
  • <window> — INTEGER (Xlib Window id).
  • <value-mask> — which fields to apply. Accepts:
    • INTEGER bitmask, or
    • single SYMBOL/STRING, or
    • MULTIFIELD of SYMBOL/STRING/INTEGER items (all OR’ed together). Supported tokens: CWX, CWY, CWWidth, CWHeight, CWBorderWidth, CWSibling, CWStackMode.
  • <x> — INTEGER
  • <y> — INTEGER
  • <width> — INTEGER
  • <height> — INTEGER
  • <border-width> — INTEGER
  • <sibling> — INTEGER (Xlib Window id; only used if CWSibling is set)
  • <stack-mode> — INTEGER or SYMBOL one of: Above, Below, TopIf, BottomIf, Opposite

x-query-tree

(x-query-tree <display> <window>)
Description

Returns multifield whose members are:

  • root - the root window
  • parent - the parent window
  • children - a list of windows that are children of the ` argument listed in stacking order (bottom-most first)

x-fetch-name

(x-fetch-name ?display ?window)
Arguments
  • <display>: External address to Display *.
  • <window>: Integer window ID.
Returns

STRING of the window name


x-store-name

(x-store-name <display> <window> <name>) → VOID
Arguments
  • <display>: External address to Display *.
  • <window>: Integer window ID.
  • <name>: The new name to set on the window
Example
(x-store-name ?window ?display "My new window!")

Cursor, Font & Color

x-query-pointer

(x-query-pointer <display>) → MULTIFIELD

Description

Returns the x, y coordinates of the cursor.

Arguments

  • <display>: External address to Display *.

Returns

A MULTIFIELD with two values x and y which are the coordinates of the cursor


x-create-font-cursor

(x-create-font-cursor <display> <shape-symbol>) → <cursor-id> | FALSE
Description

Creates a cursor from the X11 font cursor set.

Parameters
  • display (EXTERNAL-ADDRESS)
  • shape-symbol - The following symbol strings are recognised and mapped to their respective X cursor shapes:
    • XC_X_cursor
    • XC_arrow
    • XC_based_arrow_down
    • XC_based_arrow_up
    • XC_boat
    • XC_bogosity
    • XC_bottom_left_corner
    • XC_bottom_right_corner
    • XC_bottom_side
    • XC_bottom_tee
    • XC_box_spiral
    • XC_center_ptr
    • XC_circle
    • XC_clock
    • XC_coffee_mug
    • XC_cross
    • XC_cross_reverse
    • XC_crosshair
    • XC_diamond_cross
    • XC_dot
    • XC_dotbox
    • XC_double_arrow
    • XC_draft_large
    • XC_draft_small
    • XC_draped_box
    • XC_exchange
    • XC_fleur
    • XC_gobbler
    • XC_gumby
    • XC_hand1
    • XC_hand2
    • XC_heart
    • XC_icon
    • XC_iron_cross
    • XC_left_ptr
    • XC_left_side
    • XC_left_tee
    • XC_leftbutton
    • XC_ll_angle
    • XC_lr_angle
    • XC_man
    • XC_middlebutton
    • XC_mouse
    • XC_pencil
    • XC_pirate
    • XC_plus
    • XC_question_arrow
    • XC_right_ptr
    • XC_right_side
    • XC_right_tee
    • XC_rightbutton
    • XC_rtl_logo
    • XC_sailboat
    • XC_sb_down_arrow
    • XC_sb_h_double_arrow
    • XC_sb_left_arrow
    • XC_sb_right_arrow
    • XC_sb_up_arrow
    • XC_sb_v_double_arrow
    • XC_shuttle
    • XC_sizing
    • XC_spider
    • XC_spraycan
    • XC_star
    • XC_target
    • XC_tcross
    • XC_top_left_arrow
    • XC_top_left_corner
    • XC_top_right_corner
    • XC_top_side
    • XC_top_tee
    • XC_trek
    • XC_ul_angle
    • XC_umbrella
    • XC_ur_angle
    • XC_watch
    • XC_xterm

x-define-cursor

(x-define-cursor <display> <window> <cursor>) → VOID
Description

Associates a cursor with a window.


x-get-input-focus

Description

Retrieves the current input focus window and the revert-to setting for the specified display.

Arguments
  • <display>: External address to an X11 Display (as returned by x-open-display).
Returns

A multifield containing two elements:

  1. The focus window (integer).
  2. The revert-to policy as a symbol. Possible values:
    • RevertToParent
    • RevertToPointerRoot
    • RevertToNone

x-set-input-focus

(x-set-input-focus <display> <focus> <revert_to> [<time>]) → INTEGER
Description

Sets the current input focus window and the revert-to setting for the specified display.

Arguments
  • <display>: External address to an X11 Display (as returned by x-open-display).
  • <focus>: The new window to set focus to
  • <revert_to>: The revert-to policy as a symbol. Possible values:
    • RevertToParent
    • RevertToPointerRoot
    • RevertToNone
  • <time>: Timestamp integer, CurrentTime if missing (0)

x-select-input

(x-select-input <display> <window> <mask1> <mask2> ... <maskn>)
Description

Requests the X Server to report events associated with the supplied event masks.

Example
(x-select-input ?display ?window SubstructureRedirectMask)

x-warp-pointer

(x-warp-pointer <display> <src-window> <dest-window> <src-x> <src-y> <src-width> <src-height> <dest-x> <dest-y>) => <lexeme or integer>
Description

Moves the pointer (mouse cursor) to a specified location, either relative to a source window or directly into a destination window. NOTE: Does not necessarily move the visual cursor icon on the screen; check the coordinates with x-query-pointer after x-warp-pointer.

Arguments
  • display: External address to the X11 Display.
  • src-window: Source window (integer). The pointer is warped relative to this window’s coordinate system. Use 0 if not constraining to a source region.
  • dest-window: Destination window (integer) where the pointer will be moved. Use 0 to indicate the root or global coordinate space depending on your semantics.
  • src-x / src-y / src-width / src-height: Defines a source rectangle within src-window. If the current pointer position is outside this rectangle, the warp does not occur. To ignore the source restriction, supply zeros appropriately (as per X11 API).
  • dest-x / dest-y: Coordinates within dest-window to which the pointer will be moved.

black-pixel

white-pixel

(black-pixel <display> <screen>) → <pixel>
(white-pixel <display> <screen>) → <pixel>
Description

Fetches the black or white pixel value for a screen.


Graphics Context & Drawing

x-create-gc

(x-create-gc <display> <drawable> <valuemask>) → <GC-ADDRESS>
Description

Creates a graphics context; returns an external address. Uses default XGCValues.


x-set-foreground

(x-set-foreground <display> <gc> <pixel>) → <status>
Description

Sets the foreground color for drawing operations in a GC.


Drawing Primitives

(x-draw-arc <display> <drawable> <gc> <x> <y> <width> <height> <angle1> <angle2>)
(x-draw-line <display> <drawable> <gc> <x1> <y1> <x2> <y2>)
(x-draw-point <display> <drawable> <gc> <x> <y>)
(x-draw-rectangle <display> <drawable> <gc> <x> <y> <width> <height>)
(x-draw-string <display> <drawable> <gc> <x> <y> <text>)

Each wraps the corresponding XDraw* call and returns VOID.


Event Handling

x-pending

(x-pending <display>) → <count>
Description

Checks how many events are queued.


x-peek-event

x-next-event

(x-peek-event <display>) → <multifield>
(x-next-event <display>) → <multifield>
Description

Retrieves (or waits for) the next XEvent, converts it into a CLIPS multifield:

[ <xany> <type-symbol> <typed-detail> ]

Return

A multifield consisting of fields combined from the XAny event as well as the type-specific event.


x-peek-event-to-fact

x-next-event-to-fact

(x-peek-event-to-fact <display>) → <fact>
(x-next-event-to-fact <display>) → <fact>
Description

As above, but asserts an x-event, x-any-event, and a typed fact template. Check deftemplates.clp to see the structure of these deftemplates.


x-peek-event-to-instance

x-next-event-to-instance

(x-peek-event-to-instance <display>) → <instance>
(x-next-event-to-instance <display>) → <instance>
Description

As above, but asserts an X-EVENT-* typed COOL instance. Check defclasses.clp to see the structure of these defclasses.


x-pop-event

(x-pop-event <display>) → VOID
Description

Removes the next event without returning it. Useful after an x-peek-event to remove it from the event queue.


x-send-event

(x-send-event <display> <window> <propagate> <event-mask> <event>) → INTEGER
Description

Sends the event specified as the last argument to the display/window. Can be received with x-next-event if the event mask is selected using x-select-input.

Arguments
  • <display> - A c-pointer to the display object to send the event to
  • <window> - A window ID to send the event to
  • <propagate> - A boolean to determine whether or not to propagate the event if not received.
  • <event-mask> - One of:
    • An integer representing the event mask. Use lexeme-to-event-mask or multifield-to-event-mask to generate an INTEGER for this argument.
    • A symbol or string representing the event mask modifier.
    • A multifield of symbols or strings representing values to | (or) for the event mask modifier
  • <event> - A MULTIFIELD, FACT, or INSTANCE that contains the event details

If using FACT or INSTANCE as <event>, refer to the deftemplates.clp or defclasses.clp respectively to determine which slots need to be set. In all casses, c-pointer, serial, send-event and display slot values will not be used.

If using a MULTIFIELD, refer to the following to determine the order in which you must append values to the multifield for them to be received by the appropriate event types (all values are INTEGERs unless otherwise noted):

(KeyPress <window> <root> <subwindow> <time> <x> <y> <x_root> <y_root> <state> <keycode> <same_screen>)
(KeyRelease <window> <root> <subwindow> <time> <x> <y> <x_root> <y_root> <state> <keycode> <same_screen>)
(ButtonPress <window> <root> <subwindow> <time> <x> <y> <x_root> <y_root> <state> <keycode> <same_screen>)
(ButtonRelease <window> <root> <subwindow> <time> <x> <y> <x_root> <y_root> <state> <keycode> <same_screen>)
  • same_screen - TRUE or FALSE
  • state - an INTEGER for a mask. Retrievable by lexeme-to-mask or multifield-to-mask
(MotionNotify <window> <root> <subwindow> <time> <x> <y> <x_root> <y_root> <state> <is_hint> <same_screen>)
  • is_hint - NotifyNormal or NotifyHint
  • same_screen - TRUE or FALSE
  • state - an INTEGER for a mask. Retrievable by lexeme-to-mask or multifield-to-mask
(EnterNotify <window> <root> <subwindow> <time> <x> <y> <x_root> <y_root> <mode> <detal> <same_screen> <focus> <state>)
(LeaveNotify <window> <root> <subwindow> <time> <x> <y> <x_root> <y_root> <mode> <detal> <same_screen> <focus> <state>)
  • mode - NotifyNormal, NotifyGrab, or NotifyUngrab
  • detail - NotifyAncestor, NotifyVirtual, NotifyInferior, NotifyNonlinear, NotifyNonlinearVirtual, NotifyPointer, NotifyPointerRoot, or NotifyDetailNone
  • same_screen - TRUE or FALSE
  • focus - TRUE or FALSE
  • state - an INTEGER for a mask. Retrievable by lexeme-to-mask or multifield-to-mask
(FocusIn <window> <mode> <detail>)
(FocusOut <window> <mode> <detail>)
  • mode - NotifyNormal, NotifyGrab, or NotifyUngrab
  • detail - NotifyAncestor, NotifyVirtual, NotifyInferior, NotifyNonlinear, NotifyNonlinearVirtual, NotifyPointer, NotifyPointerRoot, or NotifyDetailNone
(KeymapNotify <display> <window> <bool>...<bool>)
  • display - C Pointer to Display
(Expose <window> <x> <y> <width> <height> <count>)
(GraphicsExpose <drawable> <x> <y> <width> <height> <count> <major_code> <minor_code>)
(NoExpose <drawable> <major_code> <minor_code>)
(VisibilityNotify <window> <state>)
  • state - VisibilityUnobscured, VisibilityPartiallyObscured, or VisibilityFullyObscured
(CreateNotify <parent> <window> <x> <y> <width> <height> <border_width> <override_redirect>)
  • override_redirect - TRUE or FALSE
(DestroyNotify <event> <window>)
(UnmapNotify <event> <window> <from_configure>)
  • from_configure - TRUE or FALSE
(MapNotify <event> <window> <override_redirect>)
  • override_redirect - TRUE or FALSE
(MapRequest <parent> <window>)
(ReparentNotify <event> <window> <parent> <x> <y> <override_redirect>)
(ConfigureNotify <event> <window> <parent> <x> <y> <width> <height> <border_width> <above> <override_redirect>)
  • override_redirect - TRUE or FALSE
(ConfigureRequest <parent> <window> <x> <y> <width> <height> <border_width> <above> <detail> <value_mask>)
  • detail - Above, Below, TopIf, BottomIf, Opposite
(GravityNotify <event> <window> <x> <y>)
(ResizeRequest <window> <width> <height>)
(CirculateNotify <event> <window> <place>)
(CirculateRequest <parent> <window> <place>)
  • place - PlaceOnTop or PlaceOnBottom
(PropertyNotify <window> <atom> <time> <state>)
  • state - PropertyNewValue or PropertyDelete
(SelectionClear <window> <selection> <time>)
(SelectionRequest <owner> <requestor> <selection> <target> <property> <time>)
(SelectionNotify <requestor> <selection> <target> <property> <time>)
(ColormapNotify <window> <colormap> <new> <state>)
  • state - ColormapInstalled or ColormapUninstalled
(ClientMessage <window> <message_type> <format> <b or s or l integers>...<b or s or l integers>)
  • format - 8, 16, or 32
(MappingNotify <window> <request> <first_keycode> <count>)
  • request - MappingModifier, MappingKeyboard, or MappingPointer
(GenericEvent <extension> <evtype>)

Keyboard Utilities

x-lookup-string

(x-lookup-string <event-address>) → [ <string> <keysym> ]
Description

Converts a KeyPress event to its text and keysym.


x-string-to-keysym

(x-string-to-keysym <symbol>) → <keysym>
Description

Maps a key name (e.g. "Return") to its keysym.


x-keysym-to-keycode

(x-keysym-to-keycode <display> <keysym>) → <keycode>

x-grab-server

(x-grab-server <display>) → VOID
Description

Disables processing of requests and close downs on all other connections than the one this request arrived on


x-ungrab-server

(x-ungrab-server <display>) → VOID
Description

Restarts processing of requests and close downs on other connections.


x-grab-button

(x-grab-button <display> <button> <modifiers> <grab_window> <owner-events?> <event_mask> <pointer-mode> <keyboard-mode> <confine_to> <cursor>) → <status>
Description

Grabs a specific button (with optional modifier masks) on a given window so that the application receives button events even if another client would normally have focus. This is an X11 passive button grab.

Arguments
  1. <display> - External address to an X11 Display object.
  2. <button> - Integer button to grab.
  3. <modifiers> - One of:
    • An integer representing the mask modifier. Use lexeme-to-mask or multifield-to-mask to generate an INTEGER for this argument.
    • A symbol or string representing the mask modifier.
    • A multifield of symbols or strings representing values to | (or) for the mask modifier
  4. <grab-window> - Integer representing the X11 window in which the button is to be grabbed.
  5. <owner-events?> - Boolean; if TRUE, events are reported as if the grabbing client owned the events (owner_events argument to XGrabButton).
  6. <event_mask> - One of:
    • An integer representing the event mask. Use lexeme-to-event-mask or multifield-to-event-mask to generate an INTEGER for this argument.
    • A symbol or string representing the event mask modifier.
    • A multifield of symbols or strings representing values to | (or) for the event mask modifier
  7. <pointer-mode-symbol> - Symbol controlling pointer freezing behavior during the grab. Recognized value:
    • "GrabModeSync" - pointer is frozen until explicitly released (maps to X11 GrabModeSync)
    • anything else (typically "GrabModeAsync") - pointer operates asynchronously (maps to GrabModeAsync)
  8. <keyboard-mode-symbol> - Symbol controlling keyboard freezing behavior during the grab. Same semantics as pointer-mode-symbol.
  9. <confine_to> - Window to confine the grab to
  10. <cursor> - Specifies the cursor to be displayed
Example
;grabs button t when mod4 (typically windows button) is held down
(x-grab-button ?display (x-buttonsym-to-buttoncode ?display (x-string-to-buttonsym "t")) Mod4Mask ?window TRUE GrabModeAsync GrabModeAsync)))

x-ungrab-button

(x-ungrab-button <display> <button> <modifiers> <grab_window>) → VOID
Description

Releases a specific button (with optional modifier masks) on a given window if it was grabbed by this client.

Arguments
  1. <display> - External address to an X11 Display object.
  2. <button> - Integer button to grab.
  3. <modifiers> - One of:
    • An integer representing the mask modifier. Use lexeme-to-mask or multifield-to-mask to generate an INTEGER for this argument.
    • A symbol or string representing the mask modifier.
    • A multifield of symbols or strings representing values to | (or) for the mask modifier
  4. <grab-window> - Integer representing the X11 window in which the button is to be grabbed.

x-grab-key

(x-grab-key <display> <keycode> <modifiers> <window> <owner-events?> <pointer-mode> <keyboard-mode>) → <status>
Description

Grabs a specific key (with optional modifier masks) on a given window so that the application receives key events even if another client would normally have focus. This is an X11 passive key grab.

Arguments
  1. <display> - External address to an X11 Display object.
  2. <keycode> - Integer keycode to grab.
  3. <modifiers> - One of:
    • An integer representing the mask modifier. Use lexeme-to-mask or multifield-to-mask to generate an INTEGER for this argument.
    • A symbol or string representing the mask modifier.
    • A multifield of symbols or strings representing values to | (or) for the mask modifier
  4. <grab-window> - Integer representing the X11 window in which the key is to be grabbed.
  5. <owner-events?> - Boolean; if TRUE, events are reported as if the grabbing client owned the events (owner_events argument to XGrabKey).
  6. <pointer-mode-symbol> - Symbol controlling pointer freezing behavior during the grab. Recognized value:
    • "GrabModeSync" - pointer is frozen until explicitly released (maps to X11 GrabModeSync)
    • anything else (typically "GrabModeAsync") - pointer operates asynchronously (maps to GrabModeAsync)
  7. <keyboard-mode-symbol> - Symbol controlling keyboard freezing behavior during the grab. Same semantics as pointer-mode-symbol.
Example
;grabs key t when mod4 (typically windows key) is held down
(x-grab-key ?display (x-keysym-to-keycode ?display (x-string-to-keysym "t")) Mod4Mask ?window TRUE GrabModeAsync GrabModeAsync)))

x-ungrab-key

(x-ungrab-key <display> <keycode> <modifiers> <grab_window>) → VOID
Description

Releases a specific key (with optional modifier masks) on a given window if it was grabbed by this client.

Arguments
  1. <display> - External address to an X11 Display object.
  2. <keycode> - Integer keycode to grab.
  3. <modifiers> - One of:
    • An integer representing the mask modifier. Use lexeme-to-mask or multifield-to-mask to generate an INTEGER for this argument.
    • A symbol or string representing the mask modifier.
    • A multifield of symbols or strings representing values to | (or) for the mask modifier
  4. <grab-window> - Integer representing the X11 window in which the key is to be grabbed.

x-grab-pointer

(x-grab-pointer <display> <grab_window> <owner_events?> <event_mask> <pointer-mode> <keyboard-mode> <confine_to> <cursor> [<time>]) → <status>
Description

Grabs control of the pointer. Further pointer events are reported only to the grabbing client.

Arguments
  1. <display> - External address to an X11 Display object.
  2. <grab-window> - Integer representing the X11 window in which the pointer is to be grabbed.
  3. <owner-events?> - Boolean; if TRUE, events are reported as if the grabbing client owned the events (owner_events argument to XGrabPointer).
  4. <event_mask> - One of:
    • An integer representing the event mask. Use lexeme-to-event-mask or multifield-to-event-mask to generate an INTEGER for this argument.
    • A symbol or string representing the event mask modifier.
    • A multifield of symbols or strings representing values to | (or) for the event mask modifier
  5. <pointer-mode-symbol> - Symbol controlling pointer freezing behavior during the grab. Recognized value:
    • "GrabModeSync" - pointer is frozen until explicitly released (maps to X11 GrabModeSync)
    • anything else (typically "GrabModeAsync") - pointer operates asynchronously (maps to GrabModeAsync)
  6. <keyboard-mode-symbol> - Symbol controlling keyboard freezing behavior during the grab. Same semantics as pointer-mode-symbol.
  7. <confine_to> - Window to confine the grab to
  8. <cursor> - Specifies the cursor to be displayed
  9. <time> - Specifies the time of the grab. CurrentTime if not provided.

x-ungrab-pointer

(x-ungrab-pointer <display> [<time>]) → VOID
Description

Releases the pointer and any queued events.

Arguments
  1. <display> - External address to an X11 Display object.
  2. <time> - Specifies the time. CurrentTime if not provided.

Screen Conversion

screen-to-fact

(screen-to-fact <screen-address>) → <fact>
Description

Builds and asserts a screen fact with slots:

  • c-pointer
  • ext-data
  • display
  • root
  • width
  • height
  • mwidth
  • mheight
  • ndepths
  • root-depth
  • white-pixel
  • black-pixel
  • max-maps
  • min-maps
  • backing-store
  • save-unders
  • root-input-mask

screen-to-instance

(screen-to-instance <screen-address>) → <instance>
Description

Builds and asserts a SCREEN instance with the same slots listed above.


screen-to-multifield

(screen-to-multifield <screen-address>) → <multifield>
Description

Returns the same information as a multifield vector.


Utility

event-mask-to-symbol

(event-mask-to-symbol <mask integer>) → <symbol>

Description

Converts an integer event mask to a symbol representing the event mask name. Possible event masks that will return:

  • KeyPressMask
  • KeyReleaseMask
  • ButtonPressMask
  • ButtonReleaseMask
  • EnterWindowMask
  • LeaveWindowMask
  • PointerMotionMask
  • PointerMotionHintMask
  • Button1MotionMask
  • Button2MotionMask
  • Button3MotionMask
  • Button4MotionMask
  • Button5MotionMask
  • ButtonMotionMask
  • KeymapStateMask
  • ExposureMask
  • VisibilityChangeMask
  • StructureNotifyMask
  • ResizeRedirectMask
  • SubstructureNotifyMask
  • SubstructureRedirectMask
  • FocusChangeMask
  • PropertyChangeMask
  • ColormapChangeMask
  • OwnerGrabButtonMask

mask-to-symbol

(mask-to-symbol <mask integer>) → <symbol>

Description

Converts an integer mask to a symbol representing the mask names. Possible masks that will return:

  • ShiftMask
  • LockMask
  • ControlMask
  • Mod1Mask
  • Mod2Mask
  • Mod3Mask
  • Mod4Mask
  • Mod5Mask
  • Button1Mask
  • Button2Mask
  • Button3Mask
  • Button4Mask
  • Button5Mask
  • AnyModifier

event-mask-to-multifield

(event-mask-to-multifield <mask integer>) → <multifield>

Description

Converts an integer event mask to a multifield of symbols representing the event mask names. Refer to event-mask-to-symbol for possible values that will return in the multifield.


mask-to-multifield

(mask-to-multifield <mask integer>) → <multifield>

Description

Converts an integer mask to a multifield of symbols representing the mask names. Refer to mask-to-symbol for possible values that will return in the multifield.


lexeme-to-event-mask

(lexeme-to-event-mask <symbol or string>) → <integer>
Description

Converts a symbol or string of an event mask to the integer mask for the event mask. See event-mask-to-symbol for a list of possible symbols that may be passed as the argument.


lexeme-to-mask

(lexeme-to-mask <symbol or string>) → <integer>
Description

Converts a symbol or string of a mask to the integer mask for the mask. See mask-to-symbol for a list of possible symbols that may be passed in the multifield.


multifield-to-event-mask

(multifield-to-event-mask <multifield>) → <integer>
Description

Converts a multifield containing symbols of event masks to the integer mask containing all event masks specified. See event-mask-to-symbol for a list of possible symbols that may be passed in the multifield.


multifield-to-mask

(multifield-to-mask <multifield>) → <integer>
Description

Converts a multifield containing symbols of masks to the integer mask containing all masks specified. See mask-to-symbol for a list of possible symbols that may be passed in the multifield.


x-translate-coordinates

(x-translate-coordinates <display> <src_window> <dest_window> <src_x> <src_y>) → <multifield> or FALSE
Description

Translate a coordinate in one window to the coordinate space of another window.

Returns

Takes the src_x and src_y coordinates relative to the src_window's origin and returns these coordinates as the first 2 values in a multifield relative to the destination window's origin. If the coordinates are contained in a mapped child of dest_window, that child is returned as the last value in the returned multifield.


x-allow-events

(x-allow-events <display> <event_mode> [<time>])
Description

Releases some queued events if the client has caused a device to freeze. It has no effect if the specified time is earlier than the last-grab time of the most recent active grab for the client or if the specified time is later than the current X server time

Arguments
  • display - Specifies the connection to the X server.
  • event_mode - Specifies the event mode. You can pass an integer or one of the symbols AsyncPointer, SyncPointer, AsyncKeyboard, SyncKeyboard, ReplayPointer, ReplayKeyboard, AsyncBoth, or SyncBoth.
  • time - Optional. Specifies the time. Omitting this specifies CurrentTime (0).

x-restack-windows

(x-allow-events <display> <windows> [<nwindows>])
Description

Restacks the windows in the order specified, from top to bottom.

Arguments
  • display - Specifies the connection to the X server.
  • windows - Specifies a multifield containing the window INTEGERs to be restacked.
  • nwindows - Optional. Specifies the number of windows to be restacked. Will use the length of windows multifield if omitted.

x-sync

(x-sync <display> [<discard?>]) → <status>
Description

Synchronizes with the X server. Sends all pending requests and waits until they are processed. Optionally discards any events already in the queue.

  • <display> - External address to an X11 Display*.
  • <discard?> - Optional boolean.
    • TRUE discards all queued events.
    • FALSE (default) keeps queued events.
Returns

Integer status (non-zero on success).


x-flush

(x-flush <display>) → <status>
Description

Flushes the output buffer of the X server connection, ensuring all pending requests are sent. Does not wait for responses from the server.

Arguments
  • <display> - External address to an X11 Display*.
Returns

Integer status (always non-zero).


x-set-window-background

(x-set-window-background <display> <window> <pixel>) → <status>
Description

Sets the background color of a window to the specified pixel value. The window background is used when the window is cleared.

Arguments
  • <display> - External address to an X11 Display*.
  • <window> - Integer window ID.
  • <pixel> - Integer pixel value to set as the background. Typically retrieved from black-pixel, white-pixel, or x-alloc-color.
Returns

VOID

Example
(x-set-window-background ?display ?window (white-pixel ?display (default-screen ?display)))

x-change-window-attributes

(x-change-window-attributes <display> <window> <value-mask> [<attr1> <attr2> ...]) → <status>
Description

Updates one or more attributes of a window. The <value-mask> determines which fields are modified. Arguments for the attributes must be supplied in the canonical struct order and only for the bits set in <value-mask>.

Arguments
  • <display> - External address to Display*.
  • <window> - Integer window ID.
  • <value-mask> - One of:
    • Integer bitmask
    • Symbol (e.g. "CWBackPixel")
    • Multifield of symbols/strings/integers (all OR'ed together) Supported mask bits and their corresponding arguments: CWBackPixmap - Pixmap ID or None/ParentRelative CWBackPixel - Integer pixel value CWBorderPixmap - Pixmap ID CWBorderPixel - Integer pixel value CWBitGravity - Symbol or integer gravity value CWWinGravity - Symbol or integer gravity value CWBackingStore - Symbol (NotUseful | WhenMapped | Always) or integer CWBackingPlanes - Integer CWBackingPixel - Integer CWOverrideRedirect - Boolean or integer (0/1) CWSaveUnder - Boolean or integer (0/1) CWEventMask - Integer mask of event bits CWDontPropagate - Integer mask CWColormap - Colormap ID CWCursor - Cursor ID
Returns

Integer status code (non-zero on success).

Examples
; Set only override-redirect
(x-change-window-attributes ?display ?window CWOverrideRedirect TRUE)

; Set background pixel and event mask
(x-change-window-attributes ?display ?window (create$ CWBackPixel CWEventMask)
    0
    (multifield-to-event-mask (create$ SubstructureRedirectMask StructureNotifyMask)))

x-clear-window

(x-clear-window <display> <window>) → <status>
Description

Clears the entire window to its background. Exposes regions of the window according to its current background settings.

Arguments
  • <display> - External address to Display*.
  • <window> - Integer window ID.
Returns

VOID


x-clear-area

(x-clear-area <display> <window> <x> <y> <width> <height> [<exposures?>]) → <status>
Description

Clears a rectangular region of a window to the window’s background. Optionally controls whether Expose events are generated.

Arguments
  • <display> - External address to Display*.
  • <window> - Integer window ID.
  • <x> - X coordinate of top-left corner.
  • <y> - Y coordinate of top-left corner.
  • <width> - Width of the rectangle.
  • <height> - Height of the rectangle.
  • <exposures?> - Optional boolean or integer. If TRUE (default), generate Expose events; if FALSE, suppress them
Example
(x-clear-area ?display ?window 10 10 200 100 FALSE)

x-set-selection-owner

(x-set-selection-owner <display> <selection> <owner> [<time>]) → <status>
Description

Sets the window that “owns” a selection (e.g., PRIMARY, CLIPBOARD). Ownership means your window will provide the data when requested.

Arguments
  • <display> - External address to Display*.
  • <selection> - Atom name or ID (e.g., "PRIMARY", "CLIPBOARD").
  • <owner> - Window ID that will own the selection.
  • <time> - Optional timestamp (integer). Defaults to CurrentTime (0).
Example
(x-set-selection-owner ?display "PRIMARY" ?mywin)

x-get-selection-owner

(x-get-selection-owner <display> <selection>) → <window>
Description

Gets the current owner window of a selection.

Arguments
  • <display> - External address to Display*.
  • <selection> - Atom name or ID.
Returns

Window ID (integer) or 0 if no owner.

Example
(bind ?owner (x-get-selection-owner ?display "CLIPBOARD"))

x-convert-selection

(x-convert-selection <display> <selection> <target> <property> <requestor> [<time>]) → <status>
Description

Requests the current owner of a selection to convert its data to a given target (format) and place the result into a property on your requestor window. After SelectionNotify, read it with x-get-property.

Arguments
  • <display> - External address to Display*.
  • <selection> - Atom name or ID (e.g., "PRIMARY", "CLIPBOARD").
  • <target> - Atom name or ID of desired format (e.g., "UTF8_STRING", "STRING", "TARGETS").
  • <property> - Atom name or ID where data should be stored on the requestor (e.g., "XSEL_DATA").
  • <requestor> - Your window ID.
  • <time> - Optional timestamp. Defaults to CurrentTime (0).
Example
; Ask for PRIMARY as UTF8 and store bytes in XSEL_DATA on our window
(x-convert-selection ?display "PRIMARY" "UTF8_STRING" "XSEL_DATA" ?mywin)

; Later, upon SelectionNotify, read it:
(x-get-property ?display ?mywin "XSEL_DATA")

x-get-wm-normal-hints

(x-get-wm-normal-hints <display> <window>) → <multifield> | FALSE
Description

Thin wrapper over XGetWMNormalHints. Reads ICCCM WM_NORMAL_HINTS (size/position constraints).

Arguments
  • <display>: EXTERNAL-ADDRESS to Display*
  • <window>: INTEGER window id
Returns

A MULTIFIELD of 19 elements (order fixed):

  1. flags (INTEGER bitmask: USPosition USSize PPosition PSize PMinSize PMaxSize PResizeInc PAspect PBaseSize PWinGravity)
  2. x
  3. y
  4. width
  5. height
  6. min_width
  7. min_height
  8. max_width
  9. max_height
  10. width_inc
  11. height_inc
  12. min_aspect_num
  13. min_aspect_den
  14. max_aspect_num
  15. max_aspect_den
  16. base_width
  17. base_height
  18. win_gravity (SYMBOL: ForgetGravity/NorthWestGravity/.../StaticGravity)
Example
(bind ?hints (x-get-wm-normal-hints ?d ?w))
(if (neq ?hints FALSE) then
  (printout t "flags=" (nth$ 1 ?hints) " min=(" (nth$ 6 ?hints) "," (nth$ 7 ?hints) ")" crlf))

x-get-wm-normal-hints-to-fact

(x-get-wm-normal-hints-to-fact <display> <window>) → <fact-address> | FALSE
Description

Reads WM_NORMAL_HINTS and asserts a fact using the x-size-hints deftemplate.

Arguments
  • <display>: EXTERNAL-ADDRESS to Display*
  • <window>: INTEGER window id
Returns
  • Fact address of (x-size-hints ...) on success
  • FALSE on failure
Example
(bind ?f (x-get-wm-normal-hints-to-fact ?d ?w))
(if (neq ?f FALSE) then
  (bind ?minw (fact-slot-value ?f min_width))
  (bind ?minh (fact-slot-value ?f min_height)))

x-get-wm-normal-hints-to-instance

(x-get-wm-normal-hints-to-instance <display> <window>) → <instance-address> | FALSE
Description

Reads WM_NORMAL_HINTS and creates an instance of class X-SIZE-HINTS (you provide this class).

Arguments
  • <display>: EXTERNAL-ADDRESS to Display*
  • <window>: INTEGER window id
Returns
  • Instance address of (make-instance of X-SIZE-HINTS ...) on success
  • FALSE on failure
Example
(bind ?i (x-get-wm-normal-hints-to-instance ?d ?w))
(if (neq ?i FALSE) then
  (send ?i get-min_width))

x-get-wm-hints

(x-get-wm-hints <display> <window>) → <multifield> | FALSE
Description

Thin wrapper over XGetWMHints. Reads ICCCM WM_HINTS.

Arguments
  • <display>: EXTERNAL-ADDRESS to Display*
  • <window>: INTEGER window id
Returns

A MULTIFIELD of 9 elements (order fixed):

  • flags (INTEGER bitmask: InputHint, StateHint, IconPixmapHint, IconWindowHint, IconPositionHint, IconMaskHint, WindowGroupHint)
  • input (SYMBOL TRUE|FALSE)
  • initial_state (SYMBOL WithdrawnState|NormalState|IconicState)
  • icon_pixmap (INTEGER)
  • icon_window (INTEGER)
  • icon_x (INTEGER)
  • icon_y (INTEGER)
  • icon_mask (INTEGER)
  • window_group (INTEGER)
Example
(bind ?h (x-get-wm-hints ?d ?w))
(if (neq ?h FALSE) then
  (printout t "state=" (nth$ 3 ?h) " group=" (nth$ 9 ?h) crlf))

x-get-wm-hints-to-fact

(x-get-wm-hints-to-fact <display> <window>) → <fact-address> | FALSE
Description

Reads WM_HINTS and asserts a fact using the x-wm-hints deftemplate.

Arguments
  • <display>: EXTERNAL-ADDRESS to Display*
  • <window>: INTEGER window id
Returns
  • Fact address on success
  • FALSE on failure
Example
(bind ?f (x-get-wm-hints-to-fact ?d ?w))
(if (neq ?f FALSE) then
  (bind ?state (fact-slot-value ?f initial_state))
  (printout t "initial_state=" ?state crlf))

x-get-wm-hints-to-instance

(x-get-wm-hints-to-instance <display> <window>) → <instance-address> | FALSE
Description

Reads WM_HINTS and creates an instance of class X-WM-HINTS.

Arguments
  • <display>: EXTERNAL-ADDRESS to Display*
  • <window>: INTEGER window id
Returns
  • Instance address on success
  • FALSE on failure
Example
(bind ?i (x-get-wm-hints-to-instance ?d ?w))
(if (neq ?i FALSE) then
  (send ?i get-window_group))

x-get-wm-protocols

(x-get-wm-protocols <display> <window>) → <multifield-of-atoms> | FALSE
Description

Returns the list of ICCCM WM_PROTOCOLS supported by a window (e.g., WM_DELETE_WINDOW, WM_TAKE_FOCUS) as integer Atom IDs.

Arguments
  • <display>: EXTERNAL-ADDRESS to Display*
  • <window>: INTEGER window id
Returns

MULTIFIELD of INTEGER atom IDs in server order, or FALSE if the property is absent/unavailable.

Example
(bind ?protos (x-get-wm-protocols ?d ?w))
(if (neq ?protos FALSE) then
  (bind ?del (x-intern-atom ?d "WM_DELETE_WINDOW" TRUE))
  (if (member$ ?del ?protos) then
      (printout t "Client supports WM_DELETE_WINDOW" crlf)))

x-intern-atom

(x-intern-atom <display> <name> [<only-if-exists?>]) → <atom-id (INTEGER)>
Description

Interns an atom by name on the X server (ICCCM/EWMH rely on atoms).

Arguments
  • <display>: EXTERNAL-ADDRESS to Display*.
  • <name>: Symbol or string (e.g., WM_DELETE_WINDOW, _NET_WM_NAME).
  • <only-if-exists?> (optional): Boolean/symbol/int. If true, returns 0 when the atom doesn’t already exist. Default FALSE.
Return

Integer atom ID (0 = None when only-if-exists? is true).

Example
(bind ?UTF8 (x-intern-atom ?d "UTF8_STRING" TRUE))

x-intern-atoms

(x-intern-atoms <display> <names-mf> [<only-if-exists?>]) → <multifield-of-atom-ids>
Description

Batch version of x-intern-atom. Interns multiple names with a single round trip.

Arguments
  • <display>: EXTERNAL-ADDRESS to Display*.
  • <names-mf>: Multifield of symbols/strings (atom names).
  • <only-if-exists?> (optional): Boolean/symbol/int. If true, returns 0 when the atom doesn’t already exist. Default FALSE.
Return
  • Multifield of INTEGER atom IDs (same order as <names-mf>).
  • Empty multifield if <names-mf> is empty or on validation error (error text is printed to STDERR if any element isn’t a symbol/string).
Example
(bind ?atoms (x-intern-atoms ?d (create$ "_NET_WM_NAME" "UTF8_STRING" "WM_DELETE_WINDOW") TRUE))

x-get-atom-name

(x-get-atom-name <display> <atom>) → <string> | FALSE
Description

Resolves an atom ID back to its server-side name.

Arguments
  • <display>: EXTERNAL-ADDRESS to Display*.
  • <atom>: INTEGER atom ID.
Return
  • String name on success.
  • FALSE if the atom is invalid/unknown.
Example
(bind ?name (x-get-atom-name ?d ?atom))

x-get-class-hint

(x-get-class-hint <display> <window>) → <multifield> | FALSE
Description

Returns the X resource instance (res_name) and class (res_class) of a window, used for rule matching (e.g., float dialogs, apply tags).

Arguments
  • <display>: EXTERNAL-ADDRESS to Display*
  • <window>: INTEGER window id
Return
  • MULTIFIELD of 2 strings:
    • res_name
    • res_class
  • FALSE if unavailable.
Example
(bind ?rc (x-get-class-hint ?d ?w))
(if (neq ?rc FALSE) then
  (bind ?name  (nth$ 1 ?rc))
  (bind ?class (nth$ 2 ?rc))
  (printout t "class=" ?class " name=" ?name crlf))

Error Handling

x-start-collecting-errors

(x-start-collecting-errors <display>)
Description

Start capturing X11 errors into an internal per-Display queue handled by the library's error collector. If a queue already exists for this Display, it returns TRUE without creating a new one. Will store a maximum of 128 errors before discarding the oldest error.

Arguments
  • <display>: EXTERNAL-ADDRESS to Display*
Return
  • TRUE if the error queue is active (already existed or was created).
  • FALSE if the queue could not be created.
Example
(bind ?d (x-open-display ""))
(if (x-start-collecting-errors ?d) then
  (printout t "Error collection enabled." crlf))

x-pop-error

(x-pop-error <display>)  ;; -> (serial error-code request-code minor-code resourceid) | FALSE
Description

Pop the oldest queued X11 error for a Display and return its fields.

Arguments
  • <display>: EXTERNAL-ADDRESS to Display*
Returns

Returns

  • A multifield of 5 integers on success:
    • serial
    • error-code
    • request-code
    • minor-code
    • resourceid
  • FALSE if no queue exists for the Display or the queue is empty.
Example
(bind ?d (x-open-display ""))

;; Start capturing errors once (usually at init)
(x-start-collecting-errors ?d)

;; ... make some X calls that might error ...

;; Try to pop one error
(bind ?err (x-pop-error ?d))
(if (neq ?err FALSE) then
  (bind ?serial      (nth$ 1 ?err))
  (bind ?error-code  (nth$ 2 ?err))
  (bind ?request     (nth$ 3 ?err))
  (bind ?minor       (nth$ 4 ?err))
  (bind ?resourceid  (nth$ 5 ?err))
  (printout t "X error " ?error-code
               " (req " ?request "/" ?minor
               ", serial " ?serial
               ", resource " ?resourceid ")" crlf)
)

;; Optionally resolve human-readable text
(printout t (x-get-error-text ?d ?error-code) crlf)
(printout t (error-code-to-symbol ?error-code) crlf)
(printout t (x-get-error-database-text ?d XRequest ?request))
(printout t (x-get-error-database-text ?d XProtoError ?request))

x-pop-error-to-fact

(x-pop-error-to-fact <display>)  ;; -> <fact-address> | FALSE
Description

Pop the oldest queued X11 error for a Display, assert it as an x-error fact, and return the fact-address.

Arguments
  • <display>: EXTERNAL-ADDRESS to Display*
Return
  • Fact-address of an asserted (x-error ...) fact on success.
  • FALSE if no queue exists for the Display, the queue is empty, or the fact could not be asserted.
Example
(bind ?d (x-open-display ""))

;; Start collecting errors once
(x-start-collecting-errors ?d)

;; ... do X calls that may error ...

;; Pop to fact
(bind ?f (x-pop-error-to-fact ?d))
(if (neq ?f FALSE) then
  (printout t "Got X error fact:"
              " serial="      (fact-slot-value ?f serial)
              " code="        (fact-slot-value ?f error-code)
              " request="     (fact-slot-value ?f request-code)
              " minor="       (fact-slot-value ?f minor-code)
              " resourceid="  (fact-slot-value ?f resourceid)
              crlf))

;; Optional: map code to text
;; (printout t (x-get-error-text ?d (fact-slot-value ?f error-code)) crlf)

x-pop-error-to-instance

(x-pop-error-to-instance <display> [<name>])  ;; -> <instance-address> | FALSE
Description

Pop the oldest queued X11 error for a Display, build an X-ERROR instance, and return the instance-address.

Arguments
  • <display>: EXTERNAL-ADDRESS to Display*
  • <name>: Optional name of the instance
Return
  • Instance-address of the created X-ERROR instance on success.
  • FALSE if no queue exists for the Display, the queue is empty, or the instance could not be created.
Example
(bind ?d (x-open-display ""))

;; Start once per Display
(x-start-collecting-errors ?d)

;; ... do X calls that may error ...

;; Pop into an instance (auto name)
(bind ?e (x-pop-error-to-instance ?d))
(if (neq ?e FALSE) then
  (printout t
    "X error:"
    " serial="       (send ?e get-serial)
    " code="         (send ?e get-error-code)
    " request="      (send ?e get-request-code)
    " minor="        (send ?e get-minor-code)
    " resourceid="   (send ?e get-resourceid) crlf))

;; Or give it a specific name
(bind ?e2 (x-pop-error-to-instance ?d error-1))

x-stop-collecting-errors

(x-stop-collecting-errors <display>)  ;; -> TRUE | FALSE
Description

Stop collecting X11 errors for a Display and free the per-display error queue.

Arguments
  • <display>: EXTERNAL-ADDRESS to Display*
Return
  • TRUE on success.
  • FALSE if no error queue/context was found for the given Display.
Example
(bind ?d (x-open-display ""))

;; Start collecting first
(x-start-collecting-errors ?d)

;; ... perform X operations ...

;; Stop and free the queue
(if (eq (x-stop-collecting-errors ?d) TRUE)
  then (printout t "Stopped collecting X errors." crlf)
  else (printout t "Nothing to stop for this display." crlf))

x-set-default-error-handler

(x-set-default-error-handler) -> TRUE
Description

Sets the error handler to X11's default. WARNING: will orphan error queues if you've previously created them with x-start-collecting-errors calls.


x-get-error-text

(x-get-error-text <display> <error-code>)  ;; -> <string>
Description

Return a human-readable description for an X11 error code.

Arguments
  • <display> - external-address to an open Display* (from x-open-display).
  • <error-code> - integer X error code (e.g., from x-pop-error, the error-code field).
Return

A string with the error’s textual description (empty string if none is available).

Example
;; Using a code directly
(bind ?d (x-open-display ""))
(printout t (x-get-error-text ?d 3) crlf)  ;; e.g., "BadWindow" on most servers

;; From the error queue
(bind ?e (x-pop-error ?d))
(if ?e then
  (bind ?code (nth$ 2 ?e))                 ;; serial error-code request-code minor-code resourceid
  (printout t "Error: " (x-get-error-text ?d ?code) crlf))

x-get-error-database-text

(x-get-error-database-text <display> <name> <type-int>)  ;; -> <string>
Description

Look up a formatted string from the X error database using a (name, type) key.

Arguments
  • <display> - external-address to an open Display* (from x-open-display).
  • <name> - symbol/string for the database “name” (commonly "XError" or "XRequest").
  • <type-int> - integer key; converted to a string before lookup (e.g., an error code or request code).
Return

A string from the X error database for the given key (empty string if no entry exists).

Example
;; Get human text for an error code using the database
(bind ?d (x-open-display ""))

;; From the error queue (serial error-code request-code minor-code resourceid)
(bind ?e (x-pop-error ?d))
(if ?e then
  (bind ?err (nth$ 2 ?e))
  (bind ?req (nth$ 3 ?e))

  (printout t "DB XError(" ?err "): "
              (x-get-error-database-text ?d "XError" ?err) crlf)

  (printout t "DB XRequest(" ?req "): "
              (x-get-error-database-text ?d "XRequest" ?req) crlf))

;; Direct lookups
(printout t (x-get-error-database-text ?d "XError" 3) crlf)     ;; often "BadWindow"
(printout t (x-get-error-database-text ?d "XRequest" 20) crlf)

error-code-to-symbol

(error-code-to-symbol <code-int>)  ;; -> <symbol> | <void>
Arguments
  • <code-int> - integer X error code (e.g., 1..17 for core protocol).
Return
  • The corresponding symbol (e.g., BadWindow, BadAtom) if the code is recognized.
  • void if the code is invalid; also prints "<code> is not a valid error code" to STDERR.
Examples
(error-code->symbol 3)          ;; => BadWindow
(error-code->symbol 1)          ;; => BadRequest
(bind ?s (error-code->symbol 99))  ;; prints "99 is not a valid error code" and returns void

Logo License Info

This logo was created in GIMP and is based on the CLIPS logo and the X.Org logo (User:Sven CC BY-SA 3.0, via Wikimedia Commons).

About

CLIPS X11 library

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages