62 lines
1.9 KiB
Rust
62 lines
1.9 KiB
Rust
use slint::{Color, LogicalPosition, LogicalSize, SharedString};
|
|
|
|
use i_slint_backend_winit::{
|
|
Backend,
|
|
winit::{
|
|
platform::x11::{WindowAttributesExtX11, WindowType},
|
|
window::WindowAttributes,
|
|
},
|
|
};
|
|
|
|
slint::include_modules!();
|
|
|
|
pub struct PopupData {
|
|
pub title: String,
|
|
pub time: String,
|
|
pub color: u32,
|
|
}
|
|
|
|
fn set_ui_props(ui: &MainWindow, data: &PopupData) {
|
|
ui.window().set_position(LogicalPosition::new(200.0, 35.0));
|
|
ui.window().set_size(LogicalSize::new(300.0, 124.0));
|
|
|
|
ui.set_alarm_name(SharedString::from(data.title.clone()));
|
|
ui.set_alarm_time(SharedString::from(data.time.clone()));
|
|
ui.set_alarm_color(Color::from_argb_encoded(data.color));
|
|
|
|
ui.set_popup_width(300);
|
|
ui.set_popup_height(124);
|
|
ui.set_default_font(SharedString::from("IosevkaTermSlab Nerd Font Mono"));
|
|
ui.set_alarm_icon(SharedString::from("🕓"));
|
|
}
|
|
|
|
pub fn show_popup(data: PopupData) -> Result<(), Box<dyn std::error::Error>> {
|
|
// Closure to configure X11 window attributes before Slint creates the window.
|
|
let window_attrs = |attrs: WindowAttributes| {
|
|
attrs
|
|
// Present the window as a dock so most WMs avoid decorations and normal window rules.
|
|
.with_x11_window_type(vec![WindowType::Dock])
|
|
// Make the window unmanaged. This prevents tiling WMs from reserving space or moving it.
|
|
.with_override_redirect(true)
|
|
};
|
|
|
|
// 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))?;
|
|
|
|
// Create window
|
|
let ui = MainWindow::new()?;
|
|
|
|
// Send the alarm data to the UI as properties
|
|
set_ui_props(&ui, &data);
|
|
|
|
// Run the UI
|
|
ui.run()?;
|
|
|
|
Ok(())
|
|
}
|