Something went wrong. Try again.
Windows, a GPU renderer and text for Zig programs that draw their own interface.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272// SPDX-FileCopyrightText: © 2026 Jeffrey C. Ollie <jeff@ocjtech.us>// SPDX-License-Identifier: MIT
//! What a platform tells the application, in terms that do not name the//! window system.
const std = @import("std");
pub const Mods = packed struct(u8) { shift: bool = false, ctrl: bool = false, alt: bool = false, super: bool = false, caps_lock: bool = false, num_lock: bool = false, _: u2 = 0,};
pub const KeyAction = enum { press, repeat, release };
pub const Key = struct { action: KeyAction, /// The physical key, as an evdev code: Linux's own, or the Windows /// scancode made one. What it means is the layout's business, and /// `text` says that. code: u32, /// The keysym the layout gives the key with the current modifiers. keysym: u32, /// What typing the key produces — after Compose, when a sequence just /// finished — or nothing. Valid until the next `Platform.wait`. text: []const u8, mods: Mods, /// The modifiers the layout used up to produce `text`: shift, for "A". consumed: Mods, /// The key's character with no modifiers, for encodings that report the /// key rather than the text. unshifted: u21, /// A Compose sequence is under way and this key did not finish it. composing: bool,};
pub const MouseButton = enum { left, middle, right, back, forward, other };
pub const Clipboard = enum { /// What copy and paste use. standard, /// What selecting text sets and the middle button pastes. primary,};
/// One Clipboard type of what is put on a clipboard, and its bytes.pub const ClipboardContent = struct { mime: []const u8, data: []const u8,};
/// The first text among `contents`, under whichever of the names text goes/// by.pub fn clipboardText(contents: []const ClipboardContent) ?[]const u8 { for (contents) |c| if (isTextMime(c.mime)) return c.data; return null;}
/// The names plain text goes by: its MIME types, and X11's.pub fn isTextMime(mime: []const u8) bool { for ([_][]const u8{ "text/plain;charset=utf-8", "text/plain", "UTF8_STRING", "TEXT", "STRING" }) |m| { if (std.mem.eql(u8, mime, m)) return true; } return false;}
pub const Cursor = enum { default, text, pointer, none, /// Resizing, named for the edge or corner that moves. n_resize, s_resize, e_resize, w_resize, ne_resize, nw_resize, se_resize, sw_resize, /// A divider between things side by side, or one above the other. col_resize, row_resize, /// Something that can be picked up, and something picked up. grab, grabbing,};
/// An edge or corner of a window, for an interactive resize.pub const Edge = enum { top, bottom, left, right, top_left, top_right, bottom_left, bottom_right,
/// The cursor that says this edge can be dragged. pub fn cursor(e: Edge) Cursor { return switch (e) { .top => .n_resize, .bottom => .s_resize, .left => .w_resize, .right => .e_resize, .top_left => .nw_resize, .top_right => .ne_resize, .bottom_left => .sw_resize, .bottom_right => .se_resize, }; }};
/// What the window system says about a window, beyond its size.pub const WindowState = packed struct(u8) { maximized: bool = false, fullscreen: bool = false, /// Draw as the active window. Not quite keyboard focus: a compositor /// may activate a window whose keyboard is elsewhere. activated: bool = false, /// A side that is against another window or the screen's edge in a /// tiled layout, which wants no border and no resize handle. tiled_left: bool = false, tiled_right: bool = false, tiled_top: bool = false, tiled_bottom: bool = false, _: u1 = 0,};
/// What a drag and drop does with what is dropped.pub const DndAction = enum { none, copy, move };
/// The actions a drag allows.pub const DndActions = packed struct(u8) { copy: bool = false, move: bool = false, _: u6 = 0,};
/// Something dragged over a window — by another program, or by this one/// on behalf of something it shows — and where, in logical pixels from the/// window's top left. `mimes` are the types it is offered as; they/// last until `drop_leave`, or until the window finishes with the drop.pub const DropMotion = struct { x: f32, y: f32, mimes: []const []const u8, actions: DndActions,};
/// A rectangle in logical pixels.pub const Rect = struct { x: i32, y: i32, width: i32, height: i32 };
/// One of the application's own items in the window system's menu for a/// window, as the application numbered them.pub const MenuItem = u32;
pub const Data = union(enum) { /// The user asked to close the window. close, /// The user chose one of the application's items from the window system's menu /// for the window. menu: MenuItem, /// The window's size in logical pixels, and how many physical pixels /// each of those is. Draw at `width * scale` by `height * scale`. /// `draw_title_bar` says whether the window is to draw its own title /// bar and frame, because nobody else will. resize: struct { width: u32, height: u32, scale: f32, state: WindowState, draw_title_bar: bool }, /// The compositor is ready for another frame. frame, focus: bool, key: Key, /// Text from an input method, all at once. Valid until the next `wait`. text: []const u8, /// An input method's text in progress, or null when there is none. /// Valid until the next `wait`. preedit: ?[]const u8, /// The pointer, in logical pixels from the window's top left. motion: struct { x: f32, y: f32 }, button: struct { button: MouseButton, pressed: bool }, /// In lines: positive is down and right. `precise` for a touchpad, /// whose scrolling comes in fractions of a line. scroll: struct { dx: f32, dy: f32, precise: bool }, pointer_leave, /// A local drag this program started is over the window, at a point in /// logical pixels from its top left. local_drag: struct { x: f32, y: f32 }, /// It has gone elsewhere. local_drag_leave, /// It was dropped on the window, there. local_drop: struct { x: f32, y: f32 }, /// The local drag this window started is over. A drop on one of this /// program's windows arrives as `local_drop` first; with no `local_drop`, /// it went nowhere that took it, or was cancelled. local_drag_end, /// Something not a local drag is dragged over the window, or has moved over /// it. Until the window accepts it with `Window.dropAccept`, a drop is /// refused. drop_motion: DropMotion, /// It has gone elsewhere, or was dropped without being accepted. drop_leave, /// It was dropped, accepted. The window reads what it wants with /// `Window.dropReceive` and ends it with `Window.dropFinish`. drop: DropMotion, /// For the window that started a drag with `Window.startDrag`: the /// drop target under the pointer accepts the type at this index of /// those offered, or accepts nothing. drag_target: ?u32, /// The action the drag would perform now. drag_action: DndAction, /// The drag was dropped on a target, which may still want data. drag_dropped, /// The drag is over; true if it went nowhere or was cancelled. drag_finished: bool, /// A drop target wants the data of the type at `index` of those /// offered, written to `fd`, which the window now owns and closes when /// it is done. On Windows there is no `fd`, -1, and the data goes to /// `Platform.dragData`. drag_send: struct { index: u32, fd: i32 }, /// The answer to `Window.requestToken` or `Platform.requestActivation`: /// an xdg-activation token, valid until the next `wait`, or none. With /// no window for the second. activation_token: struct { cookie: u32, token: ?[]const u8 }, /// With no window: a global hotkey set with `Platform.setHotkeys`, at /// `index` among them, was pressed or let go. `serial` is the input /// serial an activation token may be asked for with. hotkey: struct { index: u32, pressed: bool, serial: u32 }, /// With no window: what the compositor made of hotkey `index` — /// bound, refused, or bound and then withdrawn — and what it said why, /// valid until the next `wait`. hotkey_state: struct { index: u32, state: HotkeyState, message: []const u8 },};
pub const HotkeyState = enum { bound, denied, revoked };
/// A global hotkey: a key, by its keysym unshifted, held with exactly/// these modifiers.pub const HotkeySpec = struct { keysym: u32, shift: bool = false, ctrl: bool = false, alt: bool = false, super: bool = false, /// What it does, for the compositor to show. description: [:0]const u8,};
/// What follows the pointer while something is dragged: premultiplied ARGB/// pixels, a row after another, `width * height` of them, in physical/// pixels at `scale`. The pointer is at `hot_x`, `hot_y` in it.pub const DragIcon = struct { width: u32, height: u32, pixels: []const u32, scale: f32, hot_x: i32, hot_y: i32,};
/// An event, and the window it is for, as the opaque value the window was/// created with.pub const Event = struct { window: ?*anyopaque, data: Data,};