config: Add and propagate appearance_config

This commit is contained in:
Victoria Brekenfeld 2025-12-08 18:21:58 +01:00 committed by Victoria Brekenfeld
parent 94d49210e6
commit 2adebb5fe1
10 changed files with 213 additions and 40 deletions

View file

@ -4,6 +4,7 @@ use crate::{
utils::{iced::IcedElementInternal, prelude::*},
};
use calloop::LoopHandle;
use cosmic_comp_config::AppearanceConfig;
use id_tree::NodeId;
use smithay::{
backend::{
@ -500,13 +501,14 @@ impl CosmicMapped {
&mut self,
(output, overlap): (&Output, Rectangle<i32, Logical>),
theme: cosmic::Theme,
appearance: AppearanceConfig,
) {
if let CosmicMappedInternal::Window(window) = &self.element {
let surface = window.surface();
let activated = surface.is_activated(true);
let handle = window.loop_handle();
let stack = CosmicStack::new(std::iter::once(surface), handle, theme);
let stack = CosmicStack::new(std::iter::once(surface), handle, theme, appearance);
if let Some(geo) = *self.last_geometry.lock().unwrap() {
stack.set_geometry(geo.to_global(output));
}
@ -524,11 +526,12 @@ impl CosmicMapped {
surface: CosmicSurface,
(output, overlap): (&Output, Rectangle<i32, Logical>),
theme: cosmic::Theme,
appearance: AppearanceConfig,
) {
let handle = self.loop_handle();
surface.try_force_undecorated(false);
surface.set_tiled(false);
let window = CosmicWindow::new(surface, handle, theme);
let window = CosmicWindow::new(surface, handle, theme, appearance);
if let Some(geo) = *self.last_geometry.lock().unwrap() {
window.set_geometry(geo.to_global(output));
@ -810,6 +813,14 @@ impl CosmicMapped {
}
}
pub(crate) fn update_appearance_conf(&self, appearance: &AppearanceConfig) {
match &self.element {
CosmicMappedInternal::Window(w) => w.update_appearance_conf(appearance),
CosmicMappedInternal::Stack(s) => s.update_appearance_conf(appearance),
CosmicMappedInternal::_GenericCatcher(_) => {}
}
}
pub(crate) fn force_redraw(&self) {
match &self.element {
CosmicMappedInternal::Window(w) => w.force_redraw(),

View file

@ -25,6 +25,7 @@ use cosmic::{
iced_widget::scrollable::AbsoluteOffset,
theme, widget as cosmic_widget,
};
use cosmic_comp_config::AppearanceConfig;
use cosmic_settings_config::shortcuts;
use shortcuts::action::{Direction, FocusDirection};
use smithay::{
@ -106,6 +107,7 @@ pub struct CosmicStackInternal {
override_alive: AtomicBool,
geometry: Mutex<Option<Rectangle<i32, Global>>>,
mask: Mutex<Option<tiny_skia::Mask>>,
appearance_conf: Mutex<AppearanceConfig>,
}
impl CosmicStackInternal {
@ -133,6 +135,7 @@ impl CosmicStack {
windows: impl Iterator<Item = I>,
handle: LoopHandle<'static, crate::state::State>,
theme: cosmic::Theme,
appearance: AppearanceConfig,
) -> CosmicStack {
let windows = windows.map(Into::into).collect::<Vec<_>>();
assert!(!windows.is_empty());
@ -159,6 +162,7 @@ impl CosmicStack {
override_alive: AtomicBool::new(true),
geometry: Mutex::new(None),
mask: Mutex::new(None),
appearance_conf: Mutex::new(appearance),
},
(width, TAB_HEIGHT),
handle,
@ -681,6 +685,21 @@ impl CosmicStack {
self.0.set_theme(theme);
}
pub fn update_appearance_conf(&self, appearance: &AppearanceConfig) {
if self.0.with_program(|p| {
let mut conf = p.appearance_conf.lock().unwrap();
if &*conf != appearance {
*conf = *appearance;
true
} else {
false
}
}) {
self.0.force_redraw();
self.0.force_update();
}
}
pub(crate) fn force_redraw(&self) {
self.0.force_redraw();
}

View file

@ -13,6 +13,7 @@ use crate::{
};
use calloop::LoopHandle;
use cosmic::iced::{Color, Task};
use cosmic_comp_config::AppearanceConfig;
use smithay::{
backend::{
input::KeyState,
@ -72,23 +73,14 @@ impl fmt::Debug for CosmicWindow {
}
}
#[derive(Debug)]
pub struct CosmicWindowInternal {
pub(super) window: CosmicSurface,
activated: AtomicBool,
/// TODO: This needs to be per seat
pointer_entered: AtomicU8,
last_title: Mutex<String>,
}
impl fmt::Debug for CosmicWindowInternal {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("CosmicWindowInternal")
.field("window", &self.window)
.field("activated", &self.activated.load(Ordering::SeqCst))
.field("pointer_entered", &self.pointer_entered)
// skip seat to avoid loop
.finish()
}
appearance_conf: Mutex<AppearanceConfig>,
}
#[repr(u8)]
@ -184,6 +176,7 @@ impl CosmicWindow {
window: impl Into<CosmicSurface>,
handle: LoopHandle<'static, crate::state::State>,
theme: cosmic::Theme,
appearance: AppearanceConfig,
) -> CosmicWindow {
let window = window.into();
let width = window.geometry().size.w;
@ -194,6 +187,7 @@ impl CosmicWindow {
activated: AtomicBool::new(false),
pointer_entered: AtomicU8::new(0),
last_title: Mutex::new(last_title),
appearance_conf: Mutex::new(appearance),
},
(width, SSD_HEIGHT),
handle,
@ -387,6 +381,22 @@ impl CosmicWindow {
self.0.set_theme(theme);
}
pub fn update_appearance_conf(&self, appearance: &AppearanceConfig) {
self.0.with_program(|p| {
let mut conf = p.appearance_conf.lock().unwrap();
if &*conf != appearance {
*conf = *appearance;
if appearance.clip_floating_windows {
p.window.set_tiled(true);
} else {
if !p.tiled.load(Ordering::Acquire) {
p.window.set_tiled(false);
}
}
}
})
}
pub(crate) fn force_redraw(&self) {
self.0.force_redraw();
}