fix: sync light and dark theme changes
settings like corner roundness and window management settings need to be synced
This commit is contained in:
parent
020b038cab
commit
087c1e70d2
3 changed files with 131 additions and 24 deletions
32
Cargo.lock
generated
32
Cargo.lock
generated
|
|
@ -1086,7 +1086,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cosmic-config"
|
name = "cosmic-config"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic#2b23005fbff5a3d7e218a867e1aadb491abeac55"
|
source = "git+https://github.com/pop-os/libcosmic#3e6f314c6b003505ed06905eaf3e63f81f57f5a5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"atomicwrites",
|
"atomicwrites",
|
||||||
"calloop",
|
"calloop",
|
||||||
|
|
@ -1104,7 +1104,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cosmic-config-derive"
|
name = "cosmic-config-derive"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic#2b23005fbff5a3d7e218a867e1aadb491abeac55"
|
source = "git+https://github.com/pop-os/libcosmic#3e6f314c6b003505ed06905eaf3e63f81f57f5a5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"quote",
|
"quote",
|
||||||
"syn 1.0.109",
|
"syn 1.0.109",
|
||||||
|
|
@ -1273,7 +1273,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cosmic-theme"
|
name = "cosmic-theme"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic#2b23005fbff5a3d7e218a867e1aadb491abeac55"
|
source = "git+https://github.com/pop-os/libcosmic#3e6f314c6b003505ed06905eaf3e63f81f57f5a5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"almost",
|
"almost",
|
||||||
"cosmic-config",
|
"cosmic-config",
|
||||||
|
|
@ -2559,7 +2559,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced"
|
name = "iced"
|
||||||
version = "0.12.0"
|
version = "0.12.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic#2b23005fbff5a3d7e218a867e1aadb491abeac55"
|
source = "git+https://github.com/pop-os/libcosmic#3e6f314c6b003505ed06905eaf3e63f81f57f5a5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"iced_accessibility",
|
"iced_accessibility",
|
||||||
"iced_core",
|
"iced_core",
|
||||||
|
|
@ -2574,7 +2574,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_accessibility"
|
name = "iced_accessibility"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic#2b23005fbff5a3d7e218a867e1aadb491abeac55"
|
source = "git+https://github.com/pop-os/libcosmic#3e6f314c6b003505ed06905eaf3e63f81f57f5a5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"accesskit",
|
"accesskit",
|
||||||
"accesskit_unix",
|
"accesskit_unix",
|
||||||
|
|
@ -2583,7 +2583,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_core"
|
name = "iced_core"
|
||||||
version = "0.12.0"
|
version = "0.12.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic#2b23005fbff5a3d7e218a867e1aadb491abeac55"
|
source = "git+https://github.com/pop-os/libcosmic#3e6f314c6b003505ed06905eaf3e63f81f57f5a5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 1.3.2",
|
"bitflags 1.3.2",
|
||||||
"iced_accessibility",
|
"iced_accessibility",
|
||||||
|
|
@ -2602,7 +2602,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_futures"
|
name = "iced_futures"
|
||||||
version = "0.12.0"
|
version = "0.12.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic#2b23005fbff5a3d7e218a867e1aadb491abeac55"
|
source = "git+https://github.com/pop-os/libcosmic#3e6f314c6b003505ed06905eaf3e63f81f57f5a5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"futures",
|
"futures",
|
||||||
"iced_core",
|
"iced_core",
|
||||||
|
|
@ -2615,7 +2615,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_graphics"
|
name = "iced_graphics"
|
||||||
version = "0.12.0"
|
version = "0.12.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic#2b23005fbff5a3d7e218a867e1aadb491abeac55"
|
source = "git+https://github.com/pop-os/libcosmic#3e6f314c6b003505ed06905eaf3e63f81f57f5a5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 1.3.2",
|
"bitflags 1.3.2",
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
|
|
@ -2639,7 +2639,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_renderer"
|
name = "iced_renderer"
|
||||||
version = "0.12.0"
|
version = "0.12.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic#2b23005fbff5a3d7e218a867e1aadb491abeac55"
|
source = "git+https://github.com/pop-os/libcosmic#3e6f314c6b003505ed06905eaf3e63f81f57f5a5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"iced_graphics",
|
"iced_graphics",
|
||||||
"iced_tiny_skia",
|
"iced_tiny_skia",
|
||||||
|
|
@ -2651,7 +2651,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_runtime"
|
name = "iced_runtime"
|
||||||
version = "0.12.0"
|
version = "0.12.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic#2b23005fbff5a3d7e218a867e1aadb491abeac55"
|
source = "git+https://github.com/pop-os/libcosmic#3e6f314c6b003505ed06905eaf3e63f81f57f5a5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"iced_accessibility",
|
"iced_accessibility",
|
||||||
"iced_core",
|
"iced_core",
|
||||||
|
|
@ -2663,7 +2663,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_sctk"
|
name = "iced_sctk"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic#2b23005fbff5a3d7e218a867e1aadb491abeac55"
|
source = "git+https://github.com/pop-os/libcosmic#3e6f314c6b003505ed06905eaf3e63f81f57f5a5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"enum-repr",
|
"enum-repr",
|
||||||
"float-cmp",
|
"float-cmp",
|
||||||
|
|
@ -2689,7 +2689,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_style"
|
name = "iced_style"
|
||||||
version = "0.12.0"
|
version = "0.12.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic#2b23005fbff5a3d7e218a867e1aadb491abeac55"
|
source = "git+https://github.com/pop-os/libcosmic#3e6f314c6b003505ed06905eaf3e63f81f57f5a5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"iced_core",
|
"iced_core",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
|
|
@ -2699,7 +2699,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_tiny_skia"
|
name = "iced_tiny_skia"
|
||||||
version = "0.12.0"
|
version = "0.12.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic#2b23005fbff5a3d7e218a867e1aadb491abeac55"
|
source = "git+https://github.com/pop-os/libcosmic#3e6f314c6b003505ed06905eaf3e63f81f57f5a5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
"cosmic-text",
|
"cosmic-text",
|
||||||
|
|
@ -2716,7 +2716,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_wgpu"
|
name = "iced_wgpu"
|
||||||
version = "0.12.0"
|
version = "0.12.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic#2b23005fbff5a3d7e218a867e1aadb491abeac55"
|
source = "git+https://github.com/pop-os/libcosmic#3e6f314c6b003505ed06905eaf3e63f81f57f5a5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 1.3.2",
|
"bitflags 1.3.2",
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
|
|
@ -2735,7 +2735,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iced_widget"
|
name = "iced_widget"
|
||||||
version = "0.12.0"
|
version = "0.12.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic#2b23005fbff5a3d7e218a867e1aadb491abeac55"
|
source = "git+https://github.com/pop-os/libcosmic#3e6f314c6b003505ed06905eaf3e63f81f57f5a5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"iced_renderer",
|
"iced_renderer",
|
||||||
"iced_runtime",
|
"iced_runtime",
|
||||||
|
|
@ -3132,7 +3132,7 @@ checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd"
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libcosmic"
|
name = "libcosmic"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/pop-os/libcosmic#2b23005fbff5a3d7e218a867e1aadb491abeac55"
|
source = "git+https://github.com/pop-os/libcosmic#3e6f314c6b003505ed06905eaf3e63f81f57f5a5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"apply",
|
"apply",
|
||||||
"ashpd 0.7.0",
|
"ashpd 0.7.0",
|
||||||
|
|
|
||||||
|
|
@ -31,8 +31,8 @@ rev = "2e9bf9f"
|
||||||
opt-level = 3
|
opt-level = 3
|
||||||
|
|
||||||
# For development and testing purposes
|
# For development and testing purposes
|
||||||
#[patch.'https://github.com/pop-os/libcosmic']
|
# [patch.'https://github.com/pop-os/libcosmic']
|
||||||
#libcosmic = { git = "https://github.com/pop-os/libcosmic?rev=slider", branch = "slider" }
|
#libcosmic = { git = "https://github.com/pop-os/libcosmic?rev=slider", branch = "slider" }
|
||||||
#cosmic-config = { git = "https://github.com/pop-os/libcosmic?rev=slider", branch = "slider" }
|
#cosmic-config = { git = "https://github.com/pop-os/libcosmic?rev=slider", branch = "slider" }
|
||||||
#libcosmic = { path = "../libcosmic" }
|
# libcosmic = { path = "../libcosmic" }
|
||||||
#cosmic-config = { path = "../libcosmic/cosmic-config" }
|
# cosmic-config = { path = "../libcosmic/cosmic-config" }
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,9 @@ use apply::Apply;
|
||||||
use ashpd::desktop::file_chooser::{FileFilter, SelectedFiles};
|
use ashpd::desktop::file_chooser::{FileFilter, SelectedFiles};
|
||||||
use cosmic::cosmic_config::{Config, ConfigSet, CosmicConfigEntry};
|
use cosmic::cosmic_config::{Config, ConfigSet, CosmicConfigEntry};
|
||||||
use cosmic::cosmic_theme::palette::{FromColor, Hsv, Srgb, Srgba};
|
use cosmic::cosmic_theme::palette::{FromColor, Hsv, Srgb, Srgba};
|
||||||
use cosmic::cosmic_theme::{CornerRadii, Theme, ThemeBuilder, ThemeMode};
|
use cosmic::cosmic_theme::{
|
||||||
|
CornerRadii, Theme, ThemeBuilder, ThemeMode, DARK_THEME_BUILDER_ID, LIGHT_THEME_BUILDER_ID,
|
||||||
|
};
|
||||||
use cosmic::iced_core::{alignment, Color, Length};
|
use cosmic::iced_core::{alignment, Color, Length};
|
||||||
use cosmic::iced_widget::scrollable;
|
use cosmic::iced_widget::scrollable;
|
||||||
use cosmic::prelude::CollectionWidget;
|
use cosmic::prelude::CollectionWidget;
|
||||||
|
|
@ -283,6 +285,71 @@ impl From<CornerRadii> for Roundness {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Page {
|
impl Page {
|
||||||
|
/// Syncs changes for dark and light theme.
|
||||||
|
/// Roundness and window management settings should be consistent between dark / light mode.
|
||||||
|
fn sync_changes(&self) -> Result<(), cosmic::cosmic_config::Error> {
|
||||||
|
let (other_builder_config, other_theme_config) = if self.theme_mode.is_dark {
|
||||||
|
(ThemeBuilder::light_config()?, Theme::light_config()?)
|
||||||
|
} else {
|
||||||
|
(ThemeBuilder::dark_config()?, Theme::dark_config()?)
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut theme_builder = match ThemeBuilder::get_entry(&other_builder_config) {
|
||||||
|
Ok(t) => t,
|
||||||
|
Err((errs, t)) => {
|
||||||
|
for err in errs {
|
||||||
|
tracing::error!(?err, "Error loading theme builder");
|
||||||
|
}
|
||||||
|
t
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let mut theme = match Theme::get_entry(&other_theme_config) {
|
||||||
|
Ok(t) => t,
|
||||||
|
Err((errs, t)) => {
|
||||||
|
for err in errs {
|
||||||
|
tracing::error!(?err, "Error loading theme");
|
||||||
|
}
|
||||||
|
t
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if theme_builder.active_hint != self.theme_builder.active_hint {
|
||||||
|
if let Err(err) =
|
||||||
|
theme_builder.set_active_hint(&other_builder_config, self.theme_builder.active_hint)
|
||||||
|
{
|
||||||
|
tracing::error!(?err, "Error setting active hint");
|
||||||
|
}
|
||||||
|
if let Err(err) =
|
||||||
|
theme.set_active_hint(&other_theme_config, self.theme_builder.active_hint)
|
||||||
|
{
|
||||||
|
tracing::error!(?err, "Error setting active hint");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if theme_builder.gaps != self.theme_builder.gaps {
|
||||||
|
if let Err(err) = theme_builder.set_gaps(&other_builder_config, self.theme_builder.gaps)
|
||||||
|
{
|
||||||
|
tracing::error!(?err, "Error setting gaps");
|
||||||
|
}
|
||||||
|
if let Err(err) = theme.set_gaps(&other_theme_config, self.theme_builder.gaps) {
|
||||||
|
tracing::error!(?err, "Error setting gaps");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if theme_builder.corner_radii != self.theme_builder.corner_radii {
|
||||||
|
if let Err(err) = theme_builder
|
||||||
|
.set_corner_radii(&other_builder_config, self.theme_builder.corner_radii)
|
||||||
|
{
|
||||||
|
tracing::error!(?err, "Error setting corner radii");
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Err(err) =
|
||||||
|
theme.set_corner_radii(&other_theme_config, self.theme_builder.corner_radii)
|
||||||
|
{
|
||||||
|
tracing::error!(?err, "Error setting corner radii");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
fn color_picker_context_view(
|
fn color_picker_context_view(
|
||||||
&self,
|
&self,
|
||||||
description: Option<Cow<'static, str>>,
|
description: Option<Cow<'static, str>>,
|
||||||
|
|
@ -307,7 +374,7 @@ impl Page {
|
||||||
.align_x(alignment::Horizontal::Center)
|
.align_x(alignment::Horizontal::Center)
|
||||||
.apply(container)
|
.apply(container)
|
||||||
.width(Length::Fill)
|
.width(Length::Fill)
|
||||||
.align_x(alignment::Horizontal::Center)
|
.align_x(alignment::Horizontal::Center),
|
||||||
)
|
)
|
||||||
.padding(self.theme_builder.spacing.space_l)
|
.padding(self.theme_builder.spacing.space_l)
|
||||||
.align_items(cosmic::iced_core::Alignment::Center)
|
.align_items(cosmic::iced_core::Alignment::Center)
|
||||||
|
|
@ -320,7 +387,7 @@ impl Page {
|
||||||
#[allow(clippy::too_many_lines)]
|
#[allow(clippy::too_many_lines)]
|
||||||
pub fn update(&mut self, message: Message) -> Command<app::Message> {
|
pub fn update(&mut self, message: Message) -> Command<app::Message> {
|
||||||
self.theme_builder_needs_update = false;
|
self.theme_builder_needs_update = false;
|
||||||
|
let mut needs_sync = false;
|
||||||
let mut ret = match message {
|
let mut ret = match message {
|
||||||
Message::DarkMode(enabled) => {
|
Message::DarkMode(enabled) => {
|
||||||
self.theme_mode.is_dark = enabled;
|
self.theme_mode.is_dark = enabled;
|
||||||
|
|
@ -348,6 +415,7 @@ impl Page {
|
||||||
Command::none()
|
Command::none()
|
||||||
}
|
}
|
||||||
Message::AccentWindowHint(u) => {
|
Message::AccentWindowHint(u) => {
|
||||||
|
needs_sync = true;
|
||||||
let cmd = self.update_color_picker(
|
let cmd = self.update_color_picker(
|
||||||
&u,
|
&u,
|
||||||
ContextView::AccentWindowHint,
|
ContextView::AccentWindowHint,
|
||||||
|
|
@ -361,6 +429,7 @@ impl Page {
|
||||||
Command::none()
|
Command::none()
|
||||||
}
|
}
|
||||||
Message::WindowHintSize(msg) => {
|
Message::WindowHintSize(msg) => {
|
||||||
|
needs_sync = true;
|
||||||
self.theme_builder_needs_update = true;
|
self.theme_builder_needs_update = true;
|
||||||
self.theme_builder.active_hint = match msg {
|
self.theme_builder.active_hint = match msg {
|
||||||
spin_button::Message::Increment => {
|
spin_button::Message::Increment => {
|
||||||
|
|
@ -373,6 +442,7 @@ impl Page {
|
||||||
Command::none()
|
Command::none()
|
||||||
}
|
}
|
||||||
Message::GapSize(msg) => {
|
Message::GapSize(msg) => {
|
||||||
|
needs_sync = true;
|
||||||
self.theme_builder_needs_update = true;
|
self.theme_builder_needs_update = true;
|
||||||
self.theme_builder.gaps.1 = match msg {
|
self.theme_builder.gaps.1 = match msg {
|
||||||
spin_button::Message::Increment => self.theme_builder.gaps.1.saturating_add(1),
|
spin_button::Message::Increment => self.theme_builder.gaps.1.saturating_add(1),
|
||||||
|
|
@ -434,6 +504,7 @@ impl Page {
|
||||||
Command::batch(vec![cmd, self.control_component.update::<app::Message>(u)])
|
Command::batch(vec![cmd, self.control_component.update::<app::Message>(u)])
|
||||||
}
|
}
|
||||||
Message::Roundness(r) => {
|
Message::Roundness(r) => {
|
||||||
|
needs_sync = true;
|
||||||
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;
|
||||||
|
|
@ -461,9 +532,39 @@ impl Page {
|
||||||
}
|
}
|
||||||
Message::Reset => {
|
Message::Reset => {
|
||||||
self.theme_builder = if self.theme_mode.is_dark {
|
self.theme_builder = if self.theme_mode.is_dark {
|
||||||
ThemeBuilder::dark()
|
cosmic::cosmic_config::Config::system(
|
||||||
|
DARK_THEME_BUILDER_ID,
|
||||||
|
ThemeBuilder::VERSION,
|
||||||
|
)
|
||||||
|
.map_or_else(
|
||||||
|
|_| ThemeBuilder::dark(),
|
||||||
|
|config| match ThemeBuilder::get_entry(&config) {
|
||||||
|
Ok(t) => t,
|
||||||
|
Err((errs, t)) => {
|
||||||
|
for err in errs {
|
||||||
|
tracing::warn!(?err, "Error getting system theme builder");
|
||||||
|
}
|
||||||
|
t
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
ThemeBuilder::light()
|
cosmic::cosmic_config::Config::system(
|
||||||
|
LIGHT_THEME_BUILDER_ID,
|
||||||
|
ThemeBuilder::VERSION,
|
||||||
|
)
|
||||||
|
.map_or_else(
|
||||||
|
|_| ThemeBuilder::light(),
|
||||||
|
|config| match ThemeBuilder::get_entry(&config) {
|
||||||
|
Ok(t) => t,
|
||||||
|
Err((errs, t)) => {
|
||||||
|
for err in errs {
|
||||||
|
tracing::warn!(?err, "Error getting system theme builder");
|
||||||
|
}
|
||||||
|
t
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
};
|
};
|
||||||
if let Some(config) = self.theme_builder_config.as_ref() {
|
if let Some(config) = self.theme_builder_config.as_ref() {
|
||||||
_ = self.theme_builder.write_entry(config);
|
_ = self.theme_builder.write_entry(config);
|
||||||
|
|
@ -721,6 +822,12 @@ impl Page {
|
||||||
self.theme_builder != ThemeBuilder::light()
|
self.theme_builder != ThemeBuilder::light()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if needs_sync {
|
||||||
|
if let Err(err) = self.sync_changes() {
|
||||||
|
tracing::error!(?err, "Error syncing theme changes.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue