2023-04-21 23:51:29 +01:00
|
|
|
|
mod common;
|
2022-12-15 21:37:08 +00:00
|
|
|
|
mod r#impl;
|
2023-01-28 23:01:44 +00:00
|
|
|
|
mod truncate;
|
2022-12-15 21:37:08 +00:00
|
|
|
|
|
2023-02-25 14:30:45 +00:00
|
|
|
|
#[cfg(feature = "clipboard")]
|
|
|
|
|
use crate::modules::clipboard::ClipboardModule;
|
2023-02-01 20:42:05 +00:00
|
|
|
|
#[cfg(feature = "clock")]
|
2022-12-15 21:37:08 +00:00
|
|
|
|
use crate::modules::clock::ClockModule;
|
|
|
|
|
use crate::modules::custom::CustomModule;
|
2024-01-13 22:08:31 -03:00
|
|
|
|
#[cfg(feature = "focused")]
|
2022-12-15 21:37:08 +00:00
|
|
|
|
use crate::modules::focused::FocusedModule;
|
2023-04-07 14:27:16 +01:00
|
|
|
|
use crate::modules::label::LabelModule;
|
2024-01-13 22:08:31 -03:00
|
|
|
|
#[cfg(feature = "launcher")]
|
2022-12-15 21:37:08 +00:00
|
|
|
|
use crate::modules::launcher::LauncherModule;
|
2023-02-01 20:42:05 +00:00
|
|
|
|
#[cfg(feature = "music")]
|
2023-01-25 22:46:42 +00:00
|
|
|
|
use crate::modules::music::MusicModule;
|
2024-03-03 22:42:57 +00:00
|
|
|
|
#[cfg(feature = "notifications")]
|
|
|
|
|
use crate::modules::notifications::NotificationsModule;
|
2022-12-15 21:37:08 +00:00
|
|
|
|
use crate::modules::script::ScriptModule;
|
2023-02-01 20:42:05 +00:00
|
|
|
|
#[cfg(feature = "sys_info")]
|
2022-12-15 21:37:08 +00:00
|
|
|
|
use crate::modules::sysinfo::SysInfoModule;
|
2023-02-01 20:42:05 +00:00
|
|
|
|
#[cfg(feature = "tray")]
|
2022-12-15 21:37:08 +00:00
|
|
|
|
use crate::modules::tray::TrayModule;
|
2023-03-19 02:16:49 +05:30
|
|
|
|
#[cfg(feature = "upower")]
|
|
|
|
|
use crate::modules::upower::UpowerModule;
|
2023-04-01 13:07:47 +01:00
|
|
|
|
#[cfg(feature = "volume")]
|
|
|
|
|
use crate::modules::volume::VolumeModule;
|
2023-02-01 20:42:05 +00:00
|
|
|
|
#[cfg(feature = "workspaces")]
|
2022-12-15 21:37:08 +00:00
|
|
|
|
use crate::modules::workspaces::WorkspacesModule;
|
2024-03-14 22:35:33 +00:00
|
|
|
|
|
|
|
|
|
use crate::modules::{AnyModuleFactory, ModuleFactory, ModuleInfo};
|
2023-07-03 22:47:36 +01:00
|
|
|
|
use cfg_if::cfg_if;
|
2024-03-14 22:35:33 +00:00
|
|
|
|
use color_eyre::Result;
|
2022-12-15 21:37:08 +00:00
|
|
|
|
use serde::Deserialize;
|
|
|
|
|
use std::collections::HashMap;
|
|
|
|
|
|
2023-04-22 14:49:15 +01:00
|
|
|
|
pub use self::common::{CommonConfig, TransitionType};
|
2023-12-31 00:43:48 +00:00
|
|
|
|
pub use self::truncate::TruncateMode;
|
2023-01-28 23:01:44 +00:00
|
|
|
|
|
2022-12-15 21:37:08 +00:00
|
|
|
|
#[derive(Debug, Deserialize, Clone)]
|
|
|
|
|
#[serde(tag = "type", rename_all = "snake_case")]
|
|
|
|
|
pub enum ModuleConfig {
|
2023-06-30 23:00:52 +01:00
|
|
|
|
#[cfg(feature = "clipboard")]
|
2023-02-25 14:30:45 +00:00
|
|
|
|
Clipboard(Box<ClipboardModule>),
|
|
|
|
|
#[cfg(feature = "clock")]
|
|
|
|
|
Clock(Box<ClockModule>),
|
|
|
|
|
Custom(Box<CustomModule>),
|
2024-01-13 22:08:31 -03:00
|
|
|
|
#[cfg(feature = "focused")]
|
2023-02-25 14:30:45 +00:00
|
|
|
|
Focused(Box<FocusedModule>),
|
2023-04-07 14:27:16 +01:00
|
|
|
|
Label(Box<LabelModule>),
|
2024-01-13 22:08:31 -03:00
|
|
|
|
#[cfg(feature = "launcher")]
|
2023-02-25 14:30:45 +00:00
|
|
|
|
Launcher(Box<LauncherModule>),
|
2023-02-01 20:42:05 +00:00
|
|
|
|
#[cfg(feature = "music")]
|
2023-02-25 14:30:45 +00:00
|
|
|
|
Music(Box<MusicModule>),
|
2024-03-03 22:42:57 +00:00
|
|
|
|
#[cfg(feature = "notifications")]
|
|
|
|
|
Notifications(Box<NotificationsModule>),
|
2023-02-25 14:30:45 +00:00
|
|
|
|
Script(Box<ScriptModule>),
|
2023-02-01 20:42:05 +00:00
|
|
|
|
#[cfg(feature = "sys_info")]
|
2023-02-25 14:30:45 +00:00
|
|
|
|
SysInfo(Box<SysInfoModule>),
|
2023-02-01 20:42:05 +00:00
|
|
|
|
#[cfg(feature = "tray")]
|
2023-02-25 14:30:45 +00:00
|
|
|
|
Tray(Box<TrayModule>),
|
2023-03-19 02:16:49 +05:30
|
|
|
|
#[cfg(feature = "upower")]
|
|
|
|
|
Upower(Box<UpowerModule>),
|
2023-04-01 13:07:47 +01:00
|
|
|
|
#[cfg(feature = "volume")]
|
|
|
|
|
Volume(Box<VolumeModule>),
|
2023-02-01 20:42:05 +00:00
|
|
|
|
#[cfg(feature = "workspaces")]
|
2023-02-25 14:30:45 +00:00
|
|
|
|
Workspaces(Box<WorkspacesModule>),
|
2022-12-15 21:37:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-14 22:35:33 +00:00
|
|
|
|
impl ModuleConfig {
|
|
|
|
|
pub fn create(
|
|
|
|
|
self,
|
|
|
|
|
module_factory: &AnyModuleFactory,
|
|
|
|
|
container: >k::Box,
|
|
|
|
|
info: &ModuleInfo,
|
|
|
|
|
) -> Result<()> {
|
|
|
|
|
macro_rules! create {
|
|
|
|
|
($module:expr) => {
|
|
|
|
|
module_factory.create(*$module, container, info)
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
match self {
|
|
|
|
|
#[cfg(feature = "clipboard")]
|
|
|
|
|
Self::Clipboard(module) => create!(module),
|
|
|
|
|
#[cfg(feature = "clock")]
|
|
|
|
|
Self::Clock(module) => create!(module),
|
|
|
|
|
Self::Custom(module) => create!(module),
|
|
|
|
|
#[cfg(feature = "focused")]
|
|
|
|
|
Self::Focused(module) => create!(module),
|
|
|
|
|
Self::Label(module) => create!(module),
|
|
|
|
|
#[cfg(feature = "launcher")]
|
|
|
|
|
Self::Launcher(module) => create!(module),
|
|
|
|
|
#[cfg(feature = "music")]
|
|
|
|
|
Self::Music(module) => create!(module),
|
|
|
|
|
#[cfg(feature = "notifications")]
|
|
|
|
|
Self::Notifications(module) => create!(module),
|
|
|
|
|
Self::Script(module) => create!(module),
|
|
|
|
|
#[cfg(feature = "sys_info")]
|
|
|
|
|
Self::SysInfo(module) => create!(module),
|
|
|
|
|
#[cfg(feature = "tray")]
|
|
|
|
|
Self::Tray(module) => create!(module),
|
|
|
|
|
#[cfg(feature = "upower")]
|
|
|
|
|
Self::Upower(module) => create!(module),
|
|
|
|
|
#[cfg(feature = "volume")]
|
|
|
|
|
Self::Volume(module) => create!(module),
|
|
|
|
|
#[cfg(feature = "workspaces")]
|
|
|
|
|
Self::Workspaces(module) => create!(module),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-29 21:48:44 +00:00
|
|
|
|
#[derive(Debug, Deserialize, Clone)]
|
|
|
|
|
pub enum BarEntryConfig {
|
|
|
|
|
Single(BarConfig),
|
|
|
|
|
Monitors(HashMap<String, MonitorConfig>),
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-15 21:37:08 +00:00
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
|
pub enum MonitorConfig {
|
2024-03-29 21:48:44 +00:00
|
|
|
|
Single(BarConfig),
|
|
|
|
|
Multiple(Vec<BarConfig>),
|
2022-12-15 21:37:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Deserialize, Copy, Clone, PartialEq, Eq)]
|
|
|
|
|
#[serde(rename_all = "snake_case")]
|
|
|
|
|
pub enum BarPosition {
|
|
|
|
|
Top,
|
|
|
|
|
Bottom,
|
|
|
|
|
Left,
|
|
|
|
|
Right,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Default for BarPosition {
|
|
|
|
|
fn default() -> Self {
|
|
|
|
|
Self::Bottom
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-25 14:24:21 +00:00
|
|
|
|
#[derive(Debug, Default, Deserialize, Copy, Clone, PartialEq, Eq)]
|
2023-02-08 11:40:33 +00:00
|
|
|
|
pub struct MarginConfig {
|
|
|
|
|
#[serde(default)]
|
|
|
|
|
pub bottom: i32,
|
|
|
|
|
#[serde(default)]
|
|
|
|
|
pub left: i32,
|
|
|
|
|
#[serde(default)]
|
|
|
|
|
pub right: i32,
|
|
|
|
|
#[serde(default)]
|
|
|
|
|
pub top: i32,
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-15 21:37:08 +00:00
|
|
|
|
#[derive(Debug, Deserialize, Clone)]
|
2024-03-29 21:48:44 +00:00
|
|
|
|
pub struct BarConfig {
|
2023-02-08 11:40:33 +00:00
|
|
|
|
#[serde(default)]
|
2022-12-15 21:37:08 +00:00
|
|
|
|
pub position: BarPosition,
|
|
|
|
|
#[serde(default = "default_true")]
|
|
|
|
|
pub anchor_to_edges: bool,
|
|
|
|
|
#[serde(default = "default_bar_height")]
|
|
|
|
|
pub height: i32,
|
2023-02-08 11:40:33 +00:00
|
|
|
|
#[serde(default)]
|
|
|
|
|
pub margin: MarginConfig,
|
2023-07-12 18:17:04 -04:00
|
|
|
|
pub name: Option<String>,
|
2022-12-15 21:37:08 +00:00
|
|
|
|
|
2023-12-10 22:56:43 +00:00
|
|
|
|
#[serde(default)]
|
|
|
|
|
pub start_hidden: Option<bool>,
|
|
|
|
|
#[serde(default)]
|
|
|
|
|
pub autohide: Option<u64>,
|
|
|
|
|
|
2023-01-29 18:38:57 +00:00
|
|
|
|
/// GTK icon theme to use.
|
|
|
|
|
pub icon_theme: Option<String>,
|
|
|
|
|
|
2022-12-15 21:37:08 +00:00
|
|
|
|
pub start: Option<Vec<ModuleConfig>>,
|
|
|
|
|
pub center: Option<Vec<ModuleConfig>>,
|
|
|
|
|
pub end: Option<Vec<ModuleConfig>>,
|
|
|
|
|
|
2024-03-29 21:48:44 +00:00
|
|
|
|
#[serde(default = "default_popup_gap")]
|
|
|
|
|
pub popup_gap: i32,
|
2022-12-15 21:37:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-29 21:48:44 +00:00
|
|
|
|
impl Default for BarConfig {
|
2023-07-03 22:47:36 +01:00
|
|
|
|
fn default() -> Self {
|
|
|
|
|
cfg_if! {
|
|
|
|
|
if #[cfg(feature = "clock")] {
|
|
|
|
|
let end = Some(vec![ModuleConfig::Clock(Box::default())]);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
let end = None;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-13 22:08:31 -03:00
|
|
|
|
cfg_if! {
|
|
|
|
|
if #[cfg(feature = "focused")] {
|
|
|
|
|
let center = Some(vec![ModuleConfig::Focused(Box::default())]);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
let center = None;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-03 22:47:36 +01:00
|
|
|
|
Self {
|
2023-07-16 20:09:22 +01:00
|
|
|
|
position: BarPosition::default(),
|
2023-07-03 22:47:36 +01:00
|
|
|
|
height: default_bar_height(),
|
2023-07-16 20:09:22 +01:00
|
|
|
|
margin: MarginConfig::default(),
|
2023-07-12 18:17:04 -04:00
|
|
|
|
name: None,
|
2023-12-10 22:56:43 +00:00
|
|
|
|
start_hidden: None,
|
|
|
|
|
autohide: None,
|
2023-07-03 22:47:36 +01:00
|
|
|
|
icon_theme: None,
|
|
|
|
|
start: Some(vec![ModuleConfig::Label(
|
|
|
|
|
LabelModule::new("ℹ️ Using default config".to_string()).into(),
|
|
|
|
|
)]),
|
2024-01-13 22:08:31 -03:00
|
|
|
|
center,
|
2023-07-03 22:47:36 +01:00
|
|
|
|
end,
|
|
|
|
|
anchor_to_edges: default_true(),
|
2024-03-29 21:48:44 +00:00
|
|
|
|
popup_gap: default_popup_gap(),
|
2023-07-03 22:47:36 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-29 21:48:44 +00:00
|
|
|
|
#[derive(Debug, Deserialize, Clone, Default)]
|
|
|
|
|
pub struct Config {
|
|
|
|
|
pub ironvar_defaults: Option<HashMap<Box<str>, String>>,
|
|
|
|
|
|
|
|
|
|
#[serde(flatten)]
|
|
|
|
|
pub bar: BarConfig,
|
|
|
|
|
pub monitors: Option<HashMap<String, MonitorConfig>>,
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-15 21:37:08 +00:00
|
|
|
|
const fn default_bar_height() -> i32 {
|
|
|
|
|
42
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-07 14:36:12 +01:00
|
|
|
|
const fn default_popup_gap() -> i32 {
|
|
|
|
|
5
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-15 21:37:08 +00:00
|
|
|
|
pub const fn default_false() -> bool {
|
|
|
|
|
false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub const fn default_true() -> bool {
|
|
|
|
|
true
|
|
|
|
|
}
|