Skip to content

Commit

Permalink
input: Rework PointerFocus to operate directly on WlSurface
Browse files Browse the repository at this point in the history
  • Loading branch information
Drakulix committed Mar 25, 2024
1 parent 973cfed commit f2fe363
Show file tree
Hide file tree
Showing 12 changed files with 628 additions and 972 deletions.
128 changes: 72 additions & 56 deletions src/input/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ use crate::{
config::{xkb_config_to_wl, Action, Config, KeyModifiers, KeyPattern},
input::gestures::{GestureState, SwipeAction},
shell::{
focus::{target::PointerFocusTarget, FocusDirection},
focus::{
target::{KeyboardFocusTarget, PointerFocusTarget},
FocusDirection,
},
grabs::{ResizeEdge, SeatMenuGrabState, SeatMoveGrabState},
layout::{
floating::ResizeGrabMarker,
Expand Down Expand Up @@ -33,7 +36,10 @@ use smithay::{
TabletToolEvent, TabletToolProximityEvent, TabletToolTipEvent, TabletToolTipState,
TouchEvent,
},
desktop::{layer_map_for_output, space::SpaceElement, WindowSurfaceType},
desktop::{
layer_map_for_output, space::SpaceElement, utils::under_from_surface_tree,
WindowSurfaceType,
},
input::{
keyboard::{FilterResult, KeysymHandle, LedState, XkbConfig},
pointer::{
Expand Down Expand Up @@ -724,11 +730,15 @@ impl State {
ptr.frame(self);
return;
}
if let PointerFocusTarget::Element(element) = surface {
//if !element.is_in_input_region(&(position.to_i32_round() - *surface_loc).to_f64()) {
if !element.is_in_input_region(
&(position.as_logical() - surface_loc.to_f64()),
) {
if let PointerFocusTarget::WlSurface(surface) = surface {
if under_from_surface_tree(
surface,
position.as_logical() - surface_loc.to_f64(),
(0, 0),
WindowSurfaceType::ALL,
)
.is_some()
{
ptr.frame(self);
return;
}
Expand Down Expand Up @@ -886,7 +896,7 @@ impl State {

let pos = seat.get_pointer().unwrap().current_location().as_global();
let relative_pos = pos.to_local(&output);
let mut under = None;
let mut under: Option<KeyboardFocusTarget> = None;

if let Some(session_lock) = self.common.shell.session_lock.as_ref() {
under = session_lock
Expand Down Expand Up @@ -947,7 +957,7 @@ impl State {
if !done {
// Don't check override redirect windows, because we don't set keyboard focus to them explicitly.
// These cases are handled by the XwaylandKeyboardGrab.
if let Some((target, _)) =
if let Some(target) =
self.common.shell.element_under(pos, &output)
{
under = Some(target);
Expand Down Expand Up @@ -982,12 +992,7 @@ impl State {
}
}
}
Common::set_focus(
self,
under.and_then(|target| target.try_into().ok()).as_ref(),
&seat,
Some(serial),
);
Common::set_focus(self, under.as_ref(), &seat, Some(serial));
}
} else {
if let OverviewMode::Started(Trigger::Pointer(action_button), _) =
Expand Down Expand Up @@ -2270,7 +2275,7 @@ impl State {
if let Some(session_lock) = session_lock {
return session_lock.surfaces.get(output).map(|surface| {
(
PointerFocusTarget::LockSurface(surface.clone()),
PointerFocusTarget::WlSurface(surface.wl_surface().clone()),
output_geo.loc,
)
});
Expand All @@ -2280,24 +2285,33 @@ impl State {
let layers = layer_map_for_output(output);
if let Some(layer) = layers.layer_under(WlrLayer::Overlay, relative_pos.as_logical()) {
let layer_loc = layers.layer_geometry(layer).unwrap().loc;
if layer
.surface_under(
relative_pos.as_logical() - layer_loc.to_f64(),
WindowSurfaceType::ALL,
)
.is_some()
{
return Some((layer.clone().into(), output_geo.loc + layer_loc.as_global()));
if let Some((wl_surface, surface_loc)) = layer.surface_under(
relative_pos.as_logical() - layer_loc.to_f64(),
WindowSurfaceType::ALL,
) {
return Some((
wl_surface.into(),
output_geo.loc + layer_loc.as_global() + surface_loc.as_global(),
));
}
}
if let Some(or) = shell.override_redirect_windows.iter().find(|or| {
or.is_in_input_region(
&(global_pos.as_logical() - X11Surface::geometry(*or).loc.to_f64()),
)
}) {
return Some((or.clone().into(), X11Surface::geometry(or).loc.as_global()));
if let Some((surface, geo)) = shell
.override_redirect_windows
.iter()
.find(|or| {
or.is_in_input_region(
&(global_pos.as_logical() - X11Surface::geometry(*or).loc.to_f64()),
)
})
.and_then(|or| {
or.wl_surface()
.map(|surface| (surface, X11Surface::geometry(or).loc.as_global()))
})
{
return Some((surface.into(), geo));
}
Some((window.clone().into(), output_geo.loc))
PointerFocusTarget::under_surface(window, relative_pos.as_logical())
.map(|(target, surface_loc)| (target, output_geo.loc + surface_loc.as_global()))
} else {
{
let layers = layer_map_for_output(output);
Expand All @@ -2306,28 +2320,33 @@ impl State {
.or_else(|| layers.layer_under(WlrLayer::Top, relative_pos.as_logical()))
{
let layer_loc = layers.layer_geometry(layer).unwrap().loc;
if layer
.surface_under(
relative_pos.as_logical() - layer_loc.to_f64(),
WindowSurfaceType::ALL,
)
.is_some()
{
if let Some((wl_surface, surface_loc)) = layer.surface_under(
relative_pos.as_logical() - layer_loc.to_f64(),
WindowSurfaceType::ALL,
) {
return Some((
layer.clone().into(),
output_geo.loc + layer_loc.as_global(),
wl_surface.into(),
output_geo.loc + layer_loc.as_global() + surface_loc.as_global(),
));
}
}
}
if let Some(or) = shell.override_redirect_windows.iter().find(|or| {
or.is_in_input_region(
&(global_pos.as_logical() - X11Surface::geometry(*or).loc.to_f64()),
)
}) {
return Some((or.clone().into(), X11Surface::geometry(or).loc.as_global()));
if let Some((surface, geo)) = shell
.override_redirect_windows
.iter()
.find(|or| {
or.is_in_input_region(
&(global_pos.as_logical() - X11Surface::geometry(*or).loc.to_f64()),
)
})
.and_then(|or| {
or.wl_surface()
.map(|surface| (surface, X11Surface::geometry(or).loc.as_global()))
})
{
return Some((surface.into(), geo));
}
if let Some((target, loc)) = shell.element_under(global_pos, output) {
if let Some((target, loc)) = shell.surface_under(global_pos, output) {
return Some((target, loc));
}
{
Expand All @@ -2337,16 +2356,13 @@ impl State {
.or_else(|| layers.layer_under(WlrLayer::Background, relative_pos.as_logical()))
{
let layer_loc = layers.layer_geometry(layer).unwrap().loc;
if layer
.surface_under(
relative_pos.as_logical() - layer_loc.to_f64(),
WindowSurfaceType::ALL,
)
.is_some()
{
if let Some((wl_surface, surface_loc)) = layer.surface_under(
relative_pos.as_logical() - layer_loc.to_f64(),
WindowSurfaceType::ALL,
) {
return Some((
layer.clone().into(),
output_geo.loc + layer_loc.as_global(),
wl_surface.into(),
output_geo.loc + layer_loc.as_global() + surface_loc.as_global(),
));
}
}
Expand Down
Loading

0 comments on commit f2fe363

Please sign in to comment.