aaah backgrounds

lines
expectocode 2018-11-25 00:49:47 +00:00
parent caa4102856
commit e20d9cfa0c
1 changed files with 95 additions and 4 deletions

View File

@ -1,5 +1,8 @@
extern crate xcb;
// use std::fs::File;
// use std::io::Write;
fn main() {
let (conn, screen_num) = xcb::Connection::connect(None).unwrap();
let setup = conn.get_setup();
@ -7,8 +10,40 @@ fn main() {
let window = conn.generate_id();
let width = screen.width_in_pixels();
let height = screen.height_in_pixels();
println!("width {} height {}", width, height);
let screenshot = xcb::get_image(
&conn,
xcb::IMAGE_FORMAT_Z_PIXMAP as u8,
screen.root(),
0,
0,
width,
height,
0xFF_FF_FF_FF_u32,
).get_reply()
.unwrap();
// let mut buf = File::create("out.bin").unwrap();
// buf.write(screenshot.data()).unwrap();
let bg = conn.generate_id();
xcb::create_pixmap(
&conn,
xcb::COPY_FROM_PARENT as u8,
bg,
screenshot,
width,
height,
);
let values = [
(xcb::CW_BACK_PIXEL, screen.white_pixel()),
// ?RGB. First 4 bytes appear to do nothing
(xcb::CW_BACK_PIXEL, 0x00_00_00_00),
// (xcb::CW_BACK_PIXMAP, bg),
(
xcb::CW_EVENT_MASK,
xcb::EVENT_MASK_EXPOSURE
@ -16,6 +51,7 @@ fn main() {
| xcb::EVENT_MASK_BUTTON_PRESS
| xcb::EVENT_MASK_BUTTON_RELEASE,
),
(xcb::CW_OVERRIDE_REDIRECT, 1 as u32), // Don't be window managed
];
xcb::create_window(
@ -25,17 +61,47 @@ fn main() {
screen.root(),
0,
0,
150,
150,
10,
width / 2,
height / 2,
0,
xcb::WINDOW_CLASS_INPUT_OUTPUT as u16,
screen.root_visual(),
&values,
);
// // Set transparency.
// let opacity_atom = xcb::intern_atom(&conn, false, "_NET_WM_WINDOW_OPACITY")
// .get_reply()
// .expect("Couldn't create atom _NET_WM_WINDOW_OPACITY")
// .atom();
// // let opacity = u32::max_value();
// let opacity = 0;
// xcb::change_property(
// &conn,
// xcb::PROP_MODE_REPLACE as u8,
// window,
// opacity_atom,
// xcb::ATOM_CARDINAL,
// 32,
// &[opacity],
// );
xcb::map_window(&conn, window);
let title = "hacksaw";
// setting title
xcb::change_property(
&conn,
xcb::PROP_MODE_REPLACE as u8,
window,
xcb::ATOM_WM_NAME,
xcb::ATOM_STRING,
8,
title.as_bytes(),
);
conn.flush();
loop {
let ev = conn.wait_for_event();
match ev {
@ -63,4 +129,29 @@ fn main() {
}
};
}
// Now we have taken coordinates, we use them
}
// let vinfo: xcb::XVisualInfo;
// unsafe {
// xcb::XMatchVisualInfo(conn.get_raw_dpy(), screen_num, 32, xcb::Truecolor, &vinfo);
// }
// int main(int argc, char* argv[])
// {
// Display* display = XOpenDisplay(NULL);
// XVisualInfo vinfo;
// XMatchVisualInfo(display, DefaultScreen(display), 32, TrueColor, &vinfo);
// XSetWindowAttributes attr;
// attr.colormap = XCreateColormap(display, DefaultRootWindow(display), vinfo.visual, AllocNone);
// attr.border_pixel = 0;
// attr.background_pixel = 0;
// Window win = XCreateWindow(display, DefaultRootWindow(display), 0, 0, 300, 200, 0, vinfo.depth, InputOutput, vinfo.visual, CWColormap | CWBorderPixel | CWBackPixel, &attr);
// XDestroyWindow(display, win);
// XCloseDisplay(display);
// return 0;
// }