Skip to content

Commit 4bb6b9a

Browse files
emirpnetCobrand
authored andcommitted
fix in event.rs: safely unwrapping keyboard::Mod
1 parent 97e1f79 commit 4bb6b9a

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/sdl2/event.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -1262,12 +1262,13 @@ impl Event {
12621262

12631263
EventType::KeyDown => {
12641264
let event = raw.key;
1265+
12651266
Event::KeyDown {
12661267
timestamp: event.timestamp,
12671268
window_id: event.windowID,
12681269
keycode: Keycode::from_i32(event.keysym.sym as i32),
12691270
scancode: Scancode::from_i32(event.keysym.scancode as i32),
1270-
keymod: keyboard::Mod::from_bits(event.keysym.mod_).unwrap(),
1271+
keymod: Event::unwrap_keymod(keyboard::Mod::from_bits(event.keysym.mod_)),
12711272
repeat: event.repeat != 0
12721273
}
12731274
}
@@ -1607,6 +1608,13 @@ impl Event {
16071608
}} // close unsafe & match
16081609
}
16091610

1611+
pub fn unwrap_keymod(keymod_option: Option<keyboard::Mod>) -> keyboard::Mod {
1612+
match keymod_option {
1613+
None => keyboard::Mod::empty(),
1614+
Some(x) => x,
1615+
}
1616+
}
1617+
16101618
pub fn is_user_event(&self) -> bool {
16111619
match *self {
16121620
Event::User { .. } => true,

0 commit comments

Comments
 (0)