From 798f9593b2f8b2ce9f191751762d8681789e5366 Mon Sep 17 00:00:00 2001 From: Candifloss Date: Tue, 18 Nov 2025 23:21:18 +0530 Subject: [PATCH] Refactor main window setup for clarity - Extract WindowAttributes modification into a named closure - Simplify and clean up winit/Slint imports - Explanatory comments - rustfmt and clippy cleanup --- src/main.rs | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/src/main.rs b/src/main.rs index 9fc4138..6e26600 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,35 +1,48 @@ use i_slint_backend_winit::{ Backend, - winit::platform::x11::{WindowAttributesExtX11, WindowType}, + winit::{ + platform::x11::{WindowAttributesExtX11, WindowType}, + window::WindowAttributes, + }, }; use slint::{LogicalPosition, LogicalSize}; slint::include_modules!(); fn main() -> Result<(), Box> { - // Configure winit attributes before any Slint window is created. - let backend = Backend::builder() - .with_window_attributes_hook(|attrs| { - // Mark the X11 window as a dock so WMs treat it as a panel/topbar. - attrs.with_x11_window_type(vec![WindowType::Dock]) - // hide from taskbar / pagers (useful for panels) - //.with_skip_taskbar(true) - }) - .build()?; + // Closure that adjusts winit WindowAttributes before Slint creates the window. + let window_attrs = |attrs: WindowAttributes| { + // Mark the X11 window as a DOCK so the WM treats it as a top bar/panel. + attrs.with_x11_window_type(vec![WindowType::Dock]) + }; + // Build a Slint backend that applies this attribute hook to all windows. + let backend = Backend::builder() + .with_window_attributes_hook(window_attrs) // Register the hook + .build()?; // Construct backend + + // Activate this customized backend for all Slint window creation and events. slint::platform::set_platform(Box::new(backend))?; + // Bar dimensions. let bar_height = 25; let bar_width = 1366; + // Create the Slint UI component. let ui = TopBar::new()?; + // Set component properties. ui.set_bar_width(bar_width); ui.set_bar_height(bar_height); + // Size the window to match the bar. #[allow(clippy::cast_precision_loss)] ui.window() .set_size(LogicalSize::new(bar_width as f32, bar_height as f32)); + + // Position the window (bar) at the top-left. ui.window().set_position(LogicalPosition::new(0.0, 0.0)); + // Run the Slint event loop. ui.run()?; + Ok(()) }