diff --git a/src/main.rs b/src/main.rs index f8be0dc..b0a6535 100644 --- a/src/main.rs +++ b/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> { - // 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)); diff --git a/src/x11_helpers.rs b/src/x11_helpers.rs index 74f1043..bbec477 100644 --- a/src/x11_helpers.rs +++ b/src/x11_helpers.rs @@ -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> { @@ -9,3 +16,23 @@ pub fn get_screen_size() -> Result<(i32, i32), Box> { screen.height_in_pixels as i32, )) } + +pub fn init_slint_backend() -> Result<(), Box> { + // 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(()) +}