diff --git a/packages/desktop/src/common/macos/window_ext_macos.rs b/packages/desktop/src/common/macos/window_ext_macos.rs index 8ad78a78..97b8477d 100644 --- a/packages/desktop/src/common/macos/window_ext_macos.rs +++ b/packages/desktop/src/common/macos/window_ext_macos.rs @@ -5,7 +5,7 @@ use cocoa::{ }; use tauri::{Runtime, Window}; -pub trait WindowExt { +pub trait WindowExtMacOs { fn set_above_menu_bar(&self) -> anyhow::Result<()>; } diff --git a/packages/desktop/src/common/windows/app_bar.rs b/packages/desktop/src/common/windows/app_bar.rs index 1fc8611c..f456dd38 100644 --- a/packages/desktop/src/common/windows/app_bar.rs +++ b/packages/desktop/src/common/windows/app_bar.rs @@ -44,6 +44,11 @@ pub fn create_app_bar( bail!("Failed to register new app bar."); } + // TODO: Ideally we should respond to incoming `ABN_POSCHANGED` messages. + // Not responding to these messages causes space to be continually + // reserved on hot-reloads in development. This is blocked by #11650. + // Ref: https://github.com/tauri-apps/tauri/issues/11650. + // Query to get the adjusted position. This only adjusts the edges of the // rect that have an appbar on them. // e.g. { left: 0, top: 0, right: 1920, bottom: 40 } diff --git a/packages/desktop/src/providers/disk/disk_provider.rs b/packages/desktop/src/providers/disk/disk_provider.rs index 97b4890b..a6248a03 100644 --- a/packages/desktop/src/providers/disk/disk_provider.rs +++ b/packages/desktop/src/providers/disk/disk_provider.rs @@ -1,7 +1,7 @@ -use std::{any::Any, sync::Arc}; +use std::sync::Arc; use serde::{Deserialize, Serialize}; -use sysinfo::{Disk, Disks}; +use sysinfo::Disks; use tokio::sync::Mutex; use crate::{ diff --git a/packages/desktop/src/widget_factory.rs b/packages/desktop/src/widget_factory.rs index c9ff2ab9..6c1e57b5 100644 --- a/packages/desktop/src/widget_factory.rs +++ b/packages/desktop/src/widget_factory.rs @@ -21,14 +21,12 @@ use tokio::{ use tracing::{error, info}; #[cfg(target_os = "windows")] -use crate::{ - common::windows::{remove_app_bar, WindowExtWindows}, - config::DockEdge, -}; +use crate::common::windows::{remove_app_bar, WindowExtWindows}; use crate::{ common::PathExt, config::{ - AnchorPoint, Config, DockConfig, WidgetConfig, WidgetPlacement, + AnchorPoint, Config, DockConfig, DockEdge, WidgetConfig, + WidgetPlacement, }, monitor_state::{Monitor, MonitorState}, }; @@ -274,15 +272,12 @@ impl WidgetFactory { let mut size = coordinates.size; let mut position = coordinates.position; - #[cfg(target_os = "windows")] - { - if placement.dock_to_edge.enabled { - (size, position) = self.dock_to_edge( - &window, - &placement.dock_to_edge, - &coordinates, - )?; - } + if placement.dock_to_edge.enabled { + (size, position) = self.dock_to_edge( + &window, + &placement.dock_to_edge, + &coordinates, + )?; } info!("Positioning widget to {:?} {:?}", size, position); @@ -364,106 +359,117 @@ impl WidgetFactory { dock_config: &DockConfig, coords: &WidgetCoordinates, ) -> anyhow::Result<(PhysicalSize, PhysicalPosition)> { - // Disallow docking with a centered anchor point. Doesn't make sense. - if coords.anchor == AnchorPoint::Center { + #[cfg(not(target_os = "windows"))] + { return Ok((coords.size, coords.position)); } - let edge = dock_config.edge.unwrap_or_else(|| coords.closest_edge()); + #[cfg(target_os = "windows")] + { + // Disallow docking with a centered anchor point. Doesn't make sense. + if coords.anchor == AnchorPoint::Center { + return Ok((coords.size, coords.position)); + } - // Offset from the monitor edge to the window. - let offset = match edge { - DockEdge::Top => coords.offset.y, - DockEdge::Bottom => -coords.offset.y, - DockEdge::Left => coords.offset.x, - DockEdge::Right => -coords.offset.x, - }; + let edge = dock_config.edge.unwrap_or_else(|| coords.closest_edge()); - // Length of the window perpendicular to the monitor edge. - let window_length = if edge.is_horizontal() { - coords.size.height - } else { - coords.size.width - }; + // Offset from the monitor edge to the window. + let offset = match edge { + DockEdge::Top => coords.offset.y, + DockEdge::Bottom => -coords.offset.y, + DockEdge::Left => coords.offset.x, + DockEdge::Right => -coords.offset.x, + }; - // Margin to reserve *after* the window. Can be negative, but should - // not be smaller than the size of the window. - let window_margin = dock_config - .window_margin - .to_px_scaled(window_length as i32, coords.monitor.scale_factor) - .clamp(-coords.size.height, i32::MAX); + // Length of the window perpendicular to the monitor edge. + let window_length = if edge.is_horizontal() { + coords.size.height + } else { + coords.size.width + }; - let monitor_length = if edge.is_horizontal() { - coords.monitor.height - } else { - coords.monitor.width - }; + // Margin to reserve *after* the window. Can be negative, but should + // not be smaller than the size of the window. + let window_margin = dock_config + .window_margin + .to_px_scaled(window_length as i32, coords.monitor.scale_factor) + .clamp(-coords.size.height, i32::MAX); + + let monitor_length = if edge.is_horizontal() { + coords.monitor.height + } else { + coords.monitor.width + }; - // Prevent the reserved amount from exceeding 50% of the monitor size. - // This maximum is arbitrary but should be sufficient for most cases. - let reserved_length = (offset + window_length + window_margin) - .clamp(0, monitor_length as i32 / 2); + // Prevent the reserved amount from exceeding 50% of the monitor + // size. This maximum is arbitrary but should be sufficient for + // most cases. + let reserved_length = (offset + window_length + window_margin) + .clamp(0, monitor_length as i32 / 2); - let reserve_size = if edge.is_horizontal() { - PhysicalSize::new(coords.monitor.width as i32, reserved_length) - } else { - PhysicalSize::new(reserved_length, coords.monitor.height as i32) - }; + let reserve_size = if edge.is_horizontal() { + PhysicalSize::new(coords.monitor.width as i32, reserved_length) + } else { + PhysicalSize::new(reserved_length, coords.monitor.height as i32) + }; - let reserve_position = match edge { - DockEdge::Top | DockEdge::Left => { - PhysicalPosition::new(coords.monitor.x, coords.monitor.y) - } - DockEdge::Bottom => PhysicalPosition::new( - coords.monitor.x, - coords.monitor.y + coords.monitor.height as i32 - reserved_length, - ), - DockEdge::Right => PhysicalPosition::new( - coords.monitor.x + coords.monitor.width as i32 - reserved_length, - coords.monitor.y, - ), - }; + let reserve_position = match edge { + DockEdge::Top | DockEdge::Left => { + PhysicalPosition::new(coords.monitor.x, coords.monitor.y) + } + DockEdge::Bottom => PhysicalPosition::new( + coords.monitor.x, + coords.monitor.y + coords.monitor.height as i32 + - reserved_length, + ), + DockEdge::Right => PhysicalPosition::new( + coords.monitor.x + coords.monitor.width as i32 - reserved_length, + coords.monitor.y, + ), + }; - let (allocated_size, allocated_position) = window - .as_ref() - .window() - .allocate_app_bar(reserve_size, reserve_position, edge)?; + let (allocated_size, allocated_position) = window + .as_ref() + .window() + .allocate_app_bar(reserve_size, reserve_position, edge)?; - // Adjust the size to account for the window margin. - let final_size = if edge.is_horizontal() { - PhysicalSize::new( - allocated_size.width, - allocated_size.height.saturating_sub(window_margin.abs()), - ) - } else { - PhysicalSize::new( - allocated_size.width.saturating_sub(window_margin.abs()), - allocated_size.height, - ) - }; + // Adjust the size to account for the window margin. + let final_size = if edge.is_horizontal() { + PhysicalSize::new( + allocated_size.width, + allocated_size.height.saturating_sub(window_margin.abs()), + ) + } else { + PhysicalSize::new( + allocated_size.width.saturating_sub(window_margin.abs()), + allocated_size.height, + ) + }; - // Adjust position if we're docked to bottom or right edge to account - // for the size reduction. - let final_position = match edge { - DockEdge::Bottom => PhysicalPosition::new( - allocated_position.x, - allocated_position.y + (allocated_size.height - final_size.height), - ), - DockEdge::Right => PhysicalPosition::new( - allocated_position.x + (allocated_size.width - final_size.width), - allocated_position.y, - ), - _ => allocated_position, - }; + // Adjust position if we're docked to bottom or right edge to account + // for the size reduction. + let final_position = match edge { + DockEdge::Bottom => PhysicalPosition::new( + allocated_position.x, + allocated_position.y + + (allocated_size.height - final_size.height), + ), + DockEdge::Right => PhysicalPosition::new( + allocated_position.x + (allocated_size.width - final_size.width), + allocated_position.y, + ), + _ => allocated_position, + }; - tracing::info!( - "Docked widget to edge '{:?}' with size {:?} and position {:?}.", - edge, - final_size, - final_position - ); + tracing::info!( + "Docked widget to edge '{:?}' with size {:?} and position {:?}.", + edge, + final_size, + final_position + ); - Ok((final_size, final_position)) + Ok((final_size, final_position)) + } } /// Opens presets that are configured to be launched on startup.