diff --git a/lib/window.ts b/lib/window.ts index 801a3f8..10ae90e 100644 --- a/lib/window.ts +++ b/lib/window.ts @@ -1,6 +1,5 @@ import { invoke } from '@tauri-apps/api/core' import { WebviewWindow } from '@tauri-apps/api/webviewWindow' -import { platform } from '@tauri-apps/plugin-os' export async function openFullWindow({ name, @@ -20,7 +19,7 @@ export async function openWindow({ name, url, width = 840, - height = platform() === 'windows' ? 755 : 725, + height = 725, }: { name: string url: string diff --git a/src-tauri/common/shortcut.rs b/src-tauri/common/shortcut.rs index c39e954..a7398f6 100644 --- a/src-tauri/common/shortcut.rs +++ b/src-tauri/common/shortcut.rs @@ -13,6 +13,16 @@ const TOOLBAR_WIDTH: f64 = 702.0; #[cfg(target_os = "windows")] const TOOLBAR_HEIGHT: f64 = 460.0; +// #[cfg(target_os = "windows")] +// fn refresh_toolbar_bounds(window: &WebviewWindow) -> Result<(), tauri::Error> { +// // WebView2 can retain stale bounds when this initially-hidden window is shown. +// // A real resize (for example maximizing the window) fixes the clipped viewport, +// // so force the same bounds refresh without leaving the toolbar enlarged. +// window.set_size(tauri::LogicalSize::new(TOOLBAR_WIDTH + 1.0, TOOLBAR_HEIGHT))?; +// window.set_size(tauri::LogicalSize::new(TOOLBAR_WIDTH, TOOLBAR_HEIGHT))?; +// Ok(()) +// } + fn create_toolbar_window(app_handle: &AppHandle) -> Result { let monitor = match app_handle.primary_monitor()? { Some(monitor) => monitor, @@ -35,9 +45,17 @@ fn create_toolbar_window(app_handle: &AppHandle) -> Result(scale_factor); let logical_position = physical_position.to_logical::(scale_factor); + let toolbar_width = TOOLBAR_WIDTH / scale_factor; + let toolbar_height = TOOLBAR_HEIGHT / scale_factor; + // Calculate position in logical pixels, centered on the primary monitor - let pos_x = logical_position.x + (logical_size.width - TOOLBAR_WIDTH) / 2.0; - let pos_y = logical_position.y + logical_size.height / 4.0; + let pos_x = + logical_position.x + + (logical_size.width - toolbar_width) / 2.0; + + let pos_y = + logical_position.y + + logical_size.height / 4.0; WebviewWindowBuilder::new( app_handle, @@ -45,7 +63,7 @@ fn create_toolbar_window(app_handle: &AppHandle) -> Result Result<(), tauri::Error> { if let Some(window) = app_handle.get_webview_window(TOOLBAR_WINDOW_LABEL) { window.show()?; window.unminimize()?; + // #[cfg(target_os = "windows")] + // refresh_toolbar_bounds(&window)?; window.set_focus()?; #[cfg(target_os = "linux")] focus_window_linux(app_handle, &window); @@ -136,6 +156,8 @@ fn open_toolbar(app_handle: &AppHandle) -> Result<(), tauri::Error> { } else { window.show()?; window.unminimize()?; + // #[cfg(target_os = "windows")] + // refresh_toolbar_bounds(&window)?; window.set_focus()?; #[cfg(target_os = "linux")] focus_window_linux(app_handle, &window); diff --git a/src-tauri/common/window.rs b/src-tauri/common/window.rs index 494da57..dbe4f6f 100644 --- a/src-tauri/common/window.rs +++ b/src-tauri/common/window.rs @@ -157,16 +157,30 @@ pub async fn open_window( return Ok(()); } - let os = std::env::consts::OS; - - let default_height = if os == "windows" { 755.0 } else { 725.0 }; let width = width.unwrap_or(840.0); - let height = height.unwrap_or(default_height); + let height = height.unwrap_or(725.0); + + #[cfg(target_os = "windows")] + { + let monitor = match app_handle.primary_monitor().map_err(|e| e.to_string())? { + Some(monitor) => monitor, + None => app_handle + .available_monitors() + .map_err(|e| e.to_string())? + .into_iter() + .next() + .ok_or("No monitors available")?, + }; + + let scale_factor = monitor.scale_factor(); + width = width / scale_factor; + height = height / scale_factor; + } let mut builder = WebviewWindowBuilder::new(&app_handle, &name, WebviewUrl::App(url.into())) .title(&name) .inner_size(width, height) - .min_inner_size(700.0, 700.0) + .min_inner_size(650.0, 500.0) .max_inner_size(1000.0, 1000.0) .resizable(true) .visible(false) diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index f71ab3c..b7f56ed 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -48,7 +48,7 @@ fn main() { } #[cfg(target_os = "windows")] { - std::env::set_var("WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS", "--ignore-gpu-blocklist"); + std::env::set_var("WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS", "--ignore-gpu-blocklist --force-device-scale-factor=1 --disable-features=msWebOOUI"); } let _ = fix_path_env::fix(); app_lib::run(); diff --git a/src/pages/Toolbar.tsx b/src/pages/Toolbar.tsx index 8928d15..fd954bd 100644 --- a/src/pages/Toolbar.tsx +++ b/src/pages/Toolbar.tsx @@ -499,10 +499,15 @@ export default function Toolbar() { }, [highlightedIndex, engineResults]) return ( -
+
- + {engineResults.map((result, index) => { const isActive = index === highlightedIndex const elementId = `tb-result-${result.id.replace(ELEMENT_ID_REGEX, '-')}`