diff --git a/build.rs b/build.rs index 9a5d56f7..b1cfaa97 100644 --- a/build.rs +++ b/build.rs @@ -2,11 +2,7 @@ use std::process::Command; fn main() { - if let Some(output) = Command::new("git") - .args(&["rev-parse", "HEAD"]) - .output() - .ok() - { + if let Ok(output) = Command::new("git").args(["rev-parse", "HEAD"]).output() { let git_hash = String::from_utf8(output.stdout).unwrap(); println!("cargo:rustc-env=GIT_HASH={}", git_hash); } diff --git a/src/backend/kms/device.rs b/src/backend/kms/device.rs index be22b7f9..07a3c556 100644 --- a/src/backend/kms/device.rs +++ b/src/backend/kms/device.rs @@ -450,7 +450,7 @@ impl Device { let added = config .iter() - .filter(|(conn, maybe)| match (surfaces.get(&conn), maybe) { + .filter(|(conn, maybe)| match (surfaces.get(conn), maybe) { (Some(current_crtc), Some(new_crtc)) => current_crtc != new_crtc, (None, _) => true, _ => false, @@ -462,7 +462,7 @@ impl Device { .outputs .iter() .filter(|(conn, _)| match config.get(conn) { - Some(Some(c)) => surfaces.get(&conn).is_some_and(|crtc| c != crtc), + Some(Some(c)) => surfaces.get(conn).is_some_and(|crtc| c != crtc), _ => true, }) .map(|(conn, _)| *conn) @@ -485,7 +485,7 @@ impl Device { .outputs .get(&conn) .cloned() - .map(|output| Ok(output)) + .map(Ok) .unwrap_or_else(|| create_output_for_conn(&mut self.drm, conn)) .context("Failed to create `Output`")?; @@ -621,7 +621,7 @@ fn populate_modes( .iter() .find(|mode| mode.mode_type().contains(ModeTypeFlags::PREFERRED)) .copied() - .or(conn_info.modes().get(0).copied()) + .or(conn_info.modes().first().copied()) else { anyhow::bail!("No mode found"); }; diff --git a/src/backend/kms/drm_helpers.rs b/src/backend/kms/drm_helpers.rs index 0b7cdc3b..3a048488 100644 --- a/src/backend/kms/drm_helpers.rs +++ b/src/backend/kms/drm_helpers.rs @@ -85,7 +85,7 @@ pub fn display_configuration( .flat_map(|conn| device.get_connector(*conn, false).ok()) .filter(|conn| { if let Some(enc) = conn.current_encoder() { - if let Some(enc) = device.get_encoder(enc).ok() { + if let Ok(enc) = device.get_encoder(enc) { if let Some(crtc) = enc.crtc() { return cleanup.contains(&crtc); } diff --git a/src/backend/kms/mod.rs b/src/backend/kms/mod.rs index b1e54710..859d7d3c 100644 --- a/src/backend/kms/mod.rs +++ b/src/backend/kms/mod.rs @@ -181,7 +181,7 @@ fn init_libinput( .context("Failed to initialize libinput event source")?; // Create relative pointer global - RelativePointerManagerState::new::(&dh); + RelativePointerManagerState::new::(dh); Ok(libinput_context) } @@ -454,11 +454,9 @@ impl KmsState { device.egl = Some(egl); } used_devices.insert(device.render_node); - } else { - if device.egl.is_some() { - let _ = device.egl.take(); - self.api.as_mut().remove_node(&device.render_node); - } + } else if device.egl.is_some() { + let _ = device.egl.take(); + self.api.as_mut().remove_node(&device.render_node); } } @@ -749,10 +747,8 @@ impl KmsState { None }; - if !test_only { - if mirrored_output != surface.output.mirroring() { - surface.set_mirroring(mirrored_output.clone()); - } + if !test_only && mirrored_output != surface.output.mirroring() { + surface.set_mirroring(mirrored_output.clone()); } } } diff --git a/src/backend/kms/render/pixman.rs b/src/backend/kms/render/pixman.rs index 8e627289..00c1caef 100644 --- a/src/backend/kms/render/pixman.rs +++ b/src/backend/kms/render/pixman.rs @@ -42,6 +42,12 @@ impl fmt::Debug for GbmPixmanDevice { } } +impl Default for GbmPixmanBackend { + fn default() -> Self { + Self::new() + } +} + impl GbmPixmanBackend { pub fn new() -> Self { GbmPixmanBackend { diff --git a/src/backend/kms/surface/mod.rs b/src/backend/kms/surface/mod.rs index 2fe8ef05..8d7b63ef 100644 --- a/src/backend/kms/surface/mod.rs +++ b/src/backend/kms/surface/mod.rs @@ -196,15 +196,14 @@ pub type GbmDrmCompositor = DrmCompositor< DrmDeviceFd, >; -#[derive(Debug)] +#[derive(Debug, Default)] pub enum QueueState { + #[default] Idle, /// A redraw is queued. Queued(RegistrationToken), /// We submitted a frame to the KMS and waiting for it to be presented. - WaitingForVBlank { - redraw_needed: bool, - }, + WaitingForVBlank { redraw_needed: bool }, /// We did not submit anything to KMS and made a timer to fire at the estimated VBlank. WaitingForEstimatedVBlank(RegistrationToken), /// A redraw is queued on top of the above. @@ -214,12 +213,6 @@ pub enum QueueState { }, } -impl Default for QueueState { - fn default() -> Self { - QueueState::Idle - } -} - #[derive(Debug)] pub enum ThreadCommand { Suspend(SyncSender<()>), @@ -781,7 +774,7 @@ impl SurfaceThreadState { let now = self.clock.now(); let presentation_time = match metadata.as_ref().map(|data| &data.time) { - Some(DrmEventTime::Monotonic(tp)) => Some(tp.clone()), + Some(DrmEventTime::Monotonic(tp)) => Some(*tp), _ => None, }; let sequence = metadata.as_ref().map(|data| data.sequence).unwrap_or(0); @@ -912,7 +905,7 @@ impl SurfaceThreadState { warn!(?name, "Failed to submit rendering: {:?}", err); state.queue_redraw(true); } - return TimeoutAction::Drop; + TimeoutAction::Drop }) .expect("Failed to schedule render"); @@ -922,7 +915,7 @@ impl SurfaceThreadState { } QueueState::WaitingForEstimatedVBlank(estimated_vblank) => { self.state = QueueState::WaitingForEstimatedVBlankAndQueued { - estimated_vblank: estimated_vblank.clone(), + estimated_vblank: *estimated_vblank, queued_render: token, }; } @@ -936,7 +929,7 @@ impl SurfaceThreadState { } if force => { self.loop_handle.remove(*queued_render); self.state = QueueState::WaitingForEstimatedVBlankAndQueued { - estimated_vblank: estimated_vblank.clone(), + estimated_vblank: *estimated_vblank, queued_render: token, }; } @@ -953,7 +946,7 @@ impl SurfaceThreadState { self.mirroring.as_ref().unwrap_or(&self.output), &self.primary_node, &self.target_node, - &*self.shell.read().unwrap(), + &self.shell.read().unwrap(), ); let mut renderer = if render_node != self.target_node { @@ -966,17 +959,14 @@ impl SurfaceThreadState { self.timings.start_render(&self.clock); - let mut vrr = match self.vrr_mode { - AdaptiveSync::Force => true, - _ => false, - }; + let mut vrr = matches!(self.vrr_mode, AdaptiveSync::Force); let mut elements = { let shell = self.shell.read().unwrap(); let output = self.mirroring.as_ref().unwrap_or(&self.output); let (previous_workspace, workspace) = shell.workspaces.active(output); - let (previous_idx, idx) = shell.workspaces.active_num(&output); + let (previous_idx, idx) = shell.workspaces.active_num(output); let previous_workspace = previous_workspace .zip(previous_idx) .map(|((w, start), idx)| (w.handle, idx, start)); @@ -1497,7 +1487,7 @@ fn render_node_for_output( .flat_map(|w| w.wl_surface().and_then(|s| source_node_for_surface(&s))) .collect::>(); - if nodes.contains(&target_node) || nodes.is_empty() { + if nodes.contains(target_node) || nodes.is_empty() { *target_node } else { *primary_node diff --git a/src/backend/kms/surface/timings.rs b/src/backend/kms/surface/timings.rs index cfa237f5..d2955091 100644 --- a/src/backend/kms/surface/timings.rs +++ b/src/backend/kms/surface/timings.rs @@ -99,10 +99,7 @@ impl Timings { if let Some(frame) = self.pending_frame.as_mut() { frame.render_duration_draw = Some( Time::elapsed(&frame.render_start, clock.now()) - - frame - .render_duration_elements - .clone() - .unwrap_or(Duration::ZERO), + - frame.render_duration_elements.unwrap_or(Duration::ZERO), ); } } @@ -201,7 +198,7 @@ impl Timings { } let secs = match (self.previous_frames.front(), self.previous_frames.back()) { (Some(Frame { render_start, .. }), Some(end_frame)) => { - Time::elapsed(render_start, end_frame.render_start.clone()) + end_frame.frame_time() + Time::elapsed(render_start, end_frame.render_start) + end_frame.frame_time() } _ => Duration::ZERO, } diff --git a/src/backend/mod.rs b/src/backend/mod.rs index c4f3335f..36ccb952 100644 --- a/src/backend/mod.rs +++ b/src/backend/mod.rs @@ -73,7 +73,7 @@ pub fn init_backend_auto( .startup_done .store(true, std::sync::atomic::Ordering::SeqCst); for output in state.common.shell.read().unwrap().outputs() { - state.backend.schedule_render(&output); + state.backend.schedule_render(output); } } } diff --git a/src/backend/render/cursor.rs b/src/backend/render/cursor.rs index dc98ae4a..3e3c6afd 100644 --- a/src/backend/render/cursor.rs +++ b/src/backend/render/cursor.rs @@ -135,7 +135,7 @@ where { let position = location.into(); let scale = scale.into(); - let h = with_states(&surface, |states| { + let h = with_states(surface, |states| { states .data_map .get::>() @@ -174,7 +174,7 @@ where R: Renderer + ImportAll, ::TextureId: Clone + 'static, { - if get_role(&surface) != Some("dnd_icon") { + if get_role(surface) != Some("dnd_icon") { warn!( ?surface, "Trying to display as a dnd icon a surface that does not have the DndIcon role." @@ -322,7 +322,7 @@ where MemoryRenderBufferRenderElement::from_buffer( renderer, location.to_physical(scale), - &pointer_image, + pointer_image, None, None, None, diff --git a/src/backend/render/mod.rs b/src/backend/render/mod.rs index aa545068..849cbe5a 100644 --- a/src/backend/render/mod.rs +++ b/src/backend/render/mod.rs @@ -428,7 +428,7 @@ where elements.extend( cursor::draw_cursor( renderer, - &seat, + seat, location, scale.into(), now, @@ -446,7 +446,7 @@ where } if !exclude_dnd_icon { - if let Some(dnd_icon) = get_dnd_icon(&seat) { + if let Some(dnd_icon) = get_dnd_icon(seat) { elements.extend( cursor::draw_dnd_icon( renderer, @@ -616,218 +616,203 @@ where .to_physical_precise_round(scale); let crop_to_output = |element: WorkspaceRenderElement| { CropRenderElement::from_element( - element.into(), + element, scale, Rectangle::from_loc_and_size((0, 0), output_size), ) }; - render_input_order( - &*shell, - output, - previous, - current, - element_filter, - |stage| { - match stage { - Stage::SessionLock(lock_surface) => { - elements.extend( - session_lock_elements(renderer, output, lock_surface) - .into_iter() - .map(Into::into) - .flat_map(crop_to_output) - .map(Into::into), - ); - } - Stage::LayerPopup { - popup, location, .. - } => { - elements.extend( - render_elements_from_surface_tree::<_, WorkspaceRenderElement<_>>( - renderer, - popup.wl_surface(), - location - .to_local(output) - .as_logical() - .to_physical_precise_round(scale), - Scale::from(scale), - 1.0, - Kind::Unspecified, - ) + render_input_order(&shell, output, previous, current, element_filter, |stage| { + match stage { + Stage::SessionLock(lock_surface) => { + elements.extend( + session_lock_elements(renderer, output, lock_surface) .into_iter() + .map(Into::into) .flat_map(crop_to_output) .map(Into::into), - ); - } - Stage::LayerSurface { layer, location } => { - elements.extend( - render_elements_from_surface_tree::<_, WorkspaceRenderElement<_>>( - renderer, - &layer.wl_surface(), - location - .to_local(output) - .as_logical() - .to_physical_precise_round(scale), - Scale::from(scale), - 1.0, - Kind::Unspecified, - ) + ); + } + Stage::LayerPopup { + popup, location, .. + } => { + elements.extend( + render_elements_from_surface_tree::<_, WorkspaceRenderElement<_>>( + renderer, + popup.wl_surface(), + location + .to_local(output) + .as_logical() + .to_physical_precise_round(scale), + Scale::from(scale), + 1.0, + Kind::Unspecified, + ) + .into_iter() + .flat_map(crop_to_output) + .map(Into::into), + ); + } + Stage::LayerSurface { layer, location } => { + elements.extend( + render_elements_from_surface_tree::<_, WorkspaceRenderElement<_>>( + renderer, + layer.wl_surface(), + location + .to_local(output) + .as_logical() + .to_physical_precise_round(scale), + Scale::from(scale), + 1.0, + Kind::Unspecified, + ) + .into_iter() + .flat_map(crop_to_output) + .map(Into::into), + ); + } + Stage::OverrideRedirect { surface, location } => { + elements.extend( + AsRenderElements::::render_elements::>( + surface, + renderer, + location + .to_local(output) + .as_logical() + .to_physical_precise_round(scale), + Scale::from(scale), + 1.0, + ) + .into_iter() + .flat_map(crop_to_output) + .map(Into::into), + ); + } + Stage::StickyPopups(layout) => { + let alpha = match &overview.0 { + OverviewMode::Started(_, started) => { + (1.0 - (Instant::now().duration_since(*started).as_millis() + / ANIMATION_DURATION.as_millis()) as f32) + .max(0.0) + * 0.4 + + 0.6 + } + OverviewMode::Ended(_, ended) => { + ((Instant::now().duration_since(*ended).as_millis() + / ANIMATION_DURATION.as_millis()) as f32) + * 0.4 + + 0.6 + } + OverviewMode::Active(_) => 0.6, + OverviewMode::None => 1.0, + }; + + elements.extend( + layout + .render_popups(renderer, alpha) .into_iter() + .map(Into::into) .flat_map(crop_to_output) .map(Into::into), - ); - } - Stage::OverrideRedirect { surface, location } => { - elements.extend( - AsRenderElements::::render_elements::>( - surface, + ); + } + Stage::Sticky(layout) => { + let alpha = match &overview.0 { + OverviewMode::Started(_, started) => { + (1.0 - (Instant::now().duration_since(*started).as_millis() + / ANIMATION_DURATION.as_millis()) as f32) + .max(0.0) + * 0.4 + + 0.6 + } + OverviewMode::Ended(_, ended) => { + ((Instant::now().duration_since(*ended).as_millis() + / ANIMATION_DURATION.as_millis()) as f32) + * 0.4 + + 0.6 + } + OverviewMode::Active(_) => 0.6, + OverviewMode::None => 1.0, + }; + + let current_focus = (!move_active && is_active_space) + .then_some(last_active_seat) + .map(|seat| workspace.focus_stack.get(seat)); + + elements.extend( + layout + .render( renderer, - location - .to_local(output) - .as_logical() - .to_physical_precise_round(scale), - Scale::from(scale), - 1.0, + current_focus.as_ref().and_then(|stack| stack.last()), + resize_indicator.clone(), + active_hint, + alpha, + theme.cosmic(), ) .into_iter() + .map(Into::into) .flat_map(crop_to_output) .map(Into::into), - ); - } - Stage::StickyPopups(layout) => { - let alpha = match &overview.0 { - OverviewMode::Started(_, started) => { - (1.0 - (Instant::now().duration_since(*started).as_millis() - / ANIMATION_DURATION.as_millis()) - as f32) - .max(0.0) - * 0.4 - + 0.6 + ) + } + Stage::WorkspacePopups { workspace, offset } => { + elements.extend( + match workspace.render_popups( + renderer, + (!move_active && is_active_space).then_some(last_active_seat), + overview.clone(), + theme.cosmic(), + ) { + Ok(elements) => { + elements + .into_iter() + .flat_map(crop_to_output) + .map(|element| { + CosmicElement::Workspace(RelocateRenderElement::from_element( + element, + offset.to_physical_precise_round(scale), + Relocate::Relative, + )) + }) } - OverviewMode::Ended(_, ended) => { - ((Instant::now().duration_since(*ended).as_millis() - / ANIMATION_DURATION.as_millis()) - as f32) - * 0.4 - + 0.6 + Err(_) => { + return ControlFlow::Break(Err(OutputNoMode)); } - OverviewMode::Active(_) => 0.6, - OverviewMode::None => 1.0, - }; - - elements.extend( - layout - .render_popups(renderer, alpha) - .into_iter() - .map(Into::into) - .flat_map(crop_to_output) - .map(Into::into), - ); - } - Stage::Sticky(layout) => { - let alpha = match &overview.0 { - OverviewMode::Started(_, started) => { - (1.0 - (Instant::now().duration_since(*started).as_millis() - / ANIMATION_DURATION.as_millis()) - as f32) - .max(0.0) - * 0.4 - + 0.6 + }, + ); + } + Stage::Workspace { workspace, offset } => { + elements.extend( + match workspace.render( + renderer, + (!move_active && is_active_space).then_some(last_active_seat), + overview.clone(), + resize_indicator.clone(), + active_hint, + theme.cosmic(), + ) { + Ok(elements) => { + elements + .into_iter() + .flat_map(crop_to_output) + .map(|element| { + CosmicElement::Workspace(RelocateRenderElement::from_element( + element, + offset.to_physical_precise_round(scale), + Relocate::Relative, + )) + }) } - OverviewMode::Ended(_, ended) => { - ((Instant::now().duration_since(*ended).as_millis() - / ANIMATION_DURATION.as_millis()) - as f32) - * 0.4 - + 0.6 + Err(_) => { + return ControlFlow::Break(Err(OutputNoMode)); } - OverviewMode::Active(_) => 0.6, - OverviewMode::None => 1.0, - }; - - let current_focus = (!move_active && is_active_space) - .then_some(last_active_seat) - .map(|seat| workspace.focus_stack.get(seat)); - - elements.extend( - layout - .render( - renderer, - current_focus.as_ref().and_then(|stack| stack.last()), - resize_indicator.clone(), - active_hint, - alpha, - &theme.cosmic(), - ) - .into_iter() - .map(Into::into) - .flat_map(crop_to_output) - .map(Into::into), - ) - } - Stage::WorkspacePopups { workspace, offset } => { - elements.extend( - match workspace.render_popups( - renderer, - (!move_active && is_active_space).then_some(last_active_seat), - overview.clone(), - &theme.cosmic(), - ) { - Ok(elements) => { - elements - .into_iter() - .flat_map(crop_to_output) - .map(|element| { - CosmicElement::Workspace( - RelocateRenderElement::from_element( - element, - offset.to_physical_precise_round(scale), - Relocate::Relative, - ), - ) - }) - } - Err(_) => { - return ControlFlow::Break(Err(OutputNoMode)); - } - }, - ); - } - Stage::Workspace { workspace, offset } => { - elements.extend( - match workspace.render( - renderer, - (!move_active && is_active_space).then_some(last_active_seat), - overview.clone(), - resize_indicator.clone(), - active_hint, - &theme.cosmic(), - ) { - Ok(elements) => { - elements - .into_iter() - .flat_map(crop_to_output) - .map(|element| { - CosmicElement::Workspace( - RelocateRenderElement::from_element( - element, - offset.to_physical_precise_round(scale), - Relocate::Relative, - ), - ) - }) - } - Err(_) => { - return ControlFlow::Break(Err(OutputNoMode)); - } - }, - ); - } - }; + }, + ); + } + }; - ControlFlow::Continue(()) - }, - )?; + ControlFlow::Continue(()) + })?; Ok(elements) } @@ -921,7 +906,7 @@ where for (session, frame) in output.take_pending_frames() { if let Some((frame, damage)) = render_session( renderer, - &session.user_data().get::().unwrap(), + session.user_data().get::().unwrap(), frame, output.current_transform(), |buffer, renderer, dt, age, additional_damage| { @@ -966,7 +951,7 @@ where elements.truncate(old_len); } - if let (Some(ref damage), _) = &res { + if let (Some(damage), _) = &res { if let Ok(dmabuf) = get_dmabuf(buffer) { renderer .bind(dmabuf.clone()) @@ -1056,7 +1041,7 @@ where )?; if let Some(additional_damage) = additional_damage { - let output_geo = output.geometry().to_local(&output).as_logical(); + let output_geo = output.geometry().to_local(output).as_logical(); elements.extend( additional_damage .into_iter() diff --git a/src/backend/winit.rs b/src/backend/winit.rs index a1a2bdce..83191f4f 100644 --- a/src/backend/winit.rs +++ b/src/backend/winit.rs @@ -138,7 +138,7 @@ pub fn init_backend( init_egl_client_side(dh, state, &mut backend)?; - let name = format!("WINIT-0"); + let name = "WINIT-0".to_string(); let size = backend.window_size(); let props = PhysicalProperties { size: (0, 0).into(), @@ -162,7 +162,7 @@ pub fn init_backend( output.user_data().insert_if_missing(|| { RefCell::new(OutputConfig { mode: ((size.w, size.h), None), - transform: Transform::Flipped180.into(), + transform: Transform::Flipped180, ..Default::default() }) }); diff --git a/src/backend/x11.rs b/src/backend/x11.rs index ba33c14b..4ce7f2ee 100644 --- a/src/backend/x11.rs +++ b/src/backend/x11.rs @@ -494,29 +494,26 @@ where impl State { pub fn process_x11_event(&mut self, event: InputEvent) { // here we can handle special cases for x11 inputs, like mapping them to windows - match &event { - InputEvent::PointerMotionAbsolute { event } => { - if let Some(window) = event.window() { - let output = self - .backend - .x11() - .surfaces - .iter() - .find(|surface| &surface.window == window.as_ref()) - .map(|surface| surface.output.clone()) - .unwrap(); - - let device = event.device(); - for seat in self.common.shell.read().unwrap().seats.iter() { - let devices = seat.user_data().get::().unwrap(); - if devices.has_device(&device) { - seat.set_active_output(&output); - break; - } + if let InputEvent::PointerMotionAbsolute { event } = &event { + if let Some(window) = event.window() { + let output = self + .backend + .x11() + .surfaces + .iter() + .find(|surface| &surface.window == window.as_ref()) + .map(|surface| surface.output.clone()) + .unwrap(); + + let device = event.device(); + for seat in self.common.shell.read().unwrap().seats.iter() { + let devices = seat.user_data().get::().unwrap(); + if devices.has_device(&device) { + seat.set_active_output(&output); + break; } } } - _ => {} }; self.process_input_event(event); diff --git a/src/config/input_config.rs b/src/config/input_config.rs index 6371a23b..37ecf9d3 100644 --- a/src/config/input_config.rs +++ b/src/config/input_config.rs @@ -92,10 +92,8 @@ pub fn get_config<'a, T: 'a, F: Fn(&'a InputConfig) -> Option>( ) -> Option<(T, bool)> { if let Some(setting) = device_config.and_then(&f) { Some((setting, false)) - } else if let Some(setting) = f(default_config) { - Some((setting, true)) } else { - None + f(default_config).map(|setting| (setting, true)) } } diff --git a/src/config/mod.rs b/src/config/mod.rs index f8bd9a2f..1e20849d 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -518,7 +518,7 @@ impl Config { ) }) .collect::>(); - infos.sort_by(|&(ref a, _), &(ref b, _)| a.cmp(b)); + infos.sort_by(|(a, _), (b, _)| a.cmp(b)); let (infos, configs) = infos.into_iter().unzip(); self.dynamic_conf .outputs_mut() @@ -569,13 +569,13 @@ pub struct PersistenceGuard<'a, T: Serialize>(Option, &'a mut T); impl<'a, T: Serialize> std::ops::Deref for PersistenceGuard<'a, T> { type Target = T; fn deref(&self) -> &T { - &self.1 + self.1 } } impl<'a, T: Serialize> std::ops::DerefMut for PersistenceGuard<'a, T> { fn deref_mut(&mut self) -> &mut T { - &mut self.1 + self.1 } } diff --git a/src/dbus/mod.rs b/src/dbus/mod.rs index 13b2bcc5..6ae2e84c 100644 --- a/src/dbus/mod.rs +++ b/src/dbus/mod.rs @@ -27,7 +27,6 @@ pub fn init(evlh: &LoopHandle<'static, State>) -> Result> tracing::error!(?err, "Failed to update drm device {}.", node); } } - () } calloop::channel::Event::Closed => (), }) @@ -38,8 +37,8 @@ pub fn init(evlh: &LoopHandle<'static, State>) -> Result> let result = std::thread::Builder::new() .name("system76-power-hotplug".to_string()) .spawn(move || { - if let Ok(mut msg_iter) = power_daemon.receive_hot_plug_detect() { - while let Some(msg) = msg_iter.next() { + if let Ok(msg_iter) = power_daemon.receive_hot_plug_detect() { + for msg in msg_iter { if tx.send(msg).is_err() { break; } @@ -81,7 +80,7 @@ pub fn ready(common: &Common) -> Result<()> { .xwayland_state .as_ref() .map(|s| format!(":{}", s.display)) - .unwrap_or(String::new()), + .unwrap_or_default(), ), ]))?; diff --git a/src/input/actions.rs b/src/input/actions.rs index a85cf8a0..b71eb003 100644 --- a/src/input/actions.rs +++ b/src/input/actions.rs @@ -98,16 +98,16 @@ impl State { match action { SwipeAction::NextWorkspace => { let _ = to_next_workspace( - &mut *self.common.shell.write().unwrap(), - &seat, + &mut self.common.shell.write().unwrap(), + seat, true, &mut self.common.workspace_state.update(), ); } SwipeAction::PrevWorkspace => { let _ = to_previous_workspace( - &mut *self.common.shell.write().unwrap(), - &seat, + &mut self.common.shell.write().unwrap(), + seat, true, &mut self.common.workspace_state.update(), ); @@ -184,7 +184,7 @@ impl State { Action::NextWorkspace => { let next = to_next_workspace( - &mut *self.common.shell.write().unwrap(), + &mut self.common.shell.write().unwrap(), seat, false, &mut self.common.workspace_state.update(), @@ -206,7 +206,7 @@ impl State { Action::PreviousWorkspace => { let previous = to_previous_workspace( - &mut *self.common.shell.write().unwrap(), + &mut self.common.shell.write().unwrap(), seat, false, &mut self.common.workspace_state.update(), @@ -410,7 +410,7 @@ impl State { .active(&next_output) .1 .focus_stack - .get(&seat) + .get(seat) .last() .cloned() .map(KeyboardFocusTarget::from); @@ -478,8 +478,7 @@ impl State { let next_output = shell .outputs() .skip_while(|o| *o != ¤t_output) - .skip(1) - .next() + .nth(1) .cloned(); if let Some(next_output) = next_output { let idx = shell.workspaces.active_num(&next_output).1; @@ -497,7 +496,7 @@ impl State { .active(&next_output) .1 .focus_stack - .get(&seat) + .get(seat) .last() .cloned() .map(KeyboardFocusTarget::from); @@ -537,8 +536,7 @@ impl State { .outputs() .rev() .skip_while(|o| *o != ¤t_output) - .skip(1) - .next() + .nth(1) .cloned(); if let Some(prev_output) = prev_output { let idx = shell.workspaces.active_num(&prev_output).1; @@ -556,7 +554,7 @@ impl State { .active(&prev_output) .1 .focus_stack - .get(&seat) + .get(seat) .last() .cloned() .map(KeyboardFocusTarget::from); @@ -670,8 +668,7 @@ impl State { let next_output = shell .outputs() .skip_while(|o| *o != &focused_output) - .skip(1) - .next() + .nth(1) .cloned(); if let Some(next_output) = next_output { let res = shell.move_current_window( @@ -717,8 +714,7 @@ impl State { .outputs() .rev() .skip_while(|o| *o != &focused_output) - .skip(1) - .next() + .nth(1) .cloned(); if let Some(prev_output) = prev_output { let res = shell.move_current_window( @@ -761,8 +757,7 @@ impl State { let output = shell .outputs() .skip_while(|o| *o != &active_output) - .skip(1) - .next() + .nth(1) .cloned(); (shell.active_space(&active_output).handle, output) @@ -781,8 +776,7 @@ impl State { .outputs() .rev() .skip_while(|o| *o != &active_output) - .skip(1) - .next() + .nth(1) .cloned(); (shell.active_space(&active_output).handle, output) @@ -941,7 +935,7 @@ impl State { let output = seat.active_output(); let mut shell = self.common.shell.write().unwrap(); let workspace = shell.active_space_mut(&output); - workspace.tiling_layer.update_orientation(None, &seat); + workspace.tiling_layer.update_orientation(None, seat); } Action::Orientation(orientation) => { @@ -950,7 +944,7 @@ impl State { let workspace = shell.active_space_mut(&output); workspace .tiling_layer - .update_orientation(Some(orientation), &seat); + .update_orientation(Some(orientation), seat); } Action::ToggleStacking => { @@ -1059,7 +1053,12 @@ impl State { .env("XDG_ACTIVATION_TOKEN", &*token) .env("DESKTOP_STARTUP_ID", &*token) .env_remove("COSMIC_SESSION_SOCK"); - unsafe { cmd.pre_exec(|| Ok(crate::utils::rlimit::restore_nofile_limit())) }; + unsafe { + cmd.pre_exec(|| { + crate::utils::rlimit::restore_nofile_limit(); + Ok(()) + }) + }; std::thread::spawn(move || match cmd.spawn() { Ok(mut child) => { diff --git a/src/input/gestures/mod.rs b/src/input/gestures/mod.rs index 996d19cf..c0aee70f 100644 --- a/src/input/gestures/mod.rs +++ b/src/input/gestures/mod.rs @@ -50,12 +50,10 @@ impl GestureState { } else { Some(Direction::Left) } + } else if movement.y > 0.0 { + Some(Direction::Down) } else { - if movement.y > 0.0 { - Some(Direction::Down) - } else { - Some(Direction::Up) - } + Some(Direction::Up) } } diff --git a/src/input/mod.rs b/src/input/mod.rs index 8b40908e..06fb1723 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -120,8 +120,7 @@ impl SupressedKeys { Some( removed .into_iter() - .map(|(_, token)| token) - .flatten() + .filter_map(|(_, token)| token) .collect::>(), ) } @@ -246,14 +245,14 @@ impl State { InputEvent::PointerMotion { event, .. } => { use smithay::backend::input::PointerMotionEvent; - let mut shell = self.common.shell.write().unwrap(); + let shell = self.common.shell.write().unwrap(); 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(); let mut position = seat.get_pointer().unwrap().current_location().as_global(); - let under = State::surface_under(position, ¤t_output, &mut *shell) + let under = State::surface_under(position, ¤t_output, &shell) .map(|(target, pos)| (target, pos.as_logical())); let ptr = seat.get_pointer().unwrap(); @@ -297,7 +296,7 @@ impl State { .cloned() .unwrap_or(current_output.clone()); - let new_under = State::surface_under(position, &output, &mut *shell) + let new_under = State::surface_under(position, &output, &shell) .map(|(target, pos)| (target, pos.as_logical())); std::mem::drop(shell); @@ -322,18 +321,17 @@ impl State { .get::() .map(|marker| marker.get()) .unwrap_or(false) + && output != current_output { - if output != current_output { - ptr.frame(self); - return; - } + ptr.frame(self); + return; } //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 old_keyboard_target = - State::element_under(original_position, ¤t_output, &*shell); - let new_keyboard_target = State::element_under(position, &output, &*shell); + State::element_under(original_position, ¤t_output, &shell); + let new_keyboard_target = State::element_under(position, &output, &shell); if old_keyboard_target != new_keyboard_target && new_keyboard_target.is_some() @@ -503,7 +501,7 @@ impl State { shell.update_pointer_position(position.to_local(&output), &output); if output != current_output { - for session in cursor_sessions_for_output(&*shell, ¤t_output) { + for session in cursor_sessions_for_output(&shell, ¤t_output) { session.set_cursor_pos(None); } seat.set_active_output(&output); @@ -558,7 +556,7 @@ impl State { let under = State::surface_under( position, &output, - &mut *self.common.shell.write().unwrap(), + &self.common.shell.write().unwrap(), ) .map(|(target, pos)| (target, pos.as_logical())); @@ -575,7 +573,7 @@ impl State { ptr.frame(self); let shell = self.common.shell.read().unwrap(); - 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( position.as_logical().to_buffer( output.current_scale().fractional_scale(), @@ -1133,18 +1131,18 @@ impl State { } InputEvent::TouchDown { event, .. } => { - let mut shell = self.common.shell.write().unwrap(); + let shell = self.common.shell.write().unwrap(); if let Some(seat) = shell.seats.for_device(&event.device()).cloned() { self.common.idle_notifier_state.notify_activity(&seat); let Some(output) = - mapped_output_for_device(&self.common.config, &*shell, &event.device()) + mapped_output_for_device(&self.common.config, &shell, &event.device()) .cloned() else { return; }; let position = transform_output_mapped_position(&output, &event); - let under = State::surface_under(position, &output, &mut *shell) + let under = State::surface_under(position, &output, &shell) .map(|(target, pos)| (target, pos.as_logical())); std::mem::drop(shell); @@ -1164,18 +1162,18 @@ impl State { } } InputEvent::TouchMotion { event, .. } => { - let mut shell = self.common.shell.write().unwrap(); + let shell = self.common.shell.write().unwrap(); if let Some(seat) = shell.seats.for_device(&event.device()).cloned() { self.common.idle_notifier_state.notify_activity(&seat); let Some(output) = - mapped_output_for_device(&self.common.config, &*shell, &event.device()) + mapped_output_for_device(&self.common.config, &shell, &event.device()) .cloned() else { return; }; let position = transform_output_mapped_position(&output, &event); - let under = State::surface_under(position, &output, &mut *shell) + let under = State::surface_under(position, &output, &shell) .map(|(target, pos)| (target, pos.as_logical())); std::mem::drop(shell); @@ -1248,7 +1246,7 @@ impl State { } InputEvent::TabletToolAxis { event, .. } => { - let mut shell = self.common.shell.write().unwrap(); + let shell = self.common.shell.write().unwrap(); if let Some(seat) = shell.seats.for_device(&event.device()).cloned() { self.common.idle_notifier_state.notify_activity(&seat); let Some(output) = @@ -1259,7 +1257,7 @@ impl State { }; let position = transform_output_mapped_position(&output, &event); - let under = State::surface_under(position, &output, &mut *shell) + let under = State::surface_under(position, &output, &shell) .map(|(target, pos)| (target, pos.as_logical())); std::mem::drop(shell); @@ -1312,7 +1310,7 @@ impl State { } } InputEvent::TabletToolProximity { event, .. } => { - let mut shell = self.common.shell.write().unwrap(); + let shell = self.common.shell.write().unwrap(); if let Some(seat) = shell.seats.for_device(&event.device()).cloned() { self.common.idle_notifier_state.notify_activity(&seat); let Some(output) = @@ -1323,7 +1321,7 @@ impl State { }; let position = transform_output_mapped_position(&output, &event); - let under = State::surface_under(position, &output, &mut *shell) + let under = State::surface_under(position, &output, &shell) .map(|(target, pos)| (target, pos.as_logical())); std::mem::drop(shell); @@ -1442,12 +1440,9 @@ impl State { .unwrap_or(false) }); - self.common.atspi_ei.input( - modifiers, - &handle, - event.state(), - event.time() as u64 * 1000, - ); + self.common + .atspi_ei + .input(modifiers, &handle, event.state(), event.time() * 1000); // Leave move overview mode, if any modifier was released if let Some(Trigger::KeyboardMove(action_modifiers)) = @@ -1498,7 +1493,7 @@ impl State { ); } else if !cosmic_modifiers_eq_smithay(&action_pattern.modifiers, modifiers) { let mut new_pattern = action_pattern.clone(); - new_pattern.modifiers = cosmic_modifiers_from_smithay(modifiers.clone()); + new_pattern.modifiers = cosmic_modifiers_from_smithay(*modifiers); let enabled = self.common .config @@ -1544,7 +1539,7 @@ impl State { cosmic_keystate_from_smithay(event.state()), )); let key_pattern = shortcuts::Binding { - modifiers: cosmic_modifiers_from_smithay(modifiers.clone()), + modifiers: cosmic_modifiers_from_smithay(*modifiers), key: Some(handle.modified_sym()), description: None, }; @@ -1617,28 +1612,29 @@ impl State { .active_virtual_mods .remove(&event.key_code()); // If `Caps_Lock` is a virtual modifier, and is in locked state, clear it - if removed && handle.modified_sym() == Keysym::Caps_Lock { - if (modifiers.serialized.locked & 2) != 0 { - let serial = SERIAL_COUNTER.next_serial(); - let time = self.common.clock.now().as_millis(); - keyboard.input( - self, - event.key_code(), - KeyState::Pressed, - serial, - time, - |_, _, _| FilterResult::<()>::Forward, - ); - let serial = SERIAL_COUNTER.next_serial(); - keyboard.input( - self, - event.key_code(), - KeyState::Released, - serial, - time, - |_, _, _| FilterResult::<()>::Forward, - ); - } + if removed + && handle.modified_sym() == Keysym::Caps_Lock + && (modifiers.serialized.locked & 2) != 0 + { + let serial = SERIAL_COUNTER.next_serial(); + let time = self.common.clock.now().as_millis(); + keyboard.input( + self, + event.key_code(), + KeyState::Pressed, + serial, + time, + |_, _, _| FilterResult::<()>::Forward, + ); + let serial = SERIAL_COUNTER.next_serial(); + keyboard.input( + self, + event.key_code(), + KeyState::Released, + serial, + time, + |_, _, _| FilterResult::<()>::Forward, + ); } } else if event.state() == KeyState::Pressed && self @@ -1759,8 +1755,7 @@ impl State { focused_output: &Output, ) { if let Some(focus) = current_focus { - if let Some(new_descriptor) = - shell.workspaces.active(&focused_output).1.node_desc(focus) + if let Some(new_descriptor) = shell.workspaces.active(focused_output).1.node_desc(focus) { let mut spaces = shell.workspaces.spaces_mut(); if old_descriptor.handle != new_descriptor.handle { @@ -1772,7 +1767,7 @@ impl State { .find(|w| w.handle == new_descriptor.handle) { { - let mut stack = new_workspace.focus_stack.get_mut(&seat); + let mut stack = new_workspace.focus_stack.get_mut(seat); for elem in old_descriptor.focus_stack.iter().flat_map(|node_id| { old_workspace.tiling_layer.element_for_node(node_id) }) { @@ -1780,7 +1775,7 @@ impl State { } } { - let mut stack = old_workspace.focus_stack.get_mut(&seat); + let mut stack = old_workspace.focus_stack.get_mut(seat); for elem in new_descriptor.focus_stack.iter().flat_map(|node_id| { new_workspace.tiling_layer.element_for_node(node_id) }) { @@ -1790,7 +1785,7 @@ impl State { if let Some(focus) = TilingLayout::swap_trees( &mut old_workspace.tiling_layer, Some(&mut new_workspace.tiling_layer), - &old_descriptor, + old_descriptor, &new_descriptor, ) { let seat = seat.clone(); @@ -1802,26 +1797,24 @@ impl State { new_workspace.refresh_focus_stack(); } } - } else { - if let Some(workspace) = spaces.find(|w| w.handle == new_descriptor.handle) { - if let Some(focus) = TilingLayout::swap_trees( - &mut workspace.tiling_layer, - None, - &old_descriptor, - &new_descriptor, - ) { - std::mem::drop(spaces); - let seat = seat.clone(); - self.common.event_loop_handle.insert_idle(move |state| { - Shell::set_focus(state, Some(&focus), &seat, None, true); - }); - } - workspace.refresh_focus_stack(); + } else if let Some(workspace) = spaces.find(|w| w.handle == new_descriptor.handle) { + if let Some(focus) = TilingLayout::swap_trees( + &mut workspace.tiling_layer, + None, + old_descriptor, + &new_descriptor, + ) { + std::mem::drop(spaces); + let seat = seat.clone(); + self.common.event_loop_handle.insert_idle(move |state| { + Shell::set_focus(state, Some(&focus), &seat, None, true); + }); } + workspace.refresh_focus_stack(); } } } else { - let new_workspace = shell.workspaces.active(&focused_output).1.handle; + let new_workspace = shell.workspaces.active(focused_output).1.handle; if new_workspace != old_descriptor.handle { let spaces = shell.workspaces.spaces_mut(); let (mut old_w, mut other_w) = @@ -1832,7 +1825,7 @@ impl State { { if new_workspace.tiling_layer.windows().next().is_none() { { - let mut stack = new_workspace.focus_stack.get_mut(&seat); + let mut stack = new_workspace.focus_stack.get_mut(seat); for elem in old_descriptor.focus_stack.iter().flat_map(|node_id| { old_workspace.tiling_layer.element_for_node(node_id) }) { @@ -1843,8 +1836,8 @@ impl State { &mut old_workspace.tiling_layer, &mut new_workspace.tiling_layer, &new_workspace.handle, - &seat, - new_workspace.focus_stack.get(&seat).iter(), + seat, + new_workspace.focus_stack.get(seat).iter(), old_descriptor.clone(), None, ) { @@ -1913,19 +1906,18 @@ impl State { } } Stage::LayerSurface { layer, location } => { - if layer.can_receive_keyboard_focus() { - if under_from_surface_tree( + if layer.can_receive_keyboard_focus() + && under_from_surface_tree( layer.wl_surface(), global_pos.as_logical(), location.as_logical(), WindowSurfaceType::TOPLEVEL | WindowSurfaceType::SUBSURFACE, ) .is_some() - { - return ControlFlow::Break(Ok(Some( - KeyboardFocusTarget::LayerSurface(layer), - ))); - } + { + return ControlFlow::Break(Ok(Some( + KeyboardFocusTarget::LayerSurface(layer), + ))); } } Stage::OverrideRedirect { .. } => { @@ -2125,7 +2117,7 @@ fn cursor_sessions_for_output( shell: &Shell, output: &Output, ) -> impl Iterator { - let workspace = shell.active_space(&output); + let workspace = shell.active_space(output); let maybe_fullscreen = workspace.get_fullscreen(); workspace .cursor_sessions() @@ -2136,10 +2128,10 @@ fn cursor_sessions_for_output( .into_iter() .flatten(), ) - .chain(output.cursor_sessions().into_iter()) + .chain(output.cursor_sessions()) } -fn transform_output_mapped_position<'a, B, E>(output: &Output, event: &E) -> Point +fn transform_output_mapped_position(output: &Output, event: &E) -> Point where B: InputBackend, E: AbsolutePositionEvent, diff --git a/src/main.rs b/src/main.rs index 43b8a698..118aba09 100644 --- a/src/main.rs +++ b/src/main.rs @@ -69,7 +69,12 @@ impl State { command.envs( session::get_env(&self.common).expect("WAYLAND_DISPLAY should be valid UTF-8"), ); - unsafe { command.pre_exec(|| Ok(utils::rlimit::restore_nofile_limit())) }; + unsafe { + command.pre_exec(|| { + utils::rlimit::restore_nofile_limit(); + Ok(()) + }) + }; info!("Running {:?}", exec); command @@ -131,7 +136,7 @@ fn main() -> Result<()> { { let dh = state.common.display_handle.clone(); for client in clients.values() { - client_compositor_state(&client).blocker_cleared(state, &dh); + client_compositor_state(client).blocker_cleared(state, &dh); } } state.common.refresh(); diff --git a/src/session.rs b/src/session.rs index 240e649b..40fb9019 100644 --- a/src/session.rs +++ b/src/session.rs @@ -133,11 +133,11 @@ pub fn setup_socket(handle: LoopHandle, common: &Common) -> Result<()> { stream.read_bytes = 0; match std::str::from_utf8(&stream.buffer) { Ok(message) => { - match serde_json::from_str::<'_, Message>(&message) { + match serde_json::from_str::<'_, Message>(message) { Ok(Message::NewPrivilegedClient { count }) => { let mut buffer = [0; 1]; let mut fds = vec![0; count]; - match stream.stream.recv_with_fd(&mut buffer, &mut *fds) { + match stream.stream.recv_with_fd(&mut buffer, &mut fds) { Ok((_, received_count)) => { assert_eq!(received_count, count); for fd in fds.into_iter().take(received_count) { diff --git a/src/shell/element/mod.rs b/src/shell/element/mod.rs index 2a8cebab..a49c159d 100644 --- a/src/shell/element/mod.rs +++ b/src/shell/element/mod.rs @@ -252,9 +252,8 @@ impl CosmicMapped { } pub fn focus_window(&self, window: &CosmicSurface) { - match &self.element { - CosmicMappedInternal::Stack(stack) => stack.set_active(window), - _ => {} + if let CosmicMappedInternal::Stack(stack) = &self.element { + stack.set_active(window) } } @@ -264,10 +263,8 @@ impl CosmicMapped { return false; }; - if surface_type.contains(WindowSurfaceType::TOPLEVEL) { - if *toplevel == *surface { - return true; - } + if surface_type.contains(WindowSurfaceType::TOPLEVEL) && *toplevel == *surface { + return true; } if surface_type.contains(WindowSurfaceType::SUBSURFACE) { @@ -530,7 +527,7 @@ impl CosmicMapped { pub fn set_bounds(&self, size: impl Into>>) { let size = size.into(); for (surface, _) in self.windows() { - surface.set_bounds(size.clone()) + surface.set_bounds(size) } } @@ -559,17 +556,11 @@ impl CosmicMapped { } pub fn is_window(&self) -> bool { - match &self.element { - CosmicMappedInternal::Window(_) => true, - _ => false, - } + matches!(self.element, CosmicMappedInternal::Window(_)) } pub fn is_stack(&self) -> bool { - match &self.element { - CosmicMappedInternal::Stack(_) => true, - _ => false, - } + matches!(self.element, CosmicMappedInternal::Stack(_)) } pub fn stack_ref(&self) -> Option<&CosmicStack> { @@ -591,24 +582,21 @@ impl CosmicMapped { (output, overlap): (&Output, Rectangle), theme: cosmic::Theme, ) { - match &self.element { - CosmicMappedInternal::Window(window) => { - let surface = window.surface(); - let activated = surface.is_activated(true); - let handle = window.loop_handle(); - - let stack = CosmicStack::new(std::iter::once(surface), handle, theme); - if let Some(geo) = self.last_geometry.lock().unwrap().clone() { - stack.set_geometry(geo.to_global(&output)); - } - stack.output_enter(output, overlap); - stack.set_activate(activated); - stack.active().send_configure(); - stack.refresh(); - - self.element = CosmicMappedInternal::Stack(stack); + if let CosmicMappedInternal::Window(window) = &self.element { + let surface = window.surface(); + let activated = surface.is_activated(true); + let handle = window.loop_handle(); + + let stack = CosmicStack::new(std::iter::once(surface), handle, theme); + if let Some(geo) = *self.last_geometry.lock().unwrap() { + stack.set_geometry(geo.to_global(output)); } - _ => {} + stack.output_enter(output, overlap); + stack.set_activate(activated); + stack.active().send_configure(); + stack.refresh(); + + self.element = CosmicMappedInternal::Stack(stack); } } @@ -623,8 +611,8 @@ impl CosmicMapped { surface.set_tiled(false); let window = CosmicWindow::new(surface, handle, theme); - if let Some(geo) = self.last_geometry.lock().unwrap().clone() { - window.set_geometry(geo.to_global(&output)); + if let Some(geo) = *self.last_geometry.lock().unwrap() { + window.set_geometry(geo.to_global(output)); } window.output_enter(output, overlap); window.set_activate(self.is_activated(true)); diff --git a/src/shell/element/stack.rs b/src/shell/element/stack.rs index 90ae4d22..25ec3111 100644 --- a/src/shell/element/stack.rs +++ b/src/shell/element/stack.rs @@ -167,7 +167,7 @@ impl CosmicStack { window.try_force_undecorated(true); window.set_tiled(true); self.0.with_program(|p| { - if let Some(mut geo) = p.geometry.lock().unwrap().clone() { + if let Some(mut geo) = *p.geometry.lock().unwrap() { geo.loc.y += TAB_HEIGHT; geo.size.h -= TAB_HEIGHT; window.set_geometry(geo, TAB_HEIGHT as u32); @@ -197,7 +197,7 @@ impl CosmicStack { let mut windows = p.windows.lock().unwrap(); if windows.len() == 1 { p.override_alive.store(false, Ordering::SeqCst); - let window = windows.get(0).unwrap(); + let window = windows.first().unwrap(); window.try_force_undecorated(false); window.set_tiled(false); return; @@ -225,7 +225,7 @@ impl CosmicStack { let mut windows = p.windows.lock().unwrap(); if windows.len() == 1 { p.override_alive.store(false, Ordering::SeqCst); - let window = windows.get(0).unwrap(); + let window = windows.first().unwrap(); window.try_force_undecorated(false); window.set_tiled(false); return Some(window.clone()); @@ -254,6 +254,10 @@ impl CosmicStack { self.0.with_program(|p| p.windows.lock().unwrap().len()) } + pub fn is_empty(&self) -> bool { + self.len() == 0 + } + pub fn handle_focus(&self, direction: FocusDirection, swap: Option) -> bool { let result = self.0.with_program(|p| match direction { FocusDirection::Left => { @@ -474,13 +478,8 @@ impl CosmicStack { } pub fn pending_size(&self) -> Option> { - self.0.with_program(|p| { - p.geometry - .lock() - .unwrap() - .clone() - .map(|geo| geo.size.as_logical()) - }) + self.0 + .with_program(|p| (*p.geometry.lock().unwrap()).map(|geo| geo.size.as_logical())) } pub fn set_geometry(&self, geo: Rectangle) { @@ -1331,16 +1330,14 @@ impl PointerTarget for CosmicStack { } fn axis(&self, seat: &Seat, data: &mut State, frame: AxisFrame) { - match self.0.with_program(|p| p.current_focus()) { - Some(Focus::Header) => PointerTarget::axis(&self.0, seat, data, frame), - _ => {} + if let Some(Focus::Header) = self.0.with_program(|p| p.current_focus()) { + PointerTarget::axis(&self.0, seat, data, frame) } } fn frame(&self, seat: &Seat, data: &mut State) { - match self.0.with_program(|p| p.current_focus()) { - Some(Focus::Header) => PointerTarget::frame(&self.0, seat, data), - _ => {} + if let Some(Focus::Header) = self.0.with_program(|p| p.current_focus()) { + PointerTarget::frame(&self.0, seat, data) } } @@ -1474,7 +1471,7 @@ impl TouchTarget for CosmicStack { } fn up(&self, seat: &Seat, data: &mut State, event: &UpEvent, seq: Serial) { - TouchTarget::up(&self.0, seat, data, &event, seq) + TouchTarget::up(&self.0, seat, data, event, seq) } fn motion(&self, seat: &Seat, data: &mut State, event: &TouchMotionEvent, seq: Serial) { diff --git a/src/shell/element/surface.rs b/src/shell/element/surface.rs index 3c6ad3f2..5c6aad9a 100644 --- a/src/shell/element/surface.rs +++ b/src/shell/element/surface.rs @@ -241,8 +241,7 @@ impl CosmicSurface { match self.0.underlying_surface() { WindowSurface::Wayland(toplevel) => { if enable { - let previous_decoration_state = - toplevel.current_state().decoration_mode.clone(); + let previous_decoration_state = toplevel.current_state().decoration_mode; if PreferredDecorationMode::is_unset(&self.0) { PreferredDecorationMode::update(&self.0, previous_decoration_state); } diff --git a/src/shell/element/window.rs b/src/shell/element/window.rs index c88c6121..95d3bcbd 100644 --- a/src/shell/element/window.rs +++ b/src/shell/element/window.rs @@ -755,16 +755,14 @@ impl PointerTarget for CosmicWindow { } fn axis(&self, seat: &Seat, data: &mut State, frame: AxisFrame) { - match self.0.with_program(|p| p.current_focus()) { - Some(Focus::Header) => PointerTarget::axis(&self.0, seat, data, frame), - _ => {} + if let Some(Focus::Header) = self.0.with_program(|p| p.current_focus()) { + PointerTarget::axis(&self.0, seat, data, frame) } } fn frame(&self, seat: &Seat, data: &mut State) { - match self.0.with_program(|p| p.current_focus()) { - Some(Focus::Header) => PointerTarget::frame(&self.0, seat, data), - _ => {} + if let Some(Focus::Header) = self.0.with_program(|p| p.current_focus()) { + PointerTarget::frame(&self.0, seat, data) } } @@ -853,7 +851,7 @@ impl TouchTarget for CosmicWindow { } fn up(&self, seat: &Seat, data: &mut State, event: &UpEvent, seq: Serial) { - TouchTarget::up(&self.0, seat, data, &event, seq) + TouchTarget::up(&self.0, seat, data, event, seq) } fn motion(&self, seat: &Seat, data: &mut State, event: &TouchMotionEvent, seq: Serial) { diff --git a/src/shell/focus/mod.rs b/src/shell/focus/mod.rs index 638ac4ec..38281fca 100644 --- a/src/shell/focus/mod.rs +++ b/src/shell/focus/mod.rs @@ -142,18 +142,18 @@ impl Shell { } // update FocusStack and notify layouts about new focus (if any window) - let workspace = self.space_for_mut(&mapped); - let workspace = if workspace.is_none() { - //should this be the active output or the focused output? - self.active_space_mut(&seat.focused_or_active_output()) - } else { - workspace.unwrap() + let workspace = match self.space_for_mut(mapped) { + Some(workspace) => workspace, + None => { + //should this be the active output or the focused output? + self.active_space_mut(&seat.focused_or_active_output()) + } }; let mut focus_stack = workspace.focus_stack.get_mut(seat); if Some(mapped) != focus_stack.last() { trace!(?mapped, "Focusing window."); - focus_stack.append(&mapped); + focus_stack.append(mapped); // also remove popup grabs, if we are switching focus if let Some(mut popup_grab) = seat .user_data() @@ -172,7 +172,7 @@ impl Shell { let focused_windows = self .seats .iter() - .map(|seat| { + .filter_map(|seat| { if matches!( seat.get_keyboard().unwrap().current_focus(), Some(KeyboardFocusTarget::Group(_)) @@ -185,7 +185,6 @@ impl Shell { let stack = space.focus_stack.get(seat); stack.last().cloned() }) - .flatten() .collect::>(); for output in self.outputs().cloned().collect::>().into_iter() { @@ -194,7 +193,7 @@ impl Shell { raise_with_children(&mut set.sticky_layer, focused); } for window in set.sticky_layer.mapped() { - window.set_activated(focused_windows.contains(&window)); + window.set_activated(focused_windows.contains(window)); window.configure(); } for m in set.minimized_windows.iter() { @@ -207,7 +206,7 @@ impl Shell { raise_with_children(&mut workspace.floating_layer, focused); } for window in workspace.mapped() { - window.set_activated(focused_windows.contains(&window)); + window.set_activated(focused_windows.contains(window)); window.configure(); } for m in workspace.minimized_windows.iter() { @@ -238,38 +237,39 @@ fn update_focus_state( ) { // update keyboard focus if let Some(keyboard) = seat.get_keyboard() { - 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(); - // get the top left corner of the target element - let geometry = shell.focused_geometry(target.unwrap()); - if let Some(geometry) = geometry { - // get the center of the target element - let window_center = Point::from((geometry.size.w / 2, geometry.size.h / 2)); - let new_pos = (geometry.loc + window_center).to_f64(); - - // create a pointer target from the target element - let output = shell - .outputs() - .find(|output| output.geometry().to_f64().contains(new_pos)) - .cloned() - .unwrap_or(seat.active_output()); - - let focus = State::surface_under(new_pos, &output, &*shell) - .map(|(focus, loc)| (focus, loc.as_logical())); - //drop here to avoid multiple borrows - mem::drop(shell); - seat.get_pointer().unwrap().motion( - state, - focus, - &MotionEvent { - location: new_pos.as_logical(), - serial: SERIAL_COUNTER.next_serial(), - time: 0, - }, - ); - } + if should_update_cursor + && state.common.config.cosmic_conf.cursor_follows_focus + && target.is_some() + { + //need to borrow mutably for surface under + let shell = state.common.shell.read().unwrap(); + // get the top left corner of the target element + let geometry = shell.focused_geometry(target.unwrap()); + if let Some(geometry) = geometry { + // get the center of the target element + let window_center = Point::from((geometry.size.w / 2, geometry.size.h / 2)); + let new_pos = (geometry.loc + window_center).to_f64(); + + // create a pointer target from the target element + let output = shell + .outputs() + .find(|output| output.geometry().to_f64().contains(new_pos)) + .cloned() + .unwrap_or(seat.active_output()); + + let focus = State::surface_under(new_pos, &output, &shell) + .map(|(focus, loc)| (focus, loc.as_logical())); + //drop here to avoid multiple borrows + mem::drop(shell); + seat.get_pointer().unwrap().motion( + state, + focus, + &MotionEvent { + location: new_pos.as_logical(), + serial: SERIAL_COUNTER.next_serial(), + time: 0, + }, + ); } } @@ -344,7 +344,7 @@ impl Common { .cloned() .collect::>(); for seat in &seats { - update_pointer_focus(state, &seat); + update_pointer_focus(state, seat); let mut shell = state.common.shell.write().unwrap(); let output = seat.focused_or_active_output(); @@ -357,11 +357,11 @@ impl Common { continue; } - let last_known_focus = ActiveFocus::get(&seat); + let last_known_focus = ActiveFocus::get(seat); if let Some(target) = last_known_focus { if target.alive() { - if focus_target_is_valid(&mut *shell, &seat, &output, target) { + if focus_target_is_valid(&mut shell, seat, &output, target) { continue; // Focus is valid } else { trace!("Wrong Window, focus fixup"); @@ -397,7 +397,7 @@ impl Common { } } else { let workspace = shell.active_space(&output); - let focus_stack = workspace.focus_stack.get(&seat); + let focus_stack = workspace.focus_stack.get(seat); if focus_stack.last().is_none() { continue; // Focus is valid @@ -420,7 +420,7 @@ impl Common { } // update keyboard focus - let target = update_focus_target(&*shell, &seat, &output); + let target = update_focus_target(&shell, seat, &output); std::mem::drop(shell); //I can probably feature gate this condition debug!("Restoring focus to {:?}", target.as_ref()); @@ -440,8 +440,8 @@ impl Common { .as_ref() .and_then(|t| t.wl_surface()) .and_then(|s| state.common.display_handle.get_client(s.id()).ok()); - set_data_device_focus(&state.common.display_handle, &seat, client.clone()); - set_primary_focus(&state.common.display_handle, &seat, client); + set_data_device_focus(&state.common.display_handle, seat, client.clone()); + set_primary_focus(&state.common.display_handle, seat, client); } } @@ -496,8 +496,8 @@ fn focus_target_is_valid( .mapped() .any(|m| m == &mapped); - let workspace = shell.active_space(&output); - let focus_stack = workspace.focus_stack.get(&seat); + let workspace = shell.active_space(output); + let focus_stack = workspace.focus_stack.get(seat); let is_in_focus_stack = focus_stack.last().map(|m| m == &mapped).unwrap_or(false); let has_fullscreen = workspace.get_fullscreen().is_some(); @@ -508,17 +508,17 @@ fn focus_target_is_valid( (is_sticky || is_in_focus_stack) && !has_fullscreen } KeyboardFocusTarget::LayerSurface(layer) => { - layer_map_for_output(&output).layers().any(|l| l == &layer) + layer_map_for_output(output).layers().any(|l| l == &layer) } KeyboardFocusTarget::Group(WindowGroup { node, .. }) => shell .workspaces - .active(&output) + .active(output) .1 .tiling_layer .has_node(&node), KeyboardFocusTarget::Fullscreen(window) => { - let workspace = shell.active_space(&output); - let focus_stack = workspace.focus_stack.get(&seat); + let workspace = shell.active_space(output); + let focus_stack = workspace.focus_stack.get(seat); focus_stack .last() @@ -552,15 +552,15 @@ fn update_focus_target( }) .cloned() .map(KeyboardFocusTarget::from) - } else if let Some(surface) = shell.active_space(&output).get_fullscreen() { + } else if let Some(surface) = shell.active_space(output).get_fullscreen() { Some(KeyboardFocusTarget::Fullscreen(surface.clone())) } else { shell - .active_space(&output) + .active_space(output) .focus_stack - .get(&seat) + .get(seat) .last() - .or_else(|| shell.active_space(&output).mapped().next()) + .or_else(|| shell.active_space(output).mapped().next()) .cloned() .map(KeyboardFocusTarget::from) } @@ -571,8 +571,8 @@ fn update_pointer_focus(state: &mut State, seat: &Seat) { let output = seat.active_output(); let position = pointer.current_location().as_global(); - let mut shell = state.common.shell.write().unwrap(); - let under = State::surface_under(position, &output, &mut shell) + let shell = state.common.shell.write().unwrap(); + let under = State::surface_under(position, &output, &shell) .map(|(target, pos)| (target, pos.as_logical())); drop(shell); @@ -597,10 +597,10 @@ fn exclusive_layer_surface_layer(shell: &Shell) -> Option { for output in shell.outputs() { for layer_surface in layer_map_for_output(output).layers() { let data = layer_surface.cached_state(); - if data.keyboard_interactivity == KeyboardInteractivity::Exclusive { - if data.layer as u32 >= layer.unwrap_or(Layer::Top) as u32 { - layer = Some(data.layer); - } + if data.keyboard_interactivity == KeyboardInteractivity::Exclusive + && data.layer as u32 >= layer.unwrap_or(Layer::Top) as u32 + { + layer = Some(data.layer); } } } diff --git a/src/shell/focus/order.rs b/src/shell/focus/order.rs index e03eb607..b6a602a6 100644 --- a/src/shell/focus/order.rs +++ b/src/shell/focus/order.rs @@ -106,7 +106,7 @@ fn render_input_order_internal( Some((previous, previous_idx, start)) => { let layout = shell.workspaces.layout; - let Some(workspace) = shell.workspaces.space_for_handle(&previous) else { + let Some(workspace) = shell.workspaces.space_for_handle(previous) else { return ControlFlow::Break(Err(OutputNoMode)); }; let has_fullscreen = workspace.fullscreen.is_some(); @@ -332,13 +332,13 @@ fn render_input_order_internal( ControlFlow::Continue(()) } -fn layer_popups<'a>( - output: &'a Output, +fn layer_popups( + output: &Output, layer: Layer, element_filter: ElementFilter, -) -> impl Iterator)> + 'a { +) -> impl Iterator)> + '_ { layer_surfaces(output, layer, element_filter).flat_map(move |(surface, location)| { - let location_clone = location.clone(); + let location_clone = location; let surface_clone = surface.clone(); PopupManager::popups_for_surface(surface.wl_surface()).map(move |(popup, popup_offset)| { let offset = (popup_offset - popup.geometry().loc).as_global(); @@ -347,11 +347,11 @@ fn layer_popups<'a>( }) } -fn layer_surfaces<'a>( - output: &'a Output, +fn layer_surfaces( + output: &Output, layer: Layer, element_filter: ElementFilter, -) -> impl Iterator)> + 'a { +) -> impl Iterator)> + '_ { // we want to avoid deadlocks on the layer-map in callbacks, so we need to clone the layer surfaces let layers = { let layer_map = layer_map_for_output(output); diff --git a/src/shell/focus/target.rs b/src/shell/focus/target.rs index 176eff03..9b426dab 100644 --- a/src/shell/focus/target.rs +++ b/src/shell/focus/target.rs @@ -160,7 +160,7 @@ impl KeyboardFocusTarget { match self { KeyboardFocusTarget::Element(mapped) => mapped.wl_surface(), KeyboardFocusTarget::Popup(PopupKind::Xdg(xdg)) => { - get_popup_toplevel(&xdg).map(Cow::Owned) + get_popup_toplevel(xdg).map(Cow::Owned) } _ => None, } @@ -207,7 +207,7 @@ impl IsAlive for KeyboardFocusTarget { impl PointerTarget for PointerFocusTarget { fn enter(&self, seat: &Seat, data: &mut State, event: &PointerMotionEvent) { - let toplevel = self.toplevel(&*data.common.shell.read().unwrap()); + let toplevel = self.toplevel(&data.common.shell.read().unwrap()); if let Some(element) = toplevel { for session in element.cursor_sessions() { session.set_cursor_pos(Some( @@ -236,7 +236,7 @@ impl PointerTarget for PointerFocusTarget { } } fn motion(&self, seat: &Seat, data: &mut State, event: &PointerMotionEvent) { - let toplevel = self.toplevel(&*data.common.shell.read().unwrap()); + let toplevel = self.toplevel(&data.common.shell.read().unwrap()); if let Some(element) = toplevel { for session in element.cursor_sessions() { session.set_cursor_pos(Some( @@ -307,7 +307,7 @@ impl PointerTarget for PointerFocusTarget { } } fn leave(&self, seat: &Seat, data: &mut State, serial: Serial, time: u32) { - let toplevel = self.toplevel(&*data.common.shell.read().unwrap()); + let toplevel = self.toplevel(&data.common.shell.read().unwrap()); if let Some(element) = toplevel { for session in element.cursor_sessions() { session.set_cursor_pos(None); diff --git a/src/shell/grabs/menu/default.rs b/src/shell/grabs/menu/default.rs index ce227f81..0721c7a6 100644 --- a/src/shell/grabs/menu/default.rs +++ b/src/shell/grabs/menu/default.rs @@ -70,8 +70,7 @@ fn move_next_workspace(state: &mut State, mapped: &CosmicMapped) { .workspaces .spaces_for_output(&output) .skip_while(|space| space.handle != current_handle) - .skip(1) - .next() + .nth(1) .map(|space| space.handle); if let Some(next_handle) = maybe_handle { let res = shell.move_window( diff --git a/src/shell/grabs/menu/item.rs b/src/shell/grabs/menu/item.rs index bf69e3ab..dd05191d 100644 --- a/src/shell/grabs/menu/item.rs +++ b/src/shell/grabs/menu/item.rs @@ -216,11 +216,11 @@ where } } -impl<'a, Message> Into> for SubmenuItem<'a, Message> +impl<'a, Message> From> for cosmic::Element<'a, Message> where Message: CursorEvents + 'a, { - fn into(self) -> cosmic::Element<'a, Message> { - Element::new(self) + fn from(val: SubmenuItem<'a, Message>) -> Self { + Element::new(val) } } diff --git a/src/shell/grabs/menu/mod.rs b/src/shell/grabs/menu/mod.rs index 62fcaa7e..712dd09e 100644 --- a/src/shell/grabs/menu/mod.rs +++ b/src/shell/grabs/menu/mod.rs @@ -339,7 +339,7 @@ impl Program for ContextMenu { .row_width .lock() .unwrap() - .map(|size| Length::Fixed(size)) + .map(Length::Fixed) .unwrap_or(Length::Shrink); let mode = match width { Length::Shrink => Length::Shrink, diff --git a/src/shell/grabs/mod.rs b/src/shell/grabs/mod.rs index def21cfe..91741e33 100644 --- a/src/shell/grabs/mod.rs +++ b/src/shell/grabs/mod.rs @@ -122,9 +122,9 @@ impl From for ResizeEdge { } } -impl Into for ResizeEdge { - fn into(self) -> shortcuts::action::ResizeEdge { - match self { +impl From for shortcuts::action::ResizeEdge { + fn from(val: ResizeEdge) -> Self { + match val { ResizeEdge::BOTTOM => shortcuts::action::ResizeEdge::Bottom, ResizeEdge::BOTTOM_LEFT => shortcuts::action::ResizeEdge::BottomLeft, ResizeEdge::BOTTOM_RIGHT => shortcuts::action::ResizeEdge::BottomRight, diff --git a/src/shell/grabs/moving.rs b/src/shell/grabs/moving.rs index 5081ead8..fed5ba57 100644 --- a/src/shell/grabs/moving.rs +++ b/src/shell/grabs/moving.rs @@ -92,11 +92,11 @@ impl MoveGrabState { let mut window_geo = self.window.geometry(); window_geo.loc += self.location.to_i32_round() + self.window_offset; - if !output + if output .geometry() .as_logical() .intersection(window_geo) - .is_some() + .is_none() { return Vec::new(); } @@ -110,8 +110,8 @@ impl MoveGrabState { let active_window_hint = crate::theme::active_window_hint(theme); let focus_element = if self.indicator_thickness > 0 { - Some( - CosmicMappedRenderElement::from(IndicatorShader::focus_element( + Some(CosmicMappedRenderElement::from( + IndicatorShader::focus_element( renderer, Key::Window(Usage::MoveGrabIndicator, self.window.key()), Rectangle::from_loc_and_size( @@ -132,15 +132,14 @@ impl MoveGrabState { active_window_hint.green, active_window_hint.blue, ], - )) - .into(), - ) + ), + )) } else { None }; let non_exclusive_geometry = { - let layers = layer_map_for_output(&output); + let layers = layer_map_for_output(output); layers.non_exclusive_zone() }; @@ -165,8 +164,7 @@ impl MoveGrabState { active_window_hint.green, active_window_hint.blue, ], - )) - .into(), + )), CosmicMappedRenderElement::from(BackdropShader::element( renderer, Key::Window(Usage::SnappingIndicator, self.window.key()), @@ -174,8 +172,7 @@ impl MoveGrabState { theme.radius_s()[0], // TODO: Fix once shaders support 4 corner radii customization 0.4, [base_color.red, base_color.green, base_color.blue], - )) - .into(), + )), ] } _ => vec![], @@ -392,7 +389,7 @@ impl MoveGrab { indicator.output_enter(output, overlap); } } - } else if self.window_outputs.remove(&output) { + } else if self.window_outputs.remove(output) { self.window.output_leave(output); if let Some(indicator) = grab_state.stacking_indicator.as_ref().map(|x| &x.0) { indicator.output_leave(output); diff --git a/src/shell/layout/floating/grabs/resize.rs b/src/shell/layout/floating/grabs/resize.rs index 5cbd26b4..3891a9bc 100644 --- a/src/shell/layout/floating/grabs/resize.rs +++ b/src/shell/layout/floating/grabs/resize.rs @@ -103,8 +103,8 @@ impl ResizeSurfaceGrab { let min_width = min_size.map(|s| s.w).unwrap_or(360); let min_height = min_size.map(|s| s.h).unwrap_or(240); - let max_width = max_size.map(|s| s.w).unwrap_or(i32::max_value()); - let max_height = max_size.map(|s| s.h).unwrap_or(i32::max_value()); + let max_width = max_size.map(|s| s.w).unwrap_or(i32::MAX); + let max_height = max_size.map(|s| s.h).unwrap_or(i32::MAX); new_window_width = new_window_width.max(min_width).min(max_width); new_window_height = new_window_height.max(min_height).min(max_height); @@ -312,10 +312,10 @@ impl TouchGrab for ResizeSurfaceGrab { event: &TouchMotionEvent, seq: Serial, ) { - if event.slot == >::start_data(self).slot { - if self.update_location(event.location) { - handle.unset_grab(self, data); - } + if event.slot == >::start_data(self).slot + && self.update_location(event.location) + { + handle.unset_grab(self, data); } handle.motion(data, None, event, seq); @@ -460,7 +460,7 @@ impl ResizeSurfaceGrab { if edges.intersects(ResizeEdge::TOP_LEFT) { let size = window.geometry().size; - let mut new = location.clone(); + let mut new = location; if edges.intersects(ResizeEdge::LEFT) { new.x = initial_window_location.x + (initial_window_size.w - size.w); } @@ -501,7 +501,7 @@ impl ResizeSurfaceGrab { } floating_layer.space.map_element( window, - new_location.to_local(&output).as_logical(), + new_location.to_local(output).as_logical(), false, ); } diff --git a/src/shell/layout/floating/mod.rs b/src/shell/layout/floating/mod.rs index 4507d7ea..a97d35cd 100644 --- a/src/shell/layout/floating/mod.rs +++ b/src/shell/layout/floating/mod.rs @@ -136,7 +136,7 @@ impl Animation { } | Animation::Unminimize { target_geometry, .. - } => (MINIMIZE_ANIMATION_DURATION, target_geometry.clone()), + } => (MINIMIZE_ANIMATION_DURATION, *target_geometry), Animation::Tiled { .. } => { let target_geometry = if let Some(target_rect) = tiled_state.map(|state| state.relative_geometry(output_geometry, gaps)) @@ -148,7 +148,7 @@ impl Animation { (ANIMATION_DURATION, target_geometry) } }; - let previous_rect = self.previous_geometry().clone(); + let previous_rect = *self.previous_geometry(); let start = *self.start(); let now = Instant::now(); let progress = @@ -281,7 +281,7 @@ impl FloatingLayout { layers.non_exclusive_zone() }; let output_geometry = { - let layers = layer_map_for_output(&output); + let layers = layer_map_for_output(output); layers.non_exclusive_zone() }; @@ -292,7 +292,7 @@ impl FloatingLayout { .collect::>() .into_iter() { - let tiled_state = mapped.floating_tiled.lock().unwrap().clone(); + let tiled_state = *mapped.floating_tiled.lock().unwrap(); if let Some(tiled_state) = tiled_state { let geometry = tiled_state.relative_geometry(output_geometry, self.gaps()); self.map_internal( @@ -364,7 +364,7 @@ impl FloatingLayout { } if mapped.floating_tiled.lock().unwrap().take().is_some() { if let Some(state) = mapped.maximized_state.lock().unwrap().as_mut() { - if let Some(real_old_geo) = mapped.last_geometry.lock().unwrap().clone() { + if let Some(real_old_geo) = *mapped.last_geometry.lock().unwrap() { state.original_geometry = real_old_geo; } }; @@ -387,7 +387,7 @@ impl FloatingLayout { let layers = layer_map_for_output(&output); let output_geometry = layers.non_exclusive_zone(); mapped.set_bounds(output_geometry.size); - let last_geometry = mapped.last_geometry.lock().unwrap().clone(); + let last_geometry = *mapped.last_geometry.lock().unwrap(); let min_size = mapped.min_size().unwrap_or((320, 240).into()); if let Some(size) = size @@ -628,7 +628,7 @@ impl FloatingLayout { pub fn unmap(&mut self, window: &CosmicMapped) -> Option> { let mut new_size = None; - if let Some(_) = window.floating_tiled.lock().unwrap().take() { + if window.floating_tiled.lock().unwrap().take().is_some() { if let Some(last_size) = window.last_geometry.lock().unwrap().map(|geo| geo.size) { if let Some(location) = self.space.element_location(window) { window.set_tiled(false); @@ -658,7 +658,7 @@ impl FloatingLayout { let _ = self.animations.remove(window); let was_unmaped = self.space.elements().any(|e| e == window); - self.space.unmap_elem(&window); + self.space.unmap_elem(window); if was_unmaped { if let Some(pos) = self.spawn_order.iter().position(|w| w == window) { @@ -677,7 +677,7 @@ impl FloatingLayout { to: Rectangle, ) -> Option<(CosmicMapped, Point)> { let previous_geometry = self.space.element_geometry(window); - self.space.unmap_elem(&window); + self.space.unmap_elem(window); if let Some(previous_geometry) = previous_geometry { if let Some(pos) = self.spawn_order.iter().position(|w| w == window) { self.spawn_order.truncate(pos); @@ -880,7 +880,7 @@ impl FloatingLayout { } pub fn stacking_indicator(&self) -> Option> { - self.hovered_stack.as_ref().map(|(_, geo)| geo.clone()) + self.hovered_stack.as_ref().map(|(_, geo)| *geo) } pub fn resize_request( @@ -892,7 +892,7 @@ impl FloatingLayout { release: ReleaseMode, ) -> Option { if seat.get_pointer().is_some() { - let location = self.space.element_location(&mapped)?.as_local(); + let location = self.space.element_location(mapped)?.as_local(); let size = mapped.geometry().size; mapped.moved_since_mapped.store(true, Ordering::SeqCst); @@ -934,7 +934,7 @@ impl FloatingLayout { let Some(original_geo) = self.space.element_geometry(mapped) else { return false; // we don't have that window }; - let mut geo = original_geo.clone(); + let mut geo = original_geo; if edge.contains(ResizeEdge::RIGHT) || edge.contains(ResizeEdge::LEFT) { if direction == ResizeDirection::Inwards { @@ -972,8 +972,8 @@ impl FloatingLayout { let (min_size, max_size) = (mapped.min_size(), mapped.max_size()); let min_width = min_size.map(|s| s.w).unwrap_or(360); let min_height = min_size.map(|s| s.h).unwrap_or(240); - let max_width = max_size.map(|s| s.w).unwrap_or(i32::max_value()); - let max_height = max_size.map(|s| s.h).unwrap_or(i32::max_value()); + let max_width = max_size.map(|s| s.w).unwrap_or(i32::MAX); + let max_height = max_size.map(|s| s.h).unwrap_or(i32::MAX); geo.size.w = min_width.max(geo.size.w).min(max_width); geo.size.h = min_height.max(geo.size.h).min(max_height); @@ -1308,8 +1308,7 @@ impl FloatingLayout { mapped.set_geometry(geometry.to_global(&output)); geometry.loc } else { - prev.clone() - .map(|rect| rect.loc.constrain(geometry)) + prev.map(|rect| rect.loc.constrain(geometry)) .unwrap_or(Point::from((0, 0))) }; @@ -1501,14 +1500,14 @@ impl FloatingLayout { .to_physical_precise_round(output_scale), scale, ); - let relocated = RelocateRenderElement::from_element( + + RelocateRenderElement::from_element( rescaled, (geometry.loc - original_geo.loc) .as_logical() .to_physical_precise_round(output_scale), Relocate::Relative, - ); - relocated + ) }) } CosmicMappedRenderElement::Window(elem) => { @@ -1521,14 +1520,14 @@ impl FloatingLayout { .to_physical_precise_round(output_scale), scale, ); - let relocated = RelocateRenderElement::from_element( + + RelocateRenderElement::from_element( rescaled, (geometry.loc - original_geo.loc) .as_logical() .to_physical_precise_round(output_scale), Relocate::Relative, - ); - relocated + ) }) } x => x, @@ -1538,7 +1537,7 @@ impl FloatingLayout { if focused == Some(elem) && !elem.is_maximized(false) { if let Some((mode, resize)) = resize_indicator.as_mut() { - let mut resize_geometry = geometry.clone(); + let mut resize_geometry = geometry; resize_geometry.loc -= (18, 18).into(); resize_geometry.size += (36, 36).into(); diff --git a/src/shell/layout/tiling/grabs/resize.rs b/src/shell/layout/tiling/grabs/resize.rs index 03a3cf62..8b35ec27 100644 --- a/src/shell/layout/tiling/grabs/resize.rs +++ b/src/shell/layout/tiling/grabs/resize.rs @@ -511,10 +511,10 @@ impl TouchGrab for ResizeForkGrab { event: &TouchMotionEvent, seq: Serial, ) { - if event.slot == >::start_data(self).slot { - if self.update_location(data, event.location) { - handle.unset_grab(self, data); - } + if event.slot == >::start_data(self).slot + && self.update_location(data, event.location) + { + handle.unset_grab(self, data); } handle.motion(data, None, event, seq); diff --git a/src/shell/layout/tiling/grabs/swap.rs b/src/shell/layout/tiling/grabs/swap.rs index 28036ced..01b6f3f0 100644 --- a/src/shell/layout/tiling/grabs/swap.rs +++ b/src/shell/layout/tiling/grabs/swap.rs @@ -49,7 +49,7 @@ impl KeyboardGrab for SwapWindowGrab { return; } - let syms = Vec::from(handle.keysym_handle(keycode).raw_syms()); + let syms = handle.keysym_handle(keycode).raw_syms(); let focus_bindings = &data .common .config diff --git a/src/shell/layout/tiling/mod.rs b/src/shell/layout/tiling/mod.rs index 395a3466..8dfd6598 100644 --- a/src/shell/layout/tiling/mod.rs +++ b/src/shell/layout/tiling/mod.rs @@ -196,10 +196,7 @@ impl Data { } } fn is_placeholder(&self) -> bool { - match self { - Data::Placeholder { .. } => true, - _ => false, - } + matches!(self, Data::Placeholder { .. }) } fn orientation(&self) -> Orientation { @@ -404,7 +401,7 @@ impl TilingLayout { let mut tree = self.queue.trees.back().unwrap().0.copy_clone(); let last_active = focus_stack - .and_then(|focus_stack| TilingLayout::last_active_window(&mut tree, focus_stack)) + .and_then(|focus_stack| TilingLayout::last_active_window(&tree, focus_stack)) .map(|(node_id, _)| node_id); let duration = if minimize_rect.is_some() { MINIMIZE_ANIMATION_DURATION @@ -494,7 +491,7 @@ impl TilingLayout { if sibling .as_ref() - .is_some_and(|sibling| tree.get(&sibling).is_ok()) + .is_some_and(|sibling| tree.get(sibling).is_ok()) { let sibling_id = sibling.unwrap(); let new_node = Node::new(Data::Mapped { @@ -536,7 +533,7 @@ impl TilingLayout { } fn map_to_tree( - mut tree: &mut Tree, + tree: &mut Tree, window: impl Into, output: &Output, node: Option, @@ -558,7 +555,7 @@ impl TilingLayout { }; let new_id = tree.insert(new_window, InsertBehavior::AsRoot).unwrap(); - TilingLayout::new_group(&mut tree, &root_id, &new_id, orientation).unwrap(); + TilingLayout::new_group(tree, &root_id, &new_id, orientation).unwrap(); tree.make_nth_sibling( &new_id, match direction { @@ -571,36 +568,34 @@ impl TilingLayout { } else { tree.insert(new_window, InsertBehavior::AsRoot).unwrap() } + } else if let Some(ref node_id) = node { + let orientation = { + let window_size = tree.get(node_id).unwrap().data().geometry().size; + if window_size.w > window_size.h { + Orientation::Vertical + } else { + Orientation::Horizontal + } + }; + let new_id = tree.insert(new_window, InsertBehavior::AsRoot).unwrap(); + TilingLayout::new_group(tree, node_id, &new_id, orientation).unwrap(); + new_id } else { - if let Some(ref node_id) = node { + // nothing? then we add to the root + if let Some(root_id) = tree.root_node_id().cloned() { let orientation = { - let window_size = tree.get(node_id).unwrap().data().geometry().size; - if window_size.w > window_size.h { + let output_size = output.geometry().size; + if output_size.w > output_size.h { Orientation::Vertical } else { Orientation::Horizontal } }; let new_id = tree.insert(new_window, InsertBehavior::AsRoot).unwrap(); - TilingLayout::new_group(&mut tree, &node_id, &new_id, orientation).unwrap(); + TilingLayout::new_group(tree, &root_id, &new_id, orientation).unwrap(); new_id } else { - // nothing? then we add to the root - if let Some(root_id) = tree.root_node_id().cloned() { - let orientation = { - let output_size = output.geometry().size; - if output_size.w > output_size.h { - Orientation::Vertical - } else { - Orientation::Horizontal - } - }; - let new_id = tree.insert(new_window, InsertBehavior::AsRoot).unwrap(); - TilingLayout::new_group(&mut tree, &root_id, &new_id, orientation).unwrap(); - new_id - } else { - tree.insert(new_window, InsertBehavior::AsRoot).unwrap() - } + tree.insert(new_window, InsertBehavior::AsRoot).unwrap() } }; @@ -660,7 +655,7 @@ impl TilingLayout { let this_stack = this_mapped.stack_ref()?; this_stack.remove_window(&stack_surface); if !this_stack.alive() { - this.unmap(&this_mapped); + this.unmap(this_mapped); } let mapped: CosmicMapped = @@ -681,13 +676,13 @@ impl TilingLayout { mapped.set_tiled(true); other.map(mapped.clone(), Some(focus_stack), direction); - return Some(KeyboardFocusTarget::Element(mapped)); + Some(KeyboardFocusTarget::Element(mapped)) } None => { let node = this_tree.get(&desc.node).ok()?; let mut children = node .children() - .into_iter() + .iter() .map(|child_id| (desc.node.clone(), child_id.clone())) .collect::>(); let node = Node::new(node.data().clone()); @@ -813,7 +808,7 @@ impl TilingLayout { .push_tree(other_tree, ANIMATION_DURATION, blocker); other.node_desc_to_focus(&NodeDesc { - handle: other_handle.clone(), + handle: *other_handle, node: id.clone(), stack_window: None, focus_stack: Vec::new(), // node_desc_to_focus doesn't use this @@ -909,12 +904,12 @@ impl TilingLayout { // swap children let mut this_children = this_node .children() - .into_iter() + .iter() .map(|child_id| (other_desc.node.clone(), child_id.clone())) .collect::>(); let mut other_children = other_node .children() - .into_iter() + .iter() .map(|child_id| (this_desc.node.clone(), child_id.clone())) .collect::>(); @@ -1064,7 +1059,7 @@ impl TilingLayout { toplevel_leave_workspace(this_surface, &this_desc.handle); toplevel_enter_workspace(this_surface, &other_desc.handle); } - this_stack.remove_window(&this_surface); + this_stack.remove_window(this_surface); let mapped: CosmicMapped = CosmicWindow::new( this_surface.clone(), @@ -1151,7 +1146,7 @@ impl TilingLayout { toplevel_leave_workspace(other_surface, &other_desc.handle); toplevel_enter_workspace(other_surface, &this_desc.handle); } - other_stack.remove_window(&other_surface); + other_stack.remove_window(other_surface); let mapped: CosmicMapped = CosmicWindow::new( other_surface.clone(), @@ -1212,7 +1207,7 @@ impl TilingLayout { let this_was_active = &this_stack.active() == this_surface; let other_was_active = &other_stack.active() == other_surface; this_stack.add_window(other_surface.clone(), Some(this_idx)); - this_stack.remove_window(&this_surface); + this_stack.remove_window(this_surface); other_stack.add_window(this_surface.clone(), Some(other_idx)); if this.output != other_output { @@ -1228,12 +1223,12 @@ impl TilingLayout { toplevel_enter_workspace(other_surface, &this_desc.handle); } - other_stack.remove_window(&other_surface); + other_stack.remove_window(other_surface); if this_was_active { - this_stack.set_active(&other_surface); + this_stack.set_active(other_surface); } if other_was_active { - other_stack.set_active(&this_surface); + other_stack.set_active(this_surface); } return other @@ -1260,12 +1255,12 @@ impl TilingLayout { } match (&this_desc.stack_window, &other_desc.stack_window) { - (None, None) if !has_other_tree => this.node_desc_to_focus(&this_desc), + (None, None) if !has_other_tree => this.node_desc_to_focus(this_desc), //(None, Some(_)) => None, _ => other .as_ref() .unwrap_or(&this) - .node_desc_to_focus(&other_desc), + .node_desc_to_focus(other_desc), } } @@ -1315,7 +1310,7 @@ impl TilingLayout { .unwrap() .data_mut(); *data = Data::Placeholder { - last_geometry: data.geometry().clone(), + last_geometry: *data.geometry(), initial_placeholder: true, }; @@ -1333,7 +1328,7 @@ impl TilingLayout { let state = { let tree = &self.queue.trees.back().unwrap().0; tree.get(&node_id).unwrap().parent().and_then(|parent_id| { - let parent = tree.get(&parent_id).unwrap(); + let parent = tree.get(parent_id).unwrap(); let idx = parent .children() .iter() @@ -1347,7 +1342,7 @@ impl TilingLayout { // this group will be flattened Some(MinimizedTilingState { parent: None, - sibling: parent.children().iter().cloned().find(|id| id != &node_id), + sibling: parent.children().iter().find(|&id| id != &node_id).cloned(), orientation: *orientation, idx, sizes: sizes.clone(), @@ -1423,7 +1418,7 @@ impl TilingLayout { fn unmap_internal(tree: &mut Tree, node: &NodeId) { let parent_id = tree.get(node).ok().and_then(|node| node.parent()).cloned(); let position = parent_id.as_ref().and_then(|parent_id| { - tree.children_ids(&parent_id) + tree.children_ids(parent_id) .unwrap() .position(|id| id == node) }); @@ -1439,35 +1434,32 @@ impl TilingLayout { let _ = tree.remove_node(node.clone(), RemoveBehavior::DropChildren); // fixup parent node - match parent_id { - Some(id) => { - let position = position.unwrap(); - let group = tree.get_mut(&id).unwrap().data_mut(); - assert!(group.is_group()); - - if group.len() > 2 { - group.remove_window(position); - } else { - trace!("Removing Group"); - let other_child = tree.children_ids(&id).unwrap().next().cloned().unwrap(); - let fork_pos = parent_parent_id.as_ref().and_then(|parent_id| { - tree.children_ids(parent_id).unwrap().position(|i| i == &id) - }); - let _ = tree.remove_node(id.clone(), RemoveBehavior::OrphanChildren); - tree.move_node( - &other_child, - parent_parent_id - .as_ref() - .map(|parent_id| MoveBehavior::ToParent(parent_id)) - .unwrap_or(MoveBehavior::ToRoot), - ) - .unwrap(); - if let Some(old_pos) = fork_pos { - tree.make_nth_sibling(&other_child, old_pos).unwrap(); - } + if let Some(id) = parent_id { + let position = position.unwrap(); + let group = tree.get_mut(&id).unwrap().data_mut(); + assert!(group.is_group()); + + if group.len() > 2 { + group.remove_window(position); + } else { + trace!("Removing Group"); + let other_child = tree.children_ids(&id).unwrap().next().cloned().unwrap(); + let fork_pos = parent_parent_id.as_ref().and_then(|parent_id| { + tree.children_ids(parent_id).unwrap().position(|i| i == &id) + }); + let _ = tree.remove_node(id.clone(), RemoveBehavior::OrphanChildren); + tree.move_node( + &other_child, + parent_parent_id + .as_ref() + .map(MoveBehavior::ToParent) + .unwrap_or(MoveBehavior::ToRoot), + ) + .unwrap(); + if let Some(old_pos) = fork_pos { + tree.make_nth_sibling(&other_child, old_pos).unwrap(); } } - None => {} // root } } @@ -1492,7 +1484,7 @@ impl TilingLayout { let Some(target) = seat.get_keyboard().unwrap().current_focus() else { return MoveResult::None; }; - let Some((node_id, data)) = TilingLayout::currently_focused_node(&mut tree, target) else { + let Some((node_id, data)) = TilingLayout::currently_focused_node(&tree, target) else { return MoveResult::None; }; @@ -1724,8 +1716,7 @@ impl TilingLayout { let old_id = tree .children_ids(&next_child_id) .unwrap() - .skip(group_len / 2) - .next() + .nth(group_len / 2) .unwrap() .clone(); TilingLayout::new_group( @@ -1884,7 +1875,7 @@ impl TilingLayout { let mut node_id = last_node_id.clone(); while let Some(group) = tree.get(&node_id).unwrap().parent() { let child = node_id.clone(); - let group_data = tree.get(&group).unwrap().data(); + let group_data = tree.get(group).unwrap().data(); let main_orientation = group_data.orientation(); assert!(group_data.is_group()); @@ -1905,7 +1896,7 @@ impl TilingLayout { WindowGroup { node: group.clone(), alive: match group_data { - &Data::Group { ref alive, .. } => Arc::downgrade(alive), + Data::Group { alive, .. } => Arc::downgrade(alive), _ => unreachable!(), }, focus_stack: match data { @@ -1922,7 +1913,7 @@ impl TilingLayout { // which child are we? let idx = tree - .children_ids(&group) + .children_ids(group) .unwrap() .position(|id| id == &child) .unwrap(); @@ -1933,13 +1924,13 @@ impl TilingLayout { | (Orientation::Vertical, FocusDirection::Right) if idx < (len - 1) => { - tree.children_ids(&group).unwrap().skip(idx + 1).next() + tree.children_ids(group).unwrap().nth(idx + 1) } (Orientation::Horizontal, FocusDirection::Up) | (Orientation::Vertical, FocusDirection::Left) if idx > 0 => { - tree.children_ids(&group).unwrap().skip(idx - 1).next() + tree.children_ids(group).unwrap().nth(idx - 1) } _ => None, // continue iterating }; @@ -1962,7 +1953,7 @@ impl TilingLayout { Data::Group { alive, .. } => { FocusResult::Some(KeyboardFocusTarget::Group(WindowGroup { node: replacement_id.clone(), - alive: Arc::downgrade(&alive), + alive: Arc::downgrade(alive), focus_stack: tree .children_ids(replacement_id) .unwrap() @@ -2124,9 +2115,7 @@ impl TilingLayout { ) -> Option { let gaps = self.gaps(); - let Some(node_id) = mapped.tiling_node_id.lock().unwrap().clone() else { - return None; - }; + let node_id = mapped.tiling_node_id.lock().unwrap().clone()?; let mut tree = self.queue.trees.back().unwrap().0.copy_clone(); if tree.get(&node_id).is_err() { @@ -2138,7 +2127,7 @@ impl TilingLayout { match tree.get_mut(&node_id).unwrap().data_mut() { Data::Mapped { mapped, .. } => { mapped.convert_to_stack((&self.output, mapped.bbox()), self.theme.clone()); - focus_stack.append(&mapped); + focus_stack.append(mapped); KeyboardFocusTarget::Element(mapped.clone()) } _ => unreachable!(), @@ -2241,9 +2230,7 @@ impl TilingLayout { ) -> Option { let gaps = self.gaps(); - let Some(target) = seat.get_keyboard().unwrap().current_focus() else { - return None; - }; + let target = seat.get_keyboard().unwrap().current_focus()?; let mut tree = self.queue.trees.back().unwrap().0.copy_clone(); if let Some((last_active, last_active_data)) = @@ -2646,7 +2633,7 @@ impl TilingLayout { } let mapped = match self.last_overview_hover.as_ref().map(|x| &x.1) { - Some(TargetZone::GroupEdge(group_id, direction)) if tree.get(&group_id).is_ok() => { + Some(TargetZone::GroupEdge(group_id, direction)) if tree.get(group_id).is_ok() => { let new_id = tree .insert( Node::new(Data::Mapped { @@ -2664,7 +2651,7 @@ impl TilingLayout { Orientation::Horizontal }; if tree.get(group_id).unwrap().data().orientation() != orientation { - TilingLayout::new_group(&mut tree, &group_id, &new_id, orientation).unwrap(); + TilingLayout::new_group(&mut tree, group_id, &new_id, orientation).unwrap(); } else { let data = tree.get_mut(group_id).unwrap().data_mut(); let len = data.len(); @@ -2682,7 +2669,7 @@ impl TilingLayout { *window.tiling_node_id.lock().unwrap() = Some(new_id); window } - Some(TargetZone::GroupInterior(group_id, idx)) if tree.get(&group_id).is_ok() => { + Some(TargetZone::GroupInterior(group_id, idx)) if tree.get(group_id).is_ok() => { let new_id = tree .insert( Node::new(Data::Mapped { @@ -2703,9 +2690,9 @@ impl TilingLayout { *window.tiling_node_id.lock().unwrap() = Some(new_id); window } - Some(TargetZone::InitialPlaceholder(node_id)) if tree.get(&node_id).is_ok() => { - let data = tree.get_mut(&node_id).unwrap().data_mut(); - let geo = data.geometry().clone(); + Some(TargetZone::InitialPlaceholder(node_id)) if tree.get(node_id).is_ok() => { + let data = tree.get_mut(node_id).unwrap().data_mut(); + let geo = *data.geometry(); *data = Data::Mapped { mapped: window.clone(), @@ -2715,7 +2702,7 @@ impl TilingLayout { *window.tiling_node_id.lock().unwrap() = Some(node_id.clone()); window } - Some(TargetZone::WindowSplit(window_id, direction)) if tree.get(&window_id).is_ok() => { + Some(TargetZone::WindowSplit(window_id, direction)) if tree.get(window_id).is_ok() => { let new_id = tree .insert( Node::new(Data::Mapped { @@ -2723,7 +2710,7 @@ impl TilingLayout { last_geometry: Rectangle::from_loc_and_size((0, 0), (100, 100)), minimize_rect: None, }), - InsertBehavior::UnderNode(&window_id), + InsertBehavior::UnderNode(window_id), ) .unwrap(); let orientation = if matches!(direction, Direction::Left | Direction::Right) { @@ -2731,14 +2718,14 @@ impl TilingLayout { } else { Orientation::Horizontal }; - TilingLayout::new_group(&mut tree, &window_id, &new_id, orientation).unwrap(); + TilingLayout::new_group(&mut tree, window_id, &new_id, orientation).unwrap(); if matches!(direction, Direction::Left | Direction::Up) { tree.make_first_sibling(&new_id).unwrap(); } *window.tiling_node_id.lock().unwrap() = Some(new_id.clone()); window } - Some(TargetZone::WindowStack(window_id, _)) if tree.get(&window_id).is_ok() => { + Some(TargetZone::WindowStack(window_id, _)) if tree.get(window_id).is_ok() => { match tree.get_mut(window_id).unwrap().data_mut() { Data::Mapped { mapped, .. } => { mapped.convert_to_stack((&self.output, mapped.bbox()), self.theme.clone()); @@ -2962,9 +2949,7 @@ impl TilingLayout { let mut configures = Vec::new(); let (outer, inner) = gaps; - let mut geo = layer_map_for_output(&output) - .non_exclusive_zone() - .as_local(); + let mut geo = layer_map_for_output(output).non_exclusive_zone().as_local(); geo.loc.x += outer; geo.loc.y += outer; geo.size.w -= outer * 2; @@ -3079,7 +3064,7 @@ impl TilingLayout { Data::Mapped { mapped, .. } => { if !(mapped.is_fullscreen(true) || mapped.is_maximized(true)) { mapped.set_tiled(true); - let internal_geometry = geo.to_global(&output); + let internal_geometry = geo.to_global(output); mapped.set_geometry(internal_geometry); if let Some(serial) = mapped.configure() { configures.push((mapped.active_window(), serial)); @@ -3291,8 +3276,7 @@ impl TilingLayout { + tree .children(&id) .unwrap() - .skip(idx) - .next() + .nth(idx) .map(|node| { let geo = node.data().geometry(); geo.loc + geo.size @@ -3616,14 +3600,16 @@ impl TilingLayout { None, tree.traverse_pre_order_ids(root) .unwrap() - .find(|id| match tree.get(id).unwrap().data() { - Data::Placeholder { - initial_placeholder: true, - .. - } => true, - _ => false, + .find(|id| { + matches!( + tree.get(id).unwrap().data(), + Data::Placeholder { + initial_placeholder: true, + .. + } + ) }) - .map(|node_id| TargetZone::InitialPlaceholder(node_id)) + .map(TargetZone::InitialPlaceholder) .unwrap_or(TargetZone::Initial), )); } @@ -3660,14 +3646,14 @@ impl TilingLayout { let removed = if let TargetZone::InitialPlaceholder(node_id) = old_target_zone { - if tree.get(&node_id).is_ok() { - TilingLayout::unmap_internal(&mut tree, &node_id); + if tree.get(node_id).is_ok() { + TilingLayout::unmap_internal(&mut tree, node_id); } true } else if let TargetZone::WindowSplit(node_id, _) = old_target_zone { if let Some(children) = tree - .get(&node_id) + .get(node_id) .ok() .and_then(|node| node.parent()) .and_then(|parent_id| tree.get(parent_id).ok()) @@ -3690,7 +3676,7 @@ impl TilingLayout { } true } else if let TargetZone::GroupEdge(node_id, _) = old_target_zone { - if let Ok(node) = tree.get_mut(&node_id) { + if let Ok(node) = tree.get_mut(node_id) { match node.data_mut() { Data::Group { pill_indicator, .. } => { *pill_indicator = None; @@ -3702,7 +3688,7 @@ impl TilingLayout { } else if let TargetZone::GroupInterior(node_id, _) = old_target_zone { - if let Ok(node) = tree.get_mut(&node_id) { + if let Ok(node) = tree.get_mut(node_id) { match node.data_mut() { Data::Group { pill_indicator, .. } => { *pill_indicator = None; @@ -3737,7 +3723,7 @@ impl TilingLayout { } else { Orientation::Horizontal }; - TilingLayout::new_group(&mut tree, &node_id, &id, orientation) + TilingLayout::new_group(&mut tree, node_id, &id, orientation) .unwrap(); if matches!(dir, Direction::Left | Direction::Up) { tree.make_first_sibling(&id).unwrap(); @@ -3747,7 +3733,7 @@ impl TilingLayout { } else if let TargetZone::GroupEdge(node_id, direction) = &target_zone { - if let Ok(node) = tree.get_mut(&node_id) { + if let Ok(node) = tree.get_mut(node_id) { match node.data_mut() { Data::Group { pill_indicator, .. } => { *pill_indicator = @@ -3761,7 +3747,7 @@ impl TilingLayout { } } else if let TargetZone::GroupInterior(node_id, idx) = &target_zone { - if let Ok(node) = tree.get_mut(&node_id) { + if let Ok(node) = tree.get_mut(node_id) { match node.data_mut() { Data::Group { pill_indicator, .. } => { *pill_indicator = Some(PillIndicator::Inner(*idx)); @@ -3799,44 +3785,40 @@ impl TilingLayout { pub fn mapped(&self) -> impl Iterator)> { let tree = &self.queue.trees.back().unwrap().0; - let iter = if let Some(root) = tree.root_node_id() { - Some( - tree.traverse_pre_order(root) - .unwrap() - .filter(|node| node.data().is_mapped(None)) - .filter(|node| match node.data() { - Data::Mapped { mapped, .. } => mapped.is_activated(false), - _ => unreachable!(), - }) - .map(|node| match node.data() { - Data::Mapped { - mapped, - last_geometry, - .. - } => (mapped, last_geometry.clone()), - _ => unreachable!(), - }) - .chain( - tree.traverse_pre_order(root) - .unwrap() - .filter(|node| node.data().is_mapped(None)) - .filter(|node| match node.data() { - Data::Mapped { mapped, .. } => !mapped.is_activated(false), - _ => unreachable!(), - }) - .map(|node| match node.data() { - Data::Mapped { - mapped, - last_geometry, - .. - } => (mapped, last_geometry.clone()), - _ => unreachable!(), - }), - ), - ) - } else { - None - }; + let iter = tree.root_node_id().map(|root| { + tree.traverse_pre_order(root) + .unwrap() + .filter(|node| node.data().is_mapped(None)) + .filter(|node| match node.data() { + Data::Mapped { mapped, .. } => mapped.is_activated(false), + _ => unreachable!(), + }) + .map(|node| match node.data() { + Data::Mapped { + mapped, + last_geometry, + .. + } => (mapped, *last_geometry), + _ => unreachable!(), + }) + .chain( + tree.traverse_pre_order(root) + .unwrap() + .filter(|node| node.data().is_mapped(None)) + .filter(|node| match node.data() { + Data::Mapped { mapped, .. } => !mapped.is_activated(false), + _ => unreachable!(), + }) + .map(|node| match node.data() { + Data::Mapped { + mapped, + last_geometry, + .. + } => (mapped, *last_geometry), + _ => unreachable!(), + }), + ) + }); iter.into_iter().flatten() } @@ -3844,7 +3826,7 @@ impl TilingLayout { self.mapped().flat_map(|(mapped, geo)| { mapped.windows().map(move |(w, p)| { (w, { - let mut geo = geo.clone(); + let mut geo = geo; geo.loc += p.as_local(); geo.size -= p.to_size().as_local(); geo @@ -3909,7 +3891,7 @@ impl TilingLayout { while let Some((src_id, dst_id)) = stack.pop() { for child_id in src.children_ids(&src_id).unwrap() { - let src_node = src.get(&child_id).unwrap(); + let src_node = src.get(child_id).unwrap(); let new_node = Node::new(src_node.data().clone()); let new_child_id = dst .insert(new_node, InsertBehavior::UnderNode(&dst_id)) @@ -3996,7 +3978,7 @@ impl TilingLayout { &self.placeholder_id, is_mouse_tiling, swap_desc.clone(), - overview.1.as_ref().and_then(|(_, tree)| tree.clone()), + overview.1.as_ref().and_then(|(_, tree)| *tree), theme, )) } else { @@ -4034,7 +4016,7 @@ impl TilingLayout { &self.placeholder_id, is_mouse_tiling, swap_desc.clone(), - overview.1.as_ref().and_then(|(_, tree)| tree.clone()), + overview.1.as_ref().and_then(|(_, tree)| *tree), theme, )) } else { @@ -4147,7 +4129,7 @@ impl TilingLayout { &self.placeholder_id, is_mouse_tiling, swap_desc.clone(), - overview.1.as_ref().and_then(|(_, tree)| tree.clone()), + overview.1.as_ref().and_then(|(_, tree)| *tree), theme, )) } else { @@ -4183,7 +4165,7 @@ impl TilingLayout { &self.placeholder_id, is_mouse_tiling, swap_desc.clone(), - overview.1.as_ref().and_then(|(_, tree)| tree.clone()), + overview.1.as_ref().and_then(|(_, tree)| *tree), theme, )) } else { @@ -4299,14 +4281,12 @@ where seat.get_keyboard() .unwrap() .current_focus() - .and_then(|target| TilingLayout::currently_focused_node(&tree, target)) + .and_then(|target| TilingLayout::currently_focused_node(tree, target)) }) .map(|(id, _)| id); - let focused_geo = if let Some(focused_id) = focused.as_ref() { - Some(*tree.get(focused_id).unwrap().data().geometry()) - } else { - None - }; + let focused_geo = focused + .as_ref() + .map(|focused_id| *tree.get(focused_id).unwrap().data().geometry()); let has_potential_groups = if let Some(focused_id) = focused.as_ref() { let focused_node = tree.get(focused_id).unwrap(); @@ -4485,7 +4465,7 @@ where .parent() .map(|parent_id| { matches!( - tree.get(&parent_id).unwrap().data(), + tree.get(parent_id).unwrap().data(), Data::Group { pill_indicator: Some(_), .. @@ -4612,7 +4592,7 @@ where }; } - if matches!(swap_desc, Some(ref desc) if &desc.node == &node_id) { + if matches!(swap_desc, Some(ref desc) if desc.node == node_id) { if let Some(renderer) = renderer.as_mut() { elements.push( BackdropShader::element( @@ -4838,7 +4818,7 @@ where geo.size -= (WINDOW_BACKDROP_GAP * 2, WINDOW_BACKDROP_GAP * 2).into(); } - if matches!(swap_desc, Some(ref desc) if &desc.node == &node_id && desc.stack_window.is_none()) + if matches!(swap_desc, Some(ref desc) if desc.node == node_id && desc.stack_window.is_none()) { let swap_geo = swap_geometry( geo.size.as_logical(), @@ -5072,8 +5052,8 @@ fn render_old_tree( } let (scale, offset) = scaled_geo - .map(|adapted_geo| scale_to_center(&original_geo, &adapted_geo)) - .unwrap_or_else(|| (1.0.into(), (0, 0).into())); + .map(|adapted_geo| scale_to_center(original_geo, &adapted_geo)) + .unwrap_or_else(|| (1.0, (0, 0).into())); let geo = scaled_geo .map(|adapted_geo| { Rectangle::from_loc_and_size( @@ -5189,7 +5169,7 @@ where seat.get_keyboard() .unwrap() .current_focus() - .and_then(|target| TilingLayout::currently_focused_node(&target_tree, target)) + .and_then(|target| TilingLayout::currently_focused_node(target_tree, target)) }) .map(|(id, _)| id); let focused_geo = if let Some(focused) = focused.as_ref() { @@ -5258,7 +5238,7 @@ where let swap_geo = ease( Linear, EaseRectangle({ - let mut geo = focused_geo.clone(); + let mut geo = focused_geo; geo.loc.x += STACK_TAB_HEIGHT; geo.size.h -= STACK_TAB_HEIGHT; geo @@ -5322,7 +5302,7 @@ where || focused.as_ref() == Some(&node_id) { if indicator_thickness > 0 || data.is_group() { - let mut geo = geo.clone(); + let mut geo = geo; if data.is_group() { let outer_gap: i32 = (if is_overview { GAP_KEYBOARD } else { 4 } as f32 @@ -5410,7 +5390,7 @@ where } if let Some((mode, resize)) = resize_indicator.as_mut() { - let mut geo = geo.clone(); + let mut geo = geo; geo.loc -= (18, 18).into(); geo.size += (36, 36).into(); @@ -5544,7 +5524,7 @@ where if swap_desc .as_ref() .map(|swap_desc| { - (&swap_desc.node == &node_id + (swap_desc.node == node_id || target_tree .ancestor_ids(&node_id) .unwrap() @@ -5554,12 +5534,10 @@ where .unwrap_or(false) { swap_elements.extend(elements); + } else if animating { + animating_window_elements.extend(elements); } else { - if animating { - animating_window_elements.extend(elements); - } else { - window_elements.extend(elements); - } + window_elements.extend(elements); } } }, @@ -5638,7 +5616,7 @@ fn render_new_tree( let (scale, offset) = old_scaled_geo .unwrap() .map(|adapted_geo| scale_to_center(original_geo, adapted_geo)) - .unwrap_or_else(|| (1.0.into(), (0, 0).into())); + .unwrap_or_else(|| (1.0, (0, 0).into())); ( old_scaled_geo .unwrap() @@ -5669,7 +5647,7 @@ fn render_new_tree( let (scale, offset) = scaled_geo .map(|adapted_geo| scale_to_center(original_geo, adapted_geo)) - .unwrap_or_else(|| (1.0.into(), (0, 0).into())); + .unwrap_or_else(|| (1.0, (0, 0).into())); let new_geo = scaled_geo .map(|adapted_geo| { Rectangle::from_loc_and_size( diff --git a/src/shell/mod.rs b/src/shell/mod.rs index 28b87e61..70ae1841 100644 --- a/src/shell/mod.rs +++ b/src/shell/mod.rs @@ -155,7 +155,7 @@ impl OverviewMode { } pub fn trigger(&self) -> Option<&Trigger> { - self.active_trigger().or_else(|| { + self.active_trigger().or({ if let OverviewMode::Ended(trigger, _) = self { trigger.as_ref() } else { @@ -329,7 +329,7 @@ fn create_workspace( ) -> Workspace { let workspace_handle = state .create_workspace( - &group_handle, + group_handle, if tiling { TilingState::TilingEnabled } else { @@ -500,7 +500,7 @@ impl WorkspaceSet { self.sticky_layer.set_output(new_output); for window in self.sticky_layer.windows() { toplevel_leave_output(&window, &self.output); - toplevel_enter_output(&window, &new_output); + toplevel_enter_output(&window, new_output); } for workspace in &mut self.workspaces { workspace.set_output(new_output); @@ -580,7 +580,7 @@ impl WorkspaceSet { .filter(|keep| !**keep) .count(); - if keep.iter().any(|val| *val == false) { + if keep.iter().any(|val| !(*val)) { for (i, workspace) in self.workspaces.iter().enumerate() { workspace_set_idx(state, i as u8 + 1, self.idx, &workspace.handle); } @@ -639,13 +639,13 @@ impl Workspaces { .unwrap_or_else(|| { WorkspaceSet::new( workspace_state, - &output, + output, self.sets.len(), self.autotile, self.theme.clone(), ) }); - workspace_state.add_group_output(&set.group, &output); + workspace_state.add_group_output(&set.group, output); // Remove workspaces that prefer this output from other sets let mut moved_workspaces = Vec::new(); @@ -916,14 +916,14 @@ impl Workspaces { let len = self.sets[0].workspaces.len(); let mut active = self.sets[0].active; let mut keep = vec![true; len]; - for i in 0..len { + for (i, kp) in keep.iter_mut().enumerate() { let has_windows = self.sets.values().any(|s| !s.workspaces[i].is_empty()); if !has_windows && i != active && i != len - 1 { for workspace in self.sets.values().map(|s| &s.workspaces[i]) { workspace_state.remove_workspace(workspace.handle); } - keep[i] = false; + *kp = false; } } @@ -936,7 +936,7 @@ impl Workspaces { s.active = active; }); - if keep.iter().any(|val| *val == false) { + if keep.iter().any(|val| !(*val)) { for set in self.sets.values_mut() { for (i, workspace) in set.workspaces.iter().enumerate() { workspace_set_idx( @@ -1360,32 +1360,21 @@ impl Shell { ) { set.workspaces[set.active].tiling_layer.cleanup_drag(); } - if let Some((_, workspace_delta)) = set.previously_active { - match workspace_delta { - WorkspaceDelta::Gesture(delta) => { - if (velocity > 0.0 && velocity.abs() >= GESTURE_VELOCITY_THRESHOLD) - || (velocity.abs() < GESTURE_VELOCITY_THRESHOLD - && delta.abs() > GESTURE_POSITION_THRESHOLD) - { - set.activate( - set.active, - WorkspaceDelta::new_gesture_end( - delta.abs(), - velocity.abs(), - ), - workspace_state, - )?; - } else { - set.activate_previous( - WorkspaceDelta::new_gesture_end( - 1.0 - delta.abs(), - velocity.abs(), - ), - workspace_state, - )?; - } - } - _ => {} // Do nothing + if let Some((_, WorkspaceDelta::Gesture(delta))) = set.previously_active { + if (velocity > 0.0 && velocity.abs() >= GESTURE_VELOCITY_THRESHOLD) + || (velocity.abs() < GESTURE_VELOCITY_THRESHOLD + && delta.abs() > GESTURE_POSITION_THRESHOLD) + { + set.activate( + set.active, + WorkspaceDelta::new_gesture_end(delta.abs(), velocity.abs()), + workspace_state, + )?; + } else { + set.activate_previous( + WorkspaceDelta::new_gesture_end(1.0 - delta.abs(), velocity.abs()), + workspace_state, + )?; } } @@ -1400,32 +1389,21 @@ impl Shell { } WorkspaceMode::Global => { for set in self.workspaces.sets.values_mut() { - if let Some((_, workspace_delta)) = set.previously_active { - match workspace_delta { - WorkspaceDelta::Gesture(delta) => { - if (velocity > 0.0 && velocity.abs() >= GESTURE_VELOCITY_THRESHOLD) - || (velocity.abs() < GESTURE_VELOCITY_THRESHOLD - && delta.abs() > GESTURE_POSITION_THRESHOLD) - { - set.activate( - set.active, - WorkspaceDelta::new_gesture_end( - delta.abs(), - velocity.abs(), - ), - workspace_state, - )?; - } else { - set.activate_previous( - WorkspaceDelta::new_gesture_end( - 1.0 - delta.abs(), - velocity.abs(), - ), - workspace_state, - )?; - } - } - _ => {} // Do nothing + if let Some((_, WorkspaceDelta::Gesture(delta))) = set.previously_active { + if (velocity > 0.0 && velocity.abs() >= GESTURE_VELOCITY_THRESHOLD) + || (velocity.abs() < GESTURE_VELOCITY_THRESHOLD + && delta.abs() > GESTURE_POSITION_THRESHOLD) + { + set.activate( + set.active, + WorkspaceDelta::new_gesture_end(delta.abs(), velocity.abs()), + workspace_state, + )?; + } else { + set.activate_previous( + WorkspaceDelta::new_gesture_end(1.0 - delta.abs(), velocity.abs()), + workspace_state, + )?; } } } @@ -1504,7 +1482,7 @@ impl Shell { KeyboardFocusTarget::Fullscreen(elem) => self .outputs() .find(|output| { - let workspace = self.active_space(&output); + let workspace = self.active_space(output); workspace.get_fullscreen() == Some(&elem) }) .cloned(), @@ -1512,7 +1490,7 @@ impl Shell { .outputs() .find(|output| { self.workspaces - .active(&output) + .active(output) .1 .tiling_layer .has_node(&node) @@ -1561,11 +1539,8 @@ impl Shell { pub fn close_focused(&self, focus_target: &KeyboardFocusTarget) { if let KeyboardFocusTarget::Group(_group) = focus_target { //TODO: decide if we want close actions to apply to groups - return; - } else { - if let Some(mapped) = self.focused_element(focus_target) { - mapped.send_close(); - } + } else if let Some(mapped) = self.focused_element(focus_target) { + mapped.send_close(); } } @@ -1651,7 +1626,7 @@ impl Shell { .workspaces .spaces() .find(move |workspace| workspace.output() == output) - .map(|w| (w.handle.clone(), output.clone())), + .map(|w| (w.handle, output.clone())), None => self .workspaces .spaces() @@ -1662,7 +1637,7 @@ impl Shell { .iter() .any(|m| m.window.has_surface(surface, WindowSurfaceType::ALL)) }) - .map(|w| (w.handle.clone(), w.output().clone())), + .map(|w| (w.handle, w.output().clone())), } } @@ -1806,24 +1781,21 @@ impl Shell { } self.overview_mode = OverviewMode::Started(trigger, Instant::now()); } - } else { - if matches!( - self.overview_mode, - OverviewMode::Started(_, _) | OverviewMode::Active(_) - ) { - let (reverse_duration, trigger) = - if let OverviewMode::Started(trigger, start) = self.overview_mode.clone() { - ( - ANIMATION_DURATION - - Instant::now().duration_since(start).min(ANIMATION_DURATION), - Some(trigger), - ) - } else { - (Duration::ZERO, self.overview_mode.active_trigger().cloned()) - }; - self.overview_mode = - OverviewMode::Ended(trigger, Instant::now() - reverse_duration); - } + } else if matches!( + self.overview_mode, + OverviewMode::Started(_, _) | OverviewMode::Active(_) + ) { + let (reverse_duration, trigger) = + if let OverviewMode::Started(trigger, start) = self.overview_mode.clone() { + ( + ANIMATION_DURATION + - Instant::now().duration_since(start).min(ANIMATION_DURATION), + Some(trigger), + ) + } else { + (Duration::ZERO, self.overview_mode.active_trigger().cloned()) + }; + self.overview_mode = OverviewMode::Ended(trigger, Instant::now() - reverse_duration); } } @@ -1864,12 +1836,10 @@ impl Shell { evlh, self.theme.clone(), )); - } else { - if let Some(direction) = self.resize_mode.active_direction() { - self.resize_mode = ResizeMode::Ended(Instant::now(), direction); - if let Some((_, direction, edge, _, _, _)) = self.resize_state.as_ref() { - self.finish_resize(*direction, *edge); - } + } else if let Some(direction) = self.resize_mode.active_direction() { + self.resize_mode = ResizeMode::Ended(Instant::now(), direction); + if let Some((_, direction, edge, _, _, _)) = self.resize_state.as_ref() { + self.finish_resize(*direction, *edge); } } } @@ -2000,7 +1970,7 @@ impl Shell { } { - let Some(workspace) = self.workspaces.space_for_handle_mut(¤t_workspace) else { + let Some(workspace) = self.workspaces.space_for_handle_mut(current_workspace) else { return; }; let _ = workspace.unmap(&mapped); @@ -2008,18 +1978,18 @@ impl Shell { let new_workspace_output = self .workspaces - .space_for_handle(&previous_workspace) + .space_for_handle(previous_workspace) .unwrap() .output() .clone(); for (window, _) in mapped.windows() { toplevel_enter_output(&window, &new_workspace_output); - toplevel_enter_workspace(&window, &previous_workspace); + toplevel_enter_workspace(&window, previous_workspace); } let new_workspace = self .workspaces - .space_for_handle_mut(&previous_workspace) + .space_for_handle_mut(previous_workspace) .unwrap(); match target_layer { ManagedLayer::Sticky => { @@ -2099,13 +2069,16 @@ impl Shell { } if let Some((mapped, layer, previous_workspace)) = workspace.remove_fullscreen() { - let old_handle = workspace.handle.clone(); - let new_workspace_handle = self + let old_handle = workspace.handle; + let new_workspace_handle = if self .workspaces .space_for_handle(&previous_workspace) .is_some() - .then_some(previous_workspace) - .unwrap_or(old_handle); + { + previous_workspace + } else { + old_handle + }; self.remap_unfullscreened_window(mapped, &old_handle, &new_workspace_handle, layer); }; @@ -2289,7 +2262,7 @@ impl Shell { Some(set.minimized_windows.remove(idx).window.active_window()) } } else if let Some((workspace, mut elem)) = set.workspaces.iter_mut().find_map(|w| { - w.element_for_surface(&surface) + w.element_for_surface(surface) .cloned() .map(|elem| (w, elem)) }) { @@ -2361,7 +2334,7 @@ impl Shell { let any_seat = seat.unwrap_or(self.seats.last_active()).clone(); let mut to_workspace = self.workspaces.space_for_handle_mut(to).unwrap(); // checked above - let focus_stack = seat.map(|seat| to_workspace.focus_stack.get(&seat)); + let focus_stack = seat.map(|seat| to_workspace.focus_stack.get(seat)); if window_state.layer == ManagedLayer::Floating || !to_workspace.tiling_enabled { to_workspace.floating_layer.map(mapped.clone(), None); } else { @@ -2376,13 +2349,16 @@ impl Shell { if to_workspace.fullscreen.is_some() { if let Some((mapped, layer, previous_workspace)) = to_workspace.remove_fullscreen() { - let old_handle = to.clone(); - let new_workspace_handle = self + let old_handle = *to; + let new_workspace_handle = if self .workspaces .space_for_handle(&previous_workspace) .is_some() - .then_some(previous_workspace) - .unwrap_or(old_handle); + { + previous_workspace + } else { + old_handle + }; self.remap_unfullscreened_window( mapped, @@ -2457,12 +2433,12 @@ impl Shell { node, focus_stack, .. })) => { let new_pos = if follow { - seat.set_active_output(&to_output); + seat.set_active_output(to_output); self.workspaces - .idx_for_handle(&to_output, &to) + .idx_for_handle(to_output, &to) .and_then(|to_idx| { self.activate( - &to_output, + to_output, to_idx, WorkspaceDelta::new_shortcut(), workspace_state, @@ -2478,7 +2454,7 @@ impl Shell { if let Some(from_workspace) = from_w.get_mut(0) { if let Some(to_workspace) = other_w.iter_mut().find(|w| w.handle == to) { { - let mut stack = to_workspace.focus_stack.get_mut(&seat); + let mut stack = to_workspace.focus_stack.get_mut(seat); for elem in focus_stack.iter().flat_map(|node_id| { from_workspace.tiling_layer.element_for_node(node_id) }) { @@ -2490,7 +2466,7 @@ impl Shell { &mut to_workspace.tiling_layer, &to, seat, - to_workspace.focus_stack.get(&seat).iter(), + to_workspace.focus_stack.get(seat).iter(), NodeDesc { handle: from, node, @@ -2557,7 +2533,7 @@ impl Shell { ) -> Option<(MenuGrab, Focus)> { let serial = serial.into(); let Some(GrabStartData::Pointer(start_data)) = - check_grab_preconditions(&seat, surface, serial, true) + check_grab_preconditions(seat, surface, serial, true) else { return None; }; @@ -2665,7 +2641,7 @@ impl Shell { ) -> Option<(MoveGrab, Focus)> { let serial = serial.into(); - let mut start_data = check_grab_preconditions(&seat, surface, serial, client_initiated)?; + let mut start_data = check_grab_preconditions(seat, surface, serial, client_initiated)?; let mut old_mapped = self.element_for_surface(surface).cloned()?; if old_mapped.is_minimized() { return None; @@ -2739,7 +2715,7 @@ impl Shell { None }; - let layer = if mapped == old_mapped { + let layer = if if mapped == old_mapped { let was_floating = workspace.floating_layer.unmap(&mapped); let was_tiled = workspace.tiling_layer.unmap_as_placeholder(&mapped); assert!(was_floating.is_some() != was_tiled.is_some()); @@ -2752,14 +2728,16 @@ impl Shell { .tiling_layer .mapped() .any(|(m, _)| m == &old_mapped) - } - .then_some(ManagedLayer::Tiling) - .unwrap_or(ManagedLayer::Floating); + } { + ManagedLayer::Tiling + } else { + ManagedLayer::Floating + }; // if this changed the width, the window was tiled in floating mode if let Some(new_size) = new_size { let output = workspace.output(); - let ratio = pos.to_local(&output).x / (elem_geo.loc.x + elem_geo.size.w) as f64; + let ratio = pos.to_local(output).x / (elem_geo.loc.x + elem_geo.size.w) as f64; initial_window_location = Point::from(( pos.x - (new_size.w as f64 * ratio), @@ -2878,9 +2856,9 @@ impl Shell { .unwrap() .to_global(&set.output); Some(geometry) - } else if let Some(workspace) = self.space_for(&mapped) { + } else if let Some(workspace) = self.space_for(mapped) { let geometry = workspace - .element_geometry(&mapped) + .element_geometry(mapped) .unwrap() .to_global(workspace.output()); Some(geometry) @@ -3043,11 +3021,7 @@ impl Shell { } #[must_use] - pub fn move_current_element<'a>( - &mut self, - direction: Direction, - seat: &Seat, - ) -> MoveResult { + pub fn move_current_element(&mut self, direction: Direction, seat: &Seat) -> MoveResult { let Some(output) = seat.focused_output() else { return MoveResult::None; }; @@ -3110,7 +3084,7 @@ impl Shell { return None; } - let mut start_data = check_grab_preconditions(&seat, &surface, None, false)?; + let mut start_data = check_grab_preconditions(seat, &surface, None, false)?; let (floating_layer, geometry) = if let Some(set) = self .workspaces @@ -3124,9 +3098,9 @@ impl Shell { .unwrap() .to_global(&set.output); (&mut set.sticky_layer, geometry) - } else if let Some(workspace) = self.space_for_mut(&mapped) { + } else if let Some(workspace) = self.space_for_mut(mapped) { let geometry = workspace - .element_geometry(&mapped) + .element_geometry(mapped) .unwrap() .to_global(workspace.output()); (&mut workspace.floating_layer, geometry) @@ -3167,7 +3141,7 @@ impl Shell { ReleaseMode::Click, ) { grab.into() - } else if let Some(ws) = self.space_for_mut(&mapped) { + } else if let Some(ws) = self.space_for_mut(mapped) { let node_id = mapped.tiling_node_id.lock().unwrap().clone()?; let (node, left_up_idx, orientation) = ws.tiling_layer.resize_request(node_id, edge)?; ResizeForkGrab::new( @@ -3219,7 +3193,7 @@ impl Shell { .find(|workspace| workspace.mapped().any(|m| m == mapped)) }) { let to = minimize_rectangle(workspace.output(), &mapped.active_window()); - if let Some(minimized) = workspace.minimize(&mapped, to) { + if let Some(minimized) = workspace.minimize(mapped, to) { workspace.minimized_windows.push(minimized); } } @@ -3275,8 +3249,8 @@ impl Shell { { let geometry = set.sticky_layer.element_geometry(mapped).unwrap(); (ManagedLayer::Sticky, &mut set.sticky_layer, geometry) - } else if let Some(workspace) = self.space_for_mut(&mapped) { - let layer = if workspace.is_floating(&mapped) { + } else if let Some(workspace) = self.space_for_mut(mapped) { + let layer = if workspace.is_floating(mapped) { ManagedLayer::Floating } else { ManagedLayer::Tiling @@ -3342,7 +3316,7 @@ impl Shell { client_initiated: bool, ) -> Option<(ResizeGrab, Focus)> { let serial = serial.into(); - let start_data = check_grab_preconditions(&seat, surface, serial, client_initiated)?; + let start_data = check_grab_preconditions(seat, surface, serial, client_initiated)?; let mapped = self.element_for_surface(surface).cloned()?; if mapped.is_fullscreen(true) || mapped.is_maximized(true) { return None; @@ -3494,9 +3468,7 @@ impl Shell { #[must_use] pub fn toggle_stacking_focused(&mut self, seat: &Seat) -> Option { - let Some(focused_output) = seat.focused_output() else { - return None; - }; + let focused_output = seat.focused_output()?; let set = self.workspaces.sets.get_mut(&focused_output).unwrap(); let workspace = &mut set.workspaces[set.active]; let maybe_window = workspace.focus_stack.get(seat).iter().next().cloned(); @@ -3593,7 +3565,7 @@ impl Shell { } } - self.append_focus_stack(&mapped, seat); + self.append_focus_stack(mapped, seat); } pub fn toggle_sticky_current(&mut self, seat: &Seat) { @@ -3616,7 +3588,7 @@ impl Shell { } let mut container = cosmic::config::COSMIC_TK.write().unwrap(); - if &*container != &toolkit { + if *container != toolkit { *container = toolkit; drop(container); self.refresh(xdg_activation_state, workspace_state); diff --git a/src/shell/seats.rs b/src/shell/seats.rs index 8fa33069..301f40b7 100644 --- a/src/shell/seats.rs +++ b/src/shell/seats.rs @@ -37,6 +37,12 @@ pub struct Seats { last_active: Option>, } +impl Default for Seats { + fn default() -> Self { + Self::new() + } +} + impl Seats { pub fn new() -> Seats { Seats { @@ -125,7 +131,7 @@ impl Devices { let mut map = self.capabilities.borrow_mut(); map.remove(&id) - .unwrap_or(Vec::new()) + .unwrap_or_default() .into_iter() .filter(|c| map.values().flatten().all(|has| *c != *has)) .collect() diff --git a/src/shell/workspace.rs b/src/shell/workspace.rs index 05e71538..c98a46c3 100644 --- a/src/shell/workspace.rs +++ b/src/shell/workspace.rs @@ -392,8 +392,8 @@ impl Workspace { let _ = self.unmaximize_request(mapped); } - let mut was_floating = self.floating_layer.unmap(&mapped).is_some(); - let mut was_tiling = self.tiling_layer.unmap(&mapped); + let mut was_floating = self.floating_layer.unmap(mapped).is_some(); + let mut was_tiling = self.tiling_layer.unmap(mapped); if was_floating || was_tiling { assert!(was_floating != was_tiling); } @@ -636,14 +636,14 @@ impl Workspace { match state.original_layer { ManagedLayer::Tiling if self.tiling_enabled => { // should still be mapped in tiling - self.floating_layer.unmap(&elem); + self.floating_layer.unmap(elem); elem.output_enter(&self.output, elem.bbox()); elem.set_maximized(false); elem.set_geometry(state.original_geometry.to_global(&self.output)); elem.configure(); self.tiling_layer.recalculate(); self.tiling_layer - .element_geometry(&elem) + .element_geometry(elem) .map(|geo| geo.size.as_logical()) } ManagedLayer::Sticky => unreachable!(), @@ -695,7 +695,7 @@ impl Workspace { }; if self.tiling_layer.mapped().any(|(m, _)| m == elem) { - let was_maximized = self.floating_layer.unmap(&elem).is_some(); + let was_maximized = self.floating_layer.unmap(elem).is_some(); let tiling_state = self.tiling_layer.unmap_minimize(elem, to); Some(MinimizedWindow { window: elem.clone(), @@ -759,22 +759,17 @@ impl Workspace { self.floating_layer .map_maximized(window.window, previous_geometry, true); } + } else if was_maximized { + self.floating_layer.map_maximized(window.window, from, true); } else { - if was_maximized { - self.floating_layer.map_maximized(window.window, from, true); - } else { - self.floating_layer.map(window.window.clone(), None); - // get the right animation - let geometry = self - .floating_layer - .element_geometry(&window.window) - .unwrap(); - self.floating_layer.remap_minimized( - window.window.clone(), - from, - geometry.loc, - ); - } + self.floating_layer.map(window.window.clone(), None); + // get the right animation + let geometry = self + .floating_layer + .element_geometry(&window.window) + .unwrap(); + self.floating_layer + .remap_minimized(window.window.clone(), from, geometry.loc); } } } @@ -985,9 +980,9 @@ impl Workspace { for window in floating_windows.iter().filter(|w| w.is_maximized(false)) { let original_geometry = { let state = window.maximized_state.lock().unwrap(); - state.as_ref().unwrap().original_geometry.clone() + state.as_ref().unwrap().original_geometry }; - self.unmaximize_request(&window); + self.unmaximize_request(window); maximized_windows.push((window.clone(), ManagedLayer::Tiling, original_geometry)); } @@ -1010,7 +1005,7 @@ impl Workspace { if window.is_maximized(false) { let original_geometry = { let state = window.maximized_state.lock().unwrap(); - state.as_ref().unwrap().original_geometry.clone() + state.as_ref().unwrap().original_geometry }; self.unmaximize_request(&window); maximized_windows.push(( @@ -1048,7 +1043,7 @@ impl Workspace { self.floating_layer.map(window.clone(), None); } else if self.floating_layer.mapped().any(|w| w == window) { let focus_stack = self.focus_stack.get(seat); - self.floating_layer.unmap(&window); + self.floating_layer.unmap(window); self.tiling_layer .map(window.clone(), Some(focus_stack.iter()), None) } @@ -1116,7 +1111,7 @@ impl Workspace { .unwrap() .clone() .map(|node_id| NodeDesc { - handle: self.handle.clone(), + handle: self.handle, node: node_id.clone(), stack_window: if mapped .stack_ref() @@ -1137,7 +1132,7 @@ impl Workspace { KeyboardFocusTarget::Group(WindowGroup { node, focus_stack, .. }) => Some(NodeDesc { - handle: self.handle.clone(), + handle: self.handle, node, stack_window: None, focus_stack, @@ -1193,16 +1188,14 @@ impl Workspace { let mut full_geo = Rectangle::from_loc_and_size((0, 0), self.output.geometry().size.as_local()); - if fullscreen.start_at.is_none() { - if bbox != full_geo { - if bbox.size.w < full_geo.size.w { - full_geo.loc.x += (full_geo.size.w - bbox.size.w) / 2; - full_geo.size.w = bbox.size.w; - } - if bbox.size.h < full_geo.size.h { - full_geo.loc.y += (full_geo.size.h - bbox.size.h) / 2; - full_geo.size.h = bbox.size.h; - } + if fullscreen.start_at.is_none() && bbox != full_geo { + if bbox.size.w < full_geo.size.w { + full_geo.loc.x += (full_geo.size.w - bbox.size.w) / 2; + full_geo.size.w = bbox.size.w; + } + if bbox.size.h < full_geo.size.h { + full_geo.loc.y += (full_geo.size.h - bbox.size.h) / 2; + full_geo.size.h = bbox.size.h; } } @@ -1269,7 +1262,7 @@ impl Workspace { .unwrap_or(true) { let focused = draw_focus_indicator - .filter(|_| !self.fullscreen.is_some()) + .filter(|_| self.fullscreen.is_none()) .and_then(|seat| self.focus_stack.get(seat).last().cloned()); // floating surfaces @@ -1400,16 +1393,14 @@ impl Workspace { let mut full_geo = Rectangle::from_loc_and_size((0, 0), self.output.geometry().size.as_local()); - if fullscreen.start_at.is_none() { - if bbox != full_geo { - if bbox.size.w < full_geo.size.w { - full_geo.loc.x += (full_geo.size.w - bbox.size.w) / 2; - full_geo.size.w = bbox.size.w; - } - if bbox.size.h < full_geo.size.h { - full_geo.loc.y += (full_geo.size.h - bbox.size.h) / 2; - full_geo.size.h = bbox.size.h; - } + if fullscreen.start_at.is_none() && bbox != full_geo { + if bbox.size.w < full_geo.size.w { + full_geo.loc.x += (full_geo.size.w - bbox.size.w) / 2; + full_geo.size.w = bbox.size.w; + } + if bbox.size.h < full_geo.size.h { + full_geo.loc.y += (full_geo.size.h - bbox.size.h) / 2; + full_geo.size.h = bbox.size.h; } } diff --git a/src/state.rs b/src/state.rs index fc2ba06e..bf1b1bcc 100644 --- a/src/state.rs +++ b/src/state.rs @@ -153,7 +153,7 @@ impl ClientData for ClientState { pub fn advertised_node_for_client(client: &Client) -> Option { // Lets check the global drm-node the client got either through default-feedback or wl_drm if let Some(normal_client) = client.get_data::() { - return normal_client.advertised_drm_node.clone(); + return normal_client.advertised_drm_node; } // last but not least all xwayland-surfaces should also share a single node if let Some(xwayland_client) = client.get_data::() { @@ -321,7 +321,7 @@ impl BackendData { Some(c_m) => m.size != c_m.size || m.refresh != c_m.refresh, }); let transform = - Some(final_config.transform.into()).filter(|x| *x != output.current_transform()); + Some(final_config.transform).filter(|x| *x != output.current_transform()); let scale = Some(final_config.scale) .filter(|x| *x != output.current_scale().fractional_scale()); let location = Some(Point::from(( @@ -389,9 +389,7 @@ impl BackendData { ) -> Result, anyhow::Error> { match self { BackendData::Kms(ref mut state) => { - return state - .dmabuf_imported(client, global, dmabuf) - .map(|node| Some(node)) + return state.dmabuf_imported(client, global, dmabuf).map(Some) } BackendData::Winit(ref mut state) => { state.backend.renderer().import_dmabuf(&dmabuf, None)?; @@ -513,24 +511,24 @@ impl State { let seat_state = SeatState::::new(); let viewporter_state = ViewporterState::new::(dh); let wl_drm_state = WlDrmState::>::default(); - let kde_decoration_state = KdeDecorationState::new::(&dh, Mode::Client); - let xdg_decoration_state = XdgDecorationState::new::(&dh); + let kde_decoration_state = KdeDecorationState::new::(dh, Mode::Client); + let xdg_decoration_state = XdgDecorationState::new::(dh); let session_lock_manager_state = - SessionLockManagerState::new::(&dh, client_is_privileged); - XWaylandKeyboardGrabState::new::(&dh); - let xwayland_shell_state = XWaylandShellState::new::(&dh); - PointerConstraintsState::new::(&dh); - PointerGesturesState::new::(&dh); - TabletManagerState::new::(&dh); - SecurityContextState::new::(&dh, client_has_no_security_context); - InputMethodManagerState::new::(&dh, client_is_privileged); - TextInputManagerState::new::(&dh); - VirtualKeyboardManagerState::new::(&dh, client_is_privileged); - AlphaModifierState::new::(&dh); - SinglePixelBufferState::new::(&dh); - - let idle_notifier_state = IdleNotifierState::::new(&dh, handle.clone()); - let idle_inhibit_manager_state = IdleInhibitManagerState::new::(&dh); + SessionLockManagerState::new::(dh, client_is_privileged); + XWaylandKeyboardGrabState::new::(dh); + let xwayland_shell_state = XWaylandShellState::new::(dh); + PointerConstraintsState::new::(dh); + PointerGesturesState::new::(dh); + TabletManagerState::new::(dh); + SecurityContextState::new::(dh, client_has_no_security_context); + InputMethodManagerState::new::(dh, client_is_privileged); + TextInputManagerState::new::(dh); + VirtualKeyboardManagerState::new::(dh, client_is_privileged); + AlphaModifierState::new::(dh); + SinglePixelBufferState::new::(dh); + + let idle_notifier_state = IdleNotifierState::::new(dh, handle.clone()); + let idle_inhibit_manager_state = IdleInhibitManagerState::new::(dh); let idle_inhibiting_surfaces = HashSet::new(); let data_control_state = crate::utils::env::bool_var("COSMIC_DATA_CONTROL_ENABLED") @@ -783,10 +781,10 @@ impl Common { if let Some(lock_surface) = session_lock.surfaces.get(output) { if let Some(feedback) = advertised_node_for_surface(lock_surface.wl_surface(), &self.display_handle) - .and_then(|source| dmabuf_feedback(source)) + .and_then(&mut dmabuf_feedback) { send_dmabuf_feedback_surface_tree( - &lock_surface.wl_surface(), + lock_surface.wl_surface(), output, surface_primary_scanout_output, |surface, _| { @@ -815,7 +813,7 @@ impl Common { .and_then(|wl_surface| { advertised_node_for_surface(&wl_surface, &self.display_handle) }) - .and_then(|source| dmabuf_feedback(source)) + .and_then(&mut dmabuf_feedback) { window.send_dmabuf_feedback( output, @@ -843,7 +841,7 @@ impl Common { .and_then(|wl_surface| { advertised_node_for_surface(&wl_surface, &self.display_handle) }) - .and_then(|source| dmabuf_feedback(source)) + .and_then(&mut dmabuf_feedback) { window.send_dmabuf_feedback( output, @@ -863,7 +861,7 @@ impl Common { .and_then(|wl_surface| { advertised_node_for_surface(&wl_surface, &self.display_handle) }) - .and_then(|source| dmabuf_feedback(source)) + .and_then(&mut dmabuf_feedback) { window.send_dmabuf_feedback( output, @@ -879,7 +877,7 @@ impl Common { if let Some(wl_surface) = or.wl_surface() { if let Some(feedback) = advertised_node_for_surface(&wl_surface, &self.display_handle) - .and_then(|source| dmabuf_feedback(source)) + .and_then(&mut dmabuf_feedback) { send_dmabuf_feedback_surface_tree( &wl_surface, @@ -902,7 +900,7 @@ impl Common { for layer_surface in map.layers() { if let Some(feedback) = advertised_node_for_surface(layer_surface.wl_surface(), &self.display_handle) - .and_then(|source| dmabuf_feedback(source)) + .and_then(&mut dmabuf_feedback) { layer_surface.send_dmabuf_feedback( output, diff --git a/src/systemd.rs b/src/systemd.rs index 1ec18f48..100a5467 100644 --- a/src/systemd.rs +++ b/src/systemd.rs @@ -12,11 +12,11 @@ pub fn ready(common: &Common) { .env("WAYLAND_DISPLAY", &common.socket) .env( "DISPLAY", - &common + common .xwayland_state .as_ref() .map(|s| format!(":{}", s.display)) - .unwrap_or(String::new()), + .unwrap_or_default(), ) .status() { diff --git a/src/utils/iced.rs b/src/utils/iced.rs index 90f5bab9..4a25b983 100644 --- a/src/utils/iced.rs +++ b/src/utils/iced.rs @@ -194,9 +194,9 @@ impl Clone for IcedElementInternal

{ IcedElementInternal { outputs: self.outputs.clone(), buffers: self.buffers.clone(), - pending_update: self.pending_update.clone(), - size: self.size.clone(), - cursor_pos: self.cursor_pos.clone(), + pending_update: self.pending_update, + size: self.size, + cursor_pos: self.cursor_pos, touch_map: self.touch_map.clone(), theme: self.theme.clone(), renderer, @@ -841,14 +841,10 @@ where let mut internal = self.0.lock().unwrap(); // makes partial borrows easier let internal_ref = &mut *internal; - let force = if matches!( + let force = matches!( internal_ref.pending_update, Some(instant) if Instant::now().duration_since(instant) > Duration::from_millis(25) - ) { - true - } else { - false - }; + ); if force { internal_ref.pending_update = None; } @@ -882,7 +878,7 @@ where .and_then(|(last_primitives, last_color)| { (last_color == &background_color).then(|| { damage::diff( - &last_primitives, + last_primitives, current_layers, |_| { vec![cosmic::iced::Rectangle::new( @@ -946,7 +942,7 @@ where if let Ok(buffer) = MemoryRenderBufferRenderElement::from_buffer( renderer, location.to_f64(), - &buffer, + buffer, Some(alpha), Some(Rectangle::from_loc_and_size( (0., 0.), diff --git a/src/utils/prelude.rs b/src/utils/prelude.rs index 6fc68ed5..e478037b 100644 --- a/src/utils/prelude.rs +++ b/src/utils/prelude.rs @@ -1,7 +1,7 @@ use smithay::{ backend::drm::VrrSupport as Support, output::{Output, WeakOutput}, - utils::{Rectangle, Transform}, + utils::Rectangle, }; pub use super::geometry::*; @@ -39,7 +39,7 @@ struct Mirroring(Mutex>); impl OutputExt for Output { fn geometry(&self) -> Rectangle { Rectangle::from_loc_and_size(self.current_location(), { - Transform::from(self.current_transform()) + self.current_transform() .transform_size( self.current_mode() .map(|m| m.size) @@ -78,13 +78,12 @@ impl OutputExt for Output { fn adaptive_sync_support(&self) -> Option { self.user_data() .get::() - .map(|vrr| match vrr.0.load(Ordering::SeqCst) { + .and_then(|vrr| match vrr.0.load(Ordering::SeqCst) { 0 => None, 2 => Some(Support::RequiresModeset), 3 => Some(Support::Supported), _ => Some(Support::NotSupported), }) - .flatten() } fn set_adaptive_sync_support(&self, vrr: Option) { diff --git a/src/utils/screenshot.rs b/src/utils/screenshot.rs index 500efeaf..9fcf28e0 100644 --- a/src/utils/screenshot.rs +++ b/src/utils/screenshot.rs @@ -76,7 +76,7 @@ pub fn screenshot_window(state: &mut State, surface: &CosmicSurface) { )); let file = std::fs::File::create(path.join(name))?; - let ref mut writer = std::io::BufWriter::new(file); + let writer = &mut std::io::BufWriter::new(file); let mut encoder = png::Encoder::new(writer, bbox.size.w as u32, bbox.size.h as u32); encoder.set_color(png::ColorType::Rgba); encoder.set_depth(png::BitDepth::Eight); @@ -90,7 +90,7 @@ pub fn screenshot_window(state: &mut State, surface: &CosmicSurface) { ); encoder.set_source_chromaticities(source_chromaticities); let mut writer = encoder.write_header()?; - writer.write_image_data(&gl_data)?; + writer.write_image_data(gl_data)?; } Ok(()) diff --git a/src/wayland/handlers/buffer.rs b/src/wayland/handlers/buffer.rs index b638d1fb..0248f00e 100644 --- a/src/wayland/handlers/buffer.rs +++ b/src/wayland/handlers/buffer.rs @@ -11,13 +11,13 @@ impl BufferHandler for State { fn buffer_destroyed(&mut self, buffer: &WlBuffer) { if let BackendData::Kms(kms_state) = &mut self.backend { for device in kms_state.drm_devices.values_mut() { - if device.active_buffers.remove(&buffer.downgrade()) { - if !device.in_use(kms_state.primary_node.as_ref()) { - if let Err(err) = kms_state.refresh_used_devices() { - warn!(?err, "Failed to init devices."); - }; - break; - } + if device.active_buffers.remove(&buffer.downgrade()) + && !device.in_use(kms_state.primary_node.as_ref()) + { + if let Err(err) = kms_state.refresh_used_devices() { + warn!(?err, "Failed to init devices."); + }; + break; } } } diff --git a/src/wayland/handlers/compositor.rs b/src/wayland/handlers/compositor.rs index 1c43d3c3..3c753c43 100644 --- a/src/wayland/handlers/compositor.rs +++ b/src/wayland/handlers/compositor.rs @@ -148,7 +148,7 @@ impl CompositorHandler for State { // schedule a new render if let Some(output) = shell.visible_output_for_surface(surface) { - self.backend.schedule_render(&output); + self.backend.schedule_render(output); } if mapped { @@ -222,7 +222,7 @@ impl CompositorHandler for State { if let Some(element) = shell.element_for_surface(surface).cloned() { crate::shell::layout::floating::ResizeSurfaceGrab::apply_resize_to_location( element.clone(), - &mut *shell, + &mut shell, ); } } @@ -257,8 +257,8 @@ impl State { .cloned() { if let Some(toplevel) = window.0.toplevel() { - if toplevel_ensure_initial_configure(&toplevel) - && with_renderer_surface_state(&surface, |state| state.buffer().is_some()) + if toplevel_ensure_initial_configure(toplevel) + && with_renderer_surface_state(surface, |state| state.buffer().is_some()) .unwrap_or(false) { window.on_commit(); diff --git a/src/wayland/handlers/data_device.rs b/src/wayland/handlers/data_device.rs index 672a7cb7..66e9a256 100644 --- a/src/wayland/handlers/data_device.rs +++ b/src/wayland/handlers/data_device.rs @@ -68,7 +68,7 @@ impl ClientDndGrabHandler for State { seat: Seat, ) { let user_data = seat.user_data(); - user_data.insert_if_missing_threadsafe::>, _>(|| Default::default()); + user_data.insert_if_missing_threadsafe::>, _>(Default::default); let offset = seat .user_data() diff --git a/src/wayland/handlers/decoration.rs b/src/wayland/handlers/decoration.rs index 5c5e5a2f..8b5d08a4 100644 --- a/src/wayland/handlers/decoration.rs +++ b/src/wayland/handlers/decoration.rs @@ -35,12 +35,11 @@ impl PreferredDecorationMode { pub fn mode(window: &Window) -> Option { let user_data = window.user_data(); user_data.insert_if_missing(|| PreferredDecorationMode(RefCell::new(None))); - user_data + *user_data .get::() .unwrap() .0 .borrow() - .clone() } pub fn update(window: &Window, update: Option) { diff --git a/src/wayland/handlers/output_power.rs b/src/wayland/handlers/output_power.rs index 515c604e..93a36f47 100644 --- a/src/wayland/handlers/output_power.rs +++ b/src/wayland/handlers/output_power.rs @@ -46,7 +46,7 @@ fn kms_surfaces_for_output<'a>( output: &'a Output, ) -> impl Iterator + 'a { kms_surfaces(state).filter(move |surface| { - surface.output == *output || surface.output.mirroring().as_ref() == Some(&output) + surface.output == *output || surface.output.mirroring().as_ref() == Some(output) }) } diff --git a/src/wayland/handlers/screencopy/mod.rs b/src/wayland/handlers/screencopy/mod.rs index 6bb221bd..9a464e40 100644 --- a/src/wayland/handlers/screencopy/mod.rs +++ b/src/wayland/handlers/screencopy/mod.rs @@ -51,7 +51,7 @@ impl ScreencopyHandler for State { .and_then(|output| constraints_for_output(&output, &mut self.backend)), ImageSourceData::Workspace(handle) => { let shell = self.common.shell.read().unwrap(); - 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) } ImageSourceData::Toplevel(window) => { @@ -352,7 +352,7 @@ fn constraints_for_output(output: &Output, backend: &mut BackendData) -> Option< }; let mut renderer = backend - .offscreen_renderer(|kms| kms.target_node_for_output(&output).or(kms.primary_node)) + .offscreen_renderer(|kms| kms.target_node_for_output(output).or(kms.primary_node)) .unwrap(); Some(constraints_for_renderer(mode, renderer.as_mut())) } @@ -368,7 +368,7 @@ fn constraints_for_toplevel( .offscreen_renderer(|kms| { let dma_node = with_renderer_surface_state(&wl_surface, |state| { let buffer = state.buffer()?; - let dmabuf = get_dmabuf(&*buffer).ok()?; + let dmabuf = get_dmabuf(buffer).ok()?; dmabuf.node() }) .flatten(); diff --git a/src/wayland/handlers/screencopy/render.rs b/src/wayland/handlers/screencopy/render.rs index eda0951b..bb0e88fd 100644 --- a/src/wayland/handlers/screencopy/render.rs +++ b/src/wayland/handlers/screencopy/render.rs @@ -125,7 +125,7 @@ where Ok(Some(( frame, damage - .into_iter() + .iter() .map(|rect| { let logical = rect.to_logical(1); logical.to_buffer(1, transform, &logical.size) @@ -283,7 +283,7 @@ pub fn render_workspace_to_buffer( additional_damage, &common.shell, common.clock.now(), - &output, + output, None, handle, cursor_mode, @@ -313,7 +313,7 @@ pub fn render_workspace_to_buffer( additional_damage, &common.shell, common.clock.now(), - &output, + output, None, handle, cursor_mode, @@ -589,7 +589,7 @@ pub fn render_window_to_buffer( .and_then(|wl_surface| { with_renderer_surface_state(&wl_surface, |state| { let buffer = state.buffer()?; - let dmabuf = get_dmabuf(&*buffer).ok()?; + let dmabuf = get_dmabuf(buffer).ok()?; dmabuf.node() }) }) @@ -717,7 +717,7 @@ pub fn render_cursor_to_buffer( { let mut elements = cursor::draw_cursor( renderer, - &seat, + seat, Point::from((0.0, 0.0)), 1.0.into(), common.clock.now(), diff --git a/src/wayland/handlers/security_context.rs b/src/wayland/handlers/security_context.rs index e564f1bf..550bd457 100644 --- a/src/wayland/handlers/security_context.rs +++ b/src/wayland/handlers/security_context.rs @@ -37,14 +37,14 @@ impl SecurityContextHandler for State { let drm_node = client_data .as_ref() .and_then(|data| data.downcast_ref::()) - .and_then(|data| data.advertised_drm_node.clone()) + .and_then(|data| data.advertised_drm_node) .or_else(|| { client_data .as_ref() .and_then(|data| data.downcast_ref::()) .and_then(|data| data.user_data().get::().cloned()) }) - .or_else(|| new_state.advertised_drm_node.clone()); + .or(new_state.advertised_drm_node); if let Err(err) = state.common.display_handle.insert_client( client_stream, diff --git a/src/wayland/handlers/session_lock.rs b/src/wayland/handlers/session_lock.rs index 10d6f93f..a663cff1 100644 --- a/src/wayland/handlers/session_lock.rs +++ b/src/wayland/handlers/session_lock.rs @@ -40,7 +40,7 @@ impl SessionLockHandler for State { }); for output in shell.outputs() { - self.backend.schedule_render(&output); + self.backend.schedule_render(output); } } @@ -49,7 +49,7 @@ impl SessionLockHandler for State { shell.session_lock = None; for output in shell.outputs() { - self.backend.schedule_render(&output); + self.backend.schedule_render(output); } } diff --git a/src/wayland/handlers/toplevel_info.rs b/src/wayland/handlers/toplevel_info.rs index 18b16a07..cc5ebbee 100644 --- a/src/wayland/handlers/toplevel_info.rs +++ b/src/wayland/handlers/toplevel_info.rs @@ -48,7 +48,7 @@ impl Window for CosmicSurface { } fn is_sticky(&self) -> bool { - CosmicSurface::is_sticky(&self) + CosmicSurface::is_sticky(self) } fn global_geometry(&self) -> Option> { diff --git a/src/wayland/handlers/toplevel_management.rs b/src/wayland/handlers/toplevel_management.rs index 7bed781f..44fa56ea 100644 --- a/src/wayland/handlers/toplevel_management.rs +++ b/src/wayland/handlers/toplevel_management.rs @@ -54,7 +54,7 @@ impl ToplevelManagementHandler for State { .clone(); let res = shell.activate( - &output, + output, idx, WorkspaceDelta::new_shortcut(), &mut self.common.workspace_state.update(), @@ -64,7 +64,7 @@ impl ToplevelManagementHandler for State { if seat.active_output() != *output { match res { Ok(Some(new_pos)) => { - seat.set_active_output(&output); + seat.set_active_output(output); if let Some(ptr) = seat.get_pointer() { let serial = SERIAL_COUNTER.next_serial(); ptr.motion( @@ -80,7 +80,7 @@ impl ToplevelManagementHandler for State { } } Ok(None) => { - seat.set_active_output(&output); + seat.set_active_output(output); } _ => {} } @@ -135,7 +135,6 @@ impl ToplevelManagementHandler for State { std::mem::drop(shell); Shell::set_focus(self, Some(&target), &seat, None, true); } - return; } } @@ -154,7 +153,7 @@ impl ToplevelManagementHandler for State { workspace.fullscreen_request(window, None, from, &seat); } else if let Some((output, handle)) = shell .space_for(&mapped) - .map(|workspace| (workspace.output.clone(), workspace.handle.clone())) + .map(|workspace| (workspace.output.clone(), workspace.handle)) { let from = minimize_rectangle(&output, window); shell @@ -175,13 +174,16 @@ impl ToplevelManagementHandler for State { 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) { - let old_handle = workspace.handle.clone(); - let new_workspace_handle = shell + let old_handle = workspace.handle; + let new_workspace_handle = if shell .workspaces .space_for_handle(&previous_workspace) .is_some() - .then_some(previous_workspace) - .unwrap_or(old_handle); // if the workspace doesn't exist anymore, we can still remap on the right layer + { + previous_workspace + } else { + old_handle + }; // if the workspace doesn't exist anymore, we can still remap on the right layer shell.remap_unfullscreened_window( mapped, diff --git a/src/wayland/handlers/workspace.rs b/src/wayland/handlers/workspace.rs index ee231b7e..50126c85 100644 --- a/src/wayland/handlers/workspace.rs +++ b/src/wayland/handlers/workspace.rs @@ -55,10 +55,7 @@ impl WorkspaceHandler for State { if let Some(workspace) = shell.workspaces.space_for_handle_mut(&workspace) { let mut guard = self.common.workspace_state.update(); workspace.set_tiling( - match state.into_result() { - Ok(TilingState::FloatingOnly) => false, - _ => true, - }, + !matches!(state.into_result(), Ok(TilingState::FloatingOnly)), &seat, &mut guard, ); diff --git a/src/wayland/handlers/xdg_activation.rs b/src/wayland/handlers/xdg_activation.rs index 7decb4bf..19e658a7 100644 --- a/src/wayland/handlers/xdg_activation.rs +++ b/src/wayland/handlers/xdg_activation.rs @@ -116,7 +116,7 @@ impl XdgActivationHandler for State { workspace_guard.add_workspace_state(&workspace, WState::Urgent); } } - ActivationContext::Workspace(workspace) => { + ActivationContext::Workspace(_) => { let seat = shell.seats.last_active().clone(); let current_output = seat.active_output(); @@ -157,8 +157,7 @@ impl XdgActivationHandler for State { std::mem::drop(shell); Shell::set_focus(self, Some(&target), &seat, None, false); - } else if let Some(w) = shell.space_for(&element).map(|w| w.handle.clone()) - { + } else if let Some(w) = shell.space_for(&element).map(|w| w.handle) { shell.append_focus_stack(&element, &seat); let mut workspace_guard = self.common.workspace_state.update(); workspace_guard.add_workspace_state(&w, WState::Urgent); @@ -168,7 +167,7 @@ impl XdgActivationHandler for State { } else { shell .pending_activations - .insert(ActivationKey::Wayland(surface), context.clone()); + .insert(ActivationKey::Wayland(surface), *context); } } } diff --git a/src/wayland/handlers/xdg_shell/mod.rs b/src/wayland/handlers/xdg_shell/mod.rs index f3a4e5fe..d4bf8446 100644 --- a/src/wayland/handlers/xdg_shell/mod.rs +++ b/src/wayland/handlers/xdg_shell/mod.rs @@ -270,7 +270,7 @@ impl XdgShellHandler for State { mapped }; - let workspace_handle = shell.active_space(&output).handle.clone(); + let workspace_handle = shell.active_space(&output).handle; for (window, _) in mapped.windows() { toplevel_enter_output(&window, &output); toplevel_enter_workspace(&window, &workspace_handle); @@ -314,9 +314,9 @@ impl XdgShellHandler for State { let layer = workspace.unmap(&mapped).unwrap().layer; (mapped, layer) }; - let handle = workspace.handle.clone(); + let handle = workspace.handle; - let workspace_handle = shell.active_space(&output).handle.clone(); + let workspace_handle = shell.active_space(&output).handle; for (window, _) in mapped.windows() { toplevel_enter_output(&window, &output); toplevel_enter_workspace(&window, &workspace_handle); @@ -339,15 +339,13 @@ impl XdgShellHandler for State { workspace.fullscreen_request(&window, None, from, &seat) } } - } else { - if let Some(o) = shell - .pending_windows - .iter_mut() - .find(|(s, _, _)| s.wl_surface().as_deref() == Some(surface.wl_surface())) - .map(|(_, _, o)| o) - { - *o = Some(output); - } + } else if let Some(o) = shell + .pending_windows + .iter_mut() + .find(|(s, _, _)| s.wl_surface().as_deref() == Some(surface.wl_surface())) + .map(|(_, _, o)| o) + { + *o = Some(output); } } @@ -360,13 +358,16 @@ impl XdgShellHandler for State { .find(|(w, _)| w.wl_surface().as_deref() == Some(surface.wl_surface())) .unwrap(); if let Some((layer, previous_workspace)) = workspace.unfullscreen_request(&window) { - let old_handle = workspace.handle.clone(); - let new_workspace_handle = shell + let old_handle = workspace.handle; + let new_workspace_handle = if shell .workspaces .space_for_handle(&previous_workspace) .is_some() - .then_some(previous_workspace) - .unwrap_or(old_handle); // if the workspace doesn't exist anymore, we can still remap on the right layer + { + previous_workspace + } else { + old_handle + }; // if the workspace doesn't exist anymore, we can still remap on the right layer shell.remap_unfullscreened_window( mapped, @@ -403,12 +404,12 @@ impl XdgShellHandler for State { { let dh = self.common.display_handle.clone(); for client in clients.values() { - client_compositor_state(&client).blocker_cleared(self, &dh); + client_compositor_state(client).blocker_cleared(self, &dh); } } if let Some(output) = output.as_ref() { - self.backend.schedule_render(&output); + self.backend.schedule_render(output); } } diff --git a/src/wayland/handlers/xdg_shell/popup.rs b/src/wayland/handlers/xdg_shell/popup.rs index 51e74262..5359de35 100644 --- a/src/wayland/handlers/xdg_shell/popup.rs +++ b/src/wayland/handlers/xdg_shell/popup.rs @@ -27,7 +27,7 @@ use tracing::{trace, warn}; impl Shell { pub fn unconstrain_popup(&self, surface: &PopupSurface) { - if let Some(parent) = get_popup_toplevel(&surface) { + if let Some(parent) = get_popup_toplevel(surface) { if let Some(elem) = self.element_for_surface(&parent) { let (mut element_geo, output, is_tiled) = if let Some(workspace) = self.space_for(elem) { @@ -92,14 +92,14 @@ pub fn update_reactive_popups<'a>( for (popup, _) in PopupManager::popups_for_surface(toplevel.wl_surface()) { match popup { PopupKind::Xdg(surface) => { - let positioner = with_states(&surface.wl_surface(), |states| { + let positioner = with_states(surface.wl_surface(), |states| { let attributes = states .data_map .get::() .unwrap() .lock() .unwrap(); - attributes.current.positioner.clone() + attributes.current.positioner }); if positioner.reactive { let anchor_point = loc + get_anchor_point(&positioner).as_global(); @@ -131,8 +131,8 @@ fn unconstrain_xdg_popup_tile(surface: &PopupSurface, rect: Rectangle) -> bool { let toplevel_offset = get_popup_toplevel_coords(popup); - let positioner = popup.with_pending_state(|state| state.positioner.clone()); + let positioner = popup.with_pending_state(|state| state.positioner); let mut geometry = positioner.get_geometry(); geometry.loc += toplevel_offset; let offset = check_constrained(geometry, toplevel_box); @@ -193,7 +189,7 @@ fn unconstrain_flip(popup: &PopupSurface, toplevel_box: Rectangle) return true; } - let mut positioner = positioner.clone(); + let mut positioner = positioner; let flip_x = offset.x != 0 && positioner @@ -205,24 +201,24 @@ fn unconstrain_flip(popup: &PopupSurface, toplevel_box: Rectangle) .contains(ConstraintAdjustment::FlipY); if flip_x { - let old_positioner = positioner.clone(); + let old_positioner = positioner; positioner.anchor_edges = invert_anchor_x(positioner.anchor_edges); positioner.gravity = invert_gravity_x(positioner.gravity); geometry = positioner.get_geometry(); geometry.loc += toplevel_offset; let new_offset = check_constrained(geometry, toplevel_box); - if !(new_offset.x.abs() < offset.x.abs()) { + if new_offset.x.abs() >= offset.x.abs() { positioner = old_positioner; } } if flip_y { - let old_positioner = positioner.clone(); + let old_positioner = positioner; positioner.anchor_edges = invert_anchor_y(positioner.anchor_edges); positioner.gravity = invert_gravity_y(positioner.gravity); geometry = positioner.get_geometry(); geometry.loc += toplevel_offset; let new_offset = check_constrained(geometry, toplevel_box); - if !(new_offset.y.abs() < offset.y.abs()) { + if new_offset.y.abs() >= offset.y.abs() { positioner = old_positioner; } } @@ -242,7 +238,7 @@ fn unconstrain_flip(popup: &PopupSurface, toplevel_box: Rectangle) fn unconstrain_slide(popup: &PopupSurface, toplevel_box: Rectangle) -> bool { let toplevel_offset = get_popup_toplevel_coords(popup); - let positioner = popup.with_pending_state(|state| state.positioner.clone()); + let positioner = popup.with_pending_state(|state| state.positioner); let mut geometry = positioner.get_geometry(); geometry.loc += toplevel_offset; let offset = check_constrained(geometry, toplevel_box); @@ -275,7 +271,7 @@ fn unconstrain_slide(popup: &PopupSurface, toplevel_box: Rectangle geometry.loc.y += toplevel_box.loc.y - toplevel.y; } - let mut check_geometry = geometry.clone(); + let mut check_geometry = geometry; check_geometry.loc += toplevel; let new_offset = check_constrained(check_geometry, toplevel_box); if new_offset.x.abs() < offset.x.abs() || new_offset.y.abs() < offset.y.abs() { @@ -289,7 +285,7 @@ fn unconstrain_slide(popup: &PopupSurface, toplevel_box: Rectangle fn unconstrain_resize(popup: &PopupSurface, toplevel_box: Rectangle) -> bool { let toplevel_offset = get_popup_toplevel_coords(popup); - let positioner = popup.with_pending_state(|state| state.positioner.clone()); + let positioner = popup.with_pending_state(|state| state.positioner); let mut geometry = positioner.get_geometry(); geometry.loc += toplevel_offset; let offset = check_constrained(geometry, toplevel_box); @@ -314,7 +310,7 @@ fn unconstrain_resize(popup: &PopupSurface, toplevel_box: Rectangle Point { Anchor::TopRight => (rect.loc.x + rect.size.w, rect.loc.y), Anchor::BottomLeft => (rect.loc.x, rect.loc.y + rect.size.h), Anchor::BottomRight => (rect.loc.x + rect.size.w, rect.loc.y + rect.size.h), - Anchor::None | _ => ( + _ => ( rect.loc.x + (rect.size.w / 2), rect.loc.y + (rect.size.h / 2), ), diff --git a/src/wayland/protocols/drm.rs b/src/wayland/protocols/drm.rs index 6185db18..99c4d853 100644 --- a/src/wayland/protocols/drm.rs +++ b/src/wayland/protocols/drm.rs @@ -87,7 +87,7 @@ where ) { let data = DrmInstanceData { formats: global_data.formats.clone(), - dmabuf_global: global_data.dmabuf_global.clone(), + dmabuf_global: global_data.dmabuf_global, }; let drm_instance = data_init.init(resource, data); @@ -266,7 +266,7 @@ impl WlDrmState { filter: Box::new(client_filter), formats, device_path, - dmabuf_global: dmabuf_global.clone(), + dmabuf_global: *dmabuf_global, }; display.create_global::(2, data) diff --git a/src/wayland/protocols/image_source.rs b/src/wayland/protocols/image_source.rs index 1032de82..3396a194 100644 --- a/src/wayland/protocols/image_source.rs +++ b/src/wayland/protocols/image_source.rs @@ -191,15 +191,12 @@ where _dhandle: &DisplayHandle, data_init: &mut DataInit<'_, D>, ) { - match request { - OutputSourceRequest::CreateSource { source, output } => { - let data = match Output::from_resource(&output) { - Some(output) => ImageSourceData::Output(output.downgrade()), - None => ImageSourceData::Destroyed, - }; - data_init.init(source, data); - } - _ => {} + if let OutputSourceRequest::CreateSource { source, output } = request { + let data = match Output::from_resource(&output) { + Some(output) => ImageSourceData::Output(output.downgrade()), + None => ImageSourceData::Destroyed, + }; + data_init.init(source, data); } } @@ -228,15 +225,12 @@ where _dhandle: &DisplayHandle, data_init: &mut DataInit<'_, D>, ) { - match request { - WorkspaceSourceRequest::CreateSource { source, output } => { - let data = match state.workspace_state().workspace_handle(&output) { - Some(workspace) => ImageSourceData::Workspace(workspace), - None => ImageSourceData::Destroyed, - }; - data_init.init(source, data); - } - _ => {} + if let WorkspaceSourceRequest::CreateSource { source, output } = request { + let data = match state.workspace_state().workspace_handle(&output) { + Some(workspace) => ImageSourceData::Workspace(workspace), + None => ImageSourceData::Destroyed, + }; + data_init.init(source, data); } } @@ -264,18 +258,16 @@ where _dhandle: &DisplayHandle, data_init: &mut DataInit<'_, D>, ) { - match request { - ToplevelSourceRequest::CreateSource { - source, - toplevel_handle, - } => { - let data = match window_from_handle(toplevel_handle) { - Some(toplevel) => ImageSourceData::Toplevel(toplevel), - None => ImageSourceData::Destroyed, - }; - data_init.init(source, data); - } - _ => {} + if let ToplevelSourceRequest::CreateSource { + source, + toplevel_handle, + } = request + { + let data = match window_from_handle(toplevel_handle) { + Some(toplevel) => ImageSourceData::Toplevel(toplevel), + None => ImageSourceData::Destroyed, + }; + data_init.init(source, data); } } @@ -296,14 +288,12 @@ where _state: &mut D, _client: &Client, _resource: &ZcosmicImageSourceV1, - request: ::Request, + _request: ::Request, _data: &ImageSourceData, _dhandle: &DisplayHandle, _data_init: &mut DataInit<'_, D>, ) { - match request { - _ => {} - } + {} } fn destroyed( diff --git a/src/wayland/protocols/output_configuration/handlers/cosmic.rs b/src/wayland/protocols/output_configuration/handlers/cosmic.rs index b0b768df..326c9748 100644 --- a/src/wayland/protocols/output_configuration/handlers/cosmic.rs +++ b/src/wayland/protocols/output_configuration/handlers/cosmic.rs @@ -127,19 +127,16 @@ where _dh: &DisplayHandle, _data_init: &mut DataInit<'_, D>, ) { - match request { - zcosmic_output_head_v1::Request::Release => { - let inner = state.output_configuration_state(); - if let Some(head) = inner - .instances - .iter_mut() - .flat_map(|instance| instance.heads.iter_mut()) - .find(|head| head.extension_obj.as_ref().is_some_and(|o| o == obj)) - { - head.extension_obj.take(); - } + if let zcosmic_output_head_v1::Request::Release = request { + let inner = state.output_configuration_state(); + if let Some(head) = inner + .instances + .iter_mut() + .flat_map(|instance| instance.heads.iter_mut()) + .find(|head| head.extension_obj.as_ref().is_some_and(|o| o == obj)) + { + head.extension_obj.take(); } - _ => {} } } } diff --git a/src/wayland/protocols/output_configuration/handlers/wlr.rs b/src/wayland/protocols/output_configuration/handlers/wlr.rs index 4666b114..441b7244 100644 --- a/src/wayland/protocols/output_configuration/handlers/wlr.rs +++ b/src/wayland/protocols/output_configuration/handlers/wlr.rs @@ -136,13 +136,10 @@ where _dh: &DisplayHandle, _data_init: &mut DataInit<'_, D>, ) { - match request { - zwlr_output_head_v1::Request::Release => { - for instance in &mut state.output_configuration_state().instances { - instance.heads.retain(|h| &h.obj != obj); - } + if let zwlr_output_head_v1::Request::Release = request { + for instance in &mut state.output_configuration_state().instances { + instance.heads.retain(|h| &h.obj != obj); } - _ => {} } } @@ -173,16 +170,13 @@ where _dh: &DisplayHandle, _data_init: &mut DataInit<'_, D>, ) { - match request { - zwlr_output_mode_v1::Request::Release => { - let state = state.output_configuration_state(); - for instance in &mut state.instances { - for head in &mut instance.heads { - head.modes.retain(|mode| mode != obj) - } + if let zwlr_output_mode_v1::Request::Release = request { + let state = state.output_configuration_state(); + for instance in &mut state.instances { + for head in &mut instance.heads { + head.modes.retain(|mode| mode != obj) } } - _ => {} } } } @@ -281,13 +275,12 @@ where .heads .iter_mut() .map(|(head, conf)| { - let output = match { - inner - .instances - .iter() - .find_map(|instance| instance.heads.iter().find(|h| h.obj == *head)) - .map(|i| i.output.clone()) - } { + let output = match inner + .instances + .iter() + .find_map(|instance| instance.heads.iter().find(|h| h.obj == *head)) + .map(|i| i.output.clone()) + { Some(o) => o, None => { return Err(zwlr_output_configuration_head_v1::Error::InvalidMode); @@ -331,10 +324,10 @@ where .iter() .any(|o| !inner.outputs.contains(o)) || final_conf.iter().any(|(o, c)| match c { - OutputConfiguration::Enabled { mode, .. } => match mode { - Some(ModeConfiguration::Mode(m)) => !o.modes().contains(m), - _ => false, - }, + OutputConfiguration::Enabled { + mode: Some(ModeConfiguration::Mode(m)), + .. + } => !o.modes().contains(m), _ => false, }) { diff --git a/src/wayland/protocols/output_configuration/mod.rs b/src/wayland/protocols/output_configuration/mod.rs index a75c1d16..dff9f907 100644 --- a/src/wayland/protocols/output_configuration/mod.rs +++ b/src/wayland/protocols/output_configuration/mod.rs @@ -127,7 +127,7 @@ impl<'a> TryFrom<&'a mut PendingOutputConfigurationInner> for OutputConfiguratio wlr_mode .data::() .cloned() - .ok_or_else(|| zwlr_output_configuration_head_v1::Error::InvalidMode)?, + .ok_or(zwlr_output_configuration_head_v1::Error::InvalidMode)?, )), Some(ModeConfiguration::Custom { size, refresh }) => { Some(ModeConfiguration::Custom { size, refresh }) @@ -269,7 +269,7 @@ where for instance in &mut self.instances { let mut removed_heads = Vec::new(); for head in &mut instance.heads { - if &head.output == &output { + if head.output == output { if head.obj.version() < zwlr_output_head_v1::REQ_RELEASE_SINCE { removed_heads.push(head.obj.clone()); } @@ -417,7 +417,7 @@ where .map(|c| c == output_mode) .unwrap_or(false) { - instance.obj.current_mode(&*mode); + instance.obj.current_mode(mode); } } } diff --git a/src/wayland/protocols/overlap_notify.rs b/src/wayland/protocols/overlap_notify.rs index 1c7d2864..1199cae3 100644 --- a/src/wayland/protocols/overlap_notify.rs +++ b/src/wayland/protocols/overlap_notify.rs @@ -1,9 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only -use std::{ - collections::{HashMap, HashSet}, - sync::Mutex, -}; +use std::{collections::HashMap, sync::Mutex}; use cosmic_protocols::{ overlap_notify::v1::server::{ @@ -120,7 +117,7 @@ impl OverlapNotifyState { .lock() .unwrap(); active_workspaces.iter().any(|active_workspace| { - state.in_workspace(&active_workspace) + state.in_workspace(active_workspace) }) }) { @@ -169,7 +166,7 @@ pub trait OverlapNotifyHandler: ToplevelInfoHandler { fn overlap_notify_state(&mut self) -> &mut OverlapNotifyState; fn layer_surface_from_resource(&self, resource: ZwlrLayerSurfaceV1) -> Option; fn outputs(&self) -> impl Iterator; - fn active_workspaces(&self) -> impl Iterator; + fn active_workspaces(&self) -> impl Iterator; } pub struct OverlapNotifyGlobalData { @@ -208,8 +205,8 @@ impl LayerOverlapNotificationDataInternal { } } } - for (_, (identifier, namespace, exclusive, layer, overlap)) in - &self.last_snapshot.layer_overlaps + for (identifier, namespace, exclusive, layer, overlap) in + self.last_snapshot.layer_overlaps.values() { new_notification.layer_enter( identifier.clone(), @@ -414,22 +411,20 @@ where _dhandle: &DisplayHandle, data_init: &mut smithay::reexports::wayland_server::DataInit<'_, D>, ) { - match request { - zcosmic_overlap_notify_v1::Request::NotifyOnOverlap { - overlap_notification, - layer_surface, - } => { - let notification = data_init.init(overlap_notification, ()); - if let Some(surface) = state.layer_surface_from_resource(layer_surface) { - let mut data = surface - .user_data() - .get_or_insert_threadsafe(LayerOverlapNotificationData::default) - .lock() - .unwrap(); - data.add_notification(notification); - } + if let zcosmic_overlap_notify_v1::Request::NotifyOnOverlap { + overlap_notification, + layer_surface, + } = request + { + let notification = data_init.init(overlap_notification, ()); + if let Some(surface) = state.layer_surface_from_resource(layer_surface) { + let mut data = surface + .user_data() + .get_or_insert_threadsafe(LayerOverlapNotificationData::default) + .lock() + .unwrap(); + data.add_notification(notification); } - _ => {} } } @@ -456,14 +451,12 @@ where _state: &mut D, _client: &Client, _resource: &ZcosmicOverlapNotificationV1, - request: ::Request, + _request: ::Request, _data: &(), _dhandle: &DisplayHandle, _data_init: &mut smithay::reexports::wayland_server::DataInit<'_, D>, ) { - match request { - _ => {} - } + {} } } diff --git a/src/wayland/protocols/screencopy.rs b/src/wayland/protocols/screencopy.rs index 02fdc213..3681b5c8 100644 --- a/src/wayland/protocols/screencopy.rs +++ b/src/wayland/protocols/screencopy.rs @@ -164,7 +164,7 @@ impl Session { } pub fn user_data(&self) -> &UserDataMap { - &*self.user_data + &self.user_data } pub fn stop(self) { @@ -315,7 +315,7 @@ impl CursorSession { } pub fn user_data(&self) -> &UserDataMap { - &*self.user_data + &self.user_data } pub fn stop(self) { @@ -655,25 +655,22 @@ where _dhandle: &DisplayHandle, data_init: &mut DataInit<'_, D>, ) { - match request { - zcosmic_screencopy_session_v2::Request::CreateFrame { frame } => { - let inner = Arc::new(Mutex::new(FrameInner::new( - resource.clone(), - data.inner.lock().unwrap().constraints.clone(), - ))); - let obj = data_init.init( - frame, - FrameData { - inner: inner.clone(), - }, - ); - data.inner - .lock() - .unwrap() - .active_frames - .push(Frame { obj, inner }); - } - _ => {} + if let zcosmic_screencopy_session_v2::Request::CreateFrame { frame } = request { + let inner = Arc::new(Mutex::new(FrameInner::new( + resource.clone(), + data.inner.lock().unwrap().constraints.clone(), + ))); + let obj = data_init.init( + frame, + FrameData { + inner: inner.clone(), + }, + ); + data.inner + .lock() + .unwrap() + .active_frames + .push(Frame { obj, inner }); } } @@ -712,45 +709,44 @@ where _dhandle: &DisplayHandle, data_init: &mut DataInit<'_, D>, ) { - match request { - zcosmic_screencopy_cursor_session_v2::Request::GetScreencopySession { session } => { - let new_data = CursorSessionData { - inner: data.inner.clone(), - }; - let session = data_init.init(session, new_data); + if let zcosmic_screencopy_cursor_session_v2::Request::GetScreencopySession { session } = + request + { + let new_data = CursorSessionData { + inner: data.inner.clone(), + }; + let session = data_init.init(session, new_data); + + let mut inner = data.inner.lock().unwrap(); + if inner.session.is_some() { + resource.post_error( + zcosmic_screencopy_cursor_session_v2::Error::DuplicateSession, + "Duplicate session", + ); + return; + } - let mut inner = data.inner.lock().unwrap(); - if inner.session.is_some() { - resource.post_error( - zcosmic_screencopy_cursor_session_v2::Error::DuplicateSession, - "Duplicate session", - ); - return; + if inner.stopped { + session.stopped(); + } else if let Some(constraints) = inner.constraints.as_ref() { + session.buffer_size(constraints.size.w as u32, constraints.size.h as u32); + for fmt in &constraints.shm { + session.shm_format(*fmt as u32); } - - if inner.stopped { - session.stopped(); - } else if let Some(constraints) = inner.constraints.as_ref() { - session.buffer_size(constraints.size.w as u32, constraints.size.h as u32); - for fmt in &constraints.shm { - session.shm_format(*fmt as u32); - } - if let Some(dma) = constraints.dma.as_ref() { - let node = Vec::from(dma.node.dev_id().to_ne_bytes()); - session.dmabuf_device(node); - for (fmt, modifiers) in &dma.formats { - let modifiers = modifiers - .iter() - .flat_map(|modifier| u64::from(*modifier).to_ne_bytes()) - .collect::>(); - session.dmabuf_format(*fmt as u32, modifiers); - } + if let Some(dma) = constraints.dma.as_ref() { + let node = Vec::from(dma.node.dev_id().to_ne_bytes()); + session.dmabuf_device(node); + for (fmt, modifiers) in &dma.formats { + let modifiers = modifiers + .iter() + .flat_map(|modifier| u64::from(*modifier).to_ne_bytes()) + .collect::>(); + session.dmabuf_format(*fmt as u32, modifiers); } - session.done(); } - inner.session = Some(session); + session.done(); } - _ => {} + inner.session = Some(session); } } @@ -788,25 +784,22 @@ where _dhandle: &DisplayHandle, data_init: &mut DataInit<'_, D>, ) { - match request { - zcosmic_screencopy_session_v2::Request::CreateFrame { frame } => { - let inner = Arc::new(Mutex::new(FrameInner::new( - resource.clone(), - data.inner.lock().unwrap().constraints.clone(), - ))); - let obj = data_init.init( - frame, - FrameData { - inner: inner.clone(), - }, - ); - data.inner - .lock() - .unwrap() - .active_frames - .push(Frame { obj, inner }); - } - _ => {} + if let zcosmic_screencopy_session_v2::Request::CreateFrame { frame } = request { + let inner = Arc::new(Mutex::new(FrameInner::new( + resource.clone(), + data.inner.lock().unwrap().constraints.clone(), + ))); + let obj = data_init.init( + frame, + FrameData { + inner: inner.clone(), + }, + ); + data.inner + .lock() + .unwrap() + .active_frames + .push(Frame { obj, inner }); } } @@ -920,7 +913,7 @@ where || buffer_size.h < constraints.size.h { debug!(?buffer_size, ?constraints.size, "buffer too small for screencopy"); - inner.fail(&resource, FailureReason::BufferConstraints); + inner.fail(resource, FailureReason::BufferConstraints); return; } @@ -937,7 +930,7 @@ where ?dma_constraints, "unsupported buffer format for screencopy" ); - inner.fail(&resource, FailureReason::BufferConstraints); + inner.fail(resource, FailureReason::BufferConstraints); return; } } @@ -947,7 +940,7 @@ where Ok(data) => data, Err(err) => { debug!(?err, "Error accessing shm buffer for screencopy"); - inner.fail(&resource, FailureReason::Unknown); + inner.fail(resource, FailureReason::Unknown); return; } }; @@ -956,24 +949,24 @@ where || buffer_data.height < constraints.size.h { debug!(?buffer_data, ?constraints.size, "buffer too small for screencopy"); - inner.fail(&resource, FailureReason::BufferConstraints); + inner.fail(resource, FailureReason::BufferConstraints); return; } if !constraints.shm.contains(&buffer_data.format) { debug!(?buffer_data.format, ?constraints.shm, "unsupported buffer format for screencopy"); - inner.fail(&resource, FailureReason::BufferConstraints); + inner.fail(resource, FailureReason::BufferConstraints); return; } } x => { debug!(?x, "Attempt to screencopy with unsupported buffer type"); - inner.fail(&resource, FailureReason::BufferConstraints); + inner.fail(resource, FailureReason::BufferConstraints); return; } } } else { - inner.fail(&resource, FailureReason::Unknown); + inner.fail(resource, FailureReason::Unknown); return; } @@ -994,7 +987,7 @@ where }) { if session.inner.lock().unwrap().stopped { - inner.fail(&resource, FailureReason::Stopped); + inner.fail(resource, FailureReason::Stopped); return; } @@ -1014,14 +1007,14 @@ where }) { if session.inner.lock().unwrap().stopped { - inner.fail(&resource, FailureReason::Stopped); + inner.fail(resource, FailureReason::Stopped); return; } std::mem::drop(inner); state.cursor_frame(session, frame); } else { - inner.fail(&resource, FailureReason::Unknown); + inner.fail(resource, FailureReason::Unknown); } } _ => {} diff --git a/src/wayland/protocols/toplevel_info.rs b/src/wayland/protocols/toplevel_info.rs index 44db2031..a284f1ee 100644 --- a/src/wayland/protocols/toplevel_info.rs +++ b/src/wayland/protocols/toplevel_info.rs @@ -245,10 +245,7 @@ where _dh: &DisplayHandle, _data_init: &mut DataInit<'_, D>, ) { - match request { - zcosmic_toplevel_handle_v1::Request::Destroy => {} - _ => {} - } + if let zcosmic_toplevel_handle_v1::Request::Destroy = request {} } fn destroyed( @@ -283,7 +280,7 @@ pub fn toplevel_leave_output(toplevel: &impl Window, output: &Output) { pub fn toplevel_enter_workspace(toplevel: &impl Window, workspace: &WorkspaceHandle) { if let Some(state) = toplevel.user_data().get::() { - state.lock().unwrap().workspaces.push(workspace.clone()); + state.lock().unwrap().workspaces.push(*workspace); } } @@ -426,7 +423,7 @@ where } } -fn send_toplevel_to_client( +fn send_toplevel_to_client( dh: &DisplayHandle, workspace_state: &WorkspaceState, info: &ZcosmicToplevelInfoV1, @@ -438,7 +435,7 @@ where + Dispatch> + ToplevelInfoHandler + 'static, - W: Window, + W: Window + 'static, { let mut state = window .user_data() @@ -552,7 +549,7 @@ where .geometry .filter(|_| instance.version() >= zcosmic_toplevel_handle_v1::EVT_GEOMETRY_SINCE) .filter(|geo| output.geometry().intersection(*geo).is_some()) - .map(|geo| geo.to_local(&output)); + .map(|geo| geo.to_local(output)); for wl_output in output.client_outputs(&client) { if handle_state.wl_outputs.insert(wl_output.clone()) { instance.output_enter(&wl_output); @@ -574,7 +571,7 @@ where .iter() .any(|output| output.owns(wl_output)); if !retain { - instance.output_leave(&wl_output); + instance.output_leave(wl_output); changed = true; } retain @@ -586,7 +583,7 @@ where .iter() .filter(|w| !handle_state.workspaces.contains(w)) { - if let Some(handle) = workspace_state.raw_workspace_handle(&new_workspace, &instance.id()) { + if let Some(handle) = workspace_state.raw_workspace_handle(new_workspace, &instance.id()) { instance.workspace_enter(&handle); changed = true; } @@ -596,7 +593,7 @@ where .iter() .filter(|w| !state.workspaces.contains(w)) { - if let Some(handle) = workspace_state.raw_workspace_handle(&old_workspace, &instance.id()) { + if let Some(handle) = workspace_state.raw_workspace_handle(old_workspace, &instance.id()) { instance.workspace_leave(&handle); changed = true; } diff --git a/src/wayland/protocols/workspace.rs b/src/wayland/protocols/workspace.rs index 6d661ad7..3556349f 100644 --- a/src/wayland/protocols/workspace.rs +++ b/src/wayland/protocols/workspace.rs @@ -574,8 +574,8 @@ where fn done(&mut self) { let mut changed = false; for instance in &self.instances { - for mut group in &mut self.groups { - if send_group_to_client::(&self.dh, instance, &mut group) { + for group in &mut self.groups { + if send_group_to_client::(&self.dh, instance, group) { changed = true; } } @@ -776,11 +776,7 @@ where .iter_mut() .find_map(|g| g.workspaces.iter_mut().find(|w| w.id == workspace.id)) { - workspace.coordinates = coords - .iter() - .flat_map(std::convert::identity) - .copied() - .collect(); + workspace.coordinates = coords.iter().flatten().copied().collect(); } } @@ -1030,16 +1026,15 @@ where handle_state.states = workspace.states.clone(); changed = true; } - if instance.version() >= zcosmic_workspace_handle_v1::EVT_TILING_STATE_SINCE { - if handle_state + if instance.version() >= zcosmic_workspace_handle_v1::EVT_TILING_STATE_SINCE + && handle_state .tiling .map(|state| state != workspace.tiling) .unwrap_or(true) - { - instance.tiling_state(workspace.tiling); - handle_state.tiling = Some(workspace.tiling); - changed = true; - } + { + instance.tiling_state(workspace.tiling); + handle_state.tiling = Some(workspace.tiling); + changed = true; } changed diff --git a/src/xwayland.rs b/src/xwayland.rs index bec87771..c0fcfe98 100644 --- a/src/xwayland.rs +++ b/src/xwayland.rs @@ -131,7 +131,6 @@ impl State { Err(err) => { error!(?err, "Failed to listen for Xwayland"); self.notify_ready(); - return; } } } @@ -347,7 +346,7 @@ impl XwmHandler for State { { shell.pending_activations.insert( crate::shell::ActivationKey::X11(window.window_id()), - context.clone(), + *context, ); } @@ -363,9 +362,9 @@ impl XwmHandler for State { .find(|(window, _, _)| window.x11_surface() == Some(&surface)) .cloned() { - if !shell + if let std::collections::hash_map::Entry::Vacant(e) = shell .pending_activations - .contains_key(&crate::shell::ActivationKey::X11(surface.window_id())) + .entry(crate::shell::ActivationKey::X11(surface.window_id())) { if let Some(startup_id) = window.x11_surface().and_then(|x| x.startup_id()) { if let Some(context) = self @@ -374,10 +373,7 @@ impl XwmHandler for State { .data_for_token(&XdgActivationToken::from(startup_id)) .and_then(|data| data.user_data.get::()) { - shell.pending_activations.insert( - crate::shell::ActivationKey::X11(surface.window_id()), - context.clone(), - ); + e.insert(*context); } } } @@ -466,7 +462,7 @@ impl XwmHandler for State { set.sticky_layer .element_geometry(mapped) .unwrap() - .to_global(&output), + .to_global(output), ) } else { None @@ -647,7 +643,7 @@ impl XwmHandler for State { if let Some(mapped) = shell.element_for_surface(&window).cloned() { if let Some((output, handle)) = shell .space_for(&mapped) - .map(|workspace| (workspace.output.clone(), workspace.handle.clone())) + .map(|workspace| (workspace.output.clone(), workspace.handle)) { if let Some((surface, _)) = mapped .windows()