2023-02-25 14:30:45 +00:00
|
|
|
#[cfg(feature = "clipboard")]
|
|
|
|
pub mod clipboard;
|
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.
|
2023-02-01 20:42:05 +00:00
|
|
|
#[cfg(feature = "clock")]
|
2022-08-14 14:30:13 +01:00
|
|
|
pub mod clock;
|
2022-10-16 22:16:48 +01:00
|
|
|
pub mod custom;
|
2022-08-14 20:40:11 +01:00
|
|
|
pub mod focused;
|
2023-04-07 14:27:16 +01:00
|
|
|
pub mod label;
|
2022-08-14 14:30:13 +01:00
|
|
|
pub mod launcher;
|
2023-02-01 20:42:05 +00:00
|
|
|
#[cfg(feature = "music")]
|
2023-01-25 22:46:42 +00:00
|
|
|
pub mod music;
|
2022-08-14 14:30:13 +01:00
|
|
|
pub mod script;
|
2023-02-01 20:42:05 +00:00
|
|
|
#[cfg(feature = "sys_info")]
|
2022-08-14 14:30:13 +01:00
|
|
|
pub mod sysinfo;
|
2023-02-01 20:42:05 +00:00
|
|
|
#[cfg(feature = "tray")]
|
2022-08-14 14:30:13 +01:00
|
|
|
pub mod tray;
|
2023-02-01 20:42:05 +00:00
|
|
|
#[cfg(feature = "workspaces")]
|
2022-08-14 14:30:13 +01:00
|
|
|
pub mod workspaces;
|
|
|
|
|
2022-08-14 20:40:11 +01:00
|
|
|
use crate::config::BarPosition;
|
2023-04-09 22:42:35 +01:00
|
|
|
use crate::popup::WidgetGeometry;
|
2022-08-21 23:36:07 +01:00
|
|
|
use color_eyre::Result;
|
2022-08-14 14:30:13 +01:00
|
|
|
use glib::IsA;
|
2022-08-15 21:11:00 +01:00
|
|
|
use gtk::gdk::Monitor;
|
2023-01-29 18:38:57 +00:00
|
|
|
use gtk::{Application, IconTheme, 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,
|
|
|
|
}
|
|
|
|
pub struct ModuleInfo<'a> {
|
|
|
|
pub app: &'a Application,
|
|
|
|
pub location: ModuleLocation,
|
2022-10-15 16:27:25 +01:00
|
|
|
pub bar_position: 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,
|
2023-01-29 18:38:57 +00:00
|
|
|
pub icon_theme: &'a IconTheme,
|
2022-09-25 22:49:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum ModuleUpdateEvent<T> {
|
|
|
|
/// Sends an update to the module UI
|
|
|
|
Update(T),
|
|
|
|
/// Toggles the open state of the popup.
|
2023-04-09 22:42:35 +01:00
|
|
|
TogglePopup(WidgetGeometry),
|
2022-09-25 22:49:00 +01:00
|
|
|
/// Force sets the popup open.
|
|
|
|
/// Takes the button X position and width.
|
2023-04-09 22:42:35 +01:00
|
|
|
OpenPopup(WidgetGeometry),
|
2022-09-25 22:49:00 +01:00
|
|
|
/// 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;
|
|
|
|
|
2022-12-04 23:23:22 +00:00
|
|
|
fn name() -> &'static str;
|
|
|
|
|
2022-09-25 22:49:00 +01:00
|
|
|
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>,
|
2023-01-29 18:38:57 +00:00
|
|
|
_info: &ModuleInfo,
|
2022-09-25 22:49:00 +01:00
|
|
|
) -> Option<gtk::Box>
|
|
|
|
where
|
|
|
|
Self: Sized,
|
|
|
|
{
|
|
|
|
None
|
|
|
|
}
|
2022-08-14 14:30:13 +01:00
|
|
|
}
|