-
-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: window focus * refactor: window is focused is mouse in it * fix: fix windows build error * fix: formatted code * feat: 修改 image 不作为默认feature * feat: macos 实现获取窗口是否聚焦 * feat(breaking): List windows in z order (#178) * feat: 窗口按照z轴顺序返回 * refactor(BREAKING CHANGE): remove window.refresh() --------- Co-authored-by: nashaofu <nashaofu@users.noreply.github.com> * chore: fmt * feat: 修改 macos 窗口 z 值 (#179) Co-authored-by: nashaofu <nashaofu@users.noreply.github.com> --------- Co-authored-by: Louis Beaumont <louis.beaumont@gmail.com> Co-authored-by: nashaofu <nashaofu@users.noreply.github.com>
- Loading branch information
1 parent
ce2fe4f
commit 5457eb2
Showing
9 changed files
with
123 additions
and
294 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,30 @@ | ||
use fs_extra::dir; | ||
use std::{ | ||
thread, | ||
time::{Duration, Instant}, | ||
}; | ||
use std::{sync::Arc, thread, time::Duration}; | ||
use xcap::Monitor; | ||
|
||
fn main() { | ||
let monitors = Monitor::all().unwrap(); | ||
let monitor = Monitor::from_point(100, 100).unwrap(); | ||
|
||
dir::create_all("target/monitors", true).unwrap(); | ||
let video_recorder = Arc::new(monitor.video_recorder().unwrap()); | ||
|
||
let monitor = monitors.get(0).unwrap().clone(); | ||
|
||
let mut i = 0; | ||
let frame = 20; | ||
let start = Instant::now(); | ||
let fps = 1000 / frame; | ||
|
||
loop { | ||
i += 1; | ||
let time = Instant::now(); | ||
let image = monitor.capture_image().unwrap(); | ||
image | ||
.save(format!("target/monitors/monitor-{}.png", i,)) | ||
let video_recorder_clone = video_recorder.clone(); | ||
thread::spawn(move || { | ||
video_recorder_clone | ||
.on_frame(|frame| { | ||
println!("frame: {:?}", frame.width); | ||
Ok(()) | ||
}) | ||
.unwrap(); | ||
let sleep_time = fps * i - start.elapsed().as_millis() as i128; | ||
println!( | ||
"sleep_time: {:?} current_step_time: {:?}", | ||
sleep_time, | ||
time.elapsed() | ||
); | ||
if sleep_time > 0 { | ||
thread::sleep(Duration::from_millis(sleep_time as u64)); | ||
} | ||
|
||
if i >= 900 { | ||
break; | ||
} | ||
} | ||
|
||
println!("time {:?}", start.elapsed()); | ||
let actual_fps = 900 / start.elapsed().as_secs(); | ||
println!("actual fps: {}", actual_fps); | ||
|
||
// ffmpeg -framerate {actual_fps} -i monitor-%d.png -c:v libx264 -pix_fmt yuv420p output.mp4 | ||
}); | ||
|
||
println!("start"); | ||
video_recorder.start().unwrap(); | ||
thread::sleep(Duration::from_secs(2)); | ||
println!("stop"); | ||
video_recorder.stop().unwrap(); | ||
thread::sleep(Duration::from_secs(2)); | ||
println!("start"); | ||
video_recorder.start().unwrap(); | ||
thread::sleep(Duration::from_secs(2)); | ||
println!("stop"); | ||
video_recorder.stop().unwrap(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,22 @@ | ||
use std::time::Instant; | ||
use std::thread; | ||
use xcap::Window; | ||
|
||
fn main() { | ||
let start = Instant::now(); | ||
thread::sleep(std::time::Duration::from_secs(3)); | ||
|
||
let windows = Window::all().unwrap(); | ||
println!("Window::all() 运行耗时: {:?}", start.elapsed()); | ||
|
||
for window in windows { | ||
for window in windows.clone() { | ||
println!( | ||
"Window:\n id: {}\n title: {}\n app_name: {}\n monitor: {:?}\n position: {:?}\n size {:?}\n state {:?}\n", | ||
"Window:\n id: {}\n title: {}\n app_name: {}\n pid: {}\n monitor: {:?}\n position: {:?}\n size {:?}\n state {:?}\n", | ||
window.id(), | ||
window.title(), | ||
window.app_name(), | ||
window.pid(), | ||
window.current_monitor().name(), | ||
(window.x(), window.y()), | ||
(window.x(), window.y(), window.z()), | ||
(window.width(), window.height()), | ||
(window.is_minimized(), window.is_maximized()) | ||
); | ||
} | ||
|
||
println!("运行耗时: {:?}", start.elapsed()); | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.