Skip to content

Wayland ​

Toolkit windows and surfaces are in lys-ui. These packages need no toolkit. The keyboard model is on its own page.

capture ​

capture copies screen contents on a private Wayland connection, independent of the application's own event loop.

go
package main

import (
	"image/png"
	"log"
	"os"

	"github.com/stubbedev/lys/lib/capture"
)

func main() {
	client, err := capture.Connect()
	if err != nil {
		log.Fatal(err)
	}
	defer client.Close()

	outputs := client.Outputs()
	if len(outputs) == 0 {
		log.Fatal("the compositor lists no outputs")
	}
	frame, err := client.CaptureOutput(outputs[0], capture.Options{Cursor: true})
	if err != nil {
		log.Fatal(err)
	}
	img, err := frame.Image()
	if err != nil {
		log.Fatal(err)
	}
	out, err := os.Create("screen.png")
	if err != nil {
		log.Fatal(err)
	}
	defer out.Close()
	if err := png.Encode(out, img); err != nil {
		log.Fatal(err)
	}
}
  • Capture calls block until the compositor finishes the copy; keep them off the UI goroutine.
  • A Client is safe for concurrent use, but its calls serialize. Use separate clients for overlapping captures.
  • Connect (or ConnectTo with a socket) succeeds on any compositor. The Has* methods report what is offered; a capture whose protocol is missing fails with ErrUnsupported.
CaptureAPIProtocol
Output or region, to memoryCaptureOutput, CaptureOutputRegionwlr-screencopy
One output frame, to memoryCaptureOutputOnceext-image-copy-capture
Window, to memoryToplevels, CaptureToplevelext-foreign-toplevel-list, ext-image-copy-capture
Window on HyprlandCaptureHyprlandWindowhyprland-toplevel-export
Compositor's cast targetCaptureDynamic, Dynamiclys-dynamic-capture
Output, continuous and damage-drivenOpenOutputStreamext-image-copy-capture
Output or region, to a dmabufImportDmabuf, DmabufFormat, CaptureOutputDmabuf, CopyOutputDmabuf, CopyOutputRegionDmabufwlr-screencopy, linux-dmabuf
Output, window or cast target, to a dmabuf, as a sessionOpenDmabufSessionext-image-copy-capture, linux-dmabuf
Pointer position and imageOpenOutputCursor, OpenToplevelCursor, OpenDynamicCursorext-image-copy-capture
  • The dmabuf paths avoid shared-memory copies; dmabufprobe picks the modifier.
  • A window takes one session per Client. While a DmabufSession is open on it, CaptureToplevel and another OpenDmabufSession fail with ErrToplevelBusy. Dynamic sessions may overlap; a size change reports ErrReconfigured.
  • Frame.Image converts the 8-bit and 10-bit packed formats to image.RGBA.

Options:

FieldEffect
CursorComposite the pointer into the frame
IntentScreencast (default) or Screenshot; Screenshot is declared through lys-capture-hint so the compositor may show surfaces it hides from screen sharing
DstReuse this buffer for the frame's pixels when large enough
AwaitDamageWait for the source to change and report the damage in Frame.Damage

Streams and dmabuf sessions track per-buffer damage and ask the compositor to copy only what changed since that buffer was last filled.

vinput, keymapfd ​

vinput injects input on a private connection through zwlr_virtual_pointer_v1, zwp_virtual_keyboard_v1 and lys_virtual_touch_v1.

go
package main

import (
	"log"

	"github.com/stubbedev/lys/lib/vinput"
)

const btnLeft = 0x110

func main() {
	dev, err := vinput.Dial("", vinput.Options{Keyboard: true})
	if err != nil {
		log.Fatal(err)
	}
	defer dev.Close()

	if err := dev.Motion(10, 0); err != nil {
		log.Fatal(err)
	}
	if err := dev.Button(btnLeft, true); err != nil {
		log.Fatal(err)
	}
	if err := dev.Button(btnLeft, false); err != nil {
		log.Fatal(err)
	}
	if err := dev.Roundtrip(); err != nil {
		log.Fatal(err)
	}
}

Dial takes an absolute socket path, a name inside XDG_RUNTIME_DIR, or "" for WAYLAND_DISPLAY. A Device is safe to use from any goroutine.

OptionEffect
KeyboardAlso create a virtual keyboard. The seat's keymap is relayed to it, so key codes match the real keyboard
TouchAlso create a touchscreen spanning the output layout; needs lys_virtual_touch_manager_v1 (TouchAvailable checks, ErrNoTouch otherwise)
FallbackKeymapxkb_v1 keymap used when the seat announces none, such as on a headless compositor
Keymapxkb_v1 keymap the keyboard carries instead of the seat's; overrides FallbackKeymap

keymapfd.Read reads the keymap a wl_keyboard.keymap event carries. It maps the fd and never calls read(), which would move a shared memfd's offset for every client holding it.

wlr ​

wlr holds generated bindings for protocols beyond the core and xdg-shell, in one package. The XML lives beside the code; just generate regenerates it with third_party/wayland/cmd/wayland-scanner.

AreaProtocols
Shell and windowswlr-layer-shell, ext-session-lock, wlr-foreign-toplevel-management, ext-foreign-toplevel-list, xdg-activation, xdg-dialog, xdg-foreign, xdg-output, xdg-system-bell, xdg-toplevel-icon
Outputswlr-output-management, wlr-output-power-management
Capturewlr-screencopy, ext-image-capture-source, ext-image-copy-capture, hyprland-toplevel-export, lys-capture-hint, lys-dynamic-capture
Buffers and presentationlinux-dmabuf, linux-drm-syncobj, viewporter, fractional-scale, presentation-time, alpha-modifier, color-representation, content-type, ext-background-effect
Inputpointer-constraints, pointer-gestures, relative-pointer, tablet, cursor-shape, keyboard-shortcuts-inhibit, hyprland-global-shortcuts, xx-hotkey, zwlr-virtual-pointer, zwp-virtual-keyboard, lys-virtual-touch, lys-escape
Clipboardext-data-control, wlr-data-control, primary-selection
Sessionext-idle-notify, idle-inhibit, wlr-gamma-control, hyprland-ctm-control

The core protocol and xdg-shell come from third_party/wayland as wl and xdg, with the client helper wlclient and the text-input-v3 and xdg-decoration-v1 bindings under unstable.

xcursor ​

xcursor reads Xcursor files and resolves themes through XCURSOR_PATH (SearchPath), Inherits and nominal sizes. Malformed files are an error.

APIReturns
OpenA Theme
NearestThe image nearest a size, reading only that image
Widest, ReadWidestThe widest image
NearestFrames, Theme.FramesAn animated cursor's frames at one size
BuiltinA built-in arrow for systems without a theme
Shapescursor-shape-v1 shapes in protocol order, with their Xcursor names
NamesXcursor names to try for a CSS cursor name, best first

Image.Pixels holds the pixels as the file stores them, which is wl_shmargb8888.

Released under the MIT License.