big api overhaul, moved unsupported bindings to archive
This commit is contained in:
parent
97bb36827f
commit
f6686e66ec
18
README.md
18
README.md
|
|
@ -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).
|
||||
|
||||
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
|
||||
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
|
||||
|
||||
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`
|
||||
coordinates. The native bridge is private; consumers do not need Objective-C.
|
||||
|
||||
The library includes the GLAD loader implementation. With a current context inside
|
||||
`uhdk_gl_context_begin_frame` / `uhdk_gl_context_end_frame`, call
|
||||
The public header includes the GLAD declarations, while the application owns its
|
||||
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
|
||||
`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
|
||||
`GLAD_GL_IMPLEMENTATION` in your application when linking libuhdk.
|
||||
are named `Clear`, `DrawArrays`, etc. Check `VERSION_3_3` after loading.
|
||||
|
||||
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
|
||||
|
|
|
|||
|
|
@ -68,6 +68,7 @@ fn createLibraryNamed(b: *std.Build, target: std.Build.ResolvedTarget, optimize:
|
|||
.target = target,
|
||||
.optimize = optimize,
|
||||
.link_libc = true,
|
||||
.unwind_tables = if (optimize == .ReleaseSmall) .none else null,
|
||||
});
|
||||
|
||||
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, .{});
|
||||
}
|
||||
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(.{
|
||||
.name = artifact_name,
|
||||
.linkage = if (shared) .dynamic else .static,
|
||||
.root_module = module,
|
||||
});
|
||||
if (shared and target.result.os.tag == .linux)
|
||||
lib.version_script = b.path("src/linux/exports.map");
|
||||
|
||||
// temp
|
||||
// lib.root_module.strip = false;
|
||||
|
|
|
|||
|
|
@ -5,8 +5,9 @@
|
|||
`uhdk.h` with `UHDK_ENABLE_OPENGL` includes the generated `glad/gl.h`:
|
||||
OpenGL 3.3 core, no
|
||||
extensions, header-only output, explicit per-context tables (`--mx`), and no
|
||||
platform loader. `src/glad.c` compiles its implementation into libuhdk. Applications
|
||||
load a `GladGLContext` through their adapter for `uhdk_gl_context_get_proc`.
|
||||
platform loader. Applications define `UHDK_GLAD_GL_IMPLEMENTATION` before
|
||||
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:
|
||||
|
||||
|
|
|
|||
178
include/uhdk.h
178
include/uhdk.h
|
|
@ -1,6 +1,20 @@
|
|||
#ifndef 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.
|
||||
*
|
||||
|
|
@ -70,6 +84,9 @@
|
|||
* 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.
|
||||
*/
|
||||
|
||||
#define UHDK_ABI_VERSION 1u
|
||||
|
||||
#ifdef UHDK_PROFILE_BACKEND
|
||||
#include UHDK_PROFILE_BACKEND
|
||||
#else
|
||||
|
|
@ -105,7 +122,6 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define UHDK_ABI_VERSION 1u
|
||||
|
||||
typedef char uhdk_bool; /* Values are UHDK_FALSE (0) or UHDK_TRUE (1). */
|
||||
enum {
|
||||
|
|
@ -357,8 +373,8 @@ enum {
|
|||
* not permission to stop processing events. suspended is a separate compositor
|
||||
* hint that content is not ordinarily repainted, not proof of occlusion or
|
||||
* minimization. Resizing is an advisory interactive size/move-loop
|
||||
* hint, not a guaranteed transaction around every size change.
|
||||
* Async size/state completion acknowledges submission; geometry arrives here. */
|
||||
* hint, not a guaranteed transaction around every size change. Setters enqueue
|
||||
* native work; geometry and state changes are observed here. */
|
||||
typedef struct uhdk_window_metrics {
|
||||
uint32_t struct_size;
|
||||
uint32_t framebuffer_width;
|
||||
|
|
@ -375,44 +391,27 @@ typedef struct uhdk_window_metrics {
|
|||
uhdk_bool suspended;
|
||||
} 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,
|
||||
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 uhdk_status UHDK_CALL uhdk_window_set_title_async(
|
||||
uhdk_window *window,
|
||||
uhdk_text title,
|
||||
uhdk_request_id *out
|
||||
);
|
||||
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
|
||||
);
|
||||
UHDK_API uhdk_status UHDK_CALL uhdk_window_set_title(uhdk_window *window, uhdk_text title);
|
||||
UHDK_API uhdk_status UHDK_CALL uhdk_window_set_size(uhdk_window *window, uhdk_size size);
|
||||
UHDK_API uhdk_status UHDK_CALL uhdk_window_set_state(uhdk_window *window, uhdk_window_state state);
|
||||
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);
|
||||
/* Change native decoration and resize styling without recreating the window.
|
||||
* Completion acknowledges the native request; the window manager may apply it
|
||||
* asynchronously. Content dimensions remain content-area dimensions. */
|
||||
UHDK_API uhdk_status UHDK_CALL uhdk_window_set_style_async(
|
||||
* The window manager may apply it asynchronously. Content dimensions remain
|
||||
* content-area dimensions. */
|
||||
UHDK_API uhdk_status UHDK_CALL uhdk_window_set_style(
|
||||
uhdk_window *window,
|
||||
const uhdk_window_style *style,
|
||||
uhdk_request_id *out
|
||||
const uhdk_window_style *style
|
||||
);
|
||||
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_window *window,
|
||||
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. */
|
||||
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_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_end_frame(uhdk_gl_context *context);
|
||||
|
|
@ -570,17 +582,15 @@ enum {
|
|||
UHDK_POINTER_NORMAL = 0,
|
||||
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
|
||||
* 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_pointer_mode mode,
|
||||
uhdk_request_id *out
|
||||
uhdk_cursor_shape shape
|
||||
);
|
||||
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.
|
||||
|
|
@ -609,19 +619,12 @@ typedef struct uhdk_text_state {
|
|||
uint64_t selection_len;
|
||||
uhdk_rect caret; /* Window-local logical coordinates. */
|
||||
} uhdk_text_state;
|
||||
UHDK_API uhdk_status UHDK_CALL uhdk_window_set_text_input_async(
|
||||
uhdk_window *window,
|
||||
uhdk_bool enabled,
|
||||
uhdk_request_id *out
|
||||
);
|
||||
UHDK_API uhdk_status UHDK_CALL uhdk_window_set_text_input(uhdk_window *window, uhdk_bool enabled);
|
||||
UHDK_API uhdk_status UHDK_CALL uhdk_window_set_text_state(
|
||||
uhdk_window *window,
|
||||
const uhdk_text_state *state
|
||||
);
|
||||
UHDK_API uhdk_status UHDK_CALL uhdk_window_cancel_composition_async(
|
||||
uhdk_window *window,
|
||||
uhdk_request_id *out
|
||||
);
|
||||
UHDK_API uhdk_status UHDK_CALL uhdk_window_cancel_composition(uhdk_window *window);
|
||||
|
||||
/* 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
|
||||
|
|
@ -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
|
||||
* 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_text text,
|
||||
uhdk_request_id *out
|
||||
uhdk_text text
|
||||
);
|
||||
UHDK_API uhdk_status UHDK_CALL uhdk_clipboard_read_text_async(
|
||||
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
|
||||
* drag, data offers, or application-visible drop-completion transaction.
|
||||
*/
|
||||
UHDK_API uhdk_status UHDK_CALL uhdk_window_set_drop_enabled_async(
|
||||
uhdk_window *window,
|
||||
uhdk_bool enabled,
|
||||
uhdk_request_id *out
|
||||
);
|
||||
UHDK_API uhdk_status UHDK_CALL uhdk_window_set_drop_enabled(uhdk_window *window, uhdk_bool enabled);
|
||||
|
||||
/* Menus are immutable snapshots. Command IDs are application-assigned, nonzero
|
||||
* 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,
|
||||
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,
|
||||
uint64_t command_id,
|
||||
uhdk_menu_flags flags,
|
||||
uhdk_request_id *out
|
||||
uhdk_menu_flags flags
|
||||
);
|
||||
UHDK_API void UHDK_CALL uhdk_menu_retain(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_menu *menu,
|
||||
uhdk_request_id *out
|
||||
uhdk_menu *menu
|
||||
); /* 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_menu *menu,
|
||||
uhdk_request_id *out
|
||||
uhdk_menu *menu
|
||||
);
|
||||
UHDK_API uhdk_status UHDK_CALL uhdk_menu_popup_async(
|
||||
uhdk_menu *menu,
|
||||
|
|
@ -821,10 +816,9 @@ UHDK_API uhdk_status UHDK_CALL uhdk_menu_popup_async(
|
|||
uhdk_point position,
|
||||
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,
|
||||
const uhdk_image *image,
|
||||
uhdk_request_id *out
|
||||
const uhdk_image *image
|
||||
);
|
||||
|
||||
/* Successful shell completion means handed off to the OS, not that a target
|
||||
|
|
@ -902,18 +896,28 @@ enum {
|
|||
UHDK_EVENT_MENU_COMMAND,
|
||||
UHDK_EVENT_DROP_FILES,
|
||||
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;
|
||||
enum {
|
||||
UHDK_REQUEST_FILE_DIALOG = 1,
|
||||
UHDK_REQUEST_CLIPBOARD_TEXT,
|
||||
UHDK_REQUEST_MENU_POPUP,
|
||||
UHDK_REQUEST_SHELL,
|
||||
UHDK_REQUEST_COMMAND,
|
||||
UHDK_REQUEST_WINDOW,
|
||||
UHDK_REQUEST_GL_CONTEXT,
|
||||
UHDK_REQUEST_WATCH,
|
||||
UHDK_REQUEST_FILE_READ,
|
||||
UHDK_REQUEST_FILE_WRITE,
|
||||
|
|
@ -1050,21 +1054,14 @@ typedef struct uhdk_activation_event {
|
|||
typedef struct uhdk_pointer_mode_event {
|
||||
uhdk_pointer_mode mode;
|
||||
} 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 {
|
||||
uhdk_watch *watch;
|
||||
} uhdk_watch_result;
|
||||
|
||||
/* Request data mapping (only valid on UHDK_STATUS_OK):
|
||||
* 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.
|
||||
* 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 {
|
||||
uhdk_request_id id;
|
||||
|
|
@ -1082,7 +1079,8 @@ typedef struct uhdk_request_result {
|
|||
* POINTER_MODE_CHANGED: uhdk_pointer_mode_event; SCROLL: uhdk_scroll_event;
|
||||
* TEXT_COMMIT/PREEDIT: uhdk_text_event; EDIT_COMMAND: uhdk_edit_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.
|
||||
*/
|
||||
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
|
||||
/* GLAD 2: OpenGL 3.3 core, no extensions, explicit per-context function table.
|
||||
* Do not combine with platform GL headers or GL/glcorearb.h.
|
||||
* The loader implementation is linked into libuhdk; consumers must not define
|
||||
* GLAD_GL_IMPLEMENTATION when linking that library.
|
||||
* The loader implementation is consumer-owned. Define
|
||||
* 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
|
||||
* 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.
|
||||
*/
|
||||
#if defined(UHDK_SHARED)
|
||||
#define GLAD_API_CALL_EXPORT
|
||||
#endif
|
||||
#include "glad/gl.h"
|
||||
#endif /* UHDK_ENABLE_OPENGL */
|
||||
|
||||
|
|
|
|||
|
|
@ -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_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_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 }),
|
||||
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_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)),
|
||||
else => .{},
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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 std = @import("std");
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ const Resource = @import("Resource.zig");
|
|||
const FileOperation = @import("FileOperation.zig");
|
||||
|
||||
const Request = @This();
|
||||
pub const Completion = enum { request, resource, discard };
|
||||
next: ?*Request = null,
|
||||
queued_next: ?*Request = null,
|
||||
arena: abi.Arena,
|
||||
|
|
@ -14,9 +15,10 @@ gpa: std.mem.Allocator,
|
|||
data: c.z_command = std.mem.zeroes(c.z_command),
|
||||
node: *Event,
|
||||
id: u64 = 0,
|
||||
kind: u32 = c.UHDK_REQUEST_COMMAND,
|
||||
kind: u32 = 0,
|
||||
cancelled: bool = false,
|
||||
native_deferred: bool = false,
|
||||
completion: Completion = .request,
|
||||
pins: std.ArrayList(*Resource) = .empty,
|
||||
file_operation: ?FileOperation = null,
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ gpa: std.mem.Allocator,
|
|||
arena: std.heap.ArenaAllocator,
|
||||
next: ?*Resource = null,
|
||||
alive: bool = true,
|
||||
ready: bool,
|
||||
refs: usize = 1,
|
||||
native: ?*anyopaque = null,
|
||||
payload: Payload,
|
||||
|
|
@ -65,6 +66,7 @@ pub fn init(application: *Application, resource_kind: Kind) Resource {
|
|||
.app = application,
|
||||
.gpa = application.gpa,
|
||||
.arena = .init(application.gpa),
|
||||
.ready = resource_kind != .window and resource_kind != .gl,
|
||||
.payload = switch (resource_kind) {
|
||||
.window => .{ .window = .{} },
|
||||
.gl => .{ .gl = .{} },
|
||||
|
|
|
|||
|
|
@ -4,10 +4,9 @@ const c = @import("native");
|
|||
const runtime = @import("../runtime.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,
|
||||
text: c.uhdk_text,
|
||||
out: [*c]u64,
|
||||
) abi.Status {
|
||||
if (!abi.validText(text, false)) return abi.INVALID;
|
||||
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);
|
||||
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(
|
||||
|
|
@ -44,10 +43,9 @@ pub export fn uhdk_shell_open_url_async(
|
|||
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,
|
||||
image: [*c]const c.uhdk_image,
|
||||
out: [*c]u64,
|
||||
) abi.Status {
|
||||
if (!abi.validDescriptor(c.uhdk_image, image)) return abi.INVALID;
|
||||
const i = image.*;
|
||||
|
|
@ -66,7 +64,7 @@ pub export fn uhdk_app_set_icon_async(
|
|||
runtime.abandon(command);
|
||||
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(
|
||||
|
|
|
|||
|
|
@ -5,7 +5,8 @@ const c = @import("native");
|
|||
const runtime = @import("../runtime.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 w = runtime.fromObjectHandle(handle);
|
||||
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;
|
||||
w.payload.window.context = object;
|
||||
command.data.other = object;
|
||||
command.kind = c.UHDK_REQUEST_GL_CONTEXT;
|
||||
return runtime.submit(w.app, command, out);
|
||||
const status = runtime.submitResource(w.app, command);
|
||||
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 {
|
||||
|
|
@ -46,6 +48,31 @@ pub export fn uhdk_gl_context_begin_frame(handle: ?*c.uhdk_gl_context) abi.Statu
|
|||
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 {
|
||||
const status = runtime.glCall(handle, 2, null);
|
||||
if (status == abi.OK) {
|
||||
|
|
|
|||
|
|
@ -4,38 +4,23 @@ const c = @import("native");
|
|||
const runtime = @import("../runtime.zig");
|
||||
const abi = @import("../abi.zig");
|
||||
|
||||
pub export fn uhdk_window_set_cursor_shape_async(
|
||||
handle: ?*c.uhdk_window,
|
||||
shape: u32,
|
||||
out: [*c]u64,
|
||||
) abi.Status {
|
||||
pub export fn uhdk_window_set_cursor_shape(handle: ?*c.uhdk_window, shape: u32) abi.Status {
|
||||
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(
|
||||
handle: ?*c.uhdk_window,
|
||||
mode: u32,
|
||||
out: [*c]u64,
|
||||
) abi.Status {
|
||||
pub export fn uhdk_window_set_pointer_mode(handle: ?*c.uhdk_window, mode: u32) abi.Status {
|
||||
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(
|
||||
handle: ?*c.uhdk_window,
|
||||
enabled: c.uhdk_bool,
|
||||
out: [*c]u64,
|
||||
) abi.Status {
|
||||
pub export fn uhdk_window_set_text_input(handle: ?*c.uhdk_window, enabled: c.uhdk_bool) abi.Status {
|
||||
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(
|
||||
handle: ?*c.uhdk_window,
|
||||
out: [*c]u64,
|
||||
) abi.Status {
|
||||
return runtime.scalarCommand(handle, c.Z_KIND_WINDOW, c.Z_TEXT_CANCEL, 0, out);
|
||||
pub export fn uhdk_window_cancel_composition(handle: ?*c.uhdk_window) abi.Status {
|
||||
return runtime.scalarCommandValue(handle, c.Z_KIND_WINDOW, c.Z_TEXT_CANCEL, 0);
|
||||
}
|
||||
|
||||
pub export fn uhdk_window_set_text_state(
|
||||
|
|
@ -70,11 +55,7 @@ pub export fn uhdk_window_set_text_state(
|
|||
return abi.OK;
|
||||
}
|
||||
|
||||
pub export fn uhdk_window_set_drop_enabled_async(
|
||||
handle: ?*c.uhdk_window,
|
||||
enabled: c.uhdk_bool,
|
||||
out: [*c]u64,
|
||||
) abi.Status {
|
||||
pub export fn uhdk_window_set_drop_enabled(handle: ?*c.uhdk_window, enabled: c.uhdk_bool) abi.Status {
|
||||
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));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,34 +61,31 @@ pub export fn uhdk_menu_release(handle: ?*c.uhdk_menu) void {
|
|||
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,
|
||||
menu: ?*c.uhdk_menu,
|
||||
out: [*c]u64,
|
||||
) 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,
|
||||
menu: ?*c.uhdk_menu,
|
||||
out: [*c]u64,
|
||||
) abi.Status {
|
||||
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,
|
||||
id: u64,
|
||||
flags: u32,
|
||||
out: [*c]u64,
|
||||
) abi.Status {
|
||||
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);
|
||||
command.data.number = id;
|
||||
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(
|
||||
|
|
|
|||
|
|
@ -4,12 +4,13 @@ const c = @import("native");
|
|||
const runtime = @import("../runtime.zig");
|
||||
const abi = @import("../abi.zig");
|
||||
|
||||
pub export fn uhdk_window_create_async(
|
||||
pub export fn uhdk_window_create(
|
||||
handle: ?*c.uhdk_app,
|
||||
desc: [*c]const c.uhdk_window_desc,
|
||||
out: [*c]u64,
|
||||
out: [*c]?*c.uhdk_window,
|
||||
) abi.Status {
|
||||
if (handle == null or !abi.validDescriptor(c.uhdk_window_desc, desc)) return abi.INVALID;
|
||||
if (out == null) return abi.INVALID;
|
||||
const d = desc.*;
|
||||
if (!validStyle(&d.style) 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;
|
||||
command.data.target = object;
|
||||
command.data.window = d;
|
||||
command.kind = c.UHDK_REQUEST_WINDOW;
|
||||
command.data.window.title = abi.copyText(command.arena.allocator(), d.title) catch {
|
||||
runtime.abandon(command);
|
||||
object.alive = false;
|
||||
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) out.* = runtime.castHandle(*c.uhdk_window, object);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
|
@ -53,56 +54,39 @@ pub export fn uhdk_window_destroy(handle: ?*c.uhdk_window) void {
|
|||
if (handle) |_| runtime.destroyObject(runtime.fromObjectHandle(handle));
|
||||
}
|
||||
|
||||
pub export fn uhdk_window_set_title_async(
|
||||
handle: ?*c.uhdk_window,
|
||||
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_title(handle: ?*c.uhdk_window, title: c.uhdk_text) abi.Status {
|
||||
return runtime.textCommandValue(handle, c.Z_KIND_WINDOW, c.Z_TITLE, title);
|
||||
}
|
||||
|
||||
pub export fn uhdk_window_set_size_async(
|
||||
handle: ?*c.uhdk_window,
|
||||
size: c.uhdk_size,
|
||||
out: [*c]u64,
|
||||
) abi.Status {
|
||||
pub export fn uhdk_window_set_size(handle: ?*c.uhdk_window, size: c.uhdk_size) abi.Status {
|
||||
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);
|
||||
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(
|
||||
handle: ?*c.uhdk_window,
|
||||
state: c.uhdk_window_state,
|
||||
out: [*c]u64,
|
||||
) abi.Status {
|
||||
pub export fn uhdk_window_set_state(handle: ?*c.uhdk_window, state: c.uhdk_window_state) abi.Status {
|
||||
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(
|
||||
handle: ?*c.uhdk_window,
|
||||
visible: c.uhdk_bool,
|
||||
out: [*c]u64,
|
||||
) abi.Status {
|
||||
pub export fn uhdk_window_set_visible(handle: ?*c.uhdk_window, visible: c.uhdk_bool) abi.Status {
|
||||
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,
|
||||
style: [*c]const c.uhdk_window_style,
|
||||
out: [*c]u64,
|
||||
) abi.Status {
|
||||
if (!validStyle(style)) return abi.INVALID;
|
||||
const command = runtime.createObjectCommand(handle, c.Z_KIND_WINDOW, c.Z_STYLE) catch |err| return runtime.objectError(err);
|
||||
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 {
|
||||
return runtime.scalarCommand(handle, c.Z_KIND_WINDOW, c.Z_FOCUS, 0, out);
|
||||
pub export fn uhdk_window_request_focus(handle: ?*c.uhdk_window) abi.Status {
|
||||
return runtime.scalarCommandValue(handle, c.Z_KIND_WINDOW, c.Z_FOCUS, 0);
|
||||
}
|
||||
|
||||
pub export fn uhdk_window_get_metrics(
|
||||
|
|
|
|||
|
|
@ -1,3 +0,0 @@
|
|||
/* Implementation for the vendored GLAD 3.3 core header. */
|
||||
#define GLAD_GL_IMPLEMENTATION
|
||||
#include "glad/gl.h"
|
||||
|
|
@ -42,7 +42,7 @@ pub fn finish(b: *native.Backend) void {
|
|||
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 (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;
|
||||
|
|
@ -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 };
|
||||
w.egl = ctx;
|
||||
n.z_object_set_native(object, ctx);
|
||||
result.*.value.gl_context = @ptrCast(object);
|
||||
return abi.OK;
|
||||
}
|
||||
pub fn destroy(ctx: *Context) void {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
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.
|
||||
- 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.
|
||||
|
|
|
|||
|
|
@ -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| {
|
||||
module.addCSourceFile(.{
|
||||
.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", .{});
|
||||
|
|
@ -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 {
|
||||
const test_module = b.createModule(.{ .target = target, .optimize = optimize, .link_libc = true });
|
||||
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);
|
||||
const exe = b.addExecutable(.{ .name = "linux-native-tests", .root_module = test_module });
|
||||
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 {
|
||||
const module = b.createModule(.{ .target = target, .optimize = optimize, .link_libc = true });
|
||||
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);
|
||||
const exe = b.addExecutable(.{ .name = "linux-service-tests", .root_module = module });
|
||||
check.dependOn(&exe.step);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
global:
|
||||
uhdk_*;
|
||||
local:
|
||||
*;
|
||||
};
|
||||
|
|
@ -1,89 +1,93 @@
|
|||
Z_FUNCTION(wl_display_connect)
|
||||
Z_FUNCTION(wl_display_disconnect)
|
||||
Z_FUNCTION(wl_display_get_fd)
|
||||
Z_FUNCTION(wl_display_dispatch_pending)
|
||||
Z_FUNCTION(wl_display_prepare_read)
|
||||
Z_FUNCTION(wl_display_read_events)
|
||||
Z_FUNCTION(wl_display_cancel_read)
|
||||
Z_FUNCTION(wl_display_flush)
|
||||
Z_FUNCTION(wl_proxy_marshal_flags)
|
||||
Z_FUNCTION(wl_proxy_add_listener)
|
||||
Z_FUNCTION(wl_proxy_destroy)
|
||||
Z_FUNCTION(wl_proxy_get_version)
|
||||
Z_FUNCTION(wl_proxy_set_user_data)
|
||||
Z_FUNCTION(wl_proxy_get_user_data)
|
||||
Z_FUNCTION(wl_egl_window_create)
|
||||
Z_FUNCTION(wl_egl_window_destroy)
|
||||
Z_FUNCTION(wl_egl_window_resize)
|
||||
Z_FUNCTION(eglGetPlatformDisplay)
|
||||
Z_FUNCTION(eglInitialize)
|
||||
Z_FUNCTION(eglTerminate)
|
||||
Z_FUNCTION(eglBindAPI)
|
||||
Z_FUNCTION(eglChooseConfig)
|
||||
Z_FUNCTION(eglCreateContext)
|
||||
Z_FUNCTION(eglDestroyContext)
|
||||
Z_FUNCTION(eglCreateWindowSurface)
|
||||
Z_FUNCTION(eglDestroySurface)
|
||||
Z_FUNCTION(eglMakeCurrent)
|
||||
Z_FUNCTION(eglGetCurrentContext)
|
||||
Z_FUNCTION(eglSwapBuffers)
|
||||
Z_FUNCTION(eglSwapInterval)
|
||||
Z_FUNCTION(eglGetProcAddress)
|
||||
Z_FUNCTION(eglReleaseThread)
|
||||
Z_FUNCTION(xkb_context_new)
|
||||
Z_FUNCTION(xkb_context_unref)
|
||||
Z_FUNCTION(xkb_keymap_new_from_string)
|
||||
Z_FUNCTION(xkb_keymap_unref)
|
||||
Z_FUNCTION(xkb_keymap_key_repeats)
|
||||
Z_FUNCTION(xkb_state_new)
|
||||
Z_FUNCTION(xkb_state_unref)
|
||||
Z_FUNCTION(xkb_state_update_mask)
|
||||
Z_FUNCTION(xkb_state_key_get_one_sym)
|
||||
Z_FUNCTION(xkb_state_key_get_utf8)
|
||||
Z_FUNCTION(xkb_state_mod_name_is_active)
|
||||
Z_FUNCTION(xkb_keysym_to_utf32)
|
||||
Z_FUNCTION(xkb_compose_table_new_from_locale)
|
||||
Z_FUNCTION(xkb_compose_table_unref)
|
||||
Z_FUNCTION(xkb_compose_state_new)
|
||||
Z_FUNCTION(xkb_compose_state_unref)
|
||||
Z_FUNCTION(xkb_compose_state_feed)
|
||||
Z_FUNCTION(xkb_compose_state_reset)
|
||||
Z_FUNCTION(xkb_compose_state_get_status)
|
||||
Z_FUNCTION(xkb_compose_state_get_utf8)
|
||||
Z_FUNCTION(dbus_connection_open_private)
|
||||
Z_FUNCTION(dbus_connection_set_exit_on_disconnect)
|
||||
Z_FUNCTION(dbus_connection_close)
|
||||
Z_FUNCTION(dbus_connection_unref)
|
||||
Z_FUNCTION(dbus_connection_get_is_connected)
|
||||
Z_FUNCTION(dbus_connection_get_unix_fd)
|
||||
Z_FUNCTION(dbus_connection_has_messages_to_send)
|
||||
Z_FUNCTION(dbus_connection_read_write)
|
||||
Z_FUNCTION(dbus_connection_pop_message)
|
||||
Z_FUNCTION(dbus_connection_send)
|
||||
Z_FUNCTION(dbus_message_new_method_call)
|
||||
Z_FUNCTION(dbus_message_unref)
|
||||
Z_FUNCTION(dbus_message_get_type)
|
||||
Z_FUNCTION(dbus_message_get_reply_serial)
|
||||
Z_FUNCTION(dbus_message_get_path)
|
||||
Z_FUNCTION(dbus_message_get_sender)
|
||||
Z_FUNCTION(dbus_message_get_error_name)
|
||||
Z_FUNCTION(dbus_message_is_signal)
|
||||
Z_FUNCTION(dbus_message_has_signature)
|
||||
Z_FUNCTION(dbus_message_set_no_reply)
|
||||
Z_FUNCTION(dbus_message_iter_init)
|
||||
Z_FUNCTION(dbus_message_iter_init_append)
|
||||
Z_FUNCTION(dbus_message_iter_get_arg_type)
|
||||
Z_FUNCTION(dbus_message_iter_next)
|
||||
Z_FUNCTION(dbus_message_iter_recurse)
|
||||
Z_FUNCTION(dbus_message_iter_get_basic)
|
||||
Z_FUNCTION(dbus_message_iter_append_basic)
|
||||
Z_FUNCTION(dbus_message_iter_open_container)
|
||||
Z_FUNCTION(dbus_message_iter_close_container)
|
||||
Z_FUNCTION(dbus_message_iter_abandon_container_if_open)
|
||||
Z_FUNCTION(dbus_threads_init_default)
|
||||
Z_FUNCTION(dbus_message_new_method_return)
|
||||
Z_FUNCTION(dbus_message_new_error)
|
||||
Z_FUNCTION(dbus_message_new_signal)
|
||||
Z_FUNCTION(dbus_message_get_interface)
|
||||
Z_FUNCTION(dbus_message_get_member)
|
||||
Z_FUNCTION(dbus_message_get_no_reply)
|
||||
Z_REQUIRED(wl_display_connect)
|
||||
Z_REQUIRED(wl_display_disconnect)
|
||||
Z_REQUIRED(wl_display_get_fd)
|
||||
Z_REQUIRED(wl_display_dispatch_pending)
|
||||
Z_REQUIRED(wl_display_prepare_read)
|
||||
Z_REQUIRED(wl_display_read_events)
|
||||
Z_REQUIRED(wl_display_cancel_read)
|
||||
Z_REQUIRED(wl_display_flush)
|
||||
Z_REQUIRED(wl_proxy_marshal_flags)
|
||||
Z_REQUIRED(wl_proxy_add_listener)
|
||||
Z_REQUIRED(wl_proxy_destroy)
|
||||
Z_REQUIRED(wl_proxy_get_version)
|
||||
Z_REQUIRED(wl_proxy_set_user_data)
|
||||
Z_REQUIRED(wl_proxy_get_user_data)
|
||||
|
||||
Z_OPTIONAL(wayland_egl, have_egl, wl_egl_window_create)
|
||||
Z_OPTIONAL(wayland_egl, have_egl, wl_egl_window_destroy)
|
||||
Z_OPTIONAL(wayland_egl, have_egl, wl_egl_window_resize)
|
||||
|
||||
Z_OPTIONAL(egl, have_egl, eglGetPlatformDisplay)
|
||||
Z_OPTIONAL(egl, have_egl, eglInitialize)
|
||||
Z_OPTIONAL(egl, have_egl, eglTerminate)
|
||||
Z_OPTIONAL(egl, have_egl, eglBindAPI)
|
||||
Z_OPTIONAL(egl, have_egl, eglChooseConfig)
|
||||
Z_OPTIONAL(egl, have_egl, eglCreateContext)
|
||||
Z_OPTIONAL(egl, have_egl, eglDestroyContext)
|
||||
Z_OPTIONAL(egl, have_egl, eglCreateWindowSurface)
|
||||
Z_OPTIONAL(egl, have_egl, eglDestroySurface)
|
||||
Z_OPTIONAL(egl, have_egl, eglMakeCurrent)
|
||||
Z_OPTIONAL(egl, have_egl, eglGetCurrentContext)
|
||||
Z_OPTIONAL(egl, have_egl, eglSwapBuffers)
|
||||
Z_OPTIONAL(egl, have_egl, eglSwapInterval)
|
||||
Z_OPTIONAL(egl, have_egl, eglGetProcAddress)
|
||||
Z_OPTIONAL(egl, have_egl, eglReleaseThread)
|
||||
|
||||
Z_OPTIONAL(xkb, have_xkb, xkb_context_new)
|
||||
Z_OPTIONAL(xkb, have_xkb, xkb_context_unref)
|
||||
Z_OPTIONAL(xkb, have_xkb, xkb_keymap_new_from_string)
|
||||
Z_OPTIONAL(xkb, have_xkb, xkb_keymap_unref)
|
||||
Z_OPTIONAL(xkb, have_xkb, xkb_keymap_key_repeats)
|
||||
Z_OPTIONAL(xkb, have_xkb, xkb_state_new)
|
||||
Z_OPTIONAL(xkb, have_xkb, xkb_state_unref)
|
||||
Z_OPTIONAL(xkb, have_xkb, xkb_state_update_mask)
|
||||
Z_OPTIONAL(xkb, have_xkb, xkb_state_key_get_one_sym)
|
||||
Z_OPTIONAL(xkb, have_xkb, xkb_state_key_get_utf8)
|
||||
Z_OPTIONAL(xkb, have_xkb, xkb_state_mod_name_is_active)
|
||||
Z_OPTIONAL(xkb, have_xkb, xkb_keysym_to_utf32)
|
||||
Z_OPTIONAL(xkb, have_xkb, xkb_compose_table_new_from_locale)
|
||||
Z_OPTIONAL(xkb, have_xkb, xkb_compose_table_unref)
|
||||
Z_OPTIONAL(xkb, have_xkb, xkb_compose_state_new)
|
||||
Z_OPTIONAL(xkb, have_xkb, xkb_compose_state_unref)
|
||||
Z_OPTIONAL(xkb, have_xkb, xkb_compose_state_feed)
|
||||
Z_OPTIONAL(xkb, have_xkb, xkb_compose_state_reset)
|
||||
Z_OPTIONAL(xkb, have_xkb, xkb_compose_state_get_status)
|
||||
Z_OPTIONAL(xkb, have_xkb, xkb_compose_state_get_utf8)
|
||||
|
||||
Z_OPTIONAL(dbus, have_dbus, dbus_connection_open_private)
|
||||
Z_OPTIONAL(dbus, have_dbus, dbus_connection_set_exit_on_disconnect)
|
||||
Z_OPTIONAL(dbus, have_dbus, dbus_connection_close)
|
||||
Z_OPTIONAL(dbus, have_dbus, dbus_connection_unref)
|
||||
Z_OPTIONAL(dbus, have_dbus, dbus_connection_get_is_connected)
|
||||
Z_OPTIONAL(dbus, have_dbus, dbus_connection_get_unix_fd)
|
||||
Z_OPTIONAL(dbus, have_dbus, dbus_connection_has_messages_to_send)
|
||||
Z_OPTIONAL(dbus, have_dbus, dbus_connection_read_write)
|
||||
Z_OPTIONAL(dbus, have_dbus, dbus_connection_pop_message)
|
||||
Z_OPTIONAL(dbus, have_dbus, dbus_connection_send)
|
||||
Z_OPTIONAL(dbus, have_dbus, dbus_message_new_method_call)
|
||||
Z_OPTIONAL(dbus, have_dbus, dbus_message_unref)
|
||||
Z_OPTIONAL(dbus, have_dbus, dbus_message_get_type)
|
||||
Z_OPTIONAL(dbus, have_dbus, dbus_message_get_reply_serial)
|
||||
Z_OPTIONAL(dbus, have_dbus, dbus_message_get_path)
|
||||
Z_OPTIONAL(dbus, have_dbus, dbus_message_get_sender)
|
||||
Z_OPTIONAL(dbus, have_dbus, dbus_message_get_error_name)
|
||||
Z_OPTIONAL(dbus, have_dbus, dbus_message_is_signal)
|
||||
Z_OPTIONAL(dbus, have_dbus, dbus_message_has_signature)
|
||||
Z_OPTIONAL(dbus, have_dbus, dbus_message_set_no_reply)
|
||||
Z_OPTIONAL(dbus, have_dbus, dbus_message_iter_init)
|
||||
Z_OPTIONAL(dbus, have_dbus, dbus_message_iter_init_append)
|
||||
Z_OPTIONAL(dbus, have_dbus, dbus_message_iter_get_arg_type)
|
||||
Z_OPTIONAL(dbus, have_dbus, dbus_message_iter_next)
|
||||
Z_OPTIONAL(dbus, have_dbus, dbus_message_iter_recurse)
|
||||
Z_OPTIONAL(dbus, have_dbus, dbus_message_iter_get_basic)
|
||||
Z_OPTIONAL(dbus, have_dbus, dbus_message_iter_append_basic)
|
||||
Z_OPTIONAL(dbus, have_dbus, dbus_message_iter_open_container)
|
||||
Z_OPTIONAL(dbus, have_dbus, dbus_message_iter_close_container)
|
||||
Z_OPTIONAL(dbus, have_dbus, dbus_message_iter_abandon_container_if_open)
|
||||
Z_OPTIONAL(dbus, have_dbus, dbus_threads_init_default)
|
||||
Z_OPTIONAL(dbus, have_dbus, dbus_message_new_method_return)
|
||||
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)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@
|
|||
#include <pthread.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
|
@ -21,9 +20,11 @@
|
|||
#include <dbus/dbus.h>
|
||||
#include "dbus-imports.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"
|
||||
#undef Z_FUNCTION
|
||||
#undef Z_OPTIONAL
|
||||
#undef Z_REQUIRED
|
||||
|
||||
static void *wayland, *wayland_egl, *egl, *xkb, *dbus;
|
||||
static int have_egl, have_xkb, have_dbus;
|
||||
|
|
@ -59,9 +60,11 @@ void z_linux_libraries_close(void) {
|
|||
if (wayland)
|
||||
dlclose(wayland);
|
||||
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"
|
||||
#undef Z_FUNCTION
|
||||
#undef Z_OPTIONAL
|
||||
#undef Z_REQUIRED
|
||||
}
|
||||
|
||||
int z_linux_libraries_open(void) {
|
||||
|
|
@ -75,34 +78,24 @@ int z_linux_libraries_open(void) {
|
|||
have_xkb = xkb != NULL;
|
||||
dbus = open_library("libdbus-1.so.3");
|
||||
have_dbus = dbus != NULL;
|
||||
#define Z_FUNCTION(name) \
|
||||
#define Z_REQUIRED(name) \
|
||||
do { \
|
||||
const char *symbol = #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); \
|
||||
z_##name = (__typeof__(z_##name))dlsym(wayland, #name); \
|
||||
if (!z_##name) { \
|
||||
if (bus) \
|
||||
have_dbus = 0; \
|
||||
else if (keyboard) \
|
||||
have_xkb = 0; \
|
||||
else if (graphics) \
|
||||
have_egl = 0; \
|
||||
else { \
|
||||
z_linux_libraries_close(); \
|
||||
return 0; \
|
||||
} \
|
||||
z_linux_libraries_close(); \
|
||||
return 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"
|
||||
#undef Z_FUNCTION
|
||||
#undef Z_OPTIONAL
|
||||
#undef Z_REQUIRED
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -426,13 +426,11 @@ fn completeCreation(w: *Window, status: u32) void {
|
|||
if (id == 0) return;
|
||||
w.request = 0;
|
||||
const app = runtime.toAppHandle(w.owner);
|
||||
var result = std.mem.zeroes(n.z_request_result);
|
||||
result.value.window = w.handle;
|
||||
if (status != abi.OK) {
|
||||
n.z_object_set_native(w.handle, null);
|
||||
destroyWindow(w);
|
||||
}
|
||||
n.z_complete(app, id, status, &result);
|
||||
n.z_complete(app, id, status, null);
|
||||
}
|
||||
|
||||
fn apply(w: *Window) void {
|
||||
|
|
@ -582,7 +580,7 @@ fn destroyWindow(w: *Window) void {
|
|||
if (w.surface != null) c.wl_surface_destroy(w.surface);
|
||||
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 cmd: *const n.z_command = &raw.*;
|
||||
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_FOCUS => return Desktop.focus(w, id),
|
||||
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,
|
||||
}
|
||||
return abi.OK;
|
||||
|
|
|
|||
|
|
@ -1,9 +1,15 @@
|
|||
/* Included by the service harness: all desktop traffic uses private fixtures. */
|
||||
#define OPEN_ID UINT64_C(0x1234567800000065)
|
||||
static void menu_phase(uhdk_app *app, uhdk_window *w, const char *phase) {
|
||||
uint64_t id;
|
||||
OK(uhdk_window_set_title_async(w, text(phase), &id));
|
||||
OK(wait_result(app, id).status);
|
||||
OK(uhdk_window_set_title(w, text(phase)));
|
||||
uhdk_window_invalidate(w);
|
||||
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) {
|
||||
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));
|
||||
uhdk_menu_release(child);
|
||||
uint64_t id;
|
||||
OK(uhdk_app_set_menu_async(app, root, &id));
|
||||
OK(wait_result(app, id).status);
|
||||
OK(uhdk_app_set_menu(app, root));
|
||||
uhdk_window *a = window(app), *b = window(app);
|
||||
uhdk_menu_item overrides[] = {
|
||||
{.command_id = 200, .label = {"Window action", 13}},
|
||||
|
|
@ -43,11 +48,9 @@ static void menus(uhdk_app *app) {
|
|||
};
|
||||
uhdk_menu *override;
|
||||
OK(uhdk_menu_create(app, overrides, 2, &override));
|
||||
OK(uhdk_window_set_menu_async(b, override, &id));
|
||||
OK(wait_result(app, id).status);
|
||||
OK(uhdk_window_set_menu(b, override));
|
||||
uhdk_menu_release(override); // The attachment must keep its model alive.
|
||||
OK(uhdk_window_set_text_input_async(a, 1, &id));
|
||||
OK(wait_result(app, id).status);
|
||||
OK(uhdk_window_set_text_input(a, 1));
|
||||
OK(uhdk_menu_popup_async(root, a, (uhdk_point){0, 0}, &id));
|
||||
assert(wait_result(app, id).status == UHDK_STATUS_UNSUPPORTED);
|
||||
menu_phase(app, a, "menus-ready");
|
||||
|
|
@ -101,27 +104,21 @@ static void menus(uhdk_app *app) {
|
|||
assert(
|
||||
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(wait_result(app, id).status);
|
||||
OK(uhdk_menu_set_item_flags_async(root, 102, 0, &id));
|
||||
OK(wait_result(app, id).status);
|
||||
OK(uhdk_menu_set_item_flags(root, 10, UHDK_MENU_DISABLED));
|
||||
OK(uhdk_menu_set_item_flags(root, 102, 0));
|
||||
menu_phase(app, a, "flags-ready");
|
||||
} else if (stage == 2) {
|
||||
assert(raw_o >= 2);
|
||||
OK(uhdk_menu_set_item_flags_async(root, 10, 0, &id));
|
||||
OK(wait_result(app, id).status);
|
||||
OK(uhdk_window_set_menu_async(b, NULL, &id));
|
||||
OK(wait_result(app, id).status);
|
||||
OK(uhdk_menu_set_item_flags(root, 10, 0));
|
||||
OK(uhdk_window_set_menu(b, NULL));
|
||||
menu_phase(app, a, "restored-ready");
|
||||
} else if (stage == 3) {
|
||||
assert(opens_a == 2 && opens_b == 1 && copies == 2);
|
||||
// Override survives clearing the app default, then the first window dies.
|
||||
OK(uhdk_menu_create(app, overrides, 2, &override));
|
||||
OK(uhdk_window_set_menu_async(b, override, &id));
|
||||
OK(wait_result(app, id).status);
|
||||
OK(uhdk_window_set_menu(b, override));
|
||||
uhdk_menu_release(override);
|
||||
OK(uhdk_app_set_menu_async(app, NULL, &id));
|
||||
OK(wait_result(app, id).status);
|
||||
OK(uhdk_app_set_menu(app, NULL));
|
||||
uhdk_menu_release(root);
|
||||
uhdk_window_destroy(a);
|
||||
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 *menu;
|
||||
OK(uhdk_menu_create(app, &item, 1, &menu));
|
||||
uint64_t id;
|
||||
OK(uhdk_app_set_menu_async(app, menu, &id));
|
||||
assert(
|
||||
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)
|
||||
);
|
||||
(void)no_bus;
|
||||
OK(uhdk_app_set_menu(app, menu));
|
||||
OK(uhdk_window_set_menu(w, 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(wait_result(app, id).status);
|
||||
OK(uhdk_app_set_menu_async(app, NULL, &id));
|
||||
OK(wait_result(app, id).status);
|
||||
OK(uhdk_menu_set_item_flags(menu, 1, UHDK_MENU_CHECKED));
|
||||
OK(uhdk_app_set_menu(app, NULL));
|
||||
uhdk_menu_release(menu);
|
||||
uhdk_window_destroy(w);
|
||||
puts("Unavailable menu protocol/session bus: PASS");
|
||||
|
|
|
|||
|
|
@ -20,24 +20,6 @@ static uhdk_text text(const char *s) {
|
|||
}
|
||||
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) {
|
||||
uhdk_window_metrics m = {0};
|
||||
m.struct_size = sizeof(m);
|
||||
|
|
@ -70,11 +52,26 @@ static uhdk_window_desc descriptor(void) {
|
|||
|
||||
static uhdk_window *create_window(uhdk_app *app) {
|
||||
uhdk_window_desc desc = descriptor();
|
||||
uint64_t id;
|
||||
OK(uhdk_window_create_async(app, &desc, &id));
|
||||
uhdk_request_result result = wait_request(app, id);
|
||||
OK(result.status);
|
||||
return ((const uhdk_window_result *)result.data)->window;
|
||||
uhdk_window *result = NULL;
|
||||
OK(uhdk_window_create(app, &desc, &result));
|
||||
wait_metrics(app, result, 0, 320);
|
||||
return result;
|
||||
}
|
||||
|
||||
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) {
|
||||
|
|
@ -85,23 +82,18 @@ static void test_main(uhdk_app *app, void *user) {
|
|||
OK(uhdk_app_poll_events(app, 0, &ready));
|
||||
assert(ready.len > 0 && ready.ptr[0].type == UHDK_EVENT_READY);
|
||||
|
||||
// Cancellation must complete exactly once even before the first configure.
|
||||
uint64_t id;
|
||||
// Pending creation can be destroyed before the first configure.
|
||||
uhdk_window_desc desc = descriptor();
|
||||
OK(uhdk_window_create_async(app, &desc, &id));
|
||||
OK(uhdk_request_cancel(app, id));
|
||||
uhdk_request_result cancelled = wait_request(app, id);
|
||||
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);
|
||||
uhdk_window *pending = NULL;
|
||||
OK(uhdk_window_create(app, &desc, &pending));
|
||||
uhdk_window_destroy(pending);
|
||||
|
||||
// Destroying a parent must also complete a child still awaiting configure.
|
||||
uhdk_window *parent = create_window(app);
|
||||
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_request_result child = wait_request(app, id);
|
||||
assert(child.status == UHDK_STATUS_CANCELLED || child.status == UHDK_STATUS_OK);
|
||||
desc.parent = NULL;
|
||||
|
||||
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));
|
||||
assert(native.backend == UHDK_BACKEND_WAYLAND && native.primary && native.secondary);
|
||||
uhdk_window_style style = {sizeof(style), 0, 0, 0};
|
||||
OK(uhdk_window_set_style_async(w, &style, &id));
|
||||
OK(wait_request(app, id).status);
|
||||
OK(uhdk_window_set_style(w, &style));
|
||||
style.decorated = 1;
|
||||
style.resizable = 1;
|
||||
OK(uhdk_window_set_style_async(w, &style, &id));
|
||||
OK(wait_request(app, id).status);
|
||||
OK(uhdk_window_set_style(w, &style));
|
||||
|
||||
const uint8_t path[] = "/tmp/uhdk file-%\xff";
|
||||
uhdk_file *file;
|
||||
|
|
@ -130,11 +120,9 @@ static void test_main(uhdk_app *app, void *user) {
|
|||
|
||||
if (!user) {
|
||||
assert(uhdk_app_has_capability(app, UHDK_CAP_OPENGL));
|
||||
OK(uhdk_gl_context_create_async(w, &id));
|
||||
uhdk_request_result gl_result = wait_request(app, id);
|
||||
OK(gl_result.status);
|
||||
uhdk_gl_context *gl = ((const uhdk_gl_context_result *)gl_result.data)->gl_context;
|
||||
OK(uhdk_gl_context_begin_frame(gl));
|
||||
uhdk_gl_context *gl = NULL;
|
||||
OK(uhdk_gl_context_create(w, &gl));
|
||||
begin_context(app, gl);
|
||||
assert(uhdk_gl_context_begin_frame(gl) == UHDK_STATUS_BUSY);
|
||||
uint32_t 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) {
|
||||
int width = 320 + pass * 20;
|
||||
OK(uhdk_window_set_size_async(w, (uhdk_size){width, 240}, &id));
|
||||
OK(wait_request(app, id).status);
|
||||
OK(uhdk_window_set_visible_async(w, 1, &id));
|
||||
OK(wait_request(app, id).status);
|
||||
OK(uhdk_window_set_size(w, (uhdk_size){width, 240}));
|
||||
OK(uhdk_window_set_visible(w, 1));
|
||||
wait_metrics(app, w, 1, width);
|
||||
for (int frame = 0; frame < 4; ++frame) {
|
||||
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_end_frame(gl));
|
||||
}
|
||||
OK(uhdk_window_set_visible_async(w, 0, &id));
|
||||
OK(wait_request(app, id).status);
|
||||
OK(uhdk_window_set_visible(w, 0));
|
||||
wait_metrics(app, w, 0, width);
|
||||
}
|
||||
uhdk_gl_context_destroy(gl);
|
||||
// Destroying a context releases its reservation on the window.
|
||||
OK(uhdk_gl_context_create_async(w, &id));
|
||||
gl_result = wait_request(app, id);
|
||||
OK(gl_result.status);
|
||||
uhdk_gl_context_destroy(((const uhdk_gl_context_result *)gl_result.data)->gl_context);
|
||||
OK(uhdk_gl_context_create(w, &gl));
|
||||
uhdk_gl_context_destroy(gl);
|
||||
}
|
||||
uhdk_window_destroy(w);
|
||||
// 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) {
|
||||
|
|
|
|||
|
|
@ -6,10 +6,8 @@ static void popups(uhdk_app *app) {
|
|||
wait_capability(app, UHDK_CAP_CONTEXT_MENU);
|
||||
assert(!uhdk_app_has_capability(app, UHDK_CAP_APP_MENU));
|
||||
uint64_t id;
|
||||
OK(uhdk_window_set_visible_async(w, 1, &id));
|
||||
OK(wait_result(app, id).status);
|
||||
OK(uhdk_window_set_text_input_async(w, 1, &id));
|
||||
OK(wait_result(app, id).status);
|
||||
OK(uhdk_window_set_visible(w, 1));
|
||||
OK(uhdk_window_set_text_input(w, 1));
|
||||
uhdk_menu_item child_items[] = {{.command_id = POPUP_CHILD, .label = {"Child café", 11}}};
|
||||
uhdk_menu *child, *root;
|
||||
OK(uhdk_menu_create(app, child_items, 1, &child));
|
||||
|
|
@ -40,8 +38,7 @@ static void popups(uhdk_app *app) {
|
|||
}
|
||||
char title[64];
|
||||
snprintf(title, sizeof(title), "popup-stage-%u", stage);
|
||||
OK(uhdk_window_set_title_async(w, text(title), &id));
|
||||
// Do not discard the input event that may arrive with title completion.
|
||||
OK(uhdk_window_set_title(w, text(title)));
|
||||
uint64_t popup = 0, busy = 0, started = 0;
|
||||
unsigned commands = 0, complete = 0, busy_done = 0, changed = 0;
|
||||
uint64_t end = deadline(app);
|
||||
|
|
@ -92,8 +89,8 @@ static void popups(uhdk_app *app) {
|
|||
if (stage == 5)
|
||||
OK(uhdk_request_cancel(app, popup));
|
||||
if (stage == 6) {
|
||||
OK(uhdk_menu_set_item_flags_async(root, POPUP_OPEN, UHDK_MENU_DISABLED, &id));
|
||||
OK(uhdk_menu_set_item_flags_async(root, 103, 0, &id));
|
||||
OK(uhdk_menu_set_item_flags(root, POPUP_OPEN, UHDK_MENU_DISABLED));
|
||||
OK(uhdk_menu_set_item_flags(root, 103, 0));
|
||||
}
|
||||
if (stage == 11)
|
||||
uhdk_window_destroy(w);
|
||||
|
|
|
|||
|
|
@ -41,11 +41,20 @@ static uhdk_window *window(uhdk_app *app) {
|
|||
desc.title = text("UHDK service tests");
|
||||
desc.content_size = (uhdk_size){320, 240};
|
||||
desc.style = (uhdk_window_style){sizeof(uhdk_window_style), 1, 1, 0};
|
||||
uint64_t id;
|
||||
OK(uhdk_window_create_async(app, &desc, &id));
|
||||
uhdk_request_result r = wait_result(app, id);
|
||||
OK(r.status);
|
||||
return ((const uhdk_window_result *)r.data)->window;
|
||||
uhdk_window *result = NULL;
|
||||
OK(uhdk_window_create(app, &desc, &result));
|
||||
uint64_t end = deadline(app);
|
||||
while (uhdk_app_get_time_ns(app) < end) {
|
||||
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) {
|
||||
uint64_t end = deadline(app);
|
||||
|
|
@ -130,12 +139,9 @@ static void real_desktop(uhdk_app *app) {
|
|||
image.height = 1;
|
||||
image.stride_bytes = 8;
|
||||
image.pixels = (uhdk_bytes){rgba, sizeof(rgba)};
|
||||
uint64_t id;
|
||||
OK(uhdk_app_set_icon_async(app, &image, &id));
|
||||
OK(wait_result(app, id).status);
|
||||
OK(uhdk_app_set_icon(app, &image));
|
||||
// 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));
|
||||
assert(wait_result(app, id).status == UHDK_STATUS_UNAVAILABLE);
|
||||
OK(uhdk_clipboard_write_text(app, text("must not replace clipboard")));
|
||||
uhdk_window_destroy(w);
|
||||
}
|
||||
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);
|
||||
assert(metrics.observations == known);
|
||||
assert(!metrics.minimized && !metrics.occluded && !metrics.suspended && !metrics.resizing);
|
||||
uint64_t request;
|
||||
OK(uhdk_window_set_state_async(w, UHDK_WINDOW_MINIMIZED, &request));
|
||||
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);
|
||||
OK(uhdk_window_set_state(w, UHDK_WINDOW_MINIMIZED));
|
||||
OK(uhdk_window_set_state(w, UHDK_WINDOW_FULLSCREEN));
|
||||
for (int phase = 0; phase < 2; ++phase) {
|
||||
OK(uhdk_window_set_title_async(
|
||||
w, text(phase ? "fixture:resume" : "fixture:suspend"), &request
|
||||
));
|
||||
OK(uhdk_window_set_title(w, text(phase ? "fixture:resume" : "fixture:suspend")));
|
||||
uhdk_window_invalidate(w);
|
||||
int matched = 0, completed = 0;
|
||||
uint64_t end = deadline(app);
|
||||
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->suspended == (!phase && version >= 6))
|
||||
matched = 1;
|
||||
} else if (events.ptr[i].type == UHDK_EVENT_REQUEST_DONE) {
|
||||
const uhdk_request_result *r = events.ptr[i].data;
|
||||
if (r->id == request) {
|
||||
OK(r->status);
|
||||
completed = 1;
|
||||
}
|
||||
}
|
||||
} else if (events.ptr[i].type == UHDK_EVENT_WINDOW_REDRAW &&
|
||||
events.ptr[i].window == w)
|
||||
completed = 1;
|
||||
}
|
||||
}
|
||||
assert(matched && completed);
|
||||
}
|
||||
OK(uhdk_window_set_state_async(w, UHDK_WINDOW_MINIMIZED, &request));
|
||||
OK(wait_result(app, request).status);
|
||||
OK(uhdk_window_set_state(w, UHDK_WINDOW_MINIMIZED));
|
||||
OK(uhdk_window_get_metrics(w, &metrics));
|
||||
assert(!(metrics.observations & UHDK_WINDOW_OBSERVE_MINIMIZED));
|
||||
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) {
|
||||
uhdk_window *w = window(app);
|
||||
uint64_t request;
|
||||
OK(uhdk_window_set_text_input_async(w, 1, &request));
|
||||
OK(wait_result(app, request).status);
|
||||
OK(uhdk_window_set_text_input(w, 1));
|
||||
const struct {
|
||||
uint32_t command;
|
||||
int extend;
|
||||
|
|
@ -300,7 +295,8 @@ static void editing(uhdk_app *app) {
|
|||
OK(uhdk_window_set_text_state(w, &state));
|
||||
char title[32];
|
||||
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;
|
||||
unsigned commands = 0;
|
||||
uint64_t end = deadline(app);
|
||||
|
|
@ -320,13 +316,8 @@ static void editing(uhdk_app *app) {
|
|||
assert(!!edit->extend_selection == cases[i].extend);
|
||||
acknowledged = event->input_id;
|
||||
++commands;
|
||||
} else if (event->type == UHDK_EVENT_REQUEST_DONE) {
|
||||
const uhdk_request_result *r = event->data;
|
||||
if (r->id == request) {
|
||||
OK(r->status);
|
||||
completed = 1;
|
||||
}
|
||||
}
|
||||
} else if (event->type == UHDK_EVENT_WINDOW_REDRAW && event->window == w)
|
||||
completed = 1;
|
||||
}
|
||||
}
|
||||
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) {
|
||||
uhdk_window *w = window(app);
|
||||
uint64_t id;
|
||||
OK(uhdk_window_set_text_input_async(w, 1, &id));
|
||||
OK(wait_result(app, id).status);
|
||||
OK(uhdk_window_set_drop_enabled_async(w, 1, &id));
|
||||
OK(wait_result(app, id).status);
|
||||
OK(uhdk_window_set_text_input(w, 1));
|
||||
OK(uhdk_window_set_drop_enabled(w, 1));
|
||||
uhdk_text_state state = {0};
|
||||
state.struct_size = sizeof(state);
|
||||
state.surrounding_text = text("abc");
|
||||
|
|
@ -351,7 +340,7 @@ static void input(uhdk_app *app) {
|
|||
OK(uhdk_window_set_text_state(w, &state));
|
||||
unsigned key = 0, repeat = 0, commit = 0, preedit = 0, pointer = 0, scroll = 0, dropped = 0,
|
||||
copy = 0, compose = 0, captured = 0, released = 0;
|
||||
uint64_t acknowledged = 0, capture_request = 0;
|
||||
uint64_t acknowledged = 0;
|
||||
int published = 0;
|
||||
uint64_t end = deadline(app);
|
||||
while (uhdk_app_get_time_ns(app) < end &&
|
||||
|
|
@ -402,9 +391,7 @@ static void input(uhdk_app *app) {
|
|||
}
|
||||
case UHDK_EVENT_POINTER_BUTTON:
|
||||
if (((const uhdk_pointer_event *)e->data)->pressed)
|
||||
OK(uhdk_window_set_pointer_mode_async(
|
||||
w, UHDK_POINTER_CAPTURE, &capture_request
|
||||
));
|
||||
OK(uhdk_window_set_pointer_mode(w, UHDK_POINTER_CAPTURE));
|
||||
break;
|
||||
case UHDK_EVENT_POINTER_MODE_CHANGED:
|
||||
if (((const uhdk_pointer_mode_event *)e->data)->mode == UHDK_POINTER_CAPTURE)
|
||||
|
|
@ -412,10 +399,6 @@ static void input(uhdk_app *app) {
|
|||
else
|
||||
released++;
|
||||
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: {
|
||||
const uhdk_pointer_event *p = e->data;
|
||||
if (p->position.x == 12 && p->position.y == 18)
|
||||
|
|
@ -479,10 +462,8 @@ static void input(uhdk_app *app) {
|
|||
r = wait_result(app, id);
|
||||
OK(r.status);
|
||||
assert(((const uhdk_text *)r.data)->len == 0);
|
||||
OK(uhdk_clipboard_write_text_async(app, text("local copy"), &id));
|
||||
OK(wait_result(app, id).status);
|
||||
OK(uhdk_window_request_focus_async(w, &id));
|
||||
OK(wait_result(app, id).status);
|
||||
OK(uhdk_clipboard_write_text(app, text("local copy")));
|
||||
OK(uhdk_window_request_focus(w));
|
||||
uhdk_window_destroy(w);
|
||||
puts("input/IME/clipboard/drop/activation: PASS");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1508,7 +1508,6 @@ uhdk_status z_native_execute(uhdk_app *app, const z_command *cmd, uint64_t reque
|
|||
[w.window makeFirstResponder:w.view];
|
||||
[host.windows addObject:w];
|
||||
z_object_set_native(cmd->target, (__bridge_retained void *)w);
|
||||
result->value.window = cmd->target;
|
||||
[w metrics];
|
||||
break;
|
||||
}
|
||||
|
|
@ -1587,7 +1586,6 @@ uhdk_status z_native_execute(uhdk_app *app, const z_command *cmd, uint64_t reque
|
|||
return UHDK_STATUS_UNSUPPORTED;
|
||||
w.gl = gl;
|
||||
z_object_set_native(cmd->other, (__bridge_retained void *)gl);
|
||||
result->value.gl_context = cmd->other;
|
||||
[w metrics];
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,8 +16,6 @@ typedef struct z_request_result {
|
|||
union {
|
||||
uhdk_file_list files; /* FILE_DIALOG */
|
||||
uhdk_text text; /* CLIPBOARD_TEXT */
|
||||
uhdk_window *window;
|
||||
uhdk_gl_context *gl_context;
|
||||
uhdk_watch *watch;
|
||||
uhdk_bytes bytes;
|
||||
uhdk_file_info info;
|
||||
|
|
@ -44,6 +42,7 @@ typedef struct z_event {
|
|||
uhdk_drop_files_event drop_files;
|
||||
uhdk_menu_event menu;
|
||||
uhdk_watch_event watch;
|
||||
uhdk_resource_event resource;
|
||||
z_request_result request;
|
||||
} data;
|
||||
} z_event;
|
||||
|
|
|
|||
105
src/runtime.zig
105
src/runtime.zig
|
|
@ -260,6 +260,18 @@ pub fn submit(application: *Application, command: *Request, out: [*c]u64) abi.St
|
|||
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 {
|
||||
const command = createCommand(object.app, op, object) catch {
|
||||
object.app.lock();
|
||||
|
|
@ -291,17 +303,50 @@ pub fn finish(
|
|||
abandon(command);
|
||||
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);
|
||||
const node = command.node;
|
||||
node.event.type = c.UHDK_EVENT_REQUEST_DONE;
|
||||
if (value) |v| node.event.data.request = v.*;
|
||||
node.event.data.request.id = command.id;
|
||||
node.event.data.request.kind = command.kind;
|
||||
node.event.data.request.status = status;
|
||||
copyPayload(node) catch {
|
||||
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 };
|
||||
const publish = switch (command.completion) {
|
||||
.request => request: {
|
||||
node.event.type = c.UHDK_EVENT_REQUEST_DONE;
|
||||
if (value) |v| node.event.data.request = v.*;
|
||||
node.event.data.request.id = command.id;
|
||||
node.event.data.request.kind = command.kind;
|
||||
node.event.data.request.status = status;
|
||||
copyPayload(node) catch {
|
||||
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();
|
||||
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;
|
||||
}
|
||||
publishLocked(application, node);
|
||||
if (publish) publishLocked(application, node);
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
@ -402,32 +450,20 @@ pub fn objectError(err: anyerror) abi.Status {
|
|||
};
|
||||
}
|
||||
|
||||
pub fn scalarCommand(
|
||||
handle: ?*c.uhdk_window,
|
||||
kind: u32,
|
||||
op: u32,
|
||||
value: u64,
|
||||
out: [*c]u64,
|
||||
) abi.Status {
|
||||
pub fn scalarCommandValue(handle: ?*c.uhdk_window, kind: u32, op: u32, value: u64) abi.Status {
|
||||
const command = createObjectCommand(handle, kind, op) catch |err| return objectError(err);
|
||||
command.data.number = value;
|
||||
return submit(fromObjectHandle(handle).app, command, out);
|
||||
return submitCommand(fromObjectHandle(handle).app, command);
|
||||
}
|
||||
|
||||
pub fn textCommand(
|
||||
handle: ?*c.uhdk_window,
|
||||
kind: u32,
|
||||
op: u32,
|
||||
text: c.uhdk_text,
|
||||
out: [*c]u64,
|
||||
) abi.Status {
|
||||
pub fn textCommandValue(handle: ?*c.uhdk_window, kind: u32, op: u32, text: c.uhdk_text) abi.Status {
|
||||
if (!abi.validText(text, true)) return abi.INVALID;
|
||||
const command = createObjectCommand(handle, kind, op) catch |err| return objectError(err);
|
||||
command.data.text = abi.copyText(command.arena.allocator(), text) catch {
|
||||
abandon(command);
|
||||
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 {
|
||||
|
|
@ -592,7 +628,6 @@ pub fn attachMenu(
|
|||
handle: ?*c.uhdk_app,
|
||||
w: ?*c.uhdk_window,
|
||||
menu: ?*c.uhdk_menu,
|
||||
out: [*c]u64,
|
||||
) abi.Status {
|
||||
if (handle == null or
|
||||
(menu != null and (fromObjectHandle(menu).app != fromAppHandle(handle) or
|
||||
|
|
@ -616,7 +651,7 @@ pub fn attachMenu(
|
|||
return abi.OOM;
|
||||
};
|
||||
}
|
||||
return submit(fromAppHandle(handle), command, out);
|
||||
return submitCommand(fromAppHandle(handle), command);
|
||||
}
|
||||
|
||||
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);
|
||||
var count: usize = 0;
|
||||
var blocked_on_resource = false;
|
||||
while (count < 64 and now(application.io) - start < 2_000_000) : (count += 1) {
|
||||
application.lock();
|
||||
const command = application.queue_head orelse {
|
||||
|
|
@ -741,6 +777,17 @@ pub fn dispatch(handle: ?*c.uhdk_app) void {
|
|||
finish(application, command, abi.CANCELLED, null);
|
||||
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) {
|
||||
application.lock();
|
||||
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;
|
||||
}
|
||||
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();
|
||||
if (done and application.native_running) c.z_native_stop() else if (again) c.z_native_again();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
z_request_result *result) {
|
||||
(void)app;
|
||||
(void)result;
|
||||
Window *w =
|
||||
cmd->target && z_object_kind(cmd->target) == Z_KIND_WINDOW ? windowOf(cmd->target) : NULL;
|
||||
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;
|
||||
host.windows = w;
|
||||
z_object_set_native(cmd->target, w);
|
||||
result->value.window = cmd->target;
|
||||
if (host.icon) {
|
||||
SendMessageW(hwnd, WM_SETICON, ICON_BIG, (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;
|
||||
case Z_GL: {
|
||||
uhdk_status status = createGraphics(w, cmd->other);
|
||||
if (status == UHDK_STATUS_OK)
|
||||
result->value.gl_context = cmd->other;
|
||||
return status;
|
||||
}
|
||||
case Z_CURSOR: {
|
||||
|
|
|
|||
Loading…
Reference in New Issue