aboutsummaryrefslogtreecommitdiff
path: root/src/desktop/input.rs
diff options
context:
space:
mode:
authorAstatin <[email protected]>2025-07-15 18:57:03 +0200
committerAstatin <[email protected]>2025-07-15 18:57:03 +0200
commitc6972abff6c81565a41df8731509435274a80c1f (patch)
tree5d73ee5e68132df3465ad1b2b260940b6b40f1b7 /src/desktop/input.rs
parent81f8a04c38671a82c756450bbe13803e1701ada0 (diff)
Make render function not block when window is suspended
Diffstat (limited to 'src/desktop/input.rs')
-rw-r--r--src/desktop/input.rs59
1 files changed, 30 insertions, 29 deletions
diff --git a/src/desktop/input.rs b/src/desktop/input.rs
index d7c10c8..55bbfb3 100644
--- a/src/desktop/input.rs
+++ b/src/desktop/input.rs
@@ -130,46 +130,47 @@ impl Keyboard {
impl Input for Keyboard {
fn update_events(&mut self, _cycles: u128) -> Option<u128> {
- let mut res = 0xf;
- let keys = self.keys.borrow();
+ if let Ok(keys) = self.keys.lock() {
+ let mut res = 0xf;
- if keys.contains(&KeyCode::KeyA) {
- res &= 0b1110;
- }
+ if (*keys).contains(&KeyCode::KeyA) {
+ res &= 0b1110;
+ }
- if keys.contains(&KeyCode::KeyB) {
- res &= 0b1101;
- }
+ if (*keys).contains(&KeyCode::KeyB) {
+ res &= 0b1101;
+ }
- if keys.contains(&KeyCode::Backspace) {
- res &= 0b1011;
- }
+ if (*keys).contains(&KeyCode::Backspace) {
+ res &= 0b1011;
+ }
- if keys.contains(&KeyCode::Enter) {
- res &= 0b0111;
- }
+ if (*keys).contains(&KeyCode::Enter) {
+ res &= 0b0111;
+ }
- self.action_reg = res;
+ self.action_reg = res;
- let mut res = 0xf;
+ let mut res = 0xf;
- if keys.contains(&KeyCode::ArrowRight) {
- res &= 0b1110;
- }
+ if (*keys).contains(&KeyCode::ArrowRight) {
+ res &= 0b1110;
+ }
- if keys.contains(&KeyCode::ArrowLeft) {
- res &= 0b1101;
- }
+ if (*keys).contains(&KeyCode::ArrowLeft) {
+ res &= 0b1101;
+ }
- if keys.contains(&KeyCode::ArrowUp) {
- res &= 0b1011;
- }
+ if (*keys).contains(&KeyCode::ArrowUp) {
+ res &= 0b1011;
+ }
- if keys.contains(&KeyCode::ArrowDown) {
- res &= 0b0111;
- }
+ if (*keys).contains(&KeyCode::ArrowDown) {
+ res &= 0b0111;
+ }
- self.direction_reg = res;
+ self.direction_reg = res;
+ }
None
}