From 7cb750cfa7068035c22d033a410f1e088ac818b0 Mon Sep 17 00:00:00 2001 From: candifloss Date: Sat, 28 Feb 2026 12:21:23 +0530 Subject: [PATCH] Basic popup code --- alarm_widg/build.rs | 3 ++ alarm_widg/src/main.rs | 7 +++-- alarm_widg/src/show_popup.rs | 58 ++++++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 alarm_widg/build.rs create mode 100644 alarm_widg/src/show_popup.rs diff --git a/alarm_widg/build.rs b/alarm_widg/build.rs new file mode 100644 index 0000000..cc515dc --- /dev/null +++ b/alarm_widg/build.rs @@ -0,0 +1,3 @@ +fn main() { + slint_build::compile("ui/widget-popup.slint").unwrap(); +} diff --git a/alarm_widg/src/main.rs b/alarm_widg/src/main.rs index e7a11a9..22e945a 100644 --- a/alarm_widg/src/main.rs +++ b/alarm_widg/src/main.rs @@ -1,3 +1,6 @@ -fn main() { - println!("Hello, world!"); +mod show_popup; + +fn main() -> Result<(), Box> { + show_popup::show_popup()?; + Ok(()) } diff --git a/alarm_widg/src/show_popup.rs b/alarm_widg/src/show_popup.rs new file mode 100644 index 0000000..71fd3e2 --- /dev/null +++ b/alarm_widg/src/show_popup.rs @@ -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> { + // 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(()) +}