2022-07-04 16:00:29 +02:00
|
|
|
use crate::{
|
2023-12-20 20:39:51 +00:00
|
|
|
shell::{element::CosmicMapped, Shell},
|
2022-07-04 16:00:29 +02:00
|
|
|
state::Common,
|
|
|
|
|
utils::prelude::*,
|
|
|
|
|
wayland::handlers::xdg_shell::PopupGrabData,
|
2022-07-04 15:28:03 +02:00
|
|
|
};
|
|
|
|
|
use indexmap::IndexSet;
|
|
|
|
|
use smithay::{
|
2022-09-28 12:01:29 +02:00
|
|
|
desktop::{layer_map_for_output, PopupUngrabStrategy},
|
2022-08-31 13:01:23 +02:00
|
|
|
input::Seat,
|
2023-10-16 12:28:19 -07:00
|
|
|
output::Output,
|
2024-05-31 15:35:30 -07:00
|
|
|
reexports::wayland_server::Resource,
|
2022-08-31 13:01:23 +02:00
|
|
|
utils::{IsAlive, Serial, SERIAL_COUNTER},
|
2023-11-02 10:39:32 -07:00
|
|
|
wayland::{
|
|
|
|
|
seat::WaylandFocus,
|
2024-05-31 15:35:30 -07:00
|
|
|
selection::data_device::set_data_device_focus,
|
|
|
|
|
selection::primary_selection::set_primary_focus,
|
2023-11-02 10:39:32 -07:00
|
|
|
shell::wlr_layer::{KeyboardInteractivity, Layer},
|
|
|
|
|
},
|
2022-07-04 15:28:03 +02:00
|
|
|
};
|
2024-05-13 14:16:21 -07:00
|
|
|
use std::{borrow::Cow, cell::RefCell};
|
2023-03-03 19:34:41 +01:00
|
|
|
use tracing::{debug, trace};
|
2022-09-28 12:01:29 +02:00
|
|
|
|
|
|
|
|
use self::target::{KeyboardFocusTarget, WindowGroup};
|
2022-07-04 15:28:03 +02:00
|
|
|
|
2024-04-05 13:53:35 +02:00
|
|
|
use super::{layout::floating::FloatingLayout, SeatExt};
|
2023-01-23 22:53:15 +01:00
|
|
|
|
2022-09-22 18:15:05 +02:00
|
|
|
pub mod target;
|
|
|
|
|
|
2022-07-04 15:28:03 +02:00
|
|
|
#[derive(Debug, serde::Deserialize, Clone, Copy, PartialEq, Eq)]
|
|
|
|
|
pub enum FocusDirection {
|
|
|
|
|
Left,
|
|
|
|
|
Right,
|
|
|
|
|
Up,
|
|
|
|
|
Down,
|
|
|
|
|
In,
|
|
|
|
|
Out,
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-28 12:01:29 +02:00
|
|
|
pub struct FocusStack<'a>(pub(super) Option<&'a IndexSet<CosmicMapped>>);
|
|
|
|
|
pub struct FocusStackMut<'a>(pub(super) &'a mut IndexSet<CosmicMapped>);
|
2022-07-04 15:28:03 +02:00
|
|
|
|
|
|
|
|
impl<'a> FocusStack<'a> {
|
2022-09-28 12:01:29 +02:00
|
|
|
pub fn last(&self) -> Option<&CosmicMapped> {
|
|
|
|
|
self.0
|
|
|
|
|
.as_ref()
|
2024-02-23 17:25:40 +01:00
|
|
|
.and_then(|set| set.iter().rev().find(|w| w.alive() && !w.is_minimized()))
|
2022-07-04 15:28:03 +02:00
|
|
|
}
|
|
|
|
|
|
2022-09-28 12:01:29 +02:00
|
|
|
pub fn iter(&self) -> impl Iterator<Item = &'_ CosmicMapped> {
|
|
|
|
|
self.0
|
|
|
|
|
.iter()
|
2024-02-23 17:25:40 +01:00
|
|
|
.flat_map(|set| set.iter().rev().filter(|w| w.alive() && !w.is_minimized()))
|
2022-07-04 15:28:03 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'a> FocusStackMut<'a> {
|
2022-09-28 12:01:29 +02:00
|
|
|
pub fn append(&mut self, window: &CosmicMapped) {
|
|
|
|
|
self.0.retain(|w| w.alive());
|
2022-07-04 15:28:03 +02:00
|
|
|
self.0.shift_remove(window);
|
|
|
|
|
self.0.insert(window.clone());
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-20 20:19:42 +00:00
|
|
|
pub fn remove(&mut self, window: &CosmicMapped) {
|
|
|
|
|
self.0.retain(|w| w != window);
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-28 12:01:29 +02:00
|
|
|
pub fn last(&self) -> Option<&CosmicMapped> {
|
2024-02-23 17:25:40 +01:00
|
|
|
self.0.iter().rev().find(|w| w.alive() && !w.is_minimized())
|
2022-07-04 15:28:03 +02:00
|
|
|
}
|
|
|
|
|
|
2022-09-28 12:01:29 +02:00
|
|
|
pub fn iter(&self) -> impl Iterator<Item = &'_ CosmicMapped> {
|
2024-02-23 17:25:40 +01:00
|
|
|
self.0
|
|
|
|
|
.iter()
|
|
|
|
|
.rev()
|
|
|
|
|
.filter(|w| w.alive() && !w.is_minimized())
|
2022-07-04 15:28:03 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-28 12:01:29 +02:00
|
|
|
pub struct ActiveFocus(RefCell<Option<KeyboardFocusTarget>>);
|
2022-07-04 15:28:03 +02:00
|
|
|
|
|
|
|
|
impl ActiveFocus {
|
2022-09-28 12:01:29 +02:00
|
|
|
fn set(seat: &Seat<State>, target: Option<KeyboardFocusTarget>) {
|
2022-07-04 15:28:03 +02:00
|
|
|
if !seat
|
|
|
|
|
.user_data()
|
2022-09-28 12:01:29 +02:00
|
|
|
.insert_if_missing(|| ActiveFocus(RefCell::new(target.clone())))
|
2022-07-04 15:28:03 +02:00
|
|
|
{
|
|
|
|
|
*seat
|
|
|
|
|
.user_data()
|
|
|
|
|
.get::<ActiveFocus>()
|
|
|
|
|
.unwrap()
|
|
|
|
|
.0
|
2022-09-28 12:01:29 +02:00
|
|
|
.borrow_mut() = target;
|
2022-07-04 15:28:03 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-28 12:01:29 +02:00
|
|
|
fn get(seat: &Seat<State>) -> Option<KeyboardFocusTarget> {
|
2022-07-04 15:28:03 +02:00
|
|
|
seat.user_data()
|
|
|
|
|
.get::<ActiveFocus>()
|
|
|
|
|
.and_then(|a| a.0.borrow().clone())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Shell {
|
2024-02-23 17:25:40 +01:00
|
|
|
pub fn set_focus(
|
2022-08-31 13:01:23 +02:00
|
|
|
state: &mut State,
|
2022-09-28 12:01:29 +02:00
|
|
|
target: Option<&KeyboardFocusTarget>,
|
2024-04-05 13:53:35 +02:00
|
|
|
seat: &Seat<State>,
|
2024-02-23 17:25:40 +01:00
|
|
|
serial: Option<Serial>,
|
2022-07-04 15:28:03 +02:00
|
|
|
) {
|
2023-09-20 18:57:58 +02:00
|
|
|
let element = match target {
|
|
|
|
|
Some(KeyboardFocusTarget::Element(mapped)) => Some(mapped.clone()),
|
2024-04-10 15:49:08 +02:00
|
|
|
Some(KeyboardFocusTarget::Fullscreen(window)) => state
|
|
|
|
|
.common
|
|
|
|
|
.shell
|
|
|
|
|
.read()
|
|
|
|
|
.unwrap()
|
|
|
|
|
.element_for_surface(window)
|
|
|
|
|
.cloned(),
|
2023-09-20 18:57:58 +02:00
|
|
|
_ => None,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if let Some(mapped) = element {
|
2024-02-23 17:25:40 +01:00
|
|
|
if mapped.is_minimized() {
|
|
|
|
|
return;
|
2022-07-04 15:28:03 +02:00
|
|
|
}
|
2024-04-10 15:49:08 +02:00
|
|
|
state
|
|
|
|
|
.common
|
|
|
|
|
.shell
|
|
|
|
|
.write()
|
|
|
|
|
.unwrap()
|
|
|
|
|
.append_focus_stack(&mapped, seat);
|
2022-07-04 15:28:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// update keyboard focus
|
2024-04-05 13:53:35 +02:00
|
|
|
if let Some(keyboard) = seat.get_keyboard() {
|
|
|
|
|
ActiveFocus::set(seat, target.cloned());
|
2022-07-04 15:28:03 +02:00
|
|
|
keyboard.set_focus(
|
2022-08-31 13:01:23 +02:00
|
|
|
state,
|
2022-09-28 12:01:29 +02:00
|
|
|
target.cloned(),
|
2022-07-04 15:28:03 +02:00
|
|
|
serial.unwrap_or_else(|| SERIAL_COUNTER.next_serial()),
|
|
|
|
|
);
|
|
|
|
|
}
|
2024-04-05 13:53:35 +02:00
|
|
|
|
2024-04-10 15:49:08 +02:00
|
|
|
state.common.shell.write().unwrap().update_active();
|
2024-04-05 13:53:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn append_focus_stack(&mut self, mapped: &CosmicMapped, seat: &Seat<State>) {
|
|
|
|
|
if mapped.is_minimized() {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// update FocusStack and notify layouts about new focus (if any window)
|
|
|
|
|
let workspace = self.space_for_mut(&mapped);
|
|
|
|
|
let workspace = if workspace.is_none() {
|
|
|
|
|
self.active_space_mut(&seat.active_output())
|
|
|
|
|
} else {
|
|
|
|
|
workspace.unwrap()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let mut focus_stack = workspace.focus_stack.get_mut(seat);
|
|
|
|
|
if Some(mapped) != focus_stack.last() {
|
|
|
|
|
trace!(?mapped, "Focusing window.");
|
|
|
|
|
focus_stack.append(&mapped);
|
|
|
|
|
// also remove popup grabs, if we are switching focus
|
|
|
|
|
if let Some(mut popup_grab) = seat
|
|
|
|
|
.user_data()
|
|
|
|
|
.get::<PopupGrabData>()
|
|
|
|
|
.and_then(|x| x.take())
|
|
|
|
|
{
|
|
|
|
|
if !popup_grab.has_ended() {
|
|
|
|
|
popup_grab.ungrab(PopupUngrabStrategy::All);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-07-04 15:28:03 +02:00
|
|
|
}
|
|
|
|
|
|
2024-04-05 13:53:35 +02:00
|
|
|
fn update_active<'a, 'b>(&mut self) {
|
2022-07-04 15:28:03 +02:00
|
|
|
// update activate status
|
2024-04-05 13:53:35 +02:00
|
|
|
let focused_windows = self
|
|
|
|
|
.seats
|
|
|
|
|
.iter()
|
2022-07-04 15:28:03 +02:00
|
|
|
.flat_map(|seat| {
|
2023-06-09 19:47:41 +02:00
|
|
|
if matches!(
|
|
|
|
|
seat.get_keyboard().unwrap().current_focus(),
|
|
|
|
|
Some(KeyboardFocusTarget::Group(_))
|
|
|
|
|
) {
|
|
|
|
|
return None;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-25 19:40:26 +02:00
|
|
|
Some(self.outputs().flat_map(|o| {
|
2022-09-28 12:01:29 +02:00
|
|
|
let space = self.active_space(o);
|
|
|
|
|
let stack = space.focus_stack.get(seat);
|
|
|
|
|
stack.last().cloned()
|
2023-06-09 19:47:41 +02:00
|
|
|
}))
|
2022-07-04 15:28:03 +02:00
|
|
|
})
|
2023-06-09 19:47:41 +02:00
|
|
|
.flatten()
|
2022-07-04 15:28:03 +02:00
|
|
|
.collect::<Vec<_>>();
|
|
|
|
|
|
2023-10-25 19:40:26 +02:00
|
|
|
for output in self.outputs().cloned().collect::<Vec<_>>().into_iter() {
|
2023-12-20 20:39:51 +00:00
|
|
|
let set = self.workspaces.sets.get_mut(&output).unwrap();
|
|
|
|
|
for focused in focused_windows.iter() {
|
|
|
|
|
raise_with_children(&mut set.sticky_layer, focused);
|
|
|
|
|
}
|
|
|
|
|
for window in set.sticky_layer.mapped() {
|
|
|
|
|
window.set_activated(focused_windows.contains(&window));
|
|
|
|
|
window.configure();
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-25 19:40:26 +02:00
|
|
|
let workspace = self.workspaces.active_mut(&output);
|
2022-07-04 15:28:03 +02:00
|
|
|
for focused in focused_windows.iter() {
|
2023-09-20 19:20:35 +02:00
|
|
|
raise_with_children(&mut workspace.floating_layer, focused);
|
2022-07-04 15:28:03 +02:00
|
|
|
}
|
2022-09-28 12:01:29 +02:00
|
|
|
for window in workspace.mapped() {
|
|
|
|
|
window.set_activated(focused_windows.contains(&window));
|
2022-07-04 15:28:03 +02:00
|
|
|
window.configure();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-20 19:20:35 +02:00
|
|
|
fn raise_with_children(floating_layer: &mut FloatingLayout, focused: &CosmicMapped) {
|
|
|
|
|
if floating_layer.mapped().any(|m| m == focused) {
|
|
|
|
|
floating_layer.space.raise_element(focused, true);
|
|
|
|
|
for element in floating_layer
|
|
|
|
|
.space
|
|
|
|
|
.elements()
|
2024-03-05 13:53:59 +01:00
|
|
|
.filter(|elem| elem != &focused)
|
2023-09-20 19:20:35 +02:00
|
|
|
.filter(|elem| {
|
2024-02-21 13:24:56 -08:00
|
|
|
let parent = elem
|
|
|
|
|
.active_window()
|
|
|
|
|
.0
|
|
|
|
|
.toplevel()
|
|
|
|
|
.and_then(|toplevel| toplevel.parent());
|
2024-05-13 14:16:21 -07:00
|
|
|
parent == focused.active_window().wl_surface().map(Cow::into_owned)
|
2023-09-20 19:20:35 +02:00
|
|
|
})
|
|
|
|
|
.cloned()
|
|
|
|
|
.collect::<Vec<_>>()
|
|
|
|
|
.into_iter()
|
|
|
|
|
{
|
|
|
|
|
raise_with_children(floating_layer, &element);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-04 15:28:03 +02:00
|
|
|
impl Common {
|
2022-08-31 13:01:23 +02:00
|
|
|
pub fn refresh_focus(state: &mut State) {
|
2024-04-10 15:49:08 +02:00
|
|
|
let seats = state
|
2024-04-05 13:53:35 +02:00
|
|
|
.common
|
|
|
|
|
.shell
|
2024-04-10 15:49:08 +02:00
|
|
|
.read()
|
|
|
|
|
.unwrap()
|
2024-04-05 13:53:35 +02:00
|
|
|
.seats
|
|
|
|
|
.iter()
|
|
|
|
|
.cloned()
|
2024-04-10 15:49:08 +02:00
|
|
|
.collect::<Vec<_>>();
|
2024-05-31 15:35:30 -07:00
|
|
|
for seat in &seats {
|
2024-04-10 15:49:08 +02:00
|
|
|
let mut shell = state.common.shell.write().unwrap();
|
2022-09-28 12:01:29 +02:00
|
|
|
let output = seat.active_output();
|
2024-04-10 15:49:08 +02:00
|
|
|
if !shell.outputs().any(|o| o == &output) {
|
|
|
|
|
seat.set_active_output(&shell.outputs().next().unwrap());
|
2022-11-22 10:07:17 +01:00
|
|
|
continue;
|
|
|
|
|
}
|
2022-08-31 13:01:23 +02:00
|
|
|
let last_known_focus = ActiveFocus::get(&seat);
|
2022-07-04 15:28:03 +02:00
|
|
|
|
2022-09-28 12:01:29 +02:00
|
|
|
if let Some(target) = last_known_focus {
|
|
|
|
|
if target.alive() {
|
2024-04-10 15:49:08 +02:00
|
|
|
if focus_target_is_valid(&mut *shell, &seat, &output, target) {
|
2023-10-16 12:28:19 -07:00
|
|
|
continue; // Focus is valid
|
|
|
|
|
} else {
|
|
|
|
|
trace!("Wrong Window, focus fixup");
|
|
|
|
|
}
|
2022-07-04 15:28:03 +02:00
|
|
|
} else {
|
2023-10-24 17:40:28 +02:00
|
|
|
if let KeyboardFocusTarget::Popup(_) = target {
|
|
|
|
|
if let Some(popup_grab) = seat
|
|
|
|
|
.user_data()
|
|
|
|
|
.get::<PopupGrabData>()
|
|
|
|
|
.and_then(|x| x.take())
|
|
|
|
|
{
|
2024-03-26 14:15:31 -07:00
|
|
|
if !popup_grab.has_ended() {
|
|
|
|
|
if let Some(new) = popup_grab.current_grab() {
|
|
|
|
|
trace!("restore focus to previous popup grab");
|
2024-04-10 15:49:08 +02:00
|
|
|
std::mem::drop(shell);
|
|
|
|
|
|
2024-03-26 14:15:31 -07:00
|
|
|
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()
|
2023-10-24 17:40:28 +02:00
|
|
|
.get_or_insert::<PopupGrabData, _>(PopupGrabData::default)
|
2024-03-26 14:15:31 -07:00
|
|
|
.set(Some(popup_grab));
|
|
|
|
|
continue;
|
2023-10-24 17:40:28 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-03-03 19:34:41 +01:00
|
|
|
trace!("Surface dead, focus fixup");
|
2022-07-04 15:28:03 +02:00
|
|
|
}
|
2022-09-27 13:46:25 +02:00
|
|
|
} else {
|
2024-04-10 15:49:08 +02:00
|
|
|
let workspace = shell.active_space(&output);
|
2023-04-01 21:01:00 +04:00
|
|
|
let focus_stack = workspace.focus_stack.get(&seat);
|
|
|
|
|
|
|
|
|
|
if focus_stack.last().is_none() {
|
|
|
|
|
continue; // Focus is valid
|
|
|
|
|
} else {
|
|
|
|
|
trace!("No previous window, focus fixup");
|
|
|
|
|
}
|
2022-07-04 15:28:03 +02:00
|
|
|
}
|
|
|
|
|
|
2022-09-22 18:15:05 +02:00
|
|
|
// fixup focus
|
|
|
|
|
{
|
2022-07-04 15:28:03 +02:00
|
|
|
// also remove popup grabs, if we are switching focus
|
|
|
|
|
if let Some(mut popup_grab) = seat
|
|
|
|
|
.user_data()
|
|
|
|
|
.get::<PopupGrabData>()
|
|
|
|
|
.and_then(|x| x.take())
|
|
|
|
|
{
|
|
|
|
|
if !popup_grab.has_ended() {
|
2022-08-31 13:01:23 +02:00
|
|
|
popup_grab.ungrab(PopupUngrabStrategy::All);
|
2022-07-04 15:28:03 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// update keyboard focus
|
2024-04-10 15:49:08 +02:00
|
|
|
let target = update_focus_target(&*shell, &seat, &output);
|
|
|
|
|
std::mem::drop(shell);
|
|
|
|
|
|
2022-07-04 15:28:03 +02:00
|
|
|
if let Some(keyboard) = seat.get_keyboard() {
|
2023-03-03 19:34:41 +01:00
|
|
|
debug!("Restoring focus to {:?}", target.as_ref());
|
2022-09-28 12:01:29 +02:00
|
|
|
keyboard.set_focus(state, target.clone(), SERIAL_COUNTER.next_serial());
|
|
|
|
|
ActiveFocus::set(&seat, target);
|
2022-07-04 15:28:03 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-31 15:35:30 -07:00
|
|
|
// Update clipboard and primary focus
|
|
|
|
|
//
|
|
|
|
|
// For now, needs to be here instead of in `focus_changed` to update focus
|
|
|
|
|
// when the active element of a stack changes.
|
|
|
|
|
for seat in &seats {
|
|
|
|
|
if let Some(keyboard) = seat.get_keyboard() {
|
|
|
|
|
let focus = keyboard.current_focus();
|
|
|
|
|
let client = focus
|
|
|
|
|
.as_ref()
|
|
|
|
|
.and_then(|t| t.wl_surface())
|
|
|
|
|
.and_then(|s| state.common.display_handle.get_client(s.id()).ok());
|
|
|
|
|
set_data_device_focus(&state.common.display_handle, &seat, client.clone());
|
|
|
|
|
set_primary_focus(&state.common.display_handle, &seat, client);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-10 15:49:08 +02:00
|
|
|
state.common.shell.write().unwrap().update_active()
|
2022-07-04 15:28:03 +02:00
|
|
|
}
|
|
|
|
|
}
|
2023-10-16 12:28:19 -07:00
|
|
|
|
|
|
|
|
fn focus_target_is_valid(
|
2024-04-05 13:53:35 +02:00
|
|
|
shell: &mut Shell,
|
2023-10-16 12:28:19 -07:00
|
|
|
seat: &Seat<State>,
|
|
|
|
|
output: &Output,
|
|
|
|
|
target: KeyboardFocusTarget,
|
|
|
|
|
) -> bool {
|
2023-11-02 10:39:32 -07:00
|
|
|
// If a session lock is active, only lock surfaces can be focused
|
2024-04-05 13:53:35 +02:00
|
|
|
if shell.session_lock.is_some() {
|
2023-10-16 12:28:19 -07:00
|
|
|
return matches!(target, KeyboardFocusTarget::LockSurface(_));
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-02 10:39:32 -07:00
|
|
|
// If an exclusive layer shell surface exists (on any output), only exclusive
|
|
|
|
|
// shell surfaces can have focus, on the highest layer with exclusive surfaces.
|
2024-04-05 13:53:35 +02:00
|
|
|
if let Some(layer) = exclusive_layer_surface_layer(shell) {
|
2023-11-02 10:39:32 -07:00
|
|
|
return if let KeyboardFocusTarget::LayerSurface(layer_surface) = target {
|
|
|
|
|
let data = layer_surface.cached_state();
|
|
|
|
|
(data.keyboard_interactivity, data.layer) == (KeyboardInteractivity::Exclusive, layer)
|
|
|
|
|
} else {
|
|
|
|
|
false
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-16 12:28:19 -07:00
|
|
|
match target {
|
|
|
|
|
KeyboardFocusTarget::Element(mapped) => {
|
2024-04-05 13:53:35 +02:00
|
|
|
let is_sticky = shell
|
2023-12-20 20:39:51 +00:00
|
|
|
.workspaces
|
|
|
|
|
.sets
|
|
|
|
|
.get(output)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.sticky_layer
|
|
|
|
|
.mapped()
|
|
|
|
|
.any(|m| m == &mapped);
|
|
|
|
|
|
2024-04-05 13:53:35 +02:00
|
|
|
let workspace = shell.active_space(&output);
|
2023-10-16 12:28:19 -07:00
|
|
|
let focus_stack = workspace.focus_stack.get(&seat);
|
2023-12-20 20:39:51 +00:00
|
|
|
let is_in_focus_stack = focus_stack.last().map(|m| m == &mapped).unwrap_or(false);
|
|
|
|
|
let has_fullscreen = workspace.get_fullscreen().is_some();
|
|
|
|
|
|
|
|
|
|
if is_sticky && !is_in_focus_stack {
|
2024-04-05 13:53:35 +02:00
|
|
|
shell.append_focus_stack(&mapped, seat);
|
2023-12-20 20:39:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
(is_sticky || is_in_focus_stack) && !has_fullscreen
|
2023-10-16 12:28:19 -07:00
|
|
|
}
|
|
|
|
|
KeyboardFocusTarget::LayerSurface(layer) => {
|
|
|
|
|
layer_map_for_output(&output).layers().any(|l| l == &layer)
|
|
|
|
|
}
|
2024-04-05 13:53:35 +02:00
|
|
|
KeyboardFocusTarget::Group(WindowGroup { node, .. }) => shell
|
2023-10-16 12:28:19 -07:00
|
|
|
.workspaces
|
|
|
|
|
.active(&output)
|
|
|
|
|
.1
|
|
|
|
|
.tiling_layer
|
|
|
|
|
.has_node(&node),
|
|
|
|
|
KeyboardFocusTarget::Fullscreen(window) => {
|
2024-04-05 13:53:35 +02:00
|
|
|
let workspace = shell.active_space(&output);
|
2023-10-16 12:28:19 -07:00
|
|
|
let focus_stack = workspace.focus_stack.get(&seat);
|
|
|
|
|
|
|
|
|
|
focus_stack
|
|
|
|
|
.last()
|
|
|
|
|
.map(|m| m.has_active_window(&window))
|
|
|
|
|
.unwrap_or(false)
|
|
|
|
|
&& workspace.get_fullscreen().is_some()
|
|
|
|
|
}
|
|
|
|
|
KeyboardFocusTarget::Popup(_) => true,
|
|
|
|
|
KeyboardFocusTarget::LockSurface(_) => false,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn update_focus_target(
|
2024-04-05 13:53:35 +02:00
|
|
|
shell: &Shell,
|
2023-10-16 12:28:19 -07:00
|
|
|
seat: &Seat<State>,
|
|
|
|
|
output: &Output,
|
|
|
|
|
) -> Option<KeyboardFocusTarget> {
|
2024-04-05 13:53:35 +02:00
|
|
|
if let Some(session_lock) = &shell.session_lock {
|
2023-10-16 12:28:19 -07:00
|
|
|
session_lock
|
|
|
|
|
.surfaces
|
|
|
|
|
.get(output)
|
|
|
|
|
.cloned()
|
|
|
|
|
.map(KeyboardFocusTarget::from)
|
2024-04-05 13:53:35 +02:00
|
|
|
} else if let Some(layer) = exclusive_layer_surface_layer(shell) {
|
2023-11-02 10:39:32 -07:00
|
|
|
layer_map_for_output(output)
|
|
|
|
|
.layers()
|
|
|
|
|
.find(|layer_surface| {
|
|
|
|
|
let data = layer_surface.cached_state();
|
|
|
|
|
(data.keyboard_interactivity, data.layer)
|
|
|
|
|
== (KeyboardInteractivity::Exclusive, layer)
|
|
|
|
|
})
|
|
|
|
|
.cloned()
|
|
|
|
|
.map(KeyboardFocusTarget::from)
|
2024-04-05 13:53:35 +02:00
|
|
|
} else if let Some(surface) = shell.active_space(&output).get_fullscreen() {
|
2023-10-16 12:28:19 -07:00
|
|
|
Some(KeyboardFocusTarget::Fullscreen(surface.clone()))
|
|
|
|
|
} else {
|
2024-04-05 13:53:35 +02:00
|
|
|
shell
|
2023-10-16 12:28:19 -07:00
|
|
|
.active_space(&output)
|
|
|
|
|
.focus_stack
|
|
|
|
|
.get(&seat)
|
|
|
|
|
.last()
|
|
|
|
|
.cloned()
|
|
|
|
|
.map(KeyboardFocusTarget::from)
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-11-02 10:39:32 -07:00
|
|
|
|
|
|
|
|
// Get the top-most layer, if any, with at least one surface with exclusive keyboard interactivity.
|
|
|
|
|
// Only considers surface in `Top` or `Overlay` layer.
|
2024-04-05 13:53:35 +02:00
|
|
|
fn exclusive_layer_surface_layer(shell: &Shell) -> Option<Layer> {
|
2023-11-02 10:39:32 -07:00
|
|
|
let mut layer = None;
|
2024-04-05 13:53:35 +02:00
|
|
|
for output in shell.outputs() {
|
2023-11-02 10:39:32 -07:00
|
|
|
for layer_surface in layer_map_for_output(output).layers() {
|
|
|
|
|
let data = layer_surface.cached_state();
|
|
|
|
|
if data.keyboard_interactivity == KeyboardInteractivity::Exclusive {
|
|
|
|
|
if data.layer as u32 >= layer.unwrap_or(Layer::Top) as u32 {
|
|
|
|
|
layer = Some(data.layer);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
layer
|
|
|
|
|
}
|