windows scaling issues, #109
Signed-off-by: FTCHD <144691102+FTCHD@users.noreply.github.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
use tauri::{AppHandle, Manager, PhysicalSize, Size, WebviewWindow, WebviewWindowBuilder};
|
use tauri::{AppHandle, Manager, WebviewWindow, WebviewWindowBuilder};
|
||||||
use tauri_plugin_global_shortcut::{GlobalShortcutExt, Shortcut, ShortcutState};
|
use tauri_plugin_global_shortcut::{GlobalShortcutExt, Shortcut, ShortcutState};
|
||||||
|
|
||||||
use super::window::make_transparent;
|
use super::window::make_transparent;
|
||||||
@@ -6,12 +6,10 @@ use super::window::make_transparent;
|
|||||||
pub const DEFAULT_TOOLBAR_SHORTCUT: &str = "CmdOrCtrl+Shift+/";
|
pub const DEFAULT_TOOLBAR_SHORTCUT: &str = "CmdOrCtrl+Shift+/";
|
||||||
const TOOLBAR_WINDOW_LABEL: &str = "Toolbar";
|
const TOOLBAR_WINDOW_LABEL: &str = "Toolbar";
|
||||||
|
|
||||||
// Fixed physical size for the toolbar window on Windows (in physical pixels)
|
|
||||||
// This avoids DPI scaling issues on multi-monitor setups with different scale factors
|
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
const TOOLBAR_PHYSICAL_WIDTH: u32 = 702;
|
const TOOLBAR_WIDTH: f64 = 702.0;
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
const TOOLBAR_PHYSICAL_HEIGHT: u32 = 460;
|
const TOOLBAR_HEIGHT: f64 = 460.0;
|
||||||
|
|
||||||
fn create_toolbar_window(app_handle: &AppHandle) -> Result<WebviewWindow, tauri::Error> {
|
fn create_toolbar_window(app_handle: &AppHandle) -> Result<WebviewWindow, tauri::Error> {
|
||||||
let monitor = match app_handle.primary_monitor()? {
|
let monitor = match app_handle.primary_monitor()? {
|
||||||
@@ -28,13 +26,16 @@ fn create_toolbar_window(app_handle: &AppHandle) -> Result<WebviewWindow, tauri:
|
|||||||
let physical_size = monitor.size();
|
let physical_size = monitor.size();
|
||||||
let physical_position = monitor.position();
|
let physical_position = monitor.position();
|
||||||
|
|
||||||
// On Windows, use physical pixels directly to avoid DPI scaling issues
|
// On Windows, use logical coordinates with scale factor for proper DPI handling
|
||||||
// across multiple monitors with different scale factors
|
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
let builder = {
|
let builder = {
|
||||||
// Calculate position in physical pixels, centered on the primary monitor
|
let scale_factor = monitor.scale_factor();
|
||||||
let pos_x = physical_position.x + ((physical_size.width - TOOLBAR_PHYSICAL_WIDTH) / 2) as i32;
|
let logical_size = physical_size.to_logical::<f64>(scale_factor);
|
||||||
let pos_y = physical_position.y + (physical_size.height / 4) as i32;
|
let logical_position = physical_position.to_logical::<f64>(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;
|
||||||
|
|
||||||
WebviewWindowBuilder::new(
|
WebviewWindowBuilder::new(
|
||||||
app_handle,
|
app_handle,
|
||||||
@@ -42,9 +43,8 @@ fn create_toolbar_window(app_handle: &AppHandle) -> Result<WebviewWindow, tauri:
|
|||||||
tauri::WebviewUrl::App("/toolbar".into()),
|
tauri::WebviewUrl::App("/toolbar".into()),
|
||||||
)
|
)
|
||||||
.title(TOOLBAR_WINDOW_LABEL)
|
.title(TOOLBAR_WINDOW_LABEL)
|
||||||
// Use initial size (will be corrected to physical pixels after creation)
|
.inner_size(TOOLBAR_WIDTH, TOOLBAR_HEIGHT)
|
||||||
.inner_size(TOOLBAR_PHYSICAL_WIDTH as f64, TOOLBAR_PHYSICAL_HEIGHT as f64)
|
.position(pos_x, pos_y)
|
||||||
.position(pos_x as f64, pos_y as f64)
|
|
||||||
.resizable(false)
|
.resizable(false)
|
||||||
.decorations(false)
|
.decorations(false)
|
||||||
.shadow(false)
|
.shadow(false)
|
||||||
@@ -90,14 +90,6 @@ fn create_toolbar_window(app_handle: &AppHandle) -> Result<WebviewWindow, tauri:
|
|||||||
|
|
||||||
let window = builder.build()?;
|
let window = builder.build()?;
|
||||||
|
|
||||||
// On Windows, explicitly set the size in physical pixels to ensure
|
|
||||||
// consistent sizing regardless of which monitor's DPI context is used
|
|
||||||
#[cfg(target_os = "windows")]
|
|
||||||
{
|
|
||||||
let physical_size = PhysicalSize::new(TOOLBAR_PHYSICAL_WIDTH, TOOLBAR_PHYSICAL_HEIGHT);
|
|
||||||
window.set_size(Size::Physical(physical_size))?;
|
|
||||||
}
|
|
||||||
|
|
||||||
window.set_zoom(1.0)?;
|
window.set_zoom(1.0)?;
|
||||||
window.hide()?;
|
window.hide()?;
|
||||||
|
|
||||||
|
|||||||
@@ -48,10 +48,12 @@ pub async fn open_full_window(
|
|||||||
.or_else(|| app_handle.available_monitors().ok()?.into_iter().next());
|
.or_else(|| app_handle.available_monitors().ok()?.into_iter().next());
|
||||||
|
|
||||||
let monitor = primary_monitor.ok_or("No monitor found")?;
|
let monitor = primary_monitor.ok_or("No monitor found")?;
|
||||||
let size = monitor.size();
|
let physical_size = monitor.size();
|
||||||
|
let scale_factor = monitor.scale_factor();
|
||||||
|
let logical_size = physical_size.to_logical::<f64>(scale_factor);
|
||||||
|
|
||||||
let width = size.width as f64;
|
let width = logical_size.width;
|
||||||
let mut height = size.height as f64;
|
let mut height = logical_size.height;
|
||||||
|
|
||||||
if os == "windows" {
|
if os == "windows" {
|
||||||
height -= 100.0;
|
height -= 100.0;
|
||||||
|
|||||||
Reference in New Issue
Block a user