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
|
|
|
|
|
2024-03-10 12:51:23 +00:00
|
|
|
|
#[cfg(feature = "cairo")]
|
|
|
|
|
use crate::modules::cairo::CairoModule;
|
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;
|
|
|
|
|
|
2024-04-02 23:04:48 -04:00
|
|
|
|
pub use self::common::{CommonConfig, ModuleOrientation, 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 {
|
2024-03-10 12:51:23 +00:00
|
|
|
|
#[cfg(feature = "cairo")]
|
|
|
|
|
Cairo(Box<CairoModule>),
|
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 {
|
2024-03-10 12:51:23 +00:00
|
|
|
|
#[cfg(feature = "cairo")]
|
|
|
|
|
Self::Cairo(module) => create!(module),
|
2024-03-14 22:35:33 +00:00
|
|
|
|
#[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),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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,
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-19 15:16:01 +01:00
|
|
|
|
/// The following is a list of all top-level bar config options.
|
|
|
|
|
///
|
|
|
|
|
/// These options can either be written at the very top object of your config,
|
|
|
|
|
/// or within an object in the [monitors](#monitors) config,
|
|
|
|
|
/// depending on your [use-case](#2-pick-your-use-case).
|
|
|
|
|
///
|
2022-12-15 21:37:08 +00:00
|
|
|
|
#[derive(Debug, Deserialize, Clone)]
|
2024-03-29 21:48:44 +00:00
|
|
|
|
pub struct BarConfig {
|
2024-05-19 15:16:01 +01:00
|
|
|
|
/// A unique identifier for the bar, used for controlling it over IPC.
|
|
|
|
|
/// If not set, uses a generated integer suffix.
|
|
|
|
|
///
|
|
|
|
|
/// **Default**: `bar-n`
|
|
|
|
|
pub name: Option<String>,
|
|
|
|
|
|
|
|
|
|
/// The bar's position on screen.
|
|
|
|
|
///
|
|
|
|
|
/// **Valid options**: `top`, `bottom`, `left`, `right`
|
|
|
|
|
/// <br>
|
|
|
|
|
/// **Default**: `bottom`
|
2023-02-08 11:40:33 +00:00
|
|
|
|
#[serde(default)]
|
2022-12-15 21:37:08 +00:00
|
|
|
|
pub position: BarPosition,
|
2024-05-19 15:16:01 +01:00
|
|
|
|
|
|
|
|
|
/// Whether to anchor the bar to the edges of the screen.
|
|
|
|
|
/// Setting to false centers the bar.
|
|
|
|
|
///
|
|
|
|
|
/// **Default**: `true`
|
2022-12-15 21:37:08 +00:00
|
|
|
|
#[serde(default = "default_true")]
|
|
|
|
|
pub anchor_to_edges: bool,
|
2024-05-19 15:16:01 +01:00
|
|
|
|
|
|
|
|
|
/// The bar's height in pixels.
|
|
|
|
|
///
|
|
|
|
|
/// Note that GTK treats this as a target minimum,
|
|
|
|
|
/// and if content inside the bar is over this,
|
|
|
|
|
/// it will automatically expand to fit.
|
|
|
|
|
///
|
|
|
|
|
/// **Default**: `42`
|
2022-12-15 21:37:08 +00:00
|
|
|
|
#[serde(default = "default_bar_height")]
|
|
|
|
|
pub height: i32,
|
2024-05-19 15:16:01 +01:00
|
|
|
|
|
|
|
|
|
/// The margin to use on each side of the bar, in pixels.
|
|
|
|
|
/// Object which takes `top`, `bottom`, `left` and `right` keys.
|
|
|
|
|
///
|
|
|
|
|
/// **Default**: `0` on all sides.
|
|
|
|
|
///
|
|
|
|
|
/// # Example
|
|
|
|
|
///
|
|
|
|
|
/// The following would set a 10px margin around each edge.
|
|
|
|
|
///
|
|
|
|
|
/// ```corn
|
|
|
|
|
/// {
|
|
|
|
|
/// margin.top = 10
|
|
|
|
|
/// margin.bottom = 10
|
|
|
|
|
/// margin.left = 10
|
|
|
|
|
/// margin.right = 10
|
|
|
|
|
/// }
|
|
|
|
|
/// ```
|
2023-02-08 11:40:33 +00:00
|
|
|
|
#[serde(default)]
|
|
|
|
|
pub margin: MarginConfig,
|
2022-12-15 21:37:08 +00:00
|
|
|
|
|
2024-05-19 15:16:01 +01:00
|
|
|
|
/// The size of the gap in pixels
|
|
|
|
|
/// between the bar and the popup window.
|
|
|
|
|
///
|
|
|
|
|
/// **Default**: `5`
|
|
|
|
|
#[serde(default = "default_popup_gap")]
|
|
|
|
|
pub popup_gap: i32,
|
|
|
|
|
|
|
|
|
|
/// Whether the bar should be hidden when Ironbar starts.
|
|
|
|
|
///
|
|
|
|
|
/// **Default**: `false`, unless `autohide` is set.
|
2023-12-10 22:56:43 +00:00
|
|
|
|
#[serde(default)]
|
|
|
|
|
pub start_hidden: Option<bool>,
|
2024-05-19 15:16:01 +01:00
|
|
|
|
|
|
|
|
|
/// The duration in milliseconds before the bar is hidden after the cursor leaves.
|
|
|
|
|
/// Leave unset to disable auto-hide behaviour.
|
|
|
|
|
///
|
|
|
|
|
/// **Default**: `null`
|
2023-12-10 22:56:43 +00:00
|
|
|
|
#[serde(default)]
|
|
|
|
|
pub autohide: Option<u64>,
|
|
|
|
|
|
2024-05-19 15:16:01 +01:00
|
|
|
|
/// The name of the GTK icon theme to use.
|
|
|
|
|
/// Leave unset to use the default Adwaita theme.
|
|
|
|
|
///
|
|
|
|
|
/// **Default**: `null`
|
2023-01-29 18:38:57 +00:00
|
|
|
|
pub icon_theme: Option<String>,
|
|
|
|
|
|
2024-05-19 15:16:01 +01:00
|
|
|
|
/// An array of modules to append to the start of the bar.
|
|
|
|
|
/// Depending on the orientation, this is either the top of the left edge.
|
|
|
|
|
///
|
|
|
|
|
/// **Default**: `[]`
|
2022-12-15 21:37:08 +00:00
|
|
|
|
pub start: Option<Vec<ModuleConfig>>,
|
2024-05-19 15:16:01 +01:00
|
|
|
|
|
|
|
|
|
/// An array of modules to append to the center of the bar.
|
|
|
|
|
///
|
|
|
|
|
/// **Default**: `[]`
|
2022-12-15 21:37:08 +00:00
|
|
|
|
pub center: Option<Vec<ModuleConfig>>,
|
|
|
|
|
|
2024-05-19 15:16:01 +01:00
|
|
|
|
/// An array of modules to append to the end of the bar.
|
|
|
|
|
/// Depending on the orientation, this is either the bottom or right edge.
|
|
|
|
|
///
|
|
|
|
|
/// **Default**: `[]`
|
|
|
|
|
pub end: Option<Vec<ModuleConfig>>,
|
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 {
|
2024-05-19 15:16:01 +01:00
|
|
|
|
/// A map of [ironvar](ironvar) keys and values
|
|
|
|
|
/// to initialize Ironbar with on startup.
|
|
|
|
|
///
|
|
|
|
|
/// **Default**: `{}`
|
|
|
|
|
///
|
|
|
|
|
/// # Example
|
|
|
|
|
///
|
|
|
|
|
/// The following initializes an ironvar called `foo` set to `bar` on startup:
|
|
|
|
|
///
|
|
|
|
|
/// ```corn
|
|
|
|
|
/// { ironvar_defaults.foo = "bar" }
|
|
|
|
|
/// ```
|
|
|
|
|
///
|
|
|
|
|
/// The variable can then be immediately fetched without needing to be manually set:
|
|
|
|
|
///
|
|
|
|
|
/// ```sh
|
|
|
|
|
/// $ ironbar get foo
|
|
|
|
|
/// ok
|
|
|
|
|
/// bar
|
|
|
|
|
/// ```
|
2024-03-29 21:48:44 +00:00
|
|
|
|
pub ironvar_defaults: Option<HashMap<Box<str>, String>>,
|
|
|
|
|
|
2024-05-19 15:16:01 +01:00
|
|
|
|
/// The configuration for the bar.
|
|
|
|
|
/// Setting through this will enable a single identical bar on each monitor.
|
2024-03-29 21:48:44 +00:00
|
|
|
|
#[serde(flatten)]
|
|
|
|
|
pub bar: BarConfig,
|
2024-05-19 15:16:01 +01:00
|
|
|
|
|
|
|
|
|
/// A map of monitor names to configs.
|
|
|
|
|
///
|
|
|
|
|
/// The config values can be either:
|
|
|
|
|
///
|
|
|
|
|
/// - a single object, which denotes a single bar for that monitor,
|
|
|
|
|
/// - an array of multiple objects, which denotes multiple for that monitor.
|
|
|
|
|
///
|
|
|
|
|
/// Providing this option overrides the single, global `bar` option.
|
2024-03-29 21:48:44 +00:00
|
|
|
|
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
|
|
|
|
|
}
|