1
0
Fork 0
mirror of https://github.com/Zedfrigg/ironbar.git synced 2025-04-20 11:54:23 +02:00
ironbar/src/modules/mod.rs

107 lines
2.4 KiB
Rust
Raw Normal View History

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.
#[cfg(feature = "clock")]
2022-08-14 14:30:13 +01:00
pub mod clock;
pub mod custom;
2022-08-14 20:40:11 +01:00
pub mod focused;
2022-08-14 14:30:13 +01:00
pub mod launcher;
#[cfg(feature = "music")]
pub mod music;
2022-08-14 14:30:13 +01:00
pub mod script;
#[cfg(feature = "sys_info")]
2022-08-14 14:30:13 +01:00
pub mod sysinfo;
#[cfg(feature = "tray")]
2022-08-14 14:30:13 +01:00
pub mod tray;
#[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;
use crate::popup::ButtonGeometry;
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;
use gtk::{Application, IconTheme, Widget};
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,
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,
pub icon_theme: &'a IconTheme,
}
#[derive(Debug)]
pub enum ModuleUpdateEvent<T> {
/// 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<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>,
{
type SendMessage;
type ReceiveMessage;
fn name() -> &'static str;
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>,
_info: &ModuleInfo,
) -> Option<gtk::Box>
where
Self: Sized,
{
None
}
2022-08-14 14:30:13 +01:00
}