diff --git a/Cargo.lock b/Cargo.lock index 9b9b86c5..13b297c2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -576,7 +576,7 @@ dependencies = [ [[package]] name = "cosmic-config" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic/?rev=f91287d#f91287dec2297df41a339c1106850c4cf179f67f" +source = "git+https://github.com/pop-os/libcosmic/?branch=theme-dark-light-switching#d7cbffe445b34795a660c1155b35a36f1f2c8a74" dependencies = [ "atomicwrites", "calloop 0.12.2", @@ -591,7 +591,7 @@ dependencies = [ [[package]] name = "cosmic-config-derive" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic/?rev=f91287d#f91287dec2297df41a339c1106850c4cf179f67f" +source = "git+https://github.com/pop-os/libcosmic/?branch=theme-dark-light-switching#d7cbffe445b34795a660c1155b35a36f1f2c8a74" dependencies = [ "quote", "syn 1.0.109", @@ -632,7 +632,7 @@ dependencies = [ [[package]] name = "cosmic-theme" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic/?rev=f91287d#f91287dec2297df41a339c1106850c4cf179f67f" +source = "git+https://github.com/pop-os/libcosmic/?branch=theme-dark-light-switching#d7cbffe445b34795a660c1155b35a36f1f2c8a74" dependencies = [ "almost", "cosmic-config", @@ -1850,7 +1850,7 @@ dependencies = [ [[package]] name = "iced" version = "0.10.0" -source = "git+https://github.com/pop-os/libcosmic/?rev=f91287d#f91287dec2297df41a339c1106850c4cf179f67f" +source = "git+https://github.com/pop-os/libcosmic/?branch=theme-dark-light-switching#d7cbffe445b34795a660c1155b35a36f1f2c8a74" dependencies = [ "iced_core", "iced_futures", @@ -1863,7 +1863,7 @@ dependencies = [ [[package]] name = "iced_core" version = "0.10.0" -source = "git+https://github.com/pop-os/libcosmic/?rev=f91287d#f91287dec2297df41a339c1106850c4cf179f67f" +source = "git+https://github.com/pop-os/libcosmic/?branch=theme-dark-light-switching#d7cbffe445b34795a660c1155b35a36f1f2c8a74" dependencies = [ "bitflags 1.3.2", "instant", @@ -1876,7 +1876,7 @@ dependencies = [ [[package]] name = "iced_futures" version = "0.7.0" -source = "git+https://github.com/pop-os/libcosmic/?rev=f91287d#f91287dec2297df41a339c1106850c4cf179f67f" +source = "git+https://github.com/pop-os/libcosmic/?branch=theme-dark-light-switching#d7cbffe445b34795a660c1155b35a36f1f2c8a74" dependencies = [ "futures", "iced_core", @@ -1888,7 +1888,7 @@ dependencies = [ [[package]] name = "iced_graphics" version = "0.9.0" -source = "git+https://github.com/pop-os/libcosmic/?rev=f91287d#f91287dec2297df41a339c1106850c4cf179f67f" +source = "git+https://github.com/pop-os/libcosmic/?branch=theme-dark-light-switching#d7cbffe445b34795a660c1155b35a36f1f2c8a74" dependencies = [ "bitflags 1.3.2", "bytemuck", @@ -1906,7 +1906,7 @@ dependencies = [ [[package]] name = "iced_renderer" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic/?rev=f91287d#f91287dec2297df41a339c1106850c4cf179f67f" +source = "git+https://github.com/pop-os/libcosmic/?branch=theme-dark-light-switching#d7cbffe445b34795a660c1155b35a36f1f2c8a74" dependencies = [ "iced_graphics", "iced_tiny_skia", @@ -1919,7 +1919,7 @@ dependencies = [ [[package]] name = "iced_runtime" version = "0.1.1" -source = "git+https://github.com/pop-os/libcosmic/?rev=f91287d#f91287dec2297df41a339c1106850c4cf179f67f" +source = "git+https://github.com/pop-os/libcosmic/?branch=theme-dark-light-switching#d7cbffe445b34795a660c1155b35a36f1f2c8a74" dependencies = [ "iced_core", "iced_futures", @@ -1929,7 +1929,7 @@ dependencies = [ [[package]] name = "iced_style" version = "0.9.0" -source = "git+https://github.com/pop-os/libcosmic/?rev=f91287d#f91287dec2297df41a339c1106850c4cf179f67f" +source = "git+https://github.com/pop-os/libcosmic/?branch=theme-dark-light-switching#d7cbffe445b34795a660c1155b35a36f1f2c8a74" dependencies = [ "iced_core", "once_cell", @@ -1939,7 +1939,7 @@ dependencies = [ [[package]] name = "iced_tiny_skia" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic/?rev=f91287d#f91287dec2297df41a339c1106850c4cf179f67f" +source = "git+https://github.com/pop-os/libcosmic/?branch=theme-dark-light-switching#d7cbffe445b34795a660c1155b35a36f1f2c8a74" dependencies = [ "bytemuck", "cosmic-text", @@ -1957,7 +1957,7 @@ dependencies = [ [[package]] name = "iced_wgpu" version = "0.11.1" -source = "git+https://github.com/pop-os/libcosmic/?rev=f91287d#f91287dec2297df41a339c1106850c4cf179f67f" +source = "git+https://github.com/pop-os/libcosmic/?branch=theme-dark-light-switching#d7cbffe445b34795a660c1155b35a36f1f2c8a74" dependencies = [ "bitflags 1.3.2", "bytemuck", @@ -1979,7 +1979,7 @@ dependencies = [ [[package]] name = "iced_widget" version = "0.1.3" -source = "git+https://github.com/pop-os/libcosmic/?rev=f91287d#f91287dec2297df41a339c1106850c4cf179f67f" +source = "git+https://github.com/pop-os/libcosmic/?branch=theme-dark-light-switching#d7cbffe445b34795a660c1155b35a36f1f2c8a74" dependencies = [ "iced_renderer", "iced_runtime", @@ -2291,7 +2291,7 @@ checksum = "9cdc71e17332e86d2e1d38c1f99edcb6288ee11b815fb1a4b049eaa2114d369b" [[package]] name = "libcosmic" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic/?rev=f91287d#f91287dec2297df41a339c1106850c4cf179f67f" +source = "git+https://github.com/pop-os/libcosmic/?branch=theme-dark-light-switching#d7cbffe445b34795a660c1155b35a36f1f2c8a74" dependencies = [ "apply", "cosmic-config", @@ -4174,7 +4174,7 @@ dependencies = [ [[package]] name = "taffy" version = "0.3.11" -source = "git+https://github.com/DioxusLabs/taffy#120bb7a2e501822b324fd48de955450ebbba1c1a" +source = "git+https://github.com/DioxusLabs/taffy?rev=65bedf#65bedf128ec8cef40c1a21b6f141f2c771842cca" dependencies = [ "arrayvec", "grid", diff --git a/Cargo.toml b/Cargo.toml index 4333bede..a4cbfc8b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,10 +36,10 @@ libsystemd = { version = "0.6", optional = true } wayland-backend = "0.3.2" wayland-scanner = "0.31.0" cosmic-comp-config = { path = "cosmic-comp-config" } -cosmic-config = { git = "https://github.com/pop-os/libcosmic/", rev = "f91287d", features = ["calloop"] } +cosmic-config = { git = "https://github.com/pop-os/libcosmic/", features = ["calloop", "macro"], branch = "theme-dark-light-switching"} cosmic-protocols = { git = "https://github.com/pop-os/cosmic-protocols", branch = "main", default-features = false, features = ["server"] } -libcosmic = { git = "https://github.com/pop-os/libcosmic/", rev = "f91287d", default-features = false } -iced_tiny_skia = { git = "https://github.com/pop-os/libcosmic/", rev = "f91287d" } +libcosmic = { git = "https://github.com/pop-os/libcosmic/", default-features = false, branch = "theme-dark-light-switching" } +iced_tiny_skia = { git = "https://github.com/pop-os/libcosmic/", branch = "theme-dark-light-switching" } tiny-skia = "0.10" ordered-float = "4.0" glow = "0.12.0" diff --git a/src/backend/kms/mod.rs b/src/backend/kms/mod.rs index 6f8f68b8..ab5bcc67 100644 --- a/src/backend/kms/mod.rs +++ b/src/backend/kms/mod.rs @@ -3,7 +3,7 @@ #[cfg(feature = "debug")] use crate::backend::render::element::AsGlowRenderer; use crate::{ - backend::render::{workspace_elements, CLEAR_COLOR}, + backend::render::workspace_elements, config::OutputConfig, shell::Shell, state::{BackendData, ClientState, Common, Fps, SurfaceDmabufFeedback}, @@ -1107,8 +1107,11 @@ impl Surface { })?; self.fps.elements(); - let res = - compositor.render_frame::<_, _, GlesTexture>(&mut renderer, &elements, CLEAR_COLOR); + let res = compositor.render_frame::<_, _, GlesTexture>( + &mut renderer, + &elements, + crate::theme::clear_color(), + ); self.fps.render(); match res { diff --git a/src/backend/render/mod.rs b/src/backend/render/mod.rs index 75cead8a..1e950608 100644 --- a/src/backend/render/mod.rs +++ b/src/backend/render/mod.rs @@ -78,11 +78,6 @@ pub type GlMultiFrame<'a, 'b, 'frame> = MultiFrame<'a, 'a, 'b, 'frame, GbmGlesBackend, GbmGlesBackend>; pub type GlMultiError = MultiError, GbmGlesBackend>; -pub static CLEAR_COLOR: [f32; 4] = [0.153, 0.161, 0.165, 1.0]; -pub static GROUP_COLOR: [f32; 3] = [0.788, 0.788, 0.788]; -pub static ACTIVE_GROUP_COLOR: [f32; 3] = [0.58, 0.922, 0.922]; -pub static FOCUS_INDICATOR_COLOR: [f32; 3] = [0.580, 0.921, 0.921]; - pub static OUTLINE_SHADER: &str = include_str!("./shaders/rounded_outline.frag"); pub static RECTANGLE_SHADER: &str = include_str!("./shaders/rounded_rectangle.frag"); @@ -169,6 +164,7 @@ impl IndicatorShader { element_geo.loc -= (t, t).into(); element_geo.size += (t * 2, t * 2).into(); + let focus_indicator = crate::theme::active_window_hint(); IndicatorShader::element( renderer, key, @@ -177,7 +173,11 @@ impl IndicatorShader { thickness * 2, alpha, scale, - FOCUS_INDICATOR_COLOR, + [ + focus_indicator.red, + focus_indicator.green, + focus_indicator.blue, + ], ) } @@ -580,6 +580,7 @@ where } }); + let active_hint = crate::theme::active_hint(); let (w_elements, p_elements) = workspace .render_output::( renderer, @@ -589,7 +590,7 @@ where (!move_active && is_active_space).then_some(&last_active_seat), overview.clone(), resize_indicator.clone(), - state.config.static_conf.active_hint, + active_hint, ) .map_err(|_| OutputNoMode)?; elements.extend(p_elements.into_iter().map(|p_element| { @@ -647,7 +648,7 @@ where (!move_active && is_active_space).then_some(&last_active_seat), overview, resize_indicator, - state.config.static_conf.active_hint, + crate::theme::active_hint(), ) .map_err(|_| OutputNoMode)?; elements.extend(p_elements.into_iter().map(|p_element| { @@ -919,7 +920,7 @@ where } renderer.bind(target).map_err(RenderError::Rendering)?; - let res = damage_tracker.render_output(renderer, age, &elements, CLEAR_COLOR); + let res = damage_tracker.render_output(renderer, age, &elements, crate::theme::clear_color()); if let Some(fps) = fps.as_mut() { fps.render(); diff --git a/src/config/mod.rs b/src/config/mod.rs index c783a080..8640b6a8 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -50,10 +50,6 @@ pub struct StaticConfig { #[serde(default = "default_workspace_layout")] pub workspace_layout: WorkspaceLayout, pub tiling_enabled: bool, - #[serde(default = "default_active_hint")] - pub active_hint: u8, - #[serde(default = "default_gaps")] - pub gaps: (u8, u8), } #[derive(Debug, Deserialize, Clone, Copy, PartialEq, Eq)] @@ -100,14 +96,6 @@ fn default_enabled() -> bool { true } -fn default_active_hint() -> u8 { - 4 -} - -fn default_gaps() -> (u8, u8) { - (0, 4) -} - fn default_workspace_layout() -> WorkspaceLayout { WorkspaceLayout::Vertical } @@ -219,8 +207,6 @@ impl Config { workspace_amount: WorkspaceAmount::Dynamic, workspace_layout: WorkspaceLayout::Vertical, tiling_enabled: false, - active_hint: default_active_hint(), - gaps: default_gaps(), } } diff --git a/src/main.rs b/src/main.rs index e87ab39d..03fa2c5c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,6 +25,7 @@ pub mod shell; pub mod state; #[cfg(feature = "systemd")] pub mod systemd; +pub mod theme; pub mod utils; pub mod wayland; pub mod xwayland; @@ -55,6 +56,8 @@ fn main() -> Result<()> { // potentially tell the session we are setup now session::setup_socket(event_loop.handle(), &state)?; + let _theme_res = theme::watch_theme(event_loop.handle()); + // run the event loop event_loop.run(None, &mut state, |state| { // shall we shut down? diff --git a/src/shell/element/mod.rs b/src/shell/element/mod.rs index 12157b2a..c542cf9b 100644 --- a/src/shell/element/mod.rs +++ b/src/shell/element/mod.rs @@ -759,6 +759,22 @@ impl CosmicMapped { popup_elements.into_iter().map(C::from).collect(), ) } + + pub(crate) fn set_theme(&self) { + match &self.element { + CosmicMappedInternal::Window(w) => w.set_theme(), + CosmicMappedInternal::Stack(s) => s.set_theme(), + CosmicMappedInternal::_GenericCatcher(_) => {} + } + } + + pub(crate) fn force_redraw(&self) { + match &self.element { + CosmicMappedInternal::Window(w) => w.force_redraw(), + CosmicMappedInternal::Stack(s) => s.force_redraw(), + CosmicMappedInternal::_GenericCatcher(_) => {} + } + } } impl IsAlive for CosmicMapped { diff --git a/src/shell/element/stack.rs b/src/shell/element/stack.rs index 04e333ec..a9b25337 100644 --- a/src/shell/element/stack.rs +++ b/src/shell/element/stack.rs @@ -544,6 +544,14 @@ impl CosmicStack { popup_elements.into_iter().map(C::from).collect(), ) } + + pub(crate) fn set_theme(&self) { + self.0.set_theme(); + } + + pub(crate) fn force_redraw(&self) { + self.0.force_redraw(); + } } #[derive(Debug, Clone, Copy)] @@ -1059,8 +1067,7 @@ impl PointerTarget for CosmicStack { )); let elem_geo = workspace.element_geometry(stack_mapped).unwrap(); - let indicator_thickness = - data.common.config.static_conf.active_hint; + let indicator_thickness = crate::theme::active_hint(); let was_tiled = workspace.is_tiled(stack_mapped); self.remove_idx(dragged_out); diff --git a/src/shell/element/window.rs b/src/shell/element/window.rs index 67856dd1..f329cc70 100644 --- a/src/shell/element/window.rs +++ b/src/shell/element/window.rs @@ -213,6 +213,14 @@ impl CosmicWindow { popup_elements.into_iter().map(C::from).collect(), ) } + + pub(crate) fn set_theme(&self) { + self.0.set_theme(); + } + + pub(crate) fn force_redraw(&self) { + self.0.force_redraw(); + } } #[derive(Debug, Clone, Copy)] diff --git a/src/shell/layout/tiling/mod.rs b/src/shell/layout/tiling/mod.rs index 7e4c4d78..0d625de3 100644 --- a/src/shell/layout/tiling/mod.rs +++ b/src/shell/layout/tiling/mod.rs @@ -1,10 +1,7 @@ // SPDX-License-Identifier: GPL-3.0-only use crate::{ - backend::render::{ - element::AsGlowRenderer, BackdropShader, IndicatorShader, Key, Usage, ACTIVE_GROUP_COLOR, - GROUP_COLOR, - }, + backend::render::{element::AsGlowRenderer, BackdropShader, IndicatorShader, Key, Usage}, shell::{ element::{ resize_indicator::ResizeIndicator, @@ -25,6 +22,7 @@ use crate::{ CosmicSurface, Direction, FocusResult, MoveResult, OutputNotMapped, OverviewMode, ResizeDirection, ResizeMode, Trigger, }, + theme::group_color, utils::{prelude::*, tween::EaseRectangle}, wayland::{ handlers::xdg_shell::popup::get_popup_toplevel, @@ -3843,6 +3841,10 @@ impl TilingLayout { Ok((window_elements, popup_elements)) } + + pub(crate) fn update_gaps(&mut self, gaps: (i32, i32)) { + self.gaps = gaps; + } } const GAP_KEYBOARD: i32 = 8; @@ -4086,7 +4088,7 @@ where if render_active_child { 16 } else { 8 }, alpha * if render_potential_group { 0.40 } else { 1.0 }, output_scale, - GROUP_COLOR, + group_color(), ) .into(), ); @@ -4104,7 +4106,7 @@ where 8, alpha * 0.40, output_scale, - GROUP_COLOR, + group_color(), ) .into(), ); @@ -4168,7 +4170,7 @@ where 8, alpha * 0.15, output_scale, - GROUP_COLOR, + group_color(), ) .into(), ); @@ -4232,7 +4234,7 @@ where pill_geo, 8., alpha * 0.4, - GROUP_COLOR, + group_color(), ) .into(), ); @@ -4262,7 +4264,7 @@ where } else { 0.15 }, - GROUP_COLOR, + group_color(), ) .into(), ); @@ -4338,7 +4340,7 @@ where ), 8., alpha * 0.4, - GROUP_COLOR, + group_color(), ) .into(), ); @@ -4380,7 +4382,7 @@ where ), 8., alpha * 0.4, - GROUP_COLOR, + group_color(), ) .into(), ); @@ -4411,7 +4413,7 @@ where 8, alpha * 0.40, output_scale, - GROUP_COLOR, + group_color(), ) .into(), ); @@ -4419,6 +4421,8 @@ where geo.size -= (gap * 2, gap * 2).into(); } + let accent = crate::theme::accent_color(); + if focused .as_ref() .map(|focused_id| { @@ -4433,9 +4437,9 @@ where Some(Some(TargetZone::WindowStack(stack_id, _))) if *stack_id == node_id => { - ACTIVE_GROUP_COLOR + [accent.red, accent.green, accent.blue] } - _ => GROUP_COLOR, + _ => group_color(), }; geo.loc += (WINDOW_BACKDROP_BORDER, WINDOW_BACKDROP_BORDER).into(); geo.size -= @@ -4450,7 +4454,9 @@ where * if focused .as_ref() .map(|focused_id| focused_id == &node_id) - .unwrap_or(color == ACTIVE_GROUP_COLOR) + .unwrap_or( + color == [accent.red, accent.green, accent.blue], + ) { 0.4 } else { @@ -4504,7 +4510,7 @@ where geo, 8., alpha * 0.4, - GROUP_COLOR, + group_color(), ) .into(), ); @@ -4744,7 +4750,7 @@ where focused_geo, 8., transition.unwrap_or(1.0) * 0.4, - GROUP_COLOR, + group_color(), ) .into(), ); @@ -4933,7 +4939,7 @@ where geo, 8., 0.4, - GROUP_COLOR, + group_color(), )); } @@ -5079,7 +5085,7 @@ where geo, 0.0, 0.3, - GROUP_COLOR, + group_color(), )), ) } diff --git a/src/shell/mod.rs b/src/shell/mod.rs index 3640353f..fd03f5c7 100644 --- a/src/shell/mod.rs +++ b/src/shell/mod.rs @@ -603,14 +603,14 @@ impl Shell { //|client| client.get_data::().map_or(false, |s| s.privileged), client_has_security_context, ); - + let gaps = crate::theme::gaps(); let tiling_enabled = config.static_conf.tiling_enabled; let mode = WorkspaceMode::new( config.static_conf.workspace_mode, config.static_conf.workspace_amount, &mut workspace_state.update(), tiling_enabled, - config.static_conf.gaps, + gaps, ); Shell { @@ -629,7 +629,7 @@ impl Shell { xdg_shell_state, workspace_state, - gaps: config.static_conf.gaps, + gaps, overview_mode: OverviewMode::None, swap_indicator: None, resize_mode: ResizeMode::None, @@ -1608,12 +1608,13 @@ impl Shell { .find(|(w, _)| w.wl_surface().as_ref() == Some(surface)) .unwrap(); let button = start_data.button; + let active_hint = crate::theme::active_hint(); if let Some(grab) = workspace.move_request( &window, &seat, &output, start_data, - state.common.config.static_conf.active_hint, + active_hint as u8, ) { let handle = workspace.handle; state @@ -1713,6 +1714,19 @@ impl Shell { } } } + + pub(crate) fn set_gaps(&mut self, gaps: (u8, u8)) { + self.gaps = gaps; + self.refresh(); + for w in self.workspaces.spaces_mut() { + w.tiling_layer.update_gaps((gaps.0 as i32, gaps.1 as i32)); + w.refresh(); + w.dirty.store(true, Ordering::Relaxed); + for o in &self.outputs { + w.recalculate(&o); + } + } + } } fn workspace_set_idx<'a>( diff --git a/src/theme.rs b/src/theme.rs new file mode 100644 index 00000000..78e25600 --- /dev/null +++ b/src/theme.rs @@ -0,0 +1,104 @@ +// insert into the event loop, a watcher for the theme & theme mode for changes + +// update a Arc> in the state on change of the theme and mark all interfaces for a redraw. + +use std::sync::{Arc, RwLock}; + +use calloop::LoopHandle; +use cosmic::cosmic_theme::{palette, Theme, ThemeMode}; +use lazy_static::lazy_static; + +use crate::state::State; + +lazy_static! { + pub static ref THEME: Arc> = + Arc::new(RwLock::new(cosmic::theme::system_preference())); +} + +pub(crate) fn clear_color() -> [f32; 4] { + let theme_guard = THEME.read().unwrap(); + let neutral_2 = theme_guard.cosmic().palette.neutral_2; + [ + neutral_2.red, + neutral_2.green, + neutral_2.blue, + neutral_2.alpha, + ] +} + +pub(crate) fn group_color() -> [f32; 3] { + let theme_guard = THEME.read().unwrap(); + let neutral_8 = theme_guard.cosmic().palette.neutral_8; + [neutral_8.red, neutral_8.green, neutral_8.blue] +} + +pub(crate) fn accent_color() -> palette::Srgba { + let theme_guard = THEME.read().unwrap(); + theme_guard.cosmic().accent_color() +} + +pub(crate) fn active_hint() -> u8 { + let theme_guard = THEME.read().unwrap(); + theme_guard.cosmic().active_hint as u8 +} + +pub(crate) fn gaps() -> (u8, u8) { + let theme_guard = THEME.read().unwrap(); + let gaps = theme_guard.cosmic().gaps; + (gaps.0 as u8, gaps.1 as u8) +} + +pub(crate) fn active_window_hint() -> palette::Srgba { + let theme_guard = THEME.read().unwrap(); + let t = theme_guard.cosmic(); + if let Some(hint) = t.window_hint { + palette::Srgba::from(hint) + } else { + t.accent_color() + } +} + +pub fn watch_theme(handle: LoopHandle<'_, State>) -> Result<(), cosmic_config::Error> { + let (ping_tx, ping_rx) = calloop::ping::make_ping().unwrap(); + let config_mode_helper = ThemeMode::config()?; + let config_dark_helper = Theme::::dark_config()?; + let config_light_helper = Theme::::light_config()?; + + if let Err(e) = handle.insert_source(ping_rx, move |_, _, state| { + let new_theme = cosmic::theme::system_preference(); + let mut theme = THEME.write().unwrap(); + + if theme.theme_type != new_theme.theme_type { + *theme = new_theme; + } + let gaps = theme.cosmic().gaps; + state.common.shell.set_gaps((gaps.0 as u8, gaps.1 as u8)); + drop(theme); + state.common.shell.workspaces.spaces().for_each(|s| { + s.mapped().for_each(|m| { + m.set_theme(); + m.force_redraw(); + }) + }); + }) { + tracing::error!("{e}"); + }; + + let ping_tx_clone = ping_tx.clone(); + let theme_watcher_mode = config_mode_helper.watch(move |_, _keys| { + ping_tx_clone.ping(); + })?; + let ping_tx_clone = ping_tx.clone(); + let theme_watcher_light = config_light_helper.watch(move |_, _keys| { + ping_tx_clone.ping(); + })?; + let theme_watcher_dark = config_dark_helper.watch(move |_, _keys| { + ping_tx.ping(); + })?; + + std::mem::forget(theme_watcher_dark); + std::mem::forget(theme_watcher_light); + std::mem::forget(theme_watcher_mode); + + Ok(()) +} diff --git a/src/utils/iced.rs b/src/utils/iced.rs index 614d943d..ec1756bd 100644 --- a/src/utils/iced.rs +++ b/src/utils/iced.rs @@ -62,6 +62,8 @@ use smithay::{ }, }; +use crate::theme::THEME; + pub struct IcedElement(Arc>>); impl fmt::Debug for IcedElement

{ @@ -251,13 +253,16 @@ impl IcedElement

{ }) .ok(); + let theme_guard = THEME.read().unwrap(); + let theme = theme_guard.clone(); + drop(theme_guard); let mut internal = IcedElementInternal { outputs: HashSet::new(), buffers: HashMap::new(), pending_update: None, size, cursor_pos: None, - theme: Theme::dark(), // TODO + theme: theme.clone(), // TODO renderer, state, debug, @@ -308,6 +313,11 @@ impl IcedElement

{ self.0.lock().unwrap().update(true); } + pub fn set_theme(&self) { + let mut guard = self.0.lock().unwrap(); + guard.theme = THEME.read().unwrap().clone(); + } + pub fn force_redraw(&self) { let mut internal = self.0.lock().unwrap(); for (_buffer, ref mut old_primitives) in internal.buffers.values_mut() { diff --git a/src/wayland/handlers/screencopy.rs b/src/wayland/handlers/screencopy.rs index dd775448..c08882d0 100644 --- a/src/wayland/handlers/screencopy.rs +++ b/src/wayland/handlers/screencopy.rs @@ -43,7 +43,7 @@ use crate::{ backend::render::{ cursor, element::{AsGlowRenderer, CosmicElement}, - render_output, render_workspace, CursorMode, CLEAR_COLOR, + render_output, render_workspace, CursorMode, }, shell::{CosmicMappedRenderElement, CosmicSurface, WorkspaceRenderElement}, state::{BackendData, ClientState, Common, State}, @@ -1015,7 +1015,7 @@ pub fn render_window_to_buffer( renderer.bind(render_buffer).map_err(DTError::Rendering)?; } - dt.render_output(renderer, age, &elements, CLEAR_COLOR) + dt.render_output(renderer, age, &elements, crate::theme::clear_color()) } let node = node_from_params(¶ms, &mut state.backend, None);