floating: Fix next window logic
This commit is contained in:
parent
1fa6167f25
commit
be192c80e5
2 changed files with 36 additions and 127 deletions
|
|
@ -31,9 +31,9 @@ use crate::{
|
|||
window::CosmicWindowRenderElement,
|
||||
CosmicMapped, CosmicMappedRenderElement, CosmicWindow,
|
||||
},
|
||||
focus::{target::KeyboardFocusTarget, FocusDirection, FocusStackMut},
|
||||
focus::{target::KeyboardFocusTarget, FocusStackMut},
|
||||
grabs::{ReleaseMode, ResizeEdge},
|
||||
CosmicSurface, Direction, FocusResult, MoveResult, ResizeDirection, ResizeMode,
|
||||
CosmicSurface, Direction, MoveResult, ResizeDirection, ResizeMode,
|
||||
},
|
||||
state::State,
|
||||
utils::{prelude::*, tween::EaseRectangle},
|
||||
|
|
@ -566,78 +566,6 @@ impl FloatingLayout {
|
|||
true
|
||||
}
|
||||
|
||||
pub fn next_focus<'a>(
|
||||
&mut self,
|
||||
direction: FocusDirection,
|
||||
seat: &Seat<State>,
|
||||
_focus_stack: impl Iterator<Item = &'a CosmicMapped> + 'a,
|
||||
) -> FocusResult {
|
||||
let Some(target) = seat.get_keyboard().unwrap().current_focus() else {
|
||||
return FocusResult::None
|
||||
};
|
||||
|
||||
let Some(focused) = (match target {
|
||||
KeyboardFocusTarget::Popup(popup) => {
|
||||
let Some(toplevel_surface) = (match popup {
|
||||
PopupKind::Xdg(xdg) => get_popup_toplevel(&xdg),
|
||||
PopupKind::InputMethod(_) => unreachable!(),
|
||||
}) else {
|
||||
return FocusResult::None
|
||||
};
|
||||
self.space.elements().find(|elem| elem.wl_surface().as_ref() == Some(&toplevel_surface))
|
||||
},
|
||||
KeyboardFocusTarget::Element(elem) => self.space.elements().find(|e| *e == &elem),
|
||||
_ => None,
|
||||
}) else {
|
||||
return FocusResult::None
|
||||
};
|
||||
|
||||
if focused.handle_focus(direction, None) {
|
||||
return FocusResult::Handled;
|
||||
}
|
||||
|
||||
let geometry = self.space.element_geometry(focused).unwrap();
|
||||
|
||||
let next = match direction {
|
||||
FocusDirection::Up => self.space.elements().min_by_key(|other| {
|
||||
let res = geometry.loc.y - self.space.element_geometry(other).unwrap().loc.y;
|
||||
if res.is_positive() {
|
||||
res
|
||||
} else {
|
||||
i32::MAX
|
||||
}
|
||||
}),
|
||||
FocusDirection::Down => self.space.elements().max_by_key(|other| {
|
||||
let res = geometry.loc.y - self.space.element_geometry(other).unwrap().loc.y;
|
||||
if res.is_negative() {
|
||||
res
|
||||
} else {
|
||||
i32::MIN
|
||||
}
|
||||
}),
|
||||
FocusDirection::Left => self.space.elements().min_by_key(|other| {
|
||||
let res = geometry.loc.x - self.space.element_geometry(other).unwrap().loc.x;
|
||||
if res.is_positive() {
|
||||
res
|
||||
} else {
|
||||
i32::MAX
|
||||
}
|
||||
}),
|
||||
FocusDirection::Right => self.space.elements().max_by_key(|other| {
|
||||
let res = geometry.loc.x - self.space.element_geometry(other).unwrap().loc.x;
|
||||
if res.is_negative() {
|
||||
res
|
||||
} else {
|
||||
i32::MIN
|
||||
}
|
||||
}),
|
||||
_ => return FocusResult::None,
|
||||
};
|
||||
|
||||
next.map(|elem| FocusResult::Some(KeyboardFocusTarget::Element(elem.clone())))
|
||||
.unwrap_or(FocusResult::None)
|
||||
}
|
||||
|
||||
pub fn toggle_stacking(&mut self, mapped: &CosmicMapped) -> Option<KeyboardFocusTarget> {
|
||||
if !self.space.elements().any(|m| m == mapped) {
|
||||
return None;
|
||||
|
|
|
|||
|
|
@ -2420,77 +2420,57 @@ impl Shell {
|
|||
.or_else(|| floating_layer.space.element_geometry(&focused))
|
||||
.unwrap();
|
||||
|
||||
let elements = sticky_layer
|
||||
.space
|
||||
.elements()
|
||||
.chain(floating_layer.space.elements())
|
||||
.filter(|elem| *elem != &focused)
|
||||
.map(|elem| {
|
||||
(
|
||||
elem,
|
||||
sticky_layer
|
||||
.space
|
||||
.element_geometry(elem)
|
||||
.or_else(|| floating_layer.space.element_geometry(elem))
|
||||
.unwrap(),
|
||||
)
|
||||
});
|
||||
|
||||
let next = match direction {
|
||||
FocusDirection::Up => sticky_layer
|
||||
.space
|
||||
.elements()
|
||||
.chain(floating_layer.space.elements())
|
||||
.min_by_key(|other| {
|
||||
let res = geometry.loc.y
|
||||
- sticky_layer
|
||||
.space
|
||||
.element_geometry(other)
|
||||
.or_else(|| floating_layer.space.element_geometry(other))
|
||||
.unwrap()
|
||||
.loc
|
||||
.y;
|
||||
FocusDirection::Up => elements
|
||||
.filter(|(_, other_geo)| other_geo.loc.y <= geometry.loc.y)
|
||||
.min_by_key(|(_, other_geo)| {
|
||||
let res = geometry.loc.y - other_geo.loc.y;
|
||||
if res.is_positive() {
|
||||
res
|
||||
} else {
|
||||
i32::MAX
|
||||
}
|
||||
}),
|
||||
FocusDirection::Down => sticky_layer
|
||||
.space
|
||||
.elements()
|
||||
.chain(floating_layer.space.elements())
|
||||
.max_by_key(|other| {
|
||||
let res = geometry.loc.y
|
||||
- sticky_layer
|
||||
.space
|
||||
.element_geometry(other)
|
||||
.or_else(|| floating_layer.space.element_geometry(other))
|
||||
.unwrap()
|
||||
.loc
|
||||
.y;
|
||||
FocusDirection::Down => elements
|
||||
.filter(|(_, other_geo)| other_geo.loc.y > geometry.loc.y)
|
||||
.max_by_key(|(_, other_geo)| {
|
||||
let res = geometry.loc.y - other_geo.loc.y;
|
||||
if res.is_negative() {
|
||||
res
|
||||
} else {
|
||||
i32::MIN
|
||||
}
|
||||
}),
|
||||
FocusDirection::Left => sticky_layer
|
||||
.space
|
||||
.elements()
|
||||
.chain(floating_layer.space.elements())
|
||||
.min_by_key(|other| {
|
||||
let res = geometry.loc.x
|
||||
- sticky_layer
|
||||
.space
|
||||
.element_geometry(other)
|
||||
.or_else(|| floating_layer.space.element_geometry(other))
|
||||
.unwrap()
|
||||
.loc
|
||||
.x;
|
||||
FocusDirection::Left => elements
|
||||
.filter(|(_, other_geo)| other_geo.loc.x <= geometry.loc.x)
|
||||
.min_by_key(|(_, other_geo)| {
|
||||
let res = geometry.loc.x - other_geo.loc.x;
|
||||
if res.is_positive() {
|
||||
res
|
||||
} else {
|
||||
i32::MAX
|
||||
}
|
||||
}),
|
||||
FocusDirection::Right => sticky_layer
|
||||
.space
|
||||
.elements()
|
||||
.chain(floating_layer.space.elements())
|
||||
.max_by_key(|other| {
|
||||
let res = geometry.loc.x
|
||||
- sticky_layer
|
||||
.space
|
||||
.element_geometry(other)
|
||||
.or_else(|| floating_layer.space.element_geometry(other))
|
||||
.unwrap()
|
||||
.loc
|
||||
.x;
|
||||
FocusDirection::Right => elements
|
||||
.filter(|(_, other_geo)| other_geo.loc.x > geometry.loc.x)
|
||||
.max_by_key(|(_, other_geo)| {
|
||||
let res = geometry.loc.x - other_geo.loc.x;
|
||||
if res.is_negative() {
|
||||
res
|
||||
} else {
|
||||
|
|
@ -2498,7 +2478,8 @@ impl Shell {
|
|||
}
|
||||
}),
|
||||
_ => return FocusResult::None,
|
||||
};
|
||||
}
|
||||
.map(|(other, _)| other);
|
||||
|
||||
next.map(|elem| FocusResult::Some(KeyboardFocusTarget::Element(elem.clone())))
|
||||
.unwrap_or(FocusResult::None)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue