Skip to content

Commit

Permalink
Merge pull request #476 from CryZe/hotkey-repeat-wasm
Browse files Browse the repository at this point in the history
Don't repeat hotkeys on WebAssembly
  • Loading branch information
CryZe authored Nov 9, 2021
2 parents 07ae39b + 1136c43 commit a772c04
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
14 changes: 12 additions & 2 deletions benches/software_rendering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,14 @@ cfg_if::cfg_if! {
make_progress_run_with_splits_opt(&mut timer, &[Some(5.0), None, Some(10.0)]);

let snapshot = timer.snapshot();
let state = layout.state(&snapshot);
let mut state = layout.state(&snapshot);
let mut renderer = Renderer::new();

// Do a single frame beforehand as otherwise the layout state will
// keep saying that the icons changed.
renderer.render(&state, [300, 500]);
layout.update_state(&mut state, &snapshot);

c.bench_function("Software Rendering (Default)", move |b| {
b.iter(|| renderer.render(&state, [300, 500]))
});
Expand All @@ -43,9 +48,14 @@ cfg_if::cfg_if! {
make_progress_run_with_splits_opt(&mut timer, &[Some(10.0), None, Some(20.0), Some(55.0)]);

let snapshot = timer.snapshot();
let state = layout.state(&snapshot);
let mut state = layout.state(&snapshot);
let mut renderer = Renderer::new();

// Do a single frame beforehand as otherwise the layout state will
// keep saying that the icons changed.
renderer.render(&state, [300, 800]);
layout.update_state(&mut state, &snapshot);

c.bench_function("Software Rendering (Subsplits Layout)", move |b| {
b.iter(|| renderer.render(&state, [300, 800]))
});
Expand Down
8 changes: 5 additions & 3 deletions crates/livesplit-hotkey/src/wasm_web/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,11 @@ impl Hook {

let hotkey_map = hotkeys.clone();
let keyboard_callback = Closure::wrap(Box::new(move |event: KeyboardEvent| {
if let Ok(code) = event.code().parse() {
if let Some(callback) = hotkey_map.lock().unwrap().get_mut(&code) {
callback();
if !event.repeat() {
if let Ok(code) = event.code().parse() {
if let Some(callback) = hotkey_map.lock().unwrap().get_mut(&code) {
callback();
}
}
}
}) as Box<dyn FnMut(KeyboardEvent)>);
Expand Down
2 changes: 2 additions & 0 deletions crates/livesplit-hotkey/src/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ thread_local! {
}

fn parse_scan_code(value: DWORD) -> Option<KeyCode> {
// Windows uses PS/2 scan code set 1.
// https://www.avrfreaks.net/sites/default/files/PS2%20Keyboard.pdf Page 19
use self::KeyCode::*;
Some(match value {
0x0001 => Escape,
Expand Down

0 comments on commit a772c04

Please sign in to comment.