wip: New shell logic

This commit is contained in:
Victoria Brekenfeld 2022-09-28 12:01:29 +02:00
parent 146a4893ca
commit 00f1b029da
39 changed files with 3922 additions and 2503 deletions

View file

@ -1,24 +1,18 @@
use crate::{
shell::{OutputBoundState, Shell, Workspace, WorkspaceMode},
shell::{element::CosmicMapped, Shell, Workspace},
state::Common,
utils::prelude::*,
wayland::handlers::xdg_shell::PopupGrabData,
};
use indexmap::IndexSet;
use smithay::{
desktop::{layer_map_for_output, PopupUngrabStrategy, Window, WindowSurfaceType},
desktop::{layer_map_for_output, PopupUngrabStrategy},
input::Seat,
reexports::wayland_server::protocol::wl_surface::WlSurface,
utils::{IsAlive, Serial, SERIAL_COUNTER},
wayland::{
compositor::get_role,
shell::{wlr_layer::LAYER_SURFACE_ROLE, xdg::XDG_TOPLEVEL_ROLE},
},
};
use std::{
cell::{Ref, RefCell, RefMut},
collections::HashMap,
};
use std::cell::RefCell;
use self::target::{KeyboardFocusTarget, WindowGroup};
pub mod target;
@ -32,80 +26,59 @@ pub enum FocusDirection {
Out,
}
pub struct FocusStack<'a>(Ref<'a, IndexSet<Window>>);
pub struct FocusStackMut<'a>(RefMut<'a, IndexSet<Window>>);
pub struct FocusStack<'a>(pub(super) Option<&'a IndexSet<CosmicMapped>>);
pub struct FocusStackMut<'a>(pub(super) &'a mut IndexSet<CosmicMapped>);
impl<'a> FocusStack<'a> {
pub fn last(&self) -> Option<Window> {
self.0.iter().rev().find(|w| w.toplevel().alive()).cloned()
pub fn last(&self) -> Option<&CosmicMapped> {
self.0
.as_ref()
.and_then(|set| set.iter().rev().find(|w| w.alive()))
}
pub fn iter(&self) -> impl Iterator<Item = &'_ Window> {
self.0.iter().rev().filter(|w| w.toplevel().alive())
pub fn iter(&self) -> impl Iterator<Item = &'_ CosmicMapped> {
self.0
.iter()
.flat_map(|set| set.iter().rev().filter(|w| w.alive()))
}
}
impl<'a> FocusStackMut<'a> {
pub fn append(&mut self, window: &Window) {
self.0.retain(|w| w.toplevel().alive());
pub fn append(&mut self, window: &CosmicMapped) {
self.0.retain(|w| w.alive());
self.0.shift_remove(window);
self.0.insert(window.clone());
}
pub fn last(&self) -> Option<Window> {
self.0.iter().rev().find(|w| w.toplevel().alive()).cloned()
pub fn last(&self) -> Option<&CosmicMapped> {
self.0.iter().rev().find(|w| w.alive())
}
pub fn iter(&self) -> impl Iterator<Item = &'_ Window> {
self.0.iter().rev().filter(|w| w.toplevel().alive())
pub fn iter(&self) -> impl Iterator<Item = &'_ CosmicMapped> {
self.0.iter().rev().filter(|w| w.alive())
}
}
type FocusStackData = RefCell<(HashMap<u8, IndexSet<Window>>, IndexSet<Window>)>;
impl Workspace {}
impl Workspace {
pub fn focus_stack<'a, 'b>(&'b self, seat: &'a Seat<State>) -> FocusStack<'a> {
seat.user_data()
.insert_if_missing(|| FocusStackData::new((HashMap::new(), IndexSet::new())));
let idx = self.idx;
FocusStack(Ref::map(
seat.user_data().get::<FocusStackData>().unwrap().borrow(),
|map| map.0.get(&idx).unwrap_or(&map.1), //TODO: workaround until Ref::filter_map goes stable
))
}
pub fn focus_stack_mut<'a, 'b>(&'b self, seat: &'a Seat<State>) -> FocusStackMut<'a> {
seat.user_data()
.insert_if_missing(|| FocusStackData::new((HashMap::new(), IndexSet::new())));
let idx = self.idx;
FocusStackMut(RefMut::map(
seat.user_data()
.get::<FocusStackData>()
.unwrap()
.borrow_mut(),
|map| map.0.entry(idx).or_insert_with(|| IndexSet::new()),
))
}
}
pub struct ActiveFocus(RefCell<Option<WlSurface>>);
pub struct ActiveFocus(RefCell<Option<KeyboardFocusTarget>>);
impl ActiveFocus {
fn set(seat: &Seat<State>, surface: Option<WlSurface>) {
fn set(seat: &Seat<State>, target: Option<KeyboardFocusTarget>) {
if !seat
.user_data()
.insert_if_missing(|| ActiveFocus(RefCell::new(surface.clone())))
.insert_if_missing(|| ActiveFocus(RefCell::new(target.clone())))
{
*seat
.user_data()
.get::<ActiveFocus>()
.unwrap()
.0
.borrow_mut() = surface;
.borrow_mut() = target;
}
}
fn get(seat: &Seat<State>) -> Option<WlSurface> {
fn get(seat: &Seat<State>) -> Option<KeyboardFocusTarget> {
seat.user_data()
.get::<ActiveFocus>()
.and_then(|a| a.0.borrow().clone())
@ -115,30 +88,25 @@ impl ActiveFocus {
impl Shell {
pub fn set_focus<'a>(
state: &mut State,
surface: Option<&WlSurface>,
target: Option<&KeyboardFocusTarget>,
active_seat: &Seat<State>,
serial: Option<Serial>,
) {
// update FocusStack and notify layouts about new focus (if any window)
if let Some(surface) = surface {
if let Some(workspace) = state.common.shell.space_for_window_mut(surface) {
if let Some(window) = workspace
.space
.window_for_surface(surface, WindowSurfaceType::ALL)
{
let mut focus_stack = workspace.focus_stack_mut(active_seat);
if Some(window) != focus_stack.last().as_ref() {
slog_scope::debug!("Focusing window: {:?}", window);
focus_stack.append(window);
// also remove popup grabs, if we are switching focus
if let Some(mut popup_grab) = active_seat
.user_data()
.get::<PopupGrabData>()
.and_then(|x| x.take())
{
if !popup_grab.has_ended() {
popup_grab.ungrab(PopupUngrabStrategy::All);
}
if let Some(KeyboardFocusTarget::Element(mapped)) = target {
if let Some(workspace) = state.common.shell.space_for_mut(mapped) {
let mut focus_stack = workspace.focus_stack.get_mut(active_seat);
if Some(mapped) != focus_stack.last() {
slog_scope::debug!("Focusing window: {:?}", mapped);
focus_stack.append(mapped);
// also remove popup grabs, if we are switching focus
if let Some(mut popup_grab) = active_seat
.user_data()
.get::<PopupGrabData>()
.and_then(|x| x.take())
{
if !popup_grab.has_ended() {
popup_grab.ungrab(PopupUngrabStrategy::All);
}
}
}
@ -147,10 +115,10 @@ impl Shell {
// update keyboard focus
if let Some(keyboard) = active_seat.get_keyboard() {
ActiveFocus::set(active_seat, surface.cloned());
ActiveFocus::set(active_seat, target.cloned());
keyboard.set_focus(
state,
surface.cloned(),
target.cloned(),
serial.unwrap_or_else(|| SERIAL_COUNTER.next_serial()),
);
}
@ -160,30 +128,23 @@ impl Shell {
// update activate status
let focused_windows = seats
.flat_map(|seat| {
self.outputs
.iter()
.flat_map(|o| self.active_space(o).focus_stack(seat).last().clone())
self.outputs.iter().flat_map(|o| {
let space = self.active_space(o);
let stack = space.focus_stack.get(seat);
stack.last().cloned()
})
})
.collect::<Vec<_>>();
for output in self.outputs.iter() {
let workspace = match &self.workspace_mode {
WorkspaceMode::OutputBound => {
let active = output
.user_data()
.get::<OutputBoundState>()
.unwrap()
.active
.get();
&mut self.spaces[active]
}
WorkspaceMode::Global { active, .. } => &mut self.spaces[*active],
};
let workspace = self.workspaces.active_mut(output);
for focused in focused_windows.iter() {
workspace.space.raise_window(focused, true);
if workspace.floating_layer.mapped().any(|m| m == focused) {
workspace.floating_layer.space.raise_element(focused, true);
}
}
for window in workspace.space.windows() {
window.set_activated(focused_windows.contains(window));
for window in workspace.mapped() {
window.set_activated(focused_windows.contains(&window));
window.configure();
}
}
@ -193,55 +154,50 @@ impl Shell {
impl Common {
pub fn set_focus(
state: &mut State,
surface: Option<&WlSurface>,
target: Option<&KeyboardFocusTarget>,
active_seat: &Seat<State>,
serial: Option<Serial>,
) {
Shell::set_focus(state, surface, active_seat, serial);
state.common.shell.update_active(state.common.seats.iter());
Shell::set_focus(state, target, active_seat, serial);
let seats = state.common.seats().cloned().collect::<Vec<_>>();
state.common.shell.update_active(seats.iter());
}
pub fn refresh_focus(state: &mut State) {
let seats = state.common.seats.clone();
let seats = state.common.seats().cloned().collect::<Vec<_>>();
for seat in seats {
let output = active_output(&seat, &state.common);
let output = seat.active_output();
let last_known_focus = ActiveFocus::get(&seat);
if let Some(surface) = last_known_focus {
if surface.alive() {
let is_toplevel = matches!(get_role(&surface), Some(XDG_TOPLEVEL_ROLE));
let is_layer = matches!(get_role(&surface), Some(LAYER_SURFACE_ROLE));
if let Some(popup) = state.common.shell.popups.find_popup(&surface) {
if popup.alive() {
continue;
}
} else if is_layer {
if layer_map_for_output(&output)
.layer_for_surface(&surface, WindowSurfaceType::ALL)
.is_some()
{
continue; // Focus is valid
}
} else if is_toplevel {
let workspace = state.common.shell.active_space(&output);
if let Some(window) = workspace
.space
.window_for_surface(&surface, WindowSurfaceType::ALL)
{
let focus_stack = workspace.focus_stack(&seat);
if !focus_stack.last().map(|w| &w != window).unwrap_or(true) {
if let Some(target) = last_known_focus {
if target.alive() {
match target {
KeyboardFocusTarget::Element(mapped) => {
let workspace = state.common.shell.active_space(&output);
let focus_stack = workspace.focus_stack.get(&seat);
if focus_stack.last().map(|m| m == &mapped).unwrap_or(false) {
continue; // Focus is valid
} else {
slog_scope::debug!("Wrong Window, focus fixup");
}
} else {
slog_scope::debug!("Different workspaces Window, focus fixup");
}
} else {
// unknown surface type, fixup
slog_scope::debug!("Surface unmapped, focus fixup");
}
KeyboardFocusTarget::LayerSurface(layer) => {
if layer_map_for_output(&output).layers().any(|l| l == &layer) {
continue; // Focus is valid
}
}
KeyboardFocusTarget::Group(WindowGroup {
output: weak_output,
..
}) => {
if weak_output == output {
continue; // Focus is valid,
}
}
KeyboardFocusTarget::Popup(_) | KeyboardFocusTarget::Fullscreen(_) => {
continue;
} // Focus is valid
};
} else {
slog_scope::debug!("Surface dead, focus fixup");
}
@ -263,21 +219,24 @@ impl Common {
}
// update keyboard focus
let surface = state
let target = state
.common
.shell
.active_space(&output)
.focus_stack(&seat)
.focus_stack
.get(&seat)
.last()
.map(|w| w.toplevel().wl_surface().clone());
.cloned()
.map(KeyboardFocusTarget::from);
if let Some(keyboard) = seat.get_keyboard() {
slog_scope::info!("restoring focus to: {:?}", surface.as_ref());
keyboard.set_focus(state, surface.clone(), SERIAL_COUNTER.next_serial());
ActiveFocus::set(&seat, surface);
slog_scope::info!("restoring focus to: {:?}", target.as_ref());
keyboard.set_focus(state, target.clone(), SERIAL_COUNTER.next_serial());
ActiveFocus::set(&seat, target);
}
}
}
state.common.shell.update_active(state.common.seats.iter())
let seats = state.common.seats().cloned().collect::<Vec<_>>();
state.common.shell.update_active(seats.iter())
}
}

View file

@ -1,5 +1,8 @@
use crate::utils::prelude::*;
pub use smithay::{
use std::sync::Weak;
use crate::{shell::element::CosmicMapped, utils::prelude::*};
use id_tree::NodeId;
use smithay::{
backend::input::KeyState,
desktop::{LayerSurface, PopupKind, Window},
input::{
@ -7,83 +10,139 @@ pub use smithay::{
pointer::{AxisFrame, ButtonEvent, MotionEvent, PointerTarget},
Seat,
},
output::WeakOutput,
reexports::wayland_server::{backend::ObjectId, protocol::wl_surface::WlSurface, Resource},
utils::{IsAlive, Serial},
wayland::seat::WaylandFocus,
};
#[derive(Debug, Clone, PartialEq)]
pub enum FocusTarget {
Window(Window),
pub enum PointerFocusTarget {
Element(CosmicMapped),
Fullscreen(Window),
LayerSurface(LayerSurface),
Popup(PopupKind),
}
impl IsAlive for FocusTarget {
fn alive(&self) -> bool {
match self {
FocusTarget::Window(w) => w.alive(),
FocusTarget::LayerSurface(l) => l.alive(),
FocusTarget::Popup(p) => p.alive(),
#[derive(Debug, Clone, PartialEq)]
pub enum KeyboardFocusTarget {
Element(CosmicMapped),
Fullscreen(Window),
Group(WindowGroup),
LayerSurface(LayerSurface),
Popup(PopupKind),
}
impl From<KeyboardFocusTarget> for PointerFocusTarget {
fn from(target: KeyboardFocusTarget) -> Self {
match target {
KeyboardFocusTarget::Element(elem) => PointerFocusTarget::Element(elem),
KeyboardFocusTarget::Fullscreen(elem) => PointerFocusTarget::Fullscreen(elem),
KeyboardFocusTarget::LayerSurface(layer) => PointerFocusTarget::LayerSurface(layer),
KeyboardFocusTarget::Popup(popup) => PointerFocusTarget::Popup(popup),
_ => unreachable!("A window grab cannot start a popup grab"),
}
}
}
impl PointerTarget<State> for FocusTarget {
#[derive(Debug, Clone)]
pub struct WindowGroup {
pub(in crate::shell) node: NodeId,
pub(in crate::shell) output: WeakOutput,
pub(in crate::shell) alive: Weak<()>,
}
impl PartialEq for WindowGroup {
fn eq(&self, other: &Self) -> bool {
self.node == other.node
&& self.output == other.output
&& Weak::ptr_eq(&self.alive, &other.alive)
}
}
impl IsAlive for PointerFocusTarget {
fn alive(&self) -> bool {
match self {
PointerFocusTarget::Element(e) => e.alive(),
PointerFocusTarget::Fullscreen(f) => f.alive(),
PointerFocusTarget::LayerSurface(l) => l.alive(),
PointerFocusTarget::Popup(p) => p.alive(),
}
}
}
impl IsAlive for KeyboardFocusTarget {
fn alive(&self) -> bool {
match self {
KeyboardFocusTarget::Element(e) => e.alive(),
KeyboardFocusTarget::Fullscreen(f) => f.alive(),
KeyboardFocusTarget::Group(g) => g.alive.upgrade().is_some(),
KeyboardFocusTarget::LayerSurface(l) => l.alive(),
KeyboardFocusTarget::Popup(p) => p.alive(),
}
}
}
impl PointerTarget<State> for PointerFocusTarget {
fn enter(&self, seat: &Seat<State>, data: &mut State, event: &MotionEvent) {
match self {
FocusTarget::Window(w) => {
PointerTarget::enter(w.toplevel().wl_surface(), seat, data, event)
PointerFocusTarget::Element(w) => PointerTarget::enter(w, seat, data, event),
PointerFocusTarget::Fullscreen(w) => PointerTarget::enter(w, seat, data, event),
PointerFocusTarget::LayerSurface(l) => {
PointerTarget::enter(l.wl_surface(), seat, data, event)
}
FocusTarget::LayerSurface(l) => PointerTarget::enter(l.wl_surface(), seat, data, event),
FocusTarget::Popup(p) => PointerTarget::enter(p.wl_surface(), seat, data, event),
PointerFocusTarget::Popup(p) => PointerTarget::enter(p.wl_surface(), seat, data, event),
}
}
fn motion(&self, seat: &Seat<State>, data: &mut State, event: &MotionEvent) {
match self {
FocusTarget::Window(w) => {
PointerTarget::motion(w.toplevel().wl_surface(), seat, data, event)
}
FocusTarget::LayerSurface(l) => {
PointerFocusTarget::Element(w) => PointerTarget::motion(w, seat, data, event),
PointerFocusTarget::Fullscreen(w) => PointerTarget::motion(w, seat, data, event),
PointerFocusTarget::LayerSurface(l) => {
PointerTarget::motion(l.wl_surface(), seat, data, event)
}
FocusTarget::Popup(p) => PointerTarget::motion(p.wl_surface(), seat, data, event),
PointerFocusTarget::Popup(p) => {
PointerTarget::motion(p.wl_surface(), seat, data, event)
}
}
}
fn button(&self, seat: &Seat<State>, data: &mut State, event: &ButtonEvent) {
match self {
FocusTarget::Window(w) => {
PointerTarget::button(w.toplevel().wl_surface(), seat, data, event)
}
FocusTarget::LayerSurface(l) => {
PointerFocusTarget::Element(w) => PointerTarget::button(w, seat, data, event),
PointerFocusTarget::Fullscreen(w) => PointerTarget::button(w, seat, data, event),
PointerFocusTarget::LayerSurface(l) => {
PointerTarget::button(l.wl_surface(), seat, data, event)
}
FocusTarget::Popup(p) => PointerTarget::button(p.wl_surface(), seat, data, event),
PointerFocusTarget::Popup(p) => {
PointerTarget::button(p.wl_surface(), seat, data, event)
}
}
}
fn axis(&self, seat: &Seat<State>, data: &mut State, frame: AxisFrame) {
match self {
FocusTarget::Window(w) => {
PointerTarget::axis(w.toplevel().wl_surface(), seat, data, frame)
PointerFocusTarget::Element(w) => PointerTarget::axis(w, seat, data, frame),
PointerFocusTarget::Fullscreen(w) => PointerTarget::axis(w, seat, data, frame),
PointerFocusTarget::LayerSurface(l) => {
PointerTarget::axis(l.wl_surface(), seat, data, frame)
}
FocusTarget::LayerSurface(l) => PointerTarget::axis(l.wl_surface(), seat, data, frame),
FocusTarget::Popup(p) => PointerTarget::axis(p.wl_surface(), seat, data, frame),
PointerFocusTarget::Popup(p) => PointerTarget::axis(p.wl_surface(), seat, data, frame),
}
}
fn leave(&self, seat: &Seat<State>, data: &mut State, serial: Serial, time: u32) {
match self {
FocusTarget::Window(w) => {
PointerTarget::leave(w.toplevel().wl_surface(), seat, data, serial, time)
}
FocusTarget::LayerSurface(l) => {
PointerFocusTarget::Element(w) => PointerTarget::leave(w, seat, data, serial, time),
PointerFocusTarget::Fullscreen(w) => PointerTarget::leave(w, seat, data, serial, time),
PointerFocusTarget::LayerSurface(l) => {
PointerTarget::leave(l.wl_surface(), seat, data, serial, time)
}
FocusTarget::Popup(p) => PointerTarget::leave(p.wl_surface(), seat, data, serial, time),
PointerFocusTarget::Popup(p) => {
PointerTarget::leave(p.wl_surface(), seat, data, serial, time)
}
}
}
}
impl KeyboardTarget<State> for FocusTarget {
impl KeyboardTarget<State> for KeyboardFocusTarget {
fn enter(
&self,
seat: &Seat<State>,
@ -92,26 +151,30 @@ impl KeyboardTarget<State> for FocusTarget {
serial: Serial,
) {
match self {
FocusTarget::Window(w) => {
KeyboardTarget::enter(w.toplevel().wl_surface(), seat, data, keys, serial)
KeyboardFocusTarget::Element(w) => KeyboardTarget::enter(w, seat, data, keys, serial),
KeyboardFocusTarget::Fullscreen(w) => {
KeyboardTarget::enter(w, seat, data, keys, serial)
}
FocusTarget::LayerSurface(l) => {
KeyboardFocusTarget::Group(_) => {}
KeyboardFocusTarget::LayerSurface(l) => {
KeyboardTarget::enter(l.wl_surface(), seat, data, keys, serial)
}
FocusTarget::Popup(p) => {
KeyboardFocusTarget::Popup(p) => {
KeyboardTarget::enter(p.wl_surface(), seat, data, keys, serial)
}
}
}
fn leave(&self, seat: &Seat<State>, data: &mut State, serial: Serial) {
match self {
FocusTarget::Window(w) => {
KeyboardTarget::leave(w.toplevel().wl_surface(), seat, data, serial)
}
FocusTarget::LayerSurface(l) => {
KeyboardFocusTarget::Element(w) => KeyboardTarget::leave(w, seat, data, serial),
KeyboardFocusTarget::Fullscreen(w) => KeyboardTarget::leave(w, seat, data, serial),
KeyboardFocusTarget::Group(_) => {}
KeyboardFocusTarget::LayerSurface(l) => {
KeyboardTarget::leave(l.wl_surface(), seat, data, serial)
}
FocusTarget::Popup(p) => KeyboardTarget::leave(p.wl_surface(), seat, data, serial),
KeyboardFocusTarget::Popup(p) => {
KeyboardTarget::leave(p.wl_surface(), seat, data, serial)
}
}
}
fn key(
@ -124,19 +187,17 @@ impl KeyboardTarget<State> for FocusTarget {
time: u32,
) {
match self {
FocusTarget::Window(w) => KeyboardTarget::key(
w.toplevel().wl_surface(),
seat,
data,
key,
state,
serial,
time,
),
FocusTarget::LayerSurface(l) => {
KeyboardFocusTarget::Element(w) => {
KeyboardTarget::key(w, seat, data, key, state, serial, time)
}
KeyboardFocusTarget::Fullscreen(w) => {
KeyboardTarget::key(w, seat, data, key, state, serial, time)
}
KeyboardFocusTarget::Group(_) => {}
KeyboardFocusTarget::LayerSurface(l) => {
KeyboardTarget::key(l.wl_surface(), seat, data, key, state, serial, time)
}
FocusTarget::Popup(p) => {
KeyboardFocusTarget::Popup(p) => {
KeyboardTarget::key(p.wl_surface(), seat, data, key, state, serial, time)
}
}
@ -149,50 +210,113 @@ impl KeyboardTarget<State> for FocusTarget {
serial: Serial,
) {
match self {
FocusTarget::Window(w) => {
KeyboardTarget::modifiers(w.toplevel().wl_surface(), seat, data, modifiers, serial)
KeyboardFocusTarget::Element(w) => {
KeyboardTarget::modifiers(w, seat, data, modifiers, serial)
}
FocusTarget::LayerSurface(l) => {
KeyboardFocusTarget::Fullscreen(w) => {
KeyboardTarget::modifiers(w, seat, data, modifiers, serial)
}
KeyboardFocusTarget::Group(_) => {}
KeyboardFocusTarget::LayerSurface(l) => {
KeyboardTarget::modifiers(l.wl_surface(), seat, data, modifiers, serial)
}
FocusTarget::Popup(p) => {
KeyboardFocusTarget::Popup(p) => {
KeyboardTarget::modifiers(p.wl_surface(), seat, data, modifiers, serial)
}
}
}
}
impl WaylandFocus for FocusTarget {
fn wl_surface(&self) -> Option<&WlSurface> {
Some(match self {
FocusTarget::Window(w) => w.toplevel().wl_surface(),
FocusTarget::LayerSurface(l) => l.wl_surface(),
FocusTarget::Popup(p) => p.wl_surface(),
})
impl WaylandFocus for KeyboardFocusTarget {
fn wl_surface(&self) -> Option<WlSurface> {
match self {
KeyboardFocusTarget::Element(w) => WaylandFocus::wl_surface(w),
KeyboardFocusTarget::Fullscreen(w) => WaylandFocus::wl_surface(w),
KeyboardFocusTarget::Group(_) => None,
KeyboardFocusTarget::LayerSurface(l) => Some(l.wl_surface().clone()),
KeyboardFocusTarget::Popup(p) => Some(p.wl_surface().clone()),
}
}
fn same_client_as(&self, object_id: &ObjectId) -> bool {
match self {
FocusTarget::Window(w) => w.toplevel().wl_surface().id().same_client_as(object_id),
FocusTarget::LayerSurface(l) => l.wl_surface().id().same_client_as(object_id),
FocusTarget::Popup(p) => p.wl_surface().id().same_client_as(object_id),
KeyboardFocusTarget::Element(w) => WaylandFocus::same_client_as(w, object_id),
KeyboardFocusTarget::Fullscreen(w) => WaylandFocus::same_client_as(w, object_id),
KeyboardFocusTarget::Group(_) => false,
KeyboardFocusTarget::LayerSurface(l) => l.wl_surface().id().same_client_as(object_id),
KeyboardFocusTarget::Popup(p) => p.wl_surface().id().same_client_as(object_id),
}
}
}
impl From<Window> for FocusTarget {
impl WaylandFocus for PointerFocusTarget {
fn wl_surface(&self) -> Option<WlSurface> {
Some(match self {
PointerFocusTarget::Element(w) => WaylandFocus::wl_surface(w)?,
PointerFocusTarget::Fullscreen(w) => WaylandFocus::wl_surface(w)?,
PointerFocusTarget::LayerSurface(l) => l.wl_surface().clone(),
PointerFocusTarget::Popup(p) => p.wl_surface().clone(),
})
}
fn same_client_as(&self, object_id: &ObjectId) -> bool {
match self {
PointerFocusTarget::Element(w) => WaylandFocus::same_client_as(w, object_id),
PointerFocusTarget::Fullscreen(w) => WaylandFocus::same_client_as(w, object_id),
PointerFocusTarget::LayerSurface(l) => l.wl_surface().id().same_client_as(object_id),
PointerFocusTarget::Popup(p) => p.wl_surface().id().same_client_as(object_id),
}
}
}
impl From<CosmicMapped> for PointerFocusTarget {
fn from(w: CosmicMapped) -> Self {
PointerFocusTarget::Element(w)
}
}
impl From<Window> for PointerFocusTarget {
fn from(w: Window) -> Self {
FocusTarget::Window(w)
PointerFocusTarget::Fullscreen(w)
}
}
impl From<LayerSurface> for FocusTarget {
impl From<LayerSurface> for PointerFocusTarget {
fn from(l: LayerSurface) -> Self {
FocusTarget::LayerSurface(l)
PointerFocusTarget::LayerSurface(l)
}
}
impl From<PopupKind> for FocusTarget {
impl From<PopupKind> for PointerFocusTarget {
fn from(p: PopupKind) -> Self {
FocusTarget::Popup(p)
PointerFocusTarget::Popup(p)
}
}
impl From<CosmicMapped> for KeyboardFocusTarget {
fn from(w: CosmicMapped) -> Self {
KeyboardFocusTarget::Element(w)
}
}
impl From<Window> for KeyboardFocusTarget {
fn from(w: Window) -> Self {
KeyboardFocusTarget::Fullscreen(w)
}
}
impl From<WindowGroup> for KeyboardFocusTarget {
fn from(w: WindowGroup) -> Self {
KeyboardFocusTarget::Group(w)
}
}
impl From<LayerSurface> for KeyboardFocusTarget {
fn from(l: LayerSurface) -> Self {
KeyboardFocusTarget::LayerSurface(l)
}
}
impl From<PopupKind> for KeyboardFocusTarget {
fn from(p: PopupKind) -> Self {
KeyboardFocusTarget::Popup(p)
}
}