chore: clippy

This commit is contained in:
Vukašin Vojinović 2025-10-16 13:50:32 +02:00 committed by Victoria Brekenfeld
parent 3b70bc0265
commit 0847247c33
77 changed files with 865 additions and 1029 deletions

View file

@ -14,7 +14,7 @@ use smithay::{
};
use std::{
collections::{HashMap, HashSet},
ffi::{CStr, CString},
ffi::CString,
mem,
os::unix::{io::AsFd, net::UnixStream},
};
@ -49,7 +49,7 @@ impl AtspiClient {
modifiers: &ModifiersState,
) {
let keymap_text = keymap.get_as_string(xkb::KEYMAP_FORMAT_TEXT_V1);
let name = CStr::from_bytes_with_nul(b"eis-keymap\0").unwrap();
let name = c"eis-keymap";
let file = SealedFile::with_content(name, &CString::new(keymap_text).unwrap()).unwrap();
let device = seat.add_device(
@ -260,7 +260,7 @@ fn handle_event(
}
Ok(EisRequestSourceEvent::Request(EisRequest::Bind(request))) => {
if connection.has_interface("ei_keyboard")
&& request.capabilities & 2 << DeviceCapability::Keyboard as u64 != 0
&& request.capabilities & (2 << DeviceCapability::Keyboard as u64) != 0
{
let keymap = keymap_or_default(state.common.config.xkb_config());
client.add_keyboard(

View file

@ -11,16 +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.inner.active_buffers.remove(&buffer.downgrade()) {
if !device
if device.inner.active_buffers.remove(&buffer.downgrade()) && !device
.inner
.in_use(kms_state.primary_node.read().unwrap().as_ref())
{
if let Err(err) = kms_state.refresh_used_devices() {
warn!(?err, "Failed to init devices.");
};
break;
}
.in_use(kms_state.primary_node.read().unwrap().as_ref()) {
if let Err(err) = kms_state.refresh_used_devices() {
warn!(?err, "Failed to init devices.");
};
break;
}
}
}

View file

@ -122,7 +122,7 @@ pub fn frame_time_estimation(clock: &Clock<Monotonic>, states: &SurfaceData) ->
if let Some(ref last) = data.last_commit {
// if the time since the last commit is already higher than our estimation,
// there is no reason to not use that as a better "guess"
let diff = Time::elapsed(&last, clock.now());
let diff = Time::elapsed(last, clock.now());
Some(diff.max(data.estimation))
} else {
Some(data.estimation)
@ -275,7 +275,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 {
@ -349,7 +349,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,
);
}
}
@ -392,8 +392,8 @@ impl State {
} else {
None
};
if toplevel_ensure_initial_configure(&toplevel, initial_size)
&& with_renderer_surface_state(&surface, |state| state.buffer().is_some())
if toplevel_ensure_initial_configure(toplevel, initial_size)
&& with_renderer_surface_state(surface, |state| state.buffer().is_some())
.unwrap_or(false)
{
let window = pending.surface.clone();

View file

@ -68,7 +68,7 @@ impl ClientDndGrabHandler for State {
seat: Seat<Self>,
) {
let user_data = seat.user_data();
user_data.insert_if_missing_threadsafe::<Mutex<Option<DnDIcon>>, _>(|| Default::default());
user_data.insert_if_missing_threadsafe::<Mutex<Option<DnDIcon>>, _>(Default::default);
let offset = if let CursorImageStatus::Surface(ref surface) = seat.cursor_image_status() {
compositor::with_states(surface, |states| {

View file

@ -36,12 +36,11 @@ impl PreferredDecorationMode {
pub fn mode(window: &Window) -> Option<XdgMode> {
let user_data = window.user_data();
user_data.insert_if_missing(|| PreferredDecorationMode(RefCell::new(None)));
user_data
*user_data
.get::<PreferredDecorationMode>()
.unwrap()
.0
.borrow()
.clone()
}
pub fn update(window: &Window, update: Option<XdgMode>) {
@ -56,21 +55,12 @@ impl PreferredDecorationMode {
}
pub type KdeDecorationData = Mutex<KdeDecorationSurfaceState>;
#[derive(Debug)]
#[derive(Debug, Default)]
pub struct KdeDecorationSurfaceState {
pub mode: Option<KdeMode>,
pub objs: Vec<OrgKdeKwinServerDecoration>,
}
impl Default for KdeDecorationSurfaceState {
fn default() -> Self {
KdeDecorationSurfaceState {
mode: None,
objs: Vec::new(),
}
}
}
impl XdgDecorationHandler for State {
fn new_decoration(&mut self, toplevel: ToplevelSurface) {
let shell = self.common.shell.read();

View file

@ -46,7 +46,7 @@ fn kms_surfaces_for_output<'a>(
output: &'a Output,
) -> impl Iterator<Item = &'a mut Surface> + '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)
})
}

View file

@ -16,8 +16,7 @@ impl PointerConstraintsHandler for State {
fn new_constraint(&mut self, surface: &WlSurface, pointer: &PointerHandle<Self>) {
// XXX region
if pointer
.current_focus()
.map_or(false, |x| x.wl_surface().as_deref() == Some(surface))
.current_focus().is_some_and(|x| x.wl_surface().as_deref() == Some(surface))
{
with_pointer_constraint(surface, pointer, |constraint| {
constraint.unwrap().activate();

View file

@ -52,7 +52,7 @@ impl ScreencopyHandler for State {
.and_then(|output| constraints_for_output(&output, &mut self.backend)),
ImageCaptureSourceData::Workspace(handle) => {
let shell = self.common.shell.read();
let output = shell.workspaces.space_for_handle(&handle)?.output();
let output = shell.workspaces.space_for_handle(handle)?.output();
constraints_for_output(output, &mut self.backend)
}
ImageCaptureSourceData::Toplevel(window) => {
@ -339,7 +339,7 @@ fn constraints_for_output(output: &Output, backend: &mut BackendData) -> Option<
let mut renderer = backend
.offscreen_renderer(|kms| {
kms.target_node_for_output(&output)
kms.target_node_for_output(output)
.or(*kms.primary_node.read().unwrap())
})
.unwrap();
@ -357,7 +357,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();

View file

@ -173,7 +173,7 @@ where
Ok(Some(PendingImageCopyData {
frame,
damage: damage
.into_iter()
.iter()
.map(|rect| {
let logical = rect.to_logical(1);
logical.to_buffer(1, transform.invert(), &buffer_size.to_logical(1, transform))
@ -354,7 +354,7 @@ pub fn render_workspace_to_buffer(
&common.shell,
None,
common.clock.now(),
&output,
output,
None,
handle,
cursor_mode,
@ -373,7 +373,7 @@ pub fn render_workspace_to_buffer(
&common.shell,
None,
common.clock.now(),
&output,
output,
None,
handle,
cursor_mode,
@ -655,7 +655,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()
})
})
@ -783,7 +783,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(),
1.0,

View file

@ -37,14 +37,14 @@ impl SecurityContextHandler for State {
let drm_node = client_data
.as_ref()
.and_then(|data| data.downcast_ref::<ClientState>())
.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::<XWaylandClientData>())
.and_then(|data| data.user_data().get::<DrmNode>().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,

View file

@ -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);
}
}

View file

@ -52,7 +52,7 @@ impl ToplevelManagementHandler for State {
let (target, new_pos) = if let Some((idx, workspace)) = maybe {
let handle = workspace.handle;
let new_pos = shell.activate(
&output,
output,
idx,
WorkspaceDelta::new_shortcut(),
&mut self.common.workspace_state.update(),
@ -112,7 +112,7 @@ impl ToplevelManagementHandler for State {
if seat.active_output() != *output {
if let Some(new_pos) = 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(
@ -150,7 +150,7 @@ impl ToplevelManagementHandler for State {
let Some(surface) = window.wl_surface() else {
return;
};
let Some((from_workspace, _)) = shell.workspace_for_surface(&*surface) else {
let Some((from_workspace, _)) = shell.workspace_for_surface(&surface) else {
return;
};
@ -182,7 +182,7 @@ impl ToplevelManagementHandler for State {
.or_else(|| {
window
.wl_surface()
.and_then(|surface| shell.visible_output_for_surface(&*surface).cloned())
.and_then(|surface| shell.visible_output_for_surface(&surface).cloned())
})
.unwrap_or_else(|| seat.focused_or_active_output());
if let Some(target) =

View file

@ -126,7 +126,7 @@ impl XdgActivationHandler for State {
let Some((element_output, element_workspace)) = shell
.space_for(&element)
.map(|w| (w.output.clone(), w.handle.clone()))
.map(|w| (w.output.clone(), w.handle))
else {
return;
};
@ -227,7 +227,7 @@ impl XdgActivationHandler for State {
} else {
shell
.pending_activations
.insert(ActivationKey::Wayland(surface), context.clone());
.insert(ActivationKey::Wayland(surface), *context);
};
}
}

View file

@ -99,7 +99,7 @@ impl XdgShellHandler for State {
});
if let Some(root) = maybe_root {
let target = root.into();
let target = root;
let ret = self.common.popups.grab_popup(target, kind, &seat, serial);
match ret {
Ok(mut grab) => {
@ -304,12 +304,10 @@ impl XdgShellHandler for State {
if should_focus {
Shell::set_focus(self, Some(&target), &seat, None, true);
}
} else {
if let Some(pending) = shell.pending_windows.iter_mut().find(|pending| {
pending.surface.wl_surface().as_deref() == Some(surface.wl_surface())
}) {
pending.fullscreen.take();
}
} else if let Some(pending) = shell.pending_windows.iter_mut().find(|pending| {
pending.surface.wl_surface().as_deref() == Some(surface.wl_surface())
}) {
pending.fullscreen.take();
}
}
@ -337,12 +335,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);
}
}

View file

@ -22,7 +22,7 @@ use tracing::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) {
@ -87,14 +87,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::<XdgPopupSurfaceData>()
.unwrap()
.lock()
.unwrap();
attributes.current.positioner.clone()
attributes.current.positioner
});
if positioner.reactive {
let anchor_point = loc + positioner.get_anchor_point().as_global();