mirror of
https://github.com/emilk/egui.git
synced 2026-06-26 22:53:14 -04:00
Avoid repaints on device mouse motion outside window (#7866)
## Summary - Ignore raw device mouse motion unless the window is focused and the pointer is inside it - Also handles pointers starting down and then moving into or out of the window (drag & drop) - Prevents global mouse motion from triggering continuous repaint loops - Applies to both glow and wgpu backends ## Testing - I ran the check script, nothing seemed to fail --------- Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
This commit is contained in:
@@ -448,12 +448,21 @@ impl WinitApp for GlowWinitApp<'_> {
|
||||
if let Some(viewport) = glutin
|
||||
.focused_viewport
|
||||
.and_then(|viewport| glutin.viewports.get_mut(&viewport))
|
||||
&& let Some(window) = viewport.window.as_ref()
|
||||
{
|
||||
if let Some(egui_winit) = viewport.egui_winit.as_mut() {
|
||||
egui_winit.on_mouse_motion(delta);
|
||||
if !window.has_focus()
|
||||
&& !viewport
|
||||
.egui_winit
|
||||
.as_ref()
|
||||
.map(|state| state.is_any_pointer_button_down())
|
||||
.unwrap_or(false)
|
||||
{
|
||||
return Ok(EventResult::Wait);
|
||||
}
|
||||
|
||||
if let Some(window) = viewport.window.as_ref() {
|
||||
if let Some(egui_winit) = viewport.egui_winit.as_mut()
|
||||
&& egui_winit.on_mouse_motion(delta)
|
||||
{
|
||||
return Ok(EventResult::RepaintNext(window.id()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -454,12 +454,21 @@ impl WinitApp for WgpuWinitApp<'_> {
|
||||
if let Some(viewport) = shared
|
||||
.focused_viewport
|
||||
.and_then(|viewport| shared.viewports.get_mut(&viewport))
|
||||
&& let Some(window) = viewport.window.as_ref()
|
||||
{
|
||||
if let Some(egui_winit) = viewport.egui_winit.as_mut() {
|
||||
egui_winit.on_mouse_motion(delta);
|
||||
if !window.has_focus()
|
||||
&& !viewport
|
||||
.egui_winit
|
||||
.as_ref()
|
||||
.map(|state| state.is_any_pointer_button_down())
|
||||
.unwrap_or(false)
|
||||
{
|
||||
return Ok(EventResult::Wait);
|
||||
}
|
||||
|
||||
if let Some(window) = viewport.window.as_ref() {
|
||||
if let Some(egui_winit) = viewport.egui_winit.as_mut()
|
||||
&& egui_winit.on_mouse_motion(delta)
|
||||
{
|
||||
return Ok(EventResult::RepaintNext(window.id()));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user