From fd1a3a4d2eeb4dc5d6e2f7d793f7f28fa071a3a2 Mon Sep 17 00:00:00 2001 From: Fredemus Date: Mon, 2 Oct 2023 23:06:28 +0200 Subject: [PATCH 1/2] Add logic for CursorEntered/CursorLeft on x11 --- src/x11/window.rs | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/x11/window.rs b/src/x11/window.rs index fcd90837..f9902e51 100644 --- a/src/x11/window.rs +++ b/src/x11/window.rs @@ -280,10 +280,12 @@ impl Window { | xcb::EVENT_MASK_BUTTON_RELEASE | xcb::EVENT_MASK_KEY_PRESS | xcb::EVENT_MASK_KEY_RELEASE - | xcb::EVENT_MASK_STRUCTURE_NOTIFY, + | xcb::EVENT_MASK_STRUCTURE_NOTIFY + | xcb::EVENT_MASK_ENTER_WINDOW + | xcb::EVENT_MASK_LEAVE_WINDOW, ), - // As mentioend above, these two values are needed to be able to create a window - // with a dpeth of 32-bits when the parent window has a different depth + // As mentioned above, these two values are needed to be able to create a window + // with a depth of 32-bits when the parent window has a different depth (xcb::CW_COLORMAP, colormap), (xcb::CW_BORDER_PIXEL, 0), ], @@ -609,6 +611,20 @@ impl Window { } } + // mouse entering the window + // TODO: might need to consider the window used in `xcb::cast_event::(&event)` + xcb::ENTER_NOTIFY => { + handler.on_event( + &mut crate::Window::new(self), + Event::Mouse(MouseEvent::CursorEntered), + ); + } + + xcb::LEAVE_NOTIFY => { + handler + .on_event(&mut crate::Window::new(self), Event::Mouse(MouseEvent::CursorLeft)); + } + xcb::BUTTON_PRESS => { let event = unsafe { xcb::cast_event::(&event) }; let detail = event.detail(); From 486bb1f0696e45f16ae9b95e5005348bf8ed9d90 Mon Sep 17 00:00:00 2001 From: Fredemus Date: Sat, 7 Oct 2023 16:23:12 +0200 Subject: [PATCH 2/2] add MouseMoved event when ENTER_NOTIFY happens --- src/x11/window.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/x11/window.rs b/src/x11/window.rs index f9902e51..08166c9e 100644 --- a/src/x11/window.rs +++ b/src/x11/window.rs @@ -611,13 +611,23 @@ impl Window { } } - // mouse entering the window - // TODO: might need to consider the window used in `xcb::cast_event::(&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::(&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 => {