gui.window
Native windows that show a pixel buffer, with an event loop for pointer, keyboard, text input, timers and the clipboard.
import gui.window
gui.window opens real windows and shows pixels you draw yourself. It is the bottom layer of Salam's native user interface: the program renders a frame into memory (for example with gui.paint), and this package puts it on the screen and reports what the user does. It talks to the system directly: X11 on Linux, Win32 on Windows and Cocoa on macOS, with no GTK, no web view and no other library. A headless backend keeps windows in memory, so the same program can be tested on any machine.
A frame is a buffer of 32-bit pixels, premultiplied alpha, with the value 0xAARRGGBB (bytes B, G, R, A in memory), described by a pointer, a width, a height and a stride. Sizes and positions in the API are logical pixels; the buffer is in physical pixels, which is the logical size times ScaleFactor.
- Events are pulled, not pushed: call
Waitin a loop. This is what macOS needs, since its windows only work on the main thread. - Closing is a request. The close button sends
CloseRequested, and the window stays until you callClose. - Redraw requests merge. Call
RequestRedrawas often as you like; oneRedrawRequestedarrives. - Keys and text are separate.
KeyDownnames the key by its position, the same on every keyboard language; the characters come inTextInputand, from an input method, inImePreeditandImeCommit.
The text of an event belongs to the package and is freed at the next Wait or Poll. Clone it with str.Clone if you keep it.
The event loop
A window program opens a window, then waits for events until it closes. RedrawRequested asks for a frame: allocate a buffer of the physical size, fill it and give it to PresentAll. A repeating timer drives anything that changes over time. This example is headless and uses the test clock, so it runs anywhere and prints the same lines every time; drop headless and SetManualClock and the same loop drives a real window.
import gui.window
import mem
func paint(w: window.Window, frame: int):
size := w.Size()
width := size.physical_width
height := size.physical_height
pixels := mem.AllocateZeroed(((width * height) * 4) as u64) as u32*
defer mem.Free(pixels as void*)
shade := (frame * 40) as u32
repeat width * height in i:
pixels[i] = (0xFF000000 as u32) | (shade << 8)
end
w.PresentAll(pixels as void*, width, height, width * 4)
end
func main:
window.SetManualClock(true)
w := window.Open(window.Options { title = "Clock", width = 64.0, height = 48.0, headless = true })
tick := window.SetTimer(500, true)
mut frames := 0
until w.IsOpen():
e := window.Wait(-1)
switch e.kind:
window.EventKind.RedrawRequested:
paint(w, frames)
frames++
println "frame", frames, "at", window.Clock(), "ms"
break
end
window.EventKind.Timer:
w.RequestRedraw()
if frames == 3:
window.Inject(window.Event { kind = window.EventKind.CloseRequested, window = w.id })
end
break
end
window.EventKind.CloseRequested:
println "closing"
window.ClearTimer(tick)
w.Close()
break
end
else:
break
end
end
end
println "presented", w.PresentCount(), "frames"
endMouse, keys and text
Pointer events carry logical coordinates and the button. clicks counts a double or triple click: presses of the same button close together in time and place. A key event names the key with Key, by position, and the system's own key code in code. Text never comes from key events: insert the text of TextInput and ImeCommit, and draw ImePreedit as the composition underline. SetImeRect places the input method's candidate window at your caret.
import gui.window
func main:
window.SetManualClock(true)
w := window.Open(window.Options { width = 300.0, height = 200.0, headless = true, visible = false })
window.Inject(window.Event { kind = window.EventKind.PointerDown, window = w.id, x = 40.0, y = 30.0, button = window.MouseButton.Left })
window.Advance(120)
window.Inject(window.Event { kind = window.EventKind.PointerDown, window = w.id, x = 41.0, y = 30.0, button = window.MouseButton.Left })
window.Inject(window.Event { kind = window.EventKind.KeyDown, window = w.id, key = window.Key.A, code = 38 })
window.Inject(window.Event { kind = window.EventKind.TextInput, window = w.id, text = "a" })
window.Inject(window.Event { kind = window.EventKind.ImePreedit, window = w.id, text = "سل", cursor = 4 })
window.Inject(window.Event { kind = window.EventKind.ImeCommit, window = w.id, text = "سلام" })
mut e := window.Poll()
until e.kind != window.EventKind.None:
switch e.kind:
window.EventKind.PointerDown:
println "click", e.clicks, "at", e.x, e.y
break
end
window.EventKind.KeyDown:
println "key A:", e.key == window.Key.A
break
end
window.EventKind.TextInput, window.EventKind.ImeCommit:
println "insert", e.text
break
end
window.EventKind.ImePreedit:
println "composing", e.text, "caret at byte", e.cursor
break
end
else:
break
end
end
e = window.Poll()
end
w.SetImeRect(40.0, 30.0, 2.0, 18.0)
println "candidate window goes to", w.ImeRect()
endScale factor and partial updates
On a high density screen one logical pixel is several device pixels. Draw in physical pixels and use ScaleFactor to convert. Moving a window to another screen sends ScaleChanged and then Resized. When only part of the frame changed, pass the changed rectangles to Present; it copies those alone and clips them to the buffer.
import gui.window
import mem
func main:
w := window.Open(window.Options { width = 100.0, height = 50.0, headless = true, scale = 1.5, visible = false })
size := w.Size()
println "logical", size.width, size.height, "physical", size.physical_width, size.physical_height
window.Inject(window.Event { kind = window.EventKind.ScaleChanged, window = w.id, scale = 2.0 })
e := window.Poll()
println "new scale", e.scale, "logical", e.width, e.height, "physical", e.physical_width, e.physical_height
window.Inject(window.Event { kind = window.EventKind.Resized, window = w.id, physical_width = 300, physical_height = 100 })
r := window.Poll()
println "resized to", r.width, r.height
width := r.physical_width
height := r.physical_height
pixels := mem.AllocateZeroed(((width * height) * 4) as u64) as u32*
defer mem.Free(pixels as void*)
w.PresentAll(pixels as void*, width, height, width * 4)
mut damage := Vector {} as Vector<window.Rect>
defer damage.free()
damage.push(window.Rect { x = 10, y = 10, width = 20, height = 8 })
damage.push(window.Rect { x = 290, y = 90, width = 50, height = 50 })
w.Present(pixels as void*, width, height, width * 4, damage)
println "copied", w.LastDamageCount(), "rects inside", w.LastDamage()
endTesting without a screen
A headless window behaves like a real one: it gets focus, redraw requests, resize events and timers, and keeps every presented frame. PixelAt reads the frame back, Inject plays any event, and SetManualClock makes time jump straight to the next timer, so a test of a one second animation takes no time. The environment variable SALAM_WINDOW_BACKEND=headless makes every window headless without changing the program.
import gui.window
import mem
func main:
window.SetManualClock(true)
w := window.Open(window.Options { width = 2.0, height = 2.0, headless = true, visible = false })
pixels := mem.AllocateZeroed(16 as u64) as u32*
defer mem.Free(pixels as void*)
pixels[0] = 0xFFFF0000 as u32
pixels[3] = 0x80000080 as u32
w.PresentAll(pixels as void*, 2, 2, 8)
println "top left red:", w.PixelAt(0, 0) == (0xFFFF0000 as u32)
println "bottom right half blue:", w.PixelAt(1, 1) == (0x80000080 as u32)
timer := window.SetTimer(1000, false)
mut e := window.Wait(-1)
until e.kind != window.EventKind.Timer:
println "skipped event", e.kind as int
e = window.Wait(-1)
end
println "timer", e.timer == timer, "after", window.Clock(), "ms of test time"
w.Close()
end| System | Backend | Notes |
|---|---|---|
| Linux | X11 through libX11 | XPutImage per damaged rectangle, Xft.dpi for the scale, XIM for input methods, CLIPBOARD selection. Wayland sessions use XWayland. |
| Windows | Win32 | A DIB section and BitBlt, per-monitor DPI, IME composition, the Unicode clipboard and dark mode from the registry. |
| macOS | Cocoa | A layer-backed view, NSTextInputClient for input methods, NSPasteboard and the system appearance. |
| Any | Headless | In memory, for tests and rendering to files. |
Types
Rect
struct RectPresent and the IME area.| Name | Type | Description |
|---|---|---|
x | int = 0 | Left edge in pixels. |
y | int = 0 | Top edge in pixels. |
width | int = 0 | Width in pixels. |
height | int = 0 | Height in pixels. |
import gui.window
import mem
func main:
w := window.Open(window.Options { width = 4.0, height = 3.0, headless = true })
pixels := mem.AllocateZeroed((4 * 3 * 4) as u64) as u32*
defer mem.Free(pixels as void*)
repeat 12 in i:
pixels[i] = 0xFF336699 as u32
end
println w.PresentAll(pixels as void*, 4, 3, 16), w.PresentCount(), w.LastDamage()
pixels[5] = 0xFFFF0000 as u32
mut damage := Vector {} as Vector<window.Rect>
defer damage.free()
damage.push(window.Rect { x = 1, y = 1, width = 1, height = 1 })
println w.Present(pixels as void*, 4, 3, 16, damage), w.LastDamage(), w.LastDamageCount()
println w.PixelAt(1, 1) == (0xFFFF0000 as u32), w.ShownPixel(0, 0) == (0xFF336699 as u32)
println w.SetIcon(pixels as void*, 2, 2, 16)
w.Close()
endWindowSize
struct WindowSizeSize returns it.| Name | Type | Description |
|---|---|---|
width | f64 = 0 | Width in logical pixels. |
height | f64 = 0 | Height in logical pixels. |
physical_width | int = 0 | Width in device pixels: the width of the buffer to draw. |
physical_height | int = 0 | Height in device pixels. |
import gui.window
func main:
options := window.Options {
title = "Notes", width = 400.0, height = 300.0, min_width = 200.0, min_height = 150.0,
max_width = 800.0, max_height = 600.0, resizable = true, decorated = true, centered = true,
x = 0.0, y = 0.0, background = 0xF5F5F5FF as u32, visible = true, headless = true, scale = 2.0
}
w := window.Open(options)
println w.id, w.IsOpen(), w.IsHeadless(), w.IsFocused(), w.Title()
size := w.Size()
println size.width, size.height, size.physical_width, size.physical_height, w.ScaleFactor()
w.SetTitle("Notes (2)")
w.SetSize(1000.0, 100.0)
println w.Title(), w.Size()
w.SetMinSize(100.0, 100.0)
w.SetMaxSize(0.0, 0.0)
w.SetSize(1000.0, 100.0)
println w.Size()
w.SetCursor(window.Cursor.Pointer)
w.SetImeRect(20.0, 40.0, 2.0, 16.0)
println w.CurrentCursor() == window.Cursor.Pointer, w.ImeRect()
w.SetFullscreen(true)
println w.IsFullscreen()
w.SetFullscreen(false)
w.Minimize()
w.Maximize()
w.Restore()
w.Focus()
w.RequestRedraw()
println w.Handle() == null
w.Close()
println w.IsOpen()
endEventKind
enum EventKindEvent reports.| Name | Type | Description |
|---|---|---|
None | | Nothing happened before the timeout. |
CloseRequested | | The user asked to close the window. Nothing closes until you call Close. |
Resized | | The drawing area changed size; width, height and the physical fields hold the new size. |
ScaleChanged | | The window moved to a screen with another scale factor; scale holds it. |
RedrawRequested | | Draw a frame now and present it. Several requests in one turn arrive as one. |
FocusIn | | The window received keyboard focus. |
FocusOut | | The window lost keyboard focus. |
PointerMove | | The pointer moved; x and y are in logical pixels. |
PointerEnter | | The pointer entered the window. |
PointerLeave | | The pointer left the window. |
PointerDown | | A mouse button was pressed; see button and clicks. |
PointerUp | | A mouse button was released. |
Wheel | | The wheel or touchpad scrolled; see delta_x, delta_y and delta_mode. |
KeyDown | | A key was pressed or repeats; see key, code and repeated. |
KeyUp | | A key was released. |
TextInput | | Typed text, separate from the key events, in text. |
ImePreedit | | The input method's composition text changed; empty text means it ended. |
ImeCommit | | The input method committed text. |
ColorSchemeChanged | | The system switched between light and dark; see scheme. |
Timer | | A timer from SetTimer fired; timer is its number. |
Wake | | Another thread called Wake. |
import gui.window
func main:
window.SetManualClock(true)
w := window.Open(window.Options { width = 300.0, height = 200.0, headless = true })
window.Inject(window.Event { kind = window.EventKind.PointerDown, window = w.id, x = 10.0, y = 20.0, button = window.MouseButton.Left })
window.Inject(window.Event { kind = window.EventKind.PointerDown, window = w.id, x = 10.0, y = 20.0, button = window.MouseButton.Left })
window.Inject(window.Event { kind = window.EventKind.KeyDown, window = w.id, key = window.Key.Enter, code = 36, modifiers = window.mod_control })
window.Inject(window.Event { kind = window.EventKind.TextInput, window = w.id, text = "سلام" })
window.Inject(window.Event { kind = window.EventKind.Wheel, window = w.id, delta_y = 1.0, delta_mode = window.WheelMode.Line })
mut e := window.Poll()
until e.kind != window.EventKind.None:
switch e.kind:
window.EventKind.PointerDown:
println "down", e.x, e.y, e.button == window.MouseButton.Left, "clicks", e.clicks
break
end
window.EventKind.KeyDown:
println "key", e.key == window.Key.Enter, e.code, (e.modifiers & window.mod_control) != 0, e.repeated
break
end
window.EventKind.TextInput:
println "text", e.text
break
end
window.EventKind.Wheel:
println "wheel", e.delta_x, e.delta_y, e.delta_mode == window.WheelMode.Line
break
end
else:
println "other", e.kind as int, e.window
break
end
end
e = window.Wait(0)
end
w.Close()
endMouseButton
enum MouseButton| Name | Type | Description |
|---|---|---|
None | | No button, as in a move event. |
Left | | The primary button. |
Right | | The secondary button. |
Middle | | The wheel button. |
Back | | The back side button. |
Forward | | The forward side button. |
The example for this item is shown with the ones above: gui-window-Event.salam
WheelMode
enum WheelMode| Name | Type | Description |
|---|---|---|
Pixel | | Logical pixels, from a touchpad or a precise wheel. |
Line | | Lines, from a notched mouse wheel. |
The example for this item is shown with the ones above: gui-window-Event.salam
ColorScheme
enum ColorScheme| Name | Type | Description |
|---|---|---|
Light | | Light appearance. |
Dark | | Dark appearance. |
import gui.window
import mem
func main:
first := window.Open(window.Options { headless = true, visible = false })
second := window.Open(window.Options { headless = true, visible = false })
println window.OpenWindows(), first.id, second.id
println window.SetClipboardText("hello")
text := window.ClipboardText()
println text
mem.Free(text as void*)
println window.CurrentColorScheme() == window.ColorScheme.Light
window.Inject(window.Event { kind = window.EventKind.ColorSchemeChanged, scheme = window.ColorScheme.Dark })
e := window.Poll()
println e.scheme == window.ColorScheme.Dark, window.CurrentColorScheme() == window.ColorScheme.Dark
println window.LastError() == ""
second.Close()
println window.OpenWindows()
endCursor
enum Cursor| Name | Type | Description |
|---|---|---|
Default | | The arrow. |
Pointer | | A hand, for links and buttons. |
Text | | The text beam. |
Wait | | Busy. macOS has no public busy cursor and shows the arrow. |
Crosshair | | A crosshair. |
Move | | Move in any direction. |
ResizeHorizontal | | Resize left and right. |
ResizeVertical | | Resize up and down. |
ResizeDiagonalUp | | Resize along the diagonal from bottom left to top right. |
ResizeDiagonalDown | | Resize along the diagonal from top left to bottom right. |
NotAllowed | | Not allowed. |
Hidden | | No pointer at all. |
The example for this item is shown with the ones above: gui-window-Event.salam
Key
enum KeyTextInput events for the characters typed.| Name | Type | Description |
|---|---|---|
Unknown | | The Unknown key. |
A | | The A key. |
B | | The B key. |
C | | The C key. |
D | | The D key. |
E | | The E key. |
F | | The F key. |
G | | The G key. |
H | | The H key. |
I | | The I key. |
J | | The J key. |
K | | The K key. |
L | | The L key. |
M | | The M key. |
N | | The N key. |
O | | The O key. |
P | | The P key. |
Q | | The Q key. |
R | | The R key. |
S | | The S key. |
T | | The T key. |
U | | The U key. |
V | | The V key. |
W | | The W key. |
X | | The X key. |
Y | | The Y key. |
Z | | The Z key. |
Digit0 | | The Digit0 key. |
Digit1 | | The Digit1 key. |
Digit2 | | The Digit2 key. |
Digit3 | | The Digit3 key. |
Digit4 | | The Digit4 key. |
Digit5 | | The Digit5 key. |
Digit6 | | The Digit6 key. |
Digit7 | | The Digit7 key. |
Digit8 | | The Digit8 key. |
Digit9 | | The Digit9 key. |
F1 | | The F1 key. |
F2 | | The F2 key. |
F3 | | The F3 key. |
F4 | | The F4 key. |
F5 | | The F5 key. |
F6 | | The F6 key. |
F7 | | The F7 key. |
F8 | | The F8 key. |
F9 | | The F9 key. |
F10 | | The F10 key. |
F11 | | The F11 key. |
F12 | | The F12 key. |
Escape | | The Escape key. |
Enter | | The Enter key. |
Tab | | The Tab key. |
Backspace | | The Backspace key. |
Space | | The Space key. |
Insert | | The Insert key. |
Delete | | The Delete key. |
Home | | The Home key. |
End | | The End key. |
PageUp | | The Page Up key. |
PageDown | | The Page Down key. |
Left | | The Left key. |
Right | | The Right key. |
Up | | The Up key. |
Down | | The Down key. |
ShiftLeft | | The Shift Left key. |
ShiftRight | | The Shift Right key. |
ControlLeft | | The Control Left key. |
ControlRight | | The Control Right key. |
AltLeft | | The Alt Left key. |
AltRight | | The Alt Right key. |
SuperLeft | | The Super Left key. |
SuperRight | | The Super Right key. |
CapsLock | | The Caps Lock key. |
Minus | | The Minus key. |
Equal | | The Equal key. |
BracketLeft | | The Bracket Left key. |
BracketRight | | The Bracket Right key. |
Backslash | | The Backslash key. |
Semicolon | | The Semicolon key. |
Quote | | The Quote key. |
Backquote | | The Backquote key. |
Comma | | The Comma key. |
Period | | The Period key. |
Slash | | The Slash key. |
IntlBackslash | | The Intl Backslash key. |
Numpad0 | | The Numpad0 key. |
Numpad1 | | The Numpad1 key. |
Numpad2 | | The Numpad2 key. |
Numpad3 | | The Numpad3 key. |
Numpad4 | | The Numpad4 key. |
Numpad5 | | The Numpad5 key. |
Numpad6 | | The Numpad6 key. |
Numpad7 | | The Numpad7 key. |
Numpad8 | | The Numpad8 key. |
Numpad9 | | The Numpad9 key. |
NumpadAdd | | The Numpad Add key. |
NumpadSubtract | | The Numpad Subtract key. |
NumpadMultiply | | The Numpad Multiply key. |
NumpadDivide | | The Numpad Divide key. |
NumpadDecimal | | The Numpad Decimal key. |
NumpadEnter | | The Numpad Enter key. |
NumLock | | The Num Lock key. |
ScrollLock | | The Scroll Lock key. |
PrintScreen | | The Print Screen key. |
Pause | | The Pause key. |
ContextMenu | | The Context Menu key. |
The example for this item is shown with the ones above: gui-window-Event.salam
Options
struct Options| Name | Type | Description |
|---|---|---|
title | str = "Salam" | The title bar text. |
width | f64 = 800 | Width of the drawing area. |
height | f64 = 600 | Height of the drawing area. |
min_width | f64 = 0 | Smallest width the user can drag to; 0 for no limit. |
min_height | f64 = 0 | Smallest height; 0 for no limit. |
max_width | f64 = 0 | Largest width; 0 for no limit. |
max_height | f64 = 0 | Largest height; 0 for no limit. |
resizable | bool = true | Whether the user can resize the window. |
decorated | bool = true | Whether the window has a title bar and border. |
centered | bool = true | Center on the screen instead of using x and y. |
x | f64 = 0 | Left edge on the screen when not centered. |
y | f64 = 0 | Top edge on the screen when not centered. |
background | u32 = 4294967295 | Colour shown before the first frame, as 0xRRGGBBAA. |
visible | bool = true | Show the window as soon as it opens. |
headless | bool = false | Keep the window in memory only, for tests and rendering without a screen. |
scale | f64 = 0 | Force a scale factor; 0 asks the system (or SALAM_SCALE_FACTOR). |
The example for this item is shown with the ones above: gui-window-Open.salam
Event
struct EventWait or Poll. Only the fields that belong to its kind are set.| Name | Type | Description |
|---|---|---|
kind | EventKind | What happened. |
window | int = -1 | The id of the window it belongs to, or -1 for app events. |
x | f64 = 0 | Pointer position from the left, logical pixels. |
y | f64 = 0 | Pointer position from the top, logical pixels. |
width | f64 = 0 | New logical width (resize, scale and redraw events). |
height | f64 = 0 | New logical height. |
physical_width | int = 0 | New width in device pixels. |
physical_height | int = 0 | New height in device pixels. |
scale | f64 = 0 | The scale factor (scale, resize and redraw events). |
button | MouseButton | The mouse button. |
clicks | int = 0 | 1 for a single click, 2 for a double click and so on. |
modifiers | int = 0 | The Mod bits held during the event. |
delta_x | f64 = 0 | Horizontal scroll; positive scrolls right. |
delta_y | f64 = 0 | Vertical scroll; positive scrolls down, like the web wheel event. |
delta_mode | WheelMode | Whether the deltas are pixels or lines. |
key | Key | The key by position. |
code | int = 0 | The raw key code of the system (X11 keycode, Windows scan code, macOS key code). |
repeated | bool = false | True when the key repeats because it is held. |
text | str = "" | Typed or composed text in UTF-8. It is valid until the next Wait or Poll; clone it to keep it. |
cursor | int = 0 | Caret position inside the composition text, in bytes. |
scheme | ColorScheme | The new colour scheme. |
timer | int = 0 | The number of the timer that fired. |
The example for this item is shown with the ones above: gui-window-Event.salam
Window
struct Window| Name | Type | Description |
|---|---|---|
id | int = -1 | The window's number; events carry it in window. |
The example for this item is shown with the ones above: gui-window-Open.salam
IsOpen
func IsOpen(): boolLastError.The example for this item is shown with the ones above: gui-window-Open.salam
IsHeadless
func IsHeadless(): boolThe example for this item is shown with the ones above: gui-window-Open.salam
IsFocused
func IsFocused(): boolThe example for this item is shown with the ones above: gui-window-Open.salam
SetTitle
func SetTitle(title: str)The example for this item is shown with the ones above: gui-window-Open.salam
Title
func Title(): strSetTitle.The example for this item is shown with the ones above: gui-window-Open.salam
SetSize
func SetSize(width: f64, height: f64)Resized event follows.The example for this item is shown with the ones above: gui-window-Open.salam
Size
func Size(): WindowSizeThe example for this item is shown with the ones above: gui-window-Open.salam
ScaleFactor
func ScaleFactor(): f64The example for this item is shown with the ones above: gui-window-Open.salam
Present
func Present(pixels: void*, width: int, height: int, stride: int, damage: Vector<Rect>): boolThe example for this item is shown with the ones above: gui-window-Present.salam
PresentAll
func PresentAll(pixels: void*, width: int, height: int, stride: int): boolThe example for this item is shown with the ones above: gui-window-Present.salam
RequestRedraw
func RequestRedraw()RedrawRequested event; repeated requests merge into one.The example for this item is shown with the ones above: gui-window-Open.salam
SetCursor
func SetCursor(cursor: Cursor)The example for this item is shown with the ones above: gui-window-Open.salam
SetImeRect
func SetImeRect(x: f64, y: f64, width: f64, height: f64)The example for this item is shown with the ones above: gui-window-Open.salam
SetMinSize
func SetMinSize(width: f64, height: f64)The example for this item is shown with the ones above: gui-window-Open.salam
SetMaxSize
func SetMaxSize(width: f64, height: f64)The example for this item is shown with the ones above: gui-window-Open.salam
Minimize
func Minimize()The example for this item is shown with the ones above: gui-window-Open.salam
Maximize
func Maximize()The example for this item is shown with the ones above: gui-window-Open.salam
Restore
func Restore()The example for this item is shown with the ones above: gui-window-Open.salam
SetFullscreen
func SetFullscreen(enabled: bool)The example for this item is shown with the ones above: gui-window-Open.salam
IsFullscreen
func IsFullscreen(): boolThe example for this item is shown with the ones above: gui-window-Open.salam
Focus
func Focus()The example for this item is shown with the ones above: gui-window-Open.salam
Close
func Close()The example for this item is shown with the ones above: gui-window-Open.salam
SetIcon
func SetIcon(pixels: void*, width: int, height: int, stride: int): boolThe example for this item is shown with the ones above: gui-window-Present.salam
PixelAt
func PixelAt(x: int, y: int): u320xAARRGGBB, or 0 outside it.The example for this item is shown with the ones above: gui-window-Present.salam
ShownPixel
func ShownPixel(x: int, y: int): u32The example for this item is shown with the ones above: gui-window-Present.salam
PresentCount
func PresentCount(): intThe example for this item is shown with the ones above: gui-window-Present.salam
LastDamage
func LastDamage(): RectThe example for this item is shown with the ones above: gui-window-Present.salam
LastDamageCount
func LastDamageCount(): intThe example for this item is shown with the ones above: gui-window-Present.salam
CurrentCursor
func CurrentCursor(): CursorThe example for this item is shown with the ones above: gui-window-Open.salam
ImeRect
func ImeRect(): RectThe example for this item is shown with the ones above: gui-window-Open.salam
Handle
func Handle(): void*HWND or an NSWindow; null for headless windows.The example for this item is shown with the ones above: gui-window-Open.salam
Constants and variables
mod_shift
const mod_shift: i32 = 1modifiers while Shift is held.The example for this item is shown with the ones above: gui-window-Event.salam
mod_control
const mod_control: i32 = 2modifiers while Control is held.The example for this item is shown with the ones above: gui-window-Event.salam
mod_alt
const mod_alt: i32 = 4modifiers while Alt (Option on macOS) is held.The example for this item is shown with the ones above: gui-window-Event.salam
mod_super
const mod_super: i32 = 8modifiers while the Windows key or Command is held.The example for this item is shown with the ones above: gui-window-Event.salam
Functions
Open
func Open(options: Options): WindowIsOpen: without a window system it returns a closed window and LastError says why.The example for this item is shown with the ones above: gui-window-Open.salam
LastError
func LastError(): strThe example for this item is shown with the ones above: gui-window-App.salam
Wait
func Wait(timeout_ms: int): Eventtimeout_ms (-1 for no limit) for the next event, firing due timers. Returns a None event on timeout.The example for this item is shown with the ones above: gui-window-Event.salam
Poll
func Poll(): EventThe example for this item is shown with the ones above: gui-window-Event.salam
Inject
func Inject(event: Event)The example for this item is shown with the ones above: gui-window-Event.salam
SetTimer
func SetTimer(ms: int, repeating: bool): intms milliseconds, or once; returns its number.import gui.window
func main:
window.SetManualClock(true)
tick := window.SetTimer(100, true)
once := window.SetTimer(250, false)
repeat 4:
e := window.Wait(-1)
println e.kind == window.EventKind.Timer, e.timer == tick ? "tick" : "once", window.Clock()
end
window.ClearTimer(tick)
window.Advance(1000)
println window.Clock(), window.Wait(10).kind == window.EventKind.None
window.Wake()
println window.Wait(-1).kind == window.EventKind.Wake, once > tick
endClearTimer
func ClearTimer(id: int)The example for this item is shown with the ones above: gui-window-Timer.salam
Wake
func Wake()Wait from any thread with a Wake event.The example for this item is shown with the ones above: gui-window-Timer.salam
SetManualClock
func SetManualClock(enabled: bool)Wait jumps to the next timer or Advance is called.The example for this item is shown with the ones above: gui-window-Timer.salam
Clock
func Clock(): i64The example for this item is shown with the ones above: gui-window-Timer.salam
Advance
func Advance(ms: int)The example for this item is shown with the ones above: gui-window-Timer.salam
ClipboardText
func ClipboardText(): strThe example for this item is shown with the ones above: gui-window-App.salam
SetClipboardText
func SetClipboardText(text: str): boolThe example for this item is shown with the ones above: gui-window-App.salam
CurrentColorScheme
func CurrentColorScheme(): ColorSchemeThe example for this item is shown with the ones above: gui-window-App.salam
OpenWindows
func OpenWindows(): intThe example for this item is shown with the ones above: gui-window-App.salam