fix(app): restore distinction between app theme changes, and system theme changes
This commit is contained in:
parent
baad15033c
commit
023d8ad3a0
3 changed files with 34 additions and 7 deletions
|
|
@ -44,7 +44,7 @@ pub fn set_scaling_factor<M: Send + 'static>(factor: f32) -> iced::Command<Messa
|
|||
}
|
||||
|
||||
pub fn set_theme<M: Send + 'static>(theme: crate::Theme) -> iced::Command<Message<M>> {
|
||||
message::cosmic(super::cosmic::Message::ThemeChange(theme))
|
||||
message::cosmic(super::cosmic::Message::AppThemeChange(theme))
|
||||
}
|
||||
|
||||
pub fn set_title<M: Send + 'static>(title: String) -> iced::Command<Message<M>> {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
// Copyright 2023 System76 <info@system76.com>
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use crate::Theme;
|
||||
|
||||
/// Status of the nav bar and its panels.
|
||||
#[derive(Clone)]
|
||||
pub struct NavBar {
|
||||
|
|
@ -41,7 +43,10 @@ pub struct Core {
|
|||
/// Scaling factor used by the application
|
||||
scale_factor: f32,
|
||||
|
||||
pub(crate) title: String,
|
||||
/// Last known system theme
|
||||
pub(super) system_theme: Theme,
|
||||
|
||||
pub(super) title: String,
|
||||
pub window: Window,
|
||||
#[cfg(feature = "applet")]
|
||||
pub applet_helper: super::applet::CosmicAppletHelper,
|
||||
|
|
@ -59,6 +64,7 @@ impl Default for Core {
|
|||
},
|
||||
scale_factor: 1.0,
|
||||
title: String::new(),
|
||||
system_theme: crate::theme::active(),
|
||||
window: Window {
|
||||
header_title: String::new(),
|
||||
use_template: true,
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use super::{command, Application, ApplicationExt, Core, Subscription};
|
||||
use crate::theme::{self, Theme, THEME};
|
||||
use crate::theme::{self, Theme, ThemeType, THEME};
|
||||
use crate::widget::nav_bar;
|
||||
use crate::{keyboard_nav, Element};
|
||||
#[cfg(feature = "wayland")]
|
||||
|
|
@ -20,6 +20,8 @@ use sctk::reexports::csd_frame::{WindowManagerCapabilities, WindowState};
|
|||
/// A message managed internally by COSMIC.
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum Message {
|
||||
/// Application requests theme change.
|
||||
AppThemeChange(Theme),
|
||||
/// Requests to close the window.
|
||||
Close,
|
||||
/// Requests to drag the window.
|
||||
|
|
@ -34,12 +36,12 @@ pub enum Message {
|
|||
NavBar(nav_bar::Id),
|
||||
/// Set scaling factor
|
||||
ScaleFactor(f32),
|
||||
/// Requests theme changes.
|
||||
ThemeChange(Theme),
|
||||
/// Toggles visibility of the nav bar.
|
||||
ToggleNavBar,
|
||||
/// Toggles the condensed status of the nav bar.
|
||||
ToggleNavBarCondensed,
|
||||
/// Notification of system theme changes.
|
||||
SystemThemeChange(Theme),
|
||||
/// Updates the tracked window geometry.
|
||||
WindowResize(window::Id, u32, u32),
|
||||
/// Tracks updates to window state.
|
||||
|
|
@ -149,7 +151,7 @@ where
|
|||
.map(Message::KeyboardNav)
|
||||
.map(super::Message::Cosmic),
|
||||
theme::subscription(0)
|
||||
.map(Message::ThemeChange)
|
||||
.map(Message::SystemThemeChange)
|
||||
.map(super::Message::Cosmic),
|
||||
window_events.map(super::Message::Cosmic),
|
||||
])
|
||||
|
|
@ -272,13 +274,32 @@ impl<T: Application> Cosmic<T> {
|
|||
self.app.core_mut().nav_bar_toggle_condensed();
|
||||
}
|
||||
|
||||
Message::ThemeChange(theme) => {
|
||||
Message::AppThemeChange(mut theme) => {
|
||||
// Apply last-known system theme if the system theme is preferred.
|
||||
if let ThemeType::System(_) = theme.theme_type {
|
||||
theme = self.app.core().system_theme.clone();
|
||||
}
|
||||
|
||||
THEME.with(move |t| {
|
||||
let mut cosmic_theme = t.borrow_mut();
|
||||
cosmic_theme.set_theme(theme.theme_type);
|
||||
});
|
||||
}
|
||||
|
||||
Message::SystemThemeChange(theme) => {
|
||||
// Record the last-known system theme in event that the current theme is custom.
|
||||
self.app.core_mut().system_theme = theme.clone();
|
||||
|
||||
THEME.with(move |t| {
|
||||
let mut cosmic_theme = t.borrow_mut();
|
||||
|
||||
// Anly apply update if the theme is set to load a system theme
|
||||
if let ThemeType::System(_) = cosmic_theme.theme_type {
|
||||
cosmic_theme.set_theme(theme.theme_type);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Message::ScaleFactor(factor) => {
|
||||
self.app.core_mut().set_scale_factor(factor);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue