diff --git a/CHANGELOG.md b/CHANGELOG.md index 7cec5aef..ac200b61 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Unreleased +- On X11, fixed panic caused by dropping the window before running the event loop. + # Version 0.18.0 (2018-11-07) - **Breaking:** `image` crate upgraded to 0.20. This is exposed as part of the `icon_loading` API. diff --git a/src/platform/linux/x11/mod.rs b/src/platform/linux/x11/mod.rs index 461acde1..61bf3759 100644 --- a/src/platform/linux/x11/mod.rs +++ b/src/platform/linux/x11/mod.rs @@ -864,20 +864,26 @@ impl EventsLoop { event: CursorEntered { device_id }, }); - // The mods field on this event isn't actually populated, so query the - // pointer device. In the future, we can likely remove this round-trip by - // relying on Xkb for modifier values. - let modifiers = self.xconn.query_pointer(xev.event, xev.deviceid) - .expect("Failed to query pointer device").get_modifier_state(); - - let dpi_factor = self.with_window(xev.event, |window| { + if let Some(dpi_factor) = self.with_window(xev.event, |window| { window.get_hidpi_factor() - }); - if let Some(dpi_factor) = dpi_factor { + }) { let position = LogicalPosition::from_physical( (xev.event_x as f64, xev.event_y as f64), dpi_factor, ); + + // The mods field on this event isn't actually populated, so query the + // pointer device. In the future, we can likely remove this round-trip by + // relying on `Xkb` for modifier values. + // + // This needs to only be done after confirming the window still exists, + // since otherwise we risk getting a `BadWindow` error if the window was + // dropped with queued events. + let modifiers = self.xconn + .query_pointer(xev.event, xev.deviceid) + .expect("Failed to query pointer device") + .get_modifier_state(); + callback(Event::WindowEvent { window_id, event: CursorMoved {