Basic popup code

This commit is contained in:
Candifloss 2026-02-28 12:21:23 +05:30
parent 72eeef781f
commit 7cb750cfa7
3 changed files with 66 additions and 2 deletions

3
alarm_widg/build.rs Normal file
View File

@ -0,0 +1,3 @@
fn main() {
slint_build::compile("ui/widget-popup.slint").unwrap();
}

View File

@ -1,3 +1,6 @@
fn main() {
println!("Hello, world!");
mod show_popup;
fn main() -> Result<(), Box<dyn std::error::Error>> {
show_popup::show_popup()?;
Ok(())
}

View File

@ -0,0 +1,58 @@
use slint::{Color, LogicalPosition, LogicalSize, SharedString};
use i_slint_backend_winit::{
Backend,
winit::{
platform::x11::{WindowAttributesExtX11, WindowType},
window::WindowAttributes,
},
};
slint::include_modules!();
fn set_ui_props(ui: &MainWindow) {
// Window placement
ui.window().set_position(LogicalPosition::new(200.0, 35.0));
// Window size
ui.window().set_size(LogicalSize::new(300.0, 124.0));
// Alarm properties
ui.set_alarm_name(SharedString::from("Sample alarm"));
ui.set_alarm_time(SharedString::from("11:45AM"));
ui.set_alarm_color(Color::from_argb_encoded(0xff232323));
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() -> 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);
// Run the UI
ui.run()?;
Ok(())
}