AtlatestRepositorysigil-ui

sigil-ui / tree / nativeappkit-host.h

1/* Trusted native-adapter API. No AppKit pointers cross the Sigil window API.
2 * Every function and callback runs synchronously on the main thread. Callbacks
3 * must not suspend, block, navigate or enter a script engine. Tokens are scoped
4 * to this process and never reused; stale tokens fail without touching AppKit.
5 */
6#ifndef SIGIL_UI_APPKIT_HOST_H
7#define SIGIL_UI_APPKIT_HOST_H
8#include <stdbool.h>
9#include <stdint.h>
10#ifdef __cplusplus
11extern "C" {
12#endif
14typedef uint64_t SUIHostToken;
15typedef uint64_t SUIChildToken;
16typedef uint64_t SUIHookToken;
18typedef struct {
19 double x, y, width, height; /* Logical top-left child allocation. */
20 double content_width, content_height;
21 int scale;
22 bool visible, focused;
23} SUIGeometry;
25typedef enum {
26 SUI_HOST_GEOMETRY, SUI_HOST_FOCUS, SUI_HOST_DEACTIVATED,
27 SUI_CHILD_WILL_DETACH, SUI_HOST_WILL_CLOSE
28} SUIHostEvent;
29typedef void (*SUIHostNotify)(void *context, SUIHostToken host,
30 SUIChildToken child, SUIHostEvent event, const SUIGeometry *geometry);
32typedef struct {
33 int action; /* 0 release, 1 press, 2 repeat. */
34 uint16_t hardware_code;
35 uint32_t modifiers; /* shift=1 control=2 alt=4 super=8 caps=16 num=32 */
36 SUIChildToken target; /* Zero means the sigil-ui canvas. */
37 const char *name, *text; /* Copied data, valid only during this callback. */
38} SUIKey;
39typedef bool (*SUIKeyFilter)(void *context, SUIHostToken host, const SUIKey *key);
41bool sigil_ui_appkit_host_valid(SUIHostToken host);
42bool sigil_ui_appkit_host_geometry(SUIHostToken host, SUIGeometry *geometry);
43/* native_view is an unparented NSView*, bridged by the trusted adapter. The
44 * host retains it until detach; the adapter keeps its own ownership. Higher
45 * order values draw above lower values, below the canvas overlay. */
46SUIChildToken sigil_ui_appkit_child_adopt(SUIHostToken host, void *native_view,
47 double x, double y, double width, double height, int order,
48 SUIHostNotify notify, void *context);
49bool sigil_ui_appkit_child_place(SUIHostToken host, SUIChildToken child,
50 double x, double y, double width, double height, int order);
51bool sigil_ui_appkit_child_remove(SUIHostToken host, SUIChildToken child);
52bool sigil_ui_appkit_focus_child(SUIHostToken host, SUIChildToken child);
53bool sigil_ui_appkit_focus_ui(SUIHostToken host);
54/* Filters run newest first on a press; consume/pass and target stick through
55 * its repeats/release. A passed child event follows native dispatch once.
56 * Removing a filter or changing focus cancels its pending key ownership. */
57SUIHookToken sigil_ui_appkit_key_filter_add(SUIHostToken host,
58 SUIKeyFilter filter, void *context);
59bool sigil_ui_appkit_key_filter_remove(SUIHostToken host, SUIHookToken hook);
60#ifdef __cplusplus
62#endif
63#endif