From a358037d3eaadd517551ef642e01c5318793d27c Mon Sep 17 00:00:00 2001 From: Jake Stanger Date: Sun, 14 Aug 2022 15:56:21 +0100 Subject: [PATCH] feat: add support for showing bar at top of screen --- README.md | 11 ++++++++-- src/bar.rs | 13 +++++++----- src/config.rs | 20 +++++++++++++++++++ src/modules/clock/mod.rs | 2 +- src/modules/launcher/mod.rs | 2 +- src/modules/mod.rs | 2 ++ src/modules/mpd/mod.rs | 2 +- src/popup.rs | 40 ++++++++++++++++++++++++++++++++----- 8 files changed, 77 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index bb99ece..fef19cb 100644 --- a/README.md +++ b/README.md @@ -21,8 +21,7 @@ Then just run with `ironbar`. ## Configuration -By default, running will get you a blank bar. To start, you will need a configuration file in `.config/ironbar`. -Ironbar supports a range of file formats so pick your favourite: +By default, running will get you a blank bar. To start, you will need a configuration file in `.config/ironbar`. This could be called `config.`, using one of the available extensions: - JSON - TOML @@ -71,6 +70,14 @@ The monitor's config object takes any combination of `left`, `center`, and `righ } ``` +| Name | Type | Default | Description | +|------------|-------------------|---------|-----------------------------------------------------------------------------| +| `position` | `top` or `bottom` | `[]` | The bar's position on screen. | +| `left` | `Module[]` | `[]` | Array of left modules. | +| `center` | `Module[]` | `[]` | Array of center modules. | +| `right` | `Module[]` | `[]` | Array of right modules. | +| `monitors` | `RootConfig[]` | `null` | Array of root config objects for each monitor. Overrides left/center/right. | + ## Styling To get started, create a stylesheet at `.config/ironbar/style.css`. Changes will be hot-reloaded every time you save the file. diff --git a/src/bar.rs b/src/bar.rs index 11448ec..a6e9614 100644 --- a/src/bar.rs +++ b/src/bar.rs @@ -1,4 +1,4 @@ -use crate::config::ModuleConfig; +use crate::config::{BarPosition, ModuleConfig}; use crate::modules::{Module, ModuleInfo, ModuleLocation}; use crate::Config; use gtk::gdk::Monitor; @@ -8,7 +8,7 @@ use gtk::{Application, ApplicationWindow, Orientation}; pub fn create_bar(app: &Application, monitor: &Monitor, config: Config) { let win = ApplicationWindow::builder().application(app).build(); - setup_layer_shell(&win, monitor); + setup_layer_shell(&win, monitor, &config.position); let content = gtk::Box::builder() .orientation(Orientation::Horizontal) @@ -53,6 +53,7 @@ fn load_modules( let info = ModuleInfo { app, location: ModuleLocation::Left, + bar_position: &config.position }; add_modules(left, modules, info); @@ -62,6 +63,7 @@ fn load_modules( let info = ModuleInfo { app, location: ModuleLocation::Center, + bar_position: &config.position }; add_modules(center, modules, info); @@ -71,6 +73,7 @@ fn load_modules( let info = ModuleInfo { app, location: ModuleLocation::Right, + bar_position: &config.position }; add_modules(right, modules, info); @@ -119,7 +122,7 @@ fn add_modules(content: >k::Box, modules: Vec, info: ModuleInfo) } } -fn setup_layer_shell(win: &ApplicationWindow, monitor: &Monitor) { +fn setup_layer_shell(win: &ApplicationWindow, monitor: &Monitor, position: &BarPosition) { gtk_layer_shell::init_for_window(win); gtk_layer_shell::set_monitor(win, monitor); gtk_layer_shell::set_layer(win, gtk_layer_shell::Layer::Top); @@ -130,8 +133,8 @@ fn setup_layer_shell(win: &ApplicationWindow, monitor: &Monitor) { 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_anchor(win, gtk_layer_shell::Edge::Top, false); - gtk_layer_shell::set_anchor(win, gtk_layer_shell::Edge::Bottom, true); + gtk_layer_shell::set_anchor(win, gtk_layer_shell::Edge::Top, position == &BarPosition::Top); + gtk_layer_shell::set_anchor(win, gtk_layer_shell::Edge::Bottom, position == &BarPosition::Bottom); gtk_layer_shell::set_anchor(win, gtk_layer_shell::Edge::Left, true); gtk_layer_shell::set_anchor(win, gtk_layer_shell::Edge::Right, true); } diff --git a/src/config.rs b/src/config.rs index 5014ffb..1a8d88d 100644 --- a/src/config.rs +++ b/src/config.rs @@ -21,8 +21,24 @@ pub enum ModuleConfig { Script(ScriptModule), } +#[derive(Debug, Deserialize, Clone, PartialEq)] +#[serde(rename_all = "kebab-case")] +pub enum BarPosition { + Top, + Bottom +} + +impl Default for BarPosition { + fn default() -> Self { + BarPosition::Bottom + } +} + #[derive(Debug, Deserialize, Clone, Default)] pub struct Config { + #[serde(default = "default_bar_position")] + pub position: BarPosition, + pub left: Option>, pub center: Option>, pub right: Option>, @@ -30,6 +46,10 @@ pub struct Config { pub monitors: Option>, } +const fn default_bar_position() -> BarPosition { + BarPosition::Bottom +} + impl Config { pub fn load() -> Option { let config_dir = config_dir().expect("Failed to locate user config dir"); diff --git a/src/modules/clock/mod.rs b/src/modules/clock/mod.rs index 9efc788..c113580 100644 --- a/src/modules/clock/mod.rs +++ b/src/modules/clock/mod.rs @@ -30,7 +30,7 @@ impl Module