Skip to content

Commit 71f1d1b

Browse files
committed
fix intersects for macos and fix Display label
1 parent 8b773dc commit 71f1d1b

File tree

3 files changed

+43
-8
lines changed

3 files changed

+43
-8
lines changed

apps/desktop/src-tauri/src/windows.rs

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -255,13 +255,15 @@ impl ShowCapWindow {
255255
return Err(tauri::Error::WindowNotFound);
256256
};
257257

258-
let size = display.physical_size().unwrap();
259-
260258
#[cfg(target_os = "macos")]
261259
let position = display.raw_handle().logical_position();
260+
#[cfg(target_os = "macos")]
261+
let size = display.logical_size().unwrap();
262262

263263
#[cfg(windows)]
264264
let position = display.raw_handle().physical_position().unwrap();
265+
#[cfg(windows)]
266+
let size = display.physical_size().unwrap();
265267

266268
let mut window_builder = self
267269
.window_builder(
@@ -479,7 +481,8 @@ impl ShowCapWindow {
479481
if let Some(main_window) = CapWindowId::Main.get(app)
480482
&& let (Ok(outer_pos), Ok(outer_size)) =
481483
(main_window.outer_position(), main_window.outer_size())
482-
&& display.intersects(outer_pos, outer_size)
484+
&& let Ok(scale_factor) = main_window.scale_factor()
485+
&& display.intersects(outer_pos, outer_size, scale_factor)
483486
{
484487
let _ = main_window.minimize();
485488
};
@@ -729,12 +732,44 @@ fn position_traffic_lights_impl(
729732

730733
// Credits: tauri-plugin-window-state
731734
trait MonitorExt {
732-
fn intersects(&self, position: PhysicalPosition<i32>, size: PhysicalSize<u32>) -> bool;
735+
fn intersects(
736+
&self,
737+
position: PhysicalPosition<i32>,
738+
size: PhysicalSize<u32>,
739+
scale: f64,
740+
) -> bool;
733741
}
734742

735743
impl MonitorExt for Display {
736-
fn intersects(&self, position: PhysicalPosition<i32>, size: PhysicalSize<u32>) -> bool {
737-
return false;
744+
fn intersects(
745+
&self,
746+
position: PhysicalPosition<i32>,
747+
size: PhysicalSize<u32>,
748+
_scale: f64,
749+
) -> bool {
750+
#[cfg(target_os = "macos")]
751+
{
752+
let Some(bounds) = self.raw_handle().logical_bounds() else {
753+
return false;
754+
};
755+
756+
let left = (bounds.position().x() * _scale) as i32;
757+
let right = left + (bounds.size().width() * _scale) as i32;
758+
let top = (bounds.position().y() * _scale) as i32;
759+
let bottom = top + (bounds.size().height() * _scale) as i32;
760+
761+
[
762+
(position.x, position.y),
763+
(position.x + size.width as i32, position.y),
764+
(position.x, position.y + size.height as i32),
765+
(
766+
position.x + size.width as i32,
767+
position.y + size.height as i32,
768+
),
769+
]
770+
.into_iter()
771+
.any(|(x, y)| x >= left && x < right && y >= top && y < bottom)
772+
}
738773

739774
#[cfg(windows)]
740775
{

apps/desktop/src/routes/(window-chrome)/(main).tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ function Page() {
424424
);
425425
}}
426426
value={options.screen() ?? null}
427-
placeholder="display"
427+
placeholder="Display"
428428
optionsEmptyText="No screens found"
429429
selected={
430430
rawOptions.captureTarget.variant === "display" ||

apps/desktop/src/routes/(window-chrome)/new-main.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ function Page() {
300300
v === "display" ? null : "display",
301301
)
302302
}
303-
name="display"
303+
name="Display"
304304
/>
305305
<TargetTypeButton
306306
selected={rawOptions.targetMode === "window"}

0 commit comments

Comments
 (0)