细节调整及优化(26.8.3)

This commit is contained in:
zhongluofeng
2026-08-21 17:25:47 +08:00
parent 0a19b4b38a
commit 4dd60f42a1
72 changed files with 4779 additions and 1395 deletions
+42 -2
View File
@@ -60,8 +60,8 @@ mod win_api {
GetClassNameW, GetCursorPos, GetForegroundWindow, GetWindowLongPtrW,
GetWindowRect, SendMessageW, SetWindowLongPtrW, SetWindowPos,
GWL_EXSTYLE, HTCAPTION, HWND_NOTOPMOST, HWND_TOPMOST, SWP_NOACTIVATE, SWP_NOMOVE,
SWP_NOSIZE, SWP_SHOWWINDOW, WM_NCLBUTTONDOWN, WS_EX_NOACTIVATE, WS_EX_TOOLWINDOW,
WS_EX_TRANSPARENT,
SWP_NOSIZE, SWP_NOZORDER, SWP_SHOWWINDOW, WM_NCLBUTTONDOWN, WS_EX_NOACTIVATE,
WS_EX_TOOLWINDOW, WS_EX_TRANSPARENT,
};
/// windows-sys 的 HWND 类型别名(isize
@@ -190,6 +190,24 @@ mod win_api {
}
}
/// 原子设置窗口位置与尺寸(物理像素)
///
/// 一次 SetWindowPos 调用同时更新 x/y/w/h,避免 setSize + setPosition
/// 两次调用之间出现"宽度已变、位置未动"的中间帧(视觉闪烁)。
pub fn set_bounds(hwnd: Hwnd, x: i32, y: i32, w: i32, h: i32) {
unsafe {
SetWindowPos(
hwnd,
0, // 不改 Z 序
x,
y,
w,
h,
SWP_NOACTIVATE | SWP_NOZORDER,
);
}
}
/// 判断窗口类名是否为系统 UI(任务栏、开始菜单、通知区域等)
pub fn is_system_ui_class(class_name: &str) -> bool {
matches!(
@@ -378,6 +396,28 @@ pub fn osd_set_topmost(label: String, topmost: bool, app: AppHandle) -> Result<(
Ok(())
}
/// 原子设置窗口位置与尺寸(物理像素)
///
/// 一次调用同时更新位置和尺寸,避免 setSize + setPosition 两次 IPC 之间的
/// 中间帧(宽度已变、位置未动 → 视觉闪烁)。前端传入物理像素坐标。
#[tauri::command]
pub fn osd_set_bounds(
label: String,
x: i32,
y: i32,
w: i32,
h: i32,
app: AppHandle,
) -> Result<(), String> {
#[cfg(windows)]
{
let hwnd = win_api::get_hwnd(&label, &app)
.ok_or_else(|| format!("窗口 {} 不存在", label))?;
win_api::set_bounds(hwnd, x, y, w, h);
}
Ok(())
}
/// 启动原生拖动(右键长按触发)
///
/// 同步关闭点击穿透(WS_EX_TRANSPARENT),然后在独立线程中调用