Skip to content

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

A progress window with a long title gets MDM's own title bar (part of #540) (#559)

Ahmed Nefzaoui390a50168c56
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 09a6ad84..88fdfbc4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -29,6 +29,7 @@ Each release's notes on GitHub come from its section here (`## [X.Y.Z]`, see
- The window no longer freezes when a video or a gallery finishes: marking its files as downloaded from the web, which can wait on the disk and the antivirus for a while with a big video, now happens beside the window ([#510](https://github.com/anefzaoui/misterdownloadmanager/issues/510)).
- Linux: **View → Dark Mode support** turns dark on window managers such as Hyprland and sway when only GNOME's setting says so (`gsettings set org.gnome.desktop.interface color-scheme prefer-dark`), as it did when a desktop portal answered ([#324](https://github.com/anefzaoui/misterdownloadmanager/issues/324)).
- Dark mode no longer draws a bright white line under the menu bar, across the whole window, in the Classic and Native themes ([#379](https://github.com/anefzaoui/misterdownloadmanager/issues/379)).
+- Windows: a download's progress window with a title of 256 characters or more (a torrent with a long name, or a file name kept whole in a folder too deep to shorten it) has MDM's own title bar again, instead of the system's drawn above it (part of [#540](https://github.com/anefzaoui/misterdownloadmanager/issues/540)).
- Windows: closing the window hides MDM in the notification area again when Windows keeps its icon among the hidden icons (behind ^), where a new icon goes. MDM took the icon for missing there and left the window in the taskbar instead; it now does that only when Windows has no icon of MDM's at all ([#545](https://github.com/anefzaoui/misterdownloadmanager/issues/545), [#534](https://github.com/anefzaoui/misterdownloadmanager/issues/534), [#527](https://github.com/anefzaoui/misterdownloadmanager/issues/527)).
### Added
diff --git a/ROADMAP.md b/ROADMAP.md
index 976d7fed..7d9e5ab9 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -522,6 +522,10 @@ These ship in a later version, when they're ready.
### Bugs being looked into
+- 🔄 A progress window's title bar buttons not answering
+ ([#540](https://github.com/anefzaoui/misterdownloadmanager/issues/540)): a window with a title of
+ 256 characters or more got the system's title bar above MDM's own; that part is fixed, in review.
+ Still to find: whether the reporter's window was one of them
- 🔄 macOS 15 and later: PingFang moved into the system's font assets, so Chinese text lost its
font ([#541](https://github.com/anefzaoui/misterdownloadmanager/issues/541)): fix in review
- 🔄 The video button still showing after it was switched off, or its site listed, in Options
diff --git a/crates/app/src/win32.rs b/crates/app/src/win32.rs
index 60c9350c..26d8fec2 100644
--- a/crates/app/src/win32.rs
+++ b/crates/app/src/win32.rs
@@ -25,6 +25,10 @@ use windows_sys::Win32::UI::WindowsAndMessaging::{
struct Find {
pid: u32,
title: Vec<u16>,
+ /// Where each window's title is read: as long as the title looked for, one more unit and the
+ /// NUL, so a longer title reads longer, never the same. A fixed 256 units cut every title to
+ /// 255, and a window named after a long file was never found (#540).
+ buf: Vec<u16>,
found: HWND,
}
@@ -36,9 +40,9 @@ unsafe extern "system" fn enum_cb(hwnd: HWND, lparam: LPARAM) -> windows_sys::co
if pid != f.pid {
return 1;
}
- let mut buf = [0u16; 256];
- let n = unsafe { GetWindowTextW(hwnd, buf.as_mut_ptr(), buf.len() as i32) };
- if n > 0 && buf[..n as usize] == f.title[..] {
+ // SAFETY: GetWindowTextW writes at most buf.len() units, the NUL included.
+ let n = unsafe { GetWindowTextW(hwnd, f.buf.as_mut_ptr(), f.buf.len() as i32) };
+ if n > 0 && f.buf[..n as usize] == f.title[..] {
f.found = hwnd;
return 0;
}
@@ -83,9 +87,11 @@ fn own_window(title: &str, known: Option<HWND>) -> Option<HWND> {
if let Some(h) = known.filter(|h| unsafe { IsWindow(*h) } != 0) {
return Some(h);
}
+ let title: Vec<u16> = title.encode_utf16().collect();
let mut f = Find {
pid: unsafe { GetCurrentProcessId() },
- title: title.encode_utf16().collect(),
+ buf: vec![0; title.len() + 2],
+ title,
found: std::ptr::null_mut(),
};
unsafe { EnumWindows(Some(enum_cb), &mut f as *mut Find as LPARAM) };
@@ -1413,6 +1419,61 @@ mod caption_less_tests {
}
}
+#[cfg(test)]
+mod find_own_window_tests {
+ use super::*;
+ use windows_sys::Win32::UI::WindowsAndMessaging::{
+ CreateWindowExW, DefWindowProcW, DestroyWindow, RegisterClassW, WNDCLASSW,
+ };
+
+ /// Our windows are found by their whole title, however long (a progress window is named
+ /// after its file, #540), and never by a title that only starts the same.
+ #[test]
+ fn a_window_is_found_by_its_whole_title_however_long() {
+ let class: Vec<u16> = "mdm-find-own-window-test\0".encode_utf16().collect();
+ // SAFETY: a class registered with the system's own procedure, and hidden windows of it
+ // on this thread, destroyed below; the strings are NUL-terminated.
+ unsafe {
+ let mut wc: WNDCLASSW = zeroed();
+ wc.lpfnWndProc = Some(DefWindowProcW);
+ wc.lpszClassName = class.as_ptr();
+ RegisterClassW(&wc);
+ let make = |title: &str| {
+ let t: Vec<u16> = title.encode_utf16().chain(Some(0)).collect();
+ let h = CreateWindowExW(
+ 0,
+ class.as_ptr(),
+ t.as_ptr(),
+ 0,
+ -20000,
+ -20000,
+ 100,
+ 100,
+ std::ptr::null_mut(),
+ std::ptr::null_mut(),
+ std::ptr::null_mut(),
+ std::ptr::null(),
+ );
+ assert!(!h.is_null());
+ h
+ };
+ for len in [40, 255, 256, 300, 1000] {
+ let head = format!("mdm find test {} {len} ", std::process::id());
+ let title = format!("{head}{}", "x".repeat(len - head.len()));
+ assert_eq!(title.encode_utf16().count(), len);
+ // One title longer by a unit, made first: found first, were it taken for ours.
+ let longer = make(&format!("{title}x"));
+ let window = make(&title);
+ assert_eq!(find_own_window(&title), Some(window), "{len} units");
+ DestroyWindow(window);
+ assert_eq!(find_own_window(&title), None, "{len} units, gone");
+ assert_eq!(find_own_window(&format!("{title}x")), Some(longer));
+ DestroyWindow(longer);
+ }
+ }
+ }
+}
+
#[cfg(test)]
mod come_forward_tests {
use super::*;