fix: overlay event handling and mouse interaction

This commit is contained in:
Ashley Wulber 2026-02-25 13:26:38 -05:00
parent 904133397b
commit 0298487096
3 changed files with 26 additions and 7 deletions

View file

@ -12,7 +12,6 @@ use cosmic_config::CosmicConfigEntry;
pub mod context_drawer; pub mod context_drawer;
pub use context_drawer::{ContextDrawer, context_drawer}; pub use context_drawer::{ContextDrawer, context_drawer};
use iced::application::BootFn; use iced::application::BootFn;
use iced_core::Widget;
pub mod cosmic; pub mod cosmic;
pub mod settings; pub mod settings;

View file

@ -8,7 +8,7 @@ use iced::advanced::widget::{self, Operation};
use iced::advanced::{Clipboard, Shell}; use iced::advanced::{Clipboard, Shell};
use iced::advanced::{overlay, renderer}; use iced::advanced::{overlay, renderer};
use iced::{Event, Point, Size, mouse}; use iced::{Event, Point, Size, mouse};
use iced_core::Renderer; use iced_core::{Renderer, touch};
pub(super) struct Overlay<'a, 'b, Message> { pub(super) struct Overlay<'a, 'b, Message> {
pub(crate) position: Point, pub(crate) position: Point,
@ -65,7 +65,20 @@ where
clipboard, clipboard,
shell, shell,
&layout.bounds(), &layout.bounds(),
) );
match event {
Event::Mouse(e) if !matches!(e, mouse::Event::CursorLeft) => {
if cursor.is_over(layout.bounds()) {
shell.capture_event();
}
}
Event::Touch(e) if !matches!(e, touch::Event::FingerLost { .. }) => {
if cursor.is_over(layout.bounds()) {
shell.capture_event();
}
}
_ => {}
}
} }
fn draw( fn draw(
@ -86,7 +99,7 @@ where
cursor, cursor,
&layout.bounds(), &layout.bounds(),
); );
}) });
} }
fn operate( fn operate(
@ -108,9 +121,16 @@ where
) -> mouse::Interaction { ) -> mouse::Interaction {
// TODO how to handle viewport here? // TODO how to handle viewport here?
let viewport = &layout.bounds(); let viewport = &layout.bounds();
self.content let interaction = self
.content
.as_widget() .as_widget()
.mouse_interaction(self.tree, layout, cursor, viewport, renderer) .mouse_interaction(self.tree, layout, cursor, viewport, renderer);
if let mouse::Interaction::None = interaction
&& cursor.is_over(layout.bounds())
{
return mouse::Interaction::Idle;
}
interaction
} }
fn overlay<'c>( fn overlay<'c>(

View file

@ -238,7 +238,7 @@ impl<Message: Clone> Widget<Message, crate::Theme, Renderer> for ContextDrawer<'
clipboard, clipboard,
shell, shell,
viewport, viewport,
) );
} }
fn mouse_interaction( fn mouse_interaction(