Skip to main content

plat/
consts.rs

1// consts -- the platform constants of jfgui.inc / ui.inc shared by every OS layer and the UI
2//                                                        [ASMLIB/inc/jfgui.inc, ui.inc]
3
4// ---- events (Event::typ)
5pub const E_NONE: u8 = 0;
6pub const E_MOVE: u8 = 1;
7pub const E_DOWN: u8 = 2; // btn
8pub const E_UP: u8 = 3; // btn
9pub const E_WHEEL: u8 = 4; // data = (i16 dy) | (i16 dx << 16), 120 per notch, up / right positive
10pub const E_KEY_DOWN: u8 = 5; // data = VK | (repeat << 31); (E2) x = scancode, y = KL_* location
11pub const E_KEY_UP: u8 = 6; // data = VK; (E2) x = scancode, y = KL_* location
12pub const E_TEXT: u8 = 7; // data = Unicode codepoint
13pub const E_RESIZE: u8 = 8; // x = width, y = height (physical pixels)
14pub const E_DPI: u8 = 9; // data = dpi (96 = 100 %)
15pub const E_FOCUS_IN: u8 = 10;
16pub const E_FOCUS_OUT: u8 = 11;
17pub const E_LEAVE: u8 = 12; // pointer left the window
18pub const E_CLOSE: u8 = 13; // user asked to close the window
19pub const E_WAKE: u8 = 14; // generic wake-up (timer, repaint request)
20pub const E_PAINT: u8 = 15; // the OS needs the window content again
21pub const E_WINPOS: u8 = 16; // window moved: x, y = client origin in screen px
22pub const E_DROP: u8 = 17; // files dropped: x, y = position, data = count (drop_take)
23pub const E_PREEDIT: u8 = 18; // ime_preedit(win), uncommitted text
24pub const E_IME_COMMIT: u8 = 19; // data = bounded ime_commit_take token
25pub const E_POWER: u8 = 20; // data = 1: the system goes to sleep, 0: it woke up
26pub const E_SESSION_END: u8 = 21; // the user logs off, the system shuts down, SIGTERM: save and end
27pub const E_SETTINGS: u8 = 22; // data = SET_* bits: system settings changed
28pub const E_DRAG: u8 = 23; // a drag over the window: x, y, data = DT_* | DE_* << 8 (0: it left; dnd.rs)
29pub const E_DRAG_END: u8 = 24; // our outgoing drag (drag_start) ended: data = DE_* effect, 0 = none
30
31// E_SETTINGS: what changed
32pub const SET_THEME: u32 = 1; // light / dark, accent colour
33pub const SET_LOCALE: u32 = 2; // language, regional format
34pub const SET_CONTRAST: u32 = 4; // high contrast, system colours
35pub const SET_FONTS: u32 = 8; // fonts, text scaling
36pub const SET_OTHER: u32 = 16;
37pub const SET_MONITORS: u32 = 32; // monitors added, removed, moved, rescaled; work areas (screen::monitors)
38pub const EVQ_CAP: usize = 256; // event ring capacity (power of two)
39
40// ---- pointer types, buttons, modifiers
41pub const PTR_MOUSE: u32 = 0;
42pub const PTR_PEN: u32 = 1; // pen tip
43pub const PTR_ERASER: u32 = 2; // eraser end of a pen
44pub const PTR_TOUCH: u32 = 3;
45pub const BTN_LEFT: u8 = 1;
46pub const BTN_RIGHT: u8 = 2;
47pub const BTN_MIDDLE: u8 = 3;
48pub const BTN_X1: u8 = 4;
49pub const BTN_X2: u8 = 5;
50pub const MOD_SHIFT: u8 = 1;
51pub const MOD_CTRL: u8 = 2;
52pub const MOD_ALT: u8 = 4;
53pub const MOD_SUPER: u8 = 8;
54pub const MOD_ALTGR: u8 = 16;
55pub const MOD_CAPS: u8 = 32;
56pub const MOD_NUM: u8 = 64;
57
58// ---- (E2) where a key sits (Event::y of E_KEY_DOWN / E_KEY_UP; Event::x is its scancode:
59// Windows' scan code (0xE0.. for extended keys), Linux's evdev code, 0 where unknown)
60pub const KL_STANDARD: u32 = 0;
61pub const KL_LEFT: u32 = 1; // the left Shift, Ctrl, Alt, Windows key
62pub const KL_RIGHT: u32 = 2;
63pub const KL_NUMPAD: u32 = 3; // the keys of the number block
64
65/// (E2) the KL_* location of a Linux evdev key code (both sides' modifiers, the number block)
66pub const fn evdev_location(code: u32) -> u32 {
67    match code {
68        42 | 29 | 56 | 125 => KL_LEFT,     // Shift, Ctrl, Alt, Meta
69        54 | 97 | 100 | 126 => KL_RIGHT,   // (AltGr is the right Alt)
70        55 | 71..=83 | 96 | 98 | 117 | 121 => KL_NUMPAD, // *, 7 8 9 - 4 5 6 + 1 2 3 0 ., Enter, /, =, ,
71        _ => KL_STANDARD,
72    }
73}
74
75// ---- cursors (CUR_*: system shapes; CUR_USER0.. custom cursors of cursor_create)
76pub const CUR_ARROW: u32 = 0;
77pub const CUR_IBEAM: u32 = 1;
78pub const CUR_HAND: u32 = 2;
79pub const CUR_CROSS: u32 = 3;
80pub const CUR_MOVE: u32 = 4;
81pub const CUR_WAIT: u32 = 5;
82pub const CUR_SIZE_NS: u32 = 6;
83pub const CUR_SIZE_WE: u32 = 7;
84pub const CUR_SIZE_NWSE: u32 = 8;
85pub const CUR_SIZE_NESW: u32 = 9;
86pub const CUR_NONE: u32 = 10;
87pub const CUR_COUNT: u32 = 11;
88pub const CUR_CUSTOM: u32 = 15; // hit boxes only: the cursor chosen with the UI's custom call
89pub const CUR_USER0: u32 = 16;
90pub const CUR_USER_MAX: u32 = 32;
91pub const CUR_TABLE: u32 = CUR_USER0 + CUR_USER_MAX;
92pub const CUR_MAX_PX: i32 = 256; // cursor_create: largest width / height
93
94// ---- (E3) more system shapes: CSS's cursor names, past the custom cursors (CUR_X0 ..
95// CUR_X_END); a platform without one shows cursor_fallback's
96pub const CUR_X0: u32 = 64;
97pub const CUR_NOT_ALLOWED: u32 = 64; // not-allowed
98pub const CUR_NO_DROP: u32 = 65; // no-drop
99pub const CUR_GRAB: u32 = 66; // grab: an open hand
100pub const CUR_GRABBING: u32 = 67; // grabbing: a closed hand
101pub const CUR_HELP: u32 = 68; // help: the arrow with a question mark
102pub const CUR_PROGRESS: u32 = 69; // progress: the arrow with a busy sign (work in the background)
103pub const CUR_ZOOM_IN: u32 = 70; // zoom-in
104pub const CUR_ZOOM_OUT: u32 = 71; // zoom-out
105pub const CUR_CELL: u32 = 72; // cell: a thick cross (tables)
106pub const CUR_VTEXT: u32 = 73; // vertical-text
107pub const CUR_ALIAS: u32 = 74; // alias: a link will be made
108pub const CUR_COPY: u32 = 75; // copy: a copy will be made
109pub const CUR_CONTEXT_MENU: u32 = 76; // context-menu
110pub const CUR_ALL_SCROLL: u32 = 77; // all-scroll
111pub const CUR_COL_RESIZE: u32 = 78; // col-resize
112pub const CUR_ROW_RESIZE: u32 = 79; // row-resize
113pub const CUR_SIZE_N: u32 = 80; // n-resize: one edge or corner
114pub const CUR_SIZE_S: u32 = 81;
115pub const CUR_SIZE_E: u32 = 82;
116pub const CUR_SIZE_W: u32 = 83;
117pub const CUR_SIZE_NE: u32 = 84;
118pub const CUR_SIZE_NW: u32 = 85;
119pub const CUR_SIZE_SE: u32 = 86;
120pub const CUR_SIZE_SW: u32 = 87;
121pub const CUR_X_END: u32 = 88;
122
123/// (E3) the nearest of the first shapes (CUR_ARROW .. CUR_NONE) to a shape of CUR_X0 ..
124/// CUR_X_END, for the platforms and cursor themes without it; other shapes unchanged
125pub const fn cursor_fallback(shape: u32) -> u32 {
126    match shape {
127        CUR_GRAB => CUR_HAND,
128        CUR_GRABBING | CUR_ALL_SCROLL => CUR_MOVE,
129        CUR_PROGRESS => CUR_WAIT,
130        CUR_ZOOM_IN | CUR_ZOOM_OUT | CUR_CELL => CUR_CROSS,
131        CUR_VTEXT => CUR_IBEAM,
132        CUR_COL_RESIZE | CUR_SIZE_E | CUR_SIZE_W => CUR_SIZE_WE,
133        CUR_ROW_RESIZE | CUR_SIZE_N | CUR_SIZE_S => CUR_SIZE_NS,
134        CUR_SIZE_NE | CUR_SIZE_SW => CUR_SIZE_NESW,
135        CUR_SIZE_NW | CUR_SIZE_SE => CUR_SIZE_NWSE,
136        CUR_X0..CUR_X_END => CUR_ARROW,
137        _ => shape,
138    }
139}
140
141// ---- window edges, commands, states
142pub const EDGE_TOP: u32 = 1;
143pub const EDGE_BOTTOM: u32 = 2;
144pub const EDGE_LEFT: u32 = 4;
145pub const EDGE_RIGHT: u32 = 8;
146pub const WCMD_MINIMIZE: u32 = 1;
147pub const WCMD_MAXIMIZE: u32 = 2;
148pub const WCMD_RESTORE: u32 = 3;
149pub const WCMD_CLOSE: u32 = 4;
150pub const WST_MAXIMIZED: u32 = 1;
151pub const WST_FULLSCREEN: u32 = 2;
152pub const WST_ACTIVE: u32 = 4; // one of the APP's windows is active
153pub const WST_TILED: u32 = 8;
154pub const WST_MINIMIZED: u32 = 16;
155pub const WST_CSD: u32 = 32; // no system frame: the app must draw its own title bar
156/// the window is drawn inside its owner (a Wayland subsurface): win_get_rect / win_set_rect /
157/// E_WINPOS use positions relative to the owner's surface origin (px), the owner carries it
158pub const WST_CHILD: u32 = 64;
159/// with WST_TILED: which edges touch the tiling (EDGE_* << WST_TILED_SHIFT; Wayland's
160/// xdg_toplevel tiled_* states, X11 the edges of a one-direction maximize); the UI keeps its
161/// resize band off them, as from a maximized window
162pub const WST_TILED_SHIFT: u32 = 7;
163pub const WST_TILED_TOP: u32 = EDGE_TOP << WST_TILED_SHIFT;
164pub const WST_TILED_BOTTOM: u32 = EDGE_BOTTOM << WST_TILED_SHIFT;
165pub const WST_TILED_LEFT: u32 = EDGE_LEFT << WST_TILED_SHIFT;
166pub const WST_TILED_RIGHT: u32 = EDGE_RIGHT << WST_TILED_SHIFT;
167/// (Windows) the window is not shown, whoever hid it: the system hides a tool window while its owner
168/// is minimised
169pub const WST_HIDDEN: u32 = 1 << 11;
170
171// gpu_out_state: how the UI's output through the GPU came up
172/// nothing known, nothing to remember
173pub const GPU_STATE_UNKNOWN: u32 = 2;
174/// the first start is about to run a driver
175pub const GPU_STATE_TRYING: u32 = 3;
176/// a window showed through the GPU
177pub const GPU_STATE_OK: u32 = 4;
178/// this system cannot: the CPU path for good
179pub const GPU_STATE_NEVER: u32 = 5;
180
181// ---- clipboard formats
182pub const CLIP_TEXT: u32 = 1; // UTF-8
183pub const CLIP_PNG: u32 = 2; // PNG file bytes
184pub const CLIP_IMAGE: u32 = 3; // get: image file bytes (PNG, or DIB as BMP); set: PNG + DIB
185/// UTF-8 HTML fragment (Windows CF_HTML framing is handled by the platform).
186pub const CLIP_HTML: u32 = 4;
187/// Rich Text Format document bytes.
188pub const CLIP_RTF: u32 = 5;
189/// Private document fragment bytes, MIME application/x-jfgui-docx-fragment.
190pub const CLIP_DOCX: u32 = 6;
191
192// ---- platform windows (window-indexed API, docs/modules/WINDOWS_PLATFORM.md)
193pub const PW_MAX: usize = 8; // index 0 = the main window
194pub const PW_DEFAULT: i32 = i32::MIN; // win_create x / y: the system (or owner-relative) default
195pub const PW_KEEP: i32 = i32::MIN; // win_set_rect: leave this field unchanged
196pub const PW_NOOWNER: i32 = -1; // win_create owner: a top-level window
197pub const PWF_TOOL: u32 = 1; // win_create flags (the same bits as the UI's WF_*)
198pub const PWF_DIALOG: u32 = 2;
199pub const PWF_MODAL: u32 = 4;
200pub const PWF_RESIZABLE: u32 = 8;
201pub const PWF_NOCLOSE: u32 = 16;
202pub const PWF_SYSFRAME: u32 = 32; // system caption / border (else the app draws the frame)
203pub const PWF_NOACTIVATE: u32 = 64;
204pub const PWF_MASK: u32 = 127;
205pub const PWS_HIDE: u32 = 0; // win_show modes
206pub const PWS_SHOW: u32 = 1;
207pub const PWS_SHOWNA: u32 = 2; // show without activating
208pub const PPW_MAX: u32 = 4; // popup slots (popup())
209// popup_anchor kinds: how a popup hangs at its anchor when the platform places it (Wayland's
210// xdg_positioner; the compositor keeps it on screen)
211pub const PA_FREE: u32 = 0; // where it is (slides to stay on screen)
212pub const PA_BELOW: u32 = 1; // below the anchor; above it when there is no room
213pub const PA_ABOVE: u32 = 2; // above the anchor; below it when there is no room
214pub const PA_SIDE: u32 = 3; // beside the anchor (submenus); on its other side when there is no room
215pub const PA_POINT: u32 = 4; // at a point (context menus): flips both ways
216
217// ---- file dialog (file_dialog flags)
218pub const FD_OPEN: u32 = 0;
219pub const FD_SAVE: u32 = 1;
220pub const FD_FOLDER: u32 = 2; // choose a folder (Android: a document tree; Windows: the own dialog)
221pub const FD_MULTI: u32 = 4; // (E8) FD_OPEN: several files; all of them in file_dialog_paths()
222pub const FD_EXT_SHIFT: u32 = 8; // bits 8..15: initially selected extension (index)
223/// file_dialog's answer when the system answers later (Android's picker): file_dialog_poll
224pub const FD_PENDING: i32 = -2;
225
226// ---- UI hit-box flags the platform asks through the hit hook (HB_*)
227pub const HB_FOCUS: u32 = 1;
228pub const HB_BLOCK: u32 = 2;
229pub const HB_DRAG: u32 = 4; // window drag region (title bar)
230pub const HB_TEXT: u32 = 8; // text input
231pub const HB_MOVES: u32 = 16;
232pub const HB_DISABLED: u32 = 32;
233pub const HB_MIN: u32 = 64; // caption buttons (snap layouts, ...)
234pub const HB_MAX: u32 = 128;
235pub const HB_CLOSE: u32 = 256;
236pub const HB_CURSOR_SHIFT: u32 = 12;
237
238// ---- (L7) full screen: win_cmd commands; win_state reports WST_FULLSCREEN
239pub const WCMD_FULLSCREEN: u32 = 5; // the window covers its monitor without a frame
240pub const WCMD_WINDOWED: u32 = 6; // back to the place and frame it had before
241// below the other windows (a title bar action, TB_ACT_LOWER: X11 and Windows; Wayland has no
242// such request: nothing)
243pub const WCMD_LOWER: u32 = 7;