mirror of
https://github.com/Zedfrigg/ironbar.git
synced 2025-04-19 11:24:24 +02:00
feat: add support for showing bar at top of screen
This commit is contained in:
parent
19d009fe5b
commit
a358037d3e
8 changed files with 77 additions and 15 deletions
11
README.md
11
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.<fmt>`, 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.
|
||||
|
|
13
src/bar.rs
13
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<ModuleConfig>, 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);
|
||||
}
|
||||
|
|
|
@ -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<Vec<ModuleConfig>>,
|
||||
pub center: Option<Vec<ModuleConfig>>,
|
||||
pub right: Option<Vec<ModuleConfig>>,
|
||||
|
@ -30,6 +46,10 @@ pub struct Config {
|
|||
pub monitors: Option<Vec<Config>>,
|
||||
}
|
||||
|
||||
const fn default_bar_position() -> BarPosition {
|
||||
BarPosition::Bottom
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn load() -> Option<Self> {
|
||||
let config_dir = config_dir().expect("Failed to locate user config dir");
|
||||
|
|
|
@ -30,7 +30,7 @@ impl Module<Button> for ClockModule {
|
|||
fn into_widget(self, info: &ModuleInfo) -> Button {
|
||||
let button = Button::new();
|
||||
|
||||
let popup = Popup::new("popup-clock", info.app, Orientation::Vertical);
|
||||
let popup = Popup::new("popup-clock", info.app, Orientation::Vertical, info.bar_position);
|
||||
popup.add_clock_widgets();
|
||||
|
||||
button.show_all();
|
||||
|
|
|
@ -207,7 +207,7 @@ impl Module<gtk::Box> for LauncherModule {
|
|||
|
||||
let mut sway = Client::connect().unwrap();
|
||||
|
||||
let popup = Popup::new("popup-launcher", info.app, Orientation::Vertical);
|
||||
let popup = Popup::new("popup-launcher", info.app, Orientation::Vertical, info.bar_position);
|
||||
let container = gtk::Box::new(Orientation::Horizontal, 0);
|
||||
|
||||
let (ui_tx, mut ui_rx) = mpsc::channel(32);
|
||||
|
|
|
@ -18,6 +18,7 @@ use glib::IsA;
|
|||
use gtk::{Application, Widget};
|
||||
use serde::de::DeserializeOwned;
|
||||
use serde_json::Value;
|
||||
use crate::config::BarPosition;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum ModuleLocation {
|
||||
|
@ -29,6 +30,7 @@ pub enum ModuleLocation {
|
|||
pub struct ModuleInfo<'a> {
|
||||
pub app: &'a Application,
|
||||
pub location: ModuleLocation,
|
||||
pub bar_position: &'a BarPosition
|
||||
}
|
||||
|
||||
pub trait Module<W>
|
||||
|
|
|
@ -93,7 +93,7 @@ impl Module<Button> for MpdModule {
|
|||
|
||||
let (ui_tx, mut ui_rx) = mpsc::channel(32);
|
||||
|
||||
let popup = Popup::new("popup-mpd", info.app, Orientation::Horizontal);
|
||||
let popup = Popup::new("popup-mpd", info.app, Orientation::Horizontal, info.bar_position);
|
||||
let mpd_popup = MpdPopup::new(popup, ui_tx);
|
||||
|
||||
let (tx, rx) = glib::MainContext::channel(glib::PRIORITY_DEFAULT);
|
||||
|
|
40
src/popup.rs
40
src/popup.rs
|
@ -1,3 +1,4 @@
|
|||
use crate::config::BarPosition;
|
||||
use gtk::prelude::*;
|
||||
use gtk::{Application, ApplicationWindow, Orientation};
|
||||
|
||||
|
@ -14,19 +15,48 @@ pub enum PopupAlignment {
|
|||
}
|
||||
|
||||
impl Popup {
|
||||
pub fn new(name: &str, app: &Application, orientation: Orientation) -> Self {
|
||||
pub fn new(
|
||||
name: &str,
|
||||
app: &Application,
|
||||
orientation: Orientation,
|
||||
bar_position: &BarPosition,
|
||||
) -> Self {
|
||||
let win = ApplicationWindow::builder().application(app).build();
|
||||
|
||||
gtk_layer_shell::init_for_window(&win);
|
||||
gtk_layer_shell::set_layer(&win, gtk_layer_shell::Layer::Overlay);
|
||||
|
||||
gtk_layer_shell::set_margin(&win, gtk_layer_shell::Edge::Top, 0);
|
||||
gtk_layer_shell::set_margin(&win, gtk_layer_shell::Edge::Bottom, 5);
|
||||
gtk_layer_shell::set_margin(
|
||||
&win,
|
||||
gtk_layer_shell::Edge::Top,
|
||||
if bar_position == &BarPosition::Top {
|
||||
5
|
||||
} else {
|
||||
0
|
||||
},
|
||||
);
|
||||
gtk_layer_shell::set_margin(
|
||||
&win,
|
||||
gtk_layer_shell::Edge::Bottom,
|
||||
if bar_position == &BarPosition::Bottom {
|
||||
5
|
||||
} else {
|
||||
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_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,
|
||||
bar_position == &BarPosition::Top,
|
||||
);
|
||||
gtk_layer_shell::set_anchor(
|
||||
&win,
|
||||
gtk_layer_shell::Edge::Bottom,
|
||||
bar_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, false);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue