fix(positioner): Prevent tray relative windows from being moved off-screen (#291)

* feat: add system tray positioning method

* apply patch

* remove pos

* fix linter

* fix cargo fmt

* linter

* add changefile

* Update and rename stronghold-tray-position.md to tray-position.md

---------

Co-authored-by: Fabian-Lars <fabianlars@fabianlars.de>
pull/624/head
Xinyu Yang 2 years ago committed by GitHub
parent 6c7a4c0984
commit 3d279094d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,5 @@
---
"positioner": patch
---
`TrayLeft`, `TrayRight` and `TrayCenter` will now position the window according to the tray position relative to the monitor dimensions to prevent windows being displayed partially off-screen.

@ -107,13 +107,20 @@ impl<R: Runtime> WindowExt for Window<R> {
}, },
#[cfg(feature = "system-tray")] #[cfg(feature = "system-tray")]
TrayLeft => { TrayLeft => {
if let Some((tray_x, tray_y)) = tray_position { if let (Some((tray_x, tray_y)), Some((_, _tray_height))) =
PhysicalPosition { (tray_position, tray_size)
x: tray_x, {
y: tray_y - window_size.height, let y = tray_y - window_size.height;
} // Choose y value based on the target OS
#[cfg(target_os = "windows")]
let y = if y < 0 { tray_y + _tray_height } else { y };
#[cfg(target_os = "macos")]
let y = if y < 0 { tray_y } else { y };
PhysicalPosition { x: tray_x, y }
} else { } else {
panic!("tray position not set"); panic!("Tray position not set");
} }
} }
#[cfg(feature = "system-tray")] #[cfg(feature = "system-tray")]
@ -129,11 +136,20 @@ impl<R: Runtime> WindowExt for Window<R> {
} }
#[cfg(feature = "system-tray")] #[cfg(feature = "system-tray")]
TrayRight => { TrayRight => {
if let (Some((tray_x, tray_y)), Some((tray_width, _))) = (tray_position, tray_size) if let (Some((tray_x, tray_y)), Some((tray_width, _tray_height))) =
(tray_position, tray_size)
{ {
let y = tray_y - window_size.height;
// Choose y value based on the target OS
#[cfg(target_os = "windows")]
let y = if y < 0 { tray_y + _tray_height } else { y };
#[cfg(target_os = "macos")]
let y = if y < 0 { tray_y } else { y };
PhysicalPosition { PhysicalPosition {
x: tray_x + tray_width, x: tray_x + tray_width,
y: tray_y - window_size.height, y,
} }
} else { } else {
panic!("Tray position not set"); panic!("Tray position not set");
@ -153,12 +169,19 @@ impl<R: Runtime> WindowExt for Window<R> {
} }
#[cfg(feature = "system-tray")] #[cfg(feature = "system-tray")]
TrayCenter => { TrayCenter => {
if let (Some((tray_x, tray_y)), Some((tray_width, _))) = (tray_position, tray_size) if let (Some((tray_x, tray_y)), Some((tray_width, _tray_height))) =
(tray_position, tray_size)
{ {
PhysicalPosition { let x = tray_x + tray_width / 2 - window_size.width / 2;
x: tray_x + (tray_width / 2) - (window_size.width / 2), let y = tray_y - window_size.height;
y: tray_y - window_size.height, // Choose y value based on the target OS
} #[cfg(target_os = "windows")]
let y = if y < 0 { tray_y + _tray_height } else { y };
#[cfg(target_os = "macos")]
let y = if y < 0 { tray_y } else { y };
PhysicalPosition { x, y }
} else { } else {
panic!("Tray position not set"); panic!("Tray position not set");
} }

Loading…
Cancel
Save