Detect screen size at runtime
- For x11 only
This commit is contained in:
parent
07c2793f17
commit
b6abcef325
@ -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"
|
||||
|
||||
@ -8,6 +8,7 @@ use i_slint_backend_winit::{
|
||||
|
||||
mod config;
|
||||
mod powermenu;
|
||||
mod x11_helpers;
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
// Configure X11 window attributes before Slint creates the window.
|
||||
@ -23,13 +24,14 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
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)
|
||||
}
|
||||
|
||||
11
src/x11_helpers.rs
Normal file
11
src/x11_helpers.rs
Normal file
@ -0,0 +1,11 @@
|
||||
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,
|
||||
))
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user