From cf0b0f9d2df69365d026c820ddedbd73049e3256 Mon Sep 17 00:00:00 2001 From: Victoria Brekenfeld Date: Fri, 7 Jun 2024 19:51:47 +0200 Subject: [PATCH] chore: Move some rendering-related state into the shell --- src/backend/render/mod.rs | 33 +++++++++++------------ src/backend/winit.rs | 4 +-- src/backend/x11.rs | 4 +-- src/input/mod.rs | 15 +++-------- src/shell/mod.rs | 24 +++++++++++++++-- src/wayland/handlers/screencopy/render.rs | 8 ++---- 6 files changed, 45 insertions(+), 43 deletions(-) diff --git a/src/backend/render/mod.rs b/src/backend/render/mod.rs index 266dde8e..d192c472 100644 --- a/src/backend/render/mod.rs +++ b/src/backend/render/mod.rs @@ -477,9 +477,7 @@ where pub fn workspace_elements( _gpu: Option<&DrmNode>, renderer: &mut R, - shell: &Shell, - config: &Config, - theme: &Theme, + shell: &Arc>, now: Time, output: &Output, previous: Option<(WorkspaceHandle, usize, WorkspaceDelta)>, @@ -495,7 +493,10 @@ where CosmicMappedRenderElement: RenderElement, WorkspaceRenderElement: RenderElement, { + let theme = shell.read().unwrap().theme().clone(); let seats = shell + .read() + .unwrap() .seats .iter() .cloned() @@ -504,7 +505,7 @@ where let mut elements = cursor_elements( renderer, seats.iter(), - theme, + &theme, now, output, cursor_mode, @@ -535,6 +536,8 @@ where } } + let shell = shell.read().unwrap(); + // If session locked, only show session lock surfaces if let Some(session_lock) = &shell.session_lock { elements.extend( @@ -606,7 +609,7 @@ where Vec::new() }; - let active_hint = if config.cosmic_conf.active_hint { + let active_hint = if shell.active_hint { theme.active_hint as u8 } else { 0 @@ -695,7 +698,7 @@ where let offset = match previous.as_ref() { Some((previous, previous_idx, start)) => { - let layout = config.cosmic_conf.workspaces.workspace_layout; + let layout = shell.workspaces.layout; let workspace = shell .workspaces @@ -964,9 +967,7 @@ pub fn render_output<'d, R, Target, OffTarget>( target: Target, damage_tracker: &'d mut OutputDamageTracker, age: usize, - shell: &Shell, - config: &Config, - theme: &Theme, + shell: &Arc>, now: Time, output: &Output, cursor_mode: CursorMode, @@ -989,12 +990,14 @@ where WorkspaceRenderElement: RenderElement, Target: Clone, { - let (previous_workspace, workspace) = shell.workspaces.active(output); - let (previous_idx, idx) = shell.workspaces.active_num(output); + let shell_ref = shell.read().unwrap(); + let (previous_workspace, workspace) = shell_ref.workspaces.active(output); + let (previous_idx, idx) = shell_ref.workspaces.active_num(output); let previous_workspace = previous_workspace .zip(previous_idx) .map(|((w, start), idx)| (w.handle, idx, start)); let workspace = (workspace.handle, idx); + std::mem::drop(shell_ref); let result = render_workspace( gpu, @@ -1004,8 +1007,6 @@ where age, None, shell, - config, - theme, now, output, previous_workspace, @@ -1118,9 +1119,7 @@ pub fn render_workspace<'d, R, Target, OffTarget>( damage_tracker: &'d mut OutputDamageTracker, age: usize, additional_damage: Option>>, - shell: &Shell, - config: &Config, - theme: &Theme, + shell: &Arc>, now: Time, output: &Output, previous: Option<(WorkspaceHandle, usize, WorkspaceDelta)>, @@ -1154,8 +1153,6 @@ where gpu, renderer, shell, - config, - theme, now, output, previous, diff --git a/src/backend/winit.rs b/src/backend/winit.rs index 75bec651..8f92eaf1 100644 --- a/src/backend/winit.rs +++ b/src/backend/winit.rs @@ -64,9 +64,7 @@ impl WinitState { surface.clone(), &mut self.damage_tracker, age, - &*state.shell.read().unwrap(), - &state.config, - &state.theme, + &state.shell, state.clock.now(), &self.output, CursorMode::NotDefault, diff --git a/src/backend/x11.rs b/src/backend/x11.rs index e3f8817d..dd74a96a 100644 --- a/src/backend/x11.rs +++ b/src/backend/x11.rs @@ -219,9 +219,7 @@ impl Surface { buffer.clone(), &mut self.damage_tracker, age as usize, - &*state.shell.read().unwrap(), - &state.config, - &state.theme, + &state.shell, state.clock.now(), &self.output, render::CursorMode::NotDefault, diff --git a/src/input/mod.rs b/src/input/mod.rs index f5b61335..c93c6ca5 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -1671,17 +1671,10 @@ impl State { } #[cfg(feature = "debug")] Action::Debug => { - self.common.egui.active = !self.common.egui.active; - for mapped in self - .common - .shell - .read() - .unwrap() - .workspaces - .spaces() - .flat_map(|w| w.mapped()) - { - mapped.set_debug(self.common.egui.active); + let mut shell = self.common.shell.write().unwrap(); + shell.debug_active = !shell.debug_active; + for mapped in shell.workspaces.spaces().flat_map(|w| w.mapped()) { + mapped.set_debug(shell.debug_active); } } #[cfg(not(feature = "debug"))] diff --git a/src/shell/mod.rs b/src/shell/mod.rs index c26c052f..ddfbb717 100644 --- a/src/shell/mod.rs +++ b/src/shell/mod.rs @@ -7,7 +7,10 @@ use std::{ }; use wayland_backend::server::ClientId; -use cosmic_comp_config::{workspace::WorkspaceMode, TileBehavior}; +use cosmic_comp_config::{ + workspace::{WorkspaceLayout, WorkspaceMode}, + TileBehavior, +}; use cosmic_protocols::workspace::v1::server::zcosmic_workspace_handle_v1::{ State as WState, TilingState, }; @@ -200,6 +203,7 @@ pub struct Shell { pub seats: Seats, theme: cosmic::Theme, + pub active_hint: bool, overview_mode: OverviewMode, swap_indicator: Option, resize_mode: ResizeMode, @@ -212,6 +216,9 @@ pub struct Shell { Output, )>, resize_indicator: Option, + + #[cfg(feature = "debug")] + debug_active: bool, } #[derive(Debug)] @@ -552,6 +559,7 @@ impl WorkspaceSet { pub struct Workspaces { pub sets: IndexMap, backup_set: Option, + pub layout: WorkspaceLayout, mode: WorkspaceMode, autotile: bool, autotile_behavior: TileBehavior, @@ -563,6 +571,7 @@ impl Workspaces { Workspaces { sets: IndexMap::new(), backup_set: None, + layout: config.cosmic_conf.workspaces.workspace_layout, mode: config.cosmic_conf.workspaces.workspace_mode, autotile: config.cosmic_conf.autotile, autotile_behavior: config.cosmic_conf.autotile_behavior, @@ -736,6 +745,7 @@ impl Workspaces { ) { let old_mode = self.mode; self.mode = config.cosmic_conf.workspaces.workspace_mode; + self.layout = config.cosmic_conf.workspaces.workspace_layout; if self.sets.len() <= 1 { return; @@ -1091,6 +1101,8 @@ impl Common { pub fn update_config(&mut self) { let mut shell = self.shell.write().unwrap(); + shell.active_hint = self.config.cosmic_conf.active_hint; + let mut workspace_state = self.workspace_state.update(); shell.workspaces.update_config( &self.config, @@ -1147,11 +1159,15 @@ impl Shell { session_lock: None, theme, + active_hint: config.cosmic_conf.active_hint, overview_mode: OverviewMode::None, swap_indicator: None, resize_mode: ResizeMode::None, resize_state: None, resize_indicator: None, + + #[cfg(feature = "debug")] + debug_active: false, } } @@ -1833,7 +1849,7 @@ impl Shell { )); #[cfg(feature = "debug")] { - mapped.set_debug(state.common.egui.active); + mapped.set_debug(self.debug_active); } let workspace_empty = workspace.mapped().next().is_none(); @@ -3162,6 +3178,10 @@ impl Shell { .set_theme(theme.clone(), xdg_activation_state); } + pub fn theme(&self) -> &cosmic::Theme { + &self.theme + } + pub fn take_presentation_feedback( &self, output: &Output, diff --git a/src/wayland/handlers/screencopy/render.rs b/src/wayland/handlers/screencopy/render.rs index ca3547b9..3ddb2d3a 100644 --- a/src/wayland/handlers/screencopy/render.rs +++ b/src/wayland/handlers/screencopy/render.rs @@ -284,9 +284,7 @@ pub fn render_workspace_to_buffer( dt, age, additional_damage, - &*common.shell.read().unwrap(), - &common.config, - &common.theme, + &common.shell, common.clock.now(), &output, None, @@ -312,9 +310,7 @@ pub fn render_workspace_to_buffer( dt, age, additional_damage, - &*common.shell.read().unwrap(), - &common.config, - &common.theme, + &common.shell, common.clock.now(), &output, None,