Skip to content

Instantly share code, notes, and snippets.

@saethlin
Last active July 11, 2017 04:11
Show Gist options
  • Save saethlin/d3add112c433ba954082bb1f961ce3b9 to your computer and use it in GitHub Desktop.
Save saethlin/d3add112c433ba954082bb1f961ce3b9 to your computer and use it in GitHub Desktop.
rust xcb Window
pub struct Window {
connection: xcb::base::Connection,
window: xcb::xproto::Window,
foreground: xcb::Drawable,
pub width: u16,
pub height: u16,
}
impl Window {
pub fn new(width: u16, height: u16) -> Self {
let (connection, screen_num) = xcb::Connection::connect(None).unwrap();
let window = connection.generate_id();
let foreground = connection.generate_id();
{
let setup = connection.get_setup();
let screen = setup.roots().nth(screen_num as usize).unwrap();
// Set up foreground graphics context
xcb::create_gc(&connection, foreground, screen.root(), &[
(xcb::GC_FOREGROUND, screen.black_pixel()),
(xcb::GC_GRAPHICS_EXPOSURES, 0),
]);
// Set up the window itself
let values = [
(xcb::CW_BACK_PIXEL, screen.white_pixel()),
(
xcb::CW_EVENT_MASK,
xcb::EVENT_MASK_EXPOSURE | xcb::EVENT_MASK_KEY_PRESS,
),
];
xcb::create_window(
&connection,
xcb::COPY_FROM_PARENT as u8,
window,
screen.root(),
0, 0,
width, height,
10,
xcb::WINDOW_CLASS_INPUT_OUTPUT as u16,
screen.root_visual(),
&values,
);
}
Window {
connection: connection,
window: window,
foreground: foreground,
width: width,
height: height,
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment