Checks IDs, titles and shortcut uniqueness without contacting a window server.
#import "Extensions/Desktop";
Native menus, file dialogs and opt-in text services for desktop windows.
Procedures#
General#
Takes the next selected action ID, or zero when empty.
Linux has no native menu backend; returns null.
Releases a menu; a no-op on Linux.
Linux returns UNSUPPORTED without opening a dialog.
Windows#
Called before TranslateMessage; consumed accelerators must not also become keyboard/text input.
WM_COMMAND carries a menu/accelerator ID in LOWORD; controls have a nonzero lParam.
Events#
Pumps Input while enabling this extension's menu shortcuts and IME decoding. Use in place of Input.update_window_events, once per frame, on the window thread. Other Input APIs are unchanged.
Enables composition and positions candidate UI at a caret in top-left window points. Disabling cancels marked text. Linux currently leaves native composition unsupported.
Restores the original native view class/window procedure before destroying the window. Also releases queued composition text belonging to it. Call on the window thread after the last frame.
Types#
A flat native menu entry. menu groups entries into top-level menus; action must be unique
and nonzero. key is an uppercase ASCII letter (0: none), with Cmd on macOS or Ctrl on Windows.
shift adds Shift. Strings are borrowed only during creation.
Menu_Item :: struct {
menu: string;
title: string;
action: u16;
key: u8;
shift: bool;
}item := Menu_Item.{ menu = "File", title = "Open…", action = 1, key = #char "O" };
assert(item.action == 1);An owned menu installation, used on the window's thread. macOS allows one installation per application; Windows allows one per window. Remove it before destroying its window.
Native_Menu :: struct {
window: WT.Window_Type;
handle: *void;
target: *void;
accelerators: *void;
previous: *void;
pending: [..] u16;
}OPEN selects an existing file; SAVE selects an output path; FOLDER selects a directory.
Dialog_Kind :: enum {
OPEN;
SAVE;
FOLDER;
}ACCEPTED, CANCELLED, UNSUPPORTED or FAILED. Cancellation must not invoke a fallback prompt.
Dialog_Status :: enum {
ACCEPTED;
CANCELLED;
UNSUPPORTED;
FAILED;
}A dialog outcome with an owned UTF-8 path. Release path with Basic.free after using it.
Dialog_Result :: struct {
status: Dialog_Status = .UNSUPPORTED;
path: string;
}An owned composition update, ordered before Input.events_this_frame[position]. Text remains valid until the next update_events call. Cursor counts UTF-8 bytes; -1 means the text's end.
Composition_Event :: struct {
window: WT.Window_Type;
position: int;
text: string;
commit: bool;
cancel: bool;
cursor: int = -1;
}