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,
|
window::CosmicWindowRenderElement,
|
||||||
CosmicMapped, CosmicMappedRenderElement, CosmicWindow,
|
CosmicMapped, CosmicMappedRenderElement, CosmicWindow,
|
||||||
},
|
},
|
||||||
focus::{target::KeyboardFocusTarget, FocusDirection, FocusStackMut},
|
focus::{target::KeyboardFocusTarget, FocusStackMut},
|
||||||
grabs::{ReleaseMode, ResizeEdge},
|
grabs::{ReleaseMode, ResizeEdge},
|
||||||
CosmicSurface, Direction, FocusResult, MoveResult, ResizeDirection, ResizeMode,
|
CosmicSurface, Direction, MoveResult, ResizeDirection, ResizeMode,
|
||||||
},
|
},
|
||||||
state::State,
|
state::State,
|
||||||
utils::{prelude::*, tween::EaseRectangle},
|
utils::{prelude::*, tween::EaseRectangle},
|
||||||
|
|
@ -566,78 +566,6 @@ impl FloatingLayout {
|
||||||
true
|
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> {
|
pub fn toggle_stacking(&mut self, mapped: &CosmicMapped) -> Option<KeyboardFocusTarget> {
|
||||||
if !self.space.elements().any(|m| m == mapped) {
|
if !self.space.elements().any(|m| m == mapped) {
|
||||||
return None;
|
return None;
|
||||||
|
|
|
||||||
|
|
@ -2420,77 +2420,57 @@ impl Shell {
|
||||||
.or_else(|| floating_layer.space.element_geometry(&focused))
|
.or_else(|| floating_layer.space.element_geometry(&focused))
|
||||||
.unwrap();
|
.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 {
|
let next = match direction {
|
||||||
FocusDirection::Up => sticky_layer
|
FocusDirection::Up => elements
|
||||||
.space
|
.filter(|(_, other_geo)| other_geo.loc.y <= geometry.loc.y)
|
||||||
.elements()
|
.min_by_key(|(_, other_geo)| {
|
||||||
.chain(floating_layer.space.elements())
|
let res = geometry.loc.y - other_geo.loc.y;
|
||||||
.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;
|
|
||||||
if res.is_positive() {
|
if res.is_positive() {
|
||||||
res
|
res
|
||||||
} else {
|
} else {
|
||||||
i32::MAX
|
i32::MAX
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
FocusDirection::Down => sticky_layer
|
FocusDirection::Down => elements
|
||||||
.space
|
.filter(|(_, other_geo)| other_geo.loc.y > geometry.loc.y)
|
||||||
.elements()
|
.max_by_key(|(_, other_geo)| {
|
||||||
.chain(floating_layer.space.elements())
|
let res = geometry.loc.y - other_geo.loc.y;
|
||||||
.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;
|
|
||||||
if res.is_negative() {
|
if res.is_negative() {
|
||||||
res
|
res
|
||||||
} else {
|
} else {
|
||||||
i32::MIN
|
i32::MIN
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
FocusDirection::Left => sticky_layer
|
FocusDirection::Left => elements
|
||||||
.space
|
.filter(|(_, other_geo)| other_geo.loc.x <= geometry.loc.x)
|
||||||
.elements()
|
.min_by_key(|(_, other_geo)| {
|
||||||
.chain(floating_layer.space.elements())
|
let res = geometry.loc.x - other_geo.loc.x;
|
||||||
.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;
|
|
||||||
if res.is_positive() {
|
if res.is_positive() {
|
||||||
res
|
res
|
||||||
} else {
|
} else {
|
||||||
i32::MAX
|
i32::MAX
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
FocusDirection::Right => sticky_layer
|
FocusDirection::Right => elements
|
||||||
.space
|
.filter(|(_, other_geo)| other_geo.loc.x > geometry.loc.x)
|
||||||
.elements()
|
.max_by_key(|(_, other_geo)| {
|
||||||
.chain(floating_layer.space.elements())
|
let res = geometry.loc.x - other_geo.loc.x;
|
||||||
.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;
|
|
||||||
if res.is_negative() {
|
if res.is_negative() {
|
||||||
res
|
res
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -2498,7 +2478,8 @@ impl Shell {
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
_ => return FocusResult::None,
|
_ => return FocusResult::None,
|
||||||
};
|
}
|
||||||
|
.map(|(other, _)| other);
|
||||||
|
|
||||||
next.map(|elem| FocusResult::Some(KeyboardFocusTarget::Element(elem.clone())))
|
next.map(|elem| FocusResult::Some(KeyboardFocusTarget::Element(elem.clone())))
|
||||||
.unwrap_or(FocusResult::None)
|
.unwrap_or(FocusResult::None)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue