From cac064f4795e9f418cc0820f04944f91121c426a Mon Sep 17 00:00:00 2001 From: Jake Stanger Date: Fri, 7 Apr 2023 14:36:12 +0100 Subject: [PATCH] feat: ability to configure popup gap --- docs/Configuration guide.md | 1 + src/bar.rs | 15 ++++++++++----- src/config/mod.rs | 6 ++++++ src/popup.rs | 10 +++++----- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/docs/Configuration guide.md b/docs/Configuration guide.md index c51c300..e8be7db 100644 --- a/docs/Configuration guide.md +++ b/docs/Configuration guide.md @@ -272,6 +272,7 @@ 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. | +| `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 | diff --git a/src/bar.rs b/src/bar.rs index 1637974..bfa3058 100644 --- a/src/bar.rs +++ b/src/bar.rs @@ -168,17 +168,17 @@ fn load_modules( if let Some(modules) = config.start { let info = info!(ModuleLocation::Left); - add_modules(left, modules, &info)?; + add_modules(left, modules, &info, config.popup_gap)?; } if let Some(modules) = config.center { let info = info!(ModuleLocation::Center); - add_modules(center, modules, &info)?; + add_modules(center, modules, &info, config.popup_gap)?; } if let Some(modules) = config.end { let info = info!(ModuleLocation::Right); - add_modules(right, modules, &info)?; + add_modules(right, modules, &info, config.popup_gap)?; } Ok(()) @@ -186,8 +186,13 @@ fn load_modules( /// Adds modules into a provided GTK box, /// which should be one of its left, center or right containers. -fn add_modules(content: >k::Box, modules: Vec, info: &ModuleInfo) -> Result<()> { - let popup = Popup::new(info); +fn add_modules( + content: >k::Box, + modules: Vec, + info: &ModuleInfo, + popup_gap: i32, +) -> Result<()> { + let popup = Popup::new(info, popup_gap); let popup = Arc::new(RwLock::new(popup)); macro_rules! add_module { diff --git a/src/config/mod.rs b/src/config/mod.rs index fe73fe0..053345f 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -102,6 +102,8 @@ pub struct Config { pub height: i32, #[serde(default)] pub margin: MarginConfig, + #[serde(default = "default_popup_gap")] + pub popup_gap: i32, /// GTK icon theme to use. pub icon_theme: Option, @@ -117,6 +119,10 @@ const fn default_bar_height() -> i32 { 42 } +const fn default_popup_gap() -> i32 { + 5 +} + pub const fn default_false() -> bool { false } diff --git a/src/popup.rs b/src/popup.rs index 5577149..875837a 100644 --- a/src/popup.rs +++ b/src/popup.rs @@ -19,7 +19,7 @@ impl Popup { /// Creates a new popup window. /// This includes setting up gtk-layer-shell /// and an empty `gtk::Box` container. - pub fn new(module_info: &ModuleInfo) -> Self { + pub fn new(module_info: &ModuleInfo, gap: i32) -> Self { let pos = module_info.bar_position; let orientation = pos.get_orientation(); @@ -34,22 +34,22 @@ impl Popup { gtk_layer_shell::set_margin( &win, gtk_layer_shell::Edge::Top, - if pos == BarPosition::Top { 5 } else { 0 }, + if pos == BarPosition::Top { gap } else { 0 }, ); gtk_layer_shell::set_margin( &win, gtk_layer_shell::Edge::Bottom, - if pos == BarPosition::Bottom { 5 } else { 0 }, + if pos == BarPosition::Bottom { gap } else { 0 }, ); gtk_layer_shell::set_margin( &win, gtk_layer_shell::Edge::Left, - if pos == BarPosition::Left { 5 } else { 0 }, + if pos == BarPosition::Left { gap } else { 0 }, ); gtk_layer_shell::set_margin( &win, gtk_layer_shell::Edge::Right, - if pos == BarPosition::Right { 5 } else { 0 }, + if pos == BarPosition::Right { gap } else { 0 }, ); gtk_layer_shell::set_anchor(