2022-08-14 14:30:13 +01:00
|
|
|
/// 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.
|
|
|
|
pub mod clock;
|
2022-08-14 20:40:11 +01:00
|
|
|
pub mod focused;
|
2022-08-14 14:30:13 +01:00
|
|
|
pub mod launcher;
|
|
|
|
pub mod mpd;
|
|
|
|
pub mod script;
|
|
|
|
pub mod sysinfo;
|
|
|
|
pub mod tray;
|
|
|
|
pub mod workspaces;
|
|
|
|
|
2022-08-14 20:40:11 +01:00
|
|
|
use crate::config::BarPosition;
|
2022-08-21 23:36:07 +01:00
|
|
|
use color_eyre::Result;
|
2022-09-25 22:49:00 +01:00
|
|
|
use derive_builder::Builder;
|
2022-08-14 14:30:13 +01:00
|
|
|
use glib::IsA;
|
2022-08-15 21:11:00 +01:00
|
|
|
use gtk::gdk::Monitor;
|
2022-08-14 14:30:13 +01:00
|
|
|
use gtk::{Application, Widget};
|
2022-09-25 22:49:00 +01:00
|
|
|
use tokio::sync::mpsc;
|
2022-08-14 14:30:13 +01:00
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
pub enum ModuleLocation {
|
|
|
|
Left,
|
|
|
|
Center,
|
|
|
|
Right,
|
|
|
|
}
|
|
|
|
|
2022-09-25 22:49:00 +01:00
|
|
|
#[derive(Builder)]
|
2022-08-14 14:30:13 +01:00
|
|
|
pub struct ModuleInfo<'a> {
|
|
|
|
pub app: &'a Application,
|
|
|
|
pub location: ModuleLocation,
|
2022-08-14 16:23:41 +01:00
|
|
|
pub bar_position: &'a BarPosition,
|
2022-08-15 21:11:00 +01:00
|
|
|
pub monitor: &'a Monitor,
|
2022-08-14 20:40:11 +01:00
|
|
|
pub output_name: &'a str,
|
2022-09-25 22:49:00 +01:00
|
|
|
pub module_name: &'a str,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum ModuleUpdateEvent<T> {
|
|
|
|
/// Sends an update to the module UI
|
|
|
|
Update(T),
|
|
|
|
/// Toggles the open state of the popup.
|
|
|
|
/// Takes the button X position and width.
|
|
|
|
TogglePopup((i32, i32)),
|
|
|
|
/// Force sets the popup open.
|
|
|
|
/// Takes the button X position and width.
|
|
|
|
OpenPopup((i32, i32)),
|
|
|
|
/// Force sets the popup closed.
|
|
|
|
ClosePopup,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct WidgetContext<TSend, TReceive> {
|
|
|
|
pub id: usize,
|
|
|
|
pub tx: mpsc::Sender<ModuleUpdateEvent<TSend>>,
|
|
|
|
pub controller_tx: mpsc::Sender<TReceive>,
|
|
|
|
pub widget_rx: glib::Receiver<TSend>,
|
|
|
|
pub popup_rx: glib::Receiver<TSend>,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct ModuleWidget<W: IsA<Widget>> {
|
|
|
|
pub widget: W,
|
|
|
|
pub popup: Option<gtk::Box>,
|
2022-08-14 14:30:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
pub trait Module<W>
|
|
|
|
where
|
|
|
|
W: IsA<Widget>,
|
|
|
|
{
|
2022-09-25 22:49:00 +01:00
|
|
|
type SendMessage;
|
|
|
|
type ReceiveMessage;
|
|
|
|
|
|
|
|
fn spawn_controller(
|
|
|
|
&self,
|
|
|
|
info: &ModuleInfo,
|
|
|
|
tx: mpsc::Sender<ModuleUpdateEvent<Self::SendMessage>>,
|
|
|
|
rx: mpsc::Receiver<Self::ReceiveMessage>,
|
|
|
|
) -> Result<()>;
|
|
|
|
|
|
|
|
fn into_widget(
|
|
|
|
self,
|
|
|
|
context: WidgetContext<Self::SendMessage, Self::ReceiveMessage>,
|
|
|
|
info: &ModuleInfo,
|
|
|
|
) -> Result<ModuleWidget<W>>;
|
|
|
|
|
|
|
|
fn into_popup(
|
|
|
|
self,
|
|
|
|
_tx: mpsc::Sender<Self::ReceiveMessage>,
|
|
|
|
_rx: glib::Receiver<Self::SendMessage>,
|
|
|
|
) -> Option<gtk::Box>
|
|
|
|
where
|
|
|
|
Self: Sized,
|
|
|
|
{
|
|
|
|
None
|
|
|
|
}
|
2022-08-14 14:30:13 +01:00
|
|
|
}
|