The dispatch window event causes problems #9728
-
|
I am developing an application to display emojis, and I want it to behave in such a way that when the mouse leaves the window, it closes. I am achieving this with this code self.window.window().on_winit_window_event({
let no_close = self.settings.no_close;
move |w, ev| match ev {
WindowEvent::CursorLeft { .. } => (!no_close)
.then(|| w.hide().ok())
.flatten()
.map(|_| EventResult::PreventDefault)
.unwrap_or(EventResult::Propagate),
_ => EventResult::Propagate,
}
});But the problem is that it throws this error and apparently in wayland desktop environments, the window does not close If you would like more context, the source code is here https://github.com/SergioRibera/Simplemoji/blob/25e89dc58e4bdeddfa38999383a271610ffa3c1e/src/app.rs#L246-L256, and the issue that was opened for me is this one SergioRibera/Simplemoji#51 The curious thing is that it behaves very similarly. When copying an emoji, slint's DSL invokes an event called close, which calls this function in Rust, and the window closes completely without throwing any errors. I'm probably doing something wrong, and I would appreciate some help Source with more context: https://github.com/SergioRibera/Simplemoji/blob/25e89dc58e4bdeddfa38999383a271610ffa3c1e/src/app.rs#L258-L287 if close {
window
.upgrade()
.unwrap()
.window()
.dispatch_event(slint::platform::WindowEvent::CloseRequested);
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
Solved, now I quit the event_loop directly self.window.window().on_winit_window_event({
let no_close = self.settings.no_close;
move |_w, ev| match ev {
WindowEvent::CursorLeft { .. } => (!no_close)
+ .then(|| slint::quit_event_loop().ok())
.flatten()
.map(|_| EventResult::PreventDefault)
.unwrap_or(EventResult::Propagate),
_ => EventResult::Propagate,
}
}); |
Beta Was this translation helpful? Give feedback.
Solved, now I quit the event_loop directly
self.window.window().on_winit_window_event({ let no_close = self.settings.no_close; move |_w, ev| match ev { WindowEvent::CursorLeft { .. } => (!no_close) + .then(|| slint::quit_event_loop().ok()) .flatten() .map(|_| EventResult::PreventDefault) .unwrap_or(EventResult::Propagate), _ => EventResult::Propagate, } });