UI: keep a Control-click's secondary mapping until its release

PointerGone and WindowFocused(false) cleared the mapping mid-gesture. On
macOS a drag that leaves the window still delivers its release, which then
arrived as a primary release, so egui kept the secondary button down. The
mapping now lasts until the release; every press recomputes it, so a missed
release can't remap a later plain click.

Regression test: Control press, pointer exit, focus loss, re-entry and
release leave no button down (failed before this change).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Brian MonksandClaude Opus 5.5 committed 2026-10-21 13:15:23 +02:00
1 parent 0dcaa98a40
commit e92c3be28d
1 file changed
+27 -1
+27 -1
View File
@@ -23,7 +23,9 @@ impl ControlClick {
self.secondary_down = false;
}
}
egui::Event::WindowFocused(false) | egui::Event::PointerGone => self.secondary_down = false,
// A drag keeps the mapping when the pointer leaves the window or focus is lost: the
// release still arrives and must match the secondary press egui already saw. The
// next press recomputes it, so a missed release can't remap a plain click.
_ => {}
}
}
@@ -74,6 +76,30 @@ mod tests {
}
}
#[test]
fn a_control_drag_out_of_the_window_and_back_releases_the_secondary_button() {
let ctx = egui::Context::default();
let mut state = ControlClick::default();
let frames = [
vec![Event::PointerMoved(egui::pos2(50.0, 50.0)), button(true, Modifiers::CTRL)],
vec![Event::PointerGone],
vec![Event::WindowFocused(false)],
vec![Event::PointerMoved(egui::pos2(60.0, 60.0))],
vec![button(false, Modifiers::NONE)],
];
let mut down = Vec::new();
for mut events in frames {
state.normalize(&mut events, true);
ctx.run_ui(egui::RawInput { events, ..Default::default() }, |ui| {
down.push(ui.input(|i| (i.pointer.secondary_down(), i.pointer.primary_down())));
})
.textures_delta
.clear();
}
assert_eq!(down.first(), Some(&(true, false)), "the Control press is a secondary press");
assert_eq!(down.last(), Some(&(false, false)), "the release after re-entry ends it: no stuck button");
}
#[test]
fn focus_loss_does_not_remap_the_next_plain_click() {
let mut state = ControlClick::default();