x-lang

← Index

x/sys/linux

A window on the Linux console that answers Sdl’s messages: the picture on the framebuffer, keys from the kernel’s input devices, sound through ALSA’s playback device, all by syscalls.

Class Linux

A window on the Linux console: Sdl’s messages answered by the framebuffer, the kernel’s input devices and ALSA’s playback device, through syscalls alone.

open uses /dev/fb0 and its geometry in /sys/class/graphics/fb0, every /dev/input/event*, /dev/snd/pcmC0D0p for sound and /dev/tty0 for the console, unless devices! names others.

%window-cell

Static field: data held by Linux itself, not by its instances.

%device-cell

Static field: data held by Linux itself, not by its instances.

%sound-cell

Static field: data held by Linux itself, not by its instances.

(Linux devices! fb sysfs input pcm console)

Name the devices the next open and the first stream use.

Parameters:

Returns: STRING — The framebuffer’s device

Examples:

(Linux devices! "/dev/fb0" "/sys/class/graphics/fb0" "/dev/input" "/dev/snd/pcmC0D0p" "/dev/tty0") => "/dev/fb0"

(Linux %device k)

A device devices! named.

Parameters:

Returns: STRING — Its path

(Linux available?)

Whether a Linux window can be opened: the framebuffer is there.

Returns: BOOL — #t when it is

(Linux keys)

Keycodes by name for keys that are not printable characters: Sdl’s, as the window reports SDL’s keycodes.

Returns: LIST — ((name . keycode) …)

Examples:

(first (Linux keys)) => ('up . 1073741906)

(Linux key name)

The keycode the window reports for a named key.

Parameters:

Returns: INTEGER — SDL’s keycode

Examples:

(Linux key (lit escape)) => 27

(Linux buttons)

Gamepad button names, as Sdl’s; no gamepad is read.

Returns: LIST — Button names

Examples:

(first (Linux buttons)) => 'south

(Linux axes)

Gamepad axis names, as Sdl’s; no gamepad is read.

Returns: LIST — Axis names

Examples:

(first (Linux axes)) => 'left-x

(Linux error)

The last error message: always empty, as Linux raises its errors.

Returns: STRING — “”

Examples:

(Linux error) => ""

(Linux jit!)

Build and adopt the compiled loops (JIT; ARM64 and x86-64 backends) now, if they agree with the pure-x loops. Idempotent. Answers #t when they are in use: the pure-x loops draw the same frames and mix the same sound, but a frame takes seconds.

Returns: BOOL — #t when the compiled loops are in use

(Linux %ioctl fd request arg)

ioctl(2) as a syscall, sign-folded.

Parameters:

Returns: INTEGER — 0 or more, or negative on error

(Linux %mode names)

The open flags named, OR’d.

Parameters:

Returns: INTEGER — The flags

(Linux %field field)

The slot that holds a field of the window.

Parameters:

Returns: INTEGER — The slot

Examples:

(Linux %field (lit frame)) => 7

(Linux %ref win field)

A field of the window.

Parameters:

Returns: ANY — Its value

(Linux %set! win field v)

Set a field of the window.

Parameters:

Returns: ANY — v

(Linux %window)

The window open, or nil.

Returns: ANY — The window

(Linux %numbers path)

The numbers in a file, split at commas and white space.

Parameters:

Returns: LIST — The numbers

(Linux open title w h scale)

Take the screen and the keyboard for a w x h RGBA picture, scaled to the screen by whole multiples with nearest-pixel sampling. The framebuffer must be 32 bits a pixel.

Parameters:

Returns: VECTOR — The window

(Linux %open-inputs)

Every event device in the input directory, opened without blocking and grabbed from the console; those that will not open are left out.

Returns: LIST — Their descriptors

(Linux %graphics!)

The console put in graphics mode, so the kernel draws nothing on the screen.

Returns: INTEGER — The console’s descriptor, or -1 when there is none

(Linux scaling! win mode)

Set how the picture is scaled to the screen: by whole multiples, or as large as fits.

Parameters:

Returns: VECTOR — The window

(Linux place win)

Where the picture lies on the screen: its left and top, and its width and height there.

Parameters:

Returns: LIST — (X Y W H) in the screen’s pixels

(Linux %clear! win)

The whole screen black, ready for the picture.

Parameters:

Returns: ANY — nil

(Linux canvas win)

A zeroed RGBA buffer the size of the window’s picture: transparent black.

Parameters:

Returns: STRING — A region of wh4 bytes

(Linux draw! win buf)

Keep the buffer as the frame; nothing reaches the screen until present!.

Parameters:

Returns: VECTOR — The window

(Linux present! win)

Write the frame drawn last to the screen, scaled into its place there: each of the picture’s rows is converted once and copied for the screen rows it fills, and the whole screen, its black bars too, goes to the framebuffer in one write, so nothing the console drew outlives a frame.

Parameters:

Returns: VECTOR — The window

(Linux show! win buf)

Draw the buffer and write it to the screen.

Parameters:

Returns: VECTOR — The window

(Linux read-pixels win)

The frame drawn last, as an RGBA buffer; nil before any.

Parameters:

Returns: ANY — A region of wh4 bytes, or nil

(Linux fullscreen! win on)

Taken for Sdl’s sake: the window has the whole screen either way.

Parameters:

Returns: VECTOR — The window

(Linux %read-inputs! win)

Read what the input devices have, without waiting, and queue its keys as events.

Parameters:

Returns: ANY — nil

(Linux %events! win buf n)

Queue the key events among the first n bytes of buf: a press as key-down, a repeat as key-down repeating, a release as key-up, with the modifiers held.

Parameters:

Returns: ANY — nil

(Linux %key-event! win code value)

Queue one key’s event, its modifiers counted first; a key with no SDL keycode is not queued.

Parameters:

Returns: ANY — nil

(Linux %keycode code)

The SDL keycode of a Linux key number, as a US keyboard has it.

Parameters:

Returns: INTEGER|NIL — The keycode, or nil for a key with none

Examples:

(Linux %keycode 103) => 1073741906

(Linux %queue! win event)

Put an event at the end of the queue poll answers from.

Parameters:

Returns: ANY — nil

(Linux poll)

The next event from the keyboard, or nil; the same events as Sdl’s poll answers.

Returns: ANY — An event list, or nil

(Linux post-key! code)

Queue a key-down event, as a key pressed would be.

Parameters:

Returns: INTEGER — The code

(Linux close win)

Give the console back in text mode and the keyboard back to it, black the screen and close the devices.

Parameters:

Returns: ANY — nil

(Linux %sound)

The sound device open, or nil.

Returns: ANY — The sound

(Linux %hw-params rate chans)

A snd_pcm_hw_params asking for interleaved signed 16-bit little-endian frames at the rate and channels, a buffer of a tenth to a quarter of a second, and any period the device likes.

Parameters:

Returns: STRING — The struct, for SNDRV_PCM_IOCTL_HW_PARAMS

(Linux %open-sound rate chans)

The playback device opened without blocking, set to the rate and channels and prepared.

Parameters:

Returns: VECTOR — The sound

(Linux %delay snd)

The frames written to the device and not yet played; a device that ran dry is prepared again, with nothing in it.

Parameters:

Returns: INTEGER — Frames

(Linux %pump!)

Mix what the streams have waiting into the room the device has, and write it.

Returns: ANY — nil

(Linux %take! s acc n until)

Add up to n of the stream’s bytes waiting into the mix, and drop them from it.

Parameters:

Returns: ANY — nil

(Linux audio-open rate chans)

Open a stream of signed 16-bit frames. The first opens the playback device at its rate and channels; every stream after must have the same.

Parameters:

Returns: VECTOR — The stream

(Linux audio-put! s buf n)

Queue n bytes of buf to play after what the stream has queued; they are copied, so buf may be used again.

Parameters:

Returns: BOOL — #t

(Linux audio-queued s)

Bytes the stream has queued and not yet played: those waiting to be mixed, and those mixed and still in the device.

Parameters:

Returns: INTEGER — Bytes

(Linux audio-clear! s)

Drop what the stream has waiting to be mixed; what is in the device plays out.

Parameters:

Returns: BOOL — #t

(Linux audio-close s)

Release the stream. When the last is gone the device is stopped and closed.

Parameters:

Returns: ANY — nil