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

@ -241,10 +241,7 @@ 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) }
}
pub fn has_surface(&self, surface: &WlSurface, surface_type: WindowSurfaceType) -> bool {
@ -446,7 +443,7 @@ impl CosmicMapped {
pub fn set_bounds(&self, size: impl Into<Option<Size<i32, Logical>>>) {
let size = size.into();
for (surface, _) in self.windows() {
surface.set_bounds(size.clone())
surface.set_bounds(size)
}
}
@ -508,24 +505,21 @@ impl CosmicMapped {
(output, overlap): (&Output, Rectangle<i32, Logical>),
theme: cosmic::Theme,
) {
match &self.element {
CosmicMappedInternal::Window(window) => {
let surface = window.surface();
let activated = surface.is_activated(true);
let handle = window.loop_handle();
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().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);
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);
}
}
@ -540,8 +534,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));
@ -843,7 +837,7 @@ impl CosmicMapped {
pub fn ssd_height(&self, pending: bool) -> Option<i32> {
match &self.element {
CosmicMappedInternal::Window(w) => (!w.surface().is_decorated(pending))
.then(|| crate::shell::element::window::SSD_HEIGHT),
.then_some(crate::shell::element::window::SSD_HEIGHT),
CosmicMappedInternal::Stack(_) => Some(crate::shell::element::stack::TAB_HEIGHT),
_ => unreachable!(),
}

View file

@ -180,7 +180,7 @@ impl CosmicStack {
*prev_idx = last_mod_serial.map(|s| (s, p.active.load(Ordering::SeqCst)));
}
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);
@ -210,7 +210,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;
@ -238,7 +238,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());
@ -545,10 +545,9 @@ impl CosmicStack {
pub fn pending_size(&self) -> Option<Size<i32, Logical>> {
self.0.with_program(|p| {
p.geometry
(*p.geometry
.lock()
.unwrap()
.clone()
.unwrap())
.map(|geo| geo.size.as_logical())
})
}
@ -1466,17 +1465,11 @@ impl PointerTarget<State> for CosmicStack {
}
fn axis(&self, seat: &Seat<State>, 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<State>, 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) }
}
fn leave(&self, seat: &Seat<State>, data: &mut State, serial: Serial, time: u32) {
@ -1607,7 +1600,7 @@ impl TouchTarget<State> for CosmicStack {
}
fn up(&self, seat: &Seat<State>, 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<State>, data: &mut State, event: &TouchMotionEvent, seq: Serial) {

View file

@ -239,7 +239,7 @@ pub(super) struct TabInternal<'a, Message: TabMessage> {
right_click_message: Option<Message>,
}
impl<'a, Message> Widget<Message, cosmic::Theme, cosmic::Renderer> for TabInternal<'a, Message>
impl<Message> Widget<Message, cosmic::Theme, cosmic::Renderer> for TabInternal<'_, Message>
where
Message: TabMessage,
{

View file

@ -125,7 +125,7 @@ impl Offset {
const SCROLL_ANIMATION_DURATION: Duration = Duration::from_millis(200);
const TAB_ANIMATION_DURATION: Duration = Duration::from_millis(150);
impl<'a, Message> Tabs<'a, Message>
impl<Message> Tabs<'_, Message>
where
Message: TabMessage + 'static,
{
@ -308,7 +308,7 @@ impl State {
}
}
impl<'a, Message> Widget<Message, cosmic::Theme, cosmic::Renderer> for Tabs<'a, Message>
impl<Message> Widget<Message, cosmic::Theme, cosmic::Renderer> for Tabs<'_, Message>
where
Message: TabMessage,
{

View file

@ -81,14 +81,13 @@ impl From<X11Surface> for CosmicSurface {
impl PartialEq<WlSurface> for CosmicSurface {
fn eq(&self, other: &WlSurface) -> bool {
self.wl_surface().map_or(false, |s| &*s == other)
self.wl_surface().is_some_and(|s| &*s == other)
}
}
impl PartialEq<ToplevelSurface> for CosmicSurface {
fn eq(&self, other: &ToplevelSurface) -> bool {
self.wl_surface()
.map_or(false, |s| &*s == other.wl_surface())
self.wl_surface().is_some_and(|s| &*s == other.wl_surface())
}
}
@ -280,7 +279,7 @@ impl CosmicSurface {
WindowSurface::Wayland(toplevel) => {
if enable {
let previous_decoration_state =
toplevel.current_state().decoration_mode.clone();
toplevel.current_state().decoration_mode;
if PreferredDecorationMode::is_unset(&self.0) {
PreferredDecorationMode::update(&self.0, previous_decoration_state);
}
@ -639,10 +638,8 @@ impl CosmicSurface {
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) {

View file

@ -252,7 +252,7 @@ impl CosmicWindow {
let geo = p.window.geometry();
let point_i32 = relative_pos.to_i32_round::<i32>();
let ssd_height = has_ssd.then_some(SSD_HEIGHT).unwrap_or(0);
let ssd_height = if has_ssd { SSD_HEIGHT } else { 0 };
if (point_i32.x - geo.loc.x >= -RESIZE_BORDER && point_i32.x - geo.loc.x < 0)
|| (point_i32.y - geo.loc.y >= -RESIZE_BORDER && point_i32.y - geo.loc.y < 0)
@ -708,7 +708,7 @@ impl PointerTarget<State> for CosmicWindow {
if has_ssd || p.is_tiled(false) {
let Some(next) = Focus::under(
&p.window,
has_ssd.then_some(SSD_HEIGHT).unwrap_or(0),
if has_ssd { SSD_HEIGHT } else { 0 },
event.location,
) else {
return;
@ -734,7 +734,7 @@ impl PointerTarget<State> for CosmicWindow {
if has_ssd || p.is_tiled(false) {
let Some(next) = Focus::under(
&p.window,
has_ssd.then_some(SSD_HEIGHT).unwrap_or(0),
if has_ssd { SSD_HEIGHT } else { 0 },
event.location,
) else {
return;
@ -804,17 +804,11 @@ impl PointerTarget<State> for CosmicWindow {
}
fn axis(&self, seat: &Seat<State>, 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<State>, 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) }
}
fn leave(&self, seat: &Seat<State>, data: &mut State, serial: Serial, time: u32) {
@ -901,7 +895,7 @@ impl TouchTarget<State> for CosmicWindow {
}
fn up(&self, seat: &Seat<State>, 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<State>, data: &mut State, event: &TouchMotionEvent, seq: Serial) {

View file

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

View file

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

View file

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

View file

@ -51,9 +51,7 @@ fn next_workspace(
shell
.workspaces
.spaces_for_output(&output)
.skip_while(|space| space.handle != current_handle)
.skip(1)
.next()
.skip_while(|space| space.handle != current_handle).nth(1)
.map(|space| (current_handle, space.handle))
}
@ -62,7 +60,7 @@ fn move_fullscreen_prev_workspace(state: &mut State, surface: &CosmicSurface) {
let Some(wl_surface) = surface.wl_surface() else {
return;
};
let Some((from, to)) = prev_workspace(&shell, &*wl_surface) else {
let Some((from, to)) = prev_workspace(&shell, &wl_surface) else {
return;
};
@ -88,7 +86,7 @@ fn move_fullscreen_next_workspace(state: &mut State, surface: &CosmicSurface) {
let Some(wl_surface) = surface.wl_surface() else {
return;
};
let Some((from, to)) = next_workspace(&shell, &*wl_surface) else {
let Some((from, to)) = next_workspace(&shell, &wl_surface) else {
return;
};
@ -115,7 +113,7 @@ fn move_element_prev_workspace(state: &mut State, mapped: &CosmicMapped) {
let Some(wl_surface) = window.wl_surface() else {
return;
};
let Some((from, to)) = prev_workspace(&shell, &*wl_surface) else {
let Some((from, to)) = prev_workspace(&shell, &wl_surface) else {
return;
};
@ -141,7 +139,7 @@ fn move_element_next_workspace(state: &mut State, mapped: &CosmicMapped) {
let Some(wl_surface) = window.wl_surface() else {
return;
};
let Some((from, to)) = next_workspace(&shell, &*wl_surface) else {
let Some((from, to)) = next_workspace(&shell, &wl_surface) else {
return;
};

View file

@ -40,7 +40,7 @@ struct State {
cursor_over: bool,
}
impl<'a, Message> Widget<Message, cosmic::Theme, cosmic::Renderer> for SubmenuItem<'a, Message>
impl<Message> Widget<Message, cosmic::Theme, cosmic::Renderer> for SubmenuItem<'_, Message>
where
Message: CursorEvents,
{
@ -216,11 +216,11 @@ where
}
}
impl<'a, Message> Into<cosmic::Element<'a, Message>> for SubmenuItem<'a, Message>
impl<'a, Message> From<SubmenuItem<'a, Message>> 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)
}
}

View file

@ -381,7 +381,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,
@ -968,8 +968,7 @@ impl MenuAlignment {
size,
AxisAlignment::Centered,
AxisAlignment::Corner(0),
)
.into_iter(),
),
)
.chain(
for_alignment(
@ -977,8 +976,7 @@ impl MenuAlignment {
size,
AxisAlignment::Corner(0),
AxisAlignment::Centered,
)
.into_iter(),
),
)
.chain(
for_alignment(
@ -986,15 +984,14 @@ impl MenuAlignment {
size,
AxisAlignment::Corner(0),
AxisAlignment::Corner(0),
)
.into_iter(),
),
)
.collect(),
(AxisAlignment::PreferCentered, y) => {
for_alignment(position, size, AxisAlignment::Centered, y)
.into_iter()
.chain(
for_alignment(position, size, AxisAlignment::Corner(0), y).into_iter(),
for_alignment(position, size, AxisAlignment::Corner(0), y),
)
.collect()
}
@ -1002,7 +999,7 @@ impl MenuAlignment {
for_alignment(position, size, x, AxisAlignment::Centered)
.into_iter()
.chain(
for_alignment(position, size, x, AxisAlignment::Corner(0)).into_iter(),
for_alignment(position, size, x, AxisAlignment::Corner(0)),
)
.collect()
}

View file

@ -122,9 +122,9 @@ impl From<shortcuts::action::ResizeEdge> for ResizeEdge {
}
}
impl Into<shortcuts::action::ResizeEdge> for ResizeEdge {
fn into(self) -> shortcuts::action::ResizeEdge {
match self {
impl From<ResizeEdge> 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,

View file

@ -92,11 +92,10 @@ 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()
.intersection(window_geo).is_none()
{
return Vec::new();
}
@ -136,15 +135,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()
};
@ -173,8 +171,7 @@ impl MoveGrabState {
active_window_hint.green,
active_window_hint.blue,
],
))
.into(),
)),
CosmicMappedRenderElement::from(BackdropShader::element(
renderer,
Key::Window(Usage::SnappingIndicator, self.window.key()),
@ -182,8 +179,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![],
@ -431,7 +427,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);
@ -440,7 +436,7 @@ impl MoveGrab {
}
let indicator_location =
shell.stacking_indicator(&current_output, self.previous.clone());
shell.stacking_indicator(&current_output, self.previous);
if indicator_location.is_some() != grab_state.stacking_indicator.is_some() {
grab_state.stacking_indicator = indicator_location.map(|geo| {
let element = stack_hover(
@ -739,7 +735,7 @@ impl MoveGrab {
start: Instant::now(),
stacking_indicator: None,
snapping_zone: None,
previous: previous_layer.clone(),
previous: previous_layer,
location: start_data.location(),
cursor_output: cursor_output.clone(),
};
@ -787,7 +783,7 @@ impl Drop for MoveGrab {
let output = self.cursor_output.clone();
let seat = self.seat.clone();
let window_outputs = self.window_outputs.drain().collect::<HashSet<_>>();
let previous = self.previous.clone();
let previous = self.previous;
let window = self.window.clone();
let is_touch_grab = matches!(self.start_data, GrabStartData::Touch(_));

View file

@ -101,22 +101,18 @@ impl ResizeSurfaceGrab {
// If the resizing vertical edge is close to our output's edge in the same direction, snap to it.
let output_geom = self.output.geometry().to_local(&self.output);
if self.edges.intersects(ResizeEdge::LEFT) {
if ((self.initial_window_location.x - dx as i32 - output_geom.loc.x).abs() as u32)
if (self.initial_window_location.x - dx as i32 - output_geom.loc.x).unsigned_abs()
< self.edge_snap_threshold
{
new_window_width = self.initial_window_size.w - output_geom.loc.x
+ self.initial_window_location.x;
}
} else {
if ((self.initial_window_location.x + self.initial_window_size.w + dx as i32
- output_geom.loc.x
- output_geom.size.w)
.abs() as u32)
< self.edge_snap_threshold
{
new_window_width =
output_geom.loc.x - self.initial_window_location.x + output_geom.size.w;
}
} else if (self.initial_window_location.x + self.initial_window_size.w + dx as i32
- output_geom.loc.x - output_geom.size.w).unsigned_abs()
< self.edge_snap_threshold
{
new_window_width =
output_geom.loc.x - self.initial_window_location.x + output_geom.size.w;
}
}
@ -131,22 +127,18 @@ impl ResizeSurfaceGrab {
// If the resizing horizontal edge is close to our output's edge in the same direction, snap to it.
let output_geom = self.output.geometry().to_local(&self.output);
if self.edges.intersects(ResizeEdge::TOP) {
if ((self.initial_window_location.y - dy as i32 - output_geom.loc.y).abs() as u32)
if (self.initial_window_location.y - dy as i32 - output_geom.loc.y).unsigned_abs()
< self.edge_snap_threshold
{
new_window_height = self.initial_window_size.h - output_geom.loc.y
+ self.initial_window_location.y;
}
} else {
if ((self.initial_window_location.y + self.initial_window_size.h + dy as i32
- output_geom.loc.y
- output_geom.size.h)
.abs() as u32)
< self.edge_snap_threshold
{
new_window_height =
output_geom.loc.y - self.initial_window_location.y + output_geom.size.h;
}
} else if (self.initial_window_location.y + self.initial_window_size.h + dy as i32
- output_geom.loc.y - output_geom.size.h).unsigned_abs()
< self.edge_snap_threshold
{
new_window_height =
output_geom.loc.y - self.initial_window_location.y + output_geom.size.h;
}
}
@ -361,10 +353,8 @@ impl TouchGrab<State> for ResizeSurfaceGrab {
event: &TouchMotionEvent,
seq: Serial,
) {
if event.slot == <Self as TouchGrab<State>>::start_data(self).slot {
if self.update_location(event.location.as_global()) {
handle.unset_grab(self, data);
}
if event.slot == <Self as TouchGrab<State>>::start_data(self).slot && self.update_location(event.location.as_global()) {
handle.unset_grab(self, data);
}
handle.motion(data, None, event, seq);
@ -514,7 +504,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);
}
@ -555,7 +545,7 @@ impl ResizeSurfaceGrab {
}
floating_layer.space.map_element(
window,
new_location.to_local(&output).as_logical(),
new_location.to_local(output).as_logical(),
false,
);
}

View file

@ -137,7 +137,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))
@ -149,7 +149,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 =
@ -284,7 +284,7 @@ impl FloatingLayout {
}
.to_f64();
let output_geometry = {
let layers = layer_map_for_output(&output);
let layers = layer_map_for_output(output);
layers.non_exclusive_zone()
};
@ -295,7 +295,7 @@ impl FloatingLayout {
.collect::<Vec<_>>()
.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(
@ -383,7 +383,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;
}
};
@ -407,7 +407,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
@ -688,7 +688,7 @@ impl FloatingLayout {
*window.last_geometry.lock().unwrap() = Some(mapped_geometry);
}
self.space.unmap_elem(&window);
self.space.unmap_elem(window);
if let Some(pos) = self.spawn_order.iter().position(|w| w == window) {
self.spawn_order.truncate(pos);
}
@ -877,7 +877,7 @@ impl FloatingLayout {
}
pub fn stacking_indicator(&self) -> Option<Rectangle<i32, Local>> {
self.hovered_stack.as_ref().map(|(_, geo)| geo.clone())
self.hovered_stack.as_ref().map(|(_, geo)| *geo)
}
pub fn resize_request(
@ -890,7 +890,7 @@ impl FloatingLayout {
release: ReleaseMode,
) -> Option<ResizeSurfaceGrab> {
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 {
@ -1313,7 +1313,7 @@ impl FloatingLayout {
let window_geometry = if mapped.is_maximized(false) {
geometry
} else {
prev.clone()
prev
.map(|mut rect| {
if let Some(old_size) = old_output_size {
rect = Rectangle::new(
@ -1529,14 +1529,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) => {
@ -1549,14 +1549,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,
@ -1566,7 +1566,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();

View file

@ -535,10 +535,8 @@ impl TouchGrab<State> for ResizeForkGrab {
event: &TouchMotionEvent,
seq: Serial,
) {
if event.slot == <Self as TouchGrab<State>>::start_data(self).slot {
if self.update_location(data, event.location, false) {
handle.unset_grab(self, data);
}
if event.slot == <Self as TouchGrab<State>>::start_data(self).slot && self.update_location(data, event.location, false) {
handle.unset_grab(self, data);
}
handle.motion(data, None, event, seq);

View file

@ -49,7 +49,7 @@ impl KeyboardGrab<State> 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

View file

@ -500,7 +500,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 {
@ -542,7 +542,7 @@ impl TilingLayout {
}
fn map_to_tree(
mut tree: &mut Tree<Data>,
tree: &mut Tree<Data>,
window: impl Into<CosmicMapped>,
output: &Output,
node: Option<NodeId>,
@ -564,7 +564,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 {
@ -577,36 +577,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()
}
};
@ -666,7 +664,7 @@ impl TilingLayout {
let this_stack = this_mapped.stack_ref()?;
this_stack.remove_window(&stack_surface);
if !this_stack.alive() {
let _ = this.unmap(&this_mapped, None);
let _ = this.unmap(this_mapped, None);
}
let mapped: CosmicMapped =
@ -687,13 +685,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::<Vec<_>>();
let node = Node::new(node.data().clone());
@ -819,7 +817,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
@ -915,12 +913,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::<Vec<_>>();
let mut other_children = other_node
.children()
.into_iter()
.iter()
.map(|child_id| (this_desc.node.clone(), child_id.clone()))
.collect::<Vec<_>>();
@ -1070,7 +1068,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(),
@ -1157,7 +1155,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(),
@ -1266,12 +1264,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),
}
}
@ -1311,7 +1309,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()
@ -1325,7 +1323,7 @@ impl TilingLayout {
// this group will be flattened
Some(RestoreTilingState {
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(),
@ -1390,7 +1388,7 @@ impl TilingLayout {
.data_mut();
*data = Data::Placeholder {
id: Id::new(),
last_geometry: data.geometry().clone(),
last_geometry: *data.geometry(),
type_,
};
@ -1435,7 +1433,7 @@ impl TilingLayout {
fn unmap_internal(tree: &mut Tree<Data>, 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)
});
@ -1470,7 +1468,7 @@ impl TilingLayout {
&other_child,
parent_parent_id
.as_ref()
.map(|parent_id| MoveBehavior::ToParent(parent_id))
.map(MoveBehavior::ToParent)
.unwrap_or(MoveBehavior::ToRoot),
)
.unwrap();
@ -1736,9 +1734,7 @@ impl TilingLayout {
// we move again by making a new fork
let old_id = tree
.children_ids(&next_child_id)
.unwrap()
.skip(group_len / 2)
.next()
.unwrap().nth(group_len / 2)
.unwrap()
.clone();
TilingLayout::new_group(
@ -1887,7 +1883,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());
@ -1908,7 +1904,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 {
@ -1925,7 +1921,7 @@ impl TilingLayout {
// which child are we?
let idx = tree
.children_ids(&group)
.children_ids(group)
.unwrap()
.position(|id| id == &child)
.unwrap();
@ -1936,13 +1932,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
};
@ -1965,7 +1961,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()
@ -2653,7 +2649,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 {
@ -2671,7 +2667,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();
@ -2689,7 +2685,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 {
@ -2710,9 +2706,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(),
@ -2722,7 +2718,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 {
@ -2730,7 +2726,7 @@ impl TilingLayout {
last_geometry: Rectangle::from_size((100, 100).into()),
minimize_rect: None,
}),
InsertBehavior::UnderNode(&window_id),
InsertBehavior::UnderNode(window_id),
)
.unwrap();
let orientation = if matches!(direction, Direction::Left | Direction::Right) {
@ -2738,14 +2734,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());
@ -2978,7 +2974,7 @@ impl TilingLayout {
let mut configures = Vec::new();
let (outer, inner) = gaps;
let mut geo = layer_map_for_output(&output)
let mut geo = layer_map_for_output(output)
.non_exclusive_zone()
.as_local();
geo.loc.x += outer;
@ -3095,7 +3091,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));
@ -3312,9 +3308,7 @@ impl TilingLayout {
(last_geometry.loc
+ tree
.children(&id)
.unwrap()
.skip(idx)
.next()
.unwrap().nth(idx)
.map(|node| {
let geo = node.data().geometry();
geo.loc + geo.size
@ -3647,7 +3641,7 @@ impl TilingLayout {
} => true,
_ => false,
})
.map(|node_id| TargetZone::InitialPlaceholder(node_id))
.map(TargetZone::InitialPlaceholder)
.unwrap_or(TargetZone::Initial),
));
}
@ -3684,14 +3678,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())
@ -3714,7 +3708,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;
@ -3726,7 +3720,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;
@ -3761,7 +3755,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();
@ -3771,7 +3765,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 =
@ -3785,7 +3779,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));
@ -3823,9 +3817,7 @@ impl TilingLayout {
pub fn mapped(&self) -> impl Iterator<Item = (&CosmicMapped, Rectangle<i32, Local>)> {
let tree = &self.queue.trees.back().unwrap().0;
let iter = if let Some(root) = tree.root_node_id() {
Some(
tree.traverse_pre_order(root)
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() {
@ -3837,7 +3829,7 @@ impl TilingLayout {
mapped,
last_geometry,
..
} => (mapped, last_geometry.clone()),
} => (mapped, *last_geometry),
_ => unreachable!(),
})
.chain(
@ -3853,14 +3845,10 @@ impl TilingLayout {
mapped,
last_geometry,
..
} => (mapped, last_geometry.clone()),
} => (mapped, *last_geometry),
_ => unreachable!(),
}),
),
)
} else {
None
};
));
iter.into_iter().flatten()
}
@ -3868,7 +3856,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
@ -3933,7 +3921,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))
@ -4027,7 +4015,7 @@ impl TilingLayout {
&self.backdrop_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 {
@ -4064,7 +4052,7 @@ impl TilingLayout {
&self.backdrop_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 {
@ -4176,7 +4164,7 @@ impl TilingLayout {
&self.backdrop_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 {
@ -4211,7 +4199,7 @@ impl TilingLayout {
&self.backdrop_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 {
@ -4326,14 +4314,10 @@ 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();
@ -4510,7 +4494,7 @@ where
.parent()
.map(|parent_id| {
matches!(
tree.get(&parent_id).unwrap().data(),
tree.get(parent_id).unwrap().data(),
Data::Group {
pill_indicator: Some(_),
..
@ -4630,7 +4614,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(
@ -4855,7 +4839,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(),
@ -5092,8 +5076,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::new(
@ -5206,7 +5190,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() {
@ -5275,7 +5259,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
@ -5344,7 +5328,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
@ -5437,7 +5421,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();
@ -5572,7 +5556,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()
@ -5582,12 +5566,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);
}
}
},
@ -5666,7 +5648,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()
@ -5694,7 +5676,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::new(

View file

@ -170,7 +170,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 {
@ -361,7 +361,7 @@ fn create_workspace(
) -> Workspace {
let workspace_handle = state
.create_workspace(
&group_handle,
group_handle,
if tiling {
TilingState::TilingEnabled
} else {
@ -394,7 +394,7 @@ fn create_workspace_from_pinned(
) -> Workspace {
let workspace_handle = state
.create_workspace(
&group_handle,
group_handle,
if pinned.tiling_enabled {
TilingState::TilingEnabled
} else {
@ -533,7 +533,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, explicit);
@ -591,8 +591,7 @@ impl WorkspaceSet {
// add empty at the end, if necessary
if self
.workspaces
.last()
.map_or(true, |last| !last.is_empty() || last.pinned)
.last().is_none_or(|last| !last.is_empty() || last.pinned)
{
self.add_empty_workspace(state);
}
@ -607,8 +606,7 @@ impl WorkspaceSet {
let previous_is_empty = i > 0
&& self
.workspaces
.get(i - 1)
.map_or(false, |w| w.is_empty() && !w.pinned);
.get(i - 1).is_some_and(|w| w.is_empty() && !w.pinned);
let keep = if workspace.can_auto_remove(xdg_activation_state) {
// Keep empty workspace if it's active, or it's the last workspace,
// and the previous worspace is not both active and empty.
@ -632,7 +630,7 @@ impl WorkspaceSet {
.filter(|kept| !**kept)
.count();
if kept.iter().any(|val| *val == false) {
if kept.iter().any(|val| !(*val)) {
self.update_workspace_idxs(state);
}
}
@ -736,9 +734,9 @@ impl Workspaces {
set
})
.unwrap_or_else(|| {
WorkspaceSet::new(workspace_state, &output, self.autotile, self.theme.clone())
WorkspaceSet::new(workspace_state, output, self.autotile, self.theme.clone())
});
workspace_state.add_group_output(&set.group, &output);
workspace_state.add_group_output(&set.group, output);
// If this is the first output added, create workspaces for pinned workspaces from config
for pinned in std::mem::take(&mut self.persisted_workspaces) {
@ -1152,7 +1150,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() {
set.update_workspace_idxs(workspace_state);
}
@ -1751,7 +1749,7 @@ impl Shell {
KeyboardFocusTarget::Fullscreen(elem) => self
.outputs()
.find(|output| {
let workspace = self.active_space(&output).unwrap();
let workspace = self.active_space(output).unwrap();
workspace.get_fullscreen() == Some(&elem)
})
.cloned(),
@ -1759,7 +1757,7 @@ impl Shell {
.outputs()
.find(|output| {
self.workspaces
.active(&output)
.active(output)
.unwrap()
.1
.tiling_layer
@ -1809,7 +1807,6 @@ impl Shell {
match focus_target {
KeyboardFocusTarget::Group(_group) => {
//TODO: decide if we want close actions to apply to groups
return;
}
KeyboardFocusTarget::Fullscreen(surface) => {
surface.close();
@ -1937,7 +1934,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()
@ -1951,7 +1948,7 @@ impl Shell {
.is_some_and(|m| m.has_surface(surface, WindowSurfaceType::ALL))
})
})
.map(|w| (w.handle.clone(), w.output().clone())),
.map(|w| (w.handle, w.output().clone())),
}
}
@ -2130,24 +2127,22 @@ 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);
}
}
@ -2188,12 +2183,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);
}
}
}
@ -2449,7 +2442,7 @@ impl Shell {
.workspaces
.sets
.get_mut(&output)
.or_else(|| self.workspaces.backup_set.as_mut())
.or(self.workspaces.backup_set.as_mut())
.unwrap();
set.sticky_layer.map_internal(
window.clone(),
@ -2464,7 +2457,7 @@ impl Shell {
let workspace = match &state {
Some(FullscreenRestoreState::Floating { workspace, .. })
| Some(FullscreenRestoreState::Tiling { workspace, .. }) => {
let workspace = self.workspaces.space_for_handle_mut(&workspace);
let workspace = self.workspaces.space_for_handle_mut(workspace);
let workspace = match workspace {
Some(workspace) => workspace,
None => self.workspaces.active_mut(&seat.active_output()).unwrap(),
@ -2936,12 +2929,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,
@ -2957,7 +2950,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)
}) {
@ -2982,7 +2975,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,
@ -3003,7 +2996,7 @@ impl Shell {
.collect::<Vec<_>>()
.into_iter()
{
to_workspace.toggle_floating_window(&seat, &mapped);
to_workspace.toggle_floating_window(seat, &mapped);
}
to_workspace.tiling_enabled = false;
}
@ -3145,7 +3138,7 @@ impl Shell {
{
to_workspace.unmaximize_request(&mapped);
}
let focus_stack = seat.map(|seat| to_workspace.focus_stack.get(&seat));
let focus_stack = seat.map(|seat| to_workspace.focus_stack.get(seat));
to_workspace.tiling_layer.map(
mapped.clone(),
focus_stack.as_ref().map(|x| x.iter()),
@ -3239,7 +3232,7 @@ impl Shell {
{
to_workspace.unmaximize_request(&mapped);
}
let focus_stack = seat.map(|seat| to_workspace.focus_stack.get(&seat));
let focus_stack = seat.map(|seat| to_workspace.focus_stack.get(seat));
to_workspace.tiling_layer.map(
mapped.clone(),
focus_stack.as_ref().map(|x| x.iter()),
@ -3301,7 +3294,7 @@ impl Shell {
) -> Option<(MenuGrab, Focus)> {
let serial = serial.into();
let Some(GrabStartData::Pointer(start_data)) =
check_grab_preconditions(&seat, serial, Some(surface))
check_grab_preconditions(seat, serial, Some(surface))
else {
return None; // TODO: an application can send a menu request for a touch event
};
@ -3316,7 +3309,7 @@ impl Shell {
if target_stack || !is_stacked {
Box::new(
window_items(
&mapped,
mapped,
is_tiled,
is_stacked,
is_sticky,
@ -3333,7 +3326,7 @@ impl Shell {
.find(|(s, _)| s.wl_surface().as_deref() == Some(surface))
.unwrap();
Box::new(
tab_items(&mapped, &tab, is_tiled, config)
tab_items(mapped, &tab, is_tiled, config)
.collect::<Vec<Item>>()
.into_iter(),
) as Box<dyn Iterator<Item = Item>>
@ -3352,13 +3345,13 @@ impl Shell {
.map(|(mapped, relative_loc)| (set, mapped, relative_loc))
}) {
let output = set.output.clone();
let global_position = (set.sticky_layer.element_geometry(&mapped).unwrap().loc
let global_position = (set.sticky_layer.element_geometry(mapped).unwrap().loc
+ relative_loc.as_local()
+ location.as_local())
.to_global(&output);
(
global_position,
items_for_element(&mapped, false, true, false, ResizeEdge::all()),
items_for_element(mapped, false, true, false, ResizeEdge::all()),
)
} else if let Some((workspace, output)) = self.workspace_for_surface(surface) {
let workspace = self.workspaces.space_for_handle(&workspace).unwrap();
@ -3396,7 +3389,7 @@ impl Shell {
(
global_position,
items_for_element(&mapped, is_tiled, false, workspace.tiling_enabled, edge),
items_for_element(mapped, is_tiled, false, workspace.tiling_enabled, edge),
)
}
} else {
@ -3436,7 +3429,7 @@ impl Shell {
let mut element_geo = None;
let mut start_data =
check_grab_preconditions(&seat, serial, client_initiated.then_some(surface))?;
check_grab_preconditions(seat, serial, client_initiated.then_some(surface))?;
let maybe_fullscreen_workspace = self
.workspaces
@ -3523,7 +3516,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, None);
let was_tiled = workspace
.tiling_layer
@ -3538,14 +3531,12 @@ 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),
@ -3650,7 +3641,7 @@ impl Shell {
KeyboardFocusTarget::Fullscreen(surface) => {
if let Some(workspace) = surface
.wl_surface()
.and_then(|s| self.workspace_for_surface(&*s))
.and_then(|s| self.workspace_for_surface(&s))
.and_then(|(handle, _)| self.workspaces.space_for_handle(&handle))
{
workspace
@ -3683,9 +3674,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)
@ -3910,7 +3901,7 @@ impl Shell {
return None;
}
let mut start_data = check_grab_preconditions(&seat, None, None)?;
let mut start_data = check_grab_preconditions(seat, None, None)?;
let (floating_layer, geometry) = if let Some(set) = self
.workspaces
@ -3924,9 +3915,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)
@ -3968,7 +3959,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(
@ -4026,22 +4017,20 @@ impl Shell {
was_maximized: false,
},
});
} else {
if let Some((workspace, window)) = self.workspaces.sets.values_mut().find_map(|set| {
set.workspaces.iter_mut().find_map(|workspace| {
let window = workspace
.get_fullscreen()
.cloned()
.into_iter()
.chain(workspace.mapped().map(|m| m.active_window()))
.find(|s| s == surface);
window.map(|s| (workspace, s))
})
}) {
let to = minimize_rectangle(workspace.output(), &window);
if let Some(minimized) = workspace.minimize(&surface, to) {
workspace.minimized_windows.push(minimized);
}
} else if let Some((workspace, window)) = self.workspaces.sets.values_mut().find_map(|set| {
set.workspaces.iter_mut().find_map(|workspace| {
let window = workspace
.get_fullscreen()
.cloned()
.into_iter()
.chain(workspace.mapped().map(|m| m.active_window()))
.find(|s| s == surface);
window.map(|s| (workspace, s))
})
}) {
let to = minimize_rectangle(workspace.output(), &window);
if let Some(minimized) = workspace.minimize(surface, to) {
workspace.minimized_windows.push(minimized);
}
}
}
@ -4113,7 +4102,7 @@ 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) {
} else if let Some(workspace) = self.space_for_mut(mapped) {
let layer = if workspace.is_tiled(&mapped.active_window()) {
ManagedLayer::Tiling
} else {
@ -4187,7 +4176,7 @@ impl Shell {
) -> Option<(ResizeGrab, Focus)> {
let serial = serial.into();
let start_data =
check_grab_preconditions(&seat, serial, client_initiated.then_some(surface))?;
check_grab_preconditions(seat, serial, client_initiated.then_some(surface))?;
let mapped = self.element_for_surface(surface).cloned()?;
if mapped.is_maximized(true) {
return None;
@ -4556,9 +4545,9 @@ impl Shell {
mapped.active_window()
};
toplevel_leave_output(&window, &old_output);
toplevel_leave_output(&window, old_output);
let old_output = old_output.downgrade();
let workspace_handle = self.active_space(&output).unwrap().handle.clone();
let workspace_handle = self.active_space(&output).unwrap().handle;
toplevel_enter_output(&window, &output);
toplevel_enter_workspace(&window, &workspace_handle);
@ -4585,7 +4574,7 @@ impl Shell {
let from = workspace.element_geometry(&mapped).unwrap();
let (surface, state) = workspace.unmap_surface(surface).unwrap();
window = surface;
let handle = workspace.handle.clone();
let handle = workspace.handle;
toplevel_leave_output(&window, &workspace.output);
toplevel_leave_workspace(&window, &workspace.handle);
@ -4619,7 +4608,7 @@ impl Shell {
};
if let Some((old_fullscreen, restore, _)) = old_fullscreen {
self.remap_unfullscreened_window(old_fullscreen, restore, &loop_handle);
self.remap_unfullscreened_window(old_fullscreen, restore, loop_handle);
}
Some(KeyboardFocusTarget::Fullscreen(window))
@ -4662,7 +4651,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);
@ -4777,7 +4766,7 @@ pub fn check_grab_preconditions(
let touch = seat.get_touch().unwrap();
let start_data =
if serial.map_or(false, |serial| touch.has_grab(serial)) {
if serial.is_some_and(|serial| touch.has_grab(serial)) {
GrabStartData::Touch(touch.grab_start_data().unwrap())
} else {
GrabStartData::Pointer(pointer.grab_start_data().unwrap_or_else(|| {

View file

@ -37,6 +37,12 @@ pub struct Seats {
last_active: Option<Seat<State>>,
}
impl Default for Seats {
fn default() -> Self {
Self::new()
}
}
impl Seats {
pub fn new() -> Seats {
Seats {
@ -131,7 +137,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()

View file

@ -578,7 +578,7 @@ impl Workspace {
pub fn unmap_element(&mut self, mapped: &CosmicMapped) -> Option<WorkspaceRestoreData> {
let was_maximized = if mapped.maximized_state.lock().unwrap().is_some() {
// If surface is maximized then unmaximize it, so it is assigned to only one layer
self.unmaximize_request(&mapped)
self.unmaximize_request(mapped)
} else {
None
};
@ -601,7 +601,7 @@ impl Workspace {
});
}
if let Ok(state) = self.tiling_layer.unmap(&mapped, None) {
if let Ok(state) = self.tiling_layer.unmap(mapped, None) {
return Some(WorkspaceRestoreData::Tiling(Some(TilingRestoreData {
state,
was_maximized: was_maximized.is_some(),
@ -610,7 +610,7 @@ impl Workspace {
// unmaximize_request might have triggered a `floating_layer.refresh()`,
// which may have already removed a non-alive surface.
if let Some(floating_geometry) = self.floating_layer.unmap(&mapped, None).or(was_maximized)
if let Some(floating_geometry) = self.floating_layer.unmap(mapped, None).or(was_maximized)
{
return Some(WorkspaceRestoreData::Floating(Some(FloatingRestoreData {
geometry: floating_geometry,
@ -667,10 +667,8 @@ impl Workspace {
if let Some(stack) = maybe_stack {
if stack.len() > 1 {
let idx = stack.surfaces().position(|s| &s == surface);
let layer = self
.is_tiled(surface)
.then_some(ManagedLayer::Tiling)
.unwrap_or(ManagedLayer::Floating);
let layer = if self
.is_tiled(surface) { ManagedLayer::Tiling } else { ManagedLayer::Floating };
return idx
.and_then(|idx| stack.remove_idx(idx))
.map(|s| (s, layer.into()));
@ -856,14 +854,14 @@ impl Workspace {
self.fullscreen
.as_ref()
.filter(|f| last_focused.is_some_and(|t| t == &f.surface))
.and_then(|f| check_fullscreen(f))
.and_then(check_fullscreen)
.or_else(|| self.floating_layer.popup_surface_under(location))
.or_else(|| self.tiling_layer.popup_surface_under(location, overview))
.or_else(|| {
self.fullscreen
.as_ref()
.filter(|f| last_focused.is_none_or(|t| t != &f.surface))
.and_then(|f| check_fullscreen(f))
.and_then(check_fullscreen)
})
.map(|(m, p)| (m, p.to_global(&self.output)))
}
@ -909,14 +907,14 @@ impl Workspace {
self.fullscreen
.as_ref()
.filter(|f| last_focused.is_some_and(|t| t == &f.surface))
.and_then(|f| check_fullscreen(f))
.and_then(check_fullscreen)
.or_else(|| self.floating_layer.toplevel_surface_under(location))
.or_else(|| self.tiling_layer.toplevel_surface_under(location, overview))
.or_else(|| {
self.fullscreen
.as_ref()
.filter(|f| last_focused.is_none_or(|t| t != &f.surface))
.and_then(|f| check_fullscreen(f))
.and_then(check_fullscreen)
})
.map(|(m, p)| (m, p.to_global(&self.output)))
}
@ -952,8 +950,8 @@ impl Workspace {
match state.original_layer {
ManagedLayer::Tiling if self.tiling_enabled => {
// should still be mapped in tiling
let geo = self.tiling_layer.element_geometry(&elem);
self.floating_layer.unmap(&elem, geo);
let geo = self.tiling_layer.element_geometry(elem);
self.floating_layer.unmap(elem, geo);
elem.output_enter(&self.output, elem.bbox());
elem.set_maximized(false);
elem.set_geometry(state.original_geometry.to_global(&self.output));
@ -1252,7 +1250,7 @@ impl Workspace {
Some((
surface.surface.clone(),
surface.previous_state.clone(),
surface.previous_geometry.clone(),
surface.previous_geometry,
))
} else {
None
@ -1360,7 +1358,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, None);
self.floating_layer.unmap(window, None);
self.tiling_layer
.map(window.clone(), Some(focus_stack.iter()), None)
}
@ -1446,7 +1444,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()
@ -1467,7 +1465,7 @@ impl Workspace {
KeyboardFocusTarget::Group(WindowGroup {
node, focus_stack, ..
}) => Some(NodeDesc {
handle: self.handle.clone(),
handle: self.handle,
node,
stack_window: None,
focus_stack,
@ -1571,7 +1569,7 @@ impl Workspace {
};
if matches!(focused, Some(FocusTarget::Fullscreen(_))) {
elements.extend(fullscreen_elements.drain(..));
elements.append(&mut fullscreen_elements);
}
if !matches!(focused, Some(FocusTarget::Fullscreen(_)))

View file

@ -80,7 +80,7 @@ impl OutputZoomState {
let focal_point = if output_geometry.contains(cursor_position) {
match movement {
ZoomMovement::Continuously | ZoomMovement::OnEdge => {
cursor_position.to_local(&output)
cursor_position.to_local(output)
}
ZoomMovement::Centered => {
let mut zoomed_output_geometry = output.geometry().to_f64().downscale(level);
@ -89,18 +89,18 @@ impl OutputZoomState {
let mut focal_point = zoomed_output_geometry
.loc
.to_local(&output)
.to_local(output)
.upscale(level)
.to_global(&output);
.to_global(output);
focal_point.x = focal_point.x.clamp(
output_geometry.loc.x as f64,
((output_geometry.loc.x + output_geometry.size.w) as f64).next_lower(), // FIXME: Replace with f64::next_down when stable
output_geometry.loc.x,
(output_geometry.loc.x + output_geometry.size.w).next_lower(), // FIXME: Replace with f64::next_down when stable
);
focal_point.y = focal_point.y.clamp(
output_geometry.loc.y as f64,
((output_geometry.loc.y + output_geometry.size.h) as f64).next_lower(), // FIXME: Replace with f64::next_down when stable
output_geometry.loc.y,
(output_geometry.loc.y + output_geometry.size.h).next_lower(), // FIXME: Replace with f64::next_down when stable
);
focal_point.to_local(&output)
focal_point.to_local(output)
}
}
} else {
@ -282,16 +282,16 @@ impl ZoomState {
if !zoomed_output_geometry
.overlaps_or_touches(Rectangle::new(original_position, Size::from((16, 16))))
{
zoomed_output_geometry.loc = cursor_position.to_global(&output)
zoomed_output_geometry.loc = cursor_position.to_global(output)
- zoomed_output_geometry.size.downscale(2).to_point();
let mut focal_point = zoomed_output_geometry
.loc
.to_local(&output)
.to_local(output)
.upscale(
output_geometry.size.w
/ (output_geometry.size.w - zoomed_output_geometry.size.w),
)
.to_global(&output);
.to_global(output);
focal_point.x = focal_point.x.clamp(
output_geometry.loc.x,
output_geometry.loc.x + output_geometry.size.w - 1,
@ -302,10 +302,10 @@ impl ZoomState {
);
output_state_ref.previous_point =
Some((output_state_ref.focal_point, Instant::now()));
output_state_ref.focal_point = focal_point.to_local(&output).to_f64();
} else if !zoomed_output_geometry.contains(cursor_position.to_global(&output)) {
let mut diff = output_state_ref.focal_point.to_global(&output)
+ (cursor_position.to_global(&output) - original_position)
output_state_ref.focal_point = focal_point.to_local(output).to_f64();
} else if !zoomed_output_geometry.contains(cursor_position.to_global(output)) {
let mut diff = output_state_ref.focal_point.to_global(output)
+ (cursor_position.to_global(output) - original_position)
.to_f64()
.upscale(output_state_ref.level);
diff.x = diff.x.clamp(
@ -316,18 +316,18 @@ impl ZoomState {
output_geometry.loc.y as f64,
((output_geometry.loc.y + output_geometry.size.h) as f64).next_lower(), // FIXME: Replace with f64::next_down when stable
);
diff -= output_state_ref.focal_point.to_global(&output);
diff -= output_state_ref.focal_point.to_global(output);
output_state_ref.focal_point += diff.as_logical().as_local();
}
}
ZoomMovement::Centered => {
zoomed_output_geometry.loc = cursor_position.to_global(&output)
zoomed_output_geometry.loc = cursor_position.to_global(output)
- zoomed_output_geometry.size.downscale(2).to_point();
let mut focal_point = zoomed_output_geometry
.loc
.to_local(&output)
.to_local(output)
.upscale(
output_geometry
.size
@ -335,7 +335,7 @@ impl ZoomState {
.checked_div(output_geometry.size.w - zoomed_output_geometry.size.w)
.unwrap_or(1),
)
.to_global(&output);
.to_global(output);
focal_point.x = focal_point.x.clamp(
output_geometry.loc.x,
output_geometry.loc.x + output_geometry.size.w - 1,
@ -344,7 +344,7 @@ impl ZoomState {
output_geometry.loc.y,
output_geometry.loc.y + output_geometry.size.h - 1,
);
output_state_ref.focal_point = focal_point.to_local(&output).to_f64();
output_state_ref.focal_point = focal_point.to_local(output).to_f64();
}
}
}