Skip to content

misterdownloadmanager: The ultimate open-source, clean-room download manager written from scratch in pure Rust for Windows, Mac, and Linux

On a touch screen, a tap on a menu's item chooses it (fixes #733) (#888)

Ahmed Nefzaoui6c8ca1931ff6
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 975011c3..dc9922cc 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -32,6 +32,7 @@ Each release's notes on GitHub come from its section here (`## [X.Y.Z]`, see
### Fixed
+- On a touch screen (a Surface, a touch laptop), tapping an item of a menu chooses it: the menu bar's menus, right-click menus, a toolbar button's drop-down and a drop-down list's choices. A tap opened the menu, but a tap on its items did nothing, so only a mouse could use them ([#733](https://github.com/anefzaoui/misterdownloadmanager/issues/733)).
- A video's **Address** in the progress window, **Download complete** and **File Properties** is where its file comes from (the stream MDM downloads, `googlevideo.com` for YouTube), and the page it was found on shows under **The web page from which this file was obtained**, as for a file. They showed the page as the address and "Unknown" for the page. File Properties also shows where that file's server is, as the progress window does, instead of "not one server". A download's page and **Referer** are also kept with the list now: after MDM was closed and opened again, File Properties said "Unknown" and an empty Referer for every download, and a download resumed then went without its Referer ([#795](https://github.com/anefzaoui/misterdownloadmanager/issues/795)).
- The progress window's connections table is no longer empty while a video downloads. MDM's own downloader now brings videos down (0.5.2 left them to yt-dlp, whose connections MDM couldn't see), so the table lists its connections, as many as **Options → Connection** gives (8 by default; a stream in pieces as many pieces at once). While yt-dlp looks the page up first, and for a video it still downloads itself (a live stream, an RTMP stream), the table shows that one connection and what it is doing instead of nothing ([#793](https://github.com/anefzaoui/misterdownloadmanager/issues/793)).
- After a download's last byte, the progress window and the list say what MDM is doing and how far it is: **Verifying… (45%)** while the file is checked against its checksum, and **Merging… (45%)** while a video's picture and sound are joined into one file (read from the size of the file ffmpeg writes); the list's narrow Status column puts the percentage first, **45% verified**. Meanwhile the progress window's bar starts again in the accent colour and fills as the check or the merge goes. While the last of a file is written out, the progress window says **Finishing…**, not **Connecting…** as before. The map of the connections' parts also fills each finished part up to the next one: a finished download showed small gaps at the end of each part ([#736](https://github.com/anefzaoui/misterdownloadmanager/issues/736)).
diff --git a/ROADMAP.md b/ROADMAP.md
index 88c0f150..198e1698 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -557,6 +557,9 @@ Bug fixes from the first days of 0.5.0, a Safari extension, and more file types.
These ship in the next version.
+- ✅ Touch screens: a tap on a menu's item chooses it (the menu bar's, right-click menus,
+ drop-downs), where only a mouse could
+ ([#733](https://github.com/anefzaoui/misterdownloadmanager/issues/733))
- ✅ A video's Address is its file's (the stream MDM downloads) in the progress window, Download
complete and File Properties, its page the web page it was obtained from; a download's page and
Referer are kept after a restart
diff --git a/crates/app/src/chrome.rs b/crates/app/src/chrome.rs
index dd1f7622..05b9826c 100644
--- a/crates/app/src/chrome.rs
+++ b/crates/app/src/chrome.rs
@@ -1177,7 +1177,10 @@ fn popup_level<C: Clone>(
o.y + size.y - 1.0,
POPUP_BG(),
);
- let pointer = ui.ctx().pointer_hover_pos();
+ // Where the pointer is, or was on this pass: a tap on a touch screen ends with the pointer
+ // gone (egui-winit lets go of it as the finger lifts, so nothing stays lit), in the very
+ // pass that releases it, where the hover position is none and no item was chosen (#733).
+ let pointer = ui.input(|i| i.pointer.hover_pos().or(i.pointer.interact_pos()));
// The item under the pointer (none on a separator or the padding): one item is lit at a
// time, so an open submenu's entry gives up its light to it (#579).
let under = pointer.and_then(|p| item_at(entries, o, w, p));
@@ -2606,6 +2609,92 @@ mod tests {
assert_eq!(open(&ctx), Some(3), "kept on the way into it");
}
+ /// #733: a tap on a touch screen chooses the item under the finger. egui-winit makes the
+ /// tap a press and a release of the pointer, then lets go of it (PointerGone) as the finger
+ /// lifts, in the same pass as the release (in one pass with the press too, for a quick tap):
+ /// the item was looked for under a pointer that was gone, and none was chosen.
+ #[test]
+ fn a_tap_chooses_the_item_under_the_finger() {
+ let [a, b, c] = ["a", "b", "c"]; // not texts to translate (tools/i18n/extract.py)
+ let entries: Vec<MenuEntry<u8>> = vec![
+ MenuEntry::Item(a, 0, true, false),
+ MenuEntry::Sep,
+ MenuEntry::Item(b, 1, true, false),
+ MenuEntry::Item(c, 2, true, false),
+ ];
+ // Each pass's events; what the menu chose.
+ let run = |passes: &[&dyn Fn(egui::Pos2) -> Vec<egui::Event>]| {
+ let ctx = egui::Context::default();
+ let sub_key = egui::Id::unique(("popup-sub", "t733"));
+ let mut t = 0.0;
+ let mut chosen = None;
+ let mut pass = |events: Vec<egui::Event>| {
+ t += 0.016;
+ let raw = egui::RawInput {
+ time: Some(t),
+ screen_rect: Some(Rect::from_min_size(
+ pos2(0.0, 0.0),
+ egui::vec2(1200.0, 800.0),
+ )),
+ events,
+ ..Default::default()
+ };
+ let mut out = ctx.run_ui(raw, |ui| {
+ let mut result = None;
+ super::popup_level(
+ ui.ctx(),
+ MenuKind::Context,
+ "t733",
+ pos2(100.0, 100.0),
+ None,
+ &entries,
+ sub_key,
+ &mut result,
+ 0,
+ &|_| None,
+ );
+ if result.is_some() {
+ chosen = result;
+ }
+ });
+ out.textures_delta.clear();
+ };
+ pass(Vec::new());
+ let o = ctx
+ .data(|d| d.get_temp::<egui::Pos2>(sub_key.with(("origin", 0usize))))
+ .expect("drawn");
+ // "b": below "a" (3..25) and the separator (25..34), at 34..56.
+ let on_b = o + egui::vec2(60.0, 45.0);
+ for p in passes {
+ pass(p(on_b));
+ }
+ chosen
+ };
+ let button = |pos, pressed| egui::Event::PointerButton {
+ pos,
+ button: egui::PointerButton::Primary,
+ pressed,
+ modifiers: Default::default(),
+ };
+ let down = |p: egui::Pos2| vec![egui::Event::PointerMoved(p), button(p, true)];
+ let up_gone = |p: egui::Pos2| vec![button(p, false), egui::Event::PointerGone];
+ let tap = |p: egui::Pos2| {
+ vec![
+ egui::Event::PointerMoved(p),
+ button(p, true),
+ button(p, false),
+ egui::Event::PointerGone,
+ ]
+ };
+ let up = |p: egui::Pos2| vec![button(p, false)];
+ // A tap: the finger down in one pass, up (and the pointer gone) in the next.
+ assert_eq!(run(&[&down, &up_gone]), Some(1));
+ // A quick tap, all in one pass.
+ assert_eq!(run(&[&tap]), Some(1));
+ // The mouse, as before.
+ assert_eq!(run(&[&down, &up]), Some(1));
+ }
+
/// #579: the entry under the pointer, separators and padding none.
#[test]
fn the_item_under_the_pointer() {