I’m currently working on setting a background image in Xorg using XCB. I’ve managed to handle most of the problems, but I’m facing an issue where the images cover all the other windows
Here’s the code I’m using to set the background:
let (conn, screen_num) = xcb::Connection::connect(None).unwrap();
let setup = conn.get_setup();
let screen = setup.roots().nth(screen_num as usize).unwrap();
let (width, height) = (screen.width_in_pixels(), screen.height_in_pixels());
let window = screen.root();
let pixmap: x::Pixmap = conn.generate_id();
conn.check_request(conn.send_request_checked(&x::CreatePixmap {
depth: screen.root_depth(),
pid: pixmap,
drawable: x::Drawable::Window(window),
width,
height,
}))?;
let gc = conn.generate_id();
conn.check_request(conn.send_request_checked(&x::CreateGc {
cid: gc,
drawable: x::Drawable::Pixmap(pixmap),
value_list: &[],
}))?;
loop {
let image = rx.recv()?; // Receive image from mpsc channel
let image = resize_image(image, width as u32, height as u32)?; // This returns Vec<u8>
conn.check_request(conn.send_request_checked(&x::PutImage {
format: x::ImageFormat::ZPixmap,
drawable: x::Drawable::Pixmap(pixmap),
gc,
width,
height,
dst_x: 0,
dst_y: 0,
left_pad: 0,
depth: screen.root_depth(),
data: &image,
}))?;
conn.check_request(conn.send_request_checked(&x::CopyArea {
src_drawable: x::Drawable::Pixmap(pixmap),
dst_drawable: x::Drawable::Window(window),
gc,
src_x: 0,
src_y: 0,
dst_x: 0,
dst_y: 0,
width,
height,
}))?;
}