From 5bb56c219a40b2a2abeb4a92243024b67b8e8e72 Mon Sep 17 00:00:00 2001 From: zyf722 Date: Sat, 25 Jul 2026 02:22:08 +0800 Subject: [PATCH 1/3] fix: Windows toolbar clipping --- src-tauri/common/shortcut.rs | 16 +++++++++++++++- src/pages/Toolbar.tsx | 14 +++++++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src-tauri/common/shortcut.rs b/src-tauri/common/shortcut.rs index c39e954..cda1c51 100644 --- a/src-tauri/common/shortcut.rs +++ b/src-tauri/common/shortcut.rs @@ -1,9 +1,9 @@ use tauri::{AppHandle, Manager, WebviewWindow, WebviewWindowBuilder}; use tauri_plugin_global_shortcut::{GlobalShortcutExt, Shortcut, ShortcutState}; -use super::window::make_transparent; #[cfg(target_os = "linux")] use super::window::focus_window_linux; +use super::window::make_transparent; pub const DEFAULT_TOOLBAR_SHORTCUT: &str = "CmdOrCtrl+Shift+/"; const TOOLBAR_WINDOW_LABEL: &str = "Toolbar"; @@ -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, @@ -119,6 +129,8 @@ pub fn show_toolbar_window(app_handle: &AppHandle) -> 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 +148,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/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, '-')}` From a0c4525703cffe2371494fab7bd10eec20dee080 Mon Sep 17 00:00:00 2001 From: FTCHD <144691102+FTCHD@users.noreply.github.com> Date: Sat, 15 Aug 2026 16:35:21 +0300 Subject: [PATCH 2/3] comment out unnecessary windows handling --- src-tauri/common/shortcut.rs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src-tauri/common/shortcut.rs b/src-tauri/common/shortcut.rs index cda1c51..2e2b8c6 100644 --- a/src-tauri/common/shortcut.rs +++ b/src-tauri/common/shortcut.rs @@ -1,9 +1,9 @@ use tauri::{AppHandle, Manager, WebviewWindow, WebviewWindowBuilder}; use tauri_plugin_global_shortcut::{GlobalShortcutExt, Shortcut, ShortcutState}; +use super::window::make_transparent; #[cfg(target_os = "linux")] use super::window::focus_window_linux; -use super::window::make_transparent; pub const DEFAULT_TOOLBAR_SHORTCUT: &str = "CmdOrCtrl+Shift+/"; const TOOLBAR_WINDOW_LABEL: &str = "Toolbar"; @@ -13,15 +13,15 @@ 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(()) -} +// #[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()? { @@ -129,8 +129,8 @@ pub fn show_toolbar_window(app_handle: &AppHandle) -> 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)?; + // #[cfg(target_os = "windows")] + // refresh_toolbar_bounds(&window)?; window.set_focus()?; #[cfg(target_os = "linux")] focus_window_linux(app_handle, &window); @@ -148,8 +148,8 @@ fn open_toolbar(app_handle: &AppHandle) -> Result<(), tauri::Error> { } else { window.show()?; window.unminimize()?; - #[cfg(target_os = "windows")] - refresh_toolbar_bounds(&window)?; + // #[cfg(target_os = "windows")] + // refresh_toolbar_bounds(&window)?; window.set_focus()?; #[cfg(target_os = "linux")] focus_window_linux(app_handle, &window); From f3fd4865fed76529f7640c6d6f8af2053ede9cf4 Mon Sep 17 00:00:00 2001 From: FTCHD <144691102+FTCHD@users.noreply.github.com> Date: Sat, 15 Aug 2026 16:37:23 +0300 Subject: [PATCH 3/3] adjust windows scaling settings, fixes #194 --- lib/window.ts | 3 +-- src-tauri/common/shortcut.rs | 14 +++++++++++--- src-tauri/common/window.rs | 24 +++++++++++++++++++----- src-tauri/src/main.rs | 2 +- 4 files changed, 32 insertions(+), 11 deletions(-) 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 2e2b8c6..a7398f6 100644 --- a/src-tauri/common/shortcut.rs +++ b/src-tauri/common/shortcut.rs @@ -45,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, @@ -55,7 +63,7 @@ fn create_toolbar_window(app_handle: &AppHandle) -> Result 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();