Move all X11 code to helper module
This commit is contained in:
parent
b6abcef325
commit
e18f7f0afb
23
src/main.rs
23
src/main.rs
@ -1,30 +1,9 @@
|
||||
use i_slint_backend_winit::{
|
||||
Backend,
|
||||
winit::{
|
||||
platform::x11::{WindowAttributesExtX11, WindowType},
|
||||
window::WindowAttributes,
|
||||
},
|
||||
};
|
||||
|
||||
mod config;
|
||||
mod powermenu;
|
||||
mod x11_helpers;
|
||||
|
||||
fn main() -> 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))?;
|
||||
x11_helpers::init_slint_backend()?;
|
||||
|
||||
// Get screen dimensions
|
||||
let (screen_width, screen_height) = x11_helpers::get_screen_size().unwrap_or((1366, 768));
|
||||
|
||||
@ -1,3 +1,10 @@
|
||||
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>> {
|
||||
@ -9,3 +16,23 @@ pub fn get_screen_size() -> Result<(i32, i32), Box<dyn std::error::Error>> {
|
||||
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(())
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user