Skip to content

Commit

Permalink
fix in event.rs: safely unwrapping keyboard::Mod
Browse files Browse the repository at this point in the history
  • Loading branch information
emirpnet authored and Cobrand committed Jul 8, 2018
1 parent 97e1f79 commit 4bb6b9a
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/sdl2/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1262,12 +1262,13 @@ impl Event {

EventType::KeyDown => {
let event = raw.key;

Event::KeyDown {
timestamp: event.timestamp,
window_id: event.windowID,
keycode: Keycode::from_i32(event.keysym.sym as i32),
scancode: Scancode::from_i32(event.keysym.scancode as i32),
keymod: keyboard::Mod::from_bits(event.keysym.mod_).unwrap(),
keymod: Event::unwrap_keymod(keyboard::Mod::from_bits(event.keysym.mod_)),
repeat: event.repeat != 0
}
}
Expand Down Expand Up @@ -1607,6 +1608,13 @@ impl Event {
}} // close unsafe & match
}

pub fn unwrap_keymod(keymod_option: Option<keyboard::Mod>) -> keyboard::Mod {
match keymod_option {
None => keyboard::Mod::empty(),
Some(x) => x,
}
}

pub fn is_user_event(&self) -> bool {
match *self {
Event::User { .. } => true,
Expand Down

0 comments on commit 4bb6b9a

Please sign in to comment.