Initial commit, takes picture and displays it fullscreen
commit
d16bbe2032
|
@ -0,0 +1 @@
|
||||||
|
/target
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,28 @@
|
||||||
|
cargo-features = ["codegen-backend"]
|
||||||
|
|
||||||
|
[package]
|
||||||
|
name = "zoomie"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[lints.rust]
|
||||||
|
unsafe_code = { level = "forbid" }
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
tokio = { version = "1.41.0", features = ["full"] }
|
||||||
|
ashpd = "0.9.2"
|
||||||
|
winit = "0.30.5"
|
||||||
|
softbuffer = "0.4.6"
|
||||||
|
image = "0.25.4"
|
||||||
|
|
||||||
|
[profile.dev]
|
||||||
|
codegen-backend = "cranelift"
|
||||||
|
opt-level = 0
|
||||||
|
lto = false
|
||||||
|
incremental = true
|
||||||
|
|
||||||
|
[profile.release]
|
||||||
|
opt-level = 3
|
||||||
|
strip = true
|
||||||
|
lto = true
|
||||||
|
codegen-units = 1
|
|
@ -0,0 +1,2 @@
|
||||||
|
[toolchain]
|
||||||
|
channel = "nightly"
|
|
@ -0,0 +1,8 @@
|
||||||
|
unstable_features = true
|
||||||
|
reorder_imports = true
|
||||||
|
hard_tabs = true
|
||||||
|
control_brace_style = "ClosingNextLine"
|
||||||
|
imports_granularity = "Crate"
|
||||||
|
group_imports = "StdExternalCrate"
|
||||||
|
edition = "2021"
|
||||||
|
newline_style = "Unix"
|
|
@ -0,0 +1,115 @@
|
||||||
|
use std::{
|
||||||
|
error::Error,
|
||||||
|
fs::File,
|
||||||
|
io::{BufReader, Read},
|
||||||
|
num::NonZeroU32,
|
||||||
|
rc::Rc,
|
||||||
|
};
|
||||||
|
|
||||||
|
use ashpd::desktop::screenshot::Screenshot;
|
||||||
|
use image::{DynamicImage, GenericImageView, ImageReader};
|
||||||
|
use softbuffer::Surface;
|
||||||
|
use winit::{
|
||||||
|
application::ApplicationHandler,
|
||||||
|
dpi::Size,
|
||||||
|
event::WindowEvent,
|
||||||
|
event_loop::{self, ActiveEventLoop, ControlFlow, EventLoop},
|
||||||
|
monitor::{VideoMode, VideoModeHandle},
|
||||||
|
raw_window_handle::{DisplayHandle, HasDisplayHandle},
|
||||||
|
window::{Fullscreen, Window, WindowAttributes},
|
||||||
|
};
|
||||||
|
|
||||||
|
struct App {
|
||||||
|
window: Rc<Window>,
|
||||||
|
surface: Surface<Rc<Window>, Rc<Window>>,
|
||||||
|
image: DynamicImage,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl App {
|
||||||
|
pub fn new(event_loop: &EventLoop<()>, image: DynamicImage) -> Self {
|
||||||
|
let window = Rc::new(
|
||||||
|
event_loop
|
||||||
|
.create_window(
|
||||||
|
Window::default_attributes()
|
||||||
|
.with_fullscreen(Some(Fullscreen::Borderless(None))),
|
||||||
|
)
|
||||||
|
.unwrap(),
|
||||||
|
);
|
||||||
|
|
||||||
|
let context = softbuffer::Context::new(window.clone()).unwrap();
|
||||||
|
let mut surface = softbuffer::Surface::new(&context, window.clone()).unwrap();
|
||||||
|
|
||||||
|
surface
|
||||||
|
.resize(
|
||||||
|
NonZeroU32::new(image.width()).unwrap(),
|
||||||
|
NonZeroU32::new(image.height()).unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
Self {
|
||||||
|
window,
|
||||||
|
surface,
|
||||||
|
image,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ApplicationHandler for App {
|
||||||
|
fn resumed(&mut self, event_loop: &event_loop::ActiveEventLoop) {}
|
||||||
|
|
||||||
|
fn window_event(
|
||||||
|
&mut self,
|
||||||
|
event_loop: &event_loop::ActiveEventLoop,
|
||||||
|
window_id: winit::window::WindowId,
|
||||||
|
event: winit::event::WindowEvent,
|
||||||
|
) {
|
||||||
|
match event {
|
||||||
|
WindowEvent::CloseRequested => {
|
||||||
|
event_loop.exit();
|
||||||
|
}
|
||||||
|
WindowEvent::RedrawRequested => {
|
||||||
|
let mut buffer = self.surface.buffer_mut().unwrap();
|
||||||
|
let width = self.image.width() as usize;
|
||||||
|
for (x, y, pixel) in self.image.pixels() {
|
||||||
|
let red = pixel.0[0] as u32;
|
||||||
|
let green = pixel.0[1] as u32;
|
||||||
|
let blue = pixel.0[2] as u32;
|
||||||
|
|
||||||
|
let color = blue | (green << 8) | (red << 16);
|
||||||
|
buffer[y as usize * width + x as usize] = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer.present().unwrap();
|
||||||
|
|
||||||
|
// self.window.as_ref().request_redraw();
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::main]
|
||||||
|
async fn main() -> Result<(), Box<dyn Error>> {
|
||||||
|
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().path();
|
||||||
|
let path = response.uri().to_file_path().unwrap();
|
||||||
|
let file = File::open(path).unwrap();
|
||||||
|
let buffer = BufReader::new(file);
|
||||||
|
// let image_reader = ImageReader::new(file);
|
||||||
|
let image = image::load(buffer, image::ImageFormat::Png).unwrap();
|
||||||
|
|
||||||
|
let event_loop = EventLoop::new()?;
|
||||||
|
event_loop.set_control_flow(ControlFlow::Poll);
|
||||||
|
|
||||||
|
let mut app = App::new(&event_loop, image);
|
||||||
|
|
||||||
|
Ok(event_loop.run_app(&mut app)?)
|
||||||
|
}
|
Loading…
Reference in New Issue