Set X window type DOCK
This commit is contained in:
parent
9a30647394
commit
db7ca71905
@ -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"
|
||||
|
||||
@ -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<dyn std::error::Error>> {
|
||||
// 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<dyn st
|
||||
ui.set_temperature(SharedString::from(temperature));
|
||||
ui.set_unit(SharedString::from(unit_symbol));
|
||||
|
||||
#[allow(clippy::cast_precision_loss)]
|
||||
ui.window().set_size(LogicalSize::new(300.0, 124.0));
|
||||
|
||||
// Position the window (bar) at the top-left.
|
||||
ui.window().set_position(LogicalPosition::new(0.0, 0.0));
|
||||
|
||||
ui.run()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user