#window
Xu 0.13.1 API
import: #window
counts: 3 functions, 23 methods, 4 types, 0 constants, 0 method sets
Window lifecycle and event loop
#window provides window lifecycle management and per-window input event queues (keyboard, pointer, wheel, and text/IME). Portable event definitions and constants are provided in the pure Xu package window/events.
Call window.pump() once per update loop, then drain each window via target.poll() until EVENT_NONE. Close requests latch in state().close_requested.
@main
#window
#window/events
fn main() {
options := window.Options{
title: "Hello Window",
width: 640,
height: 360,
resizable: true,
high_pixel_density: true,
hidden: false,
}
$target := window.open(&options) or {
println("Failed to open window")
return
}
println("Window opened: id=", target.id())
window.pump() or >>
state := target.state() or >>
println("Window size:", state.logical_width, "x", state.logical_height)
target.close() or >>
}
Expected output: prints the window ID and logical dimensions.
struct Options
pub struct Options {
pub title string
pub width int
pub height int
pub resizable bool
pub high_pixel_density bool
pub hidden bool
}
Purpose
Window Configuration parameters and options set.
Public fields
title string- field (string)
width int- field (int)
height int- field (int)
resizable bool- field (bool)
high_pixel_density bool- field (bool)
hidden bool- field (bool)
struct Window
Purpose
Window context or state structure.
Public fields
This type has no public fields.
struct State
pub struct State {
pub width int
pub height int
pub pixel_width int
pub pixel_height int
pub close_requested bool
pub minimized bool
pub visible bool
pub focused bool
}
Purpose
Structure encapsulating width, height, pixel_width, pixel_height, close_requested.
Public fields
width int- field (int)
height int- field (int)
pixel_width int- field (int)
pixel_height int- field (int)
close_requested bool- field (bool)
minimized bool- field (bool)
visible bool- field (bool)
focused bool- field (bool)
struct SafeArea
pub struct SafeArea {
pub x int
pub y int
pub width int
pub height int
}
Purpose
Structure encapsulating x, y, width, height.
Public fields
x int- value
y int- value
width int- field (int)
height int- field (int)
open
pub fn open(options &Options) Window
Purpose
Open resource or establish connection. Throws on failure; handle the error or propagate it to the caller.
Parameters
options &Options- options (read-only borrow; caller keeps the original; type &Options)
Returns
Window — a value of this type
(&Window) id
pub fn (window &Window) id() int
Purpose
A process-local, never-reused routing identity; not a native window pointer. Creating presentation targets still requires a typed Window borrow.
Parameters
window &Window- The
Window instance used by this call (borrow).
Returns
int — a value of this type
pump
Purpose
Execute pump. Throws on failure; handle the error or propagate it to the caller.
Parameters
No arguments are required.
Returns
int — a value of this type
live_count
Purpose
Live count. Throws on failure; handle the error or propagate it to the caller.
Parameters
No arguments are required.
Returns
int — a value of this type
(&Window) state
pub fn (window &Window) state() State
Purpose
Execute state on &Window. Throws on failure; handle the error or propagate it to the caller.
Parameters
window &Window- The
Window instance used by this call (borrow).
Returns
State — a value of this type
(&Window) safe_area
pub fn (window &Window) safe_area() SafeArea
Purpose
Operation on &Window: safe area. Throws on failure; handle the error or propagate it to the caller.
Parameters
window &Window- The
Window instance used by this call (borrow).
Returns
SafeArea — a value of this type
(&Window) resize
pub fn (window &Window) resize(width int, height int) int
Purpose
Execute resize on &Window. Throws on failure; handle the error or propagate it to the caller.
Parameters
window &Window- The
Window instance used by this call (borrow).
width int- width (int)
height int- height (int)
Returns
int — a value of this type
(&Window) show
pub fn (window &Window) show() int
Purpose
Execute show on &Window. Throws on failure; handle the error or propagate it to the caller.
Parameters
window &Window- The
Window instance used by this call (borrow).
Returns
int — a value of this type
(&Window) hide
pub fn (window &Window) hide() int
Purpose
Execute hide on &Window. Throws on failure; handle the error or propagate it to the caller.
Parameters
window &Window- The
Window instance used by this call (borrow).
Returns
int — a value of this type
(&Window) minimize
pub fn (window &Window) minimize() int
Purpose
Execute minimize on &Window. Throws on failure; handle the error or propagate it to the caller.
Parameters
window &Window- The
Window instance used by this call (borrow).
Returns
int — a value of this type
(&Window) restore
pub fn (window &Window) restore() int
Purpose
Execute restore on &Window. Throws on failure; handle the error or propagate it to the caller.
Parameters
window &Window- The
Window instance used by this call (borrow).
Returns
int — a value of this type
(&Window) present_rgba
pub fn (window &Window) present_rgba(pixels &[]u8, width int, height int) int
Purpose
Blits a tightly packed RGBA8 framebuffer into the window surface (software present). Throws on failure; handle the error or propagate it to the caller.
Parameters
window &Window- The
Window instance used by this call (borrow).
pixels &[]u8- pixels (read-only borrow; caller keeps the original; type &[]u8)
width int- width (int)
height int- height (int)
Returns
int — a value of this type
($&Window) close
pub fn (window $&Window) close() int
Purpose
Closing the window safely invalidates attached presentation objects first. Throws on failure; handle the error or propagate it to the caller.
Parameters
window $&Window- The
Window instance used by this call (exclusive borrow).
Returns
int — a value of this type
(&Window) poll
pub fn (target &Window) poll() events.Event
Purpose
Drain this window's copied queue; pumping is explicit and process-wide. A failed Xu allocation before event_read leaves the native event queued. Throws on failure; handle the error or propagate it to the caller.
Parameters
target &Window- The
Window instance used by this call (borrow).
Returns
events.Event — a value of this type
(&Window) pending_events
pub fn (target &Window) pending_events() int
Purpose
Operation on &Window: pending events. Throws on failure; handle the error or propagate it to the caller.
Parameters
target &Window- The
Window instance used by this call (borrow).
Returns
int — a value of this type
(&Window) key_down
pub fn (target &Window) key_down(physical_key int) bool
Purpose
Operation on &Window: key down. Throws on failure; handle the error or propagate it to the caller.
Parameters
target &Window- The
Window instance used by this call (borrow).
physical_key int- physical_key (int)
Returns
bool — true or false
(&Window) pointer_state
pub fn (target &Window) pointer_state() events.PointerState
Purpose
Operation on &Window: pointer state. Throws on failure; handle the error or propagate it to the caller.
Parameters
target &Window- The
Window instance used by this call (borrow).
Returns
events.PointerState — a value of this type
(&Window) start_text_input
pub fn (target &Window) start_text_input() int
Purpose
Operation on &Window: start text input. Throws on failure; handle the error or propagate it to the caller.
Parameters
target &Window- The
Window instance used by this call (borrow).
Returns
int — a value of this type
(&Window) stop_text_input
pub fn (target &Window) stop_text_input() int
Purpose
Operation on &Window: stop text input. Throws on failure; handle the error or propagate it to the caller.
Parameters
target &Window- The
Window instance used by this call (borrow).
Returns
int — a value of this type
(&Window) text_input_active
pub fn (target &Window) text_input_active() bool
Purpose
Operation on &Window: text input active. Throws on failure; handle the error or propagate it to the caller.
Parameters
target &Window- The
Window instance used by this call (borrow).
Returns
bool — true or false
(&Window) text_input_area
pub fn (target &Window) text_input_area(x int, y int, width int, height int, cursor int) int
Purpose
Logical window coordinates. Cursor is an offset inside the positive-width area. Throws on failure; handle the error or propagate it to the caller.
Parameters
target &Window- The
Window instance used by this call (borrow).
x int- value (int)
y int- value (int)
width int- width (int)
height int- height (int)
cursor int- cursor (int)
Returns
int — a value of this type
(&Window) clear_text_input_area
pub fn (target &Window) clear_text_input_area() int
Purpose
Operation on &Window: clear text input area. Throws on failure; handle the error or propagate it to the caller.
Parameters
target &Window- The
Window instance used by this call (borrow).
Returns
int — a value of this type
(&Window) set_relative_pointer
pub fn (target &Window) set_relative_pointer(enabled bool) int
Purpose
Operation on &Window: set relative pointer. Throws on failure; handle the error or propagate it to the caller.
Parameters
target &Window- The
Window instance used by this call (borrow).
enabled bool- enabled (bool)
Returns
int — a value of this type
(&Window) relative_pointer
pub fn (target &Window) relative_pointer() bool
Purpose
Operation on &Window: relative pointer. Throws on failure; handle the error or propagate it to the caller.
Parameters
target &Window- The
Window instance used by this call (borrow).
Returns
bool — true or false
(&Window) set_pointer_grab
pub fn (target &Window) set_pointer_grab(enabled bool) int
Purpose
Operation on &Window: set pointer grab. Throws on failure; handle the error or propagate it to the caller.
Parameters
target &Window- The
Window instance used by this call (borrow).
enabled bool- enabled (bool)
Returns
int — a value of this type
(&Window) pointer_grab
pub fn (target &Window) pointer_grab() bool
Purpose
Operation on &Window: pointer grab. Throws on failure; handle the error or propagate it to the caller.
Parameters
target &Window- The
Window instance used by this call (borrow).
Returns
bool — true or false