我使用的是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(())
}
如果我更改width
和height
参数,窗口会调整大小。但是,如果我修改x
和y
参数,窗口不会改变位置。
可能是什么原因呢?
Rust Playground
注:我使用的是Ubuntu 22.10与X11和NVIDIA专有驱动程序。
- 更新日期:**
出于某种原因,这成功地重新定位了窗口(但不知道为什么在create_window
中修改x
和y
没有成功):
let values = ConfigureWindowAux::default().x(500).y(200);
conn.configure_window(win, &values)?;
1条答案
按热度按时间4ngedf3f1#
我不得不使用
.override_redirect
: