mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-04-25 10:08:33 +02:00
fix(bar): handle komorebi theme change properly
Previously if we changed/set the theme on `komorebi.json` it would apply that theme to the bar without taking into account the transparency alpha, also after removing the `theme` from `komorebi.json` file it wasn't applying the theme from the bar config. This commit fixes these issues.
This commit is contained in:
@@ -59,7 +59,7 @@ pub struct Komobar {
|
|||||||
pub scale_factor: f32,
|
pub scale_factor: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn apply_theme(ctx: &Context, theme: KomobarTheme, bg_color: Rc<RefCell<Color32>>) {
|
pub fn apply_theme(ctx: &Context, theme: KomobarTheme, bg_color: Rc<RefCell<Color32>>, transparency_alpha: Option<u8>) {
|
||||||
match theme {
|
match theme {
|
||||||
KomobarTheme::Catppuccin {
|
KomobarTheme::Catppuccin {
|
||||||
name: catppuccin,
|
name: catppuccin,
|
||||||
@@ -139,6 +139,12 @@ pub fn apply_theme(ctx: &Context, theme: KomobarTheme, bg_color: Rc<RefCell<Colo
|
|||||||
bg_color.replace(base16.background());
|
bg_color.replace(base16.background());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Apply transparency_alpha
|
||||||
|
let theme_color = *bg_color.borrow();
|
||||||
|
|
||||||
|
bg_color
|
||||||
|
.replace(theme_color.try_apply_alpha(transparency_alpha));
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Komobar {
|
impl Komobar {
|
||||||
@@ -204,7 +210,7 @@ impl Komobar {
|
|||||||
|
|
||||||
match config.theme {
|
match config.theme {
|
||||||
Some(theme) => {
|
Some(theme) => {
|
||||||
apply_theme(ctx, theme, self.bg_color.clone());
|
apply_theme(ctx, theme, self.bg_color.clone(), config.transparency_alpha);
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
let home_dir: PathBuf = std::env::var("KOMOREBI_CONFIG_HOME").map_or_else(
|
let home_dir: PathBuf = std::env::var("KOMOREBI_CONFIG_HOME").map_or_else(
|
||||||
@@ -224,7 +230,7 @@ impl Komobar {
|
|||||||
match komorebi_client::StaticConfig::read(&config) {
|
match komorebi_client::StaticConfig::read(&config) {
|
||||||
Ok(config) => {
|
Ok(config) => {
|
||||||
if let Some(theme) = config.theme {
|
if let Some(theme) = config.theme {
|
||||||
apply_theme(ctx, KomobarTheme::from(theme), self.bg_color.clone());
|
apply_theme(ctx, KomobarTheme::from(theme), self.bg_color.clone(), config.transparency_alpha);
|
||||||
|
|
||||||
let stack_accent = match theme {
|
let stack_accent = match theme {
|
||||||
KomorebiTheme::Catppuccin {
|
KomorebiTheme::Catppuccin {
|
||||||
@@ -266,18 +272,13 @@ impl Komobar {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let theme_color = *self.bg_color.borrow();
|
|
||||||
|
|
||||||
self.bg_color
|
|
||||||
.replace(theme_color.try_apply_alpha(config.transparency_alpha));
|
|
||||||
|
|
||||||
if let Some(font_size) = &config.font_size {
|
if let Some(font_size) = &config.font_size {
|
||||||
tracing::info!("attempting to set custom font size: {font_size}");
|
tracing::info!("attempting to set custom font size: {font_size}");
|
||||||
Self::set_font_size(ctx, *font_size);
|
Self::set_font_size(ctx, *font_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.render_config
|
self.render_config
|
||||||
.replace(config.new_renderconfig(ctx, theme_color));
|
.replace(config.new_renderconfig(ctx, *self.bg_color.borrow()));
|
||||||
|
|
||||||
let mut komorebi_notification_state = previous_notification_state;
|
let mut komorebi_notification_state = previous_notification_state;
|
||||||
let mut komorebi_widgets = Vec::new();
|
let mut komorebi_widgets = Vec::new();
|
||||||
@@ -476,6 +477,8 @@ impl eframe::App for Komobar {
|
|||||||
self.config.monitor.index,
|
self.config.monitor.index,
|
||||||
self.rx_gui.clone(),
|
self.rx_gui.clone(),
|
||||||
self.bg_color.clone(),
|
self.bg_color.clone(),
|
||||||
|
self.config.transparency_alpha,
|
||||||
|
self.config.theme,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -496,6 +496,8 @@ impl KomorebiNotificationState {
|
|||||||
monitor_index: usize,
|
monitor_index: usize,
|
||||||
rx_gui: Receiver<komorebi_client::Notification>,
|
rx_gui: Receiver<komorebi_client::Notification>,
|
||||||
bg_color: Rc<RefCell<Color32>>,
|
bg_color: Rc<RefCell<Color32>>,
|
||||||
|
transparency_alpha: Option<u8>,
|
||||||
|
default_theme: Option<KomobarTheme>,
|
||||||
) {
|
) {
|
||||||
match rx_gui.try_recv() {
|
match rx_gui.try_recv() {
|
||||||
Err(error) => match error {
|
Err(error) => match error {
|
||||||
@@ -513,13 +515,33 @@ impl KomorebiNotificationState {
|
|||||||
SocketMessage::ReloadStaticConfiguration(path) => {
|
SocketMessage::ReloadStaticConfiguration(path) => {
|
||||||
if let Ok(config) = komorebi_client::StaticConfig::read(&path) {
|
if let Ok(config) = komorebi_client::StaticConfig::read(&path) {
|
||||||
if let Some(theme) = config.theme {
|
if let Some(theme) = config.theme {
|
||||||
apply_theme(ctx, KomobarTheme::from(theme), bg_color.clone());
|
apply_theme(
|
||||||
|
ctx,
|
||||||
|
KomobarTheme::from(theme),
|
||||||
|
bg_color.clone(),
|
||||||
|
transparency_alpha,
|
||||||
|
);
|
||||||
tracing::info!("applied theme from updated komorebi.json");
|
tracing::info!("applied theme from updated komorebi.json");
|
||||||
|
} else if let Some(default_theme) = default_theme {
|
||||||
|
apply_theme(
|
||||||
|
ctx,
|
||||||
|
default_theme,
|
||||||
|
bg_color.clone(),
|
||||||
|
transparency_alpha,
|
||||||
|
);
|
||||||
|
tracing::info!("removed theme from updated komorebi.json and applied default theme");
|
||||||
|
} else {
|
||||||
|
tracing::warn!("theme was removed from updated komorebi.json but there was no default theme to apply");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SocketMessage::Theme(theme) => {
|
SocketMessage::Theme(theme) => {
|
||||||
apply_theme(ctx, KomobarTheme::from(theme), bg_color);
|
apply_theme(
|
||||||
|
ctx,
|
||||||
|
KomobarTheme::from(theme),
|
||||||
|
bg_color,
|
||||||
|
transparency_alpha,
|
||||||
|
);
|
||||||
tracing::info!("applied theme from komorebi socket message");
|
tracing::info!("applied theme from komorebi socket message");
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
|
|||||||
Reference in New Issue
Block a user