shell: Using parking_lot's RwLock for fairness guarantees

This commit is contained in:
Victoria Brekenfeld 2025-05-20 17:41:27 +02:00 committed by Victoria Brekenfeld
parent 8194be30c6
commit 465813c1c5
42 changed files with 247 additions and 396 deletions

1
Cargo.lock generated
View file

@ -843,6 +843,7 @@ dependencies = [
"log-panics", "log-panics",
"once_cell", "once_cell",
"ordered-float", "ordered-float",
"parking_lot 0.12.3",
"png", "png",
"profiling", "profiling",
"rand 0.9.1", "rand 0.9.1",

View file

@ -65,6 +65,7 @@ rand = "0.9.0"
reis = { version = "0.5", features = ["calloop"] } reis = { version = "0.5", features = ["calloop"] }
# CLI arguments # CLI arguments
clap_lex = "0.7" clap_lex = "0.7"
parking_lot = "0.12.3"
[dependencies.id_tree] [dependencies.id_tree]
branch = "feature/copy_clone" branch = "feature/copy_clone"

View file

@ -307,7 +307,7 @@ impl State {
let connectors = device.enumerate_surfaces()?.added; // There are no removed outputs on newly added devices let connectors = device.enumerate_surfaces()?.added; // There are no removed outputs on newly added devices
let mut wl_outputs = Vec::new(); 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 { for (conn, maybe_crtc) in connectors {
@ -380,7 +380,7 @@ impl State {
if let Some(device) = backend.drm_devices.get_mut(&drm_node) { if let Some(device) = backend.drm_devices.get_mut(&drm_node) {
let changes = device.enumerate_surfaces()?; 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 { for conn in changes.removed {
// contains conns with updated crtcs, just drop the surface and re-create // contains conns with updated crtcs, just drop the surface and re-create
if let Some(pos) = device if let Some(pos) = device
@ -577,7 +577,7 @@ impl Device {
position: (u32, u32), position: (u32, u32),
evlh: &LoopHandle<'static, State>, evlh: &LoopHandle<'static, State>,
screen_filter: ScreenFilter, screen_filter: ScreenFilter,
shell: Arc<RwLock<Shell>>, shell: Arc<parking_lot::RwLock<Shell>>,
startup_done: Arc<AtomicBool>, startup_done: Arc<AtomicBool>,
) -> Result<(Output, bool)> { ) -> Result<(Output, bool)> {
let output = self let output = self
@ -676,7 +676,7 @@ impl Device {
flags: FrameFlags, flags: FrameFlags,
renderer: &mut GlMultiRenderer, renderer: &mut GlMultiRenderer,
clock: &Clock<Monotonic>, clock: &Clock<Monotonic>,
shell: &Arc<RwLock<Shell>>, shell: &Arc<parking_lot::RwLock<Shell>>,
) -> Result<()> { ) -> Result<()> {
for surface in self.surfaces.values_mut() { for surface in self.surfaces.values_mut() {
surface.allow_frame_flags(flag, flags); surface.allow_frame_flags(flag, flags);
@ -733,7 +733,7 @@ impl Device {
flag: bool, flag: bool,
renderer: &mut GlMultiRenderer, renderer: &mut GlMultiRenderer,
clock: &Clock<Monotonic>, clock: &Clock<Monotonic>,
shell: &Arc<RwLock<Shell>>, shell: &Arc<parking_lot::RwLock<Shell>>,
) -> Result<()> { ) -> Result<()> {
self.allow_frame_flags( self.allow_frame_flags(
flag, flag,
@ -749,7 +749,7 @@ impl Device {
flag: bool, flag: bool,
renderer: &mut GlMultiRenderer, renderer: &mut GlMultiRenderer,
clock: &Clock<Monotonic>, clock: &Clock<Monotonic>,
shell: &Arc<RwLock<Shell>>, shell: &Arc<parking_lot::RwLock<Shell>>,
) -> Result<()> { ) -> Result<()> {
self.allow_frame_flags( self.allow_frame_flags(
flag, flag,

View file

@ -169,7 +169,7 @@ fn init_libinput(
state.process_input_event(event); 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); state.backend.kms().schedule_render(output);
} }
}) })
@ -592,7 +592,7 @@ impl KmsState {
test_only: bool, test_only: bool,
loop_handle: &LoopHandle<'static, State>, loop_handle: &LoopHandle<'static, State>,
screen_filter: &ScreenFilter, screen_filter: &ScreenFilter,
shell: Arc<RwLock<Shell>>, shell: Arc<parking_lot::RwLock<Shell>>,
startup_done: Arc<AtomicBool>, startup_done: Arc<AtomicBool>,
clock: &Clock<Monotonic>, clock: &Clock<Monotonic>,
) -> Result<Vec<Output>, anyhow::Error> { ) -> Result<Vec<Output>, anyhow::Error> {
@ -683,7 +683,7 @@ impl KmsState {
} }
// add new ones // 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 { if !test_only {
for (conn, crtc) in new_pairings { for (conn, crtc) in new_pairings {
let (output, _) = device.connector_added( let (output, _) = device.connector_added(

View file

@ -136,7 +136,7 @@ pub struct SurfaceThreadState {
screen_filter: ScreenFilter, screen_filter: ScreenFilter,
postprocess_textures: HashMap<DrmNode, PostprocessState>, postprocess_textures: HashMap<DrmNode, PostprocessState>,
shell: Arc<RwLock<Shell>>, shell: Arc<parking_lot::RwLock<Shell>>,
loop_handle: LoopHandle<'static, Self>, loop_handle: LoopHandle<'static, Self>,
clock: Clock<Monotonic>, clock: Clock<Monotonic>,
@ -233,7 +233,7 @@ impl Surface {
target_node: DrmNode, target_node: DrmNode,
evlh: &LoopHandle<'static, State>, evlh: &LoopHandle<'static, State>,
screen_filter: ScreenFilter, screen_filter: ScreenFilter,
shell: Arc<RwLock<Shell>>, shell: Arc<parking_lot::RwLock<Shell>>,
startup_done: Arc<AtomicBool>, startup_done: Arc<AtomicBool>,
) -> Result<Self> { ) -> Result<Self> {
let (tx, rx) = channel::<ThreadCommand>(); let (tx, rx) = channel::<ThreadCommand>();
@ -471,7 +471,7 @@ fn surface_thread(
output: Output, output: Output,
primary_node: Arc<RwLock<Option<DrmNode>>>, primary_node: Arc<RwLock<Option<DrmNode>>>,
target_node: DrmNode, target_node: DrmNode,
shell: Arc<RwLock<Shell>>, shell: Arc<parking_lot::RwLock<Shell>>,
active: Arc<AtomicBool>, active: Arc<AtomicBool>,
screen_filter: ScreenFilter, screen_filter: ScreenFilter,
thread_sender: Sender<SurfaceCommand>, thread_sender: Sender<SurfaceCommand>,
@ -839,7 +839,7 @@ impl SurfaceThreadState {
QueueState::WaitingForEstimatedVBlankAndQueued { .. } => unreachable!(), 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() let vblank_frame = tracy_client::Client::running()
.unwrap() .unwrap()
.non_continuous_frame(self.vblank_frame_name); .non_continuous_frame(self.vblank_frame_name);
@ -866,7 +866,7 @@ impl SurfaceThreadState {
self.frame_callback_seq = self.frame_callback_seq.wrapping_add(1); 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); self.queue_redraw(false);
} else { } else {
self.send_frame_callbacks(); self.send_frame_callbacks();
@ -962,7 +962,7 @@ impl SurfaceThreadState {
.as_ref() .as_ref()
.unwrap_or(&self.target_node), .unwrap_or(&self.target_node),
&self.target_node, &self.target_node,
&*self.shell.read().unwrap(), &*self.shell.read(),
); );
let mut renderer = if render_node != self.target_node { let mut renderer = if render_node != self.target_node {
@ -979,7 +979,7 @@ impl SurfaceThreadState {
let mut remove_frame_flags = FrameFlags::empty(); let mut remove_frame_flags = FrameFlags::empty();
let has_active_fullscreen = { 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); let output = self.mirroring.as_ref().unwrap_or(&self.output);
if let Some((_, workspace)) = shell.workspaces.active(output) { if let Some((_, workspace)) = shell.workspaces.active(output) {
workspace.get_fullscreen().is_some() workspace.get_fullscreen().is_some()
@ -1416,7 +1416,6 @@ impl SurfaceThreadState {
Some(( Some((
self.shell self.shell
.read() .read()
.unwrap()
.take_presentation_feedback(&self.output, &frame_result.states), .take_presentation_feedback(&self.output, &frame_result.states),
rx, rx,
estimated_presentation, estimated_presentation,

View file

@ -47,7 +47,6 @@ pub fn init_backend_auto(
.common .common
.shell .shell
.read() .read()
.unwrap()
.outputs() .outputs()
.next() .next()
.with_context(|| "Backend initialized without output") .with_context(|| "Backend initialized without output")
@ -68,7 +67,6 @@ pub fn init_backend_auto(
.common .common
.shell .shell
.write() .write()
.unwrap()
.seats .seats
.add_seat(initial_seat.clone()); .add_seat(initial_seat.clone());
@ -79,7 +77,7 @@ pub fn init_backend_auto(
.accessibility_zoom .accessibility_zoom
.start_on_login .start_on_login
{ {
state.common.shell.write().unwrap().trigger_zoom( state.common.shell.write().trigger_zoom(
&initial_seat, &initial_seat,
None, None,
1.0 + (state.common.config.cosmic_conf.accessibility_zoom.increment as f64 / 100.), 1.0 + (state.common.config.cosmic_conf.accessibility_zoom.increment as f64 / 100.),
@ -117,7 +115,7 @@ pub fn init_backend_auto(
.common .common
.startup_done .startup_done
.store(true, std::sync::atomic::Ordering::SeqCst); .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); state.backend.schedule_render(&output);
} }
} }

View file

@ -5,7 +5,7 @@ use std::{
cell::RefCell, cell::RefCell,
collections::HashMap, collections::HashMap,
ops::ControlFlow, ops::ControlFlow,
sync::{Arc, RwLock, Weak}, sync::{Arc, Weak},
time::Instant, time::Instant,
}; };
@ -559,7 +559,7 @@ pub enum ElementFilter {
pub fn output_elements<R>( pub fn output_elements<R>(
_gpu: Option<&DrmNode>, _gpu: Option<&DrmNode>,
renderer: &mut R, renderer: &mut R,
shell: &Arc<RwLock<Shell>>, shell: &Arc<parking_lot::RwLock<Shell>>,
now: Time<Monotonic>, now: Time<Monotonic>,
output: &Output, output: &Output,
cursor_mode: CursorMode, cursor_mode: CursorMode,
@ -575,7 +575,7 @@ where
#[cfg(feature = "debug")] #[cfg(feature = "debug")]
let mut debug_elements = { let mut debug_elements = {
let output_geo = output.geometry(); let output_geo = output.geometry();
let shell_guard = shell.read().unwrap(); let shell_guard = shell.read();
let seats = shell_guard.seats.iter().cloned().collect::<Vec<_>>(); let seats = shell_guard.seats.iter().cloned().collect::<Vec<_>>();
let debug_active = shell_guard.debug_active; let debug_active = shell_guard.debug_active;
std::mem::drop(shell_guard); 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 { let Some((previous_workspace, workspace)) = shell_guard.workspaces.active(output) else {
#[cfg(not(feature = "debug"))] #[cfg(not(feature = "debug"))]
return Ok(Vec::new()); return Ok(Vec::new());
@ -623,7 +623,7 @@ where
} else { } else {
ElementFilter::All ElementFilter::All
}; };
let zoom_state = shell.read().unwrap().zoom_state().cloned(); let zoom_state = shell.read().zoom_state().cloned();
#[allow(unused_mut)] #[allow(unused_mut)]
let workspace_elements = workspace_elements( let workspace_elements = workspace_elements(
@ -652,7 +652,7 @@ where
pub fn workspace_elements<R>( pub fn workspace_elements<R>(
_gpu: Option<&DrmNode>, _gpu: Option<&DrmNode>,
renderer: &mut R, renderer: &mut R,
shell: &Arc<RwLock<Shell>>, shell: &Arc<parking_lot::RwLock<Shell>>,
zoom_level: Option<&ZoomState>, zoom_level: Option<&ZoomState>,
now: Time<Monotonic>, now: Time<Monotonic>,
output: &Output, output: &Output,
@ -670,7 +670,7 @@ where
{ {
let mut elements = Vec::new(); let mut elements = Vec::new();
let shell_ref = shell.read().unwrap(); let shell_ref = shell.read();
let seats = shell_ref.seats.iter().cloned().collect::<Vec<_>>(); let seats = shell_ref.seats.iter().cloned().collect::<Vec<_>>();
if seats.is_empty() { if seats.is_empty() {
return Ok(Vec::new()); return Ok(Vec::new());
@ -692,7 +692,7 @@ where
element_filter == ElementFilter::ExcludeWorkspaceOverview, element_filter == ElementFilter::ExcludeWorkspaceOverview,
)); ));
let shell = shell.read().unwrap(); let shell = shell.read();
let overview = shell.overview_mode(); let overview = shell.overview_mode();
let (resize_mode, resize_indicator) = shell.resize_mode(); let (resize_mode, resize_indicator) = shell.resize_mode();
let resize_indicator = resize_indicator.map(|indicator| (resize_mode, indicator)); let resize_indicator = resize_indicator.map(|indicator| (resize_mode, indicator));
@ -1136,7 +1136,7 @@ pub fn render_output<'d, R>(
target: &mut R::Framebuffer<'_>, target: &mut R::Framebuffer<'_>,
damage_tracker: &'d mut OutputDamageTracker, damage_tracker: &'d mut OutputDamageTracker,
age: usize, age: usize,
shell: &Arc<RwLock<Shell>>, shell: &Arc<parking_lot::RwLock<Shell>>,
now: Time<Monotonic>, now: Time<Monotonic>,
output: &Output, output: &Output,
cursor_mode: CursorMode, cursor_mode: CursorMode,
@ -1157,7 +1157,7 @@ where
CosmicMappedRenderElement<R>: RenderElement<R>, CosmicMappedRenderElement<R>: RenderElement<R>,
WorkspaceRenderElement<R>: RenderElement<R>, WorkspaceRenderElement<R>: RenderElement<R>,
{ {
let shell_ref = shell.read().unwrap(); let shell_ref = shell.read();
let (previous_workspace, workspace) = shell_ref let (previous_workspace, workspace) = shell_ref
.workspaces .workspaces
.active(output) .active(output)
@ -1439,7 +1439,7 @@ pub fn render_workspace<'d, R>(
damage_tracker: &'d mut OutputDamageTracker, damage_tracker: &'d mut OutputDamageTracker,
age: usize, age: usize,
additional_damage: Option<Vec<Rectangle<i32, Logical>>>, additional_damage: Option<Vec<Rectangle<i32, Logical>>>,
shell: &Arc<RwLock<Shell>>, shell: &Arc<parking_lot::RwLock<Shell>>,
zoom_level: Option<&ZoomState>, zoom_level: Option<&ZoomState>,
now: Time<Monotonic>, now: Time<Monotonic>,
output: &Output, output: &Output,

View file

@ -76,7 +76,6 @@ impl WinitState {
let mut output_presentation_feedback = state let mut output_presentation_feedback = state
.shell .shell
.read() .read()
.unwrap()
.take_presentation_feedback(&self.output, &states); .take_presentation_feedback(&self.output, &states);
output_presentation_feedback.presented( output_presentation_feedback.presented(
state.clock.now(), state.clock.now(),
@ -297,7 +296,7 @@ impl State {
// here we can handle special cases for winit inputs // here we can handle special cases for winit inputs
match event { match event {
WinitEvent::Focus(true) => { 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::<Devices>().unwrap(); let devices = seat.user_data().get::<Devices>().unwrap();
if devices.has_device(&WinitVirtualDevice) { if devices.has_device(&WinitVirtualDevice) {
seat.set_active_output(&self.backend.winit().output); seat.set_active_output(&self.backend.winit().output);

View file

@ -240,7 +240,6 @@ impl Surface {
let mut output_presentation_feedback = state let mut output_presentation_feedback = state
.shell .shell
.read() .read()
.unwrap()
.take_presentation_feedback(&self.output, &states); .take_presentation_feedback(&self.output, &states);
output_presentation_feedback.presented( output_presentation_feedback.presented(
state.clock.now(), state.clock.now(),
@ -520,7 +519,7 @@ impl State {
.unwrap(); .unwrap();
let device = event.device(); 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::<Devices>().unwrap(); let devices = seat.user_data().get::<Devices>().unwrap();
if devices.has_device(&device) { if devices.has_device(&device) {
seat.set_active_output(&output); seat.set_active_output(&output);
@ -534,7 +533,7 @@ impl State {
self.process_input_event(event); self.process_input_event(event);
// TODO actually figure out the output // 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); self.backend.x11().schedule_render(output);
} }
} }

View file

@ -33,7 +33,7 @@ use std::{
fs::OpenOptions, fs::OpenOptions,
io::Write, io::Write,
path::PathBuf, path::PathBuf,
sync::{atomic::AtomicBool, Arc, RwLock}, sync::{atomic::AtomicBool, Arc},
}; };
use tracing::{error, warn}; use tracing::{error, warn};
@ -227,7 +227,7 @@ impl Config {
if let Ok(tk_config) = cosmic_config::Config::new("com.system76.CosmicTk", 1) { if let Ok(tk_config) = cosmic_config::Config::new("com.system76.CosmicTk", 1) {
fn handle_new_toolkit_config(config: CosmicTk, state: &mut State) { fn handle_new_toolkit_config(config: CosmicTk, state: &mut State) {
let mut workspace_guard = state.common.workspace_state.update(); let mut workspace_guard = state.common.workspace_state.update();
state.common.shell.write().unwrap().update_toolkit( state.common.shell.write().update_toolkit(
config, config,
&state.common.xdg_activation_state, &state.common.xdg_activation_state,
&mut workspace_guard, &mut workspace_guard,
@ -308,14 +308,9 @@ impl Config {
"tiling_exception_defaults" | "tiling_exception_custom" => { "tiling_exception_defaults" | "tiling_exception_custom" => {
let new_exceptions = window_rules::tiling_exceptions(&config); let new_exceptions = window_rules::tiling_exceptions(&config);
state.common.config.tiling_exceptions = new_exceptions; state.common.config.tiling_exceptions = new_exceptions;
state state.common.shell.write().update_tiling_exceptions(
.common state.common.config.tiling_exceptions.iter(),
.shell );
.write()
.unwrap()
.update_tiling_exceptions(
state.common.config.tiling_exceptions.iter(),
);
} }
_ => (), _ => (),
} }
@ -470,7 +465,7 @@ impl Config {
&mut self, &mut self,
output_state: &mut OutputConfigurationState<State>, output_state: &mut OutputConfigurationState<State>,
backend: &mut BackendData, backend: &mut BackendData,
shell: &Arc<RwLock<Shell>>, shell: &Arc<parking_lot::RwLock<Shell>>,
loop_handle: &LoopHandle<'static, State>, loop_handle: &LoopHandle<'static, State>,
workspace_state: &mut WorkspaceUpdateGuard<'_, State>, workspace_state: &mut WorkspaceUpdateGuard<'_, State>,
xdg_activation_state: &XdgActivationState, xdg_activation_state: &XdgActivationState,
@ -809,7 +804,6 @@ fn config_changed(config: cosmic_config::Config, keys: Vec<String>, state: &mut
.common .common
.shell .shell
.read() .read()
.unwrap()
.seats .seats
.iter() .iter()
.cloned() .cloned()
@ -843,7 +837,7 @@ fn config_changed(config: cosmic_config::Config, keys: Vec<String>, state: &mut
"keyboard_config" => { "keyboard_config" => {
let value = get_config::<KeyboardConfig>(&config, "keyboard_config"); let value = get_config::<KeyboardConfig>(&config, "keyboard_config");
state.common.config.cosmic_conf.keyboard_config = value; 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(); let seat = shell.seats.last_active();
state.common.config.dynamic_conf.numlock_mut().last_state = state.common.config.dynamic_conf.numlock_mut().last_state =
seat.get_keyboard().unwrap().modifier_state().num_lock; seat.get_keyboard().unwrap().modifier_state().num_lock;
@ -873,7 +867,7 @@ fn config_changed(config: cosmic_config::Config, keys: Vec<String>, state: &mut
if new != state.common.config.cosmic_conf.autotile { if new != state.common.config.cosmic_conf.autotile {
state.common.config.cosmic_conf.autotile = new; 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; let shell_ref = &mut *shell;
shell_ref.workspaces.update_autotile( shell_ref.workspaces.update_autotile(
new, new,
@ -887,7 +881,7 @@ fn config_changed(config: cosmic_config::Config, keys: Vec<String>, state: &mut
if new != state.common.config.cosmic_conf.autotile_behavior { if new != state.common.config.cosmic_conf.autotile_behavior {
state.common.config.cosmic_conf.autotile_behavior = new; 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; let shell_ref = &mut *shell;
shell_ref.workspaces.update_autotile_behavior( shell_ref.workspaces.update_autotile_behavior(
new, new,

View file

@ -46,7 +46,7 @@ impl State {
) { ) {
// TODO: Detect if started from login manager or tty, and only allow // TODO: Detect if started from login manager or tty, and only allow
// `Terminate` if it will return to login manager. // `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!( && !matches!(
action, action,
Action::Shortcut(shortcuts::Action::Terminate) Action::Shortcut(shortcuts::Action::Terminate)
@ -65,7 +65,7 @@ impl State {
} }
Action::Private(PrivateAction::Escape) => { 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_overview_mode(None, self.common.event_loop_handle.clone());
shell.set_resize_mode( shell.set_resize_mode(
None, None,
@ -88,13 +88,11 @@ impl State {
self.common self.common
.shell .shell
.write() .write()
.unwrap()
.resize(seat, direction, edge.into()); .resize(seat, direction, edge.into());
} else { } else {
self.common self.common
.shell .shell
.write() .write()
.unwrap()
.finish_resize(direction, edge.into()); .finish_resize(direction, edge.into());
} }
} }
@ -107,7 +105,7 @@ impl State {
match action { match action {
SwipeAction::NextWorkspace => { SwipeAction::NextWorkspace => {
let _ = to_next_workspace( let _ = to_next_workspace(
&mut *self.common.shell.write().unwrap(), &mut *self.common.shell.write(),
&seat, &seat,
true, true,
&mut self.common.workspace_state.update(), &mut self.common.workspace_state.update(),
@ -115,7 +113,7 @@ impl State {
} }
SwipeAction::PrevWorkspace => { SwipeAction::PrevWorkspace => {
let _ = to_previous_workspace( let _ = to_previous_workspace(
&mut *self.common.shell.write().unwrap(), &mut *self.common.shell.write(),
&seat, &seat,
true, true,
&mut self.common.workspace_state.update(), &mut self.common.workspace_state.update(),
@ -143,7 +141,7 @@ impl State {
#[cfg(feature = "debug")] #[cfg(feature = "debug")]
Action::Debug => { Action::Debug => {
let mut shell = self.common.shell.write().unwrap(); let mut shell = self.common.shell.write();
shell.debug_active = !shell.debug_active; shell.debug_active = !shell.debug_active;
for mapped in shell.workspaces.spaces().flat_map(|w| w.mapped()) { for mapped in shell.workspaces.spaces().flat_map(|w| w.mapped()) {
mapped.set_debug(shell.debug_active); mapped.set_debug(shell.debug_active);
@ -157,11 +155,7 @@ impl State {
Action::Close => { Action::Close => {
if let Some(focus_target) = seat.get_keyboard().unwrap().current_focus() { if let Some(focus_target) = seat.get_keyboard().unwrap().current_focus() {
self.common self.common.shell.read().close_focused(&focus_target);
.shell
.read()
.unwrap()
.close_focused(&focus_target);
} }
} }
@ -171,7 +165,7 @@ impl State {
0 => 9, 0 => 9,
x => x - 1, x => x - 1,
}; };
let _ = self.common.shell.write().unwrap().activate( let _ = self.common.shell.write().activate(
&current_output, &current_output,
workspace as usize, workspace as usize,
WorkspaceDelta::new_shortcut(), WorkspaceDelta::new_shortcut(),
@ -181,7 +175,7 @@ impl State {
Action::LastWorkspace => { Action::LastWorkspace => {
let current_output = seat.active_output(); 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(&current_output).saturating_sub(1); let workspace = shell.workspaces.len(&current_output).saturating_sub(1);
let _ = shell.activate( let _ = shell.activate(
&current_output, &current_output,
@ -205,7 +199,7 @@ impl State {
} }
let next = to_next_workspace( let next = to_next_workspace(
&mut *self.common.shell.write().unwrap(), &mut *self.common.shell.write(),
seat, seat,
false, false,
&mut self.common.workspace_state.update(), &mut self.common.workspace_state.update(),
@ -251,7 +245,7 @@ impl State {
} }
let previous = to_previous_workspace( let previous = to_previous_workspace(
&mut *self.common.shell.write().unwrap(), &mut *self.common.shell.write(),
seat, seat,
false, false,
&mut self.common.workspace_state.update(), &mut self.common.workspace_state.update(),
@ -293,7 +287,7 @@ impl State {
Action::MoveToWorkspace(x) | Action::SendToWorkspace(x) => x - 1, Action::MoveToWorkspace(x) | Action::SendToWorkspace(x) => x - 1,
_ => unreachable!(), _ => unreachable!(),
}; };
let res = self.common.shell.write().unwrap().move_current_window( let res = self.common.shell.write().move_current_window(
seat, seat,
&focused_output, &focused_output,
(&focused_output, Some(workspace as usize)), (&focused_output, Some(workspace as usize)),
@ -316,7 +310,7 @@ impl State {
let Some(focused_output) = seat.focused_output() else { let Some(focused_output) = seat.focused_output() else {
return; 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 workspace = shell.workspaces.len(&focused_output).saturating_sub(1);
let res = shell.move_current_window( let res = shell.move_current_window(
seat, seat,
@ -356,7 +350,7 @@ impl State {
}; };
let res = { let res = {
let mut shell = self.common.shell.write().unwrap(); let mut shell = self.common.shell.write();
shell shell
.workspaces .workspaces
.active_num(&focused_output) .active_num(&focused_output)
@ -440,7 +434,7 @@ impl State {
}; };
let res = { let res = {
let mut shell = self.common.shell.write().unwrap(); let mut shell = self.common.shell.write();
shell shell
.workspaces .workspaces
.active_num(&focused_output) .active_num(&focused_output)
@ -508,7 +502,7 @@ impl State {
Action::SwitchOutput(direction) => { Action::SwitchOutput(direction) => {
let current_output = seat.active_output(); 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(&current_output, direction).cloned(); let next_output = shell.next_output(&current_output, direction).cloned();
@ -603,7 +597,7 @@ impl State {
let Some(focused_output) = seat.focused_output() else { let Some(focused_output) = seat.focused_output() else {
return; 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(); let next_output = shell.next_output(&focused_output, direction).cloned();
if let Some(next_output) = next_output { if let Some(next_output) = next_output {
@ -667,7 +661,7 @@ impl State {
Action::MigrateWorkspaceToOutput(direction) => { Action::MigrateWorkspaceToOutput(direction) => {
let active_output = seat.active_output(); let active_output = seat.active_output();
let (active, next_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, shell.active_space(&active_output).unwrap().handle,
@ -692,7 +686,7 @@ impl State {
} }
Action::Focus(focus) => { 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 { match result {
FocusResult::None => { FocusResult::None => {
@ -706,7 +700,7 @@ impl State {
if let Some(direction) = dir { if let Some(direction) = dir {
if let Some(last_mod_serial) = seat.last_modifier_change() { 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 if !shell
.previous_workspace_idx .previous_workspace_idx
.as_ref() .as_ref()
@ -761,12 +755,11 @@ impl State {
.common .common
.shell .shell
.write() .write()
.unwrap()
.move_current_element(direction, seat); .move_current_element(direction, seat);
match res { match res {
MoveResult::MoveFurther(_move_further) => { MoveResult::MoveFurther(_move_further) => {
if let Some(last_mod_serial) = seat.last_modifier_change() { 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 if !shell
.previous_workspace_idx .previous_workspace_idx
.as_ref() .as_ref()
@ -812,7 +805,7 @@ impl State {
} }
_ => { _ => {
let current_output = seat.active_output(); 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(&current_output).unwrap(); let workspace = shell.active_space(&current_output).unwrap();
if let Some(focused_window) = workspace.focus_stack.get(seat).last() { if let Some(focused_window) = workspace.focus_stack.get(seat).last() {
if workspace.is_tiled(focused_window) { if workspace.is_tiled(focused_window) {
@ -830,7 +823,7 @@ impl State {
let Some(focused_output) = seat.focused_output() else { let Some(focused_output) = seat.focused_output() else {
return; 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 workspace = shell.active_space_mut(&focused_output).unwrap();
if workspace.get_fullscreen().is_some() { if workspace.get_fullscreen().is_some() {
@ -843,7 +836,7 @@ impl State {
let grab = SwapWindowGrab::new(seat.clone(), descriptor.clone()); let grab = SwapWindowGrab::new(seat.clone(), descriptor.clone());
drop(shell); drop(shell);
keyboard_handle.set_grab(self, grab, serial); 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( shell.set_overview_mode(
Some(Trigger::KeyboardSwap(pattern, descriptor)), Some(Trigger::KeyboardSwap(pattern, descriptor)),
self.common.event_loop_handle.clone(), self.common.event_loop_handle.clone(),
@ -856,7 +849,7 @@ impl State {
let Some(focused_output) = seat.focused_output() else { let Some(focused_output) = seat.focused_output() else {
return; 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 workspace = shell.active_space_mut(&focused_output).unwrap();
let focus_stack = workspace.focus_stack.get(seat); let focus_stack = workspace.focus_stack.get(seat);
let focused_window = focus_stack.last().cloned(); let focused_window = focus_stack.last().cloned();
@ -869,7 +862,7 @@ impl State {
let Some(focused_output) = seat.focused_output() else { let Some(focused_output) = seat.focused_output() else {
return; 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 workspace = shell.active_space(&focused_output).unwrap();
let focus_stack = workspace.focus_stack.get(seat); let focus_stack = workspace.focus_stack.get(seat);
let focused_window = focus_stack.last().cloned(); 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)), Some((pattern, direction)),
&self.common.config, &self.common.config,
self.common.event_loop_handle.clone(), self.common.event_loop_handle.clone(),
@ -887,14 +880,14 @@ impl State {
// rather than the output that has keyboard focus // rather than the output that has keyboard focus
Action::ToggleOrientation => { Action::ToggleOrientation => {
let output = seat.active_output(); 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 workspace = shell.active_space_mut(&output).unwrap();
workspace.tiling_layer.update_orientation(None, &seat); workspace.tiling_layer.update_orientation(None, &seat);
} }
Action::Orientation(orientation) => { Action::Orientation(orientation) => {
let output = seat.active_output(); 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 workspace = shell.active_space_mut(&output).unwrap();
workspace workspace
.tiling_layer .tiling_layer
@ -902,12 +895,7 @@ impl State {
} }
Action::ToggleStacking => { Action::ToggleStacking => {
let res = self let res = self.common.shell.write().toggle_stacking_focused(seat);
.common
.shell
.write()
.unwrap()
.toggle_stacking_focused(seat);
if let Some(new_focus) = res { if let Some(new_focus) = res {
Shell::set_focus(self, Some(&new_focus), seat, Some(serial), false); Shell::set_focus(self, Some(&new_focus), seat, Some(serial), false);
} }
@ -922,7 +910,7 @@ impl State {
self.common.config.cosmic_conf.autotile = autotile; 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; let shell_ref = &mut *shell;
shell_ref.workspaces.update_autotile( shell_ref.workspaces.update_autotile(
self.common.config.cosmic_conf.autotile, self.common.config.cosmic_conf.autotile,
@ -938,7 +926,7 @@ impl State {
}); });
} else { } else {
let output = seat.active_output(); 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 workspace = shell.workspaces.active_mut(&output).unwrap();
let mut guard = self.common.workspace_state.update(); let mut guard = self.common.workspace_state.update();
workspace.toggle_tiling(seat, &mut guard); workspace.toggle_tiling(seat, &mut guard);
@ -949,17 +937,13 @@ impl State {
let Some(output) = seat.focused_output() else { let Some(output) = seat.focused_output() else {
return; return;
}; };
let mut shell = self.common.shell.write().unwrap(); let mut shell = self.common.shell.write();
let workspace = shell.active_space_mut(&output).unwrap(); let workspace = shell.active_space_mut(&output).unwrap();
workspace.toggle_floating_window_focused(seat); workspace.toggle_floating_window_focused(seat);
} }
Action::ToggleSticky => { Action::ToggleSticky => {
self.common self.common.shell.write().toggle_sticky_current(seat);
.shell
.write()
.unwrap()
.toggle_sticky_current(seat);
} }
// Gets the configured command for a given system action. // Gets the configured command for a given system action.
@ -991,7 +975,7 @@ impl State {
} }
pub fn spawn_command(&mut self, command: String) { 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) = self.common.xdg_activation_state.create_external_token(None);
let (token, data) = (token.clone(), data.clone()); let (token, data) = (token.clone(), data.clone());
@ -1034,7 +1018,7 @@ impl State {
pub fn update_zoom(&mut self, seat: &Seat<State>, change: f64, animate: bool) { pub fn update_zoom(&mut self, seat: &Seat<State>, change: f64, animate: bool) {
let output = seat.active_output(); 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 let (zoom_seat, current_level) = shell
.zoom_state() .zoom_state()
.map(|state| (state.current_seat(), state.current_level(&output))) .map(|state| (state.current_seat(), state.current_level(&output)))

View file

@ -170,7 +170,7 @@ impl State {
use smithay::backend::input::Event; use smithay::backend::input::Event;
match event { match event {
InputEvent::DeviceAdded { device } => { InputEvent::DeviceAdded { device } => {
let shell = self.common.shell.read().unwrap(); let shell = self.common.shell.read();
let seat = shell.seats.last_active(); let seat = shell.seats.last_active();
let led_state = seat.get_keyboard().unwrap().led_state(); let led_state = seat.get_keyboard().unwrap().led_state();
seat.devices().add_device(&device, led_state); seat.devices().add_device(&device, led_state);
@ -182,7 +182,7 @@ impl State {
} }
} }
InputEvent::DeviceRemoved { device } => { 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(); let devices = seat.devices();
if devices.has_device(&device) { if devices.has_device(&device) {
devices.remove_device(&device); devices.remove_device(&device);
@ -205,7 +205,6 @@ impl State {
.common .common
.shell .shell
.read() .read()
.unwrap()
.seats .seats
.for_device(&event.device()) .for_device(&event.device())
.cloned(); .cloned();
@ -305,7 +304,7 @@ impl State {
InputEvent::PointerMotion { event, .. } => { InputEvent::PointerMotion { event, .. } => {
use smithay::backend::input::PointerMotionEvent; 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() { if let Some(seat) = shell.seats.for_device(&event.device()).cloned() {
self.common.idle_notifier_state.notify_activity(&seat); self.common.idle_notifier_state.notify_activity(&seat);
let current_output = seat.active_output(); 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 //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 { } 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 = let old_keyboard_target =
State::element_under(original_position, &current_output, &*shell); State::element_under(original_position, &current_output, &*shell);
let new_keyboard_target = State::element_under(position, &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_pointer_position(position.to_local(&output), &output);
shell.update_focal_point( shell.update_focal_point(
&seat, &seat,
@ -604,7 +603,6 @@ impl State {
.common .common
.shell .shell
.read() .read()
.unwrap()
.seats .seats
.for_device(&event.device()) .for_device(&event.device())
.cloned(); .cloned();
@ -619,12 +617,9 @@ impl State {
) )
.as_global(); .as_global();
let serial = SERIAL_COUNTER.next_serial(); let serial = SERIAL_COUNTER.next_serial();
let under = State::surface_under( let under =
position, State::surface_under(position, &output, &mut *self.common.shell.write())
&output, .map(|(target, pos)| (target, pos.as_logical()));
&mut *self.common.shell.write().unwrap(),
)
.map(|(target, pos)| (target, pos.as_logical()));
let ptr = seat.get_pointer().unwrap(); let ptr = seat.get_pointer().unwrap();
ptr.motion( ptr.motion(
@ -638,7 +633,7 @@ impl State {
); );
ptr.frame(self); 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) { for session in cursor_sessions_for_output(&*shell, &output) {
if let Some((geometry, offset)) = seat.cursor_geometry( if let Some((geometry, offset)) = seat.cursor_geometry(
position.as_logical().to_buffer( position.as_logical().to_buffer(
@ -673,7 +668,6 @@ impl State {
.common .common
.shell .shell
.read() .read()
.unwrap()
.seats .seats
.for_device(&event.device()) .for_device(&event.device())
.cloned() .cloned()
@ -707,7 +701,7 @@ impl State {
let global_position = let global_position =
seat.get_pointer().unwrap().current_location().as_global(); seat.get_pointer().unwrap().current_location().as_global();
let under = { let under = {
let shell = self.common.shell.read().unwrap(); let shell = self.common.shell.read();
State::element_under(global_position, &output, &shell) State::element_under(global_position, &output, &shell)
}; };
if let Some(target) = under { if let Some(target) = under {
@ -747,8 +741,7 @@ impl State {
supress_button(); supress_button();
self.common.event_loop_handle.insert_idle( self.common.event_loop_handle.insert_idle(
move |state| { move |state| {
let mut shell = let mut shell = state.common.shell.write();
state.common.shell.write().unwrap();
let res = shell.move_request( let res = shell.move_request(
&surface, &surface,
&seat_clone, &seat_clone,
@ -770,8 +763,7 @@ impl State {
supress_button(); supress_button();
self.common.event_loop_handle.insert_idle( self.common.event_loop_handle.insert_idle(
move |state| { move |state| {
let mut shell = let mut shell = state.common.shell.write();
state.common.shell.write().unwrap();
let Some(target_elem) = let Some(target_elem) =
shell.element_for_surface(&surface) shell.element_for_surface(&surface)
else { else {
@ -831,7 +823,7 @@ impl State {
} }
} }
} else { } else {
let mut shell = self.common.shell.write().unwrap(); let mut shell = self.common.shell.write();
if let Some(Trigger::Pointer(action_button)) = if let Some(Trigger::Pointer(action_button)) =
shell.overview_mode().0.active_trigger() shell.overview_mode().0.active_trigger()
{ {
@ -882,7 +874,6 @@ impl State {
.common .common
.shell .shell
.read() .read()
.unwrap()
.seats .seats
.for_device(&event.device()) .for_device(&event.device())
.cloned(); .cloned();
@ -953,7 +944,6 @@ impl State {
.common .common
.shell .shell
.read() .read()
.unwrap()
.seats .seats
.for_device(&event.device()) .for_device(&event.device())
.cloned(); .cloned();
@ -980,7 +970,6 @@ impl State {
.common .common
.shell .shell
.read() .read()
.unwrap()
.seats .seats
.for_device(&event.device()) .for_device(&event.device())
.cloned(); .cloned();
@ -1053,7 +1042,7 @@ impl State {
match gesture_state.action { match gesture_state.action {
Some(SwipeAction::NextWorkspace) | Some(SwipeAction::PrevWorkspace) => { Some(SwipeAction::NextWorkspace) | Some(SwipeAction::PrevWorkspace) => {
self.common.shell.write().unwrap().update_workspace_delta( self.common.shell.write().update_workspace_delta(
&seat.active_output(), &seat.active_output(),
gesture_state.delta, gesture_state.delta,
) )
@ -1081,7 +1070,6 @@ impl State {
.common .common
.shell .shell
.read() .read()
.unwrap()
.seats .seats
.for_device(&event.device()) .for_device(&event.device())
.cloned(); .cloned();
@ -1099,7 +1087,7 @@ impl State {
} else { } else {
velocity / seat.active_output().geometry().size.h as f64 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(), &seat.active_output(),
norm_velocity, norm_velocity,
&mut self.common.workspace_state.update(), &mut self.common.workspace_state.update(),
@ -1127,7 +1115,6 @@ impl State {
.common .common
.shell .shell
.read() .read()
.unwrap()
.seats .seats
.for_device(&event.device()) .for_device(&event.device())
.cloned(); .cloned();
@ -1150,7 +1137,6 @@ impl State {
.common .common
.shell .shell
.read() .read()
.unwrap()
.seats .seats
.for_device(&event.device()) .for_device(&event.device())
.cloned(); .cloned();
@ -1173,7 +1159,6 @@ impl State {
.common .common
.shell .shell
.read() .read()
.unwrap()
.seats .seats
.for_device(&event.device()) .for_device(&event.device())
.cloned(); .cloned();
@ -1196,7 +1181,6 @@ impl State {
.common .common
.shell .shell
.read() .read()
.unwrap()
.seats .seats
.for_device(&event.device()) .for_device(&event.device())
.cloned(); .cloned();
@ -1219,7 +1203,6 @@ impl State {
.common .common
.shell .shell
.read() .read()
.unwrap()
.seats .seats
.for_device(&event.device()) .for_device(&event.device())
.cloned(); .cloned();
@ -1239,7 +1222,7 @@ impl State {
} }
InputEvent::TouchDown { event, .. } => { 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() { if let Some(seat) = shell.seats.for_device(&event.device()).cloned() {
self.common.idle_notifier_state.notify_activity(&seat); self.common.idle_notifier_state.notify_activity(&seat);
let Some(output) = let Some(output) =
@ -1271,7 +1254,7 @@ impl State {
} }
} }
InputEvent::TouchMotion { event, .. } => { 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() { if let Some(seat) = shell.seats.for_device(&event.device()).cloned() {
self.common.idle_notifier_state.notify_activity(&seat); self.common.idle_notifier_state.notify_activity(&seat);
let Some(output) = let Some(output) =
@ -1301,7 +1284,7 @@ impl State {
} }
} }
InputEvent::TouchUp { event, .. } => { 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 let Some(Trigger::Touch(slot)) = shell.overview_mode().0.active_trigger() {
if *slot == event.slot() { if *slot == event.slot() {
shell.set_overview_mode(None, self.common.event_loop_handle.clone()); shell.set_overview_mode(None, self.common.event_loop_handle.clone());
@ -1329,7 +1312,6 @@ impl State {
.common .common
.shell .shell
.read() .read()
.unwrap()
.seats .seats
.for_device(&event.device()) .for_device(&event.device())
.cloned(); .cloned();
@ -1344,7 +1326,6 @@ impl State {
.common .common
.shell .shell
.read() .read()
.unwrap()
.seats .seats
.for_device(&event.device()) .for_device(&event.device())
.cloned(); .cloned();
@ -1356,7 +1337,7 @@ impl State {
} }
InputEvent::TabletToolAxis { event, .. } => { 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() { if let Some(seat) = shell.seats.for_device(&event.device()).cloned() {
self.common.idle_notifier_state.notify_activity(&seat); self.common.idle_notifier_state.notify_activity(&seat);
let Some(output) = let Some(output) =
@ -1421,7 +1402,7 @@ impl State {
} }
} }
InputEvent::TabletToolProximity { event, .. } => { 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() { if let Some(seat) = shell.seats.for_device(&event.device()).cloned() {
self.common.idle_notifier_state.notify_activity(&seat); self.common.idle_notifier_state.notify_activity(&seat);
let Some(output) = let Some(output) =
@ -1480,7 +1461,6 @@ impl State {
.common .common
.shell .shell
.read() .read()
.unwrap()
.seats .seats
.for_device(&event.device()) .for_device(&event.device())
.cloned(); .cloned();
@ -1503,7 +1483,6 @@ impl State {
.common .common
.shell .shell
.read() .read()
.unwrap()
.seats .seats
.for_device(&event.device()) .for_device(&event.device())
.cloned(); .cloned();
@ -1533,7 +1512,7 @@ impl State {
handle: KeysymHandle<'_>, handle: KeysymHandle<'_>,
serial: Serial, serial: Serial,
) -> FilterResult<Option<(Action, shortcuts::Binding)>> { ) -> FilterResult<Option<(Action, shortcuts::Binding)>> {
let mut shell = self.common.shell.write().unwrap(); let mut shell = self.common.shell.write();
let keyboard = seat.get_keyboard().unwrap(); let keyboard = seat.get_keyboard().unwrap();
let pointer = seat.get_pointer().unwrap(); let pointer = seat.get_pointer().unwrap();

View file

@ -162,7 +162,7 @@ fn main() -> Result<(), Box<dyn Error>> {
} }
// trigger routines // 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(); let dh = state.common.display_handle.clone();
for client in clients.values() { for client in clients.values() {
@ -173,7 +173,7 @@ fn main() -> Result<(), Box<dyn Error>> {
refresh(state); refresh(state);
{ {
let shell = state.common.shell.read().unwrap(); let shell = state.common.shell.read();
if shell.animations_going() { if shell.animations_going() {
for output in shell.outputs().cloned().collect::<Vec<_>>().into_iter() { for output in shell.outputs().cloned().collect::<Vec<_>>().into_iter() {
state.backend.schedule_render(&output); state.backend.schedule_render(&output);

View file

@ -695,7 +695,7 @@ impl CosmicStack {
surface.send_configure(); surface.send_configure();
if let Some(surface) = surface.wl_surface().map(Cow::into_owned) { if let Some(surface) = surface.wl_surface().map(Cow::into_owned) {
let _ = data.common.event_loop_handle.insert_idle(move |state| { 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, &surface,
&seat, &seat,
serial, serial,
@ -837,7 +837,7 @@ impl Program for CosmicStackInternal {
.map(Cow::into_owned) .map(Cow::into_owned)
{ {
loop_handle.insert_idle(move |state| { loop_handle.insert_idle(move |state| {
let res = state.common.shell.write().unwrap().move_request( let res = state.common.shell.write().move_request(
&surface, &surface,
&seat, &seat,
serial, serial,
@ -867,12 +867,8 @@ impl Program for CosmicStackInternal {
*self.potential_drag.lock().unwrap() = None; *self.potential_drag.lock().unwrap() = None;
if let Some(surface) = self.windows.lock().unwrap().get(idx).cloned() { if let Some(surface) = self.windows.lock().unwrap().get(idx).cloned() {
loop_handle.insert_idle(move |state| { loop_handle.insert_idle(move |state| {
if let Some(mapped) = state if let Some(mapped) =
.common state.common.shell.read().element_for_surface(&surface)
.shell
.read()
.unwrap()
.element_for_surface(&surface)
{ {
mapped.stack_ref().unwrap().set_active(&surface); mapped.stack_ref().unwrap().set_active(&surface);
} }
@ -896,7 +892,7 @@ impl Program for CosmicStackInternal {
.map(Cow::into_owned) .map(Cow::into_owned)
{ {
loop_handle.insert_idle(move |state| { 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(mapped) = shell.element_for_surface(&surface).cloned() {
let position = if let Some((output, set)) = let position = if let Some((output, set)) =
shell.workspaces.sets.iter().find(|(_, set)| { shell.workspaces.sets.iter().find(|(_, set)| {
@ -950,7 +946,7 @@ impl Program for CosmicStackInternal {
.map(Cow::into_owned) .map(Cow::into_owned)
{ {
loop_handle.insert_idle(move |state| { 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(mapped) = shell.element_for_surface(&surface).cloned() {
if let Some(workspace) = shell.space_for(&mapped) { if let Some(workspace) = shell.space_for(&mapped) {
let Some(elem_geo) = workspace.element_geometry(&mapped) else { let Some(elem_geo) = workspace.element_geometry(&mapped) else {
@ -1407,7 +1403,7 @@ impl PointerTarget<State> for CosmicStack {
return; return;
}; };
self.0.loop_handle().insert_idle(move |state| { 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, &surface,
&seat, &seat,
serial, serial,
@ -1481,7 +1477,7 @@ impl PointerTarget<State> for CosmicStack {
surface.send_configure(); surface.send_configure();
if let Some(surface) = surface.wl_surface().map(Cow::into_owned) { if let Some(surface) = surface.wl_surface().map(Cow::into_owned) {
let _ = data.common.event_loop_handle.insert_idle(move |state| { 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, &surface,
&seat, &seat,
serial, serial,

View file

@ -441,7 +441,7 @@ impl Program for CosmicWindowInternal {
if let Some((seat, serial)) = last_seat.cloned() { if let Some((seat, serial)) = last_seat.cloned() {
if let Some(surface) = self.window.wl_surface().map(Cow::into_owned) { if let Some(surface) = self.window.wl_surface().map(Cow::into_owned) {
loop_handle.insert_idle(move |state| { loop_handle.insert_idle(move |state| {
let res = state.common.shell.write().unwrap().move_request( let res = state.common.shell.write().move_request(
&surface, &surface,
&seat, &seat,
serial, serial,
@ -467,7 +467,7 @@ impl Program for CosmicWindowInternal {
Message::Minimize => { Message::Minimize => {
if let Some(surface) = self.window.wl_surface().map(Cow::into_owned) { if let Some(surface) = self.window.wl_surface().map(Cow::into_owned) {
loop_handle.insert_idle(move |state| { 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() { if let Some(mapped) = shell.element_for_surface(&surface).cloned() {
shell.minimize_request(&mapped) shell.minimize_request(&mapped)
} }
@ -477,7 +477,7 @@ impl Program for CosmicWindowInternal {
Message::Maximize => { Message::Maximize => {
if let Some(surface) = self.window.wl_surface().map(Cow::into_owned) { if let Some(surface) = self.window.wl_surface().map(Cow::into_owned) {
loop_handle.insert_idle(move |state| { 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() { if let Some(mapped) = shell.element_for_surface(&surface).cloned() {
let seat = shell.seats.last_active().clone(); let seat = shell.seats.last_active().clone();
shell.maximize_toggle(&mapped, &seat) shell.maximize_toggle(&mapped, &seat)
@ -490,7 +490,7 @@ impl Program for CosmicWindowInternal {
if let Some((seat, serial)) = last_seat.cloned() { if let Some((seat, serial)) = last_seat.cloned() {
if let Some(surface) = self.window.wl_surface().map(Cow::into_owned) { if let Some(surface) = self.window.wl_surface().map(Cow::into_owned) {
loop_handle.insert_idle(move |state| { 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(mapped) = shell.element_for_surface(&surface).cloned() {
let position = if let Some((output, set)) = let position = if let Some((output, set)) =
shell.workspaces.sets.iter().find(|(_, set)| { shell.workspaces.sets.iter().find(|(_, set)| {
@ -763,7 +763,7 @@ impl PointerTarget<State> for CosmicWindow {
return; return;
}; };
self.0.loop_handle().insert_idle(move |state| { 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, &surface,
&seat, &seat,
serial, serial,

View file

@ -112,7 +112,6 @@ impl Shell {
.common .common
.shell .shell
.read() .read()
.unwrap()
.element_for_surface(window) .element_for_surface(window)
.cloned(), .cloned(),
_ => None, _ => None,
@ -123,17 +122,12 @@ impl Shell {
return; return;
} }
state state.common.shell.write().append_focus_stack(&mapped, seat);
.common
.shell
.write()
.unwrap()
.append_focus_stack(&mapped, seat);
} }
update_focus_state(seat, target, state, serial, update_cursor); 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<State>) { pub fn append_focus_stack(&mut self, mapped: &CosmicMapped, seat: &Seat<State>) {
@ -242,7 +236,7 @@ fn update_focus_state(
if should_update_cursor && state.common.config.cosmic_conf.cursor_follows_focus { if should_update_cursor && state.common.config.cosmic_conf.cursor_follows_focus {
if target.is_some() { if target.is_some() {
//need to borrow mutably for surface under //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 // get the top left corner of the target element
let geometry = shell.focused_geometry(target.unwrap()); let geometry = shell.focused_geometry(target.unwrap());
if let Some(geometry) = geometry { if let Some(geometry) = geometry {
@ -292,7 +286,6 @@ fn update_focus_state(
.common .common
.shell .shell
.read() .read()
.unwrap()
.get_output_for_focus(seat) .get_output_for_focus(seat)
.as_ref(), .as_ref(),
) )
@ -339,14 +332,13 @@ impl Common {
.common .common
.shell .shell
.read() .read()
.unwrap()
.seats .seats
.iter() .iter()
.cloned() .cloned()
.collect::<Vec<_>>(); .collect::<Vec<_>>();
for seat in &seats { for seat in &seats {
{ {
let shell = state.common.shell.read().unwrap(); let shell = state.common.shell.read();
let focused_output = seat.focused_output(); let focused_output = seat.focused_output();
let active_output = seat.active_output(); let active_output = seat.active_output();
@ -365,7 +357,7 @@ impl Common {
update_pointer_focus(state, &seat); update_pointer_focus(state, &seat);
let output = seat.focused_or_active_output(); 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); let last_known_focus = ActiveFocus::get(&seat);
if let Some(target) = last_known_focus { 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<State>) {
let output = seat.active_output(); let output = seat.active_output();
let position = pointer.current_location().as_global(); 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) let under = State::surface_under(position, &output, &mut shell)
.map(|(target, pos)| (target, pos.as_logical())); .map(|(target, pos)| (target, pos.as_logical()));
drop(shell); drop(shell);

View file

@ -240,7 +240,7 @@ impl IsAlive for KeyboardFocusTarget {
impl PointerTarget<State> for PointerFocusTarget { impl PointerTarget<State> for PointerFocusTarget {
fn enter(&self, seat: &Seat<State>, data: &mut State, event: &PointerMotionEvent) { fn enter(&self, seat: &Seat<State>, 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 { if let Some(element) = toplevel {
for session in element.cursor_sessions() { for session in element.cursor_sessions() {
session.set_cursor_pos(Some( session.set_cursor_pos(Some(
@ -270,7 +270,7 @@ impl PointerTarget<State> for PointerFocusTarget {
} }
} }
fn motion(&self, seat: &Seat<State>, data: &mut State, event: &PointerMotionEvent) { fn motion(&self, seat: &Seat<State>, 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 { if let Some(element) = toplevel {
for session in element.cursor_sessions() { for session in element.cursor_sessions() {
session.set_cursor_pos(Some( session.set_cursor_pos(Some(
@ -346,7 +346,7 @@ impl PointerTarget<State> for PointerFocusTarget {
} }
} }
fn leave(&self, seat: &Seat<State>, data: &mut State, serial: Serial, time: u32) { fn leave(&self, seat: &Seat<State>, 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 { if let Some(element) = toplevel {
for session in element.cursor_sessions() { for session in element.cursor_sessions() {
session.set_cursor_pos(None); session.set_cursor_pos(None);

View file

@ -16,7 +16,7 @@ use crate::{
use super::{Item, ResizeEdge}; use super::{Item, ResizeEdge};
fn toggle_stacking(state: &mut State, mapped: &CosmicMapped) { 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(); let seat = shell.seats.last_active().clone();
if let Some(new_focus) = shell.toggle_stacking(&seat, mapped) { if let Some(new_focus) = shell.toggle_stacking(&seat, mapped) {
std::mem::drop(shell); 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) { 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 seat = shell.seats.last_active().clone();
let (current_handle, output) = { let (current_handle, output) = {
let Some(ws) = shell.space_for(mapped) else { 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) { 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 seat = shell.seats.last_active().clone();
let (current_handle, output) = { let (current_handle, output) = {
let Some(ws) = shell.space_for(mapped) else { let Some(ws) = shell.space_for(mapped) else {
@ -114,7 +114,7 @@ pub fn tab_items(
) )
.into(); .into();
let mut shell = state.common.shell.write().unwrap(); let mut shell = state.common.shell.write();
let seat = shell.seats.last_active().clone(); let seat = shell.seats.last_active().clone();
let output = seat.active_output(); let output = seat.active_output();
let workspace = shell.workspaces.active_mut(&output).unwrap(); let workspace = shell.workspaces.active_mut(&output).unwrap();
@ -198,12 +198,7 @@ pub fn window_items(
Item::new(fl!("window-menu-minimize"), move |handle| { Item::new(fl!("window-menu-minimize"), move |handle| {
let mapped = minimize_clone.clone(); let mapped = minimize_clone.clone();
let _ = handle.insert_idle(move |state| { let _ = handle.insert_idle(move |state| {
state state.common.shell.write().minimize_request(&mapped);
.common
.shell
.write()
.unwrap()
.minimize_request(&mapped);
}); });
}) })
.shortcut(config.shortcut_for_action(&Action::Minimize)), .shortcut(config.shortcut_for_action(&Action::Minimize)),
@ -212,7 +207,7 @@ pub fn window_items(
Item::new(fl!("window-menu-maximize"), move |handle| { Item::new(fl!("window-menu-maximize"), move |handle| {
let mapped = maximize_clone.clone(); let mapped = maximize_clone.clone();
let _ = handle.insert_idle(move |state| { 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 seat = shell.seats.last_active().clone();
shell.maximize_toggle(&mapped, &seat); shell.maximize_toggle(&mapped, &seat);
}); });
@ -224,7 +219,7 @@ pub fn window_items(
Item::new(fl!("window-menu-tiled"), move |handle| { Item::new(fl!("window-menu-tiled"), move |handle| {
let tile_clone = tile_clone.clone(); let tile_clone = tile_clone.clone();
let _ = handle.insert_idle(move |state| { 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 seat = shell.seats.last_active().clone();
if let Some(ws) = shell.space_for_mut(&tile_clone) { if let Some(ws) = shell.space_for_mut(&tile_clone) {
ws.toggle_floating_window(&seat, &tile_clone); ws.toggle_floating_window(&seat, &tile_clone);
@ -246,7 +241,7 @@ pub fn window_items(
let move_clone = move_clone.clone(); let move_clone = move_clone.clone();
let _ = handle.insert_idle(move |state| { let _ = handle.insert_idle(move |state| {
if let Some(surface) = move_clone.wl_surface() { 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 seat = shell.seats.last_active().clone();
let res = shell.move_request( let res = shell.move_request(
&surface, &surface,
@ -285,7 +280,7 @@ pub fn window_items(
Item::new(fl!("window-menu-resize-edge-top"), move |handle| { Item::new(fl!("window-menu-resize-edge-top"), move |handle| {
let resize_clone = resize_top_clone.clone(); let resize_clone = resize_top_clone.clone();
let _ = handle.insert_idle(move |state| { 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 seat = shell.seats.last_active().clone();
let res = shell.menu_resize_request( let res = shell.menu_resize_request(
&resize_clone, &resize_clone,
@ -320,7 +315,7 @@ pub fn window_items(
Item::new(fl!("window-menu-resize-edge-left"), move |handle| { Item::new(fl!("window-menu-resize-edge-left"), move |handle| {
let resize_clone = resize_left_clone.clone(); let resize_clone = resize_left_clone.clone();
let _ = handle.insert_idle(move |state| { 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 seat = shell.seats.last_active().clone();
let res = shell.menu_resize_request( let res = shell.menu_resize_request(
&resize_clone, &resize_clone,
@ -355,7 +350,7 @@ pub fn window_items(
Item::new(fl!("window-menu-resize-edge-right"), move |handle| { Item::new(fl!("window-menu-resize-edge-right"), move |handle| {
let resize_clone = resize_right_clone.clone(); let resize_clone = resize_right_clone.clone();
let _ = handle.insert_idle(move |state| { 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 seat = shell.seats.last_active().clone();
let res = shell.menu_resize_request( let res = shell.menu_resize_request(
&resize_clone, &resize_clone,
@ -390,7 +385,7 @@ pub fn window_items(
Item::new(fl!("window-menu-resize-edge-bottom"), move |handle| { Item::new(fl!("window-menu-resize-edge-bottom"), move |handle| {
let resize_clone = resize_bottom_clone.clone(); let resize_clone = resize_bottom_clone.clone();
let _ = handle.insert_idle(move |state| { 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 seat = shell.seats.last_active().clone();
let res = shell.menu_resize_request( let res = shell.menu_resize_request(
&resize_clone, &resize_clone,
@ -445,7 +440,7 @@ pub fn window_items(
Item::new(fl!("window-menu-sticky"), move |handle| { Item::new(fl!("window-menu-sticky"), move |handle| {
let mapped = sticky_clone.clone(); let mapped = sticky_clone.clone();
let _ = handle.insert_idle(move |state| { 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 seat = shell.seats.last_active().clone();
shell.toggle_sticky(&seat, &mapped); shell.toggle_sticky(&seat, &mapped);
}); });

View file

@ -522,7 +522,7 @@ impl PointerGrab<State> for MenuGrab {
let mut guard = self.elements.lock().unwrap(); let mut guard = self.elements.lock().unwrap();
let elements = &mut *guard; let elements = &mut *guard;
let event_location = if let Some(output) = self.screen_space_relative.as_ref() { 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 event
.location .location
.as_global() .as_global()
@ -726,7 +726,7 @@ impl TouchGrab<State> for MenuGrab {
let mut guard = self.elements.lock().unwrap(); let mut guard = self.elements.lock().unwrap();
let elements = &mut *guard; let elements = &mut *guard;
let event_location = if let Some(output) = self.screen_space_relative.as_ref() { 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 event
.location .location
.as_global() .as_global()

View file

@ -347,7 +347,7 @@ pub struct MoveGrab {
impl MoveGrab { impl MoveGrab {
fn update_location(&mut self, state: &mut State, location: Point<f64, Logical>) { fn update_location(&mut self, state: &mut State, location: Point<f64, Logical>) {
let mut shell = state.common.shell.write().unwrap(); let mut shell = state.common.shell.write();
let Some(current_output) = shell let Some(current_output) = shell
.outputs() .outputs()
@ -792,7 +792,7 @@ impl Drop for MoveGrab {
if grab_state.window.alive() { if grab_state.window.alive() {
let window_location = let window_location =
(grab_state.location.to_i32_round() + grab_state.window_offset).as_global(); (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; let workspace_handle = shell.active_space(&output).unwrap().handle;
for old_output in window_outputs.iter().filter(|o| *o != &output) { for old_output in window_outputs.iter().filter(|o| *o != &output) {

View file

@ -227,7 +227,7 @@ impl ResizeForkGrab {
self.last_loc = location.as_global(); self.last_loc = location.as_global();
if let Some(output) = self.output.upgrade() { 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 { let Some(workspace) = shell.active_space_mut(&output) else {
return false; return false;
}; };

View file

@ -39,7 +39,7 @@ impl KeyboardGrab<State> for SwapWindowGrab {
serial: Serial, serial: Serial,
time: u32, 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); handle.unset_grab(self, data, serial, false);
return; return;

View file

@ -1309,7 +1309,7 @@ pub struct InvalidWorkspaceIndex;
impl Common { impl Common {
pub fn add_output(&mut self, output: &Output) { pub fn add_output(&mut self, output: &Output) {
let mut shell = self.shell.write().unwrap(); let mut shell = self.shell.write();
shell shell
.workspaces .workspaces
.add_output(output, &mut self.workspace_state.update()); .add_output(output, &mut self.workspace_state.update());
@ -1333,7 +1333,7 @@ impl Common {
} }
pub fn remove_output(&mut self, output: &Output) { 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; let shell_ref = &mut *shell;
shell_ref.workspaces.remove_output( shell_ref.workspaces.remove_output(
output, output,
@ -1351,7 +1351,7 @@ impl Common {
return; return;
} }
let mut shell = self.shell.write().unwrap(); let mut shell = self.shell.write();
shell shell
.workspaces .workspaces
.migrate_workspace(from, to, handle, &mut self.workspace_state.update()); .migrate_workspace(from, to, handle, &mut self.workspace_state.update());
@ -1360,7 +1360,7 @@ impl Common {
} }
pub fn update_config(&mut self) { pub fn update_config(&mut self) {
let mut shell = self.shell.write().unwrap(); let mut shell = self.shell.write();
let shell_ref = &mut *shell; let shell_ref = &mut *shell;
shell_ref.active_hint = self.config.cosmic_conf.active_hint; shell_ref.active_hint = self.config.cosmic_conf.active_hint;
if let Some(zoom_state) = shell_ref.zoom_state.as_mut() { if let Some(zoom_state) = shell_ref.zoom_state.as_mut() {
@ -1388,7 +1388,7 @@ impl Common {
pub fn refresh(&mut self) { pub fn refresh(&mut self) {
self.xdg_activation_state self.xdg_activation_state
.retain_tokens(|_, data| data.timestamp.elapsed() < ACTIVATION_TOKEN_EXPIRE_TIME); .retain_tokens(|_, data| data.timestamp.elapsed() < ACTIVATION_TOKEN_EXPIRE_TIME);
self.shell.write().unwrap().refresh( self.shell.write().refresh(
&self.xdg_activation_state, &self.xdg_activation_state,
&mut self.workspace_state.update(), &mut self.workspace_state.update(),
); );
@ -1410,7 +1410,7 @@ impl Common {
pub fn on_commit(&mut self, surface: &WlSurface) { 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() { for seat in shell.seats.iter() {
if let Some(move_grab) = seat.user_data().get::<SeatMoveGrabState>() { if let Some(move_grab) = seat.user_data().get::<SeatMoveGrabState>() {

View file

@ -539,14 +539,7 @@ impl Program for ZoomProgram {
match message { match message {
ZoomMessage::Decrease => { ZoomMessage::Decrease => {
let _ = loop_handle.insert_idle(|state| { let _ = loop_handle.insert_idle(|state| {
let seat = state let seat = state.common.shell.read().seats.last_active().clone();
.common
.shell
.read()
.unwrap()
.seats
.last_active()
.clone();
let increment = let increment =
state.common.config.cosmic_conf.accessibility_zoom.increment as f64 / 100.0; state.common.config.cosmic_conf.accessibility_zoom.increment as f64 / 100.0;
@ -555,14 +548,7 @@ impl Program for ZoomProgram {
} }
ZoomMessage::Increase => { ZoomMessage::Increase => {
let _ = loop_handle.insert_idle(|state| { let _ = loop_handle.insert_idle(|state| {
let seat = state let seat = state.common.shell.read().seats.last_active().clone();
.common
.shell
.read()
.unwrap()
.seats
.last_active()
.clone();
let increment = let increment =
state.common.config.cosmic_conf.accessibility_zoom.increment as f64 / 100.0; 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) = if let Some(start_data) =
check_grab_preconditions(&seat, Some(serial), None) 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(); let output = seat.active_output();
if shell.zoom_state().is_some() { if shell.zoom_state().is_some() {
@ -741,7 +727,7 @@ impl Program for ZoomProgram {
if let Some(start_data) = if let Some(start_data) =
check_grab_preconditions(&seat, Some(serial), None) 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(); let output = seat.active_output();
if shell.zoom_state().is_some() { if shell.zoom_state().is_some() {

View file

@ -118,7 +118,7 @@ use std::{
collections::HashSet, collections::HashSet,
ffi::OsString, ffi::OsString,
process::Child, process::Child,
sync::{atomic::AtomicBool, Arc, Mutex, Once, RwLock}, sync::{atomic::AtomicBool, Arc, Mutex, Once},
time::{Duration, Instant}, time::{Duration, Instant},
}; };
@ -195,7 +195,7 @@ pub struct Common {
pub event_loop_signal: LoopSignal, pub event_loop_signal: LoopSignal,
pub popups: PopupManager, pub popups: PopupManager,
pub shell: Arc<RwLock<Shell>>, pub shell: Arc<parking_lot::RwLock<Shell>>,
pub clock: Clock<Monotonic>, pub clock: Clock<Monotonic>,
pub startup_done: Arc<AtomicBool>, pub startup_done: Arc<AtomicBool>,
@ -307,7 +307,7 @@ impl BackendData {
test_only: bool, test_only: bool,
loop_handle: &LoopHandle<'static, State>, loop_handle: &LoopHandle<'static, State>,
screen_filter: &ScreenFilter, screen_filter: &ScreenFilter,
shell: Arc<RwLock<Shell>>, shell: Arc<parking_lot::RwLock<Shell>>,
workspace_state: &mut WorkspaceUpdateGuard<'_, State>, workspace_state: &mut WorkspaceUpdateGuard<'_, State>,
xdg_activation_state: &XdgActivationState, xdg_activation_state: &XdgActivationState,
startup_done: Arc<AtomicBool>, startup_done: Arc<AtomicBool>,
@ -327,7 +327,7 @@ impl BackendData {
_ => unreachable!("No backend set when applying output config"), _ => unreachable!("No backend set when applying output config"),
}?; }?;
let mut shell = shell.write().unwrap(); let mut shell = shell.write();
for output in result { for output in result {
// apply to Output // apply to Output
let final_config = output let final_config = output
@ -561,7 +561,7 @@ impl State {
DataControlState::new::<Self, _>(dh, Some(&primary_selection_state), |_| true) DataControlState::new::<Self, _>(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 = let layer_shell_state =
WlrLayerShellState::new_with_filter::<State, _>(dh, client_is_privileged); WlrLayerShellState::new_with_filter::<State, _>(dh, client_is_privileged);
@ -700,7 +700,7 @@ impl Common {
output: &Output, output: &Output,
render_element_states: &RenderElementStates, render_element_states: &RenderElementStates,
) { ) {
let shell = self.shell.read().unwrap(); let shell = self.shell.read();
let processor = |surface: &WlSurface, states: &SurfaceData| { let processor = |surface: &WlSurface, states: &SurfaceData| {
let primary_scanout_output = update_surface_primary_scanout_output( let primary_scanout_output = update_surface_primary_scanout_output(
surface, surface,
@ -802,7 +802,7 @@ impl Common {
render_element_states: &RenderElementStates, render_element_states: &RenderElementStates,
mut dmabuf_feedback: impl FnMut(DrmNode) -> Option<SurfaceDmabufFeedback>, mut dmabuf_feedback: impl FnMut(DrmNode) -> Option<SurfaceDmabufFeedback>,
) { ) {
let shell = self.shell.read().unwrap(); let shell = self.shell.read();
if let Some(session_lock) = shell.session_lock.as_ref() { if let Some(session_lock) = shell.session_lock.as_ref() {
if let Some(lock_surface) = session_lock.surfaces.get(output) { 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(session_lock) = shell.session_lock.as_ref() {
if let Some(lock_surface) = session_lock.surfaces.get(output) { if let Some(lock_surface) = session_lock.surfaces.get(output) {

View file

@ -33,7 +33,7 @@ pub fn watch_theme(handle: LoopHandle<'_, State>) -> Result<(), cosmic_config::E
if theme.theme_type != new_theme.theme_type { if theme.theme_type != new_theme.theme_type {
*theme = new_theme; *theme = new_theme;
let mut workspace_guard = state.common.workspace_state.update(); let mut workspace_guard = state.common.workspace_state.update();
state.common.shell.write().unwrap().set_theme( state.common.shell.write().set_theme(
theme.clone(), theme.clone(),
&state.common.xdg_activation_state, &state.common.xdg_activation_state,
&mut workspace_guard, &mut workspace_guard,

View file

@ -12,7 +12,7 @@ impl A11yHandler for State {
} }
fn request_screen_magnifier(&mut self, enabled: bool) { 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 if shell
.zoom_state() .zoom_state()

View file

@ -173,7 +173,7 @@ impl CompositorHandler for State {
// handle initial configure events and map windows if necessary // handle initial configure events and map windows if necessary
let mapped = self.send_initial_configure_and_map(surface); 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 // schedule a new render
if let Some(output) = shell.visible_output_for_surface(surface) { if let Some(output) = shell.visible_output_for_surface(surface) {
@ -277,7 +277,7 @@ impl CompositorHandler for State {
impl State { impl State {
fn send_initial_configure_and_map(&mut self, surface: &WlSurface) -> bool { 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 if let Some(pending) = shell
.pending_windows .pending_windows

View file

@ -114,14 +114,14 @@ pub fn unset_mode(mapped: &CosmicMapped, surface: &WlSurface) {
impl XdgDecorationHandler for State { impl XdgDecorationHandler for State {
fn new_decoration(&mut self, toplevel: ToplevelSurface) { 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()) { if let Some(mapped) = shell.element_for_surface(toplevel.wl_surface()) {
new_decoration(mapped, toplevel.wl_surface()); new_decoration(mapped, toplevel.wl_surface());
} }
} }
fn request_mode(&mut self, toplevel: ToplevelSurface, mode: XdgMode) { 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()) { if let Some(mapped) = shell.element_for_surface(toplevel.wl_surface()) {
request_mode(mapped, toplevel.wl_surface(), mode); request_mode(mapped, toplevel.wl_surface(), mode);
} else { } else {
@ -130,7 +130,7 @@ impl XdgDecorationHandler for State {
} }
fn unset_mode(&mut self, toplevel: ToplevelSurface) { 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()) { if let Some(mapped) = shell.element_for_surface(toplevel.wl_surface()) {
unset_mode(mapped, 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) { 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) { if let Some(mapped) = shell.element_for_surface(surface) {
let mode = new_decoration(mapped, surface); let mode = new_decoration(mapped, surface);
decoration.mode(mode); decoration.mode(mode);
@ -157,7 +157,7 @@ impl KdeDecorationHandler for State {
mode: WEnum<KdeMode>, mode: WEnum<KdeMode>,
) { ) {
if let WEnum::Value(mode) = mode { 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. // 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) { if let Some(mapped) = shell.element_for_surface(surface) {
request_mode( request_mode(
@ -174,7 +174,7 @@ impl KdeDecorationHandler for State {
} }
fn release(&mut self, _decoration: &OrgKdeKwinServerDecoration, surface: &WlSurface) { 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) { if let Some(mapped) = shell.element_for_surface(surface) {
unset_mode(mapped, surface) unset_mode(mapped, surface)
} }

View file

@ -42,20 +42,11 @@ impl FractionalScaleHandler for State {
self.common self.common
.shell .shell
.read() .read()
.unwrap()
.visible_output_for_surface(&surface) .visible_output_for_surface(&surface)
.cloned() .cloned()
}) })
}) })
.unwrap_or_else(|| { .unwrap_or_else(|| self.common.shell.read().seats.last_active().active_output());
self.common
.shell
.read()
.unwrap()
.seats
.last_active()
.active_output()
});
with_states(&surface, |states| { with_states(&surface, |states| {
with_fractional_scale(states, |fractional_scale| { with_fractional_scale(states, |fractional_scale| {

View file

@ -27,7 +27,6 @@ impl InputMethodHandler for State {
self.common self.common
.shell .shell
.read() .read()
.unwrap()
.element_for_surface(parent) .element_for_surface(parent)
.map(|e| e.geometry()) .map(|e| e.geometry())
.unwrap_or_default() .unwrap_or_default()

View file

@ -26,7 +26,7 @@ impl WlrLayerShellHandler for State {
_layer: Layer, _layer: Layer,
namespace: String, 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 seat = shell.seats.last_active().clone();
let output = wl_output let output = wl_output
.as_ref() .as_ref()
@ -40,7 +40,7 @@ impl WlrLayerShellHandler for State {
} }
fn new_popup(&mut self, _parent: WlrLayerSurface, popup: PopupSurface) { 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() { if popup.send_configure().is_ok() {
self.common self.common
@ -51,7 +51,7 @@ impl WlrLayerShellHandler for State {
} }
fn layer_destroyed(&mut self, surface: WlrLayerSurface) { 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 let maybe_output = shell
.outputs() .outputs()
.find(|o| { .find(|o| {

View file

@ -22,7 +22,7 @@ impl OverlapNotifyHandler for State {
.layer_surfaces() .layer_surfaces()
.find(|l| l.shell_surface() == &resource) .find(|l| l.shell_surface() == &resource)
.and_then(|l| { .and_then(|l| {
let shell = self.common.shell.read().unwrap(); let shell = self.common.shell.read();
let outputs = shell.outputs(); let outputs = shell.outputs();
let ret = outputs.map(|o| layer_map_for_output(o)).find_map(|s| { let ret = outputs.map(|o| layer_map_for_output(o)).find_map(|s| {
s.layer_for_surface(l.wl_surface(), WindowSurfaceType::ALL) s.layer_for_surface(l.wl_surface(), WindowSurfaceType::ALL)
@ -34,14 +34,14 @@ impl OverlapNotifyHandler for State {
} }
fn outputs(&self) -> impl Iterator<Item = Output> { fn outputs(&self) -> impl Iterator<Item = Output> {
let shell = self.common.shell.read().unwrap(); let shell = self.common.shell.read();
shell.outputs().cloned().collect::<Vec<_>>().into_iter() shell.outputs().cloned().collect::<Vec<_>>().into_iter()
} }
fn active_workspaces( fn active_workspaces(
&self, &self,
) -> impl Iterator<Item = crate::wayland::protocols::workspace::WorkspaceHandle> { ) -> impl Iterator<Item = crate::wayland::protocols::workspace::WorkspaceHandle> {
let shell = self.common.shell.read().unwrap(); let shell = self.common.shell.read();
shell shell
.workspaces .workspaces
.sets .sets

View file

@ -51,7 +51,7 @@ impl ScreencopyHandler for State {
.upgrade() .upgrade()
.and_then(|output| constraints_for_output(&output, &mut self.backend)), .and_then(|output| constraints_for_output(&output, &mut self.backend)),
ImageCaptureSourceData::Workspace(handle) => { 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(); let output = shell.workspaces.space_for_handle(&handle)?.output();
constraints_for_output(output, &mut self.backend) constraints_for_output(output, &mut self.backend)
} }
@ -69,7 +69,6 @@ impl ScreencopyHandler for State {
.common .common
.shell .shell
.read() .read()
.unwrap()
.seats .seats
.last_active() .last_active()
.cursor_geometry((0.0, 0.0), self.common.clock.now()) .cursor_geometry((0.0, 0.0), self.common.clock.now())
@ -103,7 +102,7 @@ impl ScreencopyHandler for State {
output.add_session(session); output.add_session(session);
} }
ImageCaptureSourceData::Workspace(handle) => { 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 { let Some(workspace) = shell.workspaces.space_for_handle_mut(&handle) else {
session.stop(); session.stop();
return; return;
@ -132,14 +131,7 @@ impl ScreencopyHandler for State {
} }
fn new_cursor_session(&mut self, session: CursorSession) { fn new_cursor_session(&mut self, session: CursorSession) {
let (pointer_loc, pointer_size, hotspot) = { let (pointer_loc, pointer_size, hotspot) = {
let seat = self let seat = self.common.shell.read().seats.last_active().clone();
.common
.shell
.read()
.unwrap()
.seats
.last_active()
.clone();
let pointer = seat.get_pointer().unwrap(); let pointer = seat.get_pointer().unwrap();
let pointer_loc = pointer.current_location().to_i32_round().as_global(); let pointer_loc = pointer.current_location().to_i32_round().as_global();
@ -194,7 +186,7 @@ impl ScreencopyHandler for State {
output.add_cursor_session(session); output.add_cursor_session(session);
} }
ImageCaptureSourceData::Workspace(handle) => { 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 { let Some(workspace) = shell.workspaces.space_for_handle_mut(&handle) else {
return; return;
}; };
@ -225,7 +217,7 @@ impl ScreencopyHandler for State {
workspace.add_cursor_session(session); workspace.add_cursor_session(session);
} }
ImageCaptureSourceData::Toplevel(mut toplevel) => { 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 let Some(element) = shell.element_for_surface(&toplevel) {
if element.has_active_window(&toplevel) { if element.has_active_window(&toplevel) {
if let Some(workspace) = shell.space_for(element) { if let Some(workspace) = shell.space_for(element) {
@ -277,19 +269,12 @@ impl ScreencopyHandler for State {
return; return;
} }
let seat = self let seat = self.common.shell.read().seats.last_active().clone();
.common
.shell
.read()
.unwrap()
.seats
.last_active()
.clone();
render_cursor_to_buffer(self, &session, frame, &seat); render_cursor_to_buffer(self, &session, frame, &seat);
} }
fn frame_aborted(&mut self, frame: FrameRef) { 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() { for mut output in shell.outputs().cloned() {
output.remove_frame(&frame); output.remove_frame(&frame);
} }
@ -307,7 +292,6 @@ impl ScreencopyHandler for State {
.common .common
.shell .shell
.write() .write()
.unwrap()
.workspaces .workspaces
.space_for_handle_mut(&handle) .space_for_handle_mut(&handle)
{ {
@ -331,7 +315,6 @@ impl ScreencopyHandler for State {
.common .common
.shell .shell
.write() .write()
.unwrap()
.workspaces .workspaces
.space_for_handle_mut(&handle) .space_for_handle_mut(&handle)
{ {

View file

@ -209,7 +209,7 @@ pub fn render_workspace_to_buffer(
frame: Frame, frame: Frame,
handle: WorkspaceHandle, 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 { let Some(workspace) = shell.workspaces.space_for_handle(&handle) else {
return; return;
}; };
@ -509,7 +509,7 @@ pub fn render_window_to_buffer(
.map(Into::<WindowCaptureElement<R>>::into), .map(Into::<WindowCaptureElement<R>>::into),
); );
let shell = common.shell.read().unwrap(); let shell = common.shell.read();
let seat = shell.seats.last_active().clone(); let seat = shell.seats.last_active().clone();
let location = if let Some(mapped) = shell.element_for_surface(window) { let location = if let Some(mapped) = shell.element_for_surface(window) {
mapped.cursor_position(&seat).and_then(|mut p| { mapped.cursor_position(&seat).and_then(|mut p| {

View file

@ -18,7 +18,7 @@ impl SessionLockHandler for State {
} }
fn lock(&mut self, locker: SessionLocker) { 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 // Reject lock if sesion lock exists and is still valid
if let Some(session_lock) = shell.session_lock.as_ref() { if let Some(session_lock) = shell.session_lock.as_ref() {
@ -45,7 +45,7 @@ impl SessionLockHandler for State {
} }
fn unlock(&mut self) { fn unlock(&mut self) {
let mut shell = self.common.shell.write().unwrap(); let mut shell = self.common.shell.write();
shell.session_lock = None; shell.session_lock = None;
for output in shell.outputs() { for output in shell.outputs() {
@ -54,7 +54,7 @@ impl SessionLockHandler for State {
} }
fn new_surface(&mut self, lock_surface: LockSurface, wl_output: WlOutput) { 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(session_lock) = &mut shell.session_lock {
if let Some(output) = Output::from_resource(&wl_output) { if let Some(output) = Output::from_resource(&wl_output) {
lock_surface.with_pending_state(|states| { lock_surface.with_pending_state(|states| {

View file

@ -34,7 +34,7 @@ impl ToplevelManagementHandler for State {
) { ) {
self.unminimize(dh, window); 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::<Vec<_>>().iter() { for output in shell.outputs().cloned().collect::<Vec<_>>().iter() {
let maybe = shell let maybe = shell
.workspaces .workspaces
@ -120,7 +120,7 @@ impl ToplevelManagementHandler for State {
to_handle: WorkspaceHandle, to_handle: WorkspaceHandle,
_output: Output, _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(mut mapped) = shell.element_for_surface(window).cloned() {
if let Some(from_workspace) = shell.space_for_mut(&mapped) { 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 // If window is part of a stack, remove it and map it outside the stack
@ -168,7 +168,7 @@ impl ToplevelManagementHandler for State {
window: &<Self as ToplevelInfoHandler>::Window, window: &<Self as ToplevelInfoHandler>::Window,
output: Option<Output>, output: Option<Output>,
) { ) {
let mut shell = self.common.shell.write().unwrap(); let mut shell = self.common.shell.write();
let seat = shell.seats.last_active().clone(); let seat = shell.seats.last_active().clone();
if let Some(mapped) = shell.element_for_surface(window).cloned() { if let Some(mapped) = shell.element_for_surface(window).cloned() {
if let Some((output, workspace)) = if let Some((output, workspace)) =
@ -195,7 +195,7 @@ impl ToplevelManagementHandler for State {
_dh: &DisplayHandle, _dh: &DisplayHandle,
window: &<Self as ToplevelInfoHandler>::Window, window: &<Self as ToplevelInfoHandler>::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(mapped) = shell.element_for_surface(window).cloned() {
if let Some(workspace) = shell.space_for_mut(&mapped) { if let Some(workspace) = shell.space_for_mut(&mapped) {
if let Some((layer, previous_workspace)) = workspace.unfullscreen_request(window) { 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: &<Self as ToplevelInfoHandler>::Window) { fn maximize(&mut self, _dh: &DisplayHandle, window: &<Self as ToplevelInfoHandler>::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(mapped) = shell.element_for_surface(window).cloned() {
let seat = shell.seats.last_active().clone(); let seat = shell.seats.last_active().clone();
shell.maximize_request(&mapped, &seat, true); shell.maximize_request(&mapped, &seat, true);
@ -227,14 +227,14 @@ impl ToplevelManagementHandler for State {
} }
fn unmaximize(&mut self, _dh: &DisplayHandle, window: &<Self as ToplevelInfoHandler>::Window) { fn unmaximize(&mut self, _dh: &DisplayHandle, window: &<Self as ToplevelInfoHandler>::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(mapped) = shell.element_for_surface(window).cloned() {
shell.unmaximize_request(&mapped); shell.unmaximize_request(&mapped);
} }
} }
fn minimize(&mut self, _dh: &DisplayHandle, window: &<Self as ToplevelInfoHandler>::Window) { fn minimize(&mut self, _dh: &DisplayHandle, window: &<Self as ToplevelInfoHandler>::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(mapped) = shell.element_for_surface(window).cloned() {
if !mapped.is_stack() || &mapped.active_window() == window { if !mapped.is_stack() || &mapped.active_window() == window {
shell.minimize_request(&mapped); shell.minimize_request(&mapped);
@ -243,7 +243,7 @@ impl ToplevelManagementHandler for State {
} }
fn unminimize(&mut self, _dh: &DisplayHandle, window: &<Self as ToplevelInfoHandler>::Window) { fn unminimize(&mut self, _dh: &DisplayHandle, window: &<Self as ToplevelInfoHandler>::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(mapped) = shell.element_for_surface(window).cloned() {
let seat = shell.seats.last_active().clone(); let seat = shell.seats.last_active().clone();
shell.unminimize_request(&mapped, &seat); shell.unminimize_request(&mapped, &seat);
@ -258,7 +258,7 @@ impl ToplevelManagementHandler for State {
return; 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() { if let Some(mapped) = shell.element_for_surface(window).cloned() {
let seat = shell.seats.last_active().clone(); let seat = shell.seats.last_active().clone();
shell.toggle_sticky(&seat, &mapped); shell.toggle_sticky(&seat, &mapped);
@ -274,7 +274,7 @@ impl ToplevelManagementHandler for State {
return; 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() { if let Some(mapped) = shell.element_for_surface(window).cloned() {
let seat = shell.seats.last_active().clone(); let seat = shell.seats.last_active().clone();
shell.toggle_sticky(&seat, &mapped); shell.toggle_sticky(&seat, &mapped);

View file

@ -22,7 +22,7 @@ impl WorkspaceHandler for State {
for request in requests.into_iter() { for request in requests.into_iter() {
match request { match request {
Request::Activate(handle) => { 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)| { let maybe = shell.workspaces.iter().find_map(|(o, set)| {
set.workspaces set.workspaces
.iter() .iter()
@ -41,7 +41,7 @@ impl WorkspaceHandler for State {
} }
} }
Request::SetTilingState { workspace, 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(); let seat = shell.seats.last_active().clone();
if let Some(workspace) = shell.workspaces.space_for_handle_mut(&workspace) { if let Some(workspace) = shell.workspaces.space_for_handle_mut(&workspace) {
let mut guard = self.common.workspace_state.update(); let mut guard = self.common.workspace_state.update();
@ -56,7 +56,7 @@ impl WorkspaceHandler for State {
} }
} }
Request::SetPin { workspace, pinned } => { 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) { if let Some(workspace) = shell.workspaces.space_for_handle_mut(&workspace) {
workspace.pinned = pinned; workspace.pinned = pinned;
let mut update = self.common.workspace_state.update(); let mut update = self.common.workspace_state.update();
@ -78,7 +78,7 @@ impl WorkspaceHandler for State {
if axis != 0 { if axis != 0 {
continue; continue;
} }
let mut shell = self.common.shell.write().unwrap(); let mut shell = self.common.shell.write();
let mut update = self.common.workspace_state.update(); let mut update = self.common.workspace_state.update();
shell.workspaces.move_workspace( shell.workspaces.move_workspace(
&workspace, &workspace,
@ -95,7 +95,7 @@ impl WorkspaceHandler for State {
if axis != 0 { if axis != 0 {
continue; continue;
} }
let mut shell = self.common.shell.write().unwrap(); let mut shell = self.common.shell.write();
let mut update = self.common.workspace_state.update(); let mut update = self.common.workspace_state.update();
shell.workspaces.move_workspace( shell.workspaces.move_workspace(
&workspace, &workspace,

View file

@ -43,7 +43,7 @@ impl XdgActivationHandler for State {
{ {
if let Some(seat) = data.serial.and_then(|(_, seat)| Seat::from_resource(&seat)) { if let Some(seat) = data.serial.and_then(|(_, seat)| Seat::from_resource(&seat)) {
let output = seat.active_output(); 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 workspace = shell.active_space_mut(&output).unwrap();
let handle = workspace.handle; let handle = workspace.handle;
data.user_data data.user_data
@ -86,7 +86,7 @@ impl XdgActivationHandler for State {
if valid { if valid {
let output = seat.active_output(); 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 workspace = shell.active_space_mut(&output).unwrap();
let handle = workspace.handle; let handle = workspace.handle;
data.user_data data.user_data
@ -107,7 +107,7 @@ impl XdgActivationHandler for State {
surface: WlSurface, surface: WlSurface,
) { ) {
if let Some(context) = token_data.user_data.get::<ActivationContext>() { if let Some(context) = token_data.user_data.get::<ActivationContext>() {
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() { if let Some(element) = shell.element_for_surface(&surface).cloned() {
match context { match context {
ActivationContext::UrgentOnly => { ActivationContext::UrgentOnly => {

View file

@ -45,7 +45,7 @@ impl XdgShellHandler for State {
} }
fn new_toplevel(&mut self, surface: ToplevelSurface) { 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 seat = shell.seats.last_active().clone();
let window = CosmicSurface::from(surface); let window = CosmicSurface::from(surface);
shell.pending_windows.push(PendingWindow { shell.pending_windows.push(PendingWindow {
@ -65,11 +65,7 @@ impl XdgShellHandler for State {
if surface.get_parent_surface().is_some() { if surface.get_parent_surface().is_some() {
// let other shells deal with their popups // let other shells deal with their popups
self.common self.common.shell.read().unconstrain_popup(&surface);
.shell
.read()
.unwrap()
.unconstrain_popup(&surface);
if surface.send_configure().is_ok() { if surface.send_configure().is_ok() {
self.common self.common
@ -83,14 +79,9 @@ impl XdgShellHandler for State {
fn grab(&mut self, surface: PopupSurface, seat: WlSeat, serial: Serial) { fn grab(&mut self, surface: PopupSurface, seat: WlSeat, serial: Serial) {
let seat = Seat::from_resource(&seat).unwrap(); let seat = Seat::from_resource(&seat).unwrap();
let kind = PopupKind::Xdg(surface); let kind = PopupKind::Xdg(surface);
let maybe_root = find_popup_root_surface(&kind).ok().and_then(|root| { let maybe_root = find_popup_root_surface(&kind)
self.common .ok()
.shell .and_then(|root| self.common.shell.read().element_for_surface(&root).cloned());
.read()
.unwrap()
.element_for_surface(&root)
.cloned()
});
if let Some(root) = maybe_root { if let Some(root) = maybe_root {
let target = root.into(); let target = root.into();
@ -149,11 +140,7 @@ impl XdgShellHandler for State {
state.positioner = positioner; state.positioner = positioner;
}); });
self.common self.common.shell.read().unconstrain_popup(&surface);
.shell
.read()
.unwrap()
.unconstrain_popup(&surface);
surface.send_repositioned(token); surface.send_repositioned(token);
if let Err(err) = surface.send_configure() { if let Err(err) = surface.send_configure() {
warn!( warn!(
@ -165,7 +152,7 @@ impl XdgShellHandler for State {
fn move_request(&mut self, surface: ToplevelSurface, seat: WlSeat, serial: Serial) { fn move_request(&mut self, surface: ToplevelSurface, seat: WlSeat, serial: Serial) {
let seat = Seat::from_resource(&seat).unwrap(); 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( if let Some((grab, focus)) = shell.move_request(
surface.wl_surface(), surface.wl_surface(),
&seat, &seat,
@ -195,7 +182,7 @@ impl XdgShellHandler for State {
edges: xdg_toplevel::ResizeEdge, edges: xdg_toplevel::ResizeEdge,
) { ) {
let seat = Seat::from_resource(&seat).unwrap(); 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( if let Some((grab, focus)) = shell.resize_request(
surface.wl_surface(), surface.wl_surface(),
&seat, &seat,
@ -216,7 +203,7 @@ impl XdgShellHandler for State {
} }
fn minimize_request(&mut self, surface: ToplevelSurface) { 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 let Some(mapped) = shell.element_for_surface(surface.wl_surface()).cloned() {
if !mapped.is_stack() if !mapped.is_stack()
|| mapped.active_window().wl_surface().as_deref() == Some(surface.wl_surface()) || 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) { 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() { if let Some(mapped) = shell.element_for_surface(surface.wl_surface()).cloned() {
let seat = shell.seats.last_active().clone(); let seat = shell.seats.last_active().clone();
shell.maximize_request(&mapped, &seat, true) shell.maximize_request(&mapped, &seat, true)
@ -241,7 +228,7 @@ impl XdgShellHandler for State {
} }
fn unmaximize_request(&mut self, surface: ToplevelSurface) { 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() { if let Some(mapped) = shell.element_for_surface(surface.wl_surface()).cloned() {
shell.unmaximize_request(&mapped); shell.unmaximize_request(&mapped);
} else if let Some(pending) = shell } else if let Some(pending) = shell
@ -254,7 +241,7 @@ impl XdgShellHandler for State {
} }
fn fullscreen_request(&mut self, surface: ToplevelSurface, output: Option<WlOutput>) { fn fullscreen_request(&mut self, surface: ToplevelSurface, output: Option<WlOutput>) {
let mut shell = self.common.shell.write().unwrap(); let mut shell = self.common.shell.write();
let seat = shell.seats.last_active().clone(); let seat = shell.seats.last_active().clone();
let Some(focused_output) = seat.focused_output() else { let Some(focused_output) = seat.focused_output() else {
return; return;
@ -373,7 +360,7 @@ impl XdgShellHandler for State {
} }
fn unfullscreen_request(&mut self, surface: ToplevelSurface) { 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(mapped) = shell.element_for_surface(surface.wl_surface()).cloned() {
if let Some(workspace) = shell.space_for_mut(&mapped) { if let Some(workspace) = shell.space_for_mut(&mapped) {
let (window, _) = mapped let (window, _) = mapped
@ -408,7 +395,7 @@ impl XdgShellHandler for State {
fn toplevel_destroyed(&mut self, surface: ToplevelSurface) { fn toplevel_destroyed(&mut self, surface: ToplevelSurface) {
let (output, clients) = { 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(); let seat = shell.seats.last_active().clone();
shell.unmap_surface( shell.unmap_surface(
surface.wl_surface(), surface.wl_surface(),
@ -457,7 +444,7 @@ impl XdgShellHandler for State {
.unwrap_or_default() .unwrap_or_default()
.loc; .loc;
let shell = self.common.shell.read().unwrap(); let shell = self.common.shell.read();
let res = shell.menu_request( let res = shell.menu_request(
surface.wl_surface(), surface.wl_surface(),
&seat, &seat,

View file

@ -12,7 +12,6 @@ impl XWaylandKeyboardGrabHandler for State {
.common .common
.shell .shell
.read() .read()
.unwrap()
.workspaces .workspaces
.spaces() .spaces()
.find_map(|x| x.element_for_surface(surface).cloned())?; .find_map(|x| x.element_for_surface(surface).cloned())?;

View file

@ -248,7 +248,6 @@ impl Common {
let keyboard = self let keyboard = self
.shell .shell
.read() .read()
.unwrap()
.seats .seats
.last_active() .last_active()
.get_keyboard() .get_keyboard()
@ -260,14 +259,7 @@ impl Common {
} }
fn has_x_pointer_focus(&self, xwmid: XwmId) -> bool { fn has_x_pointer_focus(&self, xwmid: XwmId) -> bool {
let pointer = self let pointer = self.shell.read().seats.last_active().get_pointer().unwrap();
.shell
.read()
.unwrap()
.seats
.last_active()
.get_pointer()
.unwrap();
if let Some(x_client) = self.xwayland_state.as_ref().and_then(|xstate| { if let Some(x_client) = self.xwayland_state.as_ref().and_then(|xstate| {
xstate xstate
@ -307,7 +299,7 @@ impl Common {
} }
pub fn xwayland_reset_eavesdropping(&mut self, serial: Serial) { 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 keyboard = seat.get_keyboard().unwrap();
let pointer = seat.get_pointer().unwrap(); let pointer = seat.get_pointer().unwrap();
@ -350,7 +342,6 @@ impl Common {
let keyboard = self let keyboard = self
.shell .shell
.read() .read()
.unwrap()
.seats .seats
.last_active() .last_active()
.get_keyboard() .get_keyboard()
@ -420,14 +411,7 @@ impl Common {
return; return;
} }
let pointer = self let pointer = self.shell.read().seats.last_active().get_pointer().unwrap();
.shell
.read()
.unwrap()
.seats
.last_active()
.get_pointer()
.unwrap();
if self.xwayland_state.as_ref().is_none_or(|xstate| { if self.xwayland_state.as_ref().is_none_or(|xstate| {
xstate xstate
@ -466,7 +450,7 @@ impl Common {
} }
pub fn update_x11_stacking_order(&mut self) { 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(); let active_output = shell.seats.last_active().active_output();
if let Some(xwm) = self if let Some(xwm) = self
.xwayland_state .xwayland_state
@ -560,7 +544,7 @@ impl Common {
let new_scale = match self.config.cosmic_conf.descale_xwayland { let new_scale = match self.config.cosmic_conf.descale_xwayland {
XwaylandDescaling::Disabled => 1., XwaylandDescaling::Disabled => 1.,
XwaylandDescaling::Enabled => { XwaylandDescaling::Enabled => {
let shell = self.shell.read().unwrap(); let shell = self.shell.read();
shell shell
.outputs() .outputs()
.map(|o| o.current_scale().integer_scale()) .map(|o| o.current_scale().integer_scale())
@ -568,7 +552,7 @@ impl Common {
.unwrap_or(1) as f64 .unwrap_or(1) as f64
} }
XwaylandDescaling::Fractional => { XwaylandDescaling::Fractional => {
let shell = self.shell.read().unwrap(); let shell = self.shell.read();
let val = let val =
if let Some(output) = shell.outputs().find(|o| o.config().xwayland_primary) { if let Some(output) = shell.outputs().find(|o| o.config().xwayland_primary) {
output.current_scale().fractional_scale().max(1f64) output.current_scale().fractional_scale().max(1f64)
@ -589,7 +573,6 @@ impl Common {
let geometries = self let geometries = self
.shell .shell
.read() .read()
.unwrap()
.mapped() .mapped()
.flat_map(|m| m.windows().map(|(s, _)| s)) .flat_map(|m| m.windows().map(|(s, _)| s))
.filter_map(|s| s.0.x11_surface().map(|x| (x.clone(), x.geometry()))) .filter_map(|s| s.0.x11_surface().map(|x| (x.clone(), x.geometry())))
@ -638,7 +621,7 @@ impl Common {
.set_client_scale(new_scale); .set_client_scale(new_scale);
// update wl/xdg_outputs // 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); 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",); 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(); let startup_id = window.startup_id();
if shell.element_for_surface(&window).is_some() { if shell.element_for_surface(&window).is_some() {
return; return;
@ -723,7 +706,7 @@ impl XwmHandler for State {
} }
fn map_window_notify(&mut self, _xwm: XwmId, surface: X11Surface) { 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 if let Some(window) = shell
.pending_windows .pending_windows
.iter() .iter()
@ -763,7 +746,7 @@ impl XwmHandler for State {
} }
fn mapped_override_redirect_window(&mut self, _xwm: XwmId, window: X11Surface) { 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 if shell
.override_redirect_windows .override_redirect_windows
.iter() .iter()
@ -775,7 +758,7 @@ impl XwmHandler for State {
} }
fn unmapped_window(&mut self, _xwm: XwmId, window: X11Surface) { 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() { if window.is_override_redirect() {
shell.override_redirect_windows.retain(|or| or != &window); shell.override_redirect_windows.retain(|or| or != &window);
} else { } else {
@ -812,7 +795,7 @@ impl XwmHandler for State {
_reorder: Option<Reorder>, _reorder: Option<Reorder>,
) { ) {
// We only allow floating X11 windows to resize themselves. Nothing else // 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 if let Some(mapped) = shell
.element_for_surface(&window) .element_for_surface(&window)
@ -880,7 +863,7 @@ impl XwmHandler for State {
above: Option<X11Window>, above: Option<X11Window>,
) { ) {
if window.is_override_redirect() { 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 { if let Some(id) = above {
let or_windows = &mut shell.override_redirect_windows; let or_windows = &mut shell.override_redirect_windows;
if let Some(own_pos) = or_windows.iter().position(|or| or == &window) { 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, resize_edge: smithay::xwayland::xwm::ResizeEdge,
) { ) {
if let Some(wl_surface) = window.wl_surface() { 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(); let seat = shell.seats.last_active().clone();
if let Some((grab, focus)) = shell.resize_request( if let Some((grab, focus)) = shell.resize_request(
&wl_surface, &wl_surface,
@ -946,7 +929,7 @@ impl XwmHandler for State {
fn move_request(&mut self, _xwm: XwmId, window: X11Surface, _button: u32) { fn move_request(&mut self, _xwm: XwmId, window: X11Surface, _button: u32) {
if let Some(wl_surface) = window.wl_surface() { 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(); let seat = shell.seats.last_active().clone();
if let Some((grab, focus)) = shell.move_request( if let Some((grab, focus)) = shell.move_request(
&wl_surface, &wl_surface,
@ -976,7 +959,7 @@ impl XwmHandler for State {
} }
fn maximize_request(&mut self, _xwm: XwmId, window: X11Surface) { 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() { if let Some(mapped) = shell.element_for_surface(&window).cloned() {
let seat = shell.seats.last_active().clone(); let seat = shell.seats.last_active().clone();
shell.maximize_request(&mapped, &seat, true); shell.maximize_request(&mapped, &seat, true);
@ -990,7 +973,7 @@ impl XwmHandler for State {
} }
fn unmaximize_request(&mut self, _xwm: XwmId, window: X11Surface) { 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() { if let Some(mapped) = shell.element_for_surface(&window).cloned() {
shell.unmaximize_request(&mapped); shell.unmaximize_request(&mapped);
} else if let Some(pending) = shell } else if let Some(pending) = shell
@ -1003,7 +986,7 @@ impl XwmHandler for State {
} }
fn minimize_request(&mut self, _xwm: XwmId, window: X11Surface) { 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 let Some(mapped) = shell.element_for_surface(&window).cloned() {
if !mapped.is_stack() || mapped.active_window().is_window(&window) { if !mapped.is_stack() || mapped.active_window().is_window(&window) {
shell.minimize_request(&mapped); shell.minimize_request(&mapped);
@ -1012,7 +995,7 @@ impl XwmHandler for State {
} }
fn unminimize_request(&mut self, _xwm: XwmId, window: X11Surface) { 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() { if let Some(mapped) = shell.element_for_surface(&window).cloned() {
let seat = shell.seats.last_active().clone(); let seat = shell.seats.last_active().clone();
shell.unminimize_request(&mapped, &seat); shell.unminimize_request(&mapped, &seat);
@ -1026,7 +1009,7 @@ impl XwmHandler for State {
} }
fn fullscreen_request(&mut self, _xwm: XwmId, window: X11Surface) { 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(); let seat = shell.seats.last_active().clone();
if let Some(mapped) = shell.element_for_surface(&window).cloned() { if let Some(mapped) = shell.element_for_surface(&window).cloned() {
if let Some((output, handle)) = shell if let Some((output, handle)) = shell
@ -1056,7 +1039,7 @@ impl XwmHandler for State {
} }
fn unfullscreen_request(&mut self, _xwm: XwmId, window: X11Surface) { 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(mapped) = shell.element_for_surface(&window).cloned() {
if let Some(workspace) = shell.space_for_mut(&mapped) { if let Some(workspace) = shell.space_for_mut(&mapped) {
let (window, _) = mapped let (window, _) = mapped
@ -1082,14 +1065,7 @@ impl XwmHandler for State {
mime_type: String, mime_type: String,
fd: OwnedFd, fd: OwnedFd,
) { ) {
let seat = self let seat = self.common.shell.read().seats.last_active().clone();
.common
.shell
.read()
.unwrap()
.seats
.last_active()
.clone();
match selection { match selection {
SelectionTarget::Clipboard => { SelectionTarget::Clipboard => {
if let Err(err) = request_data_device_client_selection(&seat, mime_type, fd) { 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<String>) { fn new_selection(&mut self, xwm: XwmId, selection: SelectionTarget, mime_types: Vec<String>) {
trace!(?selection, ?mime_types, "Got Selection from Xwayland",); trace!(?selection, ?mime_types, "Got Selection from Xwayland",);
let seat = self let seat = self.common.shell.read().seats.last_active().clone();
.common
.shell
.read()
.unwrap()
.seats
.last_active()
.clone();
match selection { match selection {
SelectionTarget::Clipboard => { SelectionTarget::Clipboard => {
set_data_device_selection(&self.common.display_handle, &seat, mime_types, xwm) 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) { 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() { for seat in shell.seats.iter() {
match selection { match selection {
SelectionTarget::Clipboard => { SelectionTarget::Clipboard => {