Get COSMIC theme background color from configured app theme
This commit is contained in:
parent
72c97fd5fc
commit
80e8743ddc
1 changed files with 25 additions and 32 deletions
57
src/main.rs
57
src/main.rs
|
|
@ -357,11 +357,22 @@ pub struct App {
|
||||||
|
|
||||||
impl App {
|
impl App {
|
||||||
fn update_config(&mut self) -> Command<Message> {
|
fn update_config(&mut self) -> Command<Message> {
|
||||||
//TODO: provide iterator over data
|
let theme = self.config.app_theme.theme();
|
||||||
let panes: Vec<_> = self.pane_model.panes.iter().collect();
|
|
||||||
for (_pane, tab_model) in panes {
|
// Update terminal window background color
|
||||||
let entities: Vec<_> = tab_model.iter().collect();
|
{
|
||||||
for entity in entities {
|
let color = Color::from(theme.cosmic().background.base);
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set config of all tabs
|
||||||
|
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) {
|
if let Some(terminal) = tab_model.data::<Mutex<Terminal>>(entity) {
|
||||||
let mut terminal = terminal.lock().unwrap();
|
let mut terminal = terminal.lock().unwrap();
|
||||||
terminal.set_config(&self.config, &self.themes, self.zoom_adj);
|
terminal.set_config(&self.config, &self.themes, self.zoom_adj);
|
||||||
|
|
@ -369,8 +380,11 @@ impl App {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set headerbar state
|
||||||
self.core.window.show_headerbar = self.config.show_headerbar;
|
self.core.window.show_headerbar = self.config.show_headerbar;
|
||||||
cosmic::app::command::set_theme(self.config.app_theme.theme())
|
|
||||||
|
// Update application theme
|
||||||
|
cosmic::app::command::set_theme(theme)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn save_config(&mut self) -> Command<Message> {
|
fn save_config(&mut self) -> Command<Message> {
|
||||||
|
|
@ -1085,7 +1099,10 @@ impl Application for App {
|
||||||
};
|
};
|
||||||
|
|
||||||
app.set_curr_font_weights_and_stretches();
|
app.set_curr_font_weights_and_stretches();
|
||||||
let command = app.update_title(None);
|
let command = Command::batch([
|
||||||
|
app.update_config(),
|
||||||
|
app.update_title(None)
|
||||||
|
]);
|
||||||
|
|
||||||
(app, command)
|
(app, command)
|
||||||
}
|
}
|
||||||
|
|
@ -1785,31 +1802,7 @@ impl Application for App {
|
||||||
|
|
||||||
/// Creates a view after each update.
|
/// Creates a view after each update.
|
||||||
fn view(&self) -> Element<Self::Message> {
|
fn view(&self) -> Element<Self::Message> {
|
||||||
let cosmic_theme = self.core().system_theme().cosmic();
|
let cosmic_theme::Spacing { space_xxs, .. } = self.core().system_theme().cosmic().spacing;
|
||||||
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.background.base);
|
|
||||||
let bytes = color.into_rgba8();
|
|
||||||
let data = (bytes[2] as u32)
|
|
||||||
| ((bytes[1] as u32) << 8)
|
|
||||||
| ((bytes[0] as u32) << 16)
|
|
||||||
| 0xFF000000;
|
|
||||||
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 pane_grid = PaneGrid::new(&self.pane_model.panes, |pane, tab_model, _is_maximized| {
|
||||||
let mut tab_column = widget::column::with_capacity(1);
|
let mut tab_column = widget::column::with_capacity(1);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue