chore: clippy
This commit is contained in:
parent
3b70bc0265
commit
0847247c33
77 changed files with 865 additions and 1029 deletions
|
|
@ -59,9 +59,9 @@ impl From<CosmicSurface> for FocusTarget {
|
|||
}
|
||||
}
|
||||
|
||||
impl Into<KeyboardFocusTarget> for FocusTarget {
|
||||
fn into(self) -> KeyboardFocusTarget {
|
||||
match self {
|
||||
impl From<FocusTarget> for KeyboardFocusTarget {
|
||||
fn from(val: FocusTarget) -> Self {
|
||||
match val {
|
||||
FocusTarget::Window(mapped) => KeyboardFocusTarget::Element(mapped),
|
||||
FocusTarget::Fullscreen(surface) => KeyboardFocusTarget::Fullscreen(surface),
|
||||
}
|
||||
|
|
@ -94,7 +94,7 @@ impl FocusTarget {
|
|||
pub struct FocusStack<'a>(pub(super) Option<&'a IndexSet<FocusTarget>>);
|
||||
pub struct FocusStackMut<'a>(pub(super) &'a mut IndexSet<FocusTarget>);
|
||||
|
||||
impl<'a> FocusStack<'a> {
|
||||
impl FocusStack<'_> {
|
||||
/// returns the last unminimized window in the focus stack that is still alive
|
||||
pub fn last(&self) -> Option<&FocusTarget> {
|
||||
self.0
|
||||
|
|
@ -109,7 +109,7 @@ impl<'a> FocusStack<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> FocusStackMut<'a> {
|
||||
impl FocusStackMut<'_> {
|
||||
pub fn append(&mut self, target: impl Into<FocusTarget>) {
|
||||
let target = target.into();
|
||||
self.0.retain(|w| w.alive());
|
||||
|
|
@ -232,7 +232,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(_)) | Some(KeyboardFocusTarget::LockSurface(_))
|
||||
|
|
@ -248,7 +248,6 @@ impl Shell {
|
|||
FocusTarget::Fullscreen(_) => None,
|
||||
})
|
||||
})
|
||||
.flatten()
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
for output in self.outputs().cloned().collect::<Vec<_>>().into_iter() {
|
||||
|
|
@ -257,7 +256,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 window in set
|
||||
|
|
@ -291,7 +290,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() {
|
||||
|
|
@ -330,38 +329,36 @@ 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();
|
||||
// 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();
|
||||
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();
|
||||
// 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());
|
||||
// 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,
|
||||
},
|
||||
);
|
||||
}
|
||||
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,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -460,15 +457,15 @@ impl Common {
|
|||
}
|
||||
}
|
||||
|
||||
update_pointer_focus(state, &seat);
|
||||
update_pointer_focus(state, seat);
|
||||
|
||||
let output = seat.focused_or_active_output();
|
||||
let mut shell = state.common.shell.write();
|
||||
let last_known_focus = ActiveFocus::get(&seat);
|
||||
let last_known_focus = ActiveFocus::get(seat);
|
||||
|
||||
if let Some(target) = last_known_focus {
|
||||
if 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");
|
||||
|
|
@ -504,7 +501,7 @@ impl Common {
|
|||
}
|
||||
} else {
|
||||
let workspace = shell.active_space(&output).unwrap();
|
||||
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
|
||||
|
|
@ -527,7 +524,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());
|
||||
|
|
@ -547,8 +544,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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -603,8 +600,8 @@ fn focus_target_is_valid(
|
|||
.mapped()
|
||||
.any(|m| m == &mapped);
|
||||
|
||||
let workspace = shell.active_space(&output).unwrap();
|
||||
let focus_stack = workspace.focus_stack.get(&seat);
|
||||
let workspace = shell.active_space(output).unwrap();
|
||||
let focus_stack = workspace.focus_stack.get(seat);
|
||||
let is_in_focus_stack = focus_stack.last().map(|m| m == &mapped).unwrap_or(false);
|
||||
if is_sticky && !is_in_focus_stack {
|
||||
shell.append_focus_stack(mapped, seat);
|
||||
|
|
@ -613,17 +610,17 @@ fn focus_target_is_valid(
|
|||
is_sticky || is_in_focus_stack
|
||||
}
|
||||
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)
|
||||
.unwrap()
|
||||
.1
|
||||
.tiling_layer
|
||||
.has_node(&node),
|
||||
KeyboardFocusTarget::Fullscreen(window) => {
|
||||
let workspace = shell.active_space(&output).unwrap();
|
||||
let workspace = shell.active_space(output).unwrap();
|
||||
workspace.get_fullscreen().is_some_and(|w| w == &window)
|
||||
}
|
||||
KeyboardFocusTarget::Popup(_) => true,
|
||||
|
|
@ -654,15 +651,15 @@ fn update_focus_target(
|
|||
.map(KeyboardFocusTarget::from)
|
||||
} else {
|
||||
shell
|
||||
.active_space(&output)
|
||||
.active_space(output)
|
||||
.unwrap()
|
||||
.focus_stack
|
||||
.get(&seat)
|
||||
.get(seat)
|
||||
.last()
|
||||
.cloned()
|
||||
.map(Into::<KeyboardFocusTarget>::into)
|
||||
.or_else(|| {
|
||||
let workspace = shell.active_space(&output).unwrap();
|
||||
let workspace = shell.active_space(output).unwrap();
|
||||
|
||||
workspace
|
||||
.mapped()
|
||||
|
|
@ -710,10 +707,8 @@ fn exclusive_layer_surface_layer(shell: &Shell) -> Option<Layer> {
|
|||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -125,13 +125,13 @@ fn render_input_order_internal<R: 'static>(
|
|||
.last()
|
||||
.zip(fullscreen)
|
||||
.is_some_and(|(target, fullscreen)| target == &fullscreen.surface);
|
||||
let overview_is_open = workspace_overview_is_open(&output);
|
||||
let overview_is_open = workspace_overview_is_open(output);
|
||||
let has_focused_fullscreen = if is_active_workspace {
|
||||
let current_focus = seat.get_keyboard().unwrap().current_focus();
|
||||
matches!(current_focus, Some(KeyboardFocusTarget::Fullscreen(_)))
|
||||
|| (current_focus.is_none()
|
||||
&& focus_stack_is_valid_fullscreen
|
||||
&& !workspace_overview_is_open(&output))
|
||||
&& !workspace_overview_is_open(output))
|
||||
} else {
|
||||
focus_stack_is_valid_fullscreen && !overview_is_open
|
||||
};
|
||||
|
|
@ -141,7 +141,7 @@ fn render_input_order_internal<R: 'static>(
|
|||
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();
|
||||
|
|
@ -368,13 +368,13 @@ fn render_input_order_internal<R: 'static>(
|
|||
ControlFlow::Continue(())
|
||||
}
|
||||
|
||||
fn layer_popups<'a>(
|
||||
output: &'a Output,
|
||||
fn layer_popups(
|
||||
output: &Output,
|
||||
layer: Layer,
|
||||
element_filter: ElementFilter,
|
||||
) -> impl Iterator<Item = (LayerSurface, PopupKind, Point<i32, Global>)> + 'a {
|
||||
) -> impl Iterator<Item = (LayerSurface, PopupKind, Point<i32, Global>)> + '_ {
|
||||
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();
|
||||
|
|
@ -383,11 +383,11 @@ fn layer_popups<'a>(
|
|||
})
|
||||
}
|
||||
|
||||
fn layer_surfaces<'a>(
|
||||
output: &'a Output,
|
||||
fn layer_surfaces(
|
||||
output: &Output,
|
||||
layer: Layer,
|
||||
element_filter: ElementFilter,
|
||||
) -> impl Iterator<Item = (LayerSurface, Point<i32, Global>)> + 'a {
|
||||
) -> impl Iterator<Item = (LayerSurface, Point<i32, Global>)> + '_ {
|
||||
// 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);
|
||||
|
|
|
|||
|
|
@ -205,7 +205,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,
|
||||
}
|
||||
|
|
@ -278,7 +278,7 @@ impl IsAlive for KeyboardFocusTarget {
|
|||
|
||||
impl PointerTarget<State> for PointerFocusTarget {
|
||||
fn enter(&self, seat: &Seat<State>, data: &mut State, event: &PointerMotionEvent) {
|
||||
let toplevel = self.toplevel(&*data.common.shell.read());
|
||||
let toplevel = self.toplevel(&data.common.shell.read());
|
||||
if let Some(element) = toplevel {
|
||||
for session in element.cursor_sessions() {
|
||||
session.set_cursor_pos(Some(
|
||||
|
|
@ -300,7 +300,7 @@ impl PointerTarget<State> for PointerFocusTarget {
|
|||
self.inner_pointer_target().enter(seat, data, event);
|
||||
}
|
||||
fn motion(&self, seat: &Seat<State>, data: &mut State, event: &PointerMotionEvent) {
|
||||
let toplevel = self.toplevel(&*data.common.shell.read());
|
||||
let toplevel = self.toplevel(&data.common.shell.read());
|
||||
if let Some(element) = toplevel {
|
||||
for session in element.cursor_sessions() {
|
||||
session.set_cursor_pos(Some(
|
||||
|
|
@ -335,7 +335,7 @@ impl PointerTarget<State> for PointerFocusTarget {
|
|||
self.inner_pointer_target().frame(seat, data);
|
||||
}
|
||||
fn leave(&self, seat: &Seat<State>, data: &mut State, serial: Serial, time: u32) {
|
||||
let toplevel = self.toplevel(&*data.common.shell.read());
|
||||
let toplevel = self.toplevel(&data.common.shell.read());
|
||||
if let Some(element) = toplevel {
|
||||
for session in element.cursor_sessions() {
|
||||
session.set_cursor_pos(None);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue