From 91646cbafee3ff67baff52499529ac9077675239 Mon Sep 17 00:00:00 2001 From: Mitya Selivanov Date: Tue, 7 Jan 2025 00:16:22 +0100 Subject: Fix clipboard; TODO keys --- Dockerfile | 2 +- examples/ui.c | 7 +++---- index.htm | 15 ++++++++++----- reduced_system_layer.c | 2 ++ 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index bbe548b..407cb16 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,7 +5,7 @@ RUN apk add clang lld COPY examples /usr/examples COPY reduced_system_layer.c /usr/reduced_system_layer.c COPY graphics.c /usr/graphics.c -RUN clang --target=wasm32 -nostdlib -fno-builtin -mbulk-memory -Wl,--no-entry,--allow-undefined -o /usr/index.wasm /usr/examples/graph.c +RUN clang --target=wasm32 -nostdlib -fno-builtin -mbulk-memory -Wl,--no-entry,--allow-undefined -o /usr/index.wasm /usr/examples/ui.c FROM nginx:alpine EXPOSE 80 diff --git a/examples/ui.c b/examples/ui.c index 1301a6c..d595617 100755 --- a/examples/ui.c +++ b/examples/ui.c @@ -172,7 +172,7 @@ void update_and_render_frame(void) { ++cursor; break; - case '\b': + case KEY_BACKSPACE: if (selection != 0) { i64 i0 = selection < 0 ? cursor + selection : cursor; i64 i1 = selection < 0 ? cursor : cursor + selection; @@ -205,9 +205,8 @@ void update_and_render_frame(void) { } break; - case '\n': - case '\r': - case '\t': + case KEY_ENTER: + case KEY_TAB: platform.input[i].c = platform.input[i].key; // fallthrough diff --git a/index.htm b/index.htm index 7f82840..33d6c2d 100644 --- a/index.htm +++ b/index.htm @@ -34,9 +34,12 @@ }, env : { p_clipboard_write : (size, text) => { + let text_buffer = new ArrayBuffer(size); + new Uint8Array(text_buffer).set(new Uint8Array(this.memory_buffer, text, size)); + this.port.postMessage({ - id : "clipboard", - text : new TextDecoder("utf8").decode(new Uint8Array(this.memory_buffer, text, size)), // FIXME + id : "clipboard", + text_buffer : text_buffer, }); }, p_time_impl : Date.now, @@ -370,7 +373,7 @@ }, clipboard : (ev) => { - navigator.clipboard.writeText(ev.text); + navigator.clipboard.writeText(new TextDecoder("utf8").decode(new Uint8Array(ev.text_buffer))); }, frame : (ev) => { @@ -424,7 +427,7 @@ }); }); - canvas.addEventListener("keydown", (ev) => { + window.addEventListener("keydown", (ev) => { ev.preventDefault(); if (!sound_ready) return; @@ -435,6 +438,8 @@ if (key == 0) return; + console.log(ev); + sound_node.port.postMessage({ id : "keydown", mod : mod, @@ -442,7 +447,7 @@ }); }); - canvas.addEventListener("keyup", (ev) => { + window.addEventListener("keyup", (ev) => { ev.preventDefault(); if (!sound_ready) return; diff --git a/reduced_system_layer.c b/reduced_system_layer.c index 587b319..30fb48b 100755 --- a/reduced_system_layer.c +++ b/reduced_system_layer.c @@ -1723,6 +1723,7 @@ __attribute__((export_name("js_mouseup"))) void js_mouseup(u32 buttons) { } __attribute__((export_name("js_keydown"))) void js_keydown(u32 key, u32 mod) { + // TODO ++_num_events; _key_pressed[key] = 1; platform.key_down[key] = 1; @@ -1734,6 +1735,7 @@ __attribute__((export_name("js_keydown"))) void js_keydown(u32 key, u32 mod) { } __attribute__((export_name("js_keyup"))) void js_keyup(u32 key, u32 mod) { + // TODO ++_num_events; platform.key_down[key] = 0; } -- cgit v1.2.3