Ensure metadata is updated when theme changes, fixes #121
This commit is contained in:
parent
bf7668dbd7
commit
46cae2f2d3
2 changed files with 32 additions and 15 deletions
17
src/main.rs
17
src/main.rs
|
|
@ -118,7 +118,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
}
|
||||
|
||||
let startup_options = if let Some(shell_program) = shell_program_opt {
|
||||
let options = tty::Options {
|
||||
let options = tty::Options {
|
||||
shell: Some(tty::Shell::new(shell_program, shell_args)),
|
||||
..tty::Options::default()
|
||||
};
|
||||
|
|
@ -1471,13 +1471,26 @@ impl Application for App {
|
|||
let cosmic_theme = self.core().system_theme().cosmic();
|
||||
let cosmic_theme::Spacing { space_xxs, .. } = cosmic_theme.spacing;
|
||||
{
|
||||
// Update terminal window color
|
||||
//TODO: do this only when theme changes?
|
||||
let color = Color::from(cosmic_theme.bg_color());
|
||||
let bytes = color.into_rgba8();
|
||||
let data = (bytes[2] as u32)
|
||||
| ((bytes[1] as u32) << 8)
|
||||
| ((bytes[0] as u32) << 16)
|
||||
| 0xFF000000;
|
||||
terminal::WINDOW_BG_COLOR.store(data, Ordering::SeqCst);
|
||||
if terminal::WINDOW_BG_COLOR.swap(data, Ordering::SeqCst) != data {
|
||||
// If window bg color changed, update terminal colors
|
||||
for (_pane, tab_model) in self.pane_model.panes.iter() {
|
||||
for entity in tab_model.iter() {
|
||||
if let Some(terminal) = tab_model.data::<Mutex<Terminal>>(entity) {
|
||||
let mut terminal = terminal.lock().unwrap();
|
||||
terminal.update_colors(&self.config);
|
||||
terminal.update();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
let pane_grid = PaneGrid::new(&self.pane_model.panes, |pane, tab_model, _is_maximized| {
|
||||
let mut tab_column = widget::column::with_capacity(1);
|
||||
|
|
|
|||
|
|
@ -559,19 +559,7 @@ impl Terminal {
|
|||
}
|
||||
}
|
||||
if changed {
|
||||
self.metadata_set.clear();
|
||||
let default_bg = convert_color(colors, Color::Named(NamedColor::Background));
|
||||
let default_fg = convert_color(colors, Color::Named(NamedColor::Foreground));
|
||||
|
||||
let default_metadata = Metadata::new(default_bg, default_fg);
|
||||
let (default_metadata_idx, _) = self.metadata_set.insert_full(default_metadata);
|
||||
|
||||
self.default_attrs = Attrs::new()
|
||||
.family(Family::Monospace)
|
||||
.weight(Weight(config.font_weight))
|
||||
.stretch(config.typed_font_stretch())
|
||||
.color(default_fg)
|
||||
.metadata(default_metadata_idx);
|
||||
self.update_colors(config);
|
||||
update = true;
|
||||
}
|
||||
}
|
||||
|
|
@ -583,6 +571,22 @@ impl Terminal {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn update_colors(&mut self, config: &AppConfig) {
|
||||
self.metadata_set.clear();
|
||||
let default_bg = convert_color(&self.colors, Color::Named(NamedColor::Background));
|
||||
let default_fg = convert_color(&self.colors, Color::Named(NamedColor::Foreground));
|
||||
|
||||
let default_metadata = Metadata::new(default_bg, default_fg);
|
||||
let (default_metadata_idx, _) = self.metadata_set.insert_full(default_metadata);
|
||||
|
||||
self.default_attrs = Attrs::new()
|
||||
.family(Family::Monospace)
|
||||
.weight(Weight(config.font_weight))
|
||||
.stretch(config.typed_font_stretch())
|
||||
.color(default_fg)
|
||||
.metadata(default_metadata_idx);
|
||||
}
|
||||
|
||||
pub fn update_cell_size(&mut self) {
|
||||
let default_attrs = self.default_attrs;
|
||||
let (cell_width, cell_height) = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue