diff options
author | Mitya Selivanov <automainint@guattari.tech> | 2025-01-07 00:16:22 +0100 |
---|---|---|
committer | Mitya Selivanov <automainint@guattari.tech> | 2025-01-07 00:16:22 +0100 |
commit | 91646cbafee3ff67baff52499529ac9077675239 (patch) | |
tree | ef450666dc81f014025425264cf38b2bac2ab7c3 | |
parent | 8572d0ade4d8447ba68c4f6e3a7e791a8b38ad22 (diff) | |
download | reduced_system_layer-91646cbafee3ff67baff52499529ac9077675239.zip |
Fix clipboard; TODO keys
-rw-r--r-- | Dockerfile | 2 | ||||
-rwxr-xr-x | examples/ui.c | 7 | ||||
-rw-r--r-- | index.htm | 15 | ||||
-rwxr-xr-x | reduced_system_layer.c | 2 |
4 files changed, 16 insertions, 10 deletions
@@ -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 @@ -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; } |