Skip to content

Commit

Permalink
add MouseMoved event when ENTER_NOTIFY happens
Browse files Browse the repository at this point in the history
  • Loading branch information
Fredemus committed Oct 7, 2023
1 parent fd1a3a4 commit 486bb1f
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/x11/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -611,13 +611,23 @@ impl Window {
}
}

// mouse entering the window
// TODO: might need to consider the window used in `xcb::cast_event::<xcb::MotionNotifyEvent>(&event)`
xcb::ENTER_NOTIFY => {
handler.on_event(
&mut crate::Window::new(self),
Event::Mouse(MouseEvent::CursorEntered),
);
// since no `MOTION_NOTIFY` event is generated when `ENTER_NOTIFY` is generated,
// we generate a CursorMoved as well, so the mouse position from here isn't lost
let event = unsafe { xcb::cast_event::<xcb::EnterNotifyEvent>(&event) };
let physical_pos = PhyPoint::new(event.event_x() as i32, event.event_y() as i32);
let logical_pos = physical_pos.to_logical(&self.window_info);
handler.on_event(
&mut crate::Window::new(self),
Event::Mouse(MouseEvent::CursorMoved {
position: logical_pos,
modifiers: key_mods(event.state()),
}),
);
}

xcb::LEAVE_NOTIFY => {
Expand Down

0 comments on commit 486bb1f

Please sign in to comment.