托盘调整
This commit is contained in:
@@ -73,7 +73,7 @@ pub fn unregister_shortcut(app: &AppHandle) {
|
||||
/// 窗口不存在则创建(隐藏状态,等前端挂载后调用 show_window 显示)。
|
||||
/// 窗口已存在则移动到鼠标位置并显示。
|
||||
pub fn show_popup(app: &AppHandle) {
|
||||
// 获取鼠标位置(屏幕坐标)
|
||||
// 获取鼠标位置(物理像素,Per-Monitor DPI V2)
|
||||
let (mx, my) = match get_cursor_pos() {
|
||||
Some(p) => p,
|
||||
None => return,
|
||||
@@ -83,16 +83,30 @@ pub fn show_popup(app: &AppHandle) {
|
||||
let w = 380.0_f64;
|
||||
let h = 460.0_f64;
|
||||
|
||||
// 获取屏幕工作区以避免弹出位置超出屏幕
|
||||
// 获取屏幕工作区(物理像素,Per-Monitor DPI V2)
|
||||
let (screen_w, screen_h) = get_work_area().unwrap_or((1920.0, 1080.0));
|
||||
|
||||
// 计算窗口位置:鼠标位置作为左上角,超出屏幕则调整
|
||||
let x = (mx as f64).min(screen_w - w).max(0.0);
|
||||
let y = (my as f64).min(screen_h - h).max(0.0);
|
||||
// 获取 scale factor,将窗口逻辑尺寸换算为物理像素用于边界裁剪
|
||||
let scale = app
|
||||
.get_webview_window(POPUP_LABEL)
|
||||
.as_ref()
|
||||
.and_then(|w| w.scale_factor().ok())
|
||||
.or_else(|| {
|
||||
app.get_webview_window("main")
|
||||
.and_then(|w| w.scale_factor().ok())
|
||||
})
|
||||
.unwrap_or(1.0);
|
||||
|
||||
let w_phys = (w * scale) as i32;
|
||||
let h_phys = (h * scale) as i32;
|
||||
|
||||
// 物理坐标 clamping
|
||||
let x = mx.max(0).min(screen_w as i32 - w_phys);
|
||||
let y = my.max(0).min(screen_h as i32 - h_phys);
|
||||
|
||||
// 窗口已存在:移动 + 显示 + 请求焦点
|
||||
if let Some(win) = app.get_webview_window(POPUP_LABEL) {
|
||||
let _ = win.set_position(tauri::Position::Logical(tauri::LogicalPosition {
|
||||
let _ = win.set_position(tauri::Position::Physical(tauri::PhysicalPosition {
|
||||
x,
|
||||
y,
|
||||
}));
|
||||
@@ -112,7 +126,7 @@ pub fn show_popup(app: &AppHandle) {
|
||||
)
|
||||
.title("剪贴板")
|
||||
.inner_size(w, h)
|
||||
.position(x, y)
|
||||
.position(x as f64 / scale, y as f64 / scale)
|
||||
.decorations(false)
|
||||
.transparent(true)
|
||||
.shadow(true)
|
||||
|
||||
Reference in New Issue
Block a user