怎样才能让用明胶的窗口覆盖重定向?(How can I make a window override

2019-10-29 18:14发布

我创建一个使用明胶一个程序,我想提供一个命令行标志,以使窗口覆盖重定向,因此它可以被用作桌面壁纸某些窗口管理器不支持桌面窗口类型。

我已经做了很多的研究和管理,以凑齐,我认为会的工作,利用明胶所提供的xlib显示和窗口的代码块。 这里是我现有的代码:

unsafe {
    use glutin::os::unix::WindowExt;
    let x_connection = std::sync::Arc::<glutin::os::unix::x11::XConnection>::into_raw(display.gl_window().get_xlib_xconnection().unwrap());
    ((*x_connection).xlib.XChangeWindowAttributes)(
        display.gl_window().get_xlib_display().unwrap() as *mut glutin::os::unix::x11::ffi::Display,
        display.gl_window().get_xlib_window().unwrap() as glutin::os::unix::x11::ffi::XID,
        glutin::os::unix::x11::ffi::CWOverrideRedirect,
        &mut glutin::os::unix::x11::ffi::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,
        }
    );
}

它不给我任何错误,并编译和运行良好的代码的其余部分,但它不会使窗口覆盖重定向像我想。

Answer 1:

我想到了。 将覆盖重定向仅发生在映射的窗口,所以如果我取消映射并重新映射它,然后它的作品!

这是现在的代码:

unsafe {
    use glutin::os::unix::WindowExt;
    use glutin::os::unix::x11::XConnection;
    use glutin::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);
}


文章来源: How can I make a window override-redirect with glutin?
标签: rust x11