Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't repeat hotkeys on WebAssembly #476

Merged
merged 1 commit into from
Nov 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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