Skip to content

Commit

Permalink
Fix scale in GTK wheel event handler.
Browse files Browse the repository at this point in the history
  • Loading branch information
xStrom committed May 9, 2020
1 parent 57eb993 commit a12357a
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions druid-shell/src/platform/gtk/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,7 @@ impl WindowBuilder {

win_state.drawing_area.connect_scroll_event(clone!(handle => move |_widget, scroll| {
if let Some(state) = handle.state.upgrade() {
if let Ok(mut handler) = state.handler.try_borrow_mut() {

if let Ok(scale) = state.scale.try_borrow() {
let mods = get_modifiers(scroll.get_state());

// The magic "120"s are from Microsoft's documentation for WM_MOUSEWHEEL.
Expand Down Expand Up @@ -441,8 +440,8 @@ impl WindowBuilder {
}
};

if let Some(wheel_delta) = wheel_delta{
let mouse_event = MouseEvent{
if let Some(wheel_delta) = wheel_delta {
let mouse_event = MouseEvent {
pos: scale.to_dp(&Point::from(scroll.get_position())),
buttons: get_mouse_buttons_from_modifiers(scroll.get_state()),
mods,
Expand All @@ -451,10 +450,14 @@ impl WindowBuilder {
wheel_delta
};

handler.wheel(&mouse_event);
if let Ok(mut handler) = state.handler.try_borrow_mut() {
handler.wheel(&mouse_event);
} else {
log::info!("GTK event was dropped because the handler was already borrowed");
}
}
} else {
log::info!("GTK event was dropped because the handler was already borrowed");
log::warn!("GTK event was dropped because the scale was already borrowed");
}
}

Expand Down

0 comments on commit a12357a

Please # to comment.