/// Displays the current date and time. /// /// A custom date/time format string can be set in the config. /// /// Clicking the widget opens a popup containing the current time /// with second-level precision and a calendar. #[cfg(feature = "clock")] pub mod clock; pub mod custom; pub mod focused; pub mod launcher; #[cfg(feature = "music")] pub mod music; pub mod script; #[cfg(feature = "sys_info")] pub mod sysinfo; #[cfg(feature = "tray")] pub mod tray; #[cfg(feature = "workspaces")] pub mod workspaces; use crate::config::BarPosition; use crate::popup::ButtonGeometry; use color_eyre::Result; use glib::IsA; use gtk::gdk::Monitor; use gtk::{Application, IconTheme, Widget}; use tokio::sync::mpsc; #[derive(Clone)] pub enum ModuleLocation { Left, Center, Right, } pub struct ModuleInfo<'a> { pub app: &'a Application, pub location: ModuleLocation, pub bar_position: BarPosition, pub monitor: &'a Monitor, pub output_name: &'a str, pub icon_theme: &'a IconTheme, } #[derive(Debug)] pub enum ModuleUpdateEvent { /// Sends an update to the module UI Update(T), /// Toggles the open state of the popup. TogglePopup(ButtonGeometry), /// Force sets the popup open. /// Takes the button X position and width. OpenPopup(ButtonGeometry), /// Force sets the popup closed. ClosePopup, } pub struct WidgetContext { pub id: usize, pub tx: mpsc::Sender>, pub controller_tx: mpsc::Sender, pub widget_rx: glib::Receiver, pub popup_rx: glib::Receiver, } pub struct ModuleWidget> { pub widget: W, pub popup: Option, } pub trait Module where W: IsA, { type SendMessage; type ReceiveMessage; fn name() -> &'static str; fn spawn_controller( &self, info: &ModuleInfo, tx: mpsc::Sender>, rx: mpsc::Receiver, ) -> Result<()>; fn into_widget( self, context: WidgetContext, info: &ModuleInfo, ) -> Result>; fn into_popup( self, _tx: mpsc::Sender, _rx: glib::Receiver, _info: &ModuleInfo, ) -> Option where Self: Sized, { None } }