diff --git a/Cargo.toml b/Cargo.toml index 2e85aec..5808dc6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ i-slint-backend-winit = { version = "1.14.1", default-features = false, features serde = { version = "1.0.228", default-features = false, features = ["derive"] } slint = { version = "1.14.1", default-features = false, features = ["backend-winit", "compat-1-2", "renderer-software"] } toml = "0.9.11" +x11rb = { version = "0.13.2", default-features = false } [build-dependencies] slint-build = "1.14.1" diff --git a/src/main.rs b/src/main.rs index 164d532..f8be0dc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,6 +8,7 @@ use i_slint_backend_winit::{ mod config; mod powermenu; +mod x11_helpers; fn main() -> Result<(), Box> { // Configure X11 window attributes before Slint creates the window. @@ -23,13 +24,14 @@ fn main() -> Result<(), Box> { let backend = Backend::builder() .with_window_attributes_hook(window_attrs) .build()?; - slint::platform::set_platform(Box::new(backend))?; - let screen_width = 1366; - let screen_height = 768; + // Get screen dimensions + let (screen_width, screen_height) = x11_helpers::get_screen_size().unwrap_or((1366, 768)); + // Load config let conf = config::load_config(screen_width, screen_height)?; + // Run the UI powermenu::run_power_menu(conf) } diff --git a/src/x11_helpers.rs b/src/x11_helpers.rs new file mode 100644 index 0000000..74f1043 --- /dev/null +++ b/src/x11_helpers.rs @@ -0,0 +1,11 @@ +use x11rb::{connection::Connection, rust_connection::RustConnection}; + +pub fn get_screen_size() -> Result<(i32, i32), Box> { + 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, + )) +}