Documentation
¶
Overview ¶
Package platform owns the operating system: windows, the event queue, keyboard and mouse input, display scaling, window visibility, the clipboard and Vulkan surface creation.
Each operating system has its own implementation of App and Window in a build-tagged file with an identical method set, so the rest of the engine compiles against one API and the linker picks the platform. Events are translated into the platform-independent Event type here; nothing above this package sees a native handle.
All calls must happen on the main goroutine, which the package pins to the main OS thread in init, because window systems require it.
Index ¶
- Variables
- func Backend() string
- func RequiredInstanceExtensions() []string
- type App
- func (a *App) Clipboard() (string, error)
- func (a *App) Displays() ([]Display, error)
- func (a *App) Gamepads() []GamepadState
- func (a *App) KeyboardLayout() (input.KeyboardLayout, error)
- func (a *App) NewWindow(cfg Config) (*Window, error)
- func (a *App) Poll(wait bool) []Event
- func (a *App) PollTimeout(timeout time.Duration) []Event
- func (a *App) SetClipboard(text string) error
- func (a *App) Wake()
- type Config
- type CursorShape
- type Display
- type Event
- type EventKind
- type GamepadState
- type Key
- type Mods
- type MouseButton
- type NativeParent
- type VideoMode
- type Window
- func (w *Window) Capabilities() WindowCapabilities
- func (w *Window) Close()
- func (w *Window) Closed() bool
- func (w *Window) CreateSurface(instance vk.VkInstance) (vk.VkSurfaceKHR, error)
- func (w *Window) CursorCaptured() bool
- func (w *Window) Fullscreen() bool
- func (w *Window) Hide() error
- func (w *Window) PixelSize() (int, int)
- func (w *Window) Position() (int, int)
- func (w *Window) RefreshCursor()
- func (w *Window) RequestFocus() error
- func (w *Window) Scale() float64
- func (w *Window) SetAlwaysOnTop(on bool) error
- func (w *Window) SetBounds(x, y, width, height int) error
- func (w *Window) SetCursor(shape CursorShape)
- func (w *Window) SetCursorCaptured(on bool)
- func (w *Window) SetCursorImage(img image.Image, hotX, hotY int) error
- func (w *Window) SetCursorVisible(on bool)
- func (w *Window) SetFullscreen(on bool)
- func (w *Window) SetIcon(img image.Image)
- func (w *Window) SetPointerPosition(x, y float64) error
- func (w *Window) SetPosition(x, y int)
- func (w *Window) SetSize(width, height int) error
- func (w *Window) SetSizeLimits(minW, minH, maxW, maxH int)
- func (w *Window) SetTextInputRect(x, y, width, height float64)
- func (w *Window) SetTitle(title string)
- func (w *Window) Show() error
- func (w *Window) Size() (int, int)
- func (w *Window) Visible() bool
- type WindowCapabilities
Constants ¶
This section is empty.
Variables ¶
var ErrNoClipboard = errors.New("platform: clipboard is not available on this platform")
ErrNoClipboard is returned where the platform layer has no clipboard.
var ErrNoInputYet = errors.New("platform: the Wayland clipboard cannot be set before the window has had input")
ErrNoInputYet is returned when the Wayland clipboard is written before the window has had any input. Changing the selection quotes the serial of a key, a button or a pointer or keyboard entering the window, and until one of those has happened there is no serial to quote.
var ErrNoWayland = errors.New("platform: cannot connect to a Wayland compositor")
ErrNoWayland is returned when no Wayland compositor can be reached.
var ErrNoX11 = errors.New("platform: cannot connect to an X server (is DISPLAY set?)")
ErrNoX11 is returned when no X server can be reached.
var ErrUnsupported = errors.New("platform: operation unsupported by this backend")
ErrUnsupported identifies an operation unavailable in the active backend.
Functions ¶
func Backend ¶
func Backend() string
Backend names the window system the layer opened: "wayland" or "x11" on Linux, and the operating system's name elsewhere. The engine logs it at startup, because which one a Linux session got is not otherwise visible.
func RequiredInstanceExtensions ¶
func RequiredInstanceExtensions() []string
RequiredInstanceExtensions lists the instance extensions a surface needs. The backend NewApp chose decides which one: VK_KHR_wayland_surface under Wayland and VK_KHR_xcb_surface under X11.
Types ¶
type App ¶
type App struct {
// contains filtered or unexported fields
}
App is the process's connection to the window system. Create one per process.
func (*App) Clipboard ¶
Clipboard returns the system clipboard's text, empty when it holds none. Under X11 it asks whoever owns the CLIPBOARD selection and waits about a second for the answer, and under Wayland it reads the offer the compositor gave the seat. Text this process put there is returned without asking anyone. It fails only where the window system has no clipboard for a client with no window, or where the compositor has no wl_data_device_manager.
func (*App) Displays ¶
Displays uses wl_output's advertised modes on Wayland and active RandR outputs on X11. wl_output geometry does not define reliable logical bounds, so Wayland leaves BoundsKnown false instead of guessing from pixel size.
func (*App) Gamepads ¶
func (a *App) Gamepads() []GamepadState
Gamepads reads every joystick device that can be opened. The slice it returns is reused by the next call, so read it before polling again.
func (*App) KeyboardLayout ¶
func (a *App) KeyboardLayout() (input.KeyboardLayout, error)
func (*App) Poll ¶
Poll drains pending events into the returned slice, reused by the next call. With wait set it blocks until at least one event arrives.
func (*App) PollTimeout ¶
PollTimeout is Poll that waits at most timeout for the first event. A timeout of zero or less waits for nothing, as Poll(false) does.
func (*App) SetClipboard ¶
SetClipboard puts text on the system clipboard. Both backends hand the text over when another client asks for it, so it stays available for as long as this process owns the selection and no longer. Under Wayland it returns ErrNoInputYet before the window has had any input, because changing the selection quotes the serial of an input event.
type Config ¶
type Config struct {
Parent *NativeParent
Title string
Width int // content size in points (logical pixels)
Height int
Resizable bool
}
Config describes a window to open.
type CursorShape ¶
type CursorShape uint8
CursorShape names a system cursor.
const ( CursorArrow CursorShape = iota CursorHand CursorIBeam CursorCrosshair CursorResizeH CursorResizeV CursorGrab CursorGrabbing CursorNotAllowed )
type Display ¶
type Display struct {
Name string
Bounds image.Rectangle
BoundsKnown bool
Scale float64
Current VideoMode
Modes []VideoMode
}
Display describes an attached display. Bounds is in the backend's desktop coordinate space, with a top-left origin, and is valid only when BoundsKnown. Scale is logical-to-physical scaling, or zero when unknown. Modes contains only advertised modes, which may be limited to the current mode by the OS. Names and ordering are snapshots, not persistent device identifiers.
type Event ¶
type Event struct {
Kind EventKind
Window *Window
Key Key
Mods Mods
Repeat bool
Rune rune
Text string
Button MouseButton
X, Y float64
DX, DY float64
Precise bool
Focused bool
Visible bool
Width int // content size in points
Height int
PixelW int // framebuffer size in pixels
PixelH int
Scale float64
}
Event is one thing that happened to a window. Only the fields relevant to Kind are set.
type EventKind ¶
type EventKind uint8
EventKind says what an Event carries.
const ( EventNone EventKind = iota EventClose // the user asked the window to close EventResize // content or framebuffer size, or scale, changed EventFocus // Focused says whether the window gained or lost focus EventKeyDown // Key, Mods, Repeat EventKeyUp // Key, Mods EventChar // Rune: a character of text input EventCompose // Text: the input method's in-progress composition, empty when it ends EventMouseMove // X, Y in points from the top-left of the content area EventMouseDown // Button, X, Y, Mods EventMouseUp // Button, X, Y, Mods EventScroll // DX, DY in lines (or points when Precise) EventMouseEnter // the pointer entered the content area EventMouseLeave // the pointer left the content area EventWake // App.Wake was called from another goroutine EventVisible // Visible says whether the window became visible or hidden EventModifiers // Mods: modifier state changed independently of a key event )
type GamepadState ¶
type GamepadState struct {
Info input.GamepadInfo
Connected bool
Name string
Buttons [input.GamepadButtonCount]bool
Axes [input.GamepadAxisCount]float32
}
GamepadState is one controller's inputs as read this poll.
type Key ¶
The input vocabulary is re-exported so that this package's events can be read without importing input as well.
type Mods ¶
The input vocabulary is re-exported so that this package's events can be read without importing input as well.
type MouseButton ¶
type MouseButton = input.MouseButton
The input vocabulary is re-exported so that this package's events can be read without importing input as well.
type NativeParent ¶
NativeParent borrows a parent; backend values match the root NativeBackend.
type VideoMode ¶
VideoMode describes a mode reported by the display system. Dimensions are physical pixels; RefreshHz is zero when the system does not report a rate.
type Window ¶
type Window struct {
// contains filtered or unexported fields
}
Window is one window. Only the fields of the live backend are set.
func (*Window) Capabilities ¶
func (w *Window) Capabilities() WindowCapabilities
func (*Window) CreateSurface ¶
func (w *Window) CreateSurface(instance vk.VkInstance) (vk.VkSurfaceKHR, error)
CreateSurface makes a VkSurfaceKHR over the window. Under Wayland the swapchain's size comes from the last xdg_toplevel.configure, because the compositor does not resize a surface: the client picks the buffer size and the configure says what it should be.
func (*Window) CursorCaptured ¶
CursorCaptured reports the capture state.
func (*Window) Fullscreen ¶
Fullscreen reports whether the window is full screen.
func (*Window) PixelSize ¶
PixelSize is the framebuffer size. X11 reports no scale, so it matches Size there; Wayland multiplies by the fractional scale where the compositor sends one and by the integer buffer scale otherwise.
func (*Window) RefreshCursor ¶
func (w *Window) RefreshCursor()
func (*Window) RequestFocus ¶
func (*Window) Scale ¶
Scale is pixels per point. It is fractional under a compositor that offers wp_fractional_scale_v1 and a whole number everywhere else.
func (*Window) SetAlwaysOnTop ¶
func (*Window) SetCursor ¶
func (w *Window) SetCursor(shape CursorShape)
SetCursor picks the pointer's shape, from the cursor theme under Wayland and from the X cursor font under X11.
func (*Window) SetCursorCaptured ¶
SetCursorCaptured hides the cursor, holds it in the window and reports motion as deltas.
func (*Window) SetCursorImage ¶
func (*Window) SetCursorVisible ¶
SetCursorVisible shows or hides the pointer over the window.
func (*Window) SetFullscreen ¶
SetFullscreen asks the compositor or the window manager for full screen. Under Wayland the answer arrives as a configure, so Fullscreen only changes once the compositor agrees.
func (*Window) SetIcon ¶
SetIcon sets _NET_WM_ICON under X11: width, height and ARGB pixels as cardinals. Under Wayland it sends the pixels through xdg-toplevel-icon-v1, and does nothing where the compositor lacks that protocol, because the icon then comes from the desktop entry whose name matches the app id.
func (*Window) SetPointerPosition ¶
func (*Window) SetPosition ¶
Window placement is controlled by the compositor or window manager. The engine does not request or report absolute placement on Linux.
func (*Window) SetSizeLimits ¶
SetSizeLimits bounds the content size, through xdg_toplevel.set_min_size and set_max_size under Wayland and WM_NORMAL_HINTS under X11; zero lifts a bound.
func (*Window) SetTextInputRect ¶
SetTextInputRect records where text is entered. Neither backend wires an input method yet, so it only stores the rectangle.
func (*Window) SetTitle ¶
SetTitle changes the window's title, through xdg_toplevel.set_title under Wayland and WM_NAME and _NET_WM_NAME under X11.
func (*Window) Visible ¶
Visible reports whether the window can be seen. It is false while the window is minimised, unmapped or wholly covered by other windows. X11 reads MapNotify, VisibilityNotify and _NET_WM_STATE_HIDDEN; Wayland reads the suspended state of xdg_toplevel version six, so a compositor that offers an earlier version always reports true.
type WindowCapabilities ¶
type WindowCapabilities struct {
Resize, Show, Hide, Focus, AlwaysOnTop, CursorImage, PointerPosition bool
EmbeddedBounds bool
}
WindowCapabilities reports requests the active backend can issue. A supported request can still be declined by desktop policy or fail at runtime.
Source Files
¶
- alias.go
- app_linux.go
- control_linux.go
- displays_linux.go
- embedding.go
- embedding_linux.go
- embedding_watch_linux.go
- gamepad_info_linux.go
- gamepad_linux.go
- keyboard.go
- keyboard_linux.go
- keyboard_symbols_unix.go
- keys_linux.go
- platform.go
- raw_mouse.go
- surface_linux.go
- wayland_linux.go
- wayland_listen_linux.go
- wayland_proto_linux.go
- window_controls.go
- window_controls_linux.go
- x11_linux.go