diff --git a/docs/Configuration guide.md b/docs/Configuration guide.md index d63bb67..6c121ee 100644 --- a/docs/Configuration guide.md +++ b/docs/Configuration guide.md @@ -272,6 +272,10 @@ The following table lists each of the top-level bar config options: | `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. | +| `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` | `Module[]` | `[]` | Array of left or top modules. | | `center` | `Module[]` | `[]` | Array of center modules. | diff --git a/src/bar.rs b/src/bar.rs index 296933e..0c508f1 100644 --- a/src/bar.rs +++ b/src/bar.rs @@ -1,5 +1,5 @@ use crate::bridge_channel::BridgeChannel; -use crate::config::{BarPosition, CommonConfig, ModuleConfig}; +use crate::config::{BarPosition, CommonConfig, MarginConfig, ModuleConfig}; use crate::dynamic_string::DynamicString; use crate::modules::{Module, ModuleInfo, ModuleLocation, ModuleUpdateEvent, WidgetContext}; use crate::popup::Popup; @@ -24,7 +24,13 @@ pub fn create_bar( ) -> Result<()> { let win = ApplicationWindow::builder().application(app).build(); - setup_layer_shell(&win, monitor, config.position, config.anchor_to_edges); + setup_layer_shell( + &win, + monitor, + config.position, + config.anchor_to_edges, + config.margin, + ); let orientation = config.position.get_orientation(); @@ -79,6 +85,7 @@ fn setup_layer_shell( monitor: &Monitor, position: BarPosition, anchor_to_edges: bool, + margin: MarginConfig, ) { gtk_layer_shell::init_for_window(win); gtk_layer_shell::set_monitor(win, monitor); @@ -86,10 +93,10 @@ fn setup_layer_shell( gtk_layer_shell::auto_exclusive_zone_enable(win); gtk_layer_shell::set_namespace(win, env!("CARGO_PKG_NAME")); - gtk_layer_shell::set_margin(win, gtk_layer_shell::Edge::Top, 0); - gtk_layer_shell::set_margin(win, gtk_layer_shell::Edge::Bottom, 0); - gtk_layer_shell::set_margin(win, gtk_layer_shell::Edge::Left, 0); - gtk_layer_shell::set_margin(win, gtk_layer_shell::Edge::Right, 0); + gtk_layer_shell::set_margin(win, gtk_layer_shell::Edge::Top, margin.top); + gtk_layer_shell::set_margin(win, gtk_layer_shell::Edge::Bottom, margin.bottom); + gtk_layer_shell::set_margin(win, gtk_layer_shell::Edge::Left, margin.left); + gtk_layer_shell::set_margin(win, gtk_layer_shell::Edge::Right, margin.right); let bar_orientation = position.get_orientation(); diff --git a/src/config/mod.rs b/src/config/mod.rs index fdec0fc..a742fd0 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -74,14 +74,39 @@ impl Default for BarPosition { } } +#[derive(Debug, Deserialize, Copy, Clone, PartialEq, Eq)] +pub struct MarginConfig { + #[serde(default)] + pub bottom: i32, + #[serde(default)] + pub left: i32, + #[serde(default)] + pub right: i32, + #[serde(default)] + pub top: i32, +} + +impl Default for MarginConfig { + fn default() -> Self { + MarginConfig { + bottom: 0, + left: 0, + right: 0, + top: 0, + } + } +} + #[derive(Debug, Deserialize, Clone)] pub struct Config { - #[serde(default = "default_bar_position")] + #[serde(default)] pub position: BarPosition, #[serde(default = "default_true")] pub anchor_to_edges: bool, #[serde(default = "default_bar_height")] pub height: i32, + #[serde(default)] + pub margin: MarginConfig, /// GTK icon theme to use. pub icon_theme: Option, @@ -93,10 +118,6 @@ pub struct Config { pub monitors: Option>, } -const fn default_bar_position() -> BarPosition { - BarPosition::Bottom -} - const fn default_bar_height() -> i32 { 42 }