Skip to content

Commit

Permalink
feat: 优化代码
Browse files Browse the repository at this point in the history
  • Loading branch information
nashaofu committed Jan 16, 2024
1 parent 38f54ab commit 8032a7f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 0 additions & 2 deletions examples/window_capture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ fn main() {

let image = window.capture_image();
if let Ok(image) = image {
println!("title {} {}", title, filename);

image
.save(format!("target/window-{}-{}.png", i, filename))
.unwrap();
Expand Down
16 changes: 14 additions & 2 deletions src/macos/impl_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use std::ffi::c_void;

use crate::error::ScreenCaptureResult;

use super::capture::capture;
use super::{capture::capture, impl_monitor::ImplMonitor};

#[derive(Debug, Clone)]
pub(crate) struct ImplWindow {
Expand Down Expand Up @@ -98,6 +98,18 @@ impl ImplWindow {
!CFBooleanGetValue(window_is_on_screen_ref as CFBooleanRef)
};

let is_maximized = {
// 获取窗口中心点的坐标
let window_center_x = (cg_rect.origin.x + cg_rect.size.width) / 2.0;
let window_center_y = (cg_rect.origin.y + cg_rect.size.height) / 2.0;

let impl_monitor =
ImplMonitor::from_point(window_center_x as i32, window_center_y as i32)?;

cg_rect.size.width as u32 == impl_monitor.width
&& cg_rect.size.height as u32 == impl_monitor.height
};

Ok(ImplWindow {
window_cf_dictionary_ref,
id,
Expand All @@ -107,7 +119,7 @@ impl ImplWindow {
width: cg_rect.size.width as u32,
height: cg_rect.size.height as u32,
is_minimized,
is_maximized: false,
is_maximized,
})
}
}
Expand Down

0 comments on commit 8032a7f

Please sign in to comment.