X11-test/src/main.rs

74 lines
2.6 KiB
Rust

#![allow(unreachable_code)]
use gif::{DecodeOptions, Frame};
use std::fs::OpenOptions;
use x11rb::connection::Connection;
use x11rb::protocol::xproto::ConnectionExt;
use x11rb::protocol::xproto::CreateGCAux;
use std::collections::VecDeque;
fn main() {
let (conn, screen_num) = x11rb::connect(None).unwrap(); //connects to xserver
let screen = &conn.setup().roots[screen_num]; //gets the main screen
let root = screen.root; //grabs the root ID of screen
let depth = screen.root_depth; //grabs depth of root window
//let pixmap = conn.generate_id().unwrap(); //generates an ID to use for pixel data presumably
//conn.create_pixmap(depth, pixmap, root, 1920, 1080).unwrap(); //makes a space for pixel data on
//root depth with pixmap ID at
//400x400 space, need to make
//larger
let gc = conn.generate_id().unwrap(); //generates another ID for Graphics Context
let gc_aux = CreateGCAux::new().foreground(screen.white_pixel); // create aux for connecting the
// context to thingy
conn.create_gc(gc, root, &gc_aux).unwrap();
let _arg = std::env::args().next().unwrap();
let input = OpenOptions::new().read(true).open("output.gif").unwrap(); // Grabs image from arguement
let mut de_options = DecodeOptions::new();
de_options.set_color_output(gif::ColorOutput::RGBA);
let mut decoder = de_options.read_info(input).unwrap(); //Decoder Shenanigans
let mut v_frames: VecDeque<Frame> = VecDeque::new();
while let Some(frame) = decoder.read_next_frame().unwrap() {
v_frames.push_back(frame.clone());
} //Putting gif frames into a vector
conn.flush().unwrap();
loop {
let popd = &v_frames.pop_front().unwrap();
let put = conn
.put_image(
x11rb::protocol::xproto::ImageFormat::Z_PIXMAP,
root,
gc,
1920,
1080,
0,
0,
0,
depth,
&popd.buffer,
)
.unwrap();
// let copy = conn
// .copy_area(pixmap, root, gc, 0, 0, 0, 0, 1920, 1080)
// .unwrap();
v_frames.push_back(popd.clone());
put.check().unwrap();
//copy.check().unwrap();
}
conn.flush().unwrap();
// unreachable but whatever
//conn.free_pixmap(pixmap).unwrap();
conn.free_gc(gc).unwrap();
}