дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-06 10:07:11 +02:00
fix(titlebar): do not start a stuck window drag when activating on Windows (#7146)
* fix(titlebar): do not start a stuck window drag when activating on Windows (#7142) A click on the title bar of a background window raised it and also started Tauri's caption drag. start_dragging posts WM_NCLBUTTONDOWN/HTCAPTION; if the button is already up when that message runs, Win32 follows the cursor until the next click. On Windows the title bar now uses the same custom drag path as macOS: a press only arms the drag, and the native drag starts on a move while the button is still held. window_start_drag also checks GetAsyncKeyState. Double-click zoom still happens on the second press. Linux is unchanged. * chore(bindings): regenerate windowStartDrag docs for the Windows drag fix `cargo test -p openidea --test export_bindings` copies the new window_start_drag rustdoc into src/bindings.ts. commands.snap is unchanged. * fix(titlebar): preserve native Windows maximize, swapped mouse buttons, and drag state cleanup --------- Co-authored-by: l0ng-ai <[email protected]>
Цей коміт міститься в:
1 джерело
452d897032
коміт
13b8024588
6 files changed
+251
-18
No files matched your search
@@ -9,6 +9,10 @@ use tauri::WebviewWindow;
|
||||
///
|
||||
/// macOS WebKit can deliver a tap's `mousedown` after the button is already up. AppKit would then run
|
||||
/// its drag loop with no release left to end it, and the window follows the pointer until the next click.
|
||||
///
|
||||
/// On Windows, `start_dragging` posts `WM_NCLBUTTONDOWN`/`HTCAPTION`. If the button is already up
|
||||
/// (a short click that only activated a background window, after an async invoke), Win32's move loop
|
||||
/// follows the pointer until the next click (#7142).
|
||||
#[desktop_command(trust = always)]
|
||||
#[tauri::command]
|
||||
#[specta::specta]
|
||||
@@ -17,10 +21,31 @@ pub fn window_start_drag(window: WebviewWindow) -> IdeResult<bool> {
|
||||
if objc2_app_kit::NSEvent::pressedMouseButtons() & 1 == 0 {
|
||||
return Ok(false);
|
||||
}
|
||||
#[cfg(windows)]
|
||||
if !primary_mouse_button_down() {
|
||||
return Ok(false);
|
||||
}
|
||||
window.start_dragging().map_err(|e| IdeError::internal(e.to_string()))?;
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
fn primary_button_vk(swapped: bool) -> u16 {
|
||||
use windows_sys::Win32::UI::Input::KeyboardAndMouse::{VK_LBUTTON, VK_RBUTTON};
|
||||
if swapped { VK_RBUTTON } else { VK_LBUTTON }
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
fn primary_mouse_button_down() -> bool {
|
||||
use windows_sys::Win32::UI::Input::KeyboardAndMouse::GetAsyncKeyState;
|
||||
use windows_sys::Win32::UI::WindowsAndMessaging::{GetSystemMetrics, SM_SWAPBUTTON};
|
||||
// GetAsyncKeyState reads physical buttons; map logical primary when left-handed swap is active.
|
||||
let swapped = unsafe { GetSystemMetrics(SM_SWAPBUTTON) != 0 };
|
||||
let vk = primary_button_vk(swapped);
|
||||
// High-order bit is set while the button is down.
|
||||
unsafe { GetAsyncKeyState(i32::from(vk)) as u16 & 0x8000 != 0 }
|
||||
}
|
||||
|
||||
/// Drags `paths` (local files and folders) out of `window` while the primary mouse button is
|
||||
/// still down, so the app they are dropped on copies them (#2867). Resolves when the drag ends,
|
||||
/// with whether a target took the files.
|
||||
@@ -59,3 +84,15 @@ pub async fn window_drag_files(window: WebviewWindow, paths: Vec<PathBuf>) -> Id
|
||||
}
|
||||
|
||||
ide_command::desktop_domain!(window_start_drag, window_drag_files);
|
||||
|
||||
#[cfg(all(test, windows))]
|
||||
mod tests {
|
||||
use super::primary_button_vk;
|
||||
use windows_sys::Win32::UI::Input::KeyboardAndMouse::{VK_LBUTTON, VK_RBUTTON};
|
||||
|
||||
#[test]
|
||||
fn primary_button_vk_respects_swapped_setting() {
|
||||
assert_eq!(primary_button_vk(false), VK_LBUTTON);
|
||||
assert_eq!(primary_button_vk(true), VK_RBUTTON);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Заблокувати користувача