用glutin绘制到X根窗口

时间:2018-03-11 11:52:43

标签: rust x11

我想将动态壁纸渲染到X根窗口中。这是currently not possible directly through the API glutin exposes

我找到了一个帖子,提问者似乎最终弄清楚了:How can I make a window override-redirect with glutin?

但是,似乎答案中的代码片段不足以实现所需的效果:一旦设置了标志,先前创建的窗口就会消失,但不会向根窗口呈现任何内容。我错过了什么?

这是我到目前为止所拥有的:

let mut events_loop = glium::glutin::EventsLoop::new();
let context = glium::glutin::ContextBuilder::new();
let window = glium::glutin::WindowBuilder::new()
    .with_dimensions(800, 600)
    .with_title("TEST");
let display = glium::Display::new(window, context, &events_loop).unwrap();

unsafe {
    use glium::glutin::os::unix::WindowExt;
    use winit::os::unix::x11::XConnection;
    use winit::os::unix::x11::ffi::{Display, XID, CWOverrideRedirect, XSetWindowAttributes};
    let x_connection = std::sync::Arc::<XConnection>::into_raw(display.gl_window().get_xlib_xconnection().unwrap());
    let x_display = display.gl_window().get_xlib_display().unwrap() as *mut Display;
    let x_window = display.gl_window().get_xlib_window().unwrap() as XID;
    ((*x_connection).xlib.XChangeWindowAttributes)(
        x_display,
        x_window,
        CWOverrideRedirect,
        &mut XSetWindowAttributes {
            background_pixmap: 0,
            background_pixel: 0,
            border_pixmap: 0,
            border_pixel: 0,
            bit_gravity: 0,
            win_gravity: 0,
            backing_store: 0,
            backing_planes: 0,
            backing_pixel: 0,
            save_under: 0,
            event_mask: 0,
            do_not_propagate_mask: 0,
            override_redirect: 1,
            colormap: 0,
            cursor: 0,
        }
    );
    ((*x_connection).xlib.XUnmapWindow)(x_display, x_window);
    ((*x_connection).xlib.XMapWindow)(x_display, x_window);
}

0 个答案:

没有答案