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",
"once_cell",
"ordered-float",
"parking_lot 0.12.3",
"png",
"profiling",
"rand 0.9.1",

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -240,7 +240,7 @@ impl IsAlive for KeyboardFocusTarget {
impl PointerTarget<State> for PointerFocusTarget {
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 {
for session in element.cursor_sessions() {
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) {
let toplevel = self.toplevel(&*data.common.shell.read().unwrap());
let toplevel = self.toplevel(&*data.common.shell.read());
if let Some(element) = toplevel {
for session in element.cursor_sessions() {
session.set_cursor_pos(Some(
@ -346,7 +346,7 @@ impl PointerTarget<State> for PointerFocusTarget {
}
}
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 {
for session in element.cursor_sessions() {
session.set_cursor_pos(None);

View file

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

View file

@ -522,7 +522,7 @@ impl PointerGrab<State> for MenuGrab {
let mut guard = self.elements.lock().unwrap();
let elements = &mut *guard;
let event_location = if let Some(output) = self.screen_space_relative.as_ref() {
if state.common.shell.read().unwrap().zoom_state().is_some() {
if state.common.shell.read().zoom_state().is_some() {
event
.location
.as_global()
@ -726,7 +726,7 @@ impl TouchGrab<State> for MenuGrab {
let mut guard = self.elements.lock().unwrap();
let elements = &mut *guard;
let event_location = if let Some(output) = self.screen_space_relative.as_ref() {
if data.common.shell.read().unwrap().zoom_state().is_some() {
if data.common.shell.read().zoom_state().is_some() {
event
.location
.as_global()

View file

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

View file

@ -227,7 +227,7 @@ impl ResizeForkGrab {
self.last_loc = location.as_global();
if let Some(output) = self.output.upgrade() {
let mut shell = data.common.shell.write().unwrap();
let mut shell = data.common.shell.write();
let Some(workspace) = shell.active_space_mut(&output) else {
return false;
};

View file

@ -39,7 +39,7 @@ impl KeyboardGrab<State> for SwapWindowGrab {
serial: Serial,
time: u32,
) {
if !matches!(&data.common.shell.read().unwrap().overview_mode.active_trigger(), Some(Trigger::KeyboardSwap(_, d)) if d == &self.desc)
if !matches!(&data.common.shell.read().overview_mode.active_trigger(), Some(Trigger::KeyboardSwap(_, d)) if d == &self.desc)
{
handle.unset_grab(self, data, serial, false);
return;

View file

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

View file

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

View file

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

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 {
*theme = new_theme;
let mut workspace_guard = state.common.workspace_state.update();
state.common.shell.write().unwrap().set_theme(
state.common.shell.write().set_theme(
theme.clone(),
&state.common.xdg_activation_state,
&mut workspace_guard,

View file

@ -12,7 +12,7 @@ impl A11yHandler for State {
}
fn request_screen_magnifier(&mut self, enabled: bool) {
let mut shell = self.common.shell.write().unwrap();
let mut shell = self.common.shell.write();
if shell
.zoom_state()

View file

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

View file

@ -114,14 +114,14 @@ pub fn unset_mode(mapped: &CosmicMapped, surface: &WlSurface) {
impl XdgDecorationHandler for State {
fn new_decoration(&mut self, toplevel: ToplevelSurface) {
let shell = self.common.shell.read().unwrap();
let shell = self.common.shell.read();
if let Some(mapped) = shell.element_for_surface(toplevel.wl_surface()) {
new_decoration(mapped, toplevel.wl_surface());
}
}
fn request_mode(&mut self, toplevel: ToplevelSurface, mode: XdgMode) {
let shell = self.common.shell.read().unwrap();
let shell = self.common.shell.read();
if let Some(mapped) = shell.element_for_surface(toplevel.wl_surface()) {
request_mode(mapped, toplevel.wl_surface(), mode);
} else {
@ -130,7 +130,7 @@ impl XdgDecorationHandler for State {
}
fn unset_mode(&mut self, toplevel: ToplevelSurface) {
let shell = self.common.shell.read().unwrap();
let shell = self.common.shell.read();
if let Some(mapped) = shell.element_for_surface(toplevel.wl_surface()) {
unset_mode(mapped, toplevel.wl_surface())
}
@ -143,7 +143,7 @@ impl KdeDecorationHandler for State {
}
fn new_decoration(&mut self, surface: &WlSurface, decoration: &OrgKdeKwinServerDecoration) {
let shell = self.common.shell.read().unwrap();
let shell = self.common.shell.read();
if let Some(mapped) = shell.element_for_surface(surface) {
let mode = new_decoration(mapped, surface);
decoration.mode(mode);
@ -157,7 +157,7 @@ impl KdeDecorationHandler for State {
mode: WEnum<KdeMode>,
) {
if let WEnum::Value(mode) = mode {
let shell = self.common.shell.read().unwrap();
let shell = self.common.shell.read();
// TODO: We need to store this value until it gets mapped and apply it then, if it is not mapped yet.
if let Some(mapped) = shell.element_for_surface(surface) {
request_mode(
@ -174,7 +174,7 @@ impl KdeDecorationHandler for State {
}
fn release(&mut self, _decoration: &OrgKdeKwinServerDecoration, surface: &WlSurface) {
let shell = self.common.shell.read().unwrap();
let shell = self.common.shell.read();
if let Some(mapped) = shell.element_for_surface(surface) {
unset_mode(mapped, surface)
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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