Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP Input focus update #322

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 52 additions & 58 deletions src/input/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -898,18 +898,20 @@ impl State {
layers.layer_under(WlrLayer::Overlay, relative_pos.as_logical())
{
let layer_loc = layers.layer_geometry(layer).unwrap().loc;
if layer.can_receive_keyboard_focus()
&& layer
.surface_under(
relative_pos.as_logical() - layer_loc.to_f64(),
WindowSurfaceType::ALL,
)
.is_some()
{
under = Some(layer.clone().into());
if layer.can_receive_keyboard_focus() {
if let Some((wl_surface, _)) = layer.surface_under(
relative_pos.as_logical() - layer_loc.to_f64(),
WindowSurfaceType::ALL,
) {
under = Some(wl_surface.into());
}
}
} else {
under = Some(window.clone().into());
under = PointerFocusTarget::under_surface(
window,
relative_pos.as_logical(),
)
.map(|(target, _)| target)
}
} else {
let done = {
Expand All @@ -924,16 +926,16 @@ impl State {
})
{
let layer_loc = layers.layer_geometry(layer).unwrap().loc;
if layer.can_receive_keyboard_focus()
&& layer
.surface_under(
relative_pos.as_logical() - layer_loc.to_f64(),
WindowSurfaceType::ALL,
)
.is_some()
{
under = Some(layer.clone().into());
true
if layer.can_receive_keyboard_focus() {
if let Some((wl_surface, _)) = layer.surface_under(
relative_pos.as_logical() - layer_loc.to_f64(),
WindowSurfaceType::ALL,
) {
under = Some(wl_surface.into());
true
} else {
false
}
} else {
false
}
Expand Down Expand Up @@ -962,16 +964,13 @@ impl State {
{
let layer_loc =
layers.layer_geometry(layer).unwrap().loc;
if layer.can_receive_keyboard_focus()
&& layer
.surface_under(
relative_pos.as_logical()
- layer_loc.to_f64(),
WindowSurfaceType::ALL,
)
.is_some()
{
under = Some(layer.clone().into());
if layer.can_receive_keyboard_focus() {
if let Some((wl_surface, _)) = layer.surface_under(
relative_pos.as_logical() - layer_loc.to_f64(),
WindowSurfaceType::ALL,
) {
under = Some(wl_surface.into());
}
}
};
}
Expand Down Expand Up @@ -2192,7 +2191,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 @@ -2202,22 +2201,23 @@ 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() - or.geometry().loc.to_f64()))
}) {
return Some((or.clone().into(), or.geometry().loc.as_global()));
}
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 @@ -2226,16 +2226,13 @@ 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(),
));
}
}
Expand All @@ -2255,16 +2252,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
66 changes: 44 additions & 22 deletions src/shell/focus/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ use smithay::{
output::Output,
utils::{IsAlive, Serial, SERIAL_COUNTER},
wayland::{
compositor::with_states,
seat::WaylandFocus,
shell::wlr_layer::{KeyboardInteractivity, Layer},
shell::xdg::XdgPopupSurfaceData,
},
};
use std::cell::RefCell;
Expand Down Expand Up @@ -140,8 +142,8 @@ impl Shell {
) {
let element = match target {
Some(KeyboardFocusTarget::Element(mapped)) => Some(mapped.clone()),
Some(KeyboardFocusTarget::Fullscreen(window)) => {
state.common.shell.element_for_surface(window).cloned()
Some(KeyboardFocusTarget::WlSurface(surface)) => {
state.common.shell.element_for_wl_surface(surface).cloned()
}
_ => None,
};
Expand Down Expand Up @@ -260,27 +262,33 @@ impl Common {
trace!("Wrong Window, focus fixup");
}
} else {
if let KeyboardFocusTarget::Popup(_) = target {
if let KeyboardFocusTarget::WlSurface(surface) = target {
if let Some(popup_grab) = seat
.user_data()
.get::<PopupGrabData>()
.and_then(|x| x.take())
{
if !popup_grab.has_ended() {
if let Some(new) = popup_grab.current_grab() {
trace!("restore focus to previous popup grab");
if let Some(keyboard) = seat.get_keyboard() {
keyboard.set_focus(
state,
Some(new.clone()),
SERIAL_COUNTER.next_serial(),
);
if with_states(&surface, |states| {
states.data_map.get::<XdgPopupSurfaceData>().is_some()
}) {
if !popup_grab.has_ended() {
if let Some(new) = popup_grab.current_grab() {
trace!("restore focus to previous popup grab");
if let Some(keyboard) = seat.get_keyboard() {
keyboard.set_focus(
state,
Some(new.clone()),
SERIAL_COUNTER.next_serial(),
);
}
ActiveFocus::set(&seat, Some(new));
seat.user_data()
.get_or_insert::<PopupGrabData, _>(
PopupGrabData::default,
)
.set(Some(popup_grab));
continue;
}
ActiveFocus::set(&seat, Some(new));
seat.user_data()
.get_or_insert::<PopupGrabData, _>(PopupGrabData::default)
.set(Some(popup_grab));
continue;
}
}
}
Expand Down Expand Up @@ -333,19 +341,29 @@ fn focus_target_is_valid(
target: KeyboardFocusTarget,
) -> bool {
// If a session lock is active, only lock surfaces can be focused
if state.common.shell.session_lock.is_some() {
return matches!(target, KeyboardFocusTarget::LockSurface(_));
if let Some(session_lock) = state.common.shell.session_lock.as_ref() {
return if let KeyboardFocusTarget::WlSurface(surface) = target {
session_lock
.surfaces
.values()
.any(|x| x.wl_surface() == &surface)
} else {
false
};
}

// If an exclusive layer shell surface exists (on any output), only exclusive
// shell surfaces can have focus, on the highest layer with exclusive surfaces.
if let Some(layer) = exclusive_layer_surface_layer(state) {
// XXX TODO get layer surface for WlSurface, or parent of a subsurface
/*
return if let KeyboardFocusTarget::LayerSurface(layer_surface) = target {
let data = layer_surface.cached_state();
(data.keyboard_interactivity, data.layer) == (KeyboardInteractivity::Exclusive, layer)
} else {
false
};
*/
}

match target {
Expand All @@ -372,9 +390,11 @@ fn focus_target_is_valid(

(is_sticky || is_in_focus_stack) && !has_fullscreen
}
/*
KeyboardFocusTarget::LayerSurface(layer) => {
layer_map_for_output(&output).layers().any(|l| l == &layer)
}
*/
KeyboardFocusTarget::Group(WindowGroup { node, .. }) => state
.common
.shell
Expand All @@ -383,6 +403,7 @@ fn focus_target_is_valid(
.1
.tiling_layer
.has_node(&node),
/*
KeyboardFocusTarget::Fullscreen(window) => {
let workspace = state.common.shell.active_space(&output);
let focus_stack = workspace.focus_stack.get(&seat);
Expand All @@ -393,8 +414,9 @@ fn focus_target_is_valid(
.unwrap_or(false)
&& workspace.get_fullscreen().is_some()
}
KeyboardFocusTarget::Popup(_) => true,
KeyboardFocusTarget::LockSurface(_) => false,
*/
// TODO restrict when it handles all wl surfaces
KeyboardFocusTarget::WlSurface(_) => true,
}
}

Expand All @@ -420,7 +442,7 @@ fn update_focus_target(
.cloned()
.map(KeyboardFocusTarget::from)
} else if let Some(surface) = state.common.shell.active_space(&output).get_fullscreen() {
Some(KeyboardFocusTarget::Fullscreen(surface.clone()))
KeyboardFocusTarget::try_from(surface.clone()).ok()
} else {
state
.common
Expand Down
Loading