Skip to content

Commit

Permalink
input: Use render_input_order
Browse files Browse the repository at this point in the history
  • Loading branch information
Drakulix committed Oct 22, 2024
1 parent 51c8588 commit 0092dac
Show file tree
Hide file tree
Showing 10 changed files with 707 additions and 382 deletions.
423 changes: 272 additions & 151 deletions src/input/mod.rs

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions src/shell/element/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,10 +302,11 @@ impl CosmicMapped {
pub fn focus_under(
&self,
relative_pos: Point<f64, Logical>,
surface_type: WindowSurfaceType,
) -> Option<(PointerFocusTarget, Point<f64, Logical>)> {
match &self.element {
CosmicMappedInternal::Stack(stack) => stack.focus_under(relative_pos),
CosmicMappedInternal::Window(window) => window.focus_under(relative_pos),
CosmicMappedInternal::Stack(stack) => stack.focus_under(relative_pos, surface_type),
CosmicMappedInternal::Window(window) => window.focus_under(relative_pos, surface_type),
_ => unreachable!(),
}
}
Expand Down
68 changes: 36 additions & 32 deletions src/shell/element/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,48 +420,52 @@ impl CosmicStack {
pub fn focus_under(
&self,
mut relative_pos: Point<f64, Logical>,
surface_type: WindowSurfaceType,
) -> Option<(PointerFocusTarget, Point<f64, Logical>)> {
self.0.with_program(|p| {
let mut stack_ui = None;
let geo = p.windows.lock().unwrap()[p.active.load(Ordering::SeqCst)].geometry();

let point_i32 = relative_pos.to_i32_round::<i32>();
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)
|| (point_i32.x - geo.loc.x >= geo.size.w
&& point_i32.x - geo.loc.x < geo.size.w + RESIZE_BORDER)
|| (point_i32.y - geo.loc.y >= geo.size.h
&& point_i32.y - geo.loc.y < geo.size.h + TAB_HEIGHT + RESIZE_BORDER)
{
stack_ui = Some((
PointerFocusTarget::StackUI(self.clone()),
Point::from((0., 0.)),
));
}
if surface_type.contains(WindowSurfaceType::TOPLEVEL) {
let point_i32 = relative_pos.to_i32_round::<i32>();
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)
|| (point_i32.x - geo.loc.x >= geo.size.w
&& point_i32.x - geo.loc.x < geo.size.w + RESIZE_BORDER)
|| (point_i32.y - geo.loc.y >= geo.size.h
&& point_i32.y - geo.loc.y < geo.size.h + TAB_HEIGHT + RESIZE_BORDER)
{
stack_ui = Some((
PointerFocusTarget::StackUI(self.clone()),
Point::from((0., 0.)),
));
}

if point_i32.y - geo.loc.y < TAB_HEIGHT {
stack_ui = Some((
PointerFocusTarget::StackUI(self.clone()),
Point::from((0., 0.)),
));
if point_i32.y - geo.loc.y < TAB_HEIGHT {
stack_ui = Some((
PointerFocusTarget::StackUI(self.clone()),
Point::from((0., 0.)),
));
}
}

relative_pos.y -= TAB_HEIGHT as f64;

let active_window = &p.windows.lock().unwrap()[p.active.load(Ordering::SeqCst)];
active_window
.0
.surface_under(relative_pos, WindowSurfaceType::ALL)
.map(|(surface, surface_offset)| {
(
PointerFocusTarget::WlSurface {
surface,
toplevel: Some(active_window.clone().into()),
},
surface_offset.to_f64() + Point::from((0., TAB_HEIGHT as f64)),
)
})
.or(stack_ui)
stack_ui.or_else(|| {
active_window
.0
.surface_under(relative_pos, surface_type)
.map(|(surface, surface_offset)| {
(
PointerFocusTarget::WlSurface {
surface,
toplevel: Some(active_window.clone().into()),
},
surface_offset.to_f64() + Point::from((0., TAB_HEIGHT as f64)),
)
})
})
})
}

Expand Down Expand Up @@ -1034,7 +1038,7 @@ impl SpaceElement for CosmicStack {
})
}
fn is_in_input_region(&self, point: &Point<f64, Logical>) -> bool {
self.focus_under(*point).is_some()
self.focus_under(*point, WindowSurfaceType::ALL).is_some()
}
fn set_activate(&self, activated: bool) {
SpaceElement::set_activate(&self.0, activated);
Expand Down
31 changes: 16 additions & 15 deletions src/shell/element/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,12 @@ impl CosmicWindow {
pub fn focus_under(
&self,
mut relative_pos: Point<f64, Logical>,
surface_type: WindowSurfaceType,
) -> Option<(PointerFocusTarget, Point<f64, Logical>)> {
self.0.with_program(|p| {
let mut offset = Point::from((0., 0.));
let mut window_ui = None;
if p.has_ssd(false) {
if p.has_ssd(false) && surface_type.contains(WindowSurfaceType::TOPLEVEL) {
let geo = p.window.geometry();

let point_i32 = relative_pos.to_i32_round::<i32>();
Expand Down Expand Up @@ -275,19 +276,19 @@ impl CosmicWindow {
offset.y += SSD_HEIGHT as f64;
}

p.window
.0
.surface_under(relative_pos, WindowSurfaceType::ALL)
.map(|(surface, surface_offset)| {
(
PointerFocusTarget::WlSurface {
surface,
toplevel: Some(p.window.clone().into()),
},
(offset + surface_offset.to_f64()),
)
})
.or(window_ui)
window_ui.or_else(|| {
p.window.0.surface_under(relative_pos, surface_type).map(
|(surface, surface_offset)| {
(
PointerFocusTarget::WlSurface {
surface,
toplevel: Some(p.window.clone().into()),
},
(offset + surface_offset.to_f64()),
)
},
)
})
})
}

Expand Down Expand Up @@ -561,7 +562,7 @@ impl SpaceElement for CosmicWindow {
})
}
fn is_in_input_region(&self, point: &Point<f64, Logical>) -> bool {
self.focus_under(*point).is_some()
self.focus_under(*point, WindowSurfaceType::ALL).is_some()
}
fn set_activate(&self, activated: bool) {
if self
Expand Down
9 changes: 4 additions & 5 deletions src/shell/focus/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ fn update_focus_state(
if should_update_cursor && state.common.config.cosmic_conf.cursor_follows_focus {
if target.is_some() {
//need to borrow mutably for surface under
let mut shell = state.common.shell.write().unwrap();
// get geometry of the target element
let shell = state.common.shell.read().unwrap();
// 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
Expand All @@ -247,10 +247,9 @@ fn update_focus_state(
.cloned()
.unwrap_or(seat.active_output());

let focus = shell
.surface_under(new_pos, &output)
let focus = State::surface_under(new_pos, &output, &*shell)
.map(|(focus, loc)| (focus, loc.as_logical()));
//drop here to avoid multiple mutable borrows
//drop here to avoid multiple borrows
mem::drop(shell);
seat.get_pointer().unwrap().motion(
state,
Expand Down
4 changes: 2 additions & 2 deletions src/shell/grabs/moving.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use smithay::{
ImportAll, ImportMem, Renderer,
},
},
desktop::{layer_map_for_output, space::SpaceElement},
desktop::{layer_map_for_output, space::SpaceElement, WindowSurfaceType},
input::{
pointer::{
AxisFrame, ButtonEvent, CursorIcon, GestureHoldBeginEvent, GestureHoldEndEvent,
Expand Down Expand Up @@ -864,7 +864,7 @@ impl Drop for MoveGrab {
let current_location = pointer.current_location();

if let Some((target, offset)) =
mapped.focus_under(current_location - position.as_logical().to_f64())
mapped.focus_under(current_location - position.as_logical().to_f64(), WindowSurfaceType::ALL)
{
pointer.motion(
state,
Expand Down
118 changes: 104 additions & 14 deletions src/shell/layout/floating/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -728,16 +728,115 @@ impl FloatingLayout {
self.space.element_geometry(elem).map(RectExt::as_local)
}

pub fn element_under(&self, location: Point<f64, Local>) -> Option<KeyboardFocusTarget> {
pub fn popup_element_under(&self, location: Point<f64, Local>) -> Option<KeyboardFocusTarget> {
self.space
.element_under(location.as_logical())
.map(|(mapped, _)| mapped.clone().into())
.elements()
.rev()
.map(|e| (e, self.space.element_location(e).unwrap() - e.geometry().loc))
.filter(|(e, render_location)| {
let mut bbox = e.bbox();
bbox.loc += *render_location;
bbox.to_f64().contains(location.as_logical())
})
.find_map(|(e, render_location)| {
let render_location = render_location
.as_local()
.to_f64();
let point = location - render_location;
if e.focus_under(point.as_logical(), WindowSurfaceType::POPUP | WindowSurfaceType::SUBSURFACE).is_some() {
Some(e.clone().into())
} else {
None
}
})
}

pub fn toplevel_element_under(&self, location: Point<f64, Local>) -> Option<KeyboardFocusTarget> {
self.space
.elements()
.rev()
.map(|e| (e, self.space.element_location(e).unwrap() - e.geometry().loc))
.filter(|(e, render_location)| {
let mut bbox = e.bbox();
bbox.loc += *render_location;
bbox.to_f64().contains(location.as_logical())
})
.find_map(|(e, render_location)| {
let render_location = render_location
.as_local()
.to_f64();
let point = location - render_location;
if e.focus_under(point.as_logical(), WindowSurfaceType::TOPLEVEL | WindowSurfaceType::SUBSURFACE).is_some() {
Some(e.clone().into())
} else {
None
}
})
}

pub fn surface_under(
&mut self,
pub fn popup_surface_under(
&self,
location: Point<f64, Local>,
) -> Option<(PointerFocusTarget, Point<f64, Local>)> {
self.space
.elements()
.rev()
.map(|e| (e, self.space.element_location(e).unwrap() - e.geometry().loc))
.filter(|(e, render_location)| {
let mut bbox = e.bbox();
bbox.loc += *render_location;
bbox.to_f64().contains(location.as_logical())
})
.find_map(|(e, render_location)| {
let render_location = render_location
.as_local()
.to_f64();
let point = location - render_location;
e.focus_under(
point.as_logical(),
WindowSurfaceType::POPUP | WindowSurfaceType::SUBSURFACE,
)
.map(|(surface, surface_offset)| {
(surface, render_location + surface_offset.as_local())
})
})
}

pub fn toplevel_surface_under(
&self,
location: Point<f64, Local>,
) -> Option<(PointerFocusTarget, Point<f64, Local>)> {
self.space
.elements()
.rev()
.map(|e| (e, self.space.element_location(e).unwrap() - e.geometry().loc))
.filter(|(e, render_location)| {
let mut bbox = e.bbox();
bbox.loc += *render_location;
bbox.to_f64().contains(location.as_logical())
})
.find_map(|(e, render_location)| {
let render_location = render_location.as_local().to_f64();
let point = location - render_location;
e.focus_under(
point.as_logical(),
WindowSurfaceType::TOPLEVEL | WindowSurfaceType::SUBSURFACE,
)
.map(|(surface, surface_offset)| {
(
surface,
render_location + surface_offset.as_local(),
)
})
})
}

pub fn update_pointer_position(&mut self, location: Option<Point<f64, Local>>) {
let Some(location) = location else {
self.hovered_stack.take();
return;
};

let res = self
.space
.element_under(location.as_logical())
Expand All @@ -754,15 +853,6 @@ impl FloatingLayout {
} else {
self.hovered_stack.take();
}

res.and_then(|(element, space_offset)| {
let point = location - space_offset.to_f64();
element
.focus_under(point.as_logical())
.map(|(surface, surface_offset)| {
(surface, space_offset.to_f64() + surface_offset.as_local())
})
})
}

pub fn stacking_indicator(&self) -> Option<Rectangle<i32, Local>> {
Expand Down
Loading

0 comments on commit 0092dac

Please sign in to comment.