diff --git a/Cargo.lock b/Cargo.lock index 48c8e4da..daaed745 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -596,6 +596,16 @@ dependencies = [ "backtrace", ] +[[package]] +name = "base16-egui-themes" +version = "0.1.0" +source = "git+https://github.com/LGUG2Z/base16-egui-themes#b4afb9aa0104b6100d6be52b9fb2abb349a5de1e" +dependencies = [ + "egui", + "schemars", + "serde", +] + [[package]] name = "base64" version = "0.22.1" @@ -2677,6 +2687,7 @@ dependencies = [ name = "komorebi-bar" version = "0.1.0" dependencies = [ + "base16-egui-themes", "catppuccin-egui", "chrono", "clap", diff --git a/komorebi-bar/Cargo.toml b/komorebi-bar/Cargo.toml index 66a95008..f2a90f9f 100644 --- a/komorebi-bar/Cargo.toml +++ b/komorebi-bar/Cargo.toml @@ -8,6 +8,7 @@ edition = "2021" [dependencies] komorebi-client = { path = "../komorebi-client" } +base16-egui-themes = { git = "https://github.com/LGUG2Z/base16-egui-themes" } catppuccin-egui = { version = "5.1", default-features = false, features = ["egui28"] } chrono = "0.4" clap = { version = "4", features = ["derive", "wrap_help"] } @@ -33,4 +34,4 @@ tracing = "0.1" tracing-appender = "0.2" tracing-subscriber = { version = "0.3", features = ["env-filter"] } windows = { workspace = true } -windows-icons = "0.1" +windows-icons = "0.1" \ No newline at end of file diff --git a/komorebi-bar/src/bar.rs b/komorebi-bar/src/bar.rs index f37bb099..2335fa4d 100644 --- a/komorebi-bar/src/bar.rs +++ b/komorebi-bar/src/bar.rs @@ -1,3 +1,4 @@ +use crate::config::Catppuccin; use crate::config::KomobarConfig; use crate::config::Theme; use crate::komorebi::Komorebi; @@ -7,6 +8,7 @@ use crate::widget::WidgetConfig; use crossbeam_channel::Receiver; use eframe::egui::Align; use eframe::egui::CentralPanel; +use eframe::egui::Color32; use eframe::egui::Context; use eframe::egui::FontData; use eframe::egui::FontDefinitions; @@ -28,6 +30,7 @@ pub struct Komobar { pub right_widgets: Vec>, pub rx_gui: Receiver, pub rx_config: Receiver, + pub bg_color: Color32, } impl Komobar { @@ -43,22 +46,34 @@ impl Komobar { } match config.theme { - Some(Theme::CatppuccinFrappe) => { - catppuccin_egui::set_theme(ctx, catppuccin_egui::FRAPPE); - tracing::info!("theme updated: Catppuccin Frappe"); - } - Some(Theme::CatppuccinMacchiato) => { - catppuccin_egui::set_theme(ctx, catppuccin_egui::MACCHIATO); - tracing::info!("theme updated: Catppuccin Macchiato"); - } - Some(Theme::CatppuccinMocha) => { - catppuccin_egui::set_theme(ctx, catppuccin_egui::MOCHA); - tracing::info!("theme updated: Catppuccin Mocha"); - } - Some(Theme::Default) | None => { + None => { ctx.set_style(Style::default()); - tracing::info!("theme updated: Egui Default"); + self.bg_color = Style::default().visuals.panel_fill; } + Some(theme) => match theme { + Theme::Catppuccin { name: catppuccin } => match catppuccin { + Catppuccin::Frappe => { + catppuccin_egui::set_theme(ctx, catppuccin_egui::FRAPPE); + self.bg_color = catppuccin_egui::FRAPPE.base; + } + Catppuccin::Latte => { + catppuccin_egui::set_theme(ctx, catppuccin_egui::LATTE); + self.bg_color = catppuccin_egui::LATTE.base; + } + Catppuccin::Macchiato => { + catppuccin_egui::set_theme(ctx, catppuccin_egui::MACCHIATO); + self.bg_color = catppuccin_egui::MACCHIATO.base; + } + Catppuccin::Mocha => { + catppuccin_egui::set_theme(ctx, catppuccin_egui::MOCHA); + self.bg_color = catppuccin_egui::MOCHA.base; + } + }, + Theme::Base16 { name: base16 } => { + ctx.set_style(base16.style()); + self.bg_color = base16.background(); + } + }, } let mut komorebi_widget = None; @@ -139,6 +154,7 @@ impl Komobar { right_widgets: vec![], rx_gui, rx_config, + bg_color: Style::default().visuals.panel_fill, }; komobar.apply_config(&cc.egui_ctx, &config, None); @@ -199,12 +215,14 @@ impl eframe::App for Komobar { } let frame = if let Some(frame) = &self.config.frame { - Frame::none().outer_margin(Margin::symmetric( - frame.outer_margin.x, - frame.outer_margin.y, - )) - } else { Frame::none() + .inner_margin(Margin::symmetric( + frame.inner_margin.x, + frame.inner_margin.y, + )) + .fill(self.bg_color) + } else { + Frame::none().fill(self.bg_color) }; CentralPanel::default().frame(frame).show(ctx, |ui| { diff --git a/komorebi-bar/src/config.rs b/komorebi-bar/src/config.rs index 42187ca6..6daf2eea 100644 --- a/komorebi-bar/src/config.rs +++ b/komorebi-bar/src/config.rs @@ -1,4 +1,5 @@ use crate::widget::WidgetConfig; +use base16_egui_themes::Base16; use eframe::egui::Pos2; use eframe::egui::TextBuffer; use eframe::egui::Vec2; @@ -36,8 +37,8 @@ pub struct ViewportConfig { #[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)] pub struct FrameConfig { - /// Margin outside the painted frame - pub outer_margin: Position, + /// Margin inside the painted frame + pub inner_margin: Position, } #[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)] @@ -59,7 +60,7 @@ impl KomobarConfig { if value.frame.is_none() { value.frame = Some(FrameConfig { - outer_margin: Position { x: 10.0, y: 10.0 }, + inner_margin: Position { x: 10.0, y: 10.0 }, }); } @@ -94,13 +95,18 @@ impl From for Pos2 { } #[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema)] +#[serde(tag = "type")] pub enum Theme { - /// Default egui theme - Default, - /// Catpuccin Frappe - CatppuccinFrappe, - /// Catpuccin Macchiato - CatppuccinMacchiato, - /// Catpuccin Mocha - CatppuccinMocha, + /// A theme from catppuccin-egui + Catppuccin { name: Catppuccin }, + /// A theme from base16-egui-themes + Base16 { name: Base16 }, +} + +#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema)] +pub enum Catppuccin { + Frappe, + Latte, + Macchiato, + Mocha, } diff --git a/komorebi-bar/src/main.rs b/komorebi-bar/src/main.rs index 58602584..7762f5b4 100644 --- a/komorebi-bar/src/main.rs +++ b/komorebi-bar/src/main.rs @@ -184,13 +184,14 @@ fn main() -> color_eyre::Result<()> { hotwatch.watch(config_path, move |event| match event.kind { EventKind::Modify(_) | EventKind::Remove(_) => { - let updated = KomobarConfig::read(&config_path_cl).unwrap(); - tx_config.send(updated).unwrap(); + if let Ok(updated) = KomobarConfig::read(&config_path_cl) { + tx_config.send(updated).unwrap(); - tracing::info!( - "configuration file updated: {}", - config_path_cl.as_path().to_string_lossy() - ); + tracing::info!( + "configuration file updated: {}", + config_path_cl.as_path().to_string_lossy() + ); + } } _ => {} })?; diff --git a/schema.bar.json b/schema.bar.json index eb4e2ab8..a5f01b1c 100644 --- a/schema.bar.json +++ b/schema.bar.json @@ -16,11 +16,11 @@ "description": "Frame options (see: https://docs.rs/egui/latest/egui/containers/struct.Frame.html)", "type": "object", "required": [ - "outer_margin" + "inner_margin" ], "properties": { - "outer_margin": { - "description": "Margin outside the painted frame", + "inner_margin": { + "description": "Margin inside the painted frame", "type": "object", "required": [ "x", @@ -778,32 +778,319 @@ "description": "Theme", "oneOf": [ { - "description": "Default egui theme", - "type": "string", - "enum": [ - "Default" - ] + "description": "A theme from catppuccin-egui", + "type": "object", + "required": [ + "name", + "type" + ], + "properties": { + "name": { + "type": "string", + "enum": [ + "Frappe", + "Latte", + "Macchiato", + "Mocha" + ] + }, + "type": { + "type": "string", + "enum": [ + "Catppuccin" + ] + } + } }, { - "description": "Catpuccin Frappe", - "type": "string", - "enum": [ - "CatppuccinFrappe" - ] - }, - { - "description": "Catpuccin Macchiato", - "type": "string", - "enum": [ - "CatppuccinMacchiato" - ] - }, - { - "description": "Catpuccin Mocha", - "type": "string", - "enum": [ - "CatppuccinMocha" - ] + "description": "A theme from base16-egui-themes", + "type": "object", + "required": [ + "name", + "type" + ], + "properties": { + "name": { + "type": "string", + "enum": [ + "3024", + "Apathy", + "Apprentice", + "Ashes", + "AtelierCaveLight", + "AtelierCave", + "AtelierDuneLight", + "AtelierDune", + "AtelierEstuaryLight", + "AtelierEstuary", + "AtelierForestLight", + "AtelierForest", + "AtelierHeathLight", + "AtelierHeath", + "AtelierLakesideLight", + "AtelierLakeside", + "AtelierPlateauLight", + "AtelierPlateau", + "AtelierSavannaLight", + "AtelierSavanna", + "AtelierSeasideLight", + "AtelierSeaside", + "AtelierSulphurpoolLight", + "AtelierSulphurpool", + "Atlas", + "AyuDark", + "AyuLight", + "AyuMirage", + "Aztec", + "Bespin", + "BlackMetalBathory", + "BlackMetalBurzum", + "BlackMetalDarkFuneral", + "BlackMetalGorgoroth", + "BlackMetalImmortal", + "BlackMetalKhold", + "BlackMetalMarduk", + "BlackMetalMayhem", + "BlackMetalNile", + "BlackMetalVenom", + "BlackMetal", + "Blueforest", + "Blueish", + "Brewer", + "Bright", + "Brogrammer", + "BrushtreesDark", + "Brushtrees", + "Caroline", + "CatppuccinFrappe", + "CatppuccinLatte", + "CatppuccinMacchiato", + "CatppuccinMocha", + "Chalk", + "Circus", + "ClassicDark", + "ClassicLight", + "Codeschool", + "Colors", + "Cupcake", + "Cupertino", + "DaOneBlack", + "DaOneGray", + "DaOneOcean", + "DaOnePaper", + "DaOneSea", + "DaOneWhite", + "DanqingLight", + "Danqing", + "Darcula", + "Darkmoss", + "Darktooth", + "Darkviolet", + "Decaf", + "DefaultDark", + "DefaultLight", + "Dirtysea", + "Dracula", + "EdgeDark", + "EdgeLight", + "Eighties", + "EmbersLight", + "Embers", + "Emil", + "EquilibriumDark", + "EquilibriumGrayDark", + "EquilibriumGrayLight", + "EquilibriumLight", + "Eris", + "Espresso", + "EvaDim", + "Eva", + "EvenokDark", + "EverforestDarkHard", + "Everforest", + "Flat", + "Framer", + "FruitSoda", + "Gigavolt", + "Github", + "GoogleDark", + "GoogleLight", + "Gotham", + "GrayscaleDark", + "GrayscaleLight", + "Greenscreen", + "Gruber", + "GruvboxDarkHard", + "GruvboxDarkMedium", + "GruvboxDarkPale", + "GruvboxDarkSoft", + "GruvboxLightHard", + "GruvboxLightMedium", + "GruvboxLightSoft", + "GruvboxMaterialDarkHard", + "GruvboxMaterialDarkMedium", + "GruvboxMaterialDarkSoft", + "GruvboxMaterialLightHard", + "GruvboxMaterialLightMedium", + "GruvboxMaterialLightSoft", + "Hardcore", + "Harmonic16Dark", + "Harmonic16Light", + "HeetchLight", + "Heetch", + "Helios", + "Hopscotch", + "HorizonDark", + "HorizonLight", + "HorizonTerminalDark", + "HorizonTerminalLight", + "HumanoidDark", + "HumanoidLight", + "IaDark", + "IaLight", + "Icy", + "Irblack", + "Isotope", + "Jabuti", + "Kanagawa", + "Katy", + "Kimber", + "Lime", + "Macintosh", + "Marrakesh", + "Materia", + "MaterialDarker", + "MaterialLighter", + "MaterialPalenight", + "MaterialVivid", + "Material", + "MeasuredDark", + "MeasuredLight", + "MellowPurple", + "MexicoLight", + "Mocha", + "Monokai", + "Moonlight", + "Mountain", + "Nebula", + "NordLight", + "Nord", + "Nova", + "Ocean", + "Oceanicnext", + "OneLight", + "OnedarkDark", + "Onedark", + "OutrunDark", + "OxocarbonDark", + "OxocarbonLight", + "Pandora", + "PapercolorDark", + "PapercolorLight", + "Paraiso", + "Pasque", + "Phd", + "Pico", + "Pinky", + "Pop", + "Porple", + "PreciousDarkEleven", + "PreciousDarkFifteen", + "PreciousLightWarm", + "PreciousLightWhite", + "PrimerDarkDimmed", + "PrimerDark", + "PrimerLight", + "Purpledream", + "Qualia", + "Railscasts", + "Rebecca", + "RosePineDawn", + "RosePineMoon", + "RosePine", + "Saga", + "Sagelight", + "Sakura", + "Sandcastle", + "SelenizedBlack", + "SelenizedDark", + "SelenizedLight", + "SelenizedWhite", + "Seti", + "ShadesOfPurple", + "ShadesmearDark", + "ShadesmearLight", + "Shapeshifter", + "SilkDark", + "SilkLight", + "Snazzy", + "SolarflareLight", + "Solarflare", + "SolarizedDark", + "SolarizedLight", + "Spaceduck", + "Spacemacs", + "Sparky", + "StandardizedDark", + "StandardizedLight", + "Stella", + "StillAlive", + "Summercamp", + "SummerfruitDark", + "SummerfruitLight", + "SynthMidnightDark", + "SynthMidnightLight", + "Tango", + "Tarot", + "Tender", + "TerracottaDark", + "Terracotta", + "TokyoCityDark", + "TokyoCityLight", + "TokyoCityTerminalDark", + "TokyoCityTerminalLight", + "TokyoNightDark", + "TokyoNightLight", + "TokyoNightMoon", + "TokyoNightStorm", + "TokyoNightTerminalDark", + "TokyoNightTerminalLight", + "TokyoNightTerminalStorm", + "TokyodarkTerminal", + "Tokyodark", + "TomorrowNightEighties", + "TomorrowNight", + "Tomorrow", + "Tube", + "Twilight", + "UnikittyDark", + "UnikittyLight", + "UnikittyReversible", + "Uwunicorn", + "Vesper", + "Vice", + "Vulcan", + "Windows10Light", + "Windows10", + "Windows95Light", + "Windows95", + "WindowsHighcontrastLight", + "WindowsHighcontrast", + "WindowsNtLight", + "WindowsNt", + "Woodland", + "XcodeDusk", + "Zenbones", + "Zenburn" + ] + }, + "type": { + "type": "string", + "enum": [ + "Base16" + ] + } + } } ] },