mirror of
https://github.com/Zedfrigg/ironbar.git
synced 2025-07-02 03:01:04 +02:00
Merge pull request #220 from JakeStanger/feat/default-config
Default configuration
This commit is contained in:
commit
fc820746a4
6 changed files with 77 additions and 14 deletions
|
@ -21,6 +21,7 @@ use crate::modules::tray::TrayModule;
|
||||||
use crate::modules::upower::UpowerModule;
|
use crate::modules::upower::UpowerModule;
|
||||||
#[cfg(feature = "workspaces")]
|
#[cfg(feature = "workspaces")]
|
||||||
use crate::modules::workspaces::WorkspacesModule;
|
use crate::modules::workspaces::WorkspacesModule;
|
||||||
|
use cfg_if::cfg_if;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
@ -109,6 +110,35 @@ pub struct Config {
|
||||||
pub monitors: Option<HashMap<String, MonitorConfig>>,
|
pub monitors: Option<HashMap<String, MonitorConfig>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for Config {
|
||||||
|
fn default() -> Self {
|
||||||
|
cfg_if! {
|
||||||
|
if #[cfg(feature = "clock")] {
|
||||||
|
let end = Some(vec![ModuleConfig::Clock(Box::default())]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
let end = None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Self {
|
||||||
|
position: Default::default(),
|
||||||
|
height: default_bar_height(),
|
||||||
|
margin: Default::default(),
|
||||||
|
popup_gap: default_popup_gap(),
|
||||||
|
icon_theme: None,
|
||||||
|
ironvar_defaults: None,
|
||||||
|
start: Some(vec![ModuleConfig::Label(
|
||||||
|
LabelModule::new("ℹ️ Using default config".to_string()).into(),
|
||||||
|
)]),
|
||||||
|
center: Some(vec![ModuleConfig::Focused(Box::default())]),
|
||||||
|
end,
|
||||||
|
anchor_to_edges: default_true(),
|
||||||
|
monitors: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const fn default_bar_height() -> i32 {
|
const fn default_bar_height() -> i32 {
|
||||||
42
|
42
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
pub enum ExitCode {
|
pub enum ExitCode {
|
||||||
GtkDisplay = 1,
|
GtkDisplay = 1,
|
||||||
CreateBars = 2,
|
CreateBars = 2,
|
||||||
Config = 3,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const ERR_OUTPUTS: &str = "GTK and Wayland are reporting a different set of outputs - this is a severe bug and should never happen";
|
pub const ERR_OUTPUTS: &str = "GTK and Wayland are reporting a different set of outputs - this is a severe bug and should never happen";
|
||||||
|
|
21
src/main.rs
21
src/main.rs
|
@ -47,7 +47,7 @@ use tokio::task::{block_in_place, spawn_blocking};
|
||||||
|
|
||||||
use crate::error::ExitCode;
|
use crate::error::ExitCode;
|
||||||
use clients::wayland;
|
use clients::wayland;
|
||||||
use tracing::{debug, error, info};
|
use tracing::{debug, error, info, warn};
|
||||||
use universal_config::ConfigLoader;
|
use universal_config::ConfigLoader;
|
||||||
|
|
||||||
const GTK_APP_ID: &str = "dev.jstanger.ironbar";
|
const GTK_APP_ID: &str = "dev.jstanger.ironbar";
|
||||||
|
@ -159,18 +159,19 @@ pub fn load_interface(app: &Application) {
|
||||||
|display| display,
|
|display| display,
|
||||||
);
|
);
|
||||||
|
|
||||||
let config_res = env::var("IRONBAR_CONFIG").map_or_else(
|
let mut config = env::var("IRONBAR_CONFIG")
|
||||||
|
.map_or_else(
|
||||||
|_| ConfigLoader::new("ironbar").find_and_load(),
|
|_| ConfigLoader::new("ironbar").find_and_load(),
|
||||||
ConfigLoader::load,
|
ConfigLoader::load,
|
||||||
);
|
)
|
||||||
|
.unwrap_or_else(|err| {
|
||||||
|
error!("Failed to load config: {}", err);
|
||||||
|
warn!("Falling back to the default config");
|
||||||
|
info!("If this is your first time using Ironbar, you should create a config in ~/.config/ironbar/");
|
||||||
|
info!("More info here: https://github.com/JakeStanger/ironbar/wiki/configuration-guide");
|
||||||
|
|
||||||
let mut config: Config = match config_res {
|
Config::default()
|
||||||
Ok(config) => config,
|
});
|
||||||
Err(err) => {
|
|
||||||
error!("{:?}", err);
|
|
||||||
exit(ExitCode::Config as i32)
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
debug!("Loaded config file");
|
debug!("Loaded config file");
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,17 @@ pub struct ClockModule {
|
||||||
pub common: Option<CommonConfig>,
|
pub common: Option<CommonConfig>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for ClockModule {
|
||||||
|
fn default() -> Self {
|
||||||
|
ClockModule {
|
||||||
|
format: default_format(),
|
||||||
|
format_popup: default_popup_format(),
|
||||||
|
locale: default_locale(),
|
||||||
|
common: Some(CommonConfig::default()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn default_format() -> String {
|
fn default_format() -> String {
|
||||||
String::from("%d/%m/%Y %H:%M")
|
String::from("%d/%m/%Y %H:%M")
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,18 @@ pub struct FocusedModule {
|
||||||
pub common: Option<CommonConfig>,
|
pub common: Option<CommonConfig>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for FocusedModule {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
show_icon: crate::config::default_true(),
|
||||||
|
show_title: crate::config::default_true(),
|
||||||
|
icon_size: default_icon_size(),
|
||||||
|
truncate: None,
|
||||||
|
common: Some(CommonConfig::default()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const fn default_icon_size() -> i32 {
|
const fn default_icon_size() -> i32 {
|
||||||
32
|
32
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,15 @@ pub struct LabelModule {
|
||||||
pub common: Option<CommonConfig>,
|
pub common: Option<CommonConfig>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl LabelModule {
|
||||||
|
pub(crate) fn new(label: String) -> Self {
|
||||||
|
Self {
|
||||||
|
label,
|
||||||
|
common: Some(CommonConfig::default()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Module<Label> for LabelModule {
|
impl Module<Label> for LabelModule {
|
||||||
type SendMessage = String;
|
type SendMessage = String;
|
||||||
type ReceiveMessage = ();
|
type ReceiveMessage = ();
|
||||||
|
@ -45,11 +54,12 @@ impl Module<Label> for LabelModule {
|
||||||
_info: &ModuleInfo,
|
_info: &ModuleInfo,
|
||||||
) -> Result<ModuleWidget<Label>> {
|
) -> Result<ModuleWidget<Label>> {
|
||||||
let label = Label::new(None);
|
let label = Label::new(None);
|
||||||
|
label.set_use_markup(true);
|
||||||
|
|
||||||
{
|
{
|
||||||
let label = label.clone();
|
let label = label.clone();
|
||||||
context.widget_rx.attach(None, move |string| {
|
context.widget_rx.attach(None, move |string| {
|
||||||
label.set_label(&string);
|
label.set_markup(&string);
|
||||||
Continue(true)
|
Continue(true)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue