mirror of
https://github.com/Zedfrigg/ironbar.git
synced 2025-04-19 19:34:24 +02:00
Merge pull request #517 from JakeStanger/refactor/config
refactor: split bar/top-level config structs
This commit is contained in:
commit
bfdd62a321
5 changed files with 81 additions and 56 deletions
|
@ -271,27 +271,43 @@ Check [here](config) for an example config file for a fully configured bar in ea
|
||||||
|
|
||||||
The following table lists each of the top-level bar config options:
|
The following table lists each of the top-level bar config options:
|
||||||
|
|
||||||
| Name | Type | Default | Description |
|
| Name | Type | Default | Description |
|
||||||
|--------------------|----------------------------------------|--------------------------------------|----------------------------------------------------------------------------------------------------------------------------|
|
|--------------------|-----------------------------------------|---------|---------------------------------------------------------------|
|
||||||
| `name` | `string` | `bar-<n>` | A unique identifier for the bar, used for controlling it over IPC. If not set, uses a generated integer suffix. |
|
| `ironvar_defaults` | `Map<string, string>` | `{}` | Map of [ironvar](ironvars) keys against their default values. |
|
||||||
| `position` | `top` or `bottom` or `left` or `right` | `bottom` | The bar's position on screen. |
|
| `monitors` | `Map<string, BarConfig or BarConfig[]>` | `null` | Map of monitor names against bar configs. |
|
||||||
| `anchor_to_edges` | `boolean` | `false` | Whether to anchor the bar to the edges of the screen. Setting to false centres the bar. |
|
|
||||||
| `height` | `integer` | `42` | The bar's height in pixels. |
|
> [!TIP]
|
||||||
| `popup_gap` | `integer` | `5` | The gap between the bar and popup window. |
|
> `monitors` is only required if you are following **2b** or **2c** (ie not the same bar across all monitors).
|
||||||
| `margin.top` | `integer` | `0` | The margin on the top of the bar |
|
|
||||||
| `margin.bottom` | `integer` | `0` | The margin on the bottom of the bar |
|
> [!Note]
|
||||||
| `margin.left` | `integer` | `0` | The margin on the left of the bar |
|
> All bar-level options listed in the below section can also be defined at the top-level.
|
||||||
| `margin.right` | `integer` | `0` | The margin on the right of the bar |
|
|
||||||
| `icon_theme` | `string` | `null` | Name of the GTK icon theme to use. Leave blank to use default. |
|
# 3.2 Bar-level options
|
||||||
| `ironvar_defaults` | `Map<string, string>` | `{}` | Map of [ironvar](ironvars) keys against their default values. |
|
|
||||||
| `start_hidden` | `boolean` | `false`, or `true` if `autohide` set | Whether the bar should be hidden when the application starts. Enabled by default when `autohide` is set. |
|
The following table lists each of the bar-level bar config options:
|
||||||
| `autohide` | `integer` | `null` | The duration in milliseconds before the bar is hidden after the cursor leaves. Leave unset to disable auto-hide behaviour. |
|
|
||||||
| `start` | `Module[]` | `[]` | Array of left or top modules. |
|
| Name | Type | Default | Description |
|
||||||
| `center` | `Module[]` | `[]` | Array of center modules. |
|
|-------------------|----------------------------------------|--------------------------------------|----------------------------------------------------------------------------------------------------------------------------|
|
||||||
| `end` | `Module[]` | `[]` | Array of right or bottom modules. |
|
| `name` | `string` | `bar-<n>` | A unique identifier for the bar, used for controlling it over IPC. If not set, uses a generated integer suffix. |
|
||||||
|
| `position` | `top` or `bottom` or `left` or `right` | `bottom` | The bar's position on screen. |
|
||||||
|
| `anchor_to_edges` | `boolean` | `false` | Whether to anchor the bar to the edges of the screen. Setting to false centres the bar. |
|
||||||
|
| `height` | `integer` | `42` | The bar's height in pixels. |
|
||||||
|
| `popup_gap` | `integer` | `5` | The gap between the bar and popup window. |
|
||||||
|
| `margin.top` | `integer` | `0` | The margin on the top of the bar |
|
||||||
|
| `margin.bottom` | `integer` | `0` | The margin on the bottom of the bar |
|
||||||
|
| `margin.left` | `integer` | `0` | The margin on the left of the bar |
|
||||||
|
| `margin.right` | `integer` | `0` | The margin on the right of the bar |
|
||||||
|
| `icon_theme` | `string` | `null` | Name of the GTK icon theme to use. Leave blank to use default. |
|
||||||
|
| `start_hidden` | `boolean` | `false`, or `true` if `autohide` set | Whether the bar should be hidden when the application starts. Enabled by default when `autohide` is set. |
|
||||||
|
| `autohide` | `integer` | `null` | The duration in milliseconds before the bar is hidden after the cursor leaves. Leave unset to disable auto-hide behaviour. |
|
||||||
|
| `start` | `Module[]` | `[]` | Array of left or top modules. |
|
||||||
|
| `center` | `Module[]` | `[]` | Array of center modules. |
|
||||||
|
| `end` | `Module[]` | `[]` | Array of right or bottom modules. |
|
||||||
|
|
||||||
### 3.2 Module-level options
|
### 3.2 Module-level options
|
||||||
|
|
||||||
|
Each module must include a `type` key.
|
||||||
|
|
||||||
The following table lists each of the module-level options that are present on **all** modules.
|
The following table lists each of the module-level options that are present on **all** modules.
|
||||||
For details on available modules and each of their config options, check the sidebar.
|
For details on available modules and each of their config options, check the sidebar.
|
||||||
|
|
||||||
|
@ -299,19 +315,18 @@ For information on the `Script` type, and embedding scripts in strings, see [her
|
||||||
|
|
||||||
#### Events
|
#### Events
|
||||||
|
|
||||||
| Name | Type | Default | Description |
|
| Name | Type | Default | Description |
|
||||||
|-------------------|--------------------|---------|--------------------------------------------------------------------------------------------------------------------|
|
|-------------------|--------------------|---------|------------------------------------------------------------|
|
||||||
| `on_click_left` | `Script [oneshot]` | `null` | Runs the script when the module is left clicked. |
|
| `on_click_left` | `Script [oneshot]` | `null` | Runs the script when the module is left clicked. |
|
||||||
| `on_click_middle` | `Script [oneshot]` | `null` | Runs the script when the module is middle clicked. |
|
| `on_click_middle` | `Script [oneshot]` | `null` | Runs the script when the module is middle clicked. |
|
||||||
| `on_click_right` | `Script [oneshot]` | `null` | Runs the script when the module is right clicked. |
|
| `on_click_right` | `Script [oneshot]` | `null` | Runs the script when the module is right clicked. |
|
||||||
| `on_scroll_up` | `Script [oneshot]` | `null` | Runs the script when the module is scroll up on. |
|
| `on_scroll_up` | `Script [oneshot]` | `null` | Runs the script when the module is scroll up on. |
|
||||||
| `on_scroll_down` | `Script [oneshot]` | `null` | Runs the script when the module is scrolled down on. |
|
| `on_scroll_down` | `Script [oneshot]` | `null` | Runs the script when the module is scrolled down on. |
|
||||||
| `on_mouse_enter` | `Script [oneshot]` | `null` | Runs the script when the module is hovered over. |
|
| `on_mouse_enter` | `Script [oneshot]` | `null` | Runs the script when the module is hovered over. |
|
||||||
| `on_mouse_exit` | `Script [oneshot]` | `null` | Runs the script when the module is no longer hovered over. |
|
| `on_mouse_exit` | `Script [oneshot]` | `null` | Runs the script when the module is no longer hovered over. |
|
||||||
|
|
||||||
#### Visibility
|
#### Visibility
|
||||||
|
|
||||||
|
|
||||||
| Name | Type | Default | Description |
|
| Name | Type | Default | Description |
|
||||||
|-----------------------|-------------------------------------------------------|---------------|--------------------------------------------------------------------------------------------------------------------|
|
|-----------------------|-------------------------------------------------------|---------------|--------------------------------------------------------------------------------------------------------------------|
|
||||||
| `show_if` | [Dynamic Boolean](dynamic-values#dynamic-boolean) | `null` | Polls the script to check its exit code. If exit code is zero, the module is shown. For other codes, it is hidden. |
|
| `show_if` | [Dynamic Boolean](dynamic-values#dynamic-boolean) | `null` | Polls the script to check its exit code. If exit code is zero, the module is shown. For other codes, it is hidden. |
|
||||||
|
@ -320,10 +335,10 @@ For information on the `Script` type, and embedding scripts in strings, see [her
|
||||||
|
|
||||||
#### Appearance
|
#### Appearance
|
||||||
|
|
||||||
| Name | Type | Default | Description |
|
| Name | Type | Default | Description |
|
||||||
|-----------|--------------------|---------|-----------------------------------------------------------------------------------|
|
|-----------|----------|---------|-----------------------------------------------------------------------------------|
|
||||||
| `tooltip` | `string` | `null` | Shows this text on hover. Supports embedding scripts between `{{double braces}}`. |
|
| `tooltip` | `string` | `null` | Shows this text on hover. Supports embedding scripts between `{{double braces}}`. |
|
||||||
| `name` | `string` | `null` | Sets the unique widget name, allowing you to style it using `#name`. |
|
| `name` | `string` | `null` | Sets the unique widget name, allowing you to style it using `#name`. |
|
||||||
| `class` | `string` | `null` | Sets one or more CSS classes, allowing you to style it using `.class`. |
|
| `class` | `string` | `null` | Sets one or more CSS classes, allowing you to style it using `.class`. |
|
||||||
|
|
||||||
For more information on styling, please see the [styling guide](styling-guide).
|
For more information on styling, please see the [styling guide](styling-guide).
|
12
src/bar.rs
12
src/bar.rs
|
@ -1,9 +1,9 @@
|
||||||
use crate::config::{BarPosition, MarginConfig, ModuleConfig};
|
use crate::config::{BarConfig, BarPosition, MarginConfig, ModuleConfig};
|
||||||
use crate::modules::{
|
use crate::modules::{
|
||||||
create_module, set_widget_identifiers, wrap_widget, ModuleInfo, ModuleLocation,
|
create_module, set_widget_identifiers, wrap_widget, ModuleInfo, ModuleLocation,
|
||||||
};
|
};
|
||||||
use crate::popup::Popup;
|
use crate::popup::Popup;
|
||||||
use crate::{Config, Ironbar};
|
use crate::Ironbar;
|
||||||
use color_eyre::Result;
|
use color_eyre::Result;
|
||||||
use glib::Propagation;
|
use glib::Propagation;
|
||||||
use gtk::gdk::Monitor;
|
use gtk::gdk::Monitor;
|
||||||
|
@ -16,7 +16,7 @@ use tracing::{debug, info};
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
enum Inner {
|
enum Inner {
|
||||||
New { config: Option<Config> },
|
New { config: Option<BarConfig> },
|
||||||
Loaded { popup: Rc<Popup> },
|
Loaded { popup: Rc<Popup> },
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ impl Bar {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
app: &Application,
|
app: &Application,
|
||||||
monitor_name: String,
|
monitor_name: String,
|
||||||
config: Config,
|
config: BarConfig,
|
||||||
ironbar: Rc<Ironbar>,
|
ironbar: Rc<Ironbar>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let window = ApplicationWindow::builder()
|
let window = ApplicationWindow::builder()
|
||||||
|
@ -245,7 +245,7 @@ impl Bar {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Loads the configured modules onto a bar.
|
/// Loads the configured modules onto a bar.
|
||||||
fn load_modules(&self, config: Config, monitor: &Monitor) -> Result<BarLoadResult> {
|
fn load_modules(&self, config: BarConfig, monitor: &Monitor) -> Result<BarLoadResult> {
|
||||||
let icon_theme = IconTheme::new();
|
let icon_theme = IconTheme::new();
|
||||||
if let Some(ref theme) = config.icon_theme {
|
if let Some(ref theme) = config.icon_theme {
|
||||||
icon_theme.set_custom_theme(Some(theme));
|
icon_theme.set_custom_theme(Some(theme));
|
||||||
|
@ -408,7 +408,7 @@ pub fn create_bar(
|
||||||
app: &Application,
|
app: &Application,
|
||||||
monitor: &Monitor,
|
monitor: &Monitor,
|
||||||
monitor_name: String,
|
monitor_name: String,
|
||||||
config: Config,
|
config: BarConfig,
|
||||||
ironbar: Rc<Ironbar>,
|
ironbar: Rc<Ironbar>,
|
||||||
) -> Result<Bar> {
|
) -> Result<Bar> {
|
||||||
let bar = Bar::new(app, monitor_name, config, ironbar);
|
let bar = Bar::new(app, monitor_name, config, ironbar);
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use super::{BarPosition, Config, MonitorConfig};
|
use super::{BarConfig, BarPosition, MonitorConfig};
|
||||||
use color_eyre::{Help, Report};
|
use color_eyre::{Help, Report};
|
||||||
use gtk::Orientation;
|
use gtk::Orientation;
|
||||||
use serde::{Deserialize, Deserializer};
|
use serde::{Deserialize, Deserializer};
|
||||||
|
@ -13,11 +13,11 @@ impl<'de> Deserialize<'de> for MonitorConfig {
|
||||||
let content =
|
let content =
|
||||||
<serde::__private::de::Content as serde::Deserialize>::deserialize(deserializer)?;
|
<serde::__private::de::Content as serde::Deserialize>::deserialize(deserializer)?;
|
||||||
|
|
||||||
match <Config as serde::Deserialize>::deserialize(
|
match <BarConfig as serde::Deserialize>::deserialize(
|
||||||
serde::__private::de::ContentRefDeserializer::<D::Error>::new(&content),
|
serde::__private::de::ContentRefDeserializer::<D::Error>::new(&content),
|
||||||
) {
|
) {
|
||||||
Ok(config) => Ok(Self::Single(config)),
|
Ok(config) => Ok(Self::Single(config)),
|
||||||
Err(outer) => match <Vec<Config> as serde::Deserialize>::deserialize(
|
Err(outer) => match <Vec<BarConfig> as serde::Deserialize>::deserialize(
|
||||||
serde::__private::de::ContentRefDeserializer::<D::Error>::new(&content),
|
serde::__private::de::ContentRefDeserializer::<D::Error>::new(&content),
|
||||||
) {
|
) {
|
||||||
Ok(config) => Ok(Self::Multiple(config)),
|
Ok(config) => Ok(Self::Multiple(config)),
|
||||||
|
|
|
@ -64,10 +64,16 @@ pub enum ModuleConfig {
|
||||||
Workspaces(Box<WorkspacesModule>),
|
Workspaces(Box<WorkspacesModule>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize, Clone)]
|
||||||
|
pub enum BarEntryConfig {
|
||||||
|
Single(BarConfig),
|
||||||
|
Monitors(HashMap<String, MonitorConfig>),
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum MonitorConfig {
|
pub enum MonitorConfig {
|
||||||
Single(Config),
|
Single(BarConfig),
|
||||||
Multiple(Vec<Config>),
|
Multiple(Vec<BarConfig>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Copy, Clone, PartialEq, Eq)]
|
#[derive(Debug, Deserialize, Copy, Clone, PartialEq, Eq)]
|
||||||
|
@ -98,7 +104,7 @@ pub struct MarginConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Clone)]
|
#[derive(Debug, Deserialize, Clone)]
|
||||||
pub struct Config {
|
pub struct BarConfig {
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub position: BarPosition,
|
pub position: BarPosition,
|
||||||
#[serde(default = "default_true")]
|
#[serde(default = "default_true")]
|
||||||
|
@ -107,8 +113,6 @@ pub struct Config {
|
||||||
pub height: i32,
|
pub height: i32,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub margin: MarginConfig,
|
pub margin: MarginConfig,
|
||||||
#[serde(default = "default_popup_gap")]
|
|
||||||
pub popup_gap: i32,
|
|
||||||
pub name: Option<String>,
|
pub name: Option<String>,
|
||||||
|
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
|
@ -119,16 +123,15 @@ pub struct Config {
|
||||||
/// GTK icon theme to use.
|
/// GTK icon theme to use.
|
||||||
pub icon_theme: Option<String>,
|
pub icon_theme: Option<String>,
|
||||||
|
|
||||||
pub ironvar_defaults: Option<HashMap<Box<str>, String>>,
|
|
||||||
|
|
||||||
pub start: Option<Vec<ModuleConfig>>,
|
pub start: Option<Vec<ModuleConfig>>,
|
||||||
pub center: Option<Vec<ModuleConfig>>,
|
pub center: Option<Vec<ModuleConfig>>,
|
||||||
pub end: Option<Vec<ModuleConfig>>,
|
pub end: Option<Vec<ModuleConfig>>,
|
||||||
|
|
||||||
pub monitors: Option<HashMap<String, MonitorConfig>>,
|
#[serde(default = "default_popup_gap")]
|
||||||
|
pub popup_gap: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Config {
|
impl Default for BarConfig {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
cfg_if! {
|
cfg_if! {
|
||||||
if #[cfg(feature = "clock")] {
|
if #[cfg(feature = "clock")] {
|
||||||
|
@ -155,20 +158,27 @@ impl Default for Config {
|
||||||
name: None,
|
name: None,
|
||||||
start_hidden: None,
|
start_hidden: None,
|
||||||
autohide: None,
|
autohide: None,
|
||||||
popup_gap: default_popup_gap(),
|
|
||||||
icon_theme: None,
|
icon_theme: None,
|
||||||
ironvar_defaults: None,
|
|
||||||
start: Some(vec![ModuleConfig::Label(
|
start: Some(vec![ModuleConfig::Label(
|
||||||
LabelModule::new("ℹ️ Using default config".to_string()).into(),
|
LabelModule::new("ℹ️ Using default config".to_string()).into(),
|
||||||
)]),
|
)]),
|
||||||
center,
|
center,
|
||||||
end,
|
end,
|
||||||
anchor_to_edges: default_true(),
|
anchor_to_edges: default_true(),
|
||||||
monitors: None,
|
popup_gap: default_popup_gap(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[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>>,
|
||||||
|
}
|
||||||
|
|
||||||
const fn default_bar_height() -> i32 {
|
const fn default_bar_height() -> i32 {
|
||||||
42
|
42
|
||||||
}
|
}
|
||||||
|
|
|
@ -331,7 +331,7 @@ fn load_output_bars(
|
||||||
.expect("monitor to exist");
|
.expect("monitor to exist");
|
||||||
|
|
||||||
let show_default_bar =
|
let show_default_bar =
|
||||||
config.start.is_some() || config.center.is_some() || config.end.is_some();
|
config.bar.start.is_some() || config.bar.center.is_some() || config.bar.end.is_some();
|
||||||
|
|
||||||
let bars = match config
|
let bars = match config
|
||||||
.monitors
|
.monitors
|
||||||
|
@ -363,7 +363,7 @@ fn load_output_bars(
|
||||||
app,
|
app,
|
||||||
&monitor,
|
&monitor,
|
||||||
monitor_name.to_string(),
|
monitor_name.to_string(),
|
||||||
config.clone(),
|
config.bar.clone(),
|
||||||
ironbar.clone(),
|
ironbar.clone(),
|
||||||
)?],
|
)?],
|
||||||
None => vec![],
|
None => vec![],
|
||||||
|
|
Loading…
Add table
Reference in a new issue