fix(appearance): use same theme border radius for dock and panel.
This commit is contained in:
parent
2d83b22a56
commit
1deda477d9
2 changed files with 99 additions and 2 deletions
|
|
@ -23,6 +23,7 @@ use cosmic::widget::{
|
||||||
};
|
};
|
||||||
use cosmic::Apply;
|
use cosmic::Apply;
|
||||||
use cosmic::{command, Command, Element};
|
use cosmic::{command, Command, Element};
|
||||||
|
use cosmic_panel_config::CosmicPanelConfig;
|
||||||
use cosmic_settings_page::Section;
|
use cosmic_settings_page::Section;
|
||||||
use cosmic_settings_page::{self as page, section};
|
use cosmic_settings_page::{self as page, section};
|
||||||
use cosmic_settings_wallpaper as wallpaper;
|
use cosmic_settings_wallpaper as wallpaper;
|
||||||
|
|
@ -72,6 +73,10 @@ pub struct Page {
|
||||||
interface_text: ColorPickerModel,
|
interface_text: ColorPickerModel,
|
||||||
control_component: ColorPickerModel,
|
control_component: ColorPickerModel,
|
||||||
roundness: Roundness,
|
roundness: Roundness,
|
||||||
|
dock_config_helper: Option<Config>,
|
||||||
|
dock_config: Option<CosmicPanelConfig>,
|
||||||
|
panel_config_helper: Option<Config>,
|
||||||
|
panel_config: Option<CosmicPanelConfig>,
|
||||||
|
|
||||||
icon_theme_active: Option<usize>,
|
icon_theme_active: Option<usize>,
|
||||||
icon_themes: IconThemes,
|
icon_themes: IconThemes,
|
||||||
|
|
@ -149,6 +154,17 @@ impl
|
||||||
&& c != theme.palette.accent_yellow
|
&& c != theme.palette.accent_yellow
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let panel_config_helper = CosmicPanelConfig::cosmic_config("Panel").ok();
|
||||||
|
let dock_config_helper = CosmicPanelConfig::cosmic_config("Dock").ok();
|
||||||
|
let panel_config = panel_config_helper.as_ref().and_then(|config_helper| {
|
||||||
|
let panel_config = CosmicPanelConfig::get_entry(config_helper).ok()?;
|
||||||
|
(panel_config.name == "Panel").then_some(panel_config)
|
||||||
|
});
|
||||||
|
let dock_config = dock_config_helper.as_ref().and_then(|config_helper| {
|
||||||
|
let panel_config = CosmicPanelConfig::get_entry(config_helper).ok()?;
|
||||||
|
(panel_config.name == "Dock").then_some(panel_config)
|
||||||
|
});
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
can_reset: if theme_mode.is_dark {
|
can_reset: if theme_mode.is_dark {
|
||||||
theme_builder == ThemeBuilder::dark()
|
theme_builder == ThemeBuilder::dark()
|
||||||
|
|
@ -158,6 +174,10 @@ impl
|
||||||
theme_builder_needs_update: false,
|
theme_builder_needs_update: false,
|
||||||
context_view: None,
|
context_view: None,
|
||||||
roundness: theme_builder.corner_radii.into(),
|
roundness: theme_builder.corner_radii.into(),
|
||||||
|
dock_config_helper,
|
||||||
|
dock_config,
|
||||||
|
panel_config_helper,
|
||||||
|
panel_config,
|
||||||
custom_accent: ColorPickerModel::new(
|
custom_accent: ColorPickerModel::new(
|
||||||
&*HEX,
|
&*HEX,
|
||||||
&*RGB,
|
&*RGB,
|
||||||
|
|
@ -622,6 +642,7 @@ impl Page {
|
||||||
self.roundness = r;
|
self.roundness = r;
|
||||||
self.theme_builder.corner_radii = self.roundness.into();
|
self.theme_builder.corner_radii = self.roundness.into();
|
||||||
self.theme_builder_needs_update = true;
|
self.theme_builder_needs_update = true;
|
||||||
|
self.update_panel_radii(r);
|
||||||
Command::none()
|
Command::none()
|
||||||
}
|
}
|
||||||
Message::Entered((icon_themes, icon_handles)) => {
|
Message::Entered((icon_themes, icon_handles)) => {
|
||||||
|
|
@ -987,6 +1008,38 @@ impl Page {
|
||||||
_ => Command::none(),
|
_ => Command::none(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn update_panel_radii(&mut self, roundness: Roundness) {
|
||||||
|
if let Some(panel_config_helper) = self.panel_config_helper.as_ref() {
|
||||||
|
if let Some(panel_config) = self.panel_config.as_mut() {
|
||||||
|
let radii = if panel_config.anchor_gap || !panel_config.expand_to_edges {
|
||||||
|
let cornder_radii: CornerRadii = roundness.into();
|
||||||
|
cornder_radii.radius_xl[0] as u32
|
||||||
|
} else {
|
||||||
|
0
|
||||||
|
};
|
||||||
|
let update = panel_config.set_border_radius(panel_config_helper, radii);
|
||||||
|
if let Err(err) = update {
|
||||||
|
tracing::error!(?err, "Error updating panel corner radii");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Some(dock_config_helper) = self.dock_config_helper.as_ref() {
|
||||||
|
if let Some(dock_config) = self.dock_config.as_mut() {
|
||||||
|
let radii = if dock_config.anchor_gap || !dock_config.expand_to_edges {
|
||||||
|
let cornder_radii: CornerRadii = roundness.into();
|
||||||
|
cornder_radii.radius_xl[0] as u32
|
||||||
|
} else {
|
||||||
|
0
|
||||||
|
};
|
||||||
|
let update = dock_config.set_border_radius(dock_config_helper, radii);
|
||||||
|
if let Err(err) = update {
|
||||||
|
tracing::error!(?err, "Error updating dock corner radii");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl page::Page<crate::pages::Message> for Page {
|
impl page::Page<crate::pages::Message> for Page {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
use cosmic::{
|
use cosmic::{
|
||||||
cctk::sctk::reexports::client::{backend::ObjectId, protocol::wl_output::WlOutput, Proxy},
|
cctk::sctk::reexports::client::{backend::ObjectId, protocol::wl_output::WlOutput, Proxy},
|
||||||
cosmic_config::{self, CosmicConfigEntry},
|
cosmic_config::{self, Config, CosmicConfigEntry},
|
||||||
|
cosmic_theme::{CornerRadii, ThemeBuilder, ThemeMode},
|
||||||
iced::Length,
|
iced::Length,
|
||||||
theme,
|
theme,
|
||||||
widget::{
|
widget::{
|
||||||
|
|
@ -502,11 +503,54 @@ impl PageInner {
|
||||||
}
|
}
|
||||||
|
|
||||||
if panel_config.anchor_gap || !panel_config.expand_to_edges {
|
if panel_config.anchor_gap || !panel_config.expand_to_edges {
|
||||||
panel_config.border_radius = 8;
|
let radii = Self::get_corner_radii().radius_xl[0] as u32;
|
||||||
|
panel_config.border_radius = radii;
|
||||||
} else {
|
} else {
|
||||||
panel_config.border_radius = 0;
|
panel_config.border_radius = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = panel_config.write_entry(helper);
|
_ = panel_config.write_entry(helper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_corner_radii() -> CornerRadii {
|
||||||
|
let theme_mode_config = ThemeMode::config().ok();
|
||||||
|
let theme_mode = theme_mode_config
|
||||||
|
.as_ref()
|
||||||
|
.map(|c| match ThemeMode::get_entry(c) {
|
||||||
|
Ok(t) => t,
|
||||||
|
Err((errors, t)) => {
|
||||||
|
for e in errors {
|
||||||
|
tracing::error!("{e}");
|
||||||
|
}
|
||||||
|
t
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.unwrap_or_default();
|
||||||
|
|
||||||
|
let theme_builder_config = if theme_mode.is_dark {
|
||||||
|
ThemeBuilder::dark_config()
|
||||||
|
} else {
|
||||||
|
ThemeBuilder::light_config()
|
||||||
|
}
|
||||||
|
.ok();
|
||||||
|
let theme_builder = theme_builder_config.as_ref().map_or_else(
|
||||||
|
|| {
|
||||||
|
if theme_mode.is_dark {
|
||||||
|
ThemeBuilder::dark()
|
||||||
|
} else {
|
||||||
|
ThemeBuilder::light()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|c| match ThemeBuilder::get_entry(c) {
|
||||||
|
Ok(t) => t,
|
||||||
|
Err((errors, t)) => {
|
||||||
|
for e in errors {
|
||||||
|
tracing::error!("{e}");
|
||||||
|
}
|
||||||
|
t
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
theme_builder.corner_radii
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue