39 lines
1.3 KiB
Rust
39 lines
1.3 KiB
Rust
use i_slint_backend_winit::{
|
|
Backend,
|
|
winit::{
|
|
platform::x11::{WindowAttributesExtX11, WindowType},
|
|
window::WindowAttributes,
|
|
},
|
|
};
|
|
use x11rb::{connection::Connection, rust_connection::RustConnection};
|
|
|
|
pub fn get_screen_size() -> Result<(i32, i32), Box<dyn std::error::Error>> {
|
|
let (conn, screen_num) = RustConnection::connect(None)?;
|
|
let screen = &conn.setup().roots[screen_num];
|
|
|
|
Ok((
|
|
screen.width_in_pixels as i32,
|
|
screen.height_in_pixels as i32,
|
|
))
|
|
}
|
|
|
|
pub fn init_slint_backend() -> Result<(), Box<dyn std::error::Error>> {
|
|
// Configure X11 window attributes before Slint creates the window.
|
|
let window_attrs = |attrs: WindowAttributes| {
|
|
attrs
|
|
// Set the window type to Desktop so WMs avoid normal window rules, treat it as a full screen window.
|
|
.with_x11_window_type(vec![WindowType::Desktop])
|
|
// Make the window unmanaged. This prevents tiling WMs from reserving space or moving it.
|
|
.with_override_redirect(true)
|
|
};
|
|
|
|
// Build and activate backend with X11 window-attribute hook.
|
|
let backend = Backend::builder()
|
|
.with_window_attributes_hook(window_attrs)
|
|
.build()?;
|
|
|
|
slint::platform::set_platform(Box::new(backend))?;
|
|
|
|
Ok(())
|
|
}
|