diff options
| author | Ivan Molodetskikh <yalterz@gmail.com> | 2024-12-15 10:30:32 +0300 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2024-12-30 20:12:37 +0300 |
| commit | 43a4bae010b814089fe96b9c70c30bdf04b697a4 (patch) | |
| tree | c5ce7b196bd45043449bcc06a3d4f45e711e66aa /src/utils/mod.rs | |
| parent | 9c205f77a2c224e336f3e5222c4d5865d7674cf0 (diff) | |
| download | niri-43a4bae010b814089fe96b9c70c30bdf04b697a4.tar.gz niri-43a4bae010b814089fe96b9c70c30bdf04b697a4.tar.bz2 niri-43a4bae010b814089fe96b9c70c30bdf04b697a4.zip | |
Extract center_preferring_top_left_in_area()
Diffstat (limited to 'src/utils/mod.rs')
| -rw-r--r-- | src/utils/mod.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/utils/mod.rs b/src/utils/mod.rs index e7dff735..7ab89a72 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -284,6 +284,18 @@ pub fn clamp_preferring_top_left_in_area( rect.loc.y = f64::max(rect.loc.y, area.loc.y); } +pub fn center_preferring_top_left_in_area( + area: Rectangle<f64, Logical>, + size: Size<f64, Logical>, +) -> Point<f64, Logical> { + let area_size = area.size.to_point(); + let size = size.to_point(); + let mut offset = (area_size - size).downscale(2.); + offset.x = f64::max(offset.x, 0.); + offset.y = f64::max(offset.y, 0.); + area.loc + offset +} + #[cfg(feature = "dbus")] pub fn show_screenshot_notification(image_path: Option<PathBuf>) { let mut notification = notify_rust::Notification::new(); |
