diff --git a/Cargo.lock b/Cargo.lock index 864b0979..c16d697d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -843,6 +843,7 @@ dependencies = [ "log-panics", "once_cell", "ordered-float", + "parking_lot 0.12.3", "png", "profiling", "rand 0.9.1", diff --git a/Cargo.toml b/Cargo.toml index 179a5bea..57f29dab 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -65,6 +65,7 @@ rand = "0.9.0" reis = { version = "0.5", features = ["calloop"] } # CLI arguments clap_lex = "0.7" +parking_lot = "0.12.3" [dependencies.id_tree] branch = "feature/copy_clone" diff --git a/src/backend/kms/device.rs b/src/backend/kms/device.rs index 3b9a2964..47eadab9 100644 --- a/src/backend/kms/device.rs +++ b/src/backend/kms/device.rs @@ -307,7 +307,7 @@ impl State { let connectors = device.enumerate_surfaces()?.added; // There are no removed outputs on newly added devices let mut wl_outputs = Vec::new(); - let mut w = self.common.shell.read().unwrap().global_space().size.w as u32; + let mut w = self.common.shell.read().global_space().size.w as u32; { for (conn, maybe_crtc) in connectors { @@ -380,7 +380,7 @@ impl State { if let Some(device) = backend.drm_devices.get_mut(&drm_node) { let changes = device.enumerate_surfaces()?; - let mut w = self.common.shell.read().unwrap().global_space().size.w as u32; + let mut w = self.common.shell.read().global_space().size.w as u32; for conn in changes.removed { // contains conns with updated crtcs, just drop the surface and re-create if let Some(pos) = device @@ -577,7 +577,7 @@ impl Device { position: (u32, u32), evlh: &LoopHandle<'static, State>, screen_filter: ScreenFilter, - shell: Arc>, + shell: Arc>, startup_done: Arc, ) -> Result<(Output, bool)> { let output = self @@ -676,7 +676,7 @@ impl Device { flags: FrameFlags, renderer: &mut GlMultiRenderer, clock: &Clock, - shell: &Arc>, + shell: &Arc>, ) -> Result<()> { for surface in self.surfaces.values_mut() { surface.allow_frame_flags(flag, flags); @@ -733,7 +733,7 @@ impl Device { flag: bool, renderer: &mut GlMultiRenderer, clock: &Clock, - shell: &Arc>, + shell: &Arc>, ) -> Result<()> { self.allow_frame_flags( flag, @@ -749,7 +749,7 @@ impl Device { flag: bool, renderer: &mut GlMultiRenderer, clock: &Clock, - shell: &Arc>, + shell: &Arc>, ) -> Result<()> { self.allow_frame_flags( flag, diff --git a/src/backend/kms/mod.rs b/src/backend/kms/mod.rs index 4991f933..2725e3cd 100644 --- a/src/backend/kms/mod.rs +++ b/src/backend/kms/mod.rs @@ -169,7 +169,7 @@ fn init_libinput( state.process_input_event(event); - for output in state.common.shell.read().unwrap().outputs() { + for output in state.common.shell.read().outputs() { state.backend.kms().schedule_render(output); } }) @@ -592,7 +592,7 @@ impl KmsState { test_only: bool, loop_handle: &LoopHandle<'static, State>, screen_filter: &ScreenFilter, - shell: Arc>, + shell: Arc>, startup_done: Arc, clock: &Clock, ) -> Result, anyhow::Error> { @@ -683,7 +683,7 @@ impl KmsState { } // add new ones - let mut w = shell.read().unwrap().global_space().size.w as u32; + let mut w = shell.read().global_space().size.w as u32; if !test_only { for (conn, crtc) in new_pairings { let (output, _) = device.connector_added( diff --git a/src/backend/kms/surface/mod.rs b/src/backend/kms/surface/mod.rs index e6802dcc..db5dc2cf 100644 --- a/src/backend/kms/surface/mod.rs +++ b/src/backend/kms/surface/mod.rs @@ -136,7 +136,7 @@ pub struct SurfaceThreadState { screen_filter: ScreenFilter, postprocess_textures: HashMap, - shell: Arc>, + shell: Arc>, loop_handle: LoopHandle<'static, Self>, clock: Clock, @@ -233,7 +233,7 @@ impl Surface { target_node: DrmNode, evlh: &LoopHandle<'static, State>, screen_filter: ScreenFilter, - shell: Arc>, + shell: Arc>, startup_done: Arc, ) -> Result { let (tx, rx) = channel::(); @@ -471,7 +471,7 @@ fn surface_thread( output: Output, primary_node: Arc>>, target_node: DrmNode, - shell: Arc>, + shell: Arc>, active: Arc, screen_filter: ScreenFilter, thread_sender: Sender, @@ -839,7 +839,7 @@ impl SurfaceThreadState { QueueState::WaitingForEstimatedVBlankAndQueued { .. } => unreachable!(), }; - if redraw_needed || self.shell.read().unwrap().animations_going() { + if redraw_needed || self.shell.read().animations_going() { let vblank_frame = tracy_client::Client::running() .unwrap() .non_continuous_frame(self.vblank_frame_name); @@ -866,7 +866,7 @@ impl SurfaceThreadState { self.frame_callback_seq = self.frame_callback_seq.wrapping_add(1); - if force || self.shell.read().unwrap().animations_going() { + if force || self.shell.read().animations_going() { self.queue_redraw(false); } else { self.send_frame_callbacks(); @@ -962,7 +962,7 @@ impl SurfaceThreadState { .as_ref() .unwrap_or(&self.target_node), &self.target_node, - &*self.shell.read().unwrap(), + &*self.shell.read(), ); let mut renderer = if render_node != self.target_node { @@ -979,7 +979,7 @@ impl SurfaceThreadState { let mut remove_frame_flags = FrameFlags::empty(); let has_active_fullscreen = { - let shell = self.shell.read().unwrap(); + let shell = self.shell.read(); let output = self.mirroring.as_ref().unwrap_or(&self.output); if let Some((_, workspace)) = shell.workspaces.active(output) { workspace.get_fullscreen().is_some() @@ -1416,7 +1416,6 @@ impl SurfaceThreadState { Some(( self.shell .read() - .unwrap() .take_presentation_feedback(&self.output, &frame_result.states), rx, estimated_presentation, diff --git a/src/backend/mod.rs b/src/backend/mod.rs index 66fdf271..c6a644a6 100644 --- a/src/backend/mod.rs +++ b/src/backend/mod.rs @@ -47,7 +47,6 @@ pub fn init_backend_auto( .common .shell .read() - .unwrap() .outputs() .next() .with_context(|| "Backend initialized without output") @@ -68,7 +67,6 @@ pub fn init_backend_auto( .common .shell .write() - .unwrap() .seats .add_seat(initial_seat.clone()); @@ -79,7 +77,7 @@ pub fn init_backend_auto( .accessibility_zoom .start_on_login { - state.common.shell.write().unwrap().trigger_zoom( + state.common.shell.write().trigger_zoom( &initial_seat, None, 1.0 + (state.common.config.cosmic_conf.accessibility_zoom.increment as f64 / 100.), @@ -117,7 +115,7 @@ pub fn init_backend_auto( .common .startup_done .store(true, std::sync::atomic::Ordering::SeqCst); - for output in state.common.shell.read().unwrap().outputs() { + for output in state.common.shell.read().outputs() { state.backend.schedule_render(&output); } } diff --git a/src/backend/render/mod.rs b/src/backend/render/mod.rs index 4ee1cd10..081d2ad0 100644 --- a/src/backend/render/mod.rs +++ b/src/backend/render/mod.rs @@ -5,7 +5,7 @@ use std::{ cell::RefCell, collections::HashMap, ops::ControlFlow, - sync::{Arc, RwLock, Weak}, + sync::{Arc, Weak}, time::Instant, }; @@ -559,7 +559,7 @@ pub enum ElementFilter { pub fn output_elements( _gpu: Option<&DrmNode>, renderer: &mut R, - shell: &Arc>, + shell: &Arc>, now: Time, output: &Output, cursor_mode: CursorMode, @@ -575,7 +575,7 @@ where #[cfg(feature = "debug")] let mut debug_elements = { let output_geo = output.geometry(); - let shell_guard = shell.read().unwrap(); + let shell_guard = shell.read(); let seats = shell_guard.seats.iter().cloned().collect::>(); let debug_active = shell_guard.debug_active; std::mem::drop(shell_guard); @@ -602,7 +602,7 @@ where } }; - let shell_guard = shell.read().unwrap(); + let shell_guard = shell.read(); let Some((previous_workspace, workspace)) = shell_guard.workspaces.active(output) else { #[cfg(not(feature = "debug"))] return Ok(Vec::new()); @@ -623,7 +623,7 @@ where } else { ElementFilter::All }; - let zoom_state = shell.read().unwrap().zoom_state().cloned(); + let zoom_state = shell.read().zoom_state().cloned(); #[allow(unused_mut)] let workspace_elements = workspace_elements( @@ -652,7 +652,7 @@ where pub fn workspace_elements( _gpu: Option<&DrmNode>, renderer: &mut R, - shell: &Arc>, + shell: &Arc>, zoom_level: Option<&ZoomState>, now: Time, output: &Output, @@ -670,7 +670,7 @@ where { let mut elements = Vec::new(); - let shell_ref = shell.read().unwrap(); + let shell_ref = shell.read(); let seats = shell_ref.seats.iter().cloned().collect::>(); if seats.is_empty() { return Ok(Vec::new()); @@ -692,7 +692,7 @@ where element_filter == ElementFilter::ExcludeWorkspaceOverview, )); - let shell = shell.read().unwrap(); + let shell = shell.read(); let overview = shell.overview_mode(); let (resize_mode, resize_indicator) = shell.resize_mode(); let resize_indicator = resize_indicator.map(|indicator| (resize_mode, indicator)); @@ -1136,7 +1136,7 @@ pub fn render_output<'d, R>( target: &mut R::Framebuffer<'_>, damage_tracker: &'d mut OutputDamageTracker, age: usize, - shell: &Arc>, + shell: &Arc>, now: Time, output: &Output, cursor_mode: CursorMode, @@ -1157,7 +1157,7 @@ where CosmicMappedRenderElement: RenderElement, WorkspaceRenderElement: RenderElement, { - let shell_ref = shell.read().unwrap(); + let shell_ref = shell.read(); let (previous_workspace, workspace) = shell_ref .workspaces .active(output) @@ -1439,7 +1439,7 @@ pub fn render_workspace<'d, R>( damage_tracker: &'d mut OutputDamageTracker, age: usize, additional_damage: Option>>, - shell: &Arc>, + shell: &Arc>, zoom_level: Option<&ZoomState>, now: Time, output: &Output, diff --git a/src/backend/winit.rs b/src/backend/winit.rs index 2f6861bc..e365c51f 100644 --- a/src/backend/winit.rs +++ b/src/backend/winit.rs @@ -76,7 +76,6 @@ impl WinitState { let mut output_presentation_feedback = state .shell .read() - .unwrap() .take_presentation_feedback(&self.output, &states); output_presentation_feedback.presented( state.clock.now(), @@ -297,7 +296,7 @@ impl State { // here we can handle special cases for winit inputs match event { WinitEvent::Focus(true) => { - for seat in self.common.shell.read().unwrap().seats.iter() { + for seat in self.common.shell.read().seats.iter() { let devices = seat.user_data().get::().unwrap(); if devices.has_device(&WinitVirtualDevice) { seat.set_active_output(&self.backend.winit().output); diff --git a/src/backend/x11.rs b/src/backend/x11.rs index eec0d44b..8b4b4a4b 100644 --- a/src/backend/x11.rs +++ b/src/backend/x11.rs @@ -240,7 +240,6 @@ impl Surface { let mut output_presentation_feedback = state .shell .read() - .unwrap() .take_presentation_feedback(&self.output, &states); output_presentation_feedback.presented( state.clock.now(), @@ -520,7 +519,7 @@ impl State { .unwrap(); let device = event.device(); - for seat in self.common.shell.read().unwrap().seats.iter() { + for seat in self.common.shell.read().seats.iter() { let devices = seat.user_data().get::().unwrap(); if devices.has_device(&device) { seat.set_active_output(&output); @@ -534,7 +533,7 @@ impl State { self.process_input_event(event); // TODO actually figure out the output - for output in self.common.shell.read().unwrap().outputs() { + for output in self.common.shell.read().outputs() { self.backend.x11().schedule_render(output); } } diff --git a/src/config/mod.rs b/src/config/mod.rs index e7ddf409..d6dba891 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -33,7 +33,7 @@ use std::{ fs::OpenOptions, io::Write, path::PathBuf, - sync::{atomic::AtomicBool, Arc, RwLock}, + sync::{atomic::AtomicBool, Arc}, }; use tracing::{error, warn}; @@ -227,7 +227,7 @@ impl Config { if let Ok(tk_config) = cosmic_config::Config::new("com.system76.CosmicTk", 1) { fn handle_new_toolkit_config(config: CosmicTk, state: &mut State) { let mut workspace_guard = state.common.workspace_state.update(); - state.common.shell.write().unwrap().update_toolkit( + state.common.shell.write().update_toolkit( config, &state.common.xdg_activation_state, &mut workspace_guard, @@ -308,14 +308,9 @@ impl Config { "tiling_exception_defaults" | "tiling_exception_custom" => { let new_exceptions = window_rules::tiling_exceptions(&config); state.common.config.tiling_exceptions = new_exceptions; - state - .common - .shell - .write() - .unwrap() - .update_tiling_exceptions( - state.common.config.tiling_exceptions.iter(), - ); + state.common.shell.write().update_tiling_exceptions( + state.common.config.tiling_exceptions.iter(), + ); } _ => (), } @@ -470,7 +465,7 @@ impl Config { &mut self, output_state: &mut OutputConfigurationState, backend: &mut BackendData, - shell: &Arc>, + shell: &Arc>, loop_handle: &LoopHandle<'static, State>, workspace_state: &mut WorkspaceUpdateGuard<'_, State>, xdg_activation_state: &XdgActivationState, @@ -809,7 +804,6 @@ fn config_changed(config: cosmic_config::Config, keys: Vec, state: &mut .common .shell .read() - .unwrap() .seats .iter() .cloned() @@ -843,7 +837,7 @@ fn config_changed(config: cosmic_config::Config, keys: Vec, state: &mut "keyboard_config" => { let value = get_config::(&config, "keyboard_config"); state.common.config.cosmic_conf.keyboard_config = value; - let shell = state.common.shell.read().unwrap(); + let shell = state.common.shell.read(); let seat = shell.seats.last_active(); state.common.config.dynamic_conf.numlock_mut().last_state = seat.get_keyboard().unwrap().modifier_state().num_lock; @@ -873,7 +867,7 @@ fn config_changed(config: cosmic_config::Config, keys: Vec, state: &mut if new != state.common.config.cosmic_conf.autotile { state.common.config.cosmic_conf.autotile = new; - let mut shell = state.common.shell.write().unwrap(); + let mut shell = state.common.shell.write(); let shell_ref = &mut *shell; shell_ref.workspaces.update_autotile( new, @@ -887,7 +881,7 @@ fn config_changed(config: cosmic_config::Config, keys: Vec, state: &mut if new != state.common.config.cosmic_conf.autotile_behavior { state.common.config.cosmic_conf.autotile_behavior = new; - let mut shell = state.common.shell.write().unwrap(); + let mut shell = state.common.shell.write(); let shell_ref = &mut *shell; shell_ref.workspaces.update_autotile_behavior( new, diff --git a/src/input/actions.rs b/src/input/actions.rs index 143d918a..84cc9000 100644 --- a/src/input/actions.rs +++ b/src/input/actions.rs @@ -46,7 +46,7 @@ impl State { ) { // TODO: Detect if started from login manager or tty, and only allow // `Terminate` if it will return to login manager. - if self.common.shell.read().unwrap().session_lock.is_some() + if self.common.shell.read().session_lock.is_some() && !matches!( action, Action::Shortcut(shortcuts::Action::Terminate) @@ -65,7 +65,7 @@ impl State { } Action::Private(PrivateAction::Escape) => { { - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); shell.set_overview_mode(None, self.common.event_loop_handle.clone()); shell.set_resize_mode( None, @@ -88,13 +88,11 @@ impl State { self.common .shell .write() - .unwrap() .resize(seat, direction, edge.into()); } else { self.common .shell .write() - .unwrap() .finish_resize(direction, edge.into()); } } @@ -107,7 +105,7 @@ impl State { match action { SwipeAction::NextWorkspace => { let _ = to_next_workspace( - &mut *self.common.shell.write().unwrap(), + &mut *self.common.shell.write(), &seat, true, &mut self.common.workspace_state.update(), @@ -115,7 +113,7 @@ impl State { } SwipeAction::PrevWorkspace => { let _ = to_previous_workspace( - &mut *self.common.shell.write().unwrap(), + &mut *self.common.shell.write(), &seat, true, &mut self.common.workspace_state.update(), @@ -143,7 +141,7 @@ impl State { #[cfg(feature = "debug")] Action::Debug => { - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); shell.debug_active = !shell.debug_active; for mapped in shell.workspaces.spaces().flat_map(|w| w.mapped()) { mapped.set_debug(shell.debug_active); @@ -157,11 +155,7 @@ impl State { Action::Close => { if let Some(focus_target) = seat.get_keyboard().unwrap().current_focus() { - self.common - .shell - .read() - .unwrap() - .close_focused(&focus_target); + self.common.shell.read().close_focused(&focus_target); } } @@ -171,7 +165,7 @@ impl State { 0 => 9, x => x - 1, }; - let _ = self.common.shell.write().unwrap().activate( + let _ = self.common.shell.write().activate( ¤t_output, workspace as usize, WorkspaceDelta::new_shortcut(), @@ -181,7 +175,7 @@ impl State { Action::LastWorkspace => { let current_output = seat.active_output(); - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); let workspace = shell.workspaces.len(¤t_output).saturating_sub(1); let _ = shell.activate( ¤t_output, @@ -205,7 +199,7 @@ impl State { } let next = to_next_workspace( - &mut *self.common.shell.write().unwrap(), + &mut *self.common.shell.write(), seat, false, &mut self.common.workspace_state.update(), @@ -251,7 +245,7 @@ impl State { } let previous = to_previous_workspace( - &mut *self.common.shell.write().unwrap(), + &mut *self.common.shell.write(), seat, false, &mut self.common.workspace_state.update(), @@ -293,7 +287,7 @@ impl State { Action::MoveToWorkspace(x) | Action::SendToWorkspace(x) => x - 1, _ => unreachable!(), }; - let res = self.common.shell.write().unwrap().move_current_window( + let res = self.common.shell.write().move_current_window( seat, &focused_output, (&focused_output, Some(workspace as usize)), @@ -316,7 +310,7 @@ impl State { let Some(focused_output) = seat.focused_output() else { return; }; - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); let workspace = shell.workspaces.len(&focused_output).saturating_sub(1); let res = shell.move_current_window( seat, @@ -356,7 +350,7 @@ impl State { }; let res = { - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); shell .workspaces .active_num(&focused_output) @@ -440,7 +434,7 @@ impl State { }; let res = { - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); shell .workspaces .active_num(&focused_output) @@ -508,7 +502,7 @@ impl State { Action::SwitchOutput(direction) => { let current_output = seat.active_output(); - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); let next_output = shell.next_output(¤t_output, direction).cloned(); @@ -603,7 +597,7 @@ impl State { let Some(focused_output) = seat.focused_output() else { return; }; - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); let next_output = shell.next_output(&focused_output, direction).cloned(); if let Some(next_output) = next_output { @@ -667,7 +661,7 @@ impl State { Action::MigrateWorkspaceToOutput(direction) => { let active_output = seat.active_output(); let (active, next_output) = { - let shell = self.common.shell.read().unwrap(); + let shell = self.common.shell.read(); ( shell.active_space(&active_output).unwrap().handle, @@ -692,7 +686,7 @@ impl State { } Action::Focus(focus) => { - let result = self.common.shell.read().unwrap().next_focus(focus, seat); + let result = self.common.shell.read().next_focus(focus, seat); match result { FocusResult::None => { @@ -706,7 +700,7 @@ impl State { if let Some(direction) = dir { if let Some(last_mod_serial) = seat.last_modifier_change() { - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); if !shell .previous_workspace_idx .as_ref() @@ -761,12 +755,11 @@ impl State { .common .shell .write() - .unwrap() .move_current_element(direction, seat); match res { MoveResult::MoveFurther(_move_further) => { if let Some(last_mod_serial) = seat.last_modifier_change() { - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); if !shell .previous_workspace_idx .as_ref() @@ -812,7 +805,7 @@ impl State { } _ => { let current_output = seat.active_output(); - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); let workspace = shell.active_space(¤t_output).unwrap(); if let Some(focused_window) = workspace.focus_stack.get(seat).last() { if workspace.is_tiled(focused_window) { @@ -830,7 +823,7 @@ impl State { let Some(focused_output) = seat.focused_output() else { return; }; - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); let workspace = shell.active_space_mut(&focused_output).unwrap(); if workspace.get_fullscreen().is_some() { @@ -843,7 +836,7 @@ impl State { let grab = SwapWindowGrab::new(seat.clone(), descriptor.clone()); drop(shell); keyboard_handle.set_grab(self, grab, serial); - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); shell.set_overview_mode( Some(Trigger::KeyboardSwap(pattern, descriptor)), self.common.event_loop_handle.clone(), @@ -856,7 +849,7 @@ impl State { let Some(focused_output) = seat.focused_output() else { return; }; - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); let workspace = shell.active_space_mut(&focused_output).unwrap(); let focus_stack = workspace.focus_stack.get(seat); let focused_window = focus_stack.last().cloned(); @@ -869,7 +862,7 @@ impl State { let Some(focused_output) = seat.focused_output() else { return; }; - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); let workspace = shell.active_space(&focused_output).unwrap(); let focus_stack = workspace.focus_stack.get(seat); let focused_window = focus_stack.last().cloned(); @@ -878,7 +871,7 @@ impl State { } } - Action::Resizing(direction) => self.common.shell.write().unwrap().set_resize_mode( + Action::Resizing(direction) => self.common.shell.write().set_resize_mode( Some((pattern, direction)), &self.common.config, self.common.event_loop_handle.clone(), @@ -887,14 +880,14 @@ impl State { // rather than the output that has keyboard focus Action::ToggleOrientation => { let output = seat.active_output(); - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); let workspace = shell.active_space_mut(&output).unwrap(); workspace.tiling_layer.update_orientation(None, &seat); } Action::Orientation(orientation) => { let output = seat.active_output(); - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); let workspace = shell.active_space_mut(&output).unwrap(); workspace .tiling_layer @@ -902,12 +895,7 @@ impl State { } Action::ToggleStacking => { - let res = self - .common - .shell - .write() - .unwrap() - .toggle_stacking_focused(seat); + let res = self.common.shell.write().toggle_stacking_focused(seat); if let Some(new_focus) = res { Shell::set_focus(self, Some(&new_focus), seat, Some(serial), false); } @@ -922,7 +910,7 @@ impl State { self.common.config.cosmic_conf.autotile = autotile; { - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); let shell_ref = &mut *shell; shell_ref.workspaces.update_autotile( self.common.config.cosmic_conf.autotile, @@ -938,7 +926,7 @@ impl State { }); } else { let output = seat.active_output(); - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); let workspace = shell.workspaces.active_mut(&output).unwrap(); let mut guard = self.common.workspace_state.update(); workspace.toggle_tiling(seat, &mut guard); @@ -949,17 +937,13 @@ impl State { let Some(output) = seat.focused_output() else { return; }; - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); let workspace = shell.active_space_mut(&output).unwrap(); workspace.toggle_floating_window_focused(seat); } Action::ToggleSticky => { - self.common - .shell - .write() - .unwrap() - .toggle_sticky_current(seat); + self.common.shell.write().toggle_sticky_current(seat); } // Gets the configured command for a given system action. @@ -991,7 +975,7 @@ impl State { } pub fn spawn_command(&mut self, command: String) { - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); let (token, data) = self.common.xdg_activation_state.create_external_token(None); let (token, data) = (token.clone(), data.clone()); @@ -1034,7 +1018,7 @@ impl State { pub fn update_zoom(&mut self, seat: &Seat, change: f64, animate: bool) { let output = seat.active_output(); - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); let (zoom_seat, current_level) = shell .zoom_state() .map(|state| (state.current_seat(), state.current_level(&output))) diff --git a/src/input/mod.rs b/src/input/mod.rs index f3eae087..c9023d68 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -170,7 +170,7 @@ impl State { use smithay::backend::input::Event; match event { InputEvent::DeviceAdded { device } => { - let shell = self.common.shell.read().unwrap(); + let shell = self.common.shell.read(); let seat = shell.seats.last_active(); let led_state = seat.get_keyboard().unwrap().led_state(); seat.devices().add_device(&device, led_state); @@ -182,7 +182,7 @@ impl State { } } InputEvent::DeviceRemoved { device } => { - for seat in &mut self.common.shell.read().unwrap().seats.iter() { + for seat in &mut self.common.shell.read().seats.iter() { let devices = seat.devices(); if devices.has_device(&device) { devices.remove_device(&device); @@ -205,7 +205,6 @@ impl State { .common .shell .read() - .unwrap() .seats .for_device(&event.device()) .cloned(); @@ -305,7 +304,7 @@ impl State { InputEvent::PointerMotion { event, .. } => { use smithay::backend::input::PointerMotionEvent; - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); if let Some(seat) = shell.seats.for_device(&event.device()).cloned() { self.common.idle_notifier_state.notify_activity(&seat); let current_output = seat.active_output(); @@ -389,7 +388,7 @@ impl State { } //If the pointer isn't grabbed, we should check if the focused element should be updated } else if self.common.config.cosmic_conf.focus_follows_cursor { - let shell = self.common.shell.read().unwrap(); + let shell = self.common.shell.read(); let old_keyboard_target = State::element_under(original_position, ¤t_output, &*shell); let new_keyboard_target = State::element_under(position, &output, &*shell); @@ -558,7 +557,7 @@ impl State { }); } - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); shell.update_pointer_position(position.to_local(&output), &output); shell.update_focal_point( &seat, @@ -604,7 +603,6 @@ impl State { .common .shell .read() - .unwrap() .seats .for_device(&event.device()) .cloned(); @@ -619,12 +617,9 @@ impl State { ) .as_global(); let serial = SERIAL_COUNTER.next_serial(); - let under = State::surface_under( - position, - &output, - &mut *self.common.shell.write().unwrap(), - ) - .map(|(target, pos)| (target, pos.as_logical())); + let under = + State::surface_under(position, &output, &mut *self.common.shell.write()) + .map(|(target, pos)| (target, pos.as_logical())); let ptr = seat.get_pointer().unwrap(); ptr.motion( @@ -638,7 +633,7 @@ impl State { ); ptr.frame(self); - let shell = self.common.shell.read().unwrap(); + let shell = self.common.shell.read(); for session in cursor_sessions_for_output(&*shell, &output) { if let Some((geometry, offset)) = seat.cursor_geometry( position.as_logical().to_buffer( @@ -673,7 +668,6 @@ impl State { .common .shell .read() - .unwrap() .seats .for_device(&event.device()) .cloned() @@ -707,7 +701,7 @@ impl State { let global_position = seat.get_pointer().unwrap().current_location().as_global(); let under = { - let shell = self.common.shell.read().unwrap(); + let shell = self.common.shell.read(); State::element_under(global_position, &output, &shell) }; if let Some(target) = under { @@ -747,8 +741,7 @@ impl State { supress_button(); self.common.event_loop_handle.insert_idle( move |state| { - let mut shell = - state.common.shell.write().unwrap(); + let mut shell = state.common.shell.write(); let res = shell.move_request( &surface, &seat_clone, @@ -770,8 +763,7 @@ impl State { supress_button(); self.common.event_loop_handle.insert_idle( move |state| { - let mut shell = - state.common.shell.write().unwrap(); + let mut shell = state.common.shell.write(); let Some(target_elem) = shell.element_for_surface(&surface) else { @@ -831,7 +823,7 @@ impl State { } } } else { - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); if let Some(Trigger::Pointer(action_button)) = shell.overview_mode().0.active_trigger() { @@ -882,7 +874,6 @@ impl State { .common .shell .read() - .unwrap() .seats .for_device(&event.device()) .cloned(); @@ -953,7 +944,6 @@ impl State { .common .shell .read() - .unwrap() .seats .for_device(&event.device()) .cloned(); @@ -980,7 +970,6 @@ impl State { .common .shell .read() - .unwrap() .seats .for_device(&event.device()) .cloned(); @@ -1053,7 +1042,7 @@ impl State { match gesture_state.action { Some(SwipeAction::NextWorkspace) | Some(SwipeAction::PrevWorkspace) => { - self.common.shell.write().unwrap().update_workspace_delta( + self.common.shell.write().update_workspace_delta( &seat.active_output(), gesture_state.delta, ) @@ -1081,7 +1070,6 @@ impl State { .common .shell .read() - .unwrap() .seats .for_device(&event.device()) .cloned(); @@ -1099,7 +1087,7 @@ impl State { } else { velocity / seat.active_output().geometry().size.h as f64 }; - let _ = self.common.shell.write().unwrap().end_workspace_swipe( + let _ = self.common.shell.write().end_workspace_swipe( &seat.active_output(), norm_velocity, &mut self.common.workspace_state.update(), @@ -1127,7 +1115,6 @@ impl State { .common .shell .read() - .unwrap() .seats .for_device(&event.device()) .cloned(); @@ -1150,7 +1137,6 @@ impl State { .common .shell .read() - .unwrap() .seats .for_device(&event.device()) .cloned(); @@ -1173,7 +1159,6 @@ impl State { .common .shell .read() - .unwrap() .seats .for_device(&event.device()) .cloned(); @@ -1196,7 +1181,6 @@ impl State { .common .shell .read() - .unwrap() .seats .for_device(&event.device()) .cloned(); @@ -1219,7 +1203,6 @@ impl State { .common .shell .read() - .unwrap() .seats .for_device(&event.device()) .cloned(); @@ -1239,7 +1222,7 @@ impl State { } InputEvent::TouchDown { event, .. } => { - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); if let Some(seat) = shell.seats.for_device(&event.device()).cloned() { self.common.idle_notifier_state.notify_activity(&seat); let Some(output) = @@ -1271,7 +1254,7 @@ impl State { } } InputEvent::TouchMotion { event, .. } => { - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); if let Some(seat) = shell.seats.for_device(&event.device()).cloned() { self.common.idle_notifier_state.notify_activity(&seat); let Some(output) = @@ -1301,7 +1284,7 @@ impl State { } } InputEvent::TouchUp { event, .. } => { - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); if let Some(Trigger::Touch(slot)) = shell.overview_mode().0.active_trigger() { if *slot == event.slot() { shell.set_overview_mode(None, self.common.event_loop_handle.clone()); @@ -1329,7 +1312,6 @@ impl State { .common .shell .read() - .unwrap() .seats .for_device(&event.device()) .cloned(); @@ -1344,7 +1326,6 @@ impl State { .common .shell .read() - .unwrap() .seats .for_device(&event.device()) .cloned(); @@ -1356,7 +1337,7 @@ impl State { } InputEvent::TabletToolAxis { event, .. } => { - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); if let Some(seat) = shell.seats.for_device(&event.device()).cloned() { self.common.idle_notifier_state.notify_activity(&seat); let Some(output) = @@ -1421,7 +1402,7 @@ impl State { } } InputEvent::TabletToolProximity { event, .. } => { - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); if let Some(seat) = shell.seats.for_device(&event.device()).cloned() { self.common.idle_notifier_state.notify_activity(&seat); let Some(output) = @@ -1480,7 +1461,6 @@ impl State { .common .shell .read() - .unwrap() .seats .for_device(&event.device()) .cloned(); @@ -1503,7 +1483,6 @@ impl State { .common .shell .read() - .unwrap() .seats .for_device(&event.device()) .cloned(); @@ -1533,7 +1512,7 @@ impl State { handle: KeysymHandle<'_>, serial: Serial, ) -> FilterResult> { - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); let keyboard = seat.get_keyboard().unwrap(); let pointer = seat.get_pointer().unwrap(); diff --git a/src/main.rs b/src/main.rs index 961bbad8..033ccd2a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -162,7 +162,7 @@ fn main() -> Result<(), Box> { } // trigger routines - let clients = state.common.shell.write().unwrap().update_animations(); + let clients = state.common.shell.write().update_animations(); { let dh = state.common.display_handle.clone(); for client in clients.values() { @@ -173,7 +173,7 @@ fn main() -> Result<(), Box> { refresh(state); { - let shell = state.common.shell.read().unwrap(); + let shell = state.common.shell.read(); if shell.animations_going() { for output in shell.outputs().cloned().collect::>().into_iter() { state.backend.schedule_render(&output); diff --git a/src/shell/element/stack.rs b/src/shell/element/stack.rs index f6417aa4..f984fdd4 100644 --- a/src/shell/element/stack.rs +++ b/src/shell/element/stack.rs @@ -695,7 +695,7 @@ impl CosmicStack { surface.send_configure(); if let Some(surface) = surface.wl_surface().map(Cow::into_owned) { let _ = data.common.event_loop_handle.insert_idle(move |state| { - let res = state.common.shell.write().unwrap().move_request( + let res = state.common.shell.write().move_request( &surface, &seat, serial, @@ -837,7 +837,7 @@ impl Program for CosmicStackInternal { .map(Cow::into_owned) { loop_handle.insert_idle(move |state| { - let res = state.common.shell.write().unwrap().move_request( + let res = state.common.shell.write().move_request( &surface, &seat, serial, @@ -867,12 +867,8 @@ impl Program for CosmicStackInternal { *self.potential_drag.lock().unwrap() = None; if let Some(surface) = self.windows.lock().unwrap().get(idx).cloned() { loop_handle.insert_idle(move |state| { - if let Some(mapped) = state - .common - .shell - .read() - .unwrap() - .element_for_surface(&surface) + if let Some(mapped) = + state.common.shell.read().element_for_surface(&surface) { mapped.stack_ref().unwrap().set_active(&surface); } @@ -896,7 +892,7 @@ impl Program for CosmicStackInternal { .map(Cow::into_owned) { loop_handle.insert_idle(move |state| { - let shell = state.common.shell.read().unwrap(); + let shell = state.common.shell.read(); if let Some(mapped) = shell.element_for_surface(&surface).cloned() { let position = if let Some((output, set)) = shell.workspaces.sets.iter().find(|(_, set)| { @@ -950,7 +946,7 @@ impl Program for CosmicStackInternal { .map(Cow::into_owned) { loop_handle.insert_idle(move |state| { - let shell = state.common.shell.read().unwrap(); + let shell = state.common.shell.read(); if let Some(mapped) = shell.element_for_surface(&surface).cloned() { if let Some(workspace) = shell.space_for(&mapped) { let Some(elem_geo) = workspace.element_geometry(&mapped) else { @@ -1407,7 +1403,7 @@ impl PointerTarget for CosmicStack { return; }; self.0.loop_handle().insert_idle(move |state| { - let res = state.common.shell.write().unwrap().resize_request( + let res = state.common.shell.write().resize_request( &surface, &seat, serial, @@ -1481,7 +1477,7 @@ impl PointerTarget for CosmicStack { surface.send_configure(); if let Some(surface) = surface.wl_surface().map(Cow::into_owned) { let _ = data.common.event_loop_handle.insert_idle(move |state| { - let res = state.common.shell.write().unwrap().move_request( + let res = state.common.shell.write().move_request( &surface, &seat, serial, diff --git a/src/shell/element/window.rs b/src/shell/element/window.rs index 0f866757..5080ecff 100644 --- a/src/shell/element/window.rs +++ b/src/shell/element/window.rs @@ -441,7 +441,7 @@ impl Program for CosmicWindowInternal { if let Some((seat, serial)) = last_seat.cloned() { if let Some(surface) = self.window.wl_surface().map(Cow::into_owned) { loop_handle.insert_idle(move |state| { - let res = state.common.shell.write().unwrap().move_request( + let res = state.common.shell.write().move_request( &surface, &seat, serial, @@ -467,7 +467,7 @@ impl Program for CosmicWindowInternal { Message::Minimize => { if let Some(surface) = self.window.wl_surface().map(Cow::into_owned) { loop_handle.insert_idle(move |state| { - let mut shell = state.common.shell.write().unwrap(); + let mut shell = state.common.shell.write(); if let Some(mapped) = shell.element_for_surface(&surface).cloned() { shell.minimize_request(&mapped) } @@ -477,7 +477,7 @@ impl Program for CosmicWindowInternal { Message::Maximize => { if let Some(surface) = self.window.wl_surface().map(Cow::into_owned) { loop_handle.insert_idle(move |state| { - let mut shell = state.common.shell.write().unwrap(); + let mut shell = state.common.shell.write(); if let Some(mapped) = shell.element_for_surface(&surface).cloned() { let seat = shell.seats.last_active().clone(); shell.maximize_toggle(&mapped, &seat) @@ -490,7 +490,7 @@ impl Program for CosmicWindowInternal { if let Some((seat, serial)) = last_seat.cloned() { if let Some(surface) = self.window.wl_surface().map(Cow::into_owned) { loop_handle.insert_idle(move |state| { - let shell = state.common.shell.read().unwrap(); + let shell = state.common.shell.read(); if let Some(mapped) = shell.element_for_surface(&surface).cloned() { let position = if let Some((output, set)) = shell.workspaces.sets.iter().find(|(_, set)| { @@ -763,7 +763,7 @@ impl PointerTarget for CosmicWindow { return; }; self.0.loop_handle().insert_idle(move |state| { - let res = state.common.shell.write().unwrap().resize_request( + let res = state.common.shell.write().resize_request( &surface, &seat, serial, diff --git a/src/shell/focus/mod.rs b/src/shell/focus/mod.rs index 5dd50f34..a46f4027 100644 --- a/src/shell/focus/mod.rs +++ b/src/shell/focus/mod.rs @@ -112,7 +112,6 @@ impl Shell { .common .shell .read() - .unwrap() .element_for_surface(window) .cloned(), _ => None, @@ -123,17 +122,12 @@ impl Shell { return; } - state - .common - .shell - .write() - .unwrap() - .append_focus_stack(&mapped, seat); + state.common.shell.write().append_focus_stack(&mapped, seat); } update_focus_state(seat, target, state, serial, update_cursor); - state.common.shell.write().unwrap().update_active(); + state.common.shell.write().update_active(); } pub fn append_focus_stack(&mut self, mapped: &CosmicMapped, seat: &Seat) { @@ -242,7 +236,7 @@ fn update_focus_state( if should_update_cursor && state.common.config.cosmic_conf.cursor_follows_focus { if target.is_some() { //need to borrow mutably for surface under - let shell = state.common.shell.read().unwrap(); + let shell = state.common.shell.read(); // get the top left corner of the target element let geometry = shell.focused_geometry(target.unwrap()); if let Some(geometry) = geometry { @@ -292,7 +286,6 @@ fn update_focus_state( .common .shell .read() - .unwrap() .get_output_for_focus(seat) .as_ref(), ) @@ -339,14 +332,13 @@ impl Common { .common .shell .read() - .unwrap() .seats .iter() .cloned() .collect::>(); for seat in &seats { { - let shell = state.common.shell.read().unwrap(); + let shell = state.common.shell.read(); let focused_output = seat.focused_output(); let active_output = seat.active_output(); @@ -365,7 +357,7 @@ impl Common { update_pointer_focus(state, &seat); let output = seat.focused_or_active_output(); - let mut shell = state.common.shell.write().unwrap(); + let mut shell = state.common.shell.write(); let last_known_focus = ActiveFocus::get(&seat); if let Some(target) = last_known_focus { @@ -454,7 +446,7 @@ impl Common { } } - state.common.shell.write().unwrap().update_active() + state.common.shell.write().update_active() } } @@ -582,7 +574,7 @@ fn update_pointer_focus(state: &mut State, seat: &Seat) { let output = seat.active_output(); let position = pointer.current_location().as_global(); - let mut shell = state.common.shell.write().unwrap(); + let mut shell = state.common.shell.write(); let under = State::surface_under(position, &output, &mut shell) .map(|(target, pos)| (target, pos.as_logical())); drop(shell); diff --git a/src/shell/focus/target.rs b/src/shell/focus/target.rs index d211ac59..aecd3eeb 100644 --- a/src/shell/focus/target.rs +++ b/src/shell/focus/target.rs @@ -240,7 +240,7 @@ impl IsAlive for KeyboardFocusTarget { impl PointerTarget for PointerFocusTarget { fn enter(&self, seat: &Seat, data: &mut State, event: &PointerMotionEvent) { - let toplevel = self.toplevel(&*data.common.shell.read().unwrap()); + let toplevel = self.toplevel(&*data.common.shell.read()); if let Some(element) = toplevel { for session in element.cursor_sessions() { session.set_cursor_pos(Some( @@ -270,7 +270,7 @@ impl PointerTarget for PointerFocusTarget { } } fn motion(&self, seat: &Seat, data: &mut State, event: &PointerMotionEvent) { - let toplevel = self.toplevel(&*data.common.shell.read().unwrap()); + let toplevel = self.toplevel(&*data.common.shell.read()); if let Some(element) = toplevel { for session in element.cursor_sessions() { session.set_cursor_pos(Some( @@ -346,7 +346,7 @@ impl PointerTarget for PointerFocusTarget { } } fn leave(&self, seat: &Seat, data: &mut State, serial: Serial, time: u32) { - let toplevel = self.toplevel(&*data.common.shell.read().unwrap()); + let toplevel = self.toplevel(&*data.common.shell.read()); if let Some(element) = toplevel { for session in element.cursor_sessions() { session.set_cursor_pos(None); diff --git a/src/shell/grabs/menu/default.rs b/src/shell/grabs/menu/default.rs index 40df674e..8c1079a9 100644 --- a/src/shell/grabs/menu/default.rs +++ b/src/shell/grabs/menu/default.rs @@ -16,7 +16,7 @@ use crate::{ use super::{Item, ResizeEdge}; fn toggle_stacking(state: &mut State, mapped: &CosmicMapped) { - let mut shell = state.common.shell.write().unwrap(); + let mut shell = state.common.shell.write(); let seat = shell.seats.last_active().clone(); if let Some(new_focus) = shell.toggle_stacking(&seat, mapped) { std::mem::drop(shell); @@ -25,7 +25,7 @@ fn toggle_stacking(state: &mut State, mapped: &CosmicMapped) { } fn move_prev_workspace(state: &mut State, mapped: &CosmicMapped) { - let mut shell = state.common.shell.write().unwrap(); + let mut shell = state.common.shell.write(); let seat = shell.seats.last_active().clone(); let (current_handle, output) = { let Some(ws) = shell.space_for(mapped) else { @@ -58,7 +58,7 @@ fn move_prev_workspace(state: &mut State, mapped: &CosmicMapped) { } fn move_next_workspace(state: &mut State, mapped: &CosmicMapped) { - let mut shell = state.common.shell.write().unwrap(); + let mut shell = state.common.shell.write(); let seat = shell.seats.last_active().clone(); let (current_handle, output) = { let Some(ws) = shell.space_for(mapped) else { @@ -114,7 +114,7 @@ pub fn tab_items( ) .into(); - let mut shell = state.common.shell.write().unwrap(); + let mut shell = state.common.shell.write(); let seat = shell.seats.last_active().clone(); let output = seat.active_output(); let workspace = shell.workspaces.active_mut(&output).unwrap(); @@ -198,12 +198,7 @@ pub fn window_items( Item::new(fl!("window-menu-minimize"), move |handle| { let mapped = minimize_clone.clone(); let _ = handle.insert_idle(move |state| { - state - .common - .shell - .write() - .unwrap() - .minimize_request(&mapped); + state.common.shell.write().minimize_request(&mapped); }); }) .shortcut(config.shortcut_for_action(&Action::Minimize)), @@ -212,7 +207,7 @@ pub fn window_items( Item::new(fl!("window-menu-maximize"), move |handle| { let mapped = maximize_clone.clone(); let _ = handle.insert_idle(move |state| { - let mut shell = state.common.shell.write().unwrap(); + let mut shell = state.common.shell.write(); let seat = shell.seats.last_active().clone(); shell.maximize_toggle(&mapped, &seat); }); @@ -224,7 +219,7 @@ pub fn window_items( Item::new(fl!("window-menu-tiled"), move |handle| { let tile_clone = tile_clone.clone(); let _ = handle.insert_idle(move |state| { - let mut shell = state.common.shell.write().unwrap(); + let mut shell = state.common.shell.write(); let seat = shell.seats.last_active().clone(); if let Some(ws) = shell.space_for_mut(&tile_clone) { ws.toggle_floating_window(&seat, &tile_clone); @@ -246,7 +241,7 @@ pub fn window_items( let move_clone = move_clone.clone(); let _ = handle.insert_idle(move |state| { if let Some(surface) = move_clone.wl_surface() { - let mut shell = state.common.shell.write().unwrap(); + let mut shell = state.common.shell.write(); let seat = shell.seats.last_active().clone(); let res = shell.move_request( &surface, @@ -285,7 +280,7 @@ pub fn window_items( Item::new(fl!("window-menu-resize-edge-top"), move |handle| { let resize_clone = resize_top_clone.clone(); let _ = handle.insert_idle(move |state| { - let mut shell = state.common.shell.write().unwrap(); + let mut shell = state.common.shell.write(); let seat = shell.seats.last_active().clone(); let res = shell.menu_resize_request( &resize_clone, @@ -320,7 +315,7 @@ pub fn window_items( Item::new(fl!("window-menu-resize-edge-left"), move |handle| { let resize_clone = resize_left_clone.clone(); let _ = handle.insert_idle(move |state| { - let mut shell = state.common.shell.write().unwrap(); + let mut shell = state.common.shell.write(); let seat = shell.seats.last_active().clone(); let res = shell.menu_resize_request( &resize_clone, @@ -355,7 +350,7 @@ pub fn window_items( Item::new(fl!("window-menu-resize-edge-right"), move |handle| { let resize_clone = resize_right_clone.clone(); let _ = handle.insert_idle(move |state| { - let mut shell = state.common.shell.write().unwrap(); + let mut shell = state.common.shell.write(); let seat = shell.seats.last_active().clone(); let res = shell.menu_resize_request( &resize_clone, @@ -390,7 +385,7 @@ pub fn window_items( Item::new(fl!("window-menu-resize-edge-bottom"), move |handle| { let resize_clone = resize_bottom_clone.clone(); let _ = handle.insert_idle(move |state| { - let mut shell = state.common.shell.write().unwrap(); + let mut shell = state.common.shell.write(); let seat = shell.seats.last_active().clone(); let res = shell.menu_resize_request( &resize_clone, @@ -445,7 +440,7 @@ pub fn window_items( Item::new(fl!("window-menu-sticky"), move |handle| { let mapped = sticky_clone.clone(); let _ = handle.insert_idle(move |state| { - let mut shell = state.common.shell.write().unwrap(); + let mut shell = state.common.shell.write(); let seat = shell.seats.last_active().clone(); shell.toggle_sticky(&seat, &mapped); }); diff --git a/src/shell/grabs/menu/mod.rs b/src/shell/grabs/menu/mod.rs index 15a90934..35b12ec9 100644 --- a/src/shell/grabs/menu/mod.rs +++ b/src/shell/grabs/menu/mod.rs @@ -522,7 +522,7 @@ impl PointerGrab for MenuGrab { let mut guard = self.elements.lock().unwrap(); let elements = &mut *guard; let event_location = if let Some(output) = self.screen_space_relative.as_ref() { - if state.common.shell.read().unwrap().zoom_state().is_some() { + if state.common.shell.read().zoom_state().is_some() { event .location .as_global() @@ -726,7 +726,7 @@ impl TouchGrab for MenuGrab { let mut guard = self.elements.lock().unwrap(); let elements = &mut *guard; let event_location = if let Some(output) = self.screen_space_relative.as_ref() { - if data.common.shell.read().unwrap().zoom_state().is_some() { + if data.common.shell.read().zoom_state().is_some() { event .location .as_global() diff --git a/src/shell/grabs/moving.rs b/src/shell/grabs/moving.rs index 5b3c7979..9e97f450 100644 --- a/src/shell/grabs/moving.rs +++ b/src/shell/grabs/moving.rs @@ -347,7 +347,7 @@ pub struct MoveGrab { impl MoveGrab { fn update_location(&mut self, state: &mut State, location: Point) { - let mut shell = state.common.shell.write().unwrap(); + let mut shell = state.common.shell.write(); let Some(current_output) = shell .outputs() @@ -792,7 +792,7 @@ impl Drop for MoveGrab { if grab_state.window.alive() { let window_location = (grab_state.location.to_i32_round() + grab_state.window_offset).as_global(); - let mut shell = state.common.shell.write().unwrap(); + let mut shell = state.common.shell.write(); let workspace_handle = shell.active_space(&output).unwrap().handle; for old_output in window_outputs.iter().filter(|o| *o != &output) { diff --git a/src/shell/layout/tiling/grabs/resize.rs b/src/shell/layout/tiling/grabs/resize.rs index 899e92af..52062427 100644 --- a/src/shell/layout/tiling/grabs/resize.rs +++ b/src/shell/layout/tiling/grabs/resize.rs @@ -227,7 +227,7 @@ impl ResizeForkGrab { self.last_loc = location.as_global(); if let Some(output) = self.output.upgrade() { - let mut shell = data.common.shell.write().unwrap(); + let mut shell = data.common.shell.write(); let Some(workspace) = shell.active_space_mut(&output) else { return false; }; diff --git a/src/shell/layout/tiling/grabs/swap.rs b/src/shell/layout/tiling/grabs/swap.rs index 28036ced..1f62d19c 100644 --- a/src/shell/layout/tiling/grabs/swap.rs +++ b/src/shell/layout/tiling/grabs/swap.rs @@ -39,7 +39,7 @@ impl KeyboardGrab for SwapWindowGrab { serial: Serial, time: u32, ) { - if !matches!(&data.common.shell.read().unwrap().overview_mode.active_trigger(), Some(Trigger::KeyboardSwap(_, d)) if d == &self.desc) + if !matches!(&data.common.shell.read().overview_mode.active_trigger(), Some(Trigger::KeyboardSwap(_, d)) if d == &self.desc) { handle.unset_grab(self, data, serial, false); return; diff --git a/src/shell/mod.rs b/src/shell/mod.rs index d59c77ac..aa194492 100644 --- a/src/shell/mod.rs +++ b/src/shell/mod.rs @@ -1309,7 +1309,7 @@ pub struct InvalidWorkspaceIndex; impl Common { pub fn add_output(&mut self, output: &Output) { - let mut shell = self.shell.write().unwrap(); + let mut shell = self.shell.write(); shell .workspaces .add_output(output, &mut self.workspace_state.update()); @@ -1333,7 +1333,7 @@ impl Common { } pub fn remove_output(&mut self, output: &Output) { - let mut shell = self.shell.write().unwrap(); + let mut shell = self.shell.write(); let shell_ref = &mut *shell; shell_ref.workspaces.remove_output( output, @@ -1351,7 +1351,7 @@ impl Common { return; } - let mut shell = self.shell.write().unwrap(); + let mut shell = self.shell.write(); shell .workspaces .migrate_workspace(from, to, handle, &mut self.workspace_state.update()); @@ -1360,7 +1360,7 @@ impl Common { } pub fn update_config(&mut self) { - let mut shell = self.shell.write().unwrap(); + let mut shell = self.shell.write(); let shell_ref = &mut *shell; shell_ref.active_hint = self.config.cosmic_conf.active_hint; if let Some(zoom_state) = shell_ref.zoom_state.as_mut() { @@ -1388,7 +1388,7 @@ impl Common { pub fn refresh(&mut self) { self.xdg_activation_state .retain_tokens(|_, data| data.timestamp.elapsed() < ACTIVATION_TOKEN_EXPIRE_TIME); - self.shell.write().unwrap().refresh( + self.shell.write().refresh( &self.xdg_activation_state, &mut self.workspace_state.update(), ); @@ -1410,7 +1410,7 @@ impl Common { pub fn on_commit(&mut self, surface: &WlSurface) { { - let shell = self.shell.read().unwrap(); + let shell = self.shell.read(); for seat in shell.seats.iter() { if let Some(move_grab) = seat.user_data().get::() { diff --git a/src/shell/zoom.rs b/src/shell/zoom.rs index b74c9ff8..619c9cf7 100644 --- a/src/shell/zoom.rs +++ b/src/shell/zoom.rs @@ -539,14 +539,7 @@ impl Program for ZoomProgram { match message { ZoomMessage::Decrease => { let _ = loop_handle.insert_idle(|state| { - let seat = state - .common - .shell - .read() - .unwrap() - .seats - .last_active() - .clone(); + let seat = state.common.shell.read().seats.last_active().clone(); let increment = state.common.config.cosmic_conf.accessibility_zoom.increment as f64 / 100.0; @@ -555,14 +548,7 @@ impl Program for ZoomProgram { } ZoomMessage::Increase => { let _ = loop_handle.insert_idle(|state| { - let seat = state - .common - .shell - .read() - .unwrap() - .seats - .last_active() - .clone(); + let seat = state.common.shell.read().seats.last_active().clone(); let increment = state.common.config.cosmic_conf.accessibility_zoom.increment as f64 / 100.0; @@ -576,7 +562,7 @@ impl Program for ZoomProgram { if let Some(start_data) = check_grab_preconditions(&seat, Some(serial), None) { - let shell = state.common.shell.read().unwrap(); + let shell = state.common.shell.read(); let output = seat.active_output(); if shell.zoom_state().is_some() { @@ -741,7 +727,7 @@ impl Program for ZoomProgram { if let Some(start_data) = check_grab_preconditions(&seat, Some(serial), None) { - let shell = state.common.shell.read().unwrap(); + let shell = state.common.shell.read(); let output = seat.active_output(); if shell.zoom_state().is_some() { diff --git a/src/state.rs b/src/state.rs index c03c817d..12e8973e 100644 --- a/src/state.rs +++ b/src/state.rs @@ -118,7 +118,7 @@ use std::{ collections::HashSet, ffi::OsString, process::Child, - sync::{atomic::AtomicBool, Arc, Mutex, Once, RwLock}, + sync::{atomic::AtomicBool, Arc, Mutex, Once}, time::{Duration, Instant}, }; @@ -195,7 +195,7 @@ pub struct Common { pub event_loop_signal: LoopSignal, pub popups: PopupManager, - pub shell: Arc>, + pub shell: Arc>, pub clock: Clock, pub startup_done: Arc, @@ -307,7 +307,7 @@ impl BackendData { test_only: bool, loop_handle: &LoopHandle<'static, State>, screen_filter: &ScreenFilter, - shell: Arc>, + shell: Arc>, workspace_state: &mut WorkspaceUpdateGuard<'_, State>, xdg_activation_state: &XdgActivationState, startup_done: Arc, @@ -327,7 +327,7 @@ impl BackendData { _ => unreachable!("No backend set when applying output config"), }?; - let mut shell = shell.write().unwrap(); + let mut shell = shell.write(); for output in result { // apply to Output let final_config = output @@ -561,7 +561,7 @@ impl State { DataControlState::new::(dh, Some(&primary_selection_state), |_| true) }); - let shell = Arc::new(RwLock::new(Shell::new(&config))); + let shell = Arc::new(parking_lot::RwLock::new(Shell::new(&config))); let layer_shell_state = WlrLayerShellState::new_with_filter::(dh, client_is_privileged); @@ -700,7 +700,7 @@ impl Common { output: &Output, render_element_states: &RenderElementStates, ) { - let shell = self.shell.read().unwrap(); + let shell = self.shell.read(); let processor = |surface: &WlSurface, states: &SurfaceData| { let primary_scanout_output = update_surface_primary_scanout_output( surface, @@ -802,7 +802,7 @@ impl Common { render_element_states: &RenderElementStates, mut dmabuf_feedback: impl FnMut(DrmNode) -> Option, ) { - let shell = self.shell.read().unwrap(); + let shell = self.shell.read(); if let Some(session_lock) = shell.session_lock.as_ref() { if let Some(lock_surface) = session_lock.surfaces.get(output) { @@ -995,7 +995,7 @@ impl Common { } } - let shell = self.shell.read().unwrap(); + let shell = self.shell.read(); if let Some(session_lock) = shell.session_lock.as_ref() { if let Some(lock_surface) = session_lock.surfaces.get(output) { diff --git a/src/theme.rs b/src/theme.rs index d2f3c005..26fefdf1 100644 --- a/src/theme.rs +++ b/src/theme.rs @@ -33,7 +33,7 @@ pub fn watch_theme(handle: LoopHandle<'_, State>) -> Result<(), cosmic_config::E if theme.theme_type != new_theme.theme_type { *theme = new_theme; let mut workspace_guard = state.common.workspace_state.update(); - state.common.shell.write().unwrap().set_theme( + state.common.shell.write().set_theme( theme.clone(), &state.common.xdg_activation_state, &mut workspace_guard, diff --git a/src/wayland/handlers/a11y.rs b/src/wayland/handlers/a11y.rs index 235d1e12..bd7d2cca 100644 --- a/src/wayland/handlers/a11y.rs +++ b/src/wayland/handlers/a11y.rs @@ -12,7 +12,7 @@ impl A11yHandler for State { } fn request_screen_magnifier(&mut self, enabled: bool) { - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); if shell .zoom_state() diff --git a/src/wayland/handlers/compositor.rs b/src/wayland/handlers/compositor.rs index c42cbc8d..70f13711 100644 --- a/src/wayland/handlers/compositor.rs +++ b/src/wayland/handlers/compositor.rs @@ -173,7 +173,7 @@ impl CompositorHandler for State { // handle initial configure events and map windows if necessary let mapped = self.send_initial_configure_and_map(surface); - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); // schedule a new render if let Some(output) = shell.visible_output_for_surface(surface) { @@ -277,7 +277,7 @@ impl CompositorHandler for State { impl State { fn send_initial_configure_and_map(&mut self, surface: &WlSurface) -> bool { - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); if let Some(pending) = shell .pending_windows diff --git a/src/wayland/handlers/decoration.rs b/src/wayland/handlers/decoration.rs index 5c5e5a2f..8589f7b9 100644 --- a/src/wayland/handlers/decoration.rs +++ b/src/wayland/handlers/decoration.rs @@ -114,14 +114,14 @@ pub fn unset_mode(mapped: &CosmicMapped, surface: &WlSurface) { impl XdgDecorationHandler for State { fn new_decoration(&mut self, toplevel: ToplevelSurface) { - let shell = self.common.shell.read().unwrap(); + let shell = self.common.shell.read(); if let Some(mapped) = shell.element_for_surface(toplevel.wl_surface()) { new_decoration(mapped, toplevel.wl_surface()); } } fn request_mode(&mut self, toplevel: ToplevelSurface, mode: XdgMode) { - let shell = self.common.shell.read().unwrap(); + let shell = self.common.shell.read(); if let Some(mapped) = shell.element_for_surface(toplevel.wl_surface()) { request_mode(mapped, toplevel.wl_surface(), mode); } else { @@ -130,7 +130,7 @@ impl XdgDecorationHandler for State { } fn unset_mode(&mut self, toplevel: ToplevelSurface) { - let shell = self.common.shell.read().unwrap(); + let shell = self.common.shell.read(); if let Some(mapped) = shell.element_for_surface(toplevel.wl_surface()) { unset_mode(mapped, toplevel.wl_surface()) } @@ -143,7 +143,7 @@ impl KdeDecorationHandler for State { } fn new_decoration(&mut self, surface: &WlSurface, decoration: &OrgKdeKwinServerDecoration) { - let shell = self.common.shell.read().unwrap(); + let shell = self.common.shell.read(); if let Some(mapped) = shell.element_for_surface(surface) { let mode = new_decoration(mapped, surface); decoration.mode(mode); @@ -157,7 +157,7 @@ impl KdeDecorationHandler for State { mode: WEnum, ) { if let WEnum::Value(mode) = mode { - let shell = self.common.shell.read().unwrap(); + let shell = self.common.shell.read(); // TODO: We need to store this value until it gets mapped and apply it then, if it is not mapped yet. if let Some(mapped) = shell.element_for_surface(surface) { request_mode( @@ -174,7 +174,7 @@ impl KdeDecorationHandler for State { } fn release(&mut self, _decoration: &OrgKdeKwinServerDecoration, surface: &WlSurface) { - let shell = self.common.shell.read().unwrap(); + let shell = self.common.shell.read(); if let Some(mapped) = shell.element_for_surface(surface) { unset_mode(mapped, surface) } diff --git a/src/wayland/handlers/fractional_scale.rs b/src/wayland/handlers/fractional_scale.rs index b2cf0a08..d57f2576 100644 --- a/src/wayland/handlers/fractional_scale.rs +++ b/src/wayland/handlers/fractional_scale.rs @@ -42,20 +42,11 @@ impl FractionalScaleHandler for State { self.common .shell .read() - .unwrap() .visible_output_for_surface(&surface) .cloned() }) }) - .unwrap_or_else(|| { - self.common - .shell - .read() - .unwrap() - .seats - .last_active() - .active_output() - }); + .unwrap_or_else(|| self.common.shell.read().seats.last_active().active_output()); with_states(&surface, |states| { with_fractional_scale(states, |fractional_scale| { diff --git a/src/wayland/handlers/input_method.rs b/src/wayland/handlers/input_method.rs index 4587dd67..d492d886 100644 --- a/src/wayland/handlers/input_method.rs +++ b/src/wayland/handlers/input_method.rs @@ -27,7 +27,6 @@ impl InputMethodHandler for State { self.common .shell .read() - .unwrap() .element_for_surface(parent) .map(|e| e.geometry()) .unwrap_or_default() diff --git a/src/wayland/handlers/layer_shell.rs b/src/wayland/handlers/layer_shell.rs index 839e8ea5..5955a761 100644 --- a/src/wayland/handlers/layer_shell.rs +++ b/src/wayland/handlers/layer_shell.rs @@ -26,7 +26,7 @@ impl WlrLayerShellHandler for State { _layer: Layer, namespace: String, ) { - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); let seat = shell.seats.last_active().clone(); let output = wl_output .as_ref() @@ -40,7 +40,7 @@ impl WlrLayerShellHandler for State { } fn new_popup(&mut self, _parent: WlrLayerSurface, popup: PopupSurface) { - self.common.shell.read().unwrap().unconstrain_popup(&popup); + self.common.shell.read().unconstrain_popup(&popup); if popup.send_configure().is_ok() { self.common @@ -51,7 +51,7 @@ impl WlrLayerShellHandler for State { } fn layer_destroyed(&mut self, surface: WlrLayerSurface) { - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); let maybe_output = shell .outputs() .find(|o| { diff --git a/src/wayland/handlers/overlap_notify.rs b/src/wayland/handlers/overlap_notify.rs index 5afd464f..d58b231f 100644 --- a/src/wayland/handlers/overlap_notify.rs +++ b/src/wayland/handlers/overlap_notify.rs @@ -22,7 +22,7 @@ impl OverlapNotifyHandler for State { .layer_surfaces() .find(|l| l.shell_surface() == &resource) .and_then(|l| { - let shell = self.common.shell.read().unwrap(); + let shell = self.common.shell.read(); let outputs = shell.outputs(); let ret = outputs.map(|o| layer_map_for_output(o)).find_map(|s| { s.layer_for_surface(l.wl_surface(), WindowSurfaceType::ALL) @@ -34,14 +34,14 @@ impl OverlapNotifyHandler for State { } fn outputs(&self) -> impl Iterator { - let shell = self.common.shell.read().unwrap(); + let shell = self.common.shell.read(); shell.outputs().cloned().collect::>().into_iter() } fn active_workspaces( &self, ) -> impl Iterator { - let shell = self.common.shell.read().unwrap(); + let shell = self.common.shell.read(); shell .workspaces .sets diff --git a/src/wayland/handlers/screencopy/mod.rs b/src/wayland/handlers/screencopy/mod.rs index ec6cd6c6..d8a026c3 100644 --- a/src/wayland/handlers/screencopy/mod.rs +++ b/src/wayland/handlers/screencopy/mod.rs @@ -51,7 +51,7 @@ impl ScreencopyHandler for State { .upgrade() .and_then(|output| constraints_for_output(&output, &mut self.backend)), ImageCaptureSourceData::Workspace(handle) => { - let shell = self.common.shell.read().unwrap(); + let shell = self.common.shell.read(); let output = shell.workspaces.space_for_handle(&handle)?.output(); constraints_for_output(output, &mut self.backend) } @@ -69,7 +69,6 @@ impl ScreencopyHandler for State { .common .shell .read() - .unwrap() .seats .last_active() .cursor_geometry((0.0, 0.0), self.common.clock.now()) @@ -103,7 +102,7 @@ impl ScreencopyHandler for State { output.add_session(session); } ImageCaptureSourceData::Workspace(handle) => { - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); let Some(workspace) = shell.workspaces.space_for_handle_mut(&handle) else { session.stop(); return; @@ -132,14 +131,7 @@ impl ScreencopyHandler for State { } fn new_cursor_session(&mut self, session: CursorSession) { let (pointer_loc, pointer_size, hotspot) = { - let seat = self - .common - .shell - .read() - .unwrap() - .seats - .last_active() - .clone(); + let seat = self.common.shell.read().seats.last_active().clone(); let pointer = seat.get_pointer().unwrap(); let pointer_loc = pointer.current_location().to_i32_round().as_global(); @@ -194,7 +186,7 @@ impl ScreencopyHandler for State { output.add_cursor_session(session); } ImageCaptureSourceData::Workspace(handle) => { - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); let Some(workspace) = shell.workspaces.space_for_handle_mut(&handle) else { return; }; @@ -225,7 +217,7 @@ impl ScreencopyHandler for State { workspace.add_cursor_session(session); } ImageCaptureSourceData::Toplevel(mut toplevel) => { - let shell = self.common.shell.read().unwrap(); + let shell = self.common.shell.read(); if let Some(element) = shell.element_for_surface(&toplevel) { if element.has_active_window(&toplevel) { if let Some(workspace) = shell.space_for(element) { @@ -277,19 +269,12 @@ impl ScreencopyHandler for State { return; } - let seat = self - .common - .shell - .read() - .unwrap() - .seats - .last_active() - .clone(); + let seat = self.common.shell.read().seats.last_active().clone(); render_cursor_to_buffer(self, &session, frame, &seat); } fn frame_aborted(&mut self, frame: FrameRef) { - let shell = self.common.shell.read().unwrap(); + let shell = self.common.shell.read(); for mut output in shell.outputs().cloned() { output.remove_frame(&frame); } @@ -307,7 +292,6 @@ impl ScreencopyHandler for State { .common .shell .write() - .unwrap() .workspaces .space_for_handle_mut(&handle) { @@ -331,7 +315,6 @@ impl ScreencopyHandler for State { .common .shell .write() - .unwrap() .workspaces .space_for_handle_mut(&handle) { diff --git a/src/wayland/handlers/screencopy/render.rs b/src/wayland/handlers/screencopy/render.rs index d644a54a..a6bc403a 100644 --- a/src/wayland/handlers/screencopy/render.rs +++ b/src/wayland/handlers/screencopy/render.rs @@ -209,7 +209,7 @@ pub fn render_workspace_to_buffer( frame: Frame, handle: WorkspaceHandle, ) { - let shell = state.common.shell.read().unwrap(); + let shell = state.common.shell.read(); let Some(workspace) = shell.workspaces.space_for_handle(&handle) else { return; }; @@ -509,7 +509,7 @@ pub fn render_window_to_buffer( .map(Into::>::into), ); - let shell = common.shell.read().unwrap(); + let shell = common.shell.read(); let seat = shell.seats.last_active().clone(); let location = if let Some(mapped) = shell.element_for_surface(window) { mapped.cursor_position(&seat).and_then(|mut p| { diff --git a/src/wayland/handlers/session_lock.rs b/src/wayland/handlers/session_lock.rs index 10d6f93f..2c0e2d40 100644 --- a/src/wayland/handlers/session_lock.rs +++ b/src/wayland/handlers/session_lock.rs @@ -18,7 +18,7 @@ impl SessionLockHandler for State { } fn lock(&mut self, locker: SessionLocker) { - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); // Reject lock if sesion lock exists and is still valid if let Some(session_lock) = shell.session_lock.as_ref() { @@ -45,7 +45,7 @@ impl SessionLockHandler for State { } fn unlock(&mut self) { - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); shell.session_lock = None; for output in shell.outputs() { @@ -54,7 +54,7 @@ impl SessionLockHandler for State { } fn new_surface(&mut self, lock_surface: LockSurface, wl_output: WlOutput) { - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); if let Some(session_lock) = &mut shell.session_lock { if let Some(output) = Output::from_resource(&wl_output) { lock_surface.with_pending_state(|states| { diff --git a/src/wayland/handlers/toplevel_management.rs b/src/wayland/handlers/toplevel_management.rs index fb1656e6..b411913b 100644 --- a/src/wayland/handlers/toplevel_management.rs +++ b/src/wayland/handlers/toplevel_management.rs @@ -34,7 +34,7 @@ impl ToplevelManagementHandler for State { ) { self.unminimize(dh, window); - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); for output in shell.outputs().cloned().collect::>().iter() { let maybe = shell .workspaces @@ -120,7 +120,7 @@ impl ToplevelManagementHandler for State { to_handle: WorkspaceHandle, _output: Output, ) { - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); if let Some(mut mapped) = shell.element_for_surface(window).cloned() { if let Some(from_workspace) = shell.space_for_mut(&mapped) { // If window is part of a stack, remove it and map it outside the stack @@ -168,7 +168,7 @@ impl ToplevelManagementHandler for State { window: &::Window, output: Option, ) { - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); let seat = shell.seats.last_active().clone(); if let Some(mapped) = shell.element_for_surface(window).cloned() { if let Some((output, workspace)) = @@ -195,7 +195,7 @@ impl ToplevelManagementHandler for State { _dh: &DisplayHandle, window: &::Window, ) { - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); if let Some(mapped) = shell.element_for_surface(window).cloned() { if let Some(workspace) = shell.space_for_mut(&mapped) { if let Some((layer, previous_workspace)) = workspace.unfullscreen_request(window) { @@ -219,7 +219,7 @@ impl ToplevelManagementHandler for State { } fn maximize(&mut self, _dh: &DisplayHandle, window: &::Window) { - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); if let Some(mapped) = shell.element_for_surface(window).cloned() { let seat = shell.seats.last_active().clone(); shell.maximize_request(&mapped, &seat, true); @@ -227,14 +227,14 @@ impl ToplevelManagementHandler for State { } fn unmaximize(&mut self, _dh: &DisplayHandle, window: &::Window) { - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); if let Some(mapped) = shell.element_for_surface(window).cloned() { shell.unmaximize_request(&mapped); } } fn minimize(&mut self, _dh: &DisplayHandle, window: &::Window) { - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); if let Some(mapped) = shell.element_for_surface(window).cloned() { if !mapped.is_stack() || &mapped.active_window() == window { shell.minimize_request(&mapped); @@ -243,7 +243,7 @@ impl ToplevelManagementHandler for State { } fn unminimize(&mut self, _dh: &DisplayHandle, window: &::Window) { - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); if let Some(mapped) = shell.element_for_surface(window).cloned() { let seat = shell.seats.last_active().clone(); shell.unminimize_request(&mapped, &seat); @@ -258,7 +258,7 @@ impl ToplevelManagementHandler for State { return; } - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); if let Some(mapped) = shell.element_for_surface(window).cloned() { let seat = shell.seats.last_active().clone(); shell.toggle_sticky(&seat, &mapped); @@ -274,7 +274,7 @@ impl ToplevelManagementHandler for State { return; } - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); if let Some(mapped) = shell.element_for_surface(window).cloned() { let seat = shell.seats.last_active().clone(); shell.toggle_sticky(&seat, &mapped); diff --git a/src/wayland/handlers/workspace.rs b/src/wayland/handlers/workspace.rs index b78343dd..ab1ff9de 100644 --- a/src/wayland/handlers/workspace.rs +++ b/src/wayland/handlers/workspace.rs @@ -22,7 +22,7 @@ impl WorkspaceHandler for State { for request in requests.into_iter() { match request { Request::Activate(handle) => { - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); let maybe = shell.workspaces.iter().find_map(|(o, set)| { set.workspaces .iter() @@ -41,7 +41,7 @@ impl WorkspaceHandler for State { } } Request::SetTilingState { workspace, state } => { - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); let seat = shell.seats.last_active().clone(); if let Some(workspace) = shell.workspaces.space_for_handle_mut(&workspace) { let mut guard = self.common.workspace_state.update(); @@ -56,7 +56,7 @@ impl WorkspaceHandler for State { } } Request::SetPin { workspace, pinned } => { - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); if let Some(workspace) = shell.workspaces.space_for_handle_mut(&workspace) { workspace.pinned = pinned; let mut update = self.common.workspace_state.update(); @@ -78,7 +78,7 @@ impl WorkspaceHandler for State { if axis != 0 { continue; } - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); let mut update = self.common.workspace_state.update(); shell.workspaces.move_workspace( &workspace, @@ -95,7 +95,7 @@ impl WorkspaceHandler for State { if axis != 0 { continue; } - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); let mut update = self.common.workspace_state.update(); shell.workspaces.move_workspace( &workspace, diff --git a/src/wayland/handlers/xdg_activation.rs b/src/wayland/handlers/xdg_activation.rs index 62509952..77d8dc42 100644 --- a/src/wayland/handlers/xdg_activation.rs +++ b/src/wayland/handlers/xdg_activation.rs @@ -43,7 +43,7 @@ impl XdgActivationHandler for State { { if let Some(seat) = data.serial.and_then(|(_, seat)| Seat::from_resource(&seat)) { let output = seat.active_output(); - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); let workspace = shell.active_space_mut(&output).unwrap(); let handle = workspace.handle; data.user_data @@ -86,7 +86,7 @@ impl XdgActivationHandler for State { if valid { let output = seat.active_output(); - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); let workspace = shell.active_space_mut(&output).unwrap(); let handle = workspace.handle; data.user_data @@ -107,7 +107,7 @@ impl XdgActivationHandler for State { surface: WlSurface, ) { if let Some(context) = token_data.user_data.get::() { - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); if let Some(element) = shell.element_for_surface(&surface).cloned() { match context { ActivationContext::UrgentOnly => { diff --git a/src/wayland/handlers/xdg_shell/mod.rs b/src/wayland/handlers/xdg_shell/mod.rs index 056e48fd..1df2adaa 100644 --- a/src/wayland/handlers/xdg_shell/mod.rs +++ b/src/wayland/handlers/xdg_shell/mod.rs @@ -45,7 +45,7 @@ impl XdgShellHandler for State { } fn new_toplevel(&mut self, surface: ToplevelSurface) { - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); let seat = shell.seats.last_active().clone(); let window = CosmicSurface::from(surface); shell.pending_windows.push(PendingWindow { @@ -65,11 +65,7 @@ impl XdgShellHandler for State { if surface.get_parent_surface().is_some() { // let other shells deal with their popups - self.common - .shell - .read() - .unwrap() - .unconstrain_popup(&surface); + self.common.shell.read().unconstrain_popup(&surface); if surface.send_configure().is_ok() { self.common @@ -83,14 +79,9 @@ impl XdgShellHandler for State { fn grab(&mut self, surface: PopupSurface, seat: WlSeat, serial: Serial) { let seat = Seat::from_resource(&seat).unwrap(); let kind = PopupKind::Xdg(surface); - let maybe_root = find_popup_root_surface(&kind).ok().and_then(|root| { - self.common - .shell - .read() - .unwrap() - .element_for_surface(&root) - .cloned() - }); + let maybe_root = find_popup_root_surface(&kind) + .ok() + .and_then(|root| self.common.shell.read().element_for_surface(&root).cloned()); if let Some(root) = maybe_root { let target = root.into(); @@ -149,11 +140,7 @@ impl XdgShellHandler for State { state.positioner = positioner; }); - self.common - .shell - .read() - .unwrap() - .unconstrain_popup(&surface); + self.common.shell.read().unconstrain_popup(&surface); surface.send_repositioned(token); if let Err(err) = surface.send_configure() { warn!( @@ -165,7 +152,7 @@ impl XdgShellHandler for State { fn move_request(&mut self, surface: ToplevelSurface, seat: WlSeat, serial: Serial) { let seat = Seat::from_resource(&seat).unwrap(); - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); if let Some((grab, focus)) = shell.move_request( surface.wl_surface(), &seat, @@ -195,7 +182,7 @@ impl XdgShellHandler for State { edges: xdg_toplevel::ResizeEdge, ) { let seat = Seat::from_resource(&seat).unwrap(); - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); if let Some((grab, focus)) = shell.resize_request( surface.wl_surface(), &seat, @@ -216,7 +203,7 @@ impl XdgShellHandler for State { } fn minimize_request(&mut self, surface: ToplevelSurface) { - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); if let Some(mapped) = shell.element_for_surface(surface.wl_surface()).cloned() { if !mapped.is_stack() || mapped.active_window().wl_surface().as_deref() == Some(surface.wl_surface()) @@ -227,7 +214,7 @@ impl XdgShellHandler for State { } fn maximize_request(&mut self, surface: ToplevelSurface) { - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); if let Some(mapped) = shell.element_for_surface(surface.wl_surface()).cloned() { let seat = shell.seats.last_active().clone(); shell.maximize_request(&mapped, &seat, true) @@ -241,7 +228,7 @@ impl XdgShellHandler for State { } fn unmaximize_request(&mut self, surface: ToplevelSurface) { - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); if let Some(mapped) = shell.element_for_surface(surface.wl_surface()).cloned() { shell.unmaximize_request(&mapped); } else if let Some(pending) = shell @@ -254,7 +241,7 @@ impl XdgShellHandler for State { } fn fullscreen_request(&mut self, surface: ToplevelSurface, output: Option) { - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); let seat = shell.seats.last_active().clone(); let Some(focused_output) = seat.focused_output() else { return; @@ -373,7 +360,7 @@ impl XdgShellHandler for State { } fn unfullscreen_request(&mut self, surface: ToplevelSurface) { - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); if let Some(mapped) = shell.element_for_surface(surface.wl_surface()).cloned() { if let Some(workspace) = shell.space_for_mut(&mapped) { let (window, _) = mapped @@ -408,7 +395,7 @@ impl XdgShellHandler for State { fn toplevel_destroyed(&mut self, surface: ToplevelSurface) { let (output, clients) = { - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); let seat = shell.seats.last_active().clone(); shell.unmap_surface( surface.wl_surface(), @@ -457,7 +444,7 @@ impl XdgShellHandler for State { .unwrap_or_default() .loc; - let shell = self.common.shell.read().unwrap(); + let shell = self.common.shell.read(); let res = shell.menu_request( surface.wl_surface(), &seat, diff --git a/src/wayland/handlers/xwayland_keyboard_grab.rs b/src/wayland/handlers/xwayland_keyboard_grab.rs index 85e25b55..77275b48 100644 --- a/src/wayland/handlers/xwayland_keyboard_grab.rs +++ b/src/wayland/handlers/xwayland_keyboard_grab.rs @@ -12,7 +12,6 @@ impl XWaylandKeyboardGrabHandler for State { .common .shell .read() - .unwrap() .workspaces .spaces() .find_map(|x| x.element_for_surface(surface).cloned())?; diff --git a/src/xwayland.rs b/src/xwayland.rs index cb2e74ec..27662804 100644 --- a/src/xwayland.rs +++ b/src/xwayland.rs @@ -248,7 +248,6 @@ impl Common { let keyboard = self .shell .read() - .unwrap() .seats .last_active() .get_keyboard() @@ -260,14 +259,7 @@ impl Common { } fn has_x_pointer_focus(&self, xwmid: XwmId) -> bool { - let pointer = self - .shell - .read() - .unwrap() - .seats - .last_active() - .get_pointer() - .unwrap(); + let pointer = self.shell.read().seats.last_active().get_pointer().unwrap(); if let Some(x_client) = self.xwayland_state.as_ref().and_then(|xstate| { xstate @@ -307,7 +299,7 @@ impl Common { } pub fn xwayland_reset_eavesdropping(&mut self, serial: Serial) { - let seat = self.shell.read().unwrap().seats.last_active().clone(); + let seat = self.shell.read().seats.last_active().clone(); let keyboard = seat.get_keyboard().unwrap(); let pointer = seat.get_pointer().unwrap(); @@ -350,7 +342,6 @@ impl Common { let keyboard = self .shell .read() - .unwrap() .seats .last_active() .get_keyboard() @@ -420,14 +411,7 @@ impl Common { return; } - let pointer = self - .shell - .read() - .unwrap() - .seats - .last_active() - .get_pointer() - .unwrap(); + let pointer = self.shell.read().seats.last_active().get_pointer().unwrap(); if self.xwayland_state.as_ref().is_none_or(|xstate| { xstate @@ -466,7 +450,7 @@ impl Common { } pub fn update_x11_stacking_order(&mut self) { - let shell = self.shell.read().unwrap(); + let shell = self.shell.read(); let active_output = shell.seats.last_active().active_output(); if let Some(xwm) = self .xwayland_state @@ -560,7 +544,7 @@ impl Common { let new_scale = match self.config.cosmic_conf.descale_xwayland { XwaylandDescaling::Disabled => 1., XwaylandDescaling::Enabled => { - let shell = self.shell.read().unwrap(); + let shell = self.shell.read(); shell .outputs() .map(|o| o.current_scale().integer_scale()) @@ -568,7 +552,7 @@ impl Common { .unwrap_or(1) as f64 } XwaylandDescaling::Fractional => { - let shell = self.shell.read().unwrap(); + let shell = self.shell.read(); let val = if let Some(output) = shell.outputs().find(|o| o.config().xwayland_primary) { output.current_scale().fractional_scale().max(1f64) @@ -589,7 +573,6 @@ impl Common { let geometries = self .shell .read() - .unwrap() .mapped() .flat_map(|m| m.windows().map(|(s, _)| s)) .filter_map(|s| s.0.x11_surface().map(|x| (x.clone(), x.geometry()))) @@ -638,7 +621,7 @@ impl Common { .set_client_scale(new_scale); // update wl/xdg_outputs - for output in self.shell.read().unwrap().outputs() { + for output in self.shell.read().outputs() { output.change_current_state(None, None, None, None); } @@ -695,7 +678,7 @@ impl XwmHandler for State { warn!(?window, ?err, "Failed to send Xwayland Mapped-Event",); } - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); let startup_id = window.startup_id(); if shell.element_for_surface(&window).is_some() { return; @@ -723,7 +706,7 @@ impl XwmHandler for State { } fn map_window_notify(&mut self, _xwm: XwmId, surface: X11Surface) { - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); if let Some(window) = shell .pending_windows .iter() @@ -763,7 +746,7 @@ impl XwmHandler for State { } fn mapped_override_redirect_window(&mut self, _xwm: XwmId, window: X11Surface) { - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); if shell .override_redirect_windows .iter() @@ -775,7 +758,7 @@ impl XwmHandler for State { } fn unmapped_window(&mut self, _xwm: XwmId, window: X11Surface) { - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); if window.is_override_redirect() { shell.override_redirect_windows.retain(|or| or != &window); } else { @@ -812,7 +795,7 @@ impl XwmHandler for State { _reorder: Option, ) { // We only allow floating X11 windows to resize themselves. Nothing else - let shell = self.common.shell.read().unwrap(); + let shell = self.common.shell.read(); if let Some(mapped) = shell .element_for_surface(&window) @@ -880,7 +863,7 @@ impl XwmHandler for State { above: Option, ) { if window.is_override_redirect() { - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); if let Some(id) = above { let or_windows = &mut shell.override_redirect_windows; if let Some(own_pos) = or_windows.iter().position(|or| or == &window) { @@ -917,7 +900,7 @@ impl XwmHandler for State { resize_edge: smithay::xwayland::xwm::ResizeEdge, ) { if let Some(wl_surface) = window.wl_surface() { - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); let seat = shell.seats.last_active().clone(); if let Some((grab, focus)) = shell.resize_request( &wl_surface, @@ -946,7 +929,7 @@ impl XwmHandler for State { fn move_request(&mut self, _xwm: XwmId, window: X11Surface, _button: u32) { if let Some(wl_surface) = window.wl_surface() { - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); let seat = shell.seats.last_active().clone(); if let Some((grab, focus)) = shell.move_request( &wl_surface, @@ -976,7 +959,7 @@ impl XwmHandler for State { } fn maximize_request(&mut self, _xwm: XwmId, window: X11Surface) { - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); if let Some(mapped) = shell.element_for_surface(&window).cloned() { let seat = shell.seats.last_active().clone(); shell.maximize_request(&mapped, &seat, true); @@ -990,7 +973,7 @@ impl XwmHandler for State { } fn unmaximize_request(&mut self, _xwm: XwmId, window: X11Surface) { - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); if let Some(mapped) = shell.element_for_surface(&window).cloned() { shell.unmaximize_request(&mapped); } else if let Some(pending) = shell @@ -1003,7 +986,7 @@ impl XwmHandler for State { } fn minimize_request(&mut self, _xwm: XwmId, window: X11Surface) { - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); if let Some(mapped) = shell.element_for_surface(&window).cloned() { if !mapped.is_stack() || mapped.active_window().is_window(&window) { shell.minimize_request(&mapped); @@ -1012,7 +995,7 @@ impl XwmHandler for State { } fn unminimize_request(&mut self, _xwm: XwmId, window: X11Surface) { - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); if let Some(mapped) = shell.element_for_surface(&window).cloned() { let seat = shell.seats.last_active().clone(); shell.unminimize_request(&mapped, &seat); @@ -1026,7 +1009,7 @@ impl XwmHandler for State { } fn fullscreen_request(&mut self, _xwm: XwmId, window: X11Surface) { - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); let seat = shell.seats.last_active().clone(); if let Some(mapped) = shell.element_for_surface(&window).cloned() { if let Some((output, handle)) = shell @@ -1056,7 +1039,7 @@ impl XwmHandler for State { } fn unfullscreen_request(&mut self, _xwm: XwmId, window: X11Surface) { - let mut shell = self.common.shell.write().unwrap(); + let mut shell = self.common.shell.write(); if let Some(mapped) = shell.element_for_surface(&window).cloned() { if let Some(workspace) = shell.space_for_mut(&mapped) { let (window, _) = mapped @@ -1082,14 +1065,7 @@ impl XwmHandler for State { mime_type: String, fd: OwnedFd, ) { - let seat = self - .common - .shell - .read() - .unwrap() - .seats - .last_active() - .clone(); + let seat = self.common.shell.read().seats.last_active().clone(); match selection { SelectionTarget::Clipboard => { if let Err(err) = request_data_device_client_selection(&seat, mime_type, fd) { @@ -1117,14 +1093,7 @@ impl XwmHandler for State { fn new_selection(&mut self, xwm: XwmId, selection: SelectionTarget, mime_types: Vec) { trace!(?selection, ?mime_types, "Got Selection from Xwayland",); - let seat = self - .common - .shell - .read() - .unwrap() - .seats - .last_active() - .clone(); + let seat = self.common.shell.read().seats.last_active().clone(); match selection { SelectionTarget::Clipboard => { set_data_device_selection(&self.common.display_handle, &seat, mime_types, xwm) @@ -1136,7 +1105,7 @@ impl XwmHandler for State { } fn cleared_selection(&mut self, xwm: XwmId, selection: SelectionTarget) { - let shell = self.common.shell.read().unwrap(); + let shell = self.common.shell.read(); for seat in shell.seats.iter() { match selection { SelectionTarget::Clipboard => {