Documentation
¶
Overview ¶
Package surface observes the local display, window, accessibility and permission state, and captures a window and sends atomic input to one. Targets are explicitly observed values whose identity is revalidated before an operation; no handle of the native toolkit is exposed. The DesktopDriver interface is the seam that caller-selected tools implement where the OS does not allow a direct implementation (for example Wayland), and the package never selects a driver by name.
Index ¶
- Constants
- Variables
- func Code(err error) string
- func RecordDesktop(ctx context.Context, driver DesktopDriver, options media.RecordingOptions) (media.Recording, error)
- func SendDesktopInput(ctx context.Context, driver DesktopDriver, input SurfaceInput, ...) error
- func SendWindowInput(ctx context.Context, target WindowInfo, input SurfaceInput, ...) error
- type AccessibilityElement
- type AccessibilityOptions
- type AccessibilitySnapshot
- type CaptureOptions
- type DesktopDriver
- type DesktopEndpoint
- type DesktopInfo
- type DisplayInfo
- type InputOptions
- type NativeDesktop
- func (d *NativeDesktop) Capture(ctx context.Context, options CaptureOptions) (SurfaceCapture, error)
- func (d *NativeDesktop) Input(ctx context.Context, input SurfaceInput, options InputOptions) error
- func (d *NativeDesktop) Name() string
- func (d *NativeDesktop) OpenPointerSession(ctx context.Context, options PointerSessionOptions) (*PointerSession, error)
- func (d *NativeDesktop) Record(ctx context.Context, options media.RecordingOptions) (media.Recording, error)
- type NativeDesktopOptions
- type PermissionInfo
- type PermissionSnapshot
- type PointerSession
- type PointerSessionOptions
- type RecordingInfo
- type SurfaceBounds
- type SurfaceCapture
- type SurfaceInput
- type SurfaceInputKind
- type SurfaceOptions
- type SurfacePoint
- type SurfaceSnapshot
- type WindowInfo
Constants ¶
const ( DesktopNative = "desktop.native" DesktopX11 = "desktop.x11" DesktopWayland = "desktop.wayland" DesktopContainer = "desktop.container" DesktopRecording = "desktop.recording" )
Variables ¶
var ( // requested operation in the current session. ErrSurfaceUnavailable = errors.New("surface operation unavailable") // ErrSurfacePermission means the operating system has not granted the // calling process permission for the requested operation. ErrSurfacePermission = errors.New("surface operation permission is not granted") // ErrSurfaceStale means the observed process generation or window no longer // names the same native surface. ErrSurfaceStale = errors.New("surface reference is stale") // ErrSurfaceNotFocused means input could not be safely directed to the // selected surface without affecting another application. ErrSurfaceNotFocused = errors.New("surface is not focused") )
ErrDesktopUnavailable means a selected desktop mechanism cannot perform the requested operation in the current session.
var ErrInvalid = errors.New("invalid surface value")
ErrInvalid reports a snapshot or an option that breaks the rules of testdata/surface/v1.
var ErrInvalidRecording = errors.New("invalid recording options")
ErrInvalidRecording reports malformed recording options.
var ErrPointerSessionClosed = errors.New("pointer session is closed")
ErrPointerSessionClosed means a pointer session has ended, because it was closed, ran out of time or its context ended, and its held buttons have been released.
Functions ¶
func Code ¶ added in v0.4.0
Code is the stable error code of err for another language to match: invalid. It is empty for an error this package does not define.
func RecordDesktop ¶
func RecordDesktop(ctx context.Context, driver DesktopDriver, options media.RecordingOptions) (media.Recording, error)
RecordDesktop starts a bounded recording through the selected driver.
func SendDesktopInput ¶
func SendDesktopInput(ctx context.Context, driver DesktopDriver, input SurfaceInput, options InputOptions) error
SendDesktopInput sends one bounded operation through the selected driver. Drivers that only implement keyboard input must refuse pointer operations explicitly instead of emulating them.
func SendWindowInput ¶
func SendWindowInput(ctx context.Context, target WindowInfo, input SurfaceInput, options InputOptions) error
SendWindowInput sends one bounded operation to a revalidated local window. It does not choose or activate the window, hold input across calls, implement an approval policy, or expose a remote protocol.
Types ¶
type AccessibilityElement ¶
type AccessibilityElement struct {
ID string `json:"id"`
ParentID string `json:"parent_id,omitempty"`
PID int `json:"pid"`
ProcessStartID string `json:"process_start_id"`
Role string `json:"role"`
Identifier string `json:"identifier,omitempty"`
Label string `json:"label,omitempty"`
Value string `json:"value,omitempty"`
Bounds *SurfaceBounds `json:"bounds,omitempty"`
Actions []string `json:"actions,omitempty"`
Enabled *bool `json:"enabled,omitempty"`
Focused *bool `json:"focused,omitempty"`
}
AccessibilityElement is a caller-visible node in the focused application's native accessibility tree. ID and ParentID are opaque snapshot identities; they are not native handles and cannot be used to invoke actions.
type AccessibilityOptions ¶
type AccessibilityOptions struct {
MaxElements int
MaxDepth int
Timeout time.Duration
IncludeText bool
}
AccessibilityOptions bounds traversal. Text is omitted by default because labels and values may contain document or form contents. Every bound is explicit and a zero is invalid, as in the other bindings (testdata/surface/v1); start from DefaultAccessibilityOptions (1024 elements, depth 16, five seconds) and change what differs.
func DefaultAccessibilityOptions ¶ added in v0.5.0
func DefaultAccessibilityOptions() AccessibilityOptions
DefaultAccessibilityOptions returns the default of every limit and the default timeout, without text.
func (AccessibilityOptions) Validate ¶ added in v0.5.0
func (o AccessibilityOptions) Validate() error
Validate checks that the element limit is between 1 and 65536, the depth between 1 and 256, and the timeout positive.
type AccessibilitySnapshot ¶
type AccessibilitySnapshot struct {
Platform string `json:"platform"`
ObservedAt time.Time `json:"observed_at"`
Status proc.CollectionStatus `json:"status"`
Elements []AccessibilityElement `json:"elements"`
}
AccessibilitySnapshot is a bounded, read-only observation of the focused local application's UI tree. It never contains native handles or an action endpoint. Status distinguishes an empty tree from denied or unsupported native observation.
func DiscoverAccessibility ¶
func DiscoverAccessibility(ctx context.Context, options AccessibilityOptions) (AccessibilitySnapshot, error)
DiscoverAccessibility observes the focused local application's native UI structure. It does not request permission, mutate attributes, invoke actions, synthesize input, capture pixels, or communicate with another process over a transport.
func (AccessibilitySnapshot) Validate ¶ added in v0.4.0
func (s AccessibilitySnapshot) Validate() error
Validate checks a snapshot against the rules of testdata/surface/v1: the platform and time are set, the status fits the capability rules, element ids are set and unique, a parent is another element of the snapshot without a cycle, a process is named, a role is set, bounds are positive and action names are not empty.
type CaptureOptions ¶
CaptureOptions bounds native allocation and encoded output. Zero values select 16,777,216 pixels, 16 MiB, and a five-second deadline.
type DesktopDriver ¶
type DesktopDriver interface {
Name() string
Capture(context.Context, CaptureOptions) (SurfaceCapture, error)
Input(context.Context, SurfaceInput, InputOptions) error
Record(context.Context, media.RecordingOptions) (media.Recording, error)
}
DesktopDriver is a caller-selected native desktop mechanism, such as the X11 or Wayland tool adapters. Operations are desktop-scoped because those tools cannot address an observed window; window-scoped capture and input remain in CaptureWindow and SendWindowInput.
It is an interface rather than a registry: the shared library never selects a driver by name or falls back to another one.
type DesktopEndpoint ¶
type DesktopEndpoint struct {
Available bool `json:"available"`
Reason string `json:"reason,omitempty"`
}
DesktopEndpoint is evidence that a local desktop display endpoint is visible to this process. It never contains a socket path, credential, or remote host.
type DesktopInfo ¶
type DesktopInfo struct {
Platform string `json:"platform"`
Interactive bool `json:"interactive"`
Containerized bool `json:"containerized"`
Capabilities []string `json:"capabilities,omitempty"`
X11 DesktopEndpoint `json:"x11"`
Wayland DesktopEndpoint `json:"wayland"`
Recording RecordingInfo `json:"recording"`
Reason string `json:"reason,omitempty"`
ObservedAt time.Time `json:"observed_at"`
}
DesktopInfo is a point-in-time observation of the native desktop visible to the current process. It does not describe a remote display or authorize use.
func DiscoverDesktop ¶
func DiscoverDesktop(ctx context.Context) (DesktopInfo, error)
DiscoverDesktop observes only the local native desktop and its recording prerequisites. It performs no network access and launches no process.
type DisplayInfo ¶
type DisplayInfo struct {
ID string `json:"id"`
Bounds SurfaceBounds `json:"bounds"`
Scale float64 `json:"scale,omitempty"`
Primary bool `json:"primary"`
}
DisplayInfo describes a display visible to the current process. ID is an opaque observation identity, not a native handle.
type InputOptions ¶
InputOptions bounds one atomic native input operation. Zero values select a 4096-rune text ceiling and a five-second deadline.
type NativeDesktop ¶
type NativeDesktop struct {
// contains filtered or unexported fields
}
NativeDesktop is a DesktopDriver for the whole desktop of the current macOS or Windows session. It uses the operating system's own capture and event APIs, not an external tool, so it is a platform implementation of the surface contract and not an adapter.
Desktop coordinates start at the top-left corner of all displays combined, so every position is non-negative and every display is addressable. On macOS one pixel of a capture is one point of input. On Windows coordinates are pixels, and the process should be DPI-aware so that Windows does not scale them.
Recording needs an encoder, which is a tool; the caller supplies one with NativeDesktopOptions.Recorder (adapters/ffmpeg is one). Without it Record is refused.
func NewNativeDesktop ¶
func NewNativeDesktop(options NativeDesktopOptions) (*NativeDesktop, error)
NewNativeDesktop returns the native desktop driver, or an error wrapping ErrDesktopUnavailable where the platform has none (anything but macOS built with cgo, and Windows). The caller selects it explicitly; the library never falls back to it.
func (*NativeDesktop) Capture ¶
func (d *NativeDesktop) Capture(ctx context.Context, options CaptureOptions) (SurfaceCapture, error)
Capture captures every display as one PNG image.
func (*NativeDesktop) Input ¶
func (d *NativeDesktop) Input(ctx context.Context, input SurfaceInput, options InputOptions) error
Input sends one atomic operation to the desktop. Pointer positions must be inside the displays. The driver holds nothing across calls; see OpenPointerSession for held buttons.
func (*NativeDesktop) Name ¶
func (d *NativeDesktop) Name() string
Name identifies the driver for diagnostics: "native-macos" or "native-windows".
func (*NativeDesktop) OpenPointerSession ¶
func (d *NativeDesktop) OpenPointerSession(ctx context.Context, options PointerSessionOptions) (*PointerSession, error)
OpenPointerSession starts a pointer session. It ends when Close is called, when MaxDuration passes or when ctx is done.
func (*NativeDesktop) Record ¶
func (d *NativeDesktop) Record(ctx context.Context, options media.RecordingOptions) (media.Recording, error)
Record starts a recording through the recorder supplied in NativeDesktopOptions.
type NativeDesktopOptions ¶
type NativeDesktopOptions struct {
// Recorder produces recordings for Record. It may be nil.
Recorder media.Recorder
}
NativeDesktopOptions configures NewNativeDesktop.
type PermissionInfo ¶
type PermissionInfo struct {
State string `json:"state"`
// Reason says why something is unsupported or unavailable, from the set every package
// shares (testdata/capability/v1): unsupported, permission, no_device or tool_missing.
Reason string `json:"reason,omitempty"`
Scope string `json:"scope,omitempty"`
Detail string `json:"detail,omitempty"`
}
PermissionInfo reports a native capability's current state without asking for access. State is ready, denied, not-determined, not-required, unsupported, or unavailable. Scope names the OS permission when one exists.
func (PermissionInfo) Validate ¶ added in v0.4.0
func (p PermissionInfo) Validate() error
Validate checks that the state is known and the reason fits it: none for ready, denied, not-determined and not-required, and the capability reasons for unsupported and unavailable.
type PermissionSnapshot ¶
type PermissionSnapshot struct {
Platform string `json:"platform"`
ObservedAt time.Time `json:"observed_at"`
Accessibility PermissionInfo `json:"accessibility"`
ScreenRecording PermissionInfo `json:"screen_recording"`
}
PermissionSnapshot contains local OS permission state relevant to desktop observation. Discovery never opens settings or displays a native prompt.
func DiscoverPermissions ¶
func DiscoverPermissions(ctx context.Context) (PermissionSnapshot, error)
DiscoverPermissions reads current local permission state without requesting access or changing OS settings.
func (PermissionSnapshot) Validate ¶ added in v0.4.0
func (s PermissionSnapshot) Validate() error
Validate checks the platform and time and both permissions.
type PointerSession ¶
type PointerSession struct {
// contains filtered or unexported fields
}
PointerSession holds pointer buttons down across calls, for press-move-release gestures a remote viewer needs. Holding is only possible inside a session so that nothing can leave a button down: Close, the session's time limit and the end of its context all release every held button. A session is safe for concurrent use; calls are serialized.
func (*PointerSession) Close ¶
func (s *PointerSession) Close() error
Close ends the session and releases every held button at the last pointer position. It is safe to call more than once and after the session has ended by itself.
func (*PointerSession) Down ¶
func (s *PointerSession) Down(ctx context.Context, point SurfacePoint, button string) error
Down presses a button at a position and holds it until Up or Close.
func (*PointerSession) Move ¶
func (s *PointerSession) Move(ctx context.Context, point SurfacePoint) error
Move moves the pointer. While a button is held it drags with that button.
func (*PointerSession) Up ¶
func (s *PointerSession) Up(ctx context.Context, point SurfacePoint, button string) error
Up releases a held button at a position.
type PointerSessionOptions ¶
type PointerSessionOptions struct {
// MaxDuration ends the session, releasing held buttons, after this long. Zero selects
// five minutes; the ceiling is one hour.
MaxDuration time.Duration
}
PointerSessionOptions bounds one pointer session.
type RecordingInfo ¶
type RecordingInfo struct {
Status string `json:"status"`
EncoderAvailable bool `json:"encoder_available"`
CaptureAvailable bool `json:"capture_available"`
Permission string `json:"permission"`
Formats []string `json:"formats,omitempty"`
Message string `json:"message,omitempty"`
CheckedAt time.Time `json:"checked_at"`
}
RecordingInfo describes local recording prerequisites. Permission is an identifier for the embedding application to interpret; discovery never opens settings, requests permission, or starts a capture.
type SurfaceBounds ¶
type SurfaceBounds struct {
X int `json:"x"`
Y int `json:"y"`
Width int `json:"width"`
Height int `json:"height"`
}
SurfaceBounds is a rectangle in the snapshot's coordinate space. Width and height are always positive. Coordinates may be negative on multi-display desktops.
func (SurfaceBounds) Validate ¶ added in v0.4.0
func (b SurfaceBounds) Validate() error
Validate checks the bounds: width and height are positive.
type SurfaceCapture ¶
type SurfaceCapture struct {
Format string `json:"format"`
Width int `json:"width"`
Height int `json:"height"`
Data []byte `json:"data"`
CapturedAt time.Time `json:"captured_at"`
}
SurfaceCapture is an encoded image captured from one observed window. Data contains the image bytes directly; transport encodings belong to callers.
func CaptureDesktop ¶
func CaptureDesktop(ctx context.Context, driver DesktopDriver, options CaptureOptions) (SurfaceCapture, error)
CaptureDesktop captures the caller's desktop through an explicitly selected driver. Bounds and result validation are the same as CaptureWindow.
func CaptureWindow ¶
func CaptureWindow(ctx context.Context, target WindowInfo, options CaptureOptions) (SurfaceCapture, error)
CaptureWindow captures a currently observed window after revalidating its opaque ID and process generation. It never prompts for permission, selects a target, persists the image, or applies caller policy.
type SurfaceInput ¶
type SurfaceInput struct {
Kind SurfaceInputKind `json:"kind"`
Point SurfacePoint `json:"point,omitempty"`
End SurfacePoint `json:"end,omitempty"`
Button string `json:"button,omitempty"`
DeltaX int `json:"delta_x,omitempty"`
DeltaY int `json:"delta_y,omitempty"`
Text string `json:"text,omitempty"`
Key string `json:"key,omitempty"`
Modifiers []string `json:"modifiers,omitempty"`
}
SurfaceInput describes one atomic operation. Point is used by pointer operations, End by drag, DeltaX/DeltaY by scroll, Text by keyboard-text, and Key/Modifiers by keyboard-key.
type SurfaceInputKind ¶
type SurfaceInputKind string
SurfaceInputKind identifies one bounded, atomic native input operation.
const ( SurfaceInputMove SurfaceInputKind = "pointer-move" SurfaceInputClick SurfaceInputKind = "pointer-click" SurfaceInputDrag SurfaceInputKind = "pointer-drag" SurfaceInputScroll SurfaceInputKind = "pointer-scroll" SurfaceInputText SurfaceInputKind = "keyboard-text" SurfaceInputKey SurfaceInputKind = "keyboard-key" )
type SurfaceOptions ¶
SurfaceOptions bounds returned metadata and collection time. Every field is explicit and a zero is invalid, as in the other bindings (testdata/surface/v1); start from DefaultSurfaceOptions (64 displays, 4096 windows, five seconds) and change what differs.
func DefaultSurfaceOptions ¶ added in v0.5.0
func DefaultSurfaceOptions() SurfaceOptions
DefaultSurfaceOptions returns the default of every limit and the default timeout.
func (SurfaceOptions) Validate ¶ added in v0.5.0
func (o SurfaceOptions) Validate() error
Validate checks that every limit is between 1 and 65536 and that the timeout is positive.
type SurfacePoint ¶
SurfacePoint uses window-local coordinates in the current window bounds.
type SurfaceSnapshot ¶
type SurfaceSnapshot struct {
Platform string `json:"platform"`
CoordinateSpace string `json:"coordinate_space"`
ObservedAt time.Time `json:"observed_at"`
Displays []DisplayInfo `json:"displays"`
Windows []WindowInfo `json:"windows"`
DisplayStatus proc.CollectionStatus `json:"display_status"`
WindowStatus proc.CollectionStatus `json:"window_status"`
}
SurfaceSnapshot is a bounded, non-atomic observation of local displays and windows. Separate statuses distinguish an empty desktop from unavailable or truncated native data.
func DiscoverSurfaces ¶
func DiscoverSurfaces(ctx context.Context, options SurfaceOptions) (SurfaceSnapshot, error)
DiscoverSurfaces observes local display geometry and caller-visible windows. It does not request permission, capture pixels, read window titles, expose native handles, synthesize input, or contact a remote service.
func (SurfaceSnapshot) Validate ¶ added in v0.4.0
func (s SurfaceSnapshot) Validate() error
Validate checks a snapshot against the rules of testdata/surface/v1: the platform, coordinate space and time are set; display and window ids are set and unique; bounds are positive; a scale is not negative; at most one display is primary; a window has a process; each status fits the capability rules.
type WindowInfo ¶
type WindowInfo struct {
ID string `json:"id"`
PID int `json:"pid"`
ProcessStartID string `json:"process_start_id"`
Bounds SurfaceBounds `json:"bounds"`
OnScreen bool `json:"on_screen"`
}
WindowInfo describes an on-screen top-level window. It intentionally omits titles, application names, native handles, pixels, and input endpoints. ProcessStartID binds PID to a process generation when the OS exposes one.