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

@ -121,8 +121,7 @@ impl SupressedKeys {
Some(
removed
.into_iter()
.map(|(_, token)| token)
.flatten()
.filter_map(|(_, token)| token)
.collect::<Vec<_>>(),
)
}
@ -314,7 +313,7 @@ impl State {
let mut position = seat.get_pointer().unwrap().current_location().as_global();
let under = State::surface_under(position, &current_output, &mut *shell)
let under = State::surface_under(position, &current_output, &mut shell)
.map(|(target, pos)| (target, pos.as_logical()));
let ptr = seat.get_pointer().unwrap();
@ -329,7 +328,7 @@ impl State {
with_pointer_constraint(&surface, &ptr, |constraint| match constraint {
Some(constraint) if constraint.is_active() => {
// Constraint does not apply if not within region
if !constraint.region().map_or(true, |x| {
if !constraint.region().is_none_or(|x| {
x.contains(
(ptr.current_location() - *surface_loc).to_i32_round(),
)
@ -358,7 +357,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, &mut shell)
.map(|(target, pos)| (target, pos.as_logical()));
std::mem::drop(shell);
@ -382,12 +381,9 @@ impl State {
.user_data()
.get::<ResizeGrabMarker>()
.map(|marker| marker.get())
.unwrap_or(false)
{
if output != current_output {
ptr.frame(self);
return;
}
.unwrap_or(false) && output != current_output {
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 {
@ -395,11 +391,11 @@ impl State {
let old_keyboard_target = State::element_under(
original_position,
&current_output,
&*shell,
&shell,
&seat,
);
let new_keyboard_target =
State::element_under(position, &output, &*shell, &seat);
State::element_under(position, &output, &shell, &seat);
if old_keyboard_target != new_keyboard_target
&& new_keyboard_target.is_some()
@ -557,7 +553,7 @@ impl State {
};
let point =
(ptr.current_location() - surface_location).to_i32_round();
if region.map_or(true, |region| region.contains(point)) {
if region.is_none_or(|region| region.contains(point)) {
constraint.activate();
}
}
@ -574,7 +570,7 @@ impl State {
);
if output != current_output {
for session in cursor_sessions_for_output(&*shell, &current_output) {
for session in cursor_sessions_for_output(&shell, &current_output) {
session.set_cursor_pos(None);
}
seat.set_active_output(&output);
@ -626,7 +622,7 @@ impl State {
.as_global();
let serial = SERIAL_COUNTER.next_serial();
let under =
State::surface_under(position, &output, &mut *self.common.shell.write())
State::surface_under(position, &output, &mut self.common.shell.write())
.map(|(target, pos)| (target, pos.as_logical()));
let ptr = seat.get_pointer().unwrap();
@ -642,7 +638,7 @@ impl State {
ptr.frame(self);
let shell = self.common.shell.read();
for session in cursor_sessions_for_output(&*shell, &output) {
for session in cursor_sessions_for_output(&shell, &output) {
if let Some((geometry, offset)) = seat.cursor_geometry(
position.as_logical().to_buffer(
output.current_scale().fractional_scale(),
@ -922,7 +918,7 @@ impl State {
percentage *= 5.;
}
let change = -(percentage as f64 / 100.);
let change = -(percentage / 100.);
self.update_zoom(&seat, change, event.source() == AxisSource::Wheel);
}
} else {
@ -1249,7 +1245,7 @@ impl State {
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;
@ -1257,7 +1253,7 @@ impl State {
let position =
transform_output_mapped_position(&output, &event, shell.zoom_state());
let under = State::surface_under(position, &output, &mut *shell)
let under = State::surface_under(position, &output, &mut shell)
.map(|(target, pos)| (target, pos.as_logical()));
std::mem::drop(shell);
@ -1281,7 +1277,7 @@ impl State {
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;
@ -1289,7 +1285,7 @@ impl State {
let position =
transform_output_mapped_position(&output, &event, shell.zoom_state());
let under = State::surface_under(position, &output, &mut *shell)
let under = State::surface_under(position, &output, &mut shell)
.map(|(target, pos)| (target, pos.as_logical()));
std::mem::drop(shell);
@ -1372,7 +1368,7 @@ impl State {
let position =
transform_output_mapped_position(&output, &event, shell.zoom_state());
let under = State::surface_under(position, &output, &mut *shell)
let under = State::surface_under(position, &output, &mut shell)
.map(|(target, pos)| (target, pos.as_logical()));
std::mem::drop(shell);
@ -1437,7 +1433,7 @@ impl State {
let position =
transform_output_mapped_position(&output, &event, shell.zoom_state());
let under = State::surface_under(position, &output, &mut *shell)
let under = State::surface_under(position, &output, &mut shell)
.map(|(target, pos)| (target, pos.as_logical()));
std::mem::drop(shell);
@ -1602,7 +1598,7 @@ impl State {
modifiers,
&handle,
event.state(),
event.time() as u64 * 1000,
event.time() * 1000,
);
// Leave move overview mode, if any modifier was released
@ -1654,7 +1650,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
@ -1700,7 +1696,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),
keycode: None,
key: Some(handle.modified_sym()),
description: None,
@ -1774,28 +1770,26 @@ 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
@ -1918,7 +1912,7 @@ impl State {
if let Some(focus) = current_focus {
if let Some(new_descriptor) = shell
.workspaces
.active(&focused_output)
.active(focused_output)
.unwrap()
.1
.node_desc(focus)
@ -1933,7 +1927,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)
}) {
@ -1941,7 +1935,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)
}) {
@ -1951,7 +1945,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();
@ -1963,26 +1957,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).unwrap().1.handle;
let new_workspace = shell.workspaces.active(focused_output).unwrap().1.handle;
if new_workspace != old_descriptor.handle {
let spaces = shell.workspaces.spaces_mut();
let (mut old_w, mut other_w) =
@ -1993,7 +1985,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)
}) {
@ -2004,8 +1996,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,
) {
@ -2314,7 +2306,7 @@ fn cursor_sessions_for_output<'a>(
output: &'a Output,
) -> impl Iterator<Item = CursorSessionRef> + 'a {
shell
.active_space(&output)
.active_space(output)
.into_iter()
.flat_map(|workspace| {
let maybe_fullscreen = workspace.get_fullscreen();
@ -2327,7 +2319,7 @@ fn cursor_sessions_for_output<'a>(
.into_iter()
.flatten(),
)
.chain(output.cursor_sessions().into_iter())
.chain(output.cursor_sessions())
})
}