diff --git a/Cargo.lock b/Cargo.lock index 6d4a57595b5..e863ac889bc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2230,9 +2230,9 @@ dependencies = [ [[package]] name = "minifb" -version = "0.23.0" +version = "0.24.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9e21c5f89bb820c7878c300c5b944e65de0f1b2a75e0be92ce670b95943740e" +checksum = "c66a1fdd7e946fe33fe9725012e25836bba3655769bee9ee347cce7de3f396df" dependencies = [ "cc", "dlib", @@ -5379,6 +5379,7 @@ dependencies = [ "tracing", "typetag", "wasmer-wasi", + "wasmer-wasi-types", ] [[package]] diff --git a/lib/wasi-experimental-io-devices/Cargo.toml b/lib/wasi-experimental-io-devices/Cargo.toml index b924ae2288c..38e6c05399f 100644 --- a/lib/wasi-experimental-io-devices/Cargo.toml +++ b/lib/wasi-experimental-io-devices/Cargo.toml @@ -15,8 +15,9 @@ maintenance = { status = "experimental" } [dependencies] wasmer-wasi = { version = "=3.2.0-alpha.1", path = "../wasi", default-features=false } +wasmer-wasi-types = { path = "../wasi-types", version = "=3.2.0-alpha.1" } tracing = "0.1" -minifb = { version = "0.23", optional = true } +minifb = { version = "0.24.0", optional = true } nix = "0.25.0" ref_thread_local = "0.1" serde = "1" @@ -30,7 +31,7 @@ enable-serde = [ "wasmer-wasi/enable-serde" ] # This feature exists, so that "cargo build --all" doesn't -# accidentally link libxcbcommon and libwayland into the CLI +# accidentally link libxcbcommon and libwayland into the CLI # libraries. When using wasi-experimental-io-devices, users # have to enable this feature manually link_external_libs = [ diff --git a/lib/wasi-experimental-io-devices/src/link-ext.rs b/lib/wasi-experimental-io-devices/src/link-ext.rs index dec7d5959a4..81264838cd1 100644 --- a/lib/wasi-experimental-io-devices/src/link-ext.rs +++ b/lib/wasi-experimental-io-devices/src/link-ext.rs @@ -7,6 +7,7 @@ use std::io::{Read, Seek, SeekFrom, Write}; use tracing::debug; use wasmer_wasi::types::{wasi::Filesize, *}; use wasmer_wasi::{VirtualFile, WasiFsError, ALL_RIGHTS}; +use wasmer_wasi_types::wasi::Fdflags; use minifb::{Key, KeyRepeat, MouseButton, Scale, Window, WindowOptions}; @@ -48,7 +49,7 @@ pub(crate) struct FrameBufferState { pub last_mouse_pos: (u32, u32), pub inputs: VecDeque, - pub keys_pressed: BTreeSet, + pub keys: Vec, } impl FrameBufferState { @@ -72,7 +73,7 @@ impl FrameBufferState { window, last_mouse_pos: (0, 0), inputs: VecDeque::with_capacity(Self::MAX_INPUTS), - keys_pressed: BTreeSet::new(), + keys: Vec::new(), } } @@ -95,7 +96,7 @@ impl FrameBufferState { return None; } self.x_size = x; - self.y_size = x; + self.y_size = y; self.data_1.resize((x * y) as usize, 0); self.data_2.resize((x * y) as usize, 0); @@ -115,22 +116,27 @@ impl FrameBufferState { } pub fn fill_input_buffer(&mut self) -> Option<()> { - let keys_pressed = self.keys_pressed.iter().cloned().collect::>(); if !self.window.is_open() { self.push_input_event(InputEvent::WindowClosed)?; } - for key in keys_pressed { - if self.window.is_key_released(key) { - self.keys_pressed.remove(&key); - self.push_input_event(InputEvent::KeyRelease(key))?; + + let keys = self.keys.iter().cloned().collect::>(); + let new_keys = self.window.get_keys(); + + for key in &keys { + if !new_keys.contains(&key) { + self.push_input_event(InputEvent::KeyRelease(*key))?; } } - let keys = self.window.get_keys_pressed(KeyRepeat::No)?; - for key in keys { - self.keys_pressed.insert(key); - self.push_input_event(InputEvent::KeyPress(key))?; + + for key in &new_keys { + if !keys.contains(&key) { + self.push_input_event(InputEvent::KeyPress(*key))?; + } } + self.keys = new_keys; + let mouse_position = self.window.get_mouse_pos(minifb::MouseMode::Clamp)?; if mouse_position.0 as u32 != self.last_mouse_pos.0 || mouse_position.1 as u32 != self.last_mouse_pos.1 @@ -455,7 +461,7 @@ pub fn initialize(inodes: &WasiInodes, fs: &mut WasiFs) -> Result<(), String> { "_wasmer/dev/fb0".to_string(), ALL_RIGHTS, ALL_RIGHTS, - 0, + Fdflags::empty(), ) .map_err(|e| format!("fb: Failed to create dev folder {:?}", e))? }; @@ -469,7 +475,7 @@ pub fn initialize(inodes: &WasiInodes, fs: &mut WasiFs) -> Result<(), String> { "input".to_string(), ALL_RIGHTS, ALL_RIGHTS, - 0, + Fdflags::empty(), ) .map_err(|e| format!("fb: Failed to init framebuffer {:?}", e))?; @@ -484,7 +490,7 @@ pub fn initialize(inodes: &WasiInodes, fs: &mut WasiFs) -> Result<(), String> { "fb".to_string(), ALL_RIGHTS, ALL_RIGHTS, - 0, + Fdflags::empty(), ) .map_err(|e| format!("fb: Failed to init framebuffer {:?}", e))?; @@ -499,7 +505,7 @@ pub fn initialize(inodes: &WasiInodes, fs: &mut WasiFs) -> Result<(), String> { "virtual_size".to_string(), ALL_RIGHTS, ALL_RIGHTS, - 0, + Fdflags::empty(), ) .map_err(|e| format!("fb_resolution: Failed to init framebuffer {:?}", e))?; @@ -514,7 +520,7 @@ pub fn initialize(inodes: &WasiInodes, fs: &mut WasiFs) -> Result<(), String> { "draw".to_string(), ALL_RIGHTS, ALL_RIGHTS, - 0, + Fdflags::empty(), ) .map_err(|e| format!("fb_index_display: Failed to init framebuffer {:?}", e))?;