rust x11库的x和y参数对窗口没有任何影响

ldioqlga  于 2023-02-23  发布在  其他
关注(0)|答案(1)|浏览(142)

我使用的是x11cb库,用于使用Rust与x11服务器交互。

use std::error::Error;
use x11rb::connection::Connection;
use x11rb::protocol::xproto::*;
use x11rb::COPY_DEPTH_FROM_PARENT;

fn main() -> Result<(), Box<dyn Error>> {
    // Open the connection to the X server. Use the DISPLAY environment variable.
    let (conn, screen_num) = x11rb::connect(None)?;

    // Get the screen #screen_num
    let screen = &conn.setup().roots[screen_num];

    // Ask for our window's Id
    let win = conn.generate_id()?;

    // Create the window
    conn.create_window(
        COPY_DEPTH_FROM_PARENT,    // depth (same as root)
        win,                       // window Id
        screen.root,               // parent window
        200,                       // x
        200,                       // y
        150,                       // width
        150,                       // height
        10,                        // border width
        WindowClass::INPUT_OUTPUT, // class
        screen.root_visual,        // visual
        &Default::default(),
    )?; // masks, not used yet

    // Map the window on the screen
    conn.map_window(win)?;

    // Make sure commands are sent before the sleep, so window is shown
    conn.flush()?;

    std::thread::sleep(std::time::Duration::from_secs(10));

    Ok(())
}

如果我更改widthheight参数,窗口会调整大小。但是,如果我修改xy参数,窗口不会改变位置。
可能是什么原因呢?
Rust Playground
注:我使用的是Ubuntu 22.10与X11和NVIDIA专有驱动程序。

    • 更新日期:**

出于某种原因,这成功地重新定位了窗口(但不知道为什么在create_window中修改xy没有成功):

let values = ConfigureWindowAux::default().x(500).y(200);                                   
conn.configure_window(win, &values)?;
4ngedf3f

4ngedf3f1#

我不得不使用.override_redirect

let values = CreateWindowAux::default()
   .background_pixel(x11rb::NONE)
   .border_pixel(x11rb::NONE)
   .override_redirect(1u32)
   .event_mask(EventMask::EXPOSURE | EventMask::STRUCTURE_NOTIFY); // Create the window

conn.create_window(
    COPY_DEPTH_FROM_PARENT,    // depth (same as root)
    win,                       // window Id
    screen.root,               // parent window
    200,                       // x
    200,                       // y
    150,                       // width
    150,                       // height
    10,                        // border width
    WindowClass::INPUT_OUTPUT, // class
    screen.root_visual,        // visual
    &values,
)?; // masks, not used yet

相关问题