46 lines
1.0 KiB
Rust
46 lines
1.0 KiB
Rust
|
use std::{fs::File, io::BufReader};
|
||
|
|
||
|
use app::App;
|
||
|
use ashpd::desktop::screenshot::Screenshot;
|
||
|
use winit::{
|
||
|
event_loop::{ControlFlow, EventLoop},
|
||
|
window::{Fullscreen, Window},
|
||
|
};
|
||
|
|
||
|
pub mod app;
|
||
|
pub mod texture;
|
||
|
pub mod vertex;
|
||
|
|
||
|
pub async fn capture() -> anyhow::Result<()> {
|
||
|
let response = Screenshot::request()
|
||
|
.interactive(false)
|
||
|
.modal(false)
|
||
|
.send()
|
||
|
.await
|
||
|
.expect("failed to send screenshot request")
|
||
|
.response()
|
||
|
.expect("failed to receive screenshot response");
|
||
|
|
||
|
let path = response.uri().to_file_path().unwrap();
|
||
|
let file = File::open(&path).unwrap();
|
||
|
let buffer = BufReader::new(file);
|
||
|
let image = image::load(buffer, image::ImageFormat::Png).unwrap();
|
||
|
|
||
|
let event_loop = EventLoop::new()?;
|
||
|
event_loop.set_control_flow(ControlFlow::Wait);
|
||
|
|
||
|
let window = event_loop
|
||
|
.create_window(
|
||
|
Window::default_attributes().with_fullscreen(Some(Fullscreen::Borderless(None))),
|
||
|
)
|
||
|
.unwrap();
|
||
|
|
||
|
let mut app = App::new(&window, image).await;
|
||
|
|
||
|
event_loop.run_app(&mut app)?;
|
||
|
|
||
|
std::fs::remove_file(path)?;
|
||
|
|
||
|
Ok(())
|
||
|
}
|