From 5a17c6806d2e1c5b8451f5d12043ebe7c50b24e5 Mon Sep 17 00:00:00 2001 From: don Date: Wed, 25 Dec 2024 23:49:00 +0100 Subject: [PATCH] fix windows bug --- src-tauri/src/service/window.rs | 76 +++++++------------ src-tauri/tauri.conf.json | 4 - .../pages/app/clipboard/base-clipboard.tsx | 8 +- .../pages/app/clipboard/text-clipboard.tsx | 2 +- 4 files changed, 34 insertions(+), 56 deletions(-) diff --git a/src-tauri/src/service/window.rs b/src-tauri/src/service/window.rs index 244347f5..916b0717 100644 --- a/src-tauri/src/service/window.rs +++ b/src-tauri/src/service/window.rs @@ -18,23 +18,20 @@ use tauri_plugin_positioner::{Position, WindowExt}; /// App pub fn init_window() { - tauri::async_runtime::spawn(async { - let size = calculate_logical_size(MAIN_WINDOW_X, MAIN_WINDOW_Y).await; + #[cfg(any(windows, target_os = "macos"))] + { get_main_window() - .set_size(size) - .expect("Failed to set window size"); - - #[cfg(any(windows, target_os = "macos"))] - { - let _ = get_main_window().set_decorations(false); - let _ = get_main_window().set_shadow(true); - } + .set_decorations(false) + .expect("Failed to set decorations"); + get_main_window() + .set_shadow(false) + .expect("Failed to set shadow"); + } - #[cfg(debug_assertions)] - { - get_main_window().open_devtools(); - } - }); + #[cfg(debug_assertions)] + { + get_main_window().open_devtools(); + } } pub fn toggle_main_window() { @@ -72,7 +69,6 @@ pub fn toggle_main_window() { ) .expect("Failed to emit change tab event"); get_main_window().show().expect("Failed to show window"); - register_hotkeys(true); get_main_window() .emit( @@ -134,27 +130,9 @@ pub fn position_window_near_cursor() { if let Ok(cursor_position) = window.cursor_position() { let window_size = window.outer_size().expect("Failed to get window size"); - - // Get current monitor or fallback to primary let current_monitor = window - .available_monitors() - .expect("Failed to get available monitors") - .into_iter() - .find(|monitor| { - let pos = monitor.position(); - let size = monitor.size(); - let bounds = ( - pos.x as f64, - pos.y as f64, - pos.x as f64 + size.width as f64, - pos.y as f64 + size.height as f64, - ); - - cursor_position.x >= bounds.0 - && cursor_position.x < bounds.2 - && cursor_position.y >= bounds.1 - && cursor_position.y < bounds.3 - }) + .current_monitor() + .expect("Failed to get current monitor") .unwrap_or_else(|| { window .primary_monitor() @@ -166,29 +144,34 @@ pub fn position_window_near_cursor() { let monitor_pos = current_monitor.position(); let monitor_size = current_monitor.size(); - // Calculate window position with offset + // Account for Windows DPI scaling + #[cfg(windows)] + let (cursor_x, cursor_y) = ( + cursor_position.x / scale_factor, + cursor_position.y / scale_factor, + ); + #[cfg(not(windows))] + let (cursor_x, cursor_y) = (cursor_position.x, cursor_position.y); + let pos = PhysicalPosition::new( - ((cursor_position.x + 10.0) * scale_factor) as i32, - ((cursor_position.y + 10.0) * scale_factor) as i32, + (cursor_x * scale_factor) as i32, + (cursor_y * scale_factor) as i32, ); - // Calculate monitor bounds in physical pixels let monitor_bounds = ( (monitor_pos.x as f64 * scale_factor) as i32, (monitor_pos.y as f64 * scale_factor) as i32, - (monitor_pos.x as f64 * scale_factor + monitor_size.width as f64 * scale_factor) as i32, - (monitor_pos.y as f64 * scale_factor + monitor_size.height as f64 * scale_factor) - as i32, + ((monitor_pos.x as f64 + monitor_size.width as f64) * scale_factor) as i32, + ((monitor_pos.y as f64 + monitor_size.height as f64) * scale_factor) as i32, ); - // Constrain window position within monitor bounds let final_pos = PhysicalPosition::new( pos.x .max(monitor_bounds.0) - .min(monitor_bounds.2 - window_size.width as i32), + .min(monitor_bounds.2 - (window_size.width as f64 * scale_factor) as i32), pos.y .max(monitor_bounds.1) - .min(monitor_bounds.3 - window_size.height as i32), + .min(monitor_bounds.3 - (window_size.height as f64 * scale_factor) as i32), ); window @@ -196,7 +179,6 @@ pub fn position_window_near_cursor() { .expect("Failed to set window position"); } } - pub fn calculate_thumbnail_dimensions(width: u32, height: u32) -> (u32, u32) { let aspect_ratio = width as f64 / height as f64; if width > MAX_IMAGE_DIMENSIONS || height > MAX_IMAGE_DIMENSIONS { diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 07f2c8b0..f7d1d011 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -14,10 +14,6 @@ "csp": null }, "macOSPrivateApi": true, - "trayIcon": { - "iconPath": "icons/32x32.png", - "iconAsTemplate": true - }, "windows": [ { "fullscreen": false, diff --git a/src/components/pages/app/clipboard/base-clipboard.tsx b/src/components/pages/app/clipboard/base-clipboard.tsx index acbd37b1..7c2d80b4 100644 --- a/src/components/pages/app/clipboard/base-clipboard.tsx +++ b/src/components/pages/app/clipboard/base-clipboard.tsx @@ -79,21 +79,21 @@ export const BaseClipboard: Component = (props) => { title="Star" class={`${ clipboard.star ? "text-yellow-400 dark:text-yellow-300" : "hidden text-zinc-700" - } cursor-pointer text-lg hover:text-yellow-400 group-hover:block dark:text-white dark:hover:text-yellow-300`} + } cursor-pointer hover:text-yellow-400 group-hover:block dark:text-white dark:hover:text-yellow-300`} />
{props.data.rtf && (
@@ -103,7 +103,7 @@ export const BaseClipboard: Component = (props) => { handleDelete(clipboard.id); }} title="Delete" - class="hidden cursor-pointer text-lg text-zinc-700 hover:text-red-600 group-hover:block dark:text-white dark:hover:text-red-600" + class="hidden cursor-pointer text-zinc-700 hover:text-red-600 group-hover:block dark:text-white dark:hover:text-red-600" /> diff --git a/src/components/pages/app/clipboard/text-clipboard.tsx b/src/components/pages/app/clipboard/text-clipboard.tsx index 7bf4fe5c..bd35e011 100644 --- a/src/components/pages/app/clipboard/text-clipboard.tsx +++ b/src/components/pages/app/clipboard/text-clipboard.tsx @@ -79,7 +79,7 @@ export const TextClipboard: Component = (props) => {
-

{data}

+

{data}