Skip to content

A fast file manager for Windows and macOS that never freezes: tabs, dual panes, archives as folders, Quick Look-style previews. A File Explorer and Finder alternative written in Rust.

The drag thread's wrong key state is written to the log once a run, not at every drag

gelenmedyab8c48ba75a18
diff --git a/crates/rf-win/src/dnd.rs b/crates/rf-win/src/dnd.rs
index 829574e0..46b30f59 100644
--- a/crates/rf-win/src/dnd.rs
+++ b/crates/rf-win/src/dnd.rs
@@ -159,8 +159,12 @@ fn drag_out_allowing(owner: HWND, ui_thread: u32, items: &[PathBuf], allowed: DR
/// the window's input just before (`AttachThreadInput`), and Windows' documentation says of that call: "key state, which can be
/// ascertained by calls to the GetKeyState or GetKeyboardState function, is reset after a call to AttachThreadInput". A loop that
/// finds no button down drops at once, where the drag began, which looks like a drag that never started (issue 1067: "roughly 1
-/// out of every 5 attempts"). So what is really held is written back after the join. NOT tried with a real mouse here: the log
-/// lines around the drag say whether a drag is still ended at once.
+/// out of every 5 attempts"). So what is really held is written back after the join. Tried with a real mouse on 2026-12-04: the
+/// log line below came at the start of each of 26 drags (the left button read "up" while it was held), and none of those drags
+/// was lost or ended at once.
+/// Whether the line about a wrong key state was written in this run already.
+static SAID_KEY_STATE: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false);
+
fn buttons_into_key_state() {
use windows::Win32::UI::Input::KeyboardAndMouse::{GetKeyboardState, SetKeyboardState, VK_CONTROL, VK_MENU, VK_SHIFT};
let mut state = [0u8; 256];
@@ -171,8 +175,10 @@ fn buttons_into_key_state() {
for vk in [VK_LBUTTON.0, VK_RBUTTON.0, VK_CONTROL.0, VK_SHIFT.0, VK_MENU.0] {
let held = (GetAsyncKeyState(vk as i32) as u16 & 0x8000) != 0;
let was = state[vk as usize] & 0x80 != 0;
- if held != was {
- log::warn!("drag: the key state of the drag's thread had key {vk:#04x} {} while it is {}", if was { "down" } else { "up" }, if held { "down" } else { "up" });
+ // (said once a run: on the first PC it was tried on with a real mouse, 2026-12-04, the left button read "up" at the
+ // start of every one of 26 drags, so this is the rule after the join, not an accident worth a line each time)
+ if held != was && !SAID_KEY_STATE.swap(true, Ordering::Relaxed) {
+ log::warn!("drag: the key state of the drag's thread had key {vk:#04x} {} while it is {} (written back; said once a run)", if was { "down" } else { "up" }, if held { "down" } else { "up" });
}
state[vk as usize] = (state[vk as usize] & !0x80) | if held { 0x80 } else { 0 };
}