fix(panel): update defaults with shrinkable applets appearance fixes
This commit is contained in:
parent
8fd1f281da
commit
41e90bde33
5 changed files with 265 additions and 179 deletions
|
|
@ -278,6 +278,7 @@ impl Page {
|
|||
#[cfg(feature = "wayland")]
|
||||
tokio::task::spawn(async move {
|
||||
Self::update_panel_radii(r);
|
||||
Self::update_dock_padding(r);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -538,7 +539,7 @@ impl Page {
|
|||
|
||||
// TODO: cache panel and dock configs so that they needn't be re-read
|
||||
#[cfg(feature = "wayland")]
|
||||
fn update_panel_radii(roundness: Roundness) {
|
||||
pub fn update_panel_radii(roundness: Roundness) {
|
||||
let panel_config_helper = CosmicPanelConfig::cosmic_config("Panel").ok();
|
||||
let dock_config_helper = CosmicPanelConfig::cosmic_config("Dock").ok();
|
||||
|
||||
|
|
@ -555,9 +556,11 @@ impl Page {
|
|||
if let Some(panel_config_helper) = panel_config_helper.as_ref()
|
||||
&& let Some(panel_config) = panel_config.as_mut()
|
||||
{
|
||||
let radii = if panel_config.anchor_gap || !panel_config.expand_to_edges {
|
||||
let radii = if panel_config.anchor_gap {
|
||||
let cornder_radii: CornerRadii = roundness.into();
|
||||
cornder_radii.radius_xl[0] as u32
|
||||
} else if matches!(roundness, Roundness::Round) && !panel_config.expand_to_edges {
|
||||
12
|
||||
} else {
|
||||
0
|
||||
};
|
||||
|
|
@ -565,14 +568,16 @@ impl Page {
|
|||
if let Err(why) = panel_config.set_border_radius(panel_config_helper, radii) {
|
||||
tracing::error!(?why, "Error updating panel corner radii");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if let Some(dock_config_helper) = dock_config_helper.as_ref()
|
||||
&& let Some(dock_config) = dock_config.as_mut()
|
||||
{
|
||||
let radii = if dock_config.anchor_gap || !dock_config.expand_to_edges {
|
||||
let radii = if dock_config.anchor_gap {
|
||||
let cornder_radii: CornerRadii = roundness.into();
|
||||
cornder_radii.radius_xl[0] as u32
|
||||
} else if matches!(roundness, Roundness::Round) && !dock_config.expand_to_edges {
|
||||
12
|
||||
} else {
|
||||
0
|
||||
};
|
||||
|
|
@ -580,11 +585,37 @@ impl Page {
|
|||
if let Err(why) = dock_config.set_border_radius(dock_config_helper, radii) {
|
||||
tracing::error!(?why, "Error updating dock corner radii");
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update_dock_padding(roundness: Roundness) {
|
||||
let dock_config_helper = CosmicPanelConfig::cosmic_config("Dock").ok();
|
||||
|
||||
let mut 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)
|
||||
});
|
||||
|
||||
if let Some(dock_config_helper) = dock_config_helper.as_ref() {
|
||||
if let Some(dock_config) = dock_config.as_mut() {
|
||||
let padding = match roundness {
|
||||
Roundness::Round => 4,
|
||||
Roundness::SlightlyRound => 4,
|
||||
Roundness::Square => 0,
|
||||
};
|
||||
|
||||
if let Err(why) = dock_config.set_padding(dock_config_helper, padding) {
|
||||
tracing::error!(?why, "Error updating dock padding");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: cache panel and dock configs so that they needn't be re-read
|
||||
#[cfg(feature = "wayland")]
|
||||
fn update_panel_spacing(density: Density) {
|
||||
pub fn update_panel_spacing(density: Density) {
|
||||
let spacing: cosmic::cosmic_theme::Spacing = density.into();
|
||||
let space_none = spacing.space_none;
|
||||
let panel_config_helper = CosmicPanelConfig::cosmic_config("Panel").ok();
|
||||
let dock_config_helper = CosmicPanelConfig::cosmic_config("Dock").ok();
|
||||
let mut panel_config = panel_config_helper.as_ref().and_then(|config_helper| {
|
||||
|
|
@ -599,11 +630,7 @@ impl Page {
|
|||
if let Some(panel_config_helper) = panel_config_helper.as_ref()
|
||||
&& let Some(panel_config) = panel_config.as_mut()
|
||||
{
|
||||
let spacing = match density {
|
||||
Density::Compact => 0,
|
||||
_ => 4,
|
||||
};
|
||||
let update = panel_config.set_spacing(panel_config_helper, spacing);
|
||||
let update = panel_config.set_spacing(panel_config_helper, space_none as u32);
|
||||
if let Err(err) = update {
|
||||
tracing::error!(?err, "Error updating panel spacing");
|
||||
}
|
||||
|
|
@ -612,11 +639,7 @@ impl Page {
|
|||
if let Some(dock_config_helper) = dock_config_helper.as_ref()
|
||||
&& let Some(dock_config) = dock_config.as_mut()
|
||||
{
|
||||
let spacing = match density {
|
||||
Density::Compact => 0,
|
||||
_ => 4,
|
||||
};
|
||||
let update = dock_config.set_spacing(dock_config_helper, spacing);
|
||||
let update = dock_config.set_spacing(dock_config_helper, space_none as u32);
|
||||
if let Err(err) = update {
|
||||
tracing::error!(?err, "Error updating dock spacing");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -218,4 +218,10 @@ impl page::Page<crate::pages::Message> for Page {
|
|||
.title(fl!("dock"))
|
||||
.description(fl!("dock", "desc"))
|
||||
}
|
||||
|
||||
fn on_enter(&mut self) -> Task<crate::pages::Message> {
|
||||
self.inner.update_defaults();
|
||||
|
||||
Task::none()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ use cosmic::{
|
|||
Element, Task,
|
||||
cctk::sctk::reexports::client::{Proxy, backend::ObjectId, protocol::wl_output::WlOutput},
|
||||
cosmic_config::{self, CosmicConfigEntry},
|
||||
cosmic_theme::Density,
|
||||
iced::{Alignment, Length},
|
||||
surface, theme,
|
||||
widget::{
|
||||
|
|
@ -19,6 +20,8 @@ use cosmic_settings_page::{self as page, Section};
|
|||
use slab::Slab;
|
||||
use std::{collections::HashMap, time::Duration};
|
||||
|
||||
use crate::pages::desktop::appearance::Roundness;
|
||||
|
||||
pub struct PageInner {
|
||||
pub(crate) config_helper: Option<cosmic_config::Config>,
|
||||
pub(crate) panel_config: Option<CosmicPanelConfig>,
|
||||
|
|
@ -437,6 +440,43 @@ pub enum Message {
|
|||
}
|
||||
|
||||
impl PageInner {
|
||||
pub(crate) fn update_defaults(&mut self) {
|
||||
let theme = cosmic::theme::system_preference();
|
||||
let theme = theme.cosmic();
|
||||
|
||||
let Some(default) = self.system_default.as_mut() else {
|
||||
return;
|
||||
};
|
||||
|
||||
let radius = theme.corner_radii;
|
||||
let roundness: Roundness = radius.into();
|
||||
|
||||
if default.anchor_gap {
|
||||
let radii = theme.corner_radii.radius_xl[0] as u32;
|
||||
default.border_radius = radii;
|
||||
} else if matches!(roundness, Roundness::Round) && !default.expand_to_edges {
|
||||
default.border_radius = 12;
|
||||
} else {
|
||||
default.border_radius = 0;
|
||||
}
|
||||
|
||||
let spacing = theme.spacing;
|
||||
let density = Density::from(spacing);
|
||||
default.spacing = match density {
|
||||
Density::Compact => 0,
|
||||
Density::Standard => 0,
|
||||
Density::Spacious => 4,
|
||||
};
|
||||
|
||||
if self.panel_config.as_ref().is_some_and(|c| c.name == "Dock") {
|
||||
default.padding = match roundness {
|
||||
Roundness::Round => 4,
|
||||
Roundness::SlightlyRound => 4,
|
||||
Roundness::Square => 0,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_lines)]
|
||||
pub fn update(&mut self, message: Message) -> Task<Message> {
|
||||
let Some(helper) = self.config_helper.as_ref() else {
|
||||
|
|
@ -450,18 +490,24 @@ impl PageInner {
|
|||
.as_mut()
|
||||
.zip(self.config_helper.as_ref())
|
||||
{
|
||||
if default.anchor_gap || !default.expand_to_edges {
|
||||
let radii = cosmic::theme::system_preference()
|
||||
.cosmic()
|
||||
.corner_radii
|
||||
.radius_xl[0] as u32;
|
||||
let theme = cosmic::theme::system_preference();
|
||||
let theme = theme.cosmic();
|
||||
let radius = theme.corner_radii;
|
||||
let roundness: Roundness = radius.into();
|
||||
|
||||
if default.anchor_gap {
|
||||
let radii = theme.corner_radii.radius_xl[0] as u32;
|
||||
default.border_radius = radii;
|
||||
} else if matches!(roundness, Roundness::Round) && !default.expand_to_edges {
|
||||
default.border_radius = 12;
|
||||
} else {
|
||||
default.border_radius = 0;
|
||||
}
|
||||
|
||||
if let Err(err) = default.write_entry(config) {
|
||||
tracing::error!(?err, "Error resetting panel config.");
|
||||
}
|
||||
self.system_default = Some(default.clone());
|
||||
self.panel_config.clone_from(&self.system_default);
|
||||
} else {
|
||||
tracing::error!("Panel config default is missing.");
|
||||
|
|
@ -473,6 +519,21 @@ impl PageInner {
|
|||
{
|
||||
tracing::error!(?err, "Error fully resetting the panel config.");
|
||||
}
|
||||
// update the padding and spacing based on appearance
|
||||
let theme = cosmic::theme::system_preference();
|
||||
let theme = theme.cosmic();
|
||||
|
||||
let radius = theme.corner_radii;
|
||||
let roundness: Roundness = radius.into();
|
||||
crate::pages::desktop::appearance::Page::update_panel_radii(roundness);
|
||||
|
||||
let spacing = theme.spacing;
|
||||
let density = Density::from(spacing);
|
||||
crate::pages::desktop::appearance::Page::update_panel_spacing(density);
|
||||
|
||||
let radius = theme.corner_radii;
|
||||
let roundness: Roundness = radius.into();
|
||||
crate::pages::desktop::appearance::Page::update_dock_padding(roundness);
|
||||
}
|
||||
_ => {}
|
||||
};
|
||||
|
|
@ -528,6 +589,20 @@ impl PageInner {
|
|||
} else {
|
||||
_ = panel_config.set_margin(helper, 0);
|
||||
}
|
||||
let theme = cosmic::theme::system_preference();
|
||||
let theme = theme.cosmic();
|
||||
let radius = theme.corner_radii;
|
||||
let roundness: Roundness = radius.into();
|
||||
let new_radius;
|
||||
if enabled {
|
||||
let radii = theme.corner_radii.radius_xl[0] as u32;
|
||||
new_radius = radii;
|
||||
} else if matches!(roundness, Roundness::Round) && !panel_config.expand_to_edges {
|
||||
new_radius = 12;
|
||||
} else {
|
||||
new_radius = 0;
|
||||
}
|
||||
_ = panel_config.set_border_radius(helper, new_radius).unwrap();
|
||||
}
|
||||
Message::PanelSize(size) => {
|
||||
_ = panel_config.set_size(helper, size);
|
||||
|
|
@ -545,6 +620,21 @@ impl PageInner {
|
|||
}
|
||||
Message::ExtendToEdge(enabled) => {
|
||||
_ = panel_config.set_expand_to_edges(helper, enabled);
|
||||
|
||||
let theme = cosmic::theme::system_preference();
|
||||
let theme = theme.cosmic();
|
||||
let radius = theme.corner_radii;
|
||||
let roundness: Roundness = radius.into();
|
||||
let new_radius;
|
||||
if panel_config.anchor_gap {
|
||||
let radii = theme.corner_radii.radius_xl[0] as u32;
|
||||
new_radius = radii;
|
||||
} else if matches!(roundness, Roundness::Round) && !enabled {
|
||||
new_radius = 12;
|
||||
} else {
|
||||
new_radius = 0;
|
||||
}
|
||||
_ = panel_config.set_border_radius(helper, new_radius).unwrap();
|
||||
}
|
||||
Message::OpacityRequest(opacity) => {
|
||||
panel_config.opacity = opacity;
|
||||
|
|
@ -587,16 +677,6 @@ impl PageInner {
|
|||
}
|
||||
}
|
||||
|
||||
if panel_config.anchor_gap || !panel_config.expand_to_edges {
|
||||
let radii = cosmic::theme::system_preference()
|
||||
.cosmic()
|
||||
.corner_radii
|
||||
.radius_xl[0] as u32;
|
||||
_ = panel_config.set_border_radius(helper, radii);
|
||||
} else {
|
||||
_ = panel_config.set_border_radius(helper, 0);
|
||||
}
|
||||
|
||||
Task::none()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -139,4 +139,10 @@ impl page::Page<crate::pages::Message> for Page {
|
|||
.title(fl!("panel"))
|
||||
.description(fl!("panel", "desc"))
|
||||
}
|
||||
|
||||
fn on_enter(&mut self) -> Task<crate::pages::Message> {
|
||||
self.inner.update_defaults();
|
||||
|
||||
Task::none()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue