Skip to content

Commit

Permalink
Propagate live config changes
Browse files Browse the repository at this point in the history
  • Loading branch information
William Calliari authored and William Calliari committed Dec 30, 2024
1 parent 22c5ce2 commit e3d94cc
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 15 deletions.
7 changes: 4 additions & 3 deletions cosmic-comp-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,15 @@ fn default_repeat_delay() -> u32 {
600
}


#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
pub struct StackBehavior {
pub close_tab_on_middle_click: bool,
}

impl Default for StackBehavior {
fn default() -> Self {
Self { close_tab_on_middle_click: true }
Self {
close_tab_on_middle_click: true,
}
}
}
}
12 changes: 9 additions & 3 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ mod types;
pub use self::types::*;
use cosmic::config::CosmicTk;
use cosmic_comp_config::{
input::InputConfig, workspace::WorkspaceConfig, CosmicCompConfig, StackBehavior, TileBehavior, XkbConfig
input::InputConfig, workspace::WorkspaceConfig, CosmicCompConfig, StackBehavior, TileBehavior,
XkbConfig,
};

#[derive(Debug)]
Expand Down Expand Up @@ -709,8 +710,13 @@ fn config_changed(config: cosmic_config::Config, keys: Vec<String>, state: &mut
"stack_behavior" => {
let new = get_config::<StackBehavior>(&config, "stack_behavior");
if new != state.common.config.cosmic_conf.stack_behavior {
state.common.config.cosmic_conf.stack_behavior = new;
state.common.update_config();
state.common.config.cosmic_conf.stack_behavior = new.clone();

let mut shell = state.common.shell.write().unwrap();
let shell_ref = &mut *shell;
shell_ref
.workspaces
.update_stack_behavior(new, shell_ref.seats.iter())
}
}
"active_hint" => {
Expand Down
7 changes: 7 additions & 0 deletions src/shell/element/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,13 @@ impl CosmicMapped {
_ => unreachable!(),
}
}

pub fn update_stack_behavior(&mut self, behavior: &StackBehavior) {
if let CosmicMappedInternal::Stack(stack) = &mut self.element {
let mut inner = stack.0 .0.lock().unwrap();
inner.program_mut().update_behavior(behavior.clone());
}
}
}

impl IsAlive for CosmicMapped {
Expand Down
4 changes: 4 additions & 0 deletions src/shell/element/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ impl CosmicStackInternal {
pub fn current_focus(&self) -> Option<Focus> {
unsafe { Focus::from_u8(self.pointer_entered.load(Ordering::SeqCst)) }
}

pub fn update_behavior(&mut self, behavior: StackBehavior) {
self.behavior = behavior;
}
}

pub const TAB_HEIGHT: i32 = 24;
Expand Down
3 changes: 1 addition & 2 deletions src/shell/element/stack/tab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,13 +425,12 @@ where
if matches!(
event,
event::Event::Mouse(mouse::Event::ButtonReleased(mouse::Button::Middle))
) {
) {
if let Some(message) = self.middle_click_message.clone() {
shell.publish(message);
return event::Status::Captured;
}
}

}

status
Expand Down
6 changes: 5 additions & 1 deletion src/shell/layout/floating/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1015,7 +1015,11 @@ impl FloatingLayout {
if mapped.is_window() {
// if it is just a window
self.space.unmap_elem(&mapped);
mapped.convert_to_stack((&output, mapped.bbox()), self.theme.clone(), stack_behavior.clone());
mapped.convert_to_stack(
(&output, mapped.bbox()),
self.theme.clone(),
stack_behavior.clone(),
);
self.map_internal(
mapped.clone(),
Some(location.as_local()),
Expand Down
29 changes: 23 additions & 6 deletions src/shell/layout/tiling/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ pub struct TilingLayout {
swapping_stack_surface_id: Id,
last_overview_hover: Option<(Option<Instant>, TargetZone)>,
pub theme: cosmic::Theme,
stack_behavior: StackBehavior,
pub stack_behavior: StackBehavior,
}

#[derive(Debug, Clone, PartialEq)]
Expand Down Expand Up @@ -344,7 +344,11 @@ pub struct MinimizedTilingState {
}

impl TilingLayout {
pub fn new(theme: cosmic::Theme, output: &Output, stack_behavior: StackBehavior) -> TilingLayout {
pub fn new(
theme: cosmic::Theme,
output: &Output,
stack_behavior: StackBehavior,
) -> TilingLayout {
TilingLayout {
queue: TreeQueue {
trees: {
Expand Down Expand Up @@ -2124,7 +2128,7 @@ impl TilingLayout {
&mut self,
mapped: &CosmicMapped,
mut focus_stack: FocusStackMut,
stack_behavior: &StackBehavior
stack_behavior: &StackBehavior,
) -> Option<KeyboardFocusTarget> {
let gaps = self.gaps();

Expand All @@ -2141,7 +2145,11 @@ impl TilingLayout {
// if it is just a window
match tree.get_mut(&node_id).unwrap().data_mut() {
Data::Mapped { mapped, .. } => {
mapped.convert_to_stack((&self.output, mapped.bbox()), self.theme.clone(), stack_behavior.clone());
mapped.convert_to_stack(
(&self.output, mapped.bbox()),
self.theme.clone(),
stack_behavior.clone(),
);
focus_stack.append(&mapped);
KeyboardFocusTarget::Element(mapped.clone())
}
Expand Down Expand Up @@ -2279,7 +2287,12 @@ impl TilingLayout {
return None;
}
let handle = handle.unwrap();
let stack = CosmicStack::new(surfaces.into_iter(), handle, self.theme.clone(), stack_behavior.clone());
let stack = CosmicStack::new(
surfaces.into_iter(),
handle,
self.theme.clone(),
stack_behavior.clone(),
);

for child in tree
.children_ids(&last_active)
Expand Down Expand Up @@ -2746,7 +2759,11 @@ impl TilingLayout {
Some(TargetZone::WindowStack(window_id, _)) if tree.get(&window_id).is_ok() => {
match tree.get_mut(window_id).unwrap().data_mut() {
Data::Mapped { mapped, .. } => {
mapped.convert_to_stack((&self.output, mapped.bbox()), self.theme.clone(), self.stack_behavior.clone());
mapped.convert_to_stack(
(&self.output, mapped.bbox()),
self.theme.clone(),
self.stack_behavior.clone(),
);
let Some(stack) = mapped.stack_ref_mut() else {
unreachable!()
};
Expand Down
28 changes: 28 additions & 0 deletions src/shell/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1138,6 +1138,34 @@ impl Workspaces {
self.autotile = autotile;
self.apply_tile_change(guard, seats);
}

pub fn update_stack_behavior<'a>(
&mut self,
behavior: StackBehavior,
seats: impl Iterator<Item = &'a Seat<State>>,
) {
let seats = seats.cloned().collect::<Vec<_>>();
self.stack_behavior = behavior.clone();
for (_, set) in &mut self.sets {
set.stack_behavior = behavior.clone();

for w in &mut set.workspaces {
w.tiling_layer.stack_behavior = behavior.clone();
for seat in &seats {
let stack = w.focus_stack.get_mut(seat);
*stack.0 = stack
.0
.clone()
.into_iter()
.map(|mut window| {
window.update_stack_behavior(&behavior);
window
})
.collect();
}
}
}
}
}

#[derive(Debug)]
Expand Down
4 changes: 4 additions & 0 deletions src/utils/iced.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,10 @@ impl<P: Program + Send + 'static> IcedElementInternal<P> {
}
Vec::new()
}

pub fn program_mut(&mut self) -> &mut P {
&mut self.state.program_mut().0
}
}

impl<P: Program + Send + 'static> PointerTarget<crate::state::State> for IcedElement<P> {
Expand Down

0 comments on commit e3d94cc

Please sign in to comment.