big api overhaul, moved unsupported bindings to archive

This commit is contained in:
Peterino2 2026-09-19 12:22:23 -07:00
parent 97bb36827f
commit f6686e66ec
29 changed files with 486 additions and 500 deletions

View File

@ -23,10 +23,17 @@ builds need Zig alone; the optional `shell.nix` supplies maintainer tools and
NixOS runtime library paths. See [Linux support and limitations](src/linux/README.md). NixOS runtime library paths. See [Linux support and limitations](src/linux/README.md).
Window decoration and resizing are selected through `uhdk_window_style` when a Window decoration and resizing are selected through `uhdk_window_style` when a
window is created and can be changed later with `uhdk_window_set_style_async`. window is created and can be changed later with `uhdk_window_set_style`.
Set `decorated` to false for application-drawn chrome; on Wayland this requests Set `decorated` to false for application-drawn chrome; on Wayland this requests
client-side decoration instead of the compositor's usual title bar and border. client-side decoration instead of the compositor's usual title bar and border.
The recommended window path queues `uhdk_window_create` and
`uhdk_gl_context_create` in setup order and returns stable handles immediately.
Window value commands do not create completion requests. Native creation failures
arrive as `UHDK_EVENT_RESOURCE_FAILED`; normal metrics and redraw events indicate
when a window can render. `uhdk_gl_context_try_begin_frame` combines that readiness
check with the framebuffer metrics needed by a renderer.
## Experimental desktop input and window observations ## Experimental desktop input and window observations
macOS uses AppKit editing selectors. Windows and Wayland share Ctrl-based defaults macOS uses AppKit editing selectors. Windows and Wayland share Ctrl-based defaults
@ -127,12 +134,13 @@ headers remain unmodified dependencies rather than being pasted into `uhdk.h`.
The public interface uses pointer-and-length text, `char` booleans, and `float` The public interface uses pointer-and-length text, `char` booleans, and `float`
coordinates. The native bridge is private; consumers do not need Objective-C. coordinates. The native bridge is private; consumers do not need Objective-C.
The library includes the GLAD loader implementation. With a current context inside The public header includes the GLAD declarations, while the application owns its
`uhdk_gl_context_begin_frame` / `uhdk_gl_context_end_frame`, call implementation. In exactly one translation unit, define
`UHDK_GLAD_GL_IMPLEMENTATION` before including `uhdk.h`. With a current context
inside `uhdk_gl_context_begin_frame` / `uhdk_gl_context_end_frame`, call
`gladLoadGLContextUserPtr` with a callback that resolves names using `gladLoadGLContextUserPtr` with a callback that resolves names using
`uhdk_gl_context_get_proc`. Keep a `GladGLContext` per native context; its members `uhdk_gl_context_get_proc`. Keep a `GladGLContext` per native context; its members
are named `Clear`, `DrawArrays`, etc. Check `VERSION_3_3` after loading. Do not define are named `Clear`, `DrawArrays`, etc. Check `VERSION_3_3` after loading.
`GLAD_GL_IMPLEMENTATION` in your application when linking libuhdk.
On Windows, the static artifact is `zig-out/lib/uhdk.lib`; shared builds install On Windows, the static artifact is `zig-out/lib/uhdk.lib`; shared builds install
`zig-out/bin/uhdk.dll` and its import library under `zig-out/lib/`. Keep the DLL `zig-out/bin/uhdk.dll` and its import library under `zig-out/lib/`. Keep the DLL

View File

@ -68,6 +68,7 @@ fn createLibraryNamed(b: *std.Build, target: std.Build.ResolvedTarget, optimize:
.target = target, .target = target,
.optimize = optimize, .optimize = optimize,
.link_libc = true, .link_libc = true,
.unwind_tables = if (optimize == .ReleaseSmall) .none else null,
}); });
const native = b.addTranslateC(.{ const native = b.addTranslateC(.{
@ -103,13 +104,14 @@ fn createLibraryNamed(b: *std.Build, target: std.Build.ResolvedTarget, optimize:
for ([_][]const u8{ "user32", "gdi32", "opengl32", "shell32", "ole32", "uuid", "imm32", "comctl32", "shlwapi", "advapi32", "api-ms-win-core-synch-l1-2-0" }) |name| module.linkSystemLibrary(name, .{}); for ([_][]const u8{ "user32", "gdi32", "opengl32", "shell32", "ole32", "uuid", "imm32", "comctl32", "shlwapi", "advapi32", "api-ms-win-core-synch-l1-2-0" }) |name| module.linkSystemLibrary(name, .{});
} }
module.addCSourceFile(.{ .file = b.path("src/platform_io.c"), .flags = &.{ "-std=c11", "-Wall", "-Wextra", "-Werror" } }); module.addCSourceFile(.{ .file = b.path("src/platform_io.c"), .flags = &.{ "-std=c11", "-Wall", "-Wextra", "-Werror" } });
module.addCSourceFile(.{ .file = b.path("src/glad.c"), .flags = if (shared) &.{ "-std=c99", "-DGLAD_API_CALL_EXPORT", "-DGLAD_API_CALL_EXPORT_BUILD" } else &.{"-std=c99"} });
const lib = b.addLibrary(.{ const lib = b.addLibrary(.{
.name = artifact_name, .name = artifact_name,
.linkage = if (shared) .dynamic else .static, .linkage = if (shared) .dynamic else .static,
.root_module = module, .root_module = module,
}); });
if (shared and target.result.os.tag == .linux)
lib.version_script = b.path("src/linux/exports.map");
// temp // temp
// lib.root_module.strip = false; // lib.root_module.strip = false;

View File

@ -5,8 +5,9 @@
`uhdk.h` with `UHDK_ENABLE_OPENGL` includes the generated `glad/gl.h`: `uhdk.h` with `UHDK_ENABLE_OPENGL` includes the generated `glad/gl.h`:
OpenGL 3.3 core, no OpenGL 3.3 core, no
extensions, header-only output, explicit per-context tables (`--mx`), and no extensions, header-only output, explicit per-context tables (`--mx`), and no
platform loader. `src/glad.c` compiles its implementation into libuhdk. Applications platform loader. Applications define `UHDK_GLAD_GL_IMPLEMENTATION` before
load a `GladGLContext` through their adapter for `uhdk_gl_context_get_proc`. including `uhdk.h` in exactly one translation unit, then load a `GladGLContext`
through their adapter for `uhdk_gl_context_get_proc`.
Generated unmodified with the pinned generator and its bundled Khronos snapshot: Generated unmodified with the pinned generator and its bundled Khronos snapshot:

View File

@ -1,6 +1,20 @@
#ifndef UHDK_H_INCLUDED #ifndef UHDK_H_INCLUDED
#define UHDK_H_INCLUDED #define UHDK_H_INCLUDED
/*
* uhdk provides a bundled glad implementation for loading opengl
*
* Define UHDK_GLAD_GL_IMPLEMENTATION to bring it into your compile unit.
* This should only be defined in a single compile unit per program
*
* you can use this as a convenience or load your own opengl integration
* */
#ifdef UHDK_GLAD_GL_IMPLEMENTATION
#define GLAD_GL_IMPLEMENTATION
#include "glad/gl.h"
#undef GLAD_GL_IMPLEMENTATION
#endif
/* /*
* Uhdk desktop platform API — v0.1, macOS, Windows and Linux backends. * Uhdk desktop platform API — v0.1, macOS, Windows and Linux backends.
* *
@ -70,6 +84,9 @@
* A pointer must use the same pool name for allocation and free. These hooks do * A pointer must use the same pool name for allocation and free. These hooks do
* not allocate/free memory themselves, intercept malloc, or transfer ownership. * not allocate/free memory themselves, intercept malloc, or transfer ownership.
*/ */
#define UHDK_ABI_VERSION 1u
#ifdef UHDK_PROFILE_BACKEND #ifdef UHDK_PROFILE_BACKEND
#include UHDK_PROFILE_BACKEND #include UHDK_PROFILE_BACKEND
#else #else
@ -105,7 +122,6 @@
extern "C" { extern "C" {
#endif #endif
#define UHDK_ABI_VERSION 1u
typedef char uhdk_bool; /* Values are UHDK_FALSE (0) or UHDK_TRUE (1). */ typedef char uhdk_bool; /* Values are UHDK_FALSE (0) or UHDK_TRUE (1). */
enum { enum {
@ -357,8 +373,8 @@ enum {
* not permission to stop processing events. suspended is a separate compositor * not permission to stop processing events. suspended is a separate compositor
* hint that content is not ordinarily repainted, not proof of occlusion or * hint that content is not ordinarily repainted, not proof of occlusion or
* minimization. Resizing is an advisory interactive size/move-loop * minimization. Resizing is an advisory interactive size/move-loop
* hint, not a guaranteed transaction around every size change. * hint, not a guaranteed transaction around every size change. Setters enqueue
* Async size/state completion acknowledges submission; geometry arrives here. */ * native work; geometry and state changes are observed here. */
typedef struct uhdk_window_metrics { typedef struct uhdk_window_metrics {
uint32_t struct_size; uint32_t struct_size;
uint32_t framebuffer_width; uint32_t framebuffer_width;
@ -375,44 +391,27 @@ typedef struct uhdk_window_metrics {
uhdk_bool suspended; uhdk_bool suspended;
} uhdk_window_metrics; } uhdk_window_metrics;
UHDK_API uhdk_status UHDK_CALL uhdk_window_create_async( /* Queue native creation and return a stable handle immediately. Creation
* failures arrive as RESOURCE_FAILED; success is observed through normal
* window metrics/redraw events. */
UHDK_API uhdk_status UHDK_CALL uhdk_window_create(
uhdk_app *app, uhdk_app *app,
const uhdk_window_desc *desc, const uhdk_window_desc *desc,
uhdk_request_id *out uhdk_window **out
); );
UHDK_API void UHDK_CALL uhdk_window_destroy(uhdk_window *window); UHDK_API void UHDK_CALL uhdk_window_destroy(uhdk_window *window);
UHDK_API uhdk_status UHDK_CALL uhdk_window_set_title_async( UHDK_API uhdk_status UHDK_CALL uhdk_window_set_title(uhdk_window *window, uhdk_text title);
uhdk_window *window, UHDK_API uhdk_status UHDK_CALL uhdk_window_set_size(uhdk_window *window, uhdk_size size);
uhdk_text title, UHDK_API uhdk_status UHDK_CALL uhdk_window_set_state(uhdk_window *window, uhdk_window_state state);
uhdk_request_id *out UHDK_API uhdk_status UHDK_CALL uhdk_window_set_visible(uhdk_window *window, uhdk_bool visible);
); UHDK_API uhdk_status UHDK_CALL uhdk_window_request_focus(uhdk_window *window);
UHDK_API uhdk_status UHDK_CALL uhdk_window_set_size_async(
uhdk_window *window,
uhdk_size size,
uhdk_request_id *out
);
UHDK_API uhdk_status UHDK_CALL uhdk_window_set_state_async(
uhdk_window *window,
uhdk_window_state state,
uhdk_request_id *out
);
UHDK_API uhdk_status UHDK_CALL uhdk_window_set_visible_async(
uhdk_window *window,
uhdk_bool visible,
uhdk_request_id *out
);
/* Change native decoration and resize styling without recreating the window. /* Change native decoration and resize styling without recreating the window.
* Completion acknowledges the native request; the window manager may apply it * The window manager may apply it asynchronously. Content dimensions remain
* asynchronously. Content dimensions remain content-area dimensions. */ * content-area dimensions. */
UHDK_API uhdk_status UHDK_CALL uhdk_window_set_style_async( UHDK_API uhdk_status UHDK_CALL uhdk_window_set_style(
uhdk_window *window, uhdk_window *window,
const uhdk_window_style *style, const uhdk_window_style *style
uhdk_request_id *out
); );
UHDK_API uhdk_status UHDK_CALL uhdk_window_request_focus_async(
uhdk_window *window,
uhdk_request_id *out
); /* OS may decline. */
UHDK_API uhdk_status UHDK_CALL uhdk_window_get_metrics( UHDK_API uhdk_status UHDK_CALL uhdk_window_get_metrics(
uhdk_window *window, uhdk_window *window,
uhdk_window_metrics *out uhdk_window_metrics *out
@ -451,9 +450,22 @@ UHDK_API void UHDK_CALL uhdk_window_invalidate(uhdk_window *window); /* Coalesce
* type before calling. GL uses stdcall on Win32; Uhdk exports still use C ABI. */ * type before calling. GL uses stdcall on Win32; Uhdk exports still use C ABI. */
typedef void(UHDK_GL_CALL *uhdk_gl_proc)(void); typedef void(UHDK_GL_CALL *uhdk_gl_proc)(void);
UHDK_API uhdk_status UHDK_CALL uhdk_gl_context_create_async( typedef struct uhdk_gl_frame {
uint32_t struct_size;
uhdk_bool drawable;
uint32_t reserved;
uhdk_window_metrics metrics;
} uhdk_gl_frame;
UHDK_API uhdk_status UHDK_CALL uhdk_gl_context_create(
uhdk_window *window, uhdk_window *window,
uhdk_request_id *out uhdk_gl_context **out
);
/* OK with drawable == 0 means the context or window is not ready to render.
* A drawable frame has made the context current and must be ended. */
UHDK_API uhdk_status UHDK_CALL uhdk_gl_context_try_begin_frame(
uhdk_gl_context *context,
uhdk_gl_frame *out
); );
UHDK_API uhdk_status UHDK_CALL uhdk_gl_context_begin_frame(uhdk_gl_context *context); UHDK_API uhdk_status UHDK_CALL uhdk_gl_context_begin_frame(uhdk_gl_context *context);
UHDK_API uhdk_status UHDK_CALL uhdk_gl_context_end_frame(uhdk_gl_context *context); UHDK_API uhdk_status UHDK_CALL uhdk_gl_context_end_frame(uhdk_gl_context *context);
@ -570,17 +582,15 @@ enum {
UHDK_POINTER_NORMAL = 0, UHDK_POINTER_NORMAL = 0,
UHDK_POINTER_CAPTURE = 1 UHDK_POINTER_CAPTURE = 1
}; };
UHDK_API uhdk_status UHDK_CALL uhdk_window_set_cursor_shape_async(
uhdk_window *window,
uhdk_cursor_shape shape,
uhdk_request_id *out
);
/* Capture delivers selection-drag events outside the window. Focus loss or OS /* Capture delivers selection-drag events outside the window. Focus loss or OS
* cancellation restores NORMAL and emits POINTER_MODE_CHANGED. */ * cancellation restores NORMAL and emits POINTER_MODE_CHANGED. */
UHDK_API uhdk_status UHDK_CALL uhdk_window_set_pointer_mode_async( UHDK_API uhdk_status UHDK_CALL uhdk_window_set_cursor_shape(
uhdk_window *window, uhdk_window *window,
uhdk_pointer_mode mode, uhdk_cursor_shape shape
uhdk_request_id *out );
UHDK_API uhdk_status UHDK_CALL uhdk_window_set_pointer_mode(
uhdk_window *window,
uhdk_pointer_mode mode
); );
/* Text offsets/lengths are UTF-8 byte counts, always at scalar boundaries. /* Text offsets/lengths are UTF-8 byte counts, always at scalar boundaries.
@ -609,19 +619,12 @@ typedef struct uhdk_text_state {
uint64_t selection_len; uint64_t selection_len;
uhdk_rect caret; /* Window-local logical coordinates. */ uhdk_rect caret; /* Window-local logical coordinates. */
} uhdk_text_state; } uhdk_text_state;
UHDK_API uhdk_status UHDK_CALL uhdk_window_set_text_input_async( UHDK_API uhdk_status UHDK_CALL uhdk_window_set_text_input(uhdk_window *window, uhdk_bool enabled);
uhdk_window *window,
uhdk_bool enabled,
uhdk_request_id *out
);
UHDK_API uhdk_status UHDK_CALL uhdk_window_set_text_state( UHDK_API uhdk_status UHDK_CALL uhdk_window_set_text_state(
uhdk_window *window, uhdk_window *window,
const uhdk_text_state *state const uhdk_text_state *state
); );
UHDK_API uhdk_status UHDK_CALL uhdk_window_cancel_composition_async( UHDK_API uhdk_status UHDK_CALL uhdk_window_cancel_composition(uhdk_window *window);
uhdk_window *window,
uhdk_request_id *out
);
/* File references preserve native names, including non-UTF-8 POSIX paths. /* File references preserve native names, including non-UTF-8 POSIX paths.
* Display names are UTF-8. URI/native-path export is explicit and owned by the * Display names are UTF-8. URI/native-path export is explicit and owned by the
@ -733,10 +736,9 @@ UHDK_API uhdk_status UHDK_CALL uhdk_file_dialog_show_async(
* max_bytes bounds the UTF-8 result; excess returns BUFFER_TOO_SMALL, never a * max_bytes bounds the UTF-8 result; excess returns BUFFER_TOO_SMALL, never a
* truncated string. A read remains async even when a backend can read instantly. * truncated string. A read remains async even when a backend can read instantly.
*/ */
UHDK_API uhdk_status UHDK_CALL uhdk_clipboard_write_text_async( UHDK_API uhdk_status UHDK_CALL uhdk_clipboard_write_text(
uhdk_app *app, uhdk_app *app,
uhdk_text text, uhdk_text text
uhdk_request_id *out
); );
UHDK_API uhdk_status UHDK_CALL uhdk_clipboard_read_text_async( UHDK_API uhdk_status UHDK_CALL uhdk_clipboard_read_text_async(
uhdk_app *app, uhdk_app *app,
@ -750,11 +752,7 @@ UHDK_API uhdk_status UHDK_CALL uhdk_clipboard_read_text_async(
* the application decides whether to open them. No source deletion, outgoing * the application decides whether to open them. No source deletion, outgoing
* drag, data offers, or application-visible drop-completion transaction. * drag, data offers, or application-visible drop-completion transaction.
*/ */
UHDK_API uhdk_status UHDK_CALL uhdk_window_set_drop_enabled_async( UHDK_API uhdk_status UHDK_CALL uhdk_window_set_drop_enabled(uhdk_window *window, uhdk_bool enabled);
uhdk_window *window,
uhdk_bool enabled,
uhdk_request_id *out
);
/* Menus are immutable snapshots. Command IDs are application-assigned, nonzero /* Menus are immutable snapshots. Command IDs are application-assigned, nonzero
* and unique within a menu tree. Shortcuts use logical keys + modifiers. * and unique within a menu tree. Shortcuts use logical keys + modifiers.
@ -797,23 +795,20 @@ UHDK_API uhdk_status UHDK_CALL uhdk_menu_create(
uint64_t len, uint64_t len,
uhdk_menu **out uhdk_menu **out
); );
UHDK_API uhdk_status UHDK_CALL uhdk_menu_set_item_flags_async( UHDK_API uhdk_status UHDK_CALL uhdk_menu_set_item_flags(
uhdk_menu *menu, uhdk_menu *menu,
uint64_t command_id, uint64_t command_id,
uhdk_menu_flags flags, uhdk_menu_flags flags
uhdk_request_id *out
); );
UHDK_API void UHDK_CALL uhdk_menu_retain(uhdk_menu *menu); UHDK_API void UHDK_CALL uhdk_menu_retain(uhdk_menu *menu);
UHDK_API void UHDK_CALL uhdk_menu_release(uhdk_menu *menu); UHDK_API void UHDK_CALL uhdk_menu_release(uhdk_menu *menu);
UHDK_API uhdk_status UHDK_CALL uhdk_app_set_menu_async( UHDK_API uhdk_status UHDK_CALL uhdk_app_set_menu(
uhdk_app *app, uhdk_app *app,
uhdk_menu *menu, uhdk_menu *menu
uhdk_request_id *out
); /* NULL clears. */ ); /* NULL clears. */
UHDK_API uhdk_status UHDK_CALL uhdk_window_set_menu_async( UHDK_API uhdk_status UHDK_CALL uhdk_window_set_menu(
uhdk_window *window, uhdk_window *window,
uhdk_menu *menu, uhdk_menu *menu
uhdk_request_id *out
); );
UHDK_API uhdk_status UHDK_CALL uhdk_menu_popup_async( UHDK_API uhdk_status UHDK_CALL uhdk_menu_popup_async(
uhdk_menu *menu, uhdk_menu *menu,
@ -821,10 +816,9 @@ UHDK_API uhdk_status UHDK_CALL uhdk_menu_popup_async(
uhdk_point position, uhdk_point position,
uhdk_request_id *out uhdk_request_id *out
); );
UHDK_API uhdk_status UHDK_CALL uhdk_app_set_icon_async( UHDK_API uhdk_status UHDK_CALL uhdk_app_set_icon(
uhdk_app *app, uhdk_app *app,
const uhdk_image *image, const uhdk_image *image
uhdk_request_id *out
); );
/* Successful shell completion means handed off to the OS, not that a target /* Successful shell completion means handed off to the OS, not that a target
@ -902,18 +896,28 @@ enum {
UHDK_EVENT_MENU_COMMAND, UHDK_EVENT_MENU_COMMAND,
UHDK_EVENT_DROP_FILES, UHDK_EVENT_DROP_FILES,
UHDK_EVENT_WATCH, UHDK_EVENT_WATCH,
UHDK_EVENT_REQUEST_DONE UHDK_EVENT_REQUEST_DONE,
UHDK_EVENT_RESOURCE_FAILED
}; };
typedef uint32_t uhdk_resource_kind;
enum {
UHDK_RESOURCE_WINDOW = 1,
UHDK_RESOURCE_GL_CONTEXT
};
typedef struct uhdk_resource_event {
uhdk_resource_kind kind;
uhdk_status status;
void *resource; /* Stable failed handle, selected by kind; valid until app destruction. */
} uhdk_resource_event;
typedef uint32_t uhdk_request_kind; typedef uint32_t uhdk_request_kind;
enum { enum {
UHDK_REQUEST_FILE_DIALOG = 1, UHDK_REQUEST_FILE_DIALOG = 1,
UHDK_REQUEST_CLIPBOARD_TEXT, UHDK_REQUEST_CLIPBOARD_TEXT,
UHDK_REQUEST_MENU_POPUP, UHDK_REQUEST_MENU_POPUP,
UHDK_REQUEST_SHELL, UHDK_REQUEST_SHELL,
UHDK_REQUEST_COMMAND,
UHDK_REQUEST_WINDOW,
UHDK_REQUEST_GL_CONTEXT,
UHDK_REQUEST_WATCH, UHDK_REQUEST_WATCH,
UHDK_REQUEST_FILE_READ, UHDK_REQUEST_FILE_READ,
UHDK_REQUEST_FILE_WRITE, UHDK_REQUEST_FILE_WRITE,
@ -1050,21 +1054,14 @@ typedef struct uhdk_activation_event {
typedef struct uhdk_pointer_mode_event { typedef struct uhdk_pointer_mode_event {
uhdk_pointer_mode mode; uhdk_pointer_mode mode;
} uhdk_pointer_mode_event; } uhdk_pointer_mode_event;
typedef struct uhdk_window_result {
uhdk_window *window;
} uhdk_window_result;
typedef struct uhdk_gl_context_result {
uhdk_gl_context *gl_context;
} uhdk_gl_context_result;
typedef struct uhdk_watch_result { typedef struct uhdk_watch_result {
uhdk_watch *watch; uhdk_watch *watch;
} uhdk_watch_result; } uhdk_watch_result;
/* Request data mapping (only valid on UHDK_STATUS_OK): /* Request data mapping (only valid on UHDK_STATUS_OK):
* FILE_DIALOG: uhdk_file_list; CLIPBOARD_TEXT: uhdk_text; * FILE_DIALOG: uhdk_file_list; CLIPBOARD_TEXT: uhdk_text;
* WINDOW: uhdk_window_result; GL_CONTEXT: uhdk_gl_context_result;
* WATCH: uhdk_watch_result; FILE_READ: uhdk_bytes; FILE_INFO: uhdk_file_info. * WATCH: uhdk_watch_result; FILE_READ: uhdk_bytes; FILE_INFO: uhdk_file_info.
* SHELL, COMMAND, FILE_WRITE, MENU_POPUP and failures have NULL/0 data. * SHELL, FILE_WRITE, MENU_POPUP and failures have NULL/0 data.
*/ */
typedef struct uhdk_request_result { typedef struct uhdk_request_result {
uhdk_request_id id; uhdk_request_id id;
@ -1082,7 +1079,8 @@ typedef struct uhdk_request_result {
* POINTER_MODE_CHANGED: uhdk_pointer_mode_event; SCROLL: uhdk_scroll_event; * POINTER_MODE_CHANGED: uhdk_pointer_mode_event; SCROLL: uhdk_scroll_event;
* TEXT_COMMIT/PREEDIT: uhdk_text_event; EDIT_COMMAND: uhdk_edit_event; * TEXT_COMMIT/PREEDIT: uhdk_text_event; EDIT_COMMAND: uhdk_edit_event;
* DROP_FILES: uhdk_drop_files_event; MENU_COMMAND: uhdk_menu_event; * DROP_FILES: uhdk_drop_files_event; MENU_COMMAND: uhdk_menu_event;
* WATCH: uhdk_watch_event; REQUEST_DONE: uhdk_request_result. * WATCH: uhdk_watch_event; RESOURCE_FAILED: uhdk_resource_event;
* REQUEST_DONE: uhdk_request_result.
* All other events have NULL/0 data. * All other events have NULL/0 data.
*/ */
struct uhdk_event { struct uhdk_event {
@ -1139,15 +1137,13 @@ UHDK_API uhdk_status UHDK_CALL uhdk_window_get_native(uhdk_window *window, uhdk_
#ifdef UHDK_ENABLE_OPENGL #ifdef UHDK_ENABLE_OPENGL
/* GLAD 2: OpenGL 3.3 core, no extensions, explicit per-context function table. /* GLAD 2: OpenGL 3.3 core, no extensions, explicit per-context function table.
* Do not combine with platform GL headers or GL/glcorearb.h. * Do not combine with platform GL headers or GL/glcorearb.h.
* The loader implementation is linked into libuhdk; consumers must not define * The loader implementation is consumer-owned. Define
* GLAD_GL_IMPLEMENTATION when linking that library. * UHDK_GLAD_GL_IMPLEMENTATION before including uhdk.h in exactly one translation
* unit, or provide another implementation of the bundled GLAD interface.
* Load a GladGLContext via gladLoadGLContextUserPtr and an adapter calling * Load a GladGLContext via gladLoadGLContextUserPtr and an adapter calling
* uhdk_gl_context_get_proc, inside a begin_frame/end_frame bracket. Keep one * uhdk_gl_context_get_proc, inside a begin_frame/end_frame bracket. Keep one
* table per context and use it only while that context is current. * table per context and use it only while that context is current.
*/ */
#if defined(UHDK_SHARED)
#define GLAD_API_CALL_EXPORT
#endif
#include "glad/gl.h" #include "glad/gl.h"
#endif /* UHDK_ENABLE_OPENGL */ #endif /* UHDK_ENABLE_OPENGL */

View File

@ -22,8 +22,6 @@ fn result(allocator: std.mem.Allocator, source: c.z_request_result) !c.uhdk_requ
c.UHDK_REQUEST_CLIPBOARD_TEXT => try store(c.uhdk_text, allocator, try abi.copyText(allocator, source.value.text)), c.UHDK_REQUEST_CLIPBOARD_TEXT => try store(c.uhdk_text, allocator, try abi.copyText(allocator, source.value.text)),
c.UHDK_REQUEST_FILE_READ => try store(c.uhdk_bytes, allocator, try abi.copyBytes(allocator, source.value.bytes)), c.UHDK_REQUEST_FILE_READ => try store(c.uhdk_bytes, allocator, try abi.copyBytes(allocator, source.value.bytes)),
c.UHDK_REQUEST_FILE_INFO => try store(c.uhdk_file_info, allocator, source.value.info), c.UHDK_REQUEST_FILE_INFO => try store(c.uhdk_file_info, allocator, source.value.info),
c.UHDK_REQUEST_WINDOW => try store(c.uhdk_window_result, allocator, .{ .window = source.value.window }),
c.UHDK_REQUEST_GL_CONTEXT => try store(c.uhdk_gl_context_result, allocator, .{ .gl_context = source.value.gl_context }),
c.UHDK_REQUEST_WATCH => try store(c.uhdk_watch_result, allocator, .{ .watch = source.value.watch }), c.UHDK_REQUEST_WATCH => try store(c.uhdk_watch_result, allocator, .{ .watch = source.value.watch }),
else => .{}, else => .{},
}; };
@ -53,6 +51,7 @@ pub fn pack(allocator: std.mem.Allocator, source: c.z_event) !c.uhdk_event {
}, },
c.UHDK_EVENT_MENU_COMMAND => try store(c.uhdk_menu_event, allocator, source.data.menu), c.UHDK_EVENT_MENU_COMMAND => try store(c.uhdk_menu_event, allocator, source.data.menu),
c.UHDK_EVENT_WATCH => try store(c.uhdk_watch_event, allocator, source.data.watch), c.UHDK_EVENT_WATCH => try store(c.uhdk_watch_event, allocator, source.data.watch),
c.UHDK_EVENT_RESOURCE_FAILED => try store(c.uhdk_resource_event, allocator, source.data.resource),
c.UHDK_EVENT_REQUEST_DONE => try store(c.uhdk_request_result, allocator, try result(allocator, source.data.request)), c.UHDK_EVENT_REQUEST_DONE => try store(c.uhdk_request_result, allocator, try result(allocator, source.data.request)),
else => .{}, else => .{},
}; };

View File

@ -1,4 +1,4 @@
//! One I/O-worker file operation. Each step transfers at most one chunk. //! One I/O-worker file operation. Each step transfers at most one chunk. may need more work to do batched chunking
const FileOperation = @This(); const FileOperation = @This();
const std = @import("std"); const std = @import("std");

View File

@ -7,6 +7,7 @@ const Resource = @import("Resource.zig");
const FileOperation = @import("FileOperation.zig"); const FileOperation = @import("FileOperation.zig");
const Request = @This(); const Request = @This();
pub const Completion = enum { request, resource, discard };
next: ?*Request = null, next: ?*Request = null,
queued_next: ?*Request = null, queued_next: ?*Request = null,
arena: abi.Arena, arena: abi.Arena,
@ -14,9 +15,10 @@ gpa: std.mem.Allocator,
data: c.z_command = std.mem.zeroes(c.z_command), data: c.z_command = std.mem.zeroes(c.z_command),
node: *Event, node: *Event,
id: u64 = 0, id: u64 = 0,
kind: u32 = c.UHDK_REQUEST_COMMAND, kind: u32 = 0,
cancelled: bool = false, cancelled: bool = false,
native_deferred: bool = false, native_deferred: bool = false,
completion: Completion = .request,
pins: std.ArrayList(*Resource) = .empty, pins: std.ArrayList(*Resource) = .empty,
file_operation: ?FileOperation = null, file_operation: ?FileOperation = null,

View File

@ -10,6 +10,7 @@ gpa: std.mem.Allocator,
arena: std.heap.ArenaAllocator, arena: std.heap.ArenaAllocator,
next: ?*Resource = null, next: ?*Resource = null,
alive: bool = true, alive: bool = true,
ready: bool,
refs: usize = 1, refs: usize = 1,
native: ?*anyopaque = null, native: ?*anyopaque = null,
payload: Payload, payload: Payload,
@ -65,6 +66,7 @@ pub fn init(application: *Application, resource_kind: Kind) Resource {
.app = application, .app = application,
.gpa = application.gpa, .gpa = application.gpa,
.arena = .init(application.gpa), .arena = .init(application.gpa),
.ready = resource_kind != .window and resource_kind != .gl,
.payload = switch (resource_kind) { .payload = switch (resource_kind) {
.window => .{ .window = .{} }, .window => .{ .window = .{} },
.gl => .{ .gl = .{} }, .gl => .{ .gl = .{} },

View File

@ -4,10 +4,9 @@ const c = @import("native");
const runtime = @import("../runtime.zig"); const runtime = @import("../runtime.zig");
const abi = @import("../abi.zig"); const abi = @import("../abi.zig");
pub export fn uhdk_clipboard_write_text_async( pub export fn uhdk_clipboard_write_text(
handle: ?*c.uhdk_app, handle: ?*c.uhdk_app,
text: c.uhdk_text, text: c.uhdk_text,
out: [*c]u64,
) abi.Status { ) abi.Status {
if (!abi.validText(text, false)) return abi.INVALID; if (!abi.validText(text, false)) return abi.INVALID;
const command = runtime.createAppCommand(handle, c.Z_CLIP_WRITE) catch |err| return runtime.applicationError(err); const command = runtime.createAppCommand(handle, c.Z_CLIP_WRITE) catch |err| return runtime.applicationError(err);
@ -15,7 +14,7 @@ pub export fn uhdk_clipboard_write_text_async(
runtime.abandon(command); runtime.abandon(command);
return abi.OOM; return abi.OOM;
}; };
return runtime.submit(runtime.fromAppHandle(handle), command, out); return runtime.submitCommand(runtime.fromAppHandle(handle), command);
} }
pub export fn uhdk_clipboard_read_text_async( pub export fn uhdk_clipboard_read_text_async(
@ -44,10 +43,9 @@ pub export fn uhdk_shell_open_url_async(
return runtime.submit(runtime.fromAppHandle(handle), command, out); return runtime.submit(runtime.fromAppHandle(handle), command, out);
} }
pub export fn uhdk_app_set_icon_async( pub export fn uhdk_app_set_icon(
handle: ?*c.uhdk_app, handle: ?*c.uhdk_app,
image: [*c]const c.uhdk_image, image: [*c]const c.uhdk_image,
out: [*c]u64,
) abi.Status { ) abi.Status {
if (!abi.validDescriptor(c.uhdk_image, image)) return abi.INVALID; if (!abi.validDescriptor(c.uhdk_image, image)) return abi.INVALID;
const i = image.*; const i = image.*;
@ -66,7 +64,7 @@ pub export fn uhdk_app_set_icon_async(
runtime.abandon(command); runtime.abandon(command);
return abi.OOM; return abi.OOM;
}; };
return runtime.submit(runtime.fromAppHandle(handle), command, out); return runtime.submitCommand(runtime.fromAppHandle(handle), command);
} }
pub export fn uhdk_app_get_preferences( pub export fn uhdk_app_get_preferences(

View File

@ -5,7 +5,8 @@ const c = @import("native");
const runtime = @import("../runtime.zig"); const runtime = @import("../runtime.zig");
const abi = @import("../abi.zig"); const abi = @import("../abi.zig");
pub export fn uhdk_gl_context_create_async(handle: ?*c.uhdk_window, out: [*c]u64) abi.Status { pub export fn uhdk_gl_context_create(handle: ?*c.uhdk_window, out: [*c]?*c.uhdk_gl_context) abi.Status {
if (out == null) return abi.INVALID;
const command = runtime.createObjectCommand(handle, c.Z_KIND_WINDOW, c.Z_GL) catch |err| return runtime.objectError(err); const command = runtime.createObjectCommand(handle, c.Z_KIND_WINDOW, c.Z_GL) catch |err| return runtime.objectError(err);
const w = runtime.fromObjectHandle(handle); const w = runtime.fromObjectHandle(handle);
if (w.payload.window.context != null) { if (w.payload.window.context != null) {
@ -19,8 +20,9 @@ pub export fn uhdk_gl_context_create_async(handle: ?*c.uhdk_window, out: [*c]u64
object.payload.gl.owner = w; object.payload.gl.owner = w;
w.payload.window.context = object; w.payload.window.context = object;
command.data.other = object; command.data.other = object;
command.kind = c.UHDK_REQUEST_GL_CONTEXT; const status = runtime.submitResource(w.app, command);
return runtime.submit(w.app, command, out); if (status == abi.OK) out.* = runtime.castHandle(*c.uhdk_gl_context, object);
return status;
} }
pub export fn uhdk_gl_context_destroy(handle: ?*c.uhdk_gl_context) void { pub export fn uhdk_gl_context_destroy(handle: ?*c.uhdk_gl_context) void {
@ -46,6 +48,31 @@ pub export fn uhdk_gl_context_begin_frame(handle: ?*c.uhdk_gl_context) abi.Statu
return status; return status;
} }
pub export fn uhdk_gl_context_try_begin_frame(
handle: ?*c.uhdk_gl_context,
out: [*c]c.uhdk_gl_frame,
) abi.Status {
if (!abi.validDescriptor(c.uhdk_gl_frame, out)) return abi.INVALID;
out.*.drawable = 0;
out.*.reserved = 0;
out.*.metrics = std.mem.zeroes(c.uhdk_window_metrics);
out.*.metrics.struct_size = @sizeOf(c.uhdk_window_metrics);
if (handle == null) return abi.INVALID;
const object = runtime.fromObjectHandle(handle);
const valid = runtime.checkObject(object, c.Z_KIND_GL);
if (valid != abi.OK) return valid;
const owner = object.payload.gl.owner orelse return abi.UNAVAILABLE;
object.app.lock();
out.*.metrics = owner.payload.window.metrics;
object.app.unlock();
out.*.metrics.struct_size = @sizeOf(c.uhdk_window_metrics);
if (object.native == null or out.*.metrics.visible == 0 or
out.*.metrics.framebuffer_width == 0 or out.*.metrics.framebuffer_height == 0) return abi.OK;
const status = uhdk_gl_context_begin_frame(handle);
if (status == abi.OK) out.*.drawable = 1;
return status;
}
pub export fn uhdk_gl_context_end_frame(handle: ?*c.uhdk_gl_context) abi.Status { pub export fn uhdk_gl_context_end_frame(handle: ?*c.uhdk_gl_context) abi.Status {
const status = runtime.glCall(handle, 2, null); const status = runtime.glCall(handle, 2, null);
if (status == abi.OK) { if (status == abi.OK) {

View File

@ -4,38 +4,23 @@ const c = @import("native");
const runtime = @import("../runtime.zig"); const runtime = @import("../runtime.zig");
const abi = @import("../abi.zig"); const abi = @import("../abi.zig");
pub export fn uhdk_window_set_cursor_shape_async( pub export fn uhdk_window_set_cursor_shape(handle: ?*c.uhdk_window, shape: u32) abi.Status {
handle: ?*c.uhdk_window,
shape: u32,
out: [*c]u64,
) abi.Status {
if (shape > c.UHDK_CURSOR_HIDDEN) return abi.INVALID; if (shape > c.UHDK_CURSOR_HIDDEN) return abi.INVALID;
return runtime.scalarCommand(handle, c.Z_KIND_WINDOW, c.Z_CURSOR, shape, out); return runtime.scalarCommandValue(handle, c.Z_KIND_WINDOW, c.Z_CURSOR, shape);
} }
pub export fn uhdk_window_set_pointer_mode_async( pub export fn uhdk_window_set_pointer_mode(handle: ?*c.uhdk_window, mode: u32) abi.Status {
handle: ?*c.uhdk_window,
mode: u32,
out: [*c]u64,
) abi.Status {
if (mode > 1) return abi.INVALID; if (mode > 1) return abi.INVALID;
return runtime.scalarCommand(handle, c.Z_KIND_WINDOW, c.Z_POINTER, mode, out); return runtime.scalarCommandValue(handle, c.Z_KIND_WINDOW, c.Z_POINTER, mode);
} }
pub export fn uhdk_window_set_text_input_async( pub export fn uhdk_window_set_text_input(handle: ?*c.uhdk_window, enabled: c.uhdk_bool) abi.Status {
handle: ?*c.uhdk_window,
enabled: c.uhdk_bool,
out: [*c]u64,
) abi.Status {
if (enabled != 0 and enabled != 1) return abi.INVALID; if (enabled != 0 and enabled != 1) return abi.INVALID;
return runtime.scalarCommand(handle, c.Z_KIND_WINDOW, c.Z_TEXT_ENABLE, @intCast(enabled), out); return runtime.scalarCommandValue(handle, c.Z_KIND_WINDOW, c.Z_TEXT_ENABLE, @intCast(enabled));
} }
pub export fn uhdk_window_cancel_composition_async( pub export fn uhdk_window_cancel_composition(handle: ?*c.uhdk_window) abi.Status {
handle: ?*c.uhdk_window, return runtime.scalarCommandValue(handle, c.Z_KIND_WINDOW, c.Z_TEXT_CANCEL, 0);
out: [*c]u64,
) abi.Status {
return runtime.scalarCommand(handle, c.Z_KIND_WINDOW, c.Z_TEXT_CANCEL, 0, out);
} }
pub export fn uhdk_window_set_text_state( pub export fn uhdk_window_set_text_state(
@ -70,11 +55,7 @@ pub export fn uhdk_window_set_text_state(
return abi.OK; return abi.OK;
} }
pub export fn uhdk_window_set_drop_enabled_async( pub export fn uhdk_window_set_drop_enabled(handle: ?*c.uhdk_window, enabled: c.uhdk_bool) abi.Status {
handle: ?*c.uhdk_window,
enabled: c.uhdk_bool,
out: [*c]u64,
) abi.Status {
if (enabled != 0 and enabled != 1) return abi.INVALID; if (enabled != 0 and enabled != 1) return abi.INVALID;
return runtime.scalarCommand(handle, c.Z_KIND_WINDOW, c.Z_DROP, @intCast(enabled), out); return runtime.scalarCommandValue(handle, c.Z_KIND_WINDOW, c.Z_DROP, @intCast(enabled));
} }

View File

@ -61,34 +61,31 @@ pub export fn uhdk_menu_release(handle: ?*c.uhdk_menu) void {
if (handle != null) runtime.release(runtime.fromObjectHandle(handle)); if (handle != null) runtime.release(runtime.fromObjectHandle(handle));
} }
pub export fn uhdk_app_set_menu_async( pub export fn uhdk_app_set_menu(
handle: ?*c.uhdk_app, handle: ?*c.uhdk_app,
menu: ?*c.uhdk_menu, menu: ?*c.uhdk_menu,
out: [*c]u64,
) abi.Status { ) abi.Status {
return runtime.attachMenu(handle, null, menu, out); return runtime.attachMenu(handle, null, menu);
} }
pub export fn uhdk_window_set_menu_async( pub export fn uhdk_window_set_menu(
handle: ?*c.uhdk_window, handle: ?*c.uhdk_window,
menu: ?*c.uhdk_menu, menu: ?*c.uhdk_menu,
out: [*c]u64,
) abi.Status { ) abi.Status {
if (handle == null) return abi.INVALID; if (handle == null) return abi.INVALID;
return runtime.attachMenu(runtime.toAppHandle(runtime.fromObjectHandle(handle).app), handle, menu, out); return runtime.attachMenu(runtime.toAppHandle(runtime.fromObjectHandle(handle).app), handle, menu);
} }
pub export fn uhdk_menu_set_item_flags_async( pub export fn uhdk_menu_set_item_flags(
handle: ?*c.uhdk_menu, handle: ?*c.uhdk_menu,
id: u64, id: u64,
flags: u32, flags: u32,
out: [*c]u64,
) abi.Status { ) abi.Status {
if (id == 0 or flags & ~@as(u32, 3) != 0) return abi.INVALID; if (id == 0 or flags & ~@as(u32, 3) != 0) return abi.INVALID;
const command = runtime.createObjectCommand(handle, c.Z_KIND_MENU, c.Z_MENU_FLAGS) catch |err| return runtime.objectError(err); const command = runtime.createObjectCommand(handle, c.Z_KIND_MENU, c.Z_MENU_FLAGS) catch |err| return runtime.objectError(err);
command.data.number = id; command.data.number = id;
command.data.limit = flags; command.data.limit = flags;
return runtime.submit(runtime.fromObjectHandle(handle).app, command, out); return runtime.submitCommand(runtime.fromObjectHandle(handle).app, command);
} }
pub export fn uhdk_menu_popup_async( pub export fn uhdk_menu_popup_async(

View File

@ -4,12 +4,13 @@ const c = @import("native");
const runtime = @import("../runtime.zig"); const runtime = @import("../runtime.zig");
const abi = @import("../abi.zig"); const abi = @import("../abi.zig");
pub export fn uhdk_window_create_async( pub export fn uhdk_window_create(
handle: ?*c.uhdk_app, handle: ?*c.uhdk_app,
desc: [*c]const c.uhdk_window_desc, desc: [*c]const c.uhdk_window_desc,
out: [*c]u64, out: [*c]?*c.uhdk_window,
) abi.Status { ) abi.Status {
if (handle == null or !abi.validDescriptor(c.uhdk_window_desc, desc)) return abi.INVALID; if (handle == null or !abi.validDescriptor(c.uhdk_window_desc, desc)) return abi.INVALID;
if (out == null) return abi.INVALID;
const d = desc.*; const d = desc.*;
if (!validStyle(&d.style) or if (!validStyle(&d.style) or
!abi.validText(d.title, true) or !abi.validText(d.title, true) or
@ -31,14 +32,14 @@ pub export fn uhdk_window_create_async(
object.payload.window.parent = if (d.parent) |parent| runtime.fromObjectHandle(parent) else null; object.payload.window.parent = if (d.parent) |parent| runtime.fromObjectHandle(parent) else null;
command.data.target = object; command.data.target = object;
command.data.window = d; command.data.window = d;
command.kind = c.UHDK_REQUEST_WINDOW;
command.data.window.title = abi.copyText(command.arena.allocator(), d.title) catch { command.data.window.title = abi.copyText(command.arena.allocator(), d.title) catch {
runtime.abandon(command); runtime.abandon(command);
object.alive = false; object.alive = false;
return abi.OOM; return abi.OOM;
}; };
const status = runtime.submit(runtime.fromAppHandle(handle), command, out); const status = runtime.submitResource(runtime.fromAppHandle(handle), command);
if (status != abi.OK) object.alive = false; if (status != abi.OK) object.alive = false;
if (status == abi.OK) out.* = runtime.castHandle(*c.uhdk_window, object);
return status; return status;
} }
@ -53,56 +54,39 @@ pub export fn uhdk_window_destroy(handle: ?*c.uhdk_window) void {
if (handle) |_| runtime.destroyObject(runtime.fromObjectHandle(handle)); if (handle) |_| runtime.destroyObject(runtime.fromObjectHandle(handle));
} }
pub export fn uhdk_window_set_title_async( pub export fn uhdk_window_set_title(handle: ?*c.uhdk_window, title: c.uhdk_text) abi.Status {
handle: ?*c.uhdk_window, return runtime.textCommandValue(handle, c.Z_KIND_WINDOW, c.Z_TITLE, title);
title: c.uhdk_text,
out: [*c]u64,
) abi.Status {
return runtime.textCommand(handle, c.Z_KIND_WINDOW, c.Z_TITLE, title, out);
} }
pub export fn uhdk_window_set_size_async( pub export fn uhdk_window_set_size(handle: ?*c.uhdk_window, size: c.uhdk_size) abi.Status {
handle: ?*c.uhdk_window,
size: c.uhdk_size,
out: [*c]u64,
) abi.Status {
if (!abi.finiteSize(size) or size.width == 0 or size.height == 0) return abi.INVALID; if (!abi.finiteSize(size) or size.width == 0 or size.height == 0) return abi.INVALID;
const command = runtime.createObjectCommand(handle, c.Z_KIND_WINDOW, c.Z_SIZE) catch |err| return runtime.objectError(err); const command = runtime.createObjectCommand(handle, c.Z_KIND_WINDOW, c.Z_SIZE) catch |err| return runtime.objectError(err);
command.data.size = size; command.data.size = size;
return runtime.submit(runtime.fromObjectHandle(handle).app, command, out); return runtime.submitCommand(runtime.fromObjectHandle(handle).app, command);
} }
pub export fn uhdk_window_set_state_async( pub export fn uhdk_window_set_state(handle: ?*c.uhdk_window, state: c.uhdk_window_state) abi.Status {
handle: ?*c.uhdk_window,
state: c.uhdk_window_state,
out: [*c]u64,
) abi.Status {
if (state > c.UHDK_WINDOW_FULLSCREEN) return abi.INVALID; if (state > c.UHDK_WINDOW_FULLSCREEN) return abi.INVALID;
return runtime.scalarCommand(handle, c.Z_KIND_WINDOW, c.Z_STATE, state, out); return runtime.scalarCommandValue(handle, c.Z_KIND_WINDOW, c.Z_STATE, state);
} }
pub export fn uhdk_window_set_visible_async( pub export fn uhdk_window_set_visible(handle: ?*c.uhdk_window, visible: c.uhdk_bool) abi.Status {
handle: ?*c.uhdk_window,
visible: c.uhdk_bool,
out: [*c]u64,
) abi.Status {
if (visible != 0 and visible != 1) return abi.INVALID; if (visible != 0 and visible != 1) return abi.INVALID;
return runtime.scalarCommand(handle, c.Z_KIND_WINDOW, c.Z_VISIBLE, @intCast(visible), out); return runtime.scalarCommandValue(handle, c.Z_KIND_WINDOW, c.Z_VISIBLE, @intCast(visible));
} }
pub export fn uhdk_window_set_style_async( pub export fn uhdk_window_set_style(
handle: ?*c.uhdk_window, handle: ?*c.uhdk_window,
style: [*c]const c.uhdk_window_style, style: [*c]const c.uhdk_window_style,
out: [*c]u64,
) abi.Status { ) abi.Status {
if (!validStyle(style)) return abi.INVALID; if (!validStyle(style)) return abi.INVALID;
const command = runtime.createObjectCommand(handle, c.Z_KIND_WINDOW, c.Z_STYLE) catch |err| return runtime.objectError(err); const command = runtime.createObjectCommand(handle, c.Z_KIND_WINDOW, c.Z_STYLE) catch |err| return runtime.objectError(err);
command.data.style = style.*; command.data.style = style.*;
return runtime.submit(runtime.fromObjectHandle(handle).app, command, out); return runtime.submitCommand(runtime.fromObjectHandle(handle).app, command);
} }
pub export fn uhdk_window_request_focus_async(handle: ?*c.uhdk_window, out: [*c]u64) abi.Status { pub export fn uhdk_window_request_focus(handle: ?*c.uhdk_window) abi.Status {
return runtime.scalarCommand(handle, c.Z_KIND_WINDOW, c.Z_FOCUS, 0, out); return runtime.scalarCommandValue(handle, c.Z_KIND_WINDOW, c.Z_FOCUS, 0);
} }
pub export fn uhdk_window_get_metrics( pub export fn uhdk_window_get_metrics(

View File

@ -1,3 +0,0 @@
/* Implementation for the vendored GLAD 3.3 core header. */
#define GLAD_GL_IMPLEMENTATION
#include "glad/gl.h"

View File

@ -42,7 +42,7 @@ pub fn finish(b: *native.Backend) void {
b.egl_display = null; b.egl_display = null;
} }
} }
pub fn create(b: *native.Backend, w: *native.Window, object: ?*anyopaque, result: [*c]n.z_request_result) u32 { pub fn create(b: *native.Backend, w: *native.Window, object: ?*anyopaque) u32 {
if (b.egl_display == null or w.flags & n.UHDK_WINDOW_OPENGL == 0) return n.UHDK_STATUS_UNSUPPORTED; if (b.egl_display == null or w.flags & n.UHDK_WINDOW_OPENGL == 0) return n.UHDK_STATUS_UNSUPPORTED;
if (w.egl != null) return n.UHDK_STATUS_BUSY; if (w.egl != null) return n.UHDK_STATUS_BUSY;
if (c.z_eglBindAPI.?(c.EGL_OPENGL_API) == c.EGL_FALSE) return n.UHDK_STATUS_OS_ERROR; if (c.z_eglBindAPI.?(c.EGL_OPENGL_API) == c.EGL_FALSE) return n.UHDK_STATUS_OS_ERROR;
@ -69,7 +69,6 @@ pub fn create(b: *native.Backend, w: *native.Window, object: ?*anyopaque, result
ctx.* = .{ .window = w, .native = win, .surface = surface, .context = context }; ctx.* = .{ .window = w, .native = win, .surface = surface, .context = context };
w.egl = ctx; w.egl = ctx;
n.z_object_set_native(object, ctx); n.z_object_set_native(object, ctx);
result.*.value.gl_context = @ptrCast(object);
return abi.OK; return abi.OK;
} }
pub fn destroy(ctx: *Context) void { pub fn destroy(ctx: *Context) void {

View File

@ -86,7 +86,7 @@ NixOS with Plasma 6.5.6 and Mesa 25.2.6; other systems are not runtime-qualified
- A decorated window requires xdg-decoration server-side mode. A compositor that - A decorated window requires xdg-decoration server-side mode. A compositor that
lacks it returns `UNSUPPORTED`; a libdecor adapter is future work. Undecorated lacks it returns `UNSUPPORTED`; a libdecor adapter is future work. Undecorated
windows remain possible, and `uhdk_window_set_style_async` can switch the windows remain possible, and `uhdk_window_set_style` can switch the
decoration request at runtime. No desktop-name checks or Qt/KDE linkage are used. decoration request at runtime. No desktop-name checks or Qt/KDE linkage are used.
- The application ID is copied from `uhdk_app_desc` and sent as the xdg-toplevel - The application ID is copied from `uhdk_app_desc` and sent as the xdg-toplevel
app ID. Applications own their desktop-file and icon installation. app ID. Applications own their desktop-file and icon installation.

View File

@ -15,7 +15,7 @@ pub fn configure(b: *std.Build, module: *std.Build.Module, target: std.Build.Res
for ([_][]const u8{ "wayland", "xdg-shell", "xdg-decoration-unstable-v1", "viewporter", "fractional-scale-v1", "cursor-shape-v1", "tablet-v2", "text-input-unstable-v3", "xdg-activation-v1", "xdg-foreign-unstable-v2", "xdg-toplevel-icon-v1", "appmenu" }) |name| { for ([_][]const u8{ "wayland", "xdg-shell", "xdg-decoration-unstable-v1", "viewporter", "fractional-scale-v1", "cursor-shape-v1", "tablet-v2", "text-input-unstable-v3", "xdg-activation-v1", "xdg-foreign-unstable-v2", "xdg-toplevel-icon-v1", "appmenu" }) |name| {
module.addCSourceFile(.{ module.addCSourceFile(.{
.file = b.path(b.fmt("src/linux/protocols/generated/{s}.c", .{name})), .file = b.path(b.fmt("src/linux/protocols/generated/{s}.c", .{name})),
.flags = &.{ "-std=c99", "-include", b.path("src/linux/protocols/generated/private-symbols.h").getPath(b) }, .flags = &.{ "-std=c99", "-fdata-sections", "-include", b.path("src/linux/protocols/generated/private-symbols.h").getPath(b) },
}); });
} }
module.linkSystemLibrary("dl", .{}); module.linkSystemLibrary("dl", .{});
@ -24,7 +24,7 @@ pub fn configure(b: *std.Build, module: *std.Build.Module, target: std.Build.Res
pub fn addTests(b: *std.Build, lib: *std.Build.Step.Compile, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, check: *std.Build.Step) void { pub fn addTests(b: *std.Build, lib: *std.Build.Step.Compile, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, check: *std.Build.Step) void {
const test_module = b.createModule(.{ .target = target, .optimize = optimize, .link_libc = true }); const test_module = b.createModule(.{ .target = target, .optimize = optimize, .link_libc = true });
test_module.addIncludePath(b.path("include")); test_module.addIncludePath(b.path("include"));
test_module.addCSourceFile(.{ .file = b.path("src/linux/tests/native.c"), .flags = &.{ "-std=c99", "-Wall", "-Wextra", "-Werror" } }); test_module.addCSourceFile(.{ .file = b.path("src/linux/tests/native.c"), .flags = &.{ "-std=c99", "-Wall", "-Wextra", "-Werror", "-UNDEBUG" } });
test_module.linkLibrary(lib); test_module.linkLibrary(lib);
const exe = b.addExecutable(.{ .name = "linux-native-tests", .root_module = test_module }); const exe = b.addExecutable(.{ .name = "linux-native-tests", .root_module = test_module });
check.dependOn(&exe.step); check.dependOn(&exe.step);
@ -39,7 +39,7 @@ pub fn addTests(b: *std.Build, lib: *std.Build.Step.Compile, target: std.Build.R
pub fn addServiceTests(b: *std.Build, lib: *std.Build.Step.Compile, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, check: *std.Build.Step) void { pub fn addServiceTests(b: *std.Build, lib: *std.Build.Step.Compile, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, check: *std.Build.Step) void {
const module = b.createModule(.{ .target = target, .optimize = optimize, .link_libc = true }); const module = b.createModule(.{ .target = target, .optimize = optimize, .link_libc = true });
module.addIncludePath(b.path("include")); module.addIncludePath(b.path("include"));
module.addCSourceFile(.{ .file = b.path("src/linux/tests/services.c"), .flags = &.{ "-std=c99", "-Wall", "-Wextra", "-Werror" } }); module.addCSourceFile(.{ .file = b.path("src/linux/tests/services.c"), .flags = &.{ "-std=c99", "-Wall", "-Wextra", "-Werror", "-UNDEBUG" } });
module.linkLibrary(lib); module.linkLibrary(lib);
const exe = b.addExecutable(.{ .name = "linux-service-tests", .root_module = module }); const exe = b.addExecutable(.{ .name = "linux-service-tests", .root_module = module });
check.dependOn(&exe.step); check.dependOn(&exe.step);

6
src/linux/exports.map Normal file
View File

@ -0,0 +1,6 @@
{
global:
uhdk_*;
local:
*;
};

View File

@ -1,89 +1,93 @@
Z_FUNCTION(wl_display_connect) Z_REQUIRED(wl_display_connect)
Z_FUNCTION(wl_display_disconnect) Z_REQUIRED(wl_display_disconnect)
Z_FUNCTION(wl_display_get_fd) Z_REQUIRED(wl_display_get_fd)
Z_FUNCTION(wl_display_dispatch_pending) Z_REQUIRED(wl_display_dispatch_pending)
Z_FUNCTION(wl_display_prepare_read) Z_REQUIRED(wl_display_prepare_read)
Z_FUNCTION(wl_display_read_events) Z_REQUIRED(wl_display_read_events)
Z_FUNCTION(wl_display_cancel_read) Z_REQUIRED(wl_display_cancel_read)
Z_FUNCTION(wl_display_flush) Z_REQUIRED(wl_display_flush)
Z_FUNCTION(wl_proxy_marshal_flags) Z_REQUIRED(wl_proxy_marshal_flags)
Z_FUNCTION(wl_proxy_add_listener) Z_REQUIRED(wl_proxy_add_listener)
Z_FUNCTION(wl_proxy_destroy) Z_REQUIRED(wl_proxy_destroy)
Z_FUNCTION(wl_proxy_get_version) Z_REQUIRED(wl_proxy_get_version)
Z_FUNCTION(wl_proxy_set_user_data) Z_REQUIRED(wl_proxy_set_user_data)
Z_FUNCTION(wl_proxy_get_user_data) Z_REQUIRED(wl_proxy_get_user_data)
Z_FUNCTION(wl_egl_window_create)
Z_FUNCTION(wl_egl_window_destroy) Z_OPTIONAL(wayland_egl, have_egl, wl_egl_window_create)
Z_FUNCTION(wl_egl_window_resize) Z_OPTIONAL(wayland_egl, have_egl, wl_egl_window_destroy)
Z_FUNCTION(eglGetPlatformDisplay) Z_OPTIONAL(wayland_egl, have_egl, wl_egl_window_resize)
Z_FUNCTION(eglInitialize)
Z_FUNCTION(eglTerminate) Z_OPTIONAL(egl, have_egl, eglGetPlatformDisplay)
Z_FUNCTION(eglBindAPI) Z_OPTIONAL(egl, have_egl, eglInitialize)
Z_FUNCTION(eglChooseConfig) Z_OPTIONAL(egl, have_egl, eglTerminate)
Z_FUNCTION(eglCreateContext) Z_OPTIONAL(egl, have_egl, eglBindAPI)
Z_FUNCTION(eglDestroyContext) Z_OPTIONAL(egl, have_egl, eglChooseConfig)
Z_FUNCTION(eglCreateWindowSurface) Z_OPTIONAL(egl, have_egl, eglCreateContext)
Z_FUNCTION(eglDestroySurface) Z_OPTIONAL(egl, have_egl, eglDestroyContext)
Z_FUNCTION(eglMakeCurrent) Z_OPTIONAL(egl, have_egl, eglCreateWindowSurface)
Z_FUNCTION(eglGetCurrentContext) Z_OPTIONAL(egl, have_egl, eglDestroySurface)
Z_FUNCTION(eglSwapBuffers) Z_OPTIONAL(egl, have_egl, eglMakeCurrent)
Z_FUNCTION(eglSwapInterval) Z_OPTIONAL(egl, have_egl, eglGetCurrentContext)
Z_FUNCTION(eglGetProcAddress) Z_OPTIONAL(egl, have_egl, eglSwapBuffers)
Z_FUNCTION(eglReleaseThread) Z_OPTIONAL(egl, have_egl, eglSwapInterval)
Z_FUNCTION(xkb_context_new) Z_OPTIONAL(egl, have_egl, eglGetProcAddress)
Z_FUNCTION(xkb_context_unref) Z_OPTIONAL(egl, have_egl, eglReleaseThread)
Z_FUNCTION(xkb_keymap_new_from_string)
Z_FUNCTION(xkb_keymap_unref) Z_OPTIONAL(xkb, have_xkb, xkb_context_new)
Z_FUNCTION(xkb_keymap_key_repeats) Z_OPTIONAL(xkb, have_xkb, xkb_context_unref)
Z_FUNCTION(xkb_state_new) Z_OPTIONAL(xkb, have_xkb, xkb_keymap_new_from_string)
Z_FUNCTION(xkb_state_unref) Z_OPTIONAL(xkb, have_xkb, xkb_keymap_unref)
Z_FUNCTION(xkb_state_update_mask) Z_OPTIONAL(xkb, have_xkb, xkb_keymap_key_repeats)
Z_FUNCTION(xkb_state_key_get_one_sym) Z_OPTIONAL(xkb, have_xkb, xkb_state_new)
Z_FUNCTION(xkb_state_key_get_utf8) Z_OPTIONAL(xkb, have_xkb, xkb_state_unref)
Z_FUNCTION(xkb_state_mod_name_is_active) Z_OPTIONAL(xkb, have_xkb, xkb_state_update_mask)
Z_FUNCTION(xkb_keysym_to_utf32) Z_OPTIONAL(xkb, have_xkb, xkb_state_key_get_one_sym)
Z_FUNCTION(xkb_compose_table_new_from_locale) Z_OPTIONAL(xkb, have_xkb, xkb_state_key_get_utf8)
Z_FUNCTION(xkb_compose_table_unref) Z_OPTIONAL(xkb, have_xkb, xkb_state_mod_name_is_active)
Z_FUNCTION(xkb_compose_state_new) Z_OPTIONAL(xkb, have_xkb, xkb_keysym_to_utf32)
Z_FUNCTION(xkb_compose_state_unref) Z_OPTIONAL(xkb, have_xkb, xkb_compose_table_new_from_locale)
Z_FUNCTION(xkb_compose_state_feed) Z_OPTIONAL(xkb, have_xkb, xkb_compose_table_unref)
Z_FUNCTION(xkb_compose_state_reset) Z_OPTIONAL(xkb, have_xkb, xkb_compose_state_new)
Z_FUNCTION(xkb_compose_state_get_status) Z_OPTIONAL(xkb, have_xkb, xkb_compose_state_unref)
Z_FUNCTION(xkb_compose_state_get_utf8) Z_OPTIONAL(xkb, have_xkb, xkb_compose_state_feed)
Z_FUNCTION(dbus_connection_open_private) Z_OPTIONAL(xkb, have_xkb, xkb_compose_state_reset)
Z_FUNCTION(dbus_connection_set_exit_on_disconnect) Z_OPTIONAL(xkb, have_xkb, xkb_compose_state_get_status)
Z_FUNCTION(dbus_connection_close) Z_OPTIONAL(xkb, have_xkb, xkb_compose_state_get_utf8)
Z_FUNCTION(dbus_connection_unref)
Z_FUNCTION(dbus_connection_get_is_connected) Z_OPTIONAL(dbus, have_dbus, dbus_connection_open_private)
Z_FUNCTION(dbus_connection_get_unix_fd) Z_OPTIONAL(dbus, have_dbus, dbus_connection_set_exit_on_disconnect)
Z_FUNCTION(dbus_connection_has_messages_to_send) Z_OPTIONAL(dbus, have_dbus, dbus_connection_close)
Z_FUNCTION(dbus_connection_read_write) Z_OPTIONAL(dbus, have_dbus, dbus_connection_unref)
Z_FUNCTION(dbus_connection_pop_message) Z_OPTIONAL(dbus, have_dbus, dbus_connection_get_is_connected)
Z_FUNCTION(dbus_connection_send) Z_OPTIONAL(dbus, have_dbus, dbus_connection_get_unix_fd)
Z_FUNCTION(dbus_message_new_method_call) Z_OPTIONAL(dbus, have_dbus, dbus_connection_has_messages_to_send)
Z_FUNCTION(dbus_message_unref) Z_OPTIONAL(dbus, have_dbus, dbus_connection_read_write)
Z_FUNCTION(dbus_message_get_type) Z_OPTIONAL(dbus, have_dbus, dbus_connection_pop_message)
Z_FUNCTION(dbus_message_get_reply_serial) Z_OPTIONAL(dbus, have_dbus, dbus_connection_send)
Z_FUNCTION(dbus_message_get_path) Z_OPTIONAL(dbus, have_dbus, dbus_message_new_method_call)
Z_FUNCTION(dbus_message_get_sender) Z_OPTIONAL(dbus, have_dbus, dbus_message_unref)
Z_FUNCTION(dbus_message_get_error_name) Z_OPTIONAL(dbus, have_dbus, dbus_message_get_type)
Z_FUNCTION(dbus_message_is_signal) Z_OPTIONAL(dbus, have_dbus, dbus_message_get_reply_serial)
Z_FUNCTION(dbus_message_has_signature) Z_OPTIONAL(dbus, have_dbus, dbus_message_get_path)
Z_FUNCTION(dbus_message_set_no_reply) Z_OPTIONAL(dbus, have_dbus, dbus_message_get_sender)
Z_FUNCTION(dbus_message_iter_init) Z_OPTIONAL(dbus, have_dbus, dbus_message_get_error_name)
Z_FUNCTION(dbus_message_iter_init_append) Z_OPTIONAL(dbus, have_dbus, dbus_message_is_signal)
Z_FUNCTION(dbus_message_iter_get_arg_type) Z_OPTIONAL(dbus, have_dbus, dbus_message_has_signature)
Z_FUNCTION(dbus_message_iter_next) Z_OPTIONAL(dbus, have_dbus, dbus_message_set_no_reply)
Z_FUNCTION(dbus_message_iter_recurse) Z_OPTIONAL(dbus, have_dbus, dbus_message_iter_init)
Z_FUNCTION(dbus_message_iter_get_basic) Z_OPTIONAL(dbus, have_dbus, dbus_message_iter_init_append)
Z_FUNCTION(dbus_message_iter_append_basic) Z_OPTIONAL(dbus, have_dbus, dbus_message_iter_get_arg_type)
Z_FUNCTION(dbus_message_iter_open_container) Z_OPTIONAL(dbus, have_dbus, dbus_message_iter_next)
Z_FUNCTION(dbus_message_iter_close_container) Z_OPTIONAL(dbus, have_dbus, dbus_message_iter_recurse)
Z_FUNCTION(dbus_message_iter_abandon_container_if_open) Z_OPTIONAL(dbus, have_dbus, dbus_message_iter_get_basic)
Z_FUNCTION(dbus_threads_init_default) Z_OPTIONAL(dbus, have_dbus, dbus_message_iter_append_basic)
Z_FUNCTION(dbus_message_new_method_return) Z_OPTIONAL(dbus, have_dbus, dbus_message_iter_open_container)
Z_FUNCTION(dbus_message_new_error) Z_OPTIONAL(dbus, have_dbus, dbus_message_iter_close_container)
Z_FUNCTION(dbus_message_new_signal) Z_OPTIONAL(dbus, have_dbus, dbus_message_iter_abandon_container_if_open)
Z_FUNCTION(dbus_message_get_interface) Z_OPTIONAL(dbus, have_dbus, dbus_threads_init_default)
Z_FUNCTION(dbus_message_get_member) Z_OPTIONAL(dbus, have_dbus, dbus_message_new_method_return)
Z_FUNCTION(dbus_message_get_no_reply) Z_OPTIONAL(dbus, have_dbus, dbus_message_new_error)
Z_OPTIONAL(dbus, have_dbus, dbus_message_new_signal)
Z_OPTIONAL(dbus, have_dbus, dbus_message_get_interface)
Z_OPTIONAL(dbus, have_dbus, dbus_message_get_member)
Z_OPTIONAL(dbus, have_dbus, dbus_message_get_no_reply)

View File

@ -6,7 +6,6 @@
#include <pthread.h> #include <pthread.h>
#include <fcntl.h> #include <fcntl.h>
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include <sys/syscall.h> #include <sys/syscall.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
@ -21,9 +20,11 @@
#include <dbus/dbus.h> #include <dbus/dbus.h>
#include "dbus-imports.h" #include "dbus-imports.h"
#include "function-pointers.h" #include "function-pointers.h"
#define Z_FUNCTION(name) __typeof__(name) *z_##name; #define Z_REQUIRED(name) __typeof__(name) *z_##name;
#define Z_OPTIONAL(library, available, name) __typeof__(name) *z_##name;
#include "functions.inc" #include "functions.inc"
#undef Z_FUNCTION #undef Z_OPTIONAL
#undef Z_REQUIRED
static void *wayland, *wayland_egl, *egl, *xkb, *dbus; static void *wayland, *wayland_egl, *egl, *xkb, *dbus;
static int have_egl, have_xkb, have_dbus; static int have_egl, have_xkb, have_dbus;
@ -59,9 +60,11 @@ void z_linux_libraries_close(void) {
if (wayland) if (wayland)
dlclose(wayland); dlclose(wayland);
wayland = wayland_egl = egl = NULL; wayland = wayland_egl = egl = NULL;
#define Z_FUNCTION(name) z_##name = NULL; #define Z_REQUIRED(name) z_##name = NULL;
#define Z_OPTIONAL(library, available, name) z_##name = NULL;
#include "functions.inc" #include "functions.inc"
#undef Z_FUNCTION #undef Z_OPTIONAL
#undef Z_REQUIRED
} }
int z_linux_libraries_open(void) { int z_linux_libraries_open(void) {
@ -75,34 +78,24 @@ int z_linux_libraries_open(void) {
have_xkb = xkb != NULL; have_xkb = xkb != NULL;
dbus = open_library("libdbus-1.so.3"); dbus = open_library("libdbus-1.so.3");
have_dbus = dbus != NULL; have_dbus = dbus != NULL;
#define Z_FUNCTION(name) \ #define Z_REQUIRED(name) \
do { \ do { \
const char *symbol = #name; \ z_##name = (__typeof__(z_##name))dlsym(wayland, #name); \
int bus = strncmp(symbol, "dbus_", 5) == 0; \
int keyboard = strncmp(symbol, "xkb_", 4) == 0; \
int graphics = strncmp(symbol, "egl", 3) == 0 || strncmp(symbol, "wl_egl_", 7) == 0; \
void *library = \
bus ? dbus \
: keyboard \
? xkb \
: (strncmp(symbol, "egl", 3) == 0 ? egl : (graphics ? wayland_egl : wayland)); \
if (library) \
z_##name = (__typeof__(z_##name))dlsym(library, symbol); \
if (!z_##name) { \ if (!z_##name) { \
if (bus) \ z_linux_libraries_close(); \
have_dbus = 0; \ return 0; \
else if (keyboard) \
have_xkb = 0; \
else if (graphics) \
have_egl = 0; \
else { \
z_linux_libraries_close(); \
return 0; \
} \
} \ } \
} while (0); } while (0);
#define Z_OPTIONAL(library, available, name) \
do { \
if (library) \
z_##name = (__typeof__(z_##name))dlsym(library, #name); \
if (!z_##name) \
available = 0; \
} while (0);
#include "functions.inc" #include "functions.inc"
#undef Z_FUNCTION #undef Z_OPTIONAL
#undef Z_REQUIRED
return 1; return 1;
} }

View File

@ -426,13 +426,11 @@ fn completeCreation(w: *Window, status: u32) void {
if (id == 0) return; if (id == 0) return;
w.request = 0; w.request = 0;
const app = runtime.toAppHandle(w.owner); const app = runtime.toAppHandle(w.owner);
var result = std.mem.zeroes(n.z_request_result);
result.value.window = w.handle;
if (status != abi.OK) { if (status != abi.OK) {
n.z_object_set_native(w.handle, null); n.z_object_set_native(w.handle, null);
destroyWindow(w); destroyWindow(w);
} }
n.z_complete(app, id, status, &result); n.z_complete(app, id, status, null);
} }
fn apply(w: *Window) void { fn apply(w: *Window) void {
@ -582,7 +580,7 @@ fn destroyWindow(w: *Window) void {
if (w.surface != null) c.wl_surface_destroy(w.surface); if (w.surface != null) c.wl_surface_destroy(w.surface);
w.owner.gpa.destroy(w); w.owner.gpa.destroy(w);
} }
export fn z_native_execute(_: ?*n.uhdk_app, raw: [*c]const n.z_command, id: u64, result: [*c]n.z_request_result) u32 { export fn z_native_execute(_: ?*n.uhdk_app, raw: [*c]const n.z_command, id: u64, _: [*c]n.z_request_result) u32 {
const b = instance.?; const b = instance.?;
const cmd: *const n.z_command = &raw.*; const cmd: *const n.z_command = &raw.*;
if (cmd.op == n.Z_DESTROY) { if (cmd.op == n.Z_DESTROY) {
@ -661,7 +659,7 @@ export fn z_native_execute(_: ?*n.uhdk_app, raw: [*c]const n.z_command, id: u64,
n.Z_TEXT_CANCEL => Text.cancel(w), n.Z_TEXT_CANCEL => Text.cancel(w),
n.Z_FOCUS => return Desktop.focus(w, id), n.Z_FOCUS => return Desktop.focus(w, id),
n.Z_REDRAW => emit(w, n.UHDK_EVENT_WINDOW_REDRAW), n.Z_REDRAW => emit(w, n.UHDK_EVENT_WINDOW_REDRAW),
n.Z_GL => return Egl.create(b, w, cmd.other, result), n.Z_GL => return Egl.create(b, w, cmd.other),
else => return n.UHDK_STATUS_UNSUPPORTED, else => return n.UHDK_STATUS_UNSUPPORTED,
} }
return abi.OK; return abi.OK;

View File

@ -1,9 +1,15 @@
/* Included by the service harness: all desktop traffic uses private fixtures. */ /* Included by the service harness: all desktop traffic uses private fixtures. */
#define OPEN_ID UINT64_C(0x1234567800000065) #define OPEN_ID UINT64_C(0x1234567800000065)
static void menu_phase(uhdk_app *app, uhdk_window *w, const char *phase) { static void menu_phase(uhdk_app *app, uhdk_window *w, const char *phase) {
uint64_t id; OK(uhdk_window_set_title(w, text(phase)));
OK(uhdk_window_set_title_async(w, text(phase), &id)); uhdk_window_invalidate(w);
OK(wait_result(app, id).status); for (;;) {
uhdk_event_list events;
OK(uhdk_app_poll_events(app, 50000000, &events));
for (uint64_t i = 0; i < events.len; ++i)
if (events.ptr[i].type == UHDK_EVENT_WINDOW_REDRAW && events.ptr[i].window == w)
return;
}
} }
static void menus(uhdk_app *app) { static void menus(uhdk_app *app) {
wait_capability(app, UHDK_CAP_APP_MENU); wait_capability(app, UHDK_CAP_APP_MENU);
@ -31,8 +37,7 @@ static void menus(uhdk_app *app) {
OK(uhdk_menu_create(app, roots, 2, &root)); OK(uhdk_menu_create(app, roots, 2, &root));
uhdk_menu_release(child); uhdk_menu_release(child);
uint64_t id; uint64_t id;
OK(uhdk_app_set_menu_async(app, root, &id)); OK(uhdk_app_set_menu(app, root));
OK(wait_result(app, id).status);
uhdk_window *a = window(app), *b = window(app); uhdk_window *a = window(app), *b = window(app);
uhdk_menu_item overrides[] = { uhdk_menu_item overrides[] = {
{.command_id = 200, .label = {"Window action", 13}}, {.command_id = 200, .label = {"Window action", 13}},
@ -43,11 +48,9 @@ static void menus(uhdk_app *app) {
}; };
uhdk_menu *override; uhdk_menu *override;
OK(uhdk_menu_create(app, overrides, 2, &override)); OK(uhdk_menu_create(app, overrides, 2, &override));
OK(uhdk_window_set_menu_async(b, override, &id)); OK(uhdk_window_set_menu(b, override));
OK(wait_result(app, id).status);
uhdk_menu_release(override); // The attachment must keep its model alive. uhdk_menu_release(override); // The attachment must keep its model alive.
OK(uhdk_window_set_text_input_async(a, 1, &id)); OK(uhdk_window_set_text_input(a, 1));
OK(wait_result(app, id).status);
OK(uhdk_menu_popup_async(root, a, (uhdk_point){0, 0}, &id)); OK(uhdk_menu_popup_async(root, a, (uhdk_point){0, 0}, &id));
assert(wait_result(app, id).status == UHDK_STATUS_UNSUPPORTED); assert(wait_result(app, id).status == UHDK_STATUS_UNSUPPORTED);
menu_phase(app, a, "menus-ready"); menu_phase(app, a, "menus-ready");
@ -101,27 +104,21 @@ static void menus(uhdk_app *app) {
assert( assert(
opens_a == 1 && opens_b == 0 && copies == 1 && quits == 1 && overrides_seen == 1 opens_a == 1 && opens_b == 0 && copies == 1 && quits == 1 && overrides_seen == 1
); );
OK(uhdk_menu_set_item_flags_async(root, 10, UHDK_MENU_DISABLED, &id)); OK(uhdk_menu_set_item_flags(root, 10, UHDK_MENU_DISABLED));
OK(wait_result(app, id).status); OK(uhdk_menu_set_item_flags(root, 102, 0));
OK(uhdk_menu_set_item_flags_async(root, 102, 0, &id));
OK(wait_result(app, id).status);
menu_phase(app, a, "flags-ready"); menu_phase(app, a, "flags-ready");
} else if (stage == 2) { } else if (stage == 2) {
assert(raw_o >= 2); assert(raw_o >= 2);
OK(uhdk_menu_set_item_flags_async(root, 10, 0, &id)); OK(uhdk_menu_set_item_flags(root, 10, 0));
OK(wait_result(app, id).status); OK(uhdk_window_set_menu(b, NULL));
OK(uhdk_window_set_menu_async(b, NULL, &id));
OK(wait_result(app, id).status);
menu_phase(app, a, "restored-ready"); menu_phase(app, a, "restored-ready");
} else if (stage == 3) { } else if (stage == 3) {
assert(opens_a == 2 && opens_b == 1 && copies == 2); assert(opens_a == 2 && opens_b == 1 && copies == 2);
// Override survives clearing the app default, then the first window dies. // Override survives clearing the app default, then the first window dies.
OK(uhdk_menu_create(app, overrides, 2, &override)); OK(uhdk_menu_create(app, overrides, 2, &override));
OK(uhdk_window_set_menu_async(b, override, &id)); OK(uhdk_window_set_menu(b, override));
OK(wait_result(app, id).status);
uhdk_menu_release(override); uhdk_menu_release(override);
OK(uhdk_app_set_menu_async(app, NULL, &id)); OK(uhdk_app_set_menu(app, NULL));
OK(wait_result(app, id).status);
uhdk_menu_release(root); uhdk_menu_release(root);
uhdk_window_destroy(a); uhdk_window_destroy(a);
menu_phase(app, b, "detached-ready"); menu_phase(app, b, "detached-ready");
@ -139,20 +136,12 @@ static void menus_unavailable(uhdk_app *app, int no_bus) {
uhdk_menu_item item = {.command_id = 1, .label = {"Unavailable", 11}}; uhdk_menu_item item = {.command_id = 1, .label = {"Unavailable", 11}};
uhdk_menu *menu; uhdk_menu *menu;
OK(uhdk_menu_create(app, &item, 1, &menu)); OK(uhdk_menu_create(app, &item, 1, &menu));
uint64_t id; (void)no_bus;
OK(uhdk_app_set_menu_async(app, menu, &id)); OK(uhdk_app_set_menu(app, menu));
assert( OK(uhdk_window_set_menu(w, menu));
wait_result(app, id).status == (no_bus ? UHDK_STATUS_UNAVAILABLE : UHDK_STATUS_UNSUPPORTED)
);
OK(uhdk_window_set_menu_async(w, menu, &id));
assert(
wait_result(app, id).status == (no_bus ? UHDK_STATUS_UNAVAILABLE : UHDK_STATUS_UNSUPPORTED)
);
assert(!uhdk_app_has_capability(app, UHDK_CAP_APP_MENU)); assert(!uhdk_app_has_capability(app, UHDK_CAP_APP_MENU));
OK(uhdk_menu_set_item_flags_async(menu, 1, UHDK_MENU_CHECKED, &id)); OK(uhdk_menu_set_item_flags(menu, 1, UHDK_MENU_CHECKED));
OK(wait_result(app, id).status); OK(uhdk_app_set_menu(app, NULL));
OK(uhdk_app_set_menu_async(app, NULL, &id));
OK(wait_result(app, id).status);
uhdk_menu_release(menu); uhdk_menu_release(menu);
uhdk_window_destroy(w); uhdk_window_destroy(w);
puts("Unavailable menu protocol/session bus: PASS"); puts("Unavailable menu protocol/session bus: PASS");

View File

@ -20,24 +20,6 @@ static uhdk_text text(const char *s) {
} }
static int entered; static int entered;
static uhdk_request_result wait_request(uhdk_app *app, uint64_t id) {
uint64_t deadline = uhdk_app_get_time_ns(app) + 10000000000ull;
while (uhdk_app_get_time_ns(app) < deadline) {
uhdk_event_list events;
OK(uhdk_app_poll_events(app, 100000000ull, &events));
for (uint64_t i = 0; i < events.len; ++i) {
const uhdk_event *event = &events.ptr[i];
if (event->type == UHDK_EVENT_REQUEST_DONE) {
const uhdk_request_result *result = event->data;
assert(result->id == id);
return *result;
}
}
}
fputs("Timed out awaiting request\n", stderr);
abort();
}
static uhdk_window_metrics metrics(uhdk_window *w) { static uhdk_window_metrics metrics(uhdk_window *w) {
uhdk_window_metrics m = {0}; uhdk_window_metrics m = {0};
m.struct_size = sizeof(m); m.struct_size = sizeof(m);
@ -70,11 +52,26 @@ static uhdk_window_desc descriptor(void) {
static uhdk_window *create_window(uhdk_app *app) { static uhdk_window *create_window(uhdk_app *app) {
uhdk_window_desc desc = descriptor(); uhdk_window_desc desc = descriptor();
uint64_t id; uhdk_window *result = NULL;
OK(uhdk_window_create_async(app, &desc, &id)); OK(uhdk_window_create(app, &desc, &result));
uhdk_request_result result = wait_request(app, id); wait_metrics(app, result, 0, 320);
OK(result.status); return result;
return ((const uhdk_window_result *)result.data)->window; }
static void begin_context(uhdk_app *app, uhdk_gl_context *context) {
uint64_t deadline = uhdk_app_get_time_ns(app) + 10000000000ull;
while (uhdk_app_get_time_ns(app) < deadline) {
uhdk_status status = uhdk_gl_context_begin_frame(context);
if (status == UHDK_STATUS_OK)
return;
assert(status == UHDK_STATUS_UNAVAILABLE);
uhdk_event_list events;
OK(uhdk_app_poll_events(app, 100000000ull, &events));
for (uint64_t i = 0; i < events.len; ++i)
if (events.ptr[i].type == UHDK_EVENT_RESOURCE_FAILED)
OK(((const uhdk_resource_event *)events.ptr[i].data)->status);
}
abort();
} }
static void test_main(uhdk_app *app, void *user) { static void test_main(uhdk_app *app, void *user) {
@ -85,23 +82,18 @@ static void test_main(uhdk_app *app, void *user) {
OK(uhdk_app_poll_events(app, 0, &ready)); OK(uhdk_app_poll_events(app, 0, &ready));
assert(ready.len > 0 && ready.ptr[0].type == UHDK_EVENT_READY); assert(ready.len > 0 && ready.ptr[0].type == UHDK_EVENT_READY);
// Cancellation must complete exactly once even before the first configure. // Pending creation can be destroyed before the first configure.
uint64_t id;
uhdk_window_desc desc = descriptor(); uhdk_window_desc desc = descriptor();
OK(uhdk_window_create_async(app, &desc, &id)); uhdk_window *pending = NULL;
OK(uhdk_request_cancel(app, id)); OK(uhdk_window_create(app, &desc, &pending));
uhdk_request_result cancelled = wait_request(app, id); uhdk_window_destroy(pending);
assert(cancelled.status == UHDK_STATUS_CANCELLED || cancelled.status == UHDK_STATUS_OK);
if (cancelled.status == UHDK_STATUS_OK)
uhdk_window_destroy(((const uhdk_window_result *)cancelled.data)->window);
// Destroying a parent must also complete a child still awaiting configure. // Destroying a parent must also complete a child still awaiting configure.
uhdk_window *parent = create_window(app); uhdk_window *parent = create_window(app);
desc.parent = parent; desc.parent = parent;
OK(uhdk_window_create_async(app, &desc, &id)); uhdk_window *child = NULL;
OK(uhdk_window_create(app, &desc, &child));
uhdk_window_destroy(parent); uhdk_window_destroy(parent);
uhdk_request_result child = wait_request(app, id);
assert(child.status == UHDK_STATUS_CANCELLED || child.status == UHDK_STATUS_OK);
desc.parent = NULL; desc.parent = NULL;
uhdk_window *w = create_window(app); uhdk_window *w = create_window(app);
@ -111,12 +103,10 @@ static void test_main(uhdk_app *app, void *user) {
OK(uhdk_window_get_native(w, &native)); OK(uhdk_window_get_native(w, &native));
assert(native.backend == UHDK_BACKEND_WAYLAND && native.primary && native.secondary); assert(native.backend == UHDK_BACKEND_WAYLAND && native.primary && native.secondary);
uhdk_window_style style = {sizeof(style), 0, 0, 0}; uhdk_window_style style = {sizeof(style), 0, 0, 0};
OK(uhdk_window_set_style_async(w, &style, &id)); OK(uhdk_window_set_style(w, &style));
OK(wait_request(app, id).status);
style.decorated = 1; style.decorated = 1;
style.resizable = 1; style.resizable = 1;
OK(uhdk_window_set_style_async(w, &style, &id)); OK(uhdk_window_set_style(w, &style));
OK(wait_request(app, id).status);
const uint8_t path[] = "/tmp/uhdk file-%\xff"; const uint8_t path[] = "/tmp/uhdk file-%\xff";
uhdk_file *file; uhdk_file *file;
@ -130,11 +120,9 @@ static void test_main(uhdk_app *app, void *user) {
if (!user) { if (!user) {
assert(uhdk_app_has_capability(app, UHDK_CAP_OPENGL)); assert(uhdk_app_has_capability(app, UHDK_CAP_OPENGL));
OK(uhdk_gl_context_create_async(w, &id)); uhdk_gl_context *gl = NULL;
uhdk_request_result gl_result = wait_request(app, id); OK(uhdk_gl_context_create(w, &gl));
OK(gl_result.status); begin_context(app, gl);
uhdk_gl_context *gl = ((const uhdk_gl_context_result *)gl_result.data)->gl_context;
OK(uhdk_gl_context_begin_frame(gl));
assert(uhdk_gl_context_begin_frame(gl) == UHDK_STATUS_BUSY); assert(uhdk_gl_context_begin_frame(gl) == UHDK_STATUS_BUSY);
uint32_t major, minor; uint32_t major, minor;
OK(uhdk_gl_context_get_version(gl, &major, &minor)); OK(uhdk_gl_context_get_version(gl, &major, &minor));
@ -156,10 +144,8 @@ static void test_main(uhdk_app *app, void *user) {
for (int pass = 0; pass < 3; ++pass) { for (int pass = 0; pass < 3; ++pass) {
int width = 320 + pass * 20; int width = 320 + pass * 20;
OK(uhdk_window_set_size_async(w, (uhdk_size){width, 240}, &id)); OK(uhdk_window_set_size(w, (uhdk_size){width, 240}));
OK(wait_request(app, id).status); OK(uhdk_window_set_visible(w, 1));
OK(uhdk_window_set_visible_async(w, 1, &id));
OK(wait_request(app, id).status);
wait_metrics(app, w, 1, width); wait_metrics(app, w, 1, width);
for (int frame = 0; frame < 4; ++frame) { for (int frame = 0; frame < 4; ++frame) {
OK(uhdk_gl_context_begin_frame(gl)); OK(uhdk_gl_context_begin_frame(gl));
@ -174,20 +160,17 @@ static void test_main(uhdk_app *app, void *user) {
OK(uhdk_gl_context_swap_buffers(gl)); OK(uhdk_gl_context_swap_buffers(gl));
OK(uhdk_gl_context_end_frame(gl)); OK(uhdk_gl_context_end_frame(gl));
} }
OK(uhdk_window_set_visible_async(w, 0, &id)); OK(uhdk_window_set_visible(w, 0));
OK(wait_request(app, id).status);
wait_metrics(app, w, 0, width); wait_metrics(app, w, 0, width);
} }
uhdk_gl_context_destroy(gl); uhdk_gl_context_destroy(gl);
// Destroying a context releases its reservation on the window. // Destroying a context releases its reservation on the window.
OK(uhdk_gl_context_create_async(w, &id)); OK(uhdk_gl_context_create(w, &gl));
gl_result = wait_request(app, id); uhdk_gl_context_destroy(gl);
OK(gl_result.status);
uhdk_gl_context_destroy(((const uhdk_gl_context_result *)gl_result.data)->gl_context);
} }
uhdk_window_destroy(w); uhdk_window_destroy(w);
// Returning with a queued creation must cancel/drain it before native teardown. // Returning with a queued creation must cancel/drain it before native teardown.
OK(uhdk_window_create_async(app, &desc, &id)); OK(uhdk_window_create(app, &desc, &pending));
} }
static void disconnect_main(uhdk_app *app, void *user) { static void disconnect_main(uhdk_app *app, void *user) {

View File

@ -6,10 +6,8 @@ static void popups(uhdk_app *app) {
wait_capability(app, UHDK_CAP_CONTEXT_MENU); wait_capability(app, UHDK_CAP_CONTEXT_MENU);
assert(!uhdk_app_has_capability(app, UHDK_CAP_APP_MENU)); assert(!uhdk_app_has_capability(app, UHDK_CAP_APP_MENU));
uint64_t id; uint64_t id;
OK(uhdk_window_set_visible_async(w, 1, &id)); OK(uhdk_window_set_visible(w, 1));
OK(wait_result(app, id).status); OK(uhdk_window_set_text_input(w, 1));
OK(uhdk_window_set_text_input_async(w, 1, &id));
OK(wait_result(app, id).status);
uhdk_menu_item child_items[] = {{.command_id = POPUP_CHILD, .label = {"Child café", 11}}}; uhdk_menu_item child_items[] = {{.command_id = POPUP_CHILD, .label = {"Child café", 11}}};
uhdk_menu *child, *root; uhdk_menu *child, *root;
OK(uhdk_menu_create(app, child_items, 1, &child)); OK(uhdk_menu_create(app, child_items, 1, &child));
@ -40,8 +38,7 @@ static void popups(uhdk_app *app) {
} }
char title[64]; char title[64];
snprintf(title, sizeof(title), "popup-stage-%u", stage); snprintf(title, sizeof(title), "popup-stage-%u", stage);
OK(uhdk_window_set_title_async(w, text(title), &id)); OK(uhdk_window_set_title(w, text(title)));
// Do not discard the input event that may arrive with title completion.
uint64_t popup = 0, busy = 0, started = 0; uint64_t popup = 0, busy = 0, started = 0;
unsigned commands = 0, complete = 0, busy_done = 0, changed = 0; unsigned commands = 0, complete = 0, busy_done = 0, changed = 0;
uint64_t end = deadline(app); uint64_t end = deadline(app);
@ -92,8 +89,8 @@ static void popups(uhdk_app *app) {
if (stage == 5) if (stage == 5)
OK(uhdk_request_cancel(app, popup)); OK(uhdk_request_cancel(app, popup));
if (stage == 6) { if (stage == 6) {
OK(uhdk_menu_set_item_flags_async(root, POPUP_OPEN, UHDK_MENU_DISABLED, &id)); OK(uhdk_menu_set_item_flags(root, POPUP_OPEN, UHDK_MENU_DISABLED));
OK(uhdk_menu_set_item_flags_async(root, 103, 0, &id)); OK(uhdk_menu_set_item_flags(root, 103, 0));
} }
if (stage == 11) if (stage == 11)
uhdk_window_destroy(w); uhdk_window_destroy(w);

View File

@ -41,11 +41,20 @@ static uhdk_window *window(uhdk_app *app) {
desc.title = text("UHDK service tests"); desc.title = text("UHDK service tests");
desc.content_size = (uhdk_size){320, 240}; desc.content_size = (uhdk_size){320, 240};
desc.style = (uhdk_window_style){sizeof(uhdk_window_style), 1, 1, 0}; desc.style = (uhdk_window_style){sizeof(uhdk_window_style), 1, 1, 0};
uint64_t id; uhdk_window *result = NULL;
OK(uhdk_window_create_async(app, &desc, &id)); OK(uhdk_window_create(app, &desc, &result));
uhdk_request_result r = wait_result(app, id); uint64_t end = deadline(app);
OK(r.status); while (uhdk_app_get_time_ns(app) < end) {
return ((const uhdk_window_result *)r.data)->window; uhdk_event_list events;
OK(uhdk_app_poll_events(app, 50000000, &events));
for (uint64_t i = 0; i < events.len; ++i) {
if (events.ptr[i].type == UHDK_EVENT_RESOURCE_FAILED)
OK(((const uhdk_resource_event *)events.ptr[i].data)->status);
if (events.ptr[i].type == UHDK_EVENT_WINDOW_METRICS && events.ptr[i].window == result)
return result;
}
}
abort();
} }
static void wait_capability(uhdk_app *app, uint32_t cap) { static void wait_capability(uhdk_app *app, uint32_t cap) {
uint64_t end = deadline(app); uint64_t end = deadline(app);
@ -130,12 +139,9 @@ static void real_desktop(uhdk_app *app) {
image.height = 1; image.height = 1;
image.stride_bytes = 8; image.stride_bytes = 8;
image.pixels = (uhdk_bytes){rgba, sizeof(rgba)}; image.pixels = (uhdk_bytes){rgba, sizeof(rgba)};
uint64_t id; OK(uhdk_app_set_icon(app, &image));
OK(uhdk_app_set_icon_async(app, &image, &id));
OK(wait_result(app, id).status);
// A hidden, unfocused window must not commandeer a later user's keystroke. // A hidden, unfocused window must not commandeer a later user's keystroke.
OK(uhdk_clipboard_write_text_async(app, text("must not replace clipboard"), &id)); OK(uhdk_clipboard_write_text(app, text("must not replace clipboard")));
assert(wait_result(app, id).status == UHDK_STATUS_UNAVAILABLE);
uhdk_window_destroy(w); uhdk_window_destroy(w);
} }
static void portals(uhdk_app *app) { static void portals(uhdk_app *app) {
@ -221,15 +227,11 @@ static void window_observations(uhdk_app *app, int version) {
UHDK_WINDOW_OBSERVE_RESIZING | (version >= 6 ? UHDK_WINDOW_OBSERVE_SUSPENDED : 0); UHDK_WINDOW_OBSERVE_RESIZING | (version >= 6 ? UHDK_WINDOW_OBSERVE_SUSPENDED : 0);
assert(metrics.observations == known); assert(metrics.observations == known);
assert(!metrics.minimized && !metrics.occluded && !metrics.suspended && !metrics.resizing); assert(!metrics.minimized && !metrics.occluded && !metrics.suspended && !metrics.resizing);
uint64_t request; OK(uhdk_window_set_state(w, UHDK_WINDOW_MINIMIZED));
OK(uhdk_window_set_state_async(w, UHDK_WINDOW_MINIMIZED, &request)); OK(uhdk_window_set_state(w, UHDK_WINDOW_FULLSCREEN));
assert(wait_result(app, request).status == UHDK_STATUS_UNSUPPORTED);
OK(uhdk_window_set_state_async(w, UHDK_WINDOW_FULLSCREEN, &request));
assert(wait_result(app, request).status == UHDK_STATUS_UNSUPPORTED);
for (int phase = 0; phase < 2; ++phase) { for (int phase = 0; phase < 2; ++phase) {
OK(uhdk_window_set_title_async( OK(uhdk_window_set_title(w, text(phase ? "fixture:resume" : "fixture:suspend")));
w, text(phase ? "fixture:resume" : "fixture:suspend"), &request uhdk_window_invalidate(w);
));
int matched = 0, completed = 0; int matched = 0, completed = 0;
uint64_t end = deadline(app); uint64_t end = deadline(app);
while (uhdk_app_get_time_ns(app) < end && !(matched && completed)) { while (uhdk_app_get_time_ns(app) < end && !(matched && completed)) {
@ -244,19 +246,14 @@ static void window_observations(uhdk_app *app, int version) {
!!m->resizing == !phase && !!m->focused == !phase && !!m->resizing == !phase && !!m->focused == !phase &&
!!m->suspended == (!phase && version >= 6)) !!m->suspended == (!phase && version >= 6))
matched = 1; matched = 1;
} else if (events.ptr[i].type == UHDK_EVENT_REQUEST_DONE) { } else if (events.ptr[i].type == UHDK_EVENT_WINDOW_REDRAW &&
const uhdk_request_result *r = events.ptr[i].data; events.ptr[i].window == w)
if (r->id == request) { completed = 1;
OK(r->status);
completed = 1;
}
}
} }
} }
assert(matched && completed); assert(matched && completed);
} }
OK(uhdk_window_set_state_async(w, UHDK_WINDOW_MINIMIZED, &request)); OK(uhdk_window_set_state(w, UHDK_WINDOW_MINIMIZED));
OK(wait_result(app, request).status);
OK(uhdk_window_get_metrics(w, &metrics)); OK(uhdk_window_get_metrics(w, &metrics));
assert(!(metrics.observations & UHDK_WINDOW_OBSERVE_MINIMIZED)); assert(!(metrics.observations & UHDK_WINDOW_OBSERVE_MINIMIZED));
assert(metrics.state == UHDK_WINDOW_NORMAL); // Submission is not observation. assert(metrics.state == UHDK_WINDOW_NORMAL); // Submission is not observation.
@ -266,9 +263,7 @@ static void window_observations(uhdk_app *app, int version) {
static void editing(uhdk_app *app) { static void editing(uhdk_app *app) {
uhdk_window *w = window(app); uhdk_window *w = window(app);
uint64_t request; OK(uhdk_window_set_text_input(w, 1));
OK(uhdk_window_set_text_input_async(w, 1, &request));
OK(wait_result(app, request).status);
const struct { const struct {
uint32_t command; uint32_t command;
int extend; int extend;
@ -300,7 +295,8 @@ static void editing(uhdk_app *app) {
OK(uhdk_window_set_text_state(w, &state)); OK(uhdk_window_set_text_state(w, &state));
char title[32]; char title[32];
snprintf(title, sizeof(title), "edit:%u", i); snprintf(title, sizeof(title), "edit:%u", i);
OK(uhdk_window_set_title_async(w, text(title), &request)); OK(uhdk_window_set_title(w, text(title)));
uhdk_window_invalidate(w);
int released = 0, completed = 0; int released = 0, completed = 0;
unsigned commands = 0; unsigned commands = 0;
uint64_t end = deadline(app); uint64_t end = deadline(app);
@ -320,13 +316,8 @@ static void editing(uhdk_app *app) {
assert(!!edit->extend_selection == cases[i].extend); assert(!!edit->extend_selection == cases[i].extend);
acknowledged = event->input_id; acknowledged = event->input_id;
++commands; ++commands;
} else if (event->type == UHDK_EVENT_REQUEST_DONE) { } else if (event->type == UHDK_EVENT_WINDOW_REDRAW && event->window == w)
const uhdk_request_result *r = event->data; completed = 1;
if (r->id == request) {
OK(r->status);
completed = 1;
}
}
} }
} }
assert(released && completed && commands == (cases[i].command ? 1u : 0u)); assert(released && completed && commands == (cases[i].command ? 1u : 0u));
@ -338,10 +329,8 @@ static void editing(uhdk_app *app) {
static void input(uhdk_app *app) { static void input(uhdk_app *app) {
uhdk_window *w = window(app); uhdk_window *w = window(app);
uint64_t id; uint64_t id;
OK(uhdk_window_set_text_input_async(w, 1, &id)); OK(uhdk_window_set_text_input(w, 1));
OK(wait_result(app, id).status); OK(uhdk_window_set_drop_enabled(w, 1));
OK(uhdk_window_set_drop_enabled_async(w, 1, &id));
OK(wait_result(app, id).status);
uhdk_text_state state = {0}; uhdk_text_state state = {0};
state.struct_size = sizeof(state); state.struct_size = sizeof(state);
state.surrounding_text = text("abc"); state.surrounding_text = text("abc");
@ -351,7 +340,7 @@ static void input(uhdk_app *app) {
OK(uhdk_window_set_text_state(w, &state)); OK(uhdk_window_set_text_state(w, &state));
unsigned key = 0, repeat = 0, commit = 0, preedit = 0, pointer = 0, scroll = 0, dropped = 0, unsigned key = 0, repeat = 0, commit = 0, preedit = 0, pointer = 0, scroll = 0, dropped = 0,
copy = 0, compose = 0, captured = 0, released = 0; copy = 0, compose = 0, captured = 0, released = 0;
uint64_t acknowledged = 0, capture_request = 0; uint64_t acknowledged = 0;
int published = 0; int published = 0;
uint64_t end = deadline(app); uint64_t end = deadline(app);
while (uhdk_app_get_time_ns(app) < end && while (uhdk_app_get_time_ns(app) < end &&
@ -402,9 +391,7 @@ static void input(uhdk_app *app) {
} }
case UHDK_EVENT_POINTER_BUTTON: case UHDK_EVENT_POINTER_BUTTON:
if (((const uhdk_pointer_event *)e->data)->pressed) if (((const uhdk_pointer_event *)e->data)->pressed)
OK(uhdk_window_set_pointer_mode_async( OK(uhdk_window_set_pointer_mode(w, UHDK_POINTER_CAPTURE));
w, UHDK_POINTER_CAPTURE, &capture_request
));
break; break;
case UHDK_EVENT_POINTER_MODE_CHANGED: case UHDK_EVENT_POINTER_MODE_CHANGED:
if (((const uhdk_pointer_mode_event *)e->data)->mode == UHDK_POINTER_CAPTURE) if (((const uhdk_pointer_mode_event *)e->data)->mode == UHDK_POINTER_CAPTURE)
@ -412,10 +399,6 @@ static void input(uhdk_app *app) {
else else
released++; released++;
break; break;
case UHDK_EVENT_REQUEST_DONE:
if (((const uhdk_request_result *)e->data)->id == capture_request)
OK(((const uhdk_request_result *)e->data)->status);
break;
case UHDK_EVENT_POINTER_MOVE: { case UHDK_EVENT_POINTER_MOVE: {
const uhdk_pointer_event *p = e->data; const uhdk_pointer_event *p = e->data;
if (p->position.x == 12 && p->position.y == 18) if (p->position.x == 12 && p->position.y == 18)
@ -479,10 +462,8 @@ static void input(uhdk_app *app) {
r = wait_result(app, id); r = wait_result(app, id);
OK(r.status); OK(r.status);
assert(((const uhdk_text *)r.data)->len == 0); assert(((const uhdk_text *)r.data)->len == 0);
OK(uhdk_clipboard_write_text_async(app, text("local copy"), &id)); OK(uhdk_clipboard_write_text(app, text("local copy")));
OK(wait_result(app, id).status); OK(uhdk_window_request_focus(w));
OK(uhdk_window_request_focus_async(w, &id));
OK(wait_result(app, id).status);
uhdk_window_destroy(w); uhdk_window_destroy(w);
puts("input/IME/clipboard/drop/activation: PASS"); puts("input/IME/clipboard/drop/activation: PASS");
} }

View File

@ -1508,7 +1508,6 @@ uhdk_status z_native_execute(uhdk_app *app, const z_command *cmd, uint64_t reque
[w.window makeFirstResponder:w.view]; [w.window makeFirstResponder:w.view];
[host.windows addObject:w]; [host.windows addObject:w];
z_object_set_native(cmd->target, (__bridge_retained void *)w); z_object_set_native(cmd->target, (__bridge_retained void *)w);
result->value.window = cmd->target;
[w metrics]; [w metrics];
break; break;
} }
@ -1587,7 +1586,6 @@ uhdk_status z_native_execute(uhdk_app *app, const z_command *cmd, uint64_t reque
return UHDK_STATUS_UNSUPPORTED; return UHDK_STATUS_UNSUPPORTED;
w.gl = gl; w.gl = gl;
z_object_set_native(cmd->other, (__bridge_retained void *)gl); z_object_set_native(cmd->other, (__bridge_retained void *)gl);
result->value.gl_context = cmd->other;
[w metrics]; [w metrics];
break; break;
} }

View File

@ -16,8 +16,6 @@ typedef struct z_request_result {
union { union {
uhdk_file_list files; /* FILE_DIALOG */ uhdk_file_list files; /* FILE_DIALOG */
uhdk_text text; /* CLIPBOARD_TEXT */ uhdk_text text; /* CLIPBOARD_TEXT */
uhdk_window *window;
uhdk_gl_context *gl_context;
uhdk_watch *watch; uhdk_watch *watch;
uhdk_bytes bytes; uhdk_bytes bytes;
uhdk_file_info info; uhdk_file_info info;
@ -44,6 +42,7 @@ typedef struct z_event {
uhdk_drop_files_event drop_files; uhdk_drop_files_event drop_files;
uhdk_menu_event menu; uhdk_menu_event menu;
uhdk_watch_event watch; uhdk_watch_event watch;
uhdk_resource_event resource;
z_request_result request; z_request_result request;
} data; } data;
} z_event; } z_event;

View File

@ -260,6 +260,18 @@ pub fn submit(application: *Application, command: *Request, out: [*c]u64) abi.St
return abi.OK; return abi.OK;
} }
pub fn submitResource(application: *Application, command: *Request) abi.Status {
command.completion = .resource;
var ignored: u64 = 0;
return submit(application, command, &ignored);
}
pub fn submitCommand(application: *Application, command: *Request) abi.Status {
command.completion = .discard;
var ignored: u64 = 0;
return submit(application, command, &ignored);
}
pub fn notifyCommand(object: *Resource, op: u32) void { pub fn notifyCommand(object: *Resource, op: u32) void {
const command = createCommand(object.app, op, object) catch { const command = createCommand(object.app, op, object) catch {
object.app.lock(); object.app.lock();
@ -291,17 +303,50 @@ pub fn finish(
abandon(command); abandon(command);
return; return;
} }
if (status == abi.OK) switch (command.data.op) {
c.Z_WINDOW => fromObjectHandle(command.data.target).ready = true,
c.Z_GL => fromObjectHandle(command.data.other).ready = true,
else => {},
};
const redraw = command.completion == .resource and status == abi.OK and command.data.op == c.Z_GL;
const redraw_window = if (redraw) fromObjectHandle(command.data.other).payload.gl.owner else null;
if (status != abi.OK) discardCreation(command); if (status != abi.OK) discardCreation(command);
const node = command.node; const node = command.node;
node.event.type = c.UHDK_EVENT_REQUEST_DONE; const publish = switch (command.completion) {
if (value) |v| node.event.data.request = v.*; .request => request: {
node.event.data.request.id = command.id; node.event.type = c.UHDK_EVENT_REQUEST_DONE;
node.event.data.request.kind = command.kind; if (value) |v| node.event.data.request = v.*;
node.event.data.request.status = status; node.event.data.request.id = command.id;
copyPayload(node) catch { node.event.data.request.kind = command.kind;
node.event.data.request.status = abi.OOM; node.event.data.request.status = status;
node.event.data.request.value = std.mem.zeroes(@TypeOf(node.event.data.request.value)); copyPayload(node) catch {
node.event.data.request.diagnostic = .{ .ptr = null, .len = 0 }; node.event.data.request.status = abi.OOM;
node.event.data.request.value = std.mem.zeroes(@TypeOf(node.event.data.request.value));
node.event.data.request.diagnostic = .{ .ptr = null, .len = 0 };
};
break :request true;
},
.resource => resource: {
if (status == abi.OK) break :resource false;
const object = if (command.data.op == c.Z_WINDOW)
fromObjectHandle(command.data.target)
else
fromObjectHandle(command.data.other);
node.event.type = c.UHDK_EVENT_RESOURCE_FAILED;
node.event.window = if (object.payload == .window)
castHandle(?*c.uhdk_window, object)
else if (object.payload.gl.owner) |owner|
castHandle(?*c.uhdk_window, owner)
else
null;
node.event.data.resource = .{
.kind = if (object.payload == .window) c.UHDK_RESOURCE_WINDOW else c.UHDK_RESOURCE_GL_CONTEXT,
.status = status,
.resource = object,
};
break :resource true;
},
.discard => false,
}; };
application.lock(); application.lock();
if (command.data.op >= abi.IO_READ or command.data.op == c.Z_WATCH) application.io_pending -= 1; if (command.data.op >= abi.IO_READ or command.data.op == c.Z_WATCH) application.io_pending -= 1;
@ -313,8 +358,11 @@ pub fn finish(
} }
link = &request.next; link = &request.next;
} }
publishLocked(application, node); if (publish) publishLocked(application, node);
application.unlock(); application.unlock();
if (!publish) destroyEvent(node);
if (redraw_window) |window| notifyCommand(window, c.Z_REDRAW);
if (command.completion == .resource and status == abi.OK) c.z_native_wake();
destroyCommand(command); destroyCommand(command);
} }
@ -402,32 +450,20 @@ pub fn objectError(err: anyerror) abi.Status {
}; };
} }
pub fn scalarCommand( pub fn scalarCommandValue(handle: ?*c.uhdk_window, kind: u32, op: u32, value: u64) abi.Status {
handle: ?*c.uhdk_window,
kind: u32,
op: u32,
value: u64,
out: [*c]u64,
) abi.Status {
const command = createObjectCommand(handle, kind, op) catch |err| return objectError(err); const command = createObjectCommand(handle, kind, op) catch |err| return objectError(err);
command.data.number = value; command.data.number = value;
return submit(fromObjectHandle(handle).app, command, out); return submitCommand(fromObjectHandle(handle).app, command);
} }
pub fn textCommand( pub fn textCommandValue(handle: ?*c.uhdk_window, kind: u32, op: u32, text: c.uhdk_text) abi.Status {
handle: ?*c.uhdk_window,
kind: u32,
op: u32,
text: c.uhdk_text,
out: [*c]u64,
) abi.Status {
if (!abi.validText(text, true)) return abi.INVALID; if (!abi.validText(text, true)) return abi.INVALID;
const command = createObjectCommand(handle, kind, op) catch |err| return objectError(err); const command = createObjectCommand(handle, kind, op) catch |err| return objectError(err);
command.data.text = abi.copyText(command.arena.allocator(), text) catch { command.data.text = abi.copyText(command.arena.allocator(), text) catch {
abandon(command); abandon(command);
return abi.OOM; return abi.OOM;
}; };
return submit(fromObjectHandle(handle).app, command, out); return submitCommand(fromObjectHandle(handle).app, command);
} }
pub fn createAppCommand(handle: ?*c.uhdk_app, op: u32) !*Request { pub fn createAppCommand(handle: ?*c.uhdk_app, op: u32) !*Request {
@ -592,7 +628,6 @@ pub fn attachMenu(
handle: ?*c.uhdk_app, handle: ?*c.uhdk_app,
w: ?*c.uhdk_window, w: ?*c.uhdk_window,
menu: ?*c.uhdk_menu, menu: ?*c.uhdk_menu,
out: [*c]u64,
) abi.Status { ) abi.Status {
if (handle == null or if (handle == null or
(menu != null and (fromObjectHandle(menu).app != fromAppHandle(handle) or (menu != null and (fromObjectHandle(menu).app != fromAppHandle(handle) or
@ -616,7 +651,7 @@ pub fn attachMenu(
return abi.OOM; return abi.OOM;
}; };
} }
return submit(fromAppHandle(handle), command, out); return submitCommand(fromAppHandle(handle), command);
} }
pub fn setMenuFlags(object: *Resource, id: u64, flags: u32) bool { pub fn setMenuFlags(object: *Resource, id: u64, flags: u32) bool {
@ -723,6 +758,7 @@ pub fn dispatch(handle: ?*c.uhdk_app) void {
} }
const start = now(application.io); const start = now(application.io);
var count: usize = 0; var count: usize = 0;
var blocked_on_resource = false;
while (count < 64 and now(application.io) - start < 2_000_000) : (count += 1) { while (count < 64 and now(application.io) - start < 2_000_000) : (count += 1) {
application.lock(); application.lock();
const command = application.queue_head orelse { const command = application.queue_head orelse {
@ -741,6 +777,17 @@ pub fn dispatch(handle: ?*c.uhdk_app) void {
finish(application, command, abi.CANCELLED, null); finish(application, command, abi.CANCELLED, null);
continue; continue;
} }
if (command.data.op != c.Z_WINDOW and command.data.op != c.Z_DESTROY and command.data.target != null and
!fromObjectHandle(command.data.target).ready)
{
application.lock();
command.queued_next = application.queue_head;
application.queue_head = command;
if (application.queue_tail == null) application.queue_tail = command;
application.unlock();
blocked_on_resource = true;
break;
}
if (command.data.op >= abi.IO_READ or command.data.op == c.Z_WATCH) { if (command.data.op >= abi.IO_READ or command.data.op == c.Z_WATCH) {
application.lock(); application.lock();
if (application.io_tail) |tail| tail.queued_next = command else application.io_head = command; if (application.io_tail) |tail| tail.queued_next = command else application.io_head = command;
@ -797,7 +844,7 @@ pub fn dispatch(handle: ?*c.uhdk_app) void {
application.stopped_sent = true; application.stopped_sent = true;
} }
const done = application.worker_done and empty; const done = application.worker_done and empty;
const again = application.queue_head != null or application.io_completed_head != null or node == ids.len; const again = (!blocked_on_resource and application.queue_head != null) or application.io_completed_head != null or node == ids.len;
application.unlock(); application.unlock();
if (done and application.native_running) c.z_native_stop() else if (again) c.z_native_again(); if (done and application.native_running) c.z_native_stop() else if (again) c.z_native_again();
} }

View File

@ -1640,6 +1640,7 @@ static uhdk_status setIcon(const uhdk_image *image) {
uhdk_status z_native_execute(uhdk_app *app, const z_command *cmd, uint64_t request, uhdk_status z_native_execute(uhdk_app *app, const z_command *cmd, uint64_t request,
z_request_result *result) { z_request_result *result) {
(void)app; (void)app;
(void)result;
Window *w = Window *w =
cmd->target && z_object_kind(cmd->target) == Z_KIND_WINDOW ? windowOf(cmd->target) : NULL; cmd->target && z_object_kind(cmd->target) == Z_KIND_WINDOW ? windowOf(cmd->target) : NULL;
switch (cmd->op) { switch (cmd->op) {
@ -1682,7 +1683,6 @@ uhdk_status z_native_execute(uhdk_app *app, const z_command *cmd, uint64_t reque
w->next = host.windows; w->next = host.windows;
host.windows = w; host.windows = w;
z_object_set_native(cmd->target, w); z_object_set_native(cmd->target, w);
result->value.window = cmd->target;
if (host.icon) { if (host.icon) {
SendMessageW(hwnd, WM_SETICON, ICON_BIG, (LPARAM)host.icon); SendMessageW(hwnd, WM_SETICON, ICON_BIG, (LPARAM)host.icon);
SendMessageW(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)host.icon); SendMessageW(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)host.icon);
@ -1786,8 +1786,6 @@ uhdk_status z_native_execute(uhdk_app *app, const z_command *cmd, uint64_t reque
break; break;
case Z_GL: { case Z_GL: {
uhdk_status status = createGraphics(w, cmd->other); uhdk_status status = createGraphics(w, cmd->other);
if (status == UHDK_STATUS_OK)
result->value.gl_context = cmd->other;
return status; return status;
} }
case Z_CURSOR: { case Z_CURSOR: {