diff --git a/widget/Cargo.toml b/widget/Cargo.toml index 07986bf..95a7a88 100644 --- a/widget/Cargo.toml +++ b/widget/Cargo.toml @@ -11,6 +11,7 @@ toml = "0.9.7" dirs = "6.0.0" serde_json = "1.0.145" slint = "1.14.1" +i-slint-backend-winit = "1.14.1" [build-dependencies] slint-build = "1.14.1" diff --git a/widget/src/show_popup.rs b/widget/src/show_popup.rs index 56d5658..ba03184 100644 --- a/widget/src/show_popup.rs +++ b/widget/src/show_popup.rs @@ -1,6 +1,14 @@ use owm_rs::free_api_v25::current::WeatherResponse; use owm_widg_config::config::Config; -use slint::SharedString; +use slint::{LogicalPosition, LogicalSize, SharedString}; + +use i_slint_backend_winit::{ + Backend, + winit::{ + platform::x11::{WindowAttributesExtX11, WindowType}, + window::WindowAttributes, + }, +}; slint::include_modules!(); @@ -14,6 +22,20 @@ fn unit_symbol(units: &str) -> char { } pub fn show_popup(resp: &WeatherResponse, cfg: &Config) -> Result<(), Box> { + // 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))?; + let ui = MainWindow::new()?; let city = resp.name.clone().unwrap_or_else(|| "Unknown".into()); @@ -41,6 +63,12 @@ pub fn show_popup(resp: &WeatherResponse, cfg: &Config) -> Result<(), Box