2022-09-28 12:01:29 +02:00
|
|
|
use std::sync::Weak;
|
|
|
|
|
|
|
|
|
|
use crate::{shell::element::CosmicMapped, utils::prelude::*};
|
|
|
|
|
use id_tree::NodeId;
|
|
|
|
|
use smithay::{
|
2022-09-22 18:15:05 +02:00
|
|
|
backend::input::KeyState,
|
|
|
|
|
desktop::{LayerSurface, PopupKind, Window},
|
|
|
|
|
input::{
|
|
|
|
|
keyboard::{KeyboardTarget, KeysymHandle, ModifiersState},
|
|
|
|
|
pointer::{AxisFrame, ButtonEvent, MotionEvent, PointerTarget},
|
|
|
|
|
Seat,
|
|
|
|
|
},
|
2022-09-28 12:01:29 +02:00
|
|
|
output::WeakOutput,
|
2022-09-22 18:15:05 +02:00
|
|
|
reexports::wayland_server::{backend::ObjectId, protocol::wl_surface::WlSurface, Resource},
|
|
|
|
|
utils::{IsAlive, Serial},
|
|
|
|
|
wayland::seat::WaylandFocus,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, PartialEq)]
|
2022-09-28 12:01:29 +02:00
|
|
|
pub enum PointerFocusTarget {
|
|
|
|
|
Element(CosmicMapped),
|
|
|
|
|
Fullscreen(Window),
|
|
|
|
|
LayerSurface(LayerSurface),
|
|
|
|
|
Popup(PopupKind),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, PartialEq)]
|
|
|
|
|
pub enum KeyboardFocusTarget {
|
|
|
|
|
Element(CosmicMapped),
|
|
|
|
|
Fullscreen(Window),
|
|
|
|
|
Group(WindowGroup),
|
2022-09-22 18:15:05 +02:00
|
|
|
LayerSurface(LayerSurface),
|
|
|
|
|
Popup(PopupKind),
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-28 12:01:29 +02:00
|
|
|
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"),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[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 {
|
2022-09-22 18:15:05 +02:00
|
|
|
fn alive(&self) -> bool {
|
|
|
|
|
match self {
|
2022-09-28 12:01:29 +02:00
|
|
|
PointerFocusTarget::Element(e) => e.alive(),
|
|
|
|
|
PointerFocusTarget::Fullscreen(f) => f.alive(),
|
|
|
|
|
PointerFocusTarget::LayerSurface(l) => l.alive(),
|
|
|
|
|
PointerFocusTarget::Popup(p) => p.alive(),
|
2022-09-22 18:15:05 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-28 12:01:29 +02:00
|
|
|
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 {
|
2022-09-22 18:15:05 +02:00
|
|
|
fn enter(&self, seat: &Seat<State>, data: &mut State, event: &MotionEvent) {
|
|
|
|
|
match self {
|
2022-09-28 12:01:29 +02:00
|
|
|
PointerFocusTarget::Element(w) => PointerTarget::enter(w, seat, data, event),
|
|
|
|
|
PointerFocusTarget::Fullscreen(w) => PointerTarget::enter(w, seat, data, event),
|
2022-11-21 10:09:32 +01:00
|
|
|
PointerFocusTarget::LayerSurface(l) => PointerTarget::enter(l, seat, data, event),
|
2022-09-28 12:01:29 +02:00
|
|
|
PointerFocusTarget::Popup(p) => PointerTarget::enter(p.wl_surface(), seat, data, event),
|
2022-09-22 18:15:05 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fn motion(&self, seat: &Seat<State>, data: &mut State, event: &MotionEvent) {
|
|
|
|
|
match self {
|
2022-09-28 12:01:29 +02:00
|
|
|
PointerFocusTarget::Element(w) => PointerTarget::motion(w, seat, data, event),
|
|
|
|
|
PointerFocusTarget::Fullscreen(w) => PointerTarget::motion(w, seat, data, event),
|
2022-11-21 10:09:32 +01:00
|
|
|
PointerFocusTarget::LayerSurface(l) => PointerTarget::motion(l, seat, data, event),
|
2022-09-28 12:01:29 +02:00
|
|
|
PointerFocusTarget::Popup(p) => {
|
|
|
|
|
PointerTarget::motion(p.wl_surface(), seat, data, event)
|
|
|
|
|
}
|
2022-09-22 18:15:05 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fn button(&self, seat: &Seat<State>, data: &mut State, event: &ButtonEvent) {
|
|
|
|
|
match self {
|
2022-09-28 12:01:29 +02:00
|
|
|
PointerFocusTarget::Element(w) => PointerTarget::button(w, seat, data, event),
|
|
|
|
|
PointerFocusTarget::Fullscreen(w) => PointerTarget::button(w, seat, data, event),
|
2022-11-21 10:09:32 +01:00
|
|
|
PointerFocusTarget::LayerSurface(l) => PointerTarget::button(l, seat, data, event),
|
2022-09-28 12:01:29 +02:00
|
|
|
PointerFocusTarget::Popup(p) => {
|
|
|
|
|
PointerTarget::button(p.wl_surface(), seat, data, event)
|
|
|
|
|
}
|
2022-09-22 18:15:05 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fn axis(&self, seat: &Seat<State>, data: &mut State, frame: AxisFrame) {
|
|
|
|
|
match self {
|
2022-09-28 12:01:29 +02:00
|
|
|
PointerFocusTarget::Element(w) => PointerTarget::axis(w, seat, data, frame),
|
|
|
|
|
PointerFocusTarget::Fullscreen(w) => PointerTarget::axis(w, seat, data, frame),
|
2022-11-21 10:09:32 +01:00
|
|
|
PointerFocusTarget::LayerSurface(l) => PointerTarget::axis(l, seat, data, frame),
|
2022-09-28 12:01:29 +02:00
|
|
|
PointerFocusTarget::Popup(p) => PointerTarget::axis(p.wl_surface(), seat, data, frame),
|
2022-09-22 18:15:05 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fn leave(&self, seat: &Seat<State>, data: &mut State, serial: Serial, time: u32) {
|
|
|
|
|
match self {
|
2022-09-28 12:01:29 +02:00
|
|
|
PointerFocusTarget::Element(w) => PointerTarget::leave(w, seat, data, serial, time),
|
|
|
|
|
PointerFocusTarget::Fullscreen(w) => PointerTarget::leave(w, seat, data, serial, time),
|
|
|
|
|
PointerFocusTarget::LayerSurface(l) => {
|
2022-11-21 10:09:32 +01:00
|
|
|
PointerTarget::leave(l, seat, data, serial, time)
|
2022-09-22 18:15:05 +02:00
|
|
|
}
|
2022-09-28 12:01:29 +02:00
|
|
|
PointerFocusTarget::Popup(p) => {
|
|
|
|
|
PointerTarget::leave(p.wl_surface(), seat, data, serial, time)
|
|
|
|
|
}
|
2022-09-22 18:15:05 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-28 12:01:29 +02:00
|
|
|
impl KeyboardTarget<State> for KeyboardFocusTarget {
|
2022-09-22 18:15:05 +02:00
|
|
|
fn enter(
|
|
|
|
|
&self,
|
|
|
|
|
seat: &Seat<State>,
|
|
|
|
|
data: &mut State,
|
|
|
|
|
keys: Vec<KeysymHandle<'_>>,
|
|
|
|
|
serial: Serial,
|
|
|
|
|
) {
|
|
|
|
|
match self {
|
2022-09-28 12:01:29 +02:00
|
|
|
KeyboardFocusTarget::Element(w) => KeyboardTarget::enter(w, seat, data, keys, serial),
|
|
|
|
|
KeyboardFocusTarget::Fullscreen(w) => {
|
|
|
|
|
KeyboardTarget::enter(w, seat, data, keys, serial)
|
2022-09-22 18:15:05 +02:00
|
|
|
}
|
2022-09-28 12:01:29 +02:00
|
|
|
KeyboardFocusTarget::Group(_) => {}
|
|
|
|
|
KeyboardFocusTarget::LayerSurface(l) => {
|
2022-11-21 10:09:32 +01:00
|
|
|
KeyboardTarget::enter(l, seat, data, keys, serial)
|
2022-09-22 18:15:05 +02:00
|
|
|
}
|
2022-09-28 12:01:29 +02:00
|
|
|
KeyboardFocusTarget::Popup(p) => {
|
2022-09-22 18:15:05 +02:00
|
|
|
KeyboardTarget::enter(p.wl_surface(), seat, data, keys, serial)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fn leave(&self, seat: &Seat<State>, data: &mut State, serial: Serial) {
|
|
|
|
|
match self {
|
2022-09-28 12:01:29 +02:00
|
|
|
KeyboardFocusTarget::Element(w) => KeyboardTarget::leave(w, seat, data, serial),
|
|
|
|
|
KeyboardFocusTarget::Fullscreen(w) => KeyboardTarget::leave(w, seat, data, serial),
|
|
|
|
|
KeyboardFocusTarget::Group(_) => {}
|
2022-11-21 10:09:32 +01:00
|
|
|
KeyboardFocusTarget::LayerSurface(l) => KeyboardTarget::leave(l, seat, data, serial),
|
2022-09-28 12:01:29 +02:00
|
|
|
KeyboardFocusTarget::Popup(p) => {
|
|
|
|
|
KeyboardTarget::leave(p.wl_surface(), seat, data, serial)
|
|
|
|
|
}
|
2022-09-22 18:15:05 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fn key(
|
|
|
|
|
&self,
|
|
|
|
|
seat: &Seat<State>,
|
|
|
|
|
data: &mut State,
|
|
|
|
|
key: KeysymHandle<'_>,
|
|
|
|
|
state: KeyState,
|
|
|
|
|
serial: Serial,
|
|
|
|
|
time: u32,
|
|
|
|
|
) {
|
|
|
|
|
match self {
|
2022-09-28 12:01:29 +02:00
|
|
|
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) => {
|
2022-11-21 10:09:32 +01:00
|
|
|
KeyboardTarget::key(l, seat, data, key, state, serial, time)
|
2022-09-22 18:15:05 +02:00
|
|
|
}
|
2022-09-28 12:01:29 +02:00
|
|
|
KeyboardFocusTarget::Popup(p) => {
|
2022-09-22 18:15:05 +02:00
|
|
|
KeyboardTarget::key(p.wl_surface(), seat, data, key, state, serial, time)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fn modifiers(
|
|
|
|
|
&self,
|
|
|
|
|
seat: &Seat<State>,
|
|
|
|
|
data: &mut State,
|
|
|
|
|
modifiers: ModifiersState,
|
|
|
|
|
serial: Serial,
|
|
|
|
|
) {
|
|
|
|
|
match self {
|
2022-09-28 12:01:29 +02:00
|
|
|
KeyboardFocusTarget::Element(w) => {
|
|
|
|
|
KeyboardTarget::modifiers(w, seat, data, modifiers, serial)
|
2022-09-22 18:15:05 +02:00
|
|
|
}
|
2022-09-28 12:01:29 +02:00
|
|
|
KeyboardFocusTarget::Fullscreen(w) => {
|
|
|
|
|
KeyboardTarget::modifiers(w, seat, data, modifiers, serial)
|
|
|
|
|
}
|
|
|
|
|
KeyboardFocusTarget::Group(_) => {}
|
|
|
|
|
KeyboardFocusTarget::LayerSurface(l) => {
|
2022-11-21 10:09:32 +01:00
|
|
|
KeyboardTarget::modifiers(l, seat, data, modifiers, serial)
|
2022-09-22 18:15:05 +02:00
|
|
|
}
|
2022-09-28 12:01:29 +02:00
|
|
|
KeyboardFocusTarget::Popup(p) => {
|
2022-09-22 18:15:05 +02:00
|
|
|
KeyboardTarget::modifiers(p.wl_surface(), seat, data, modifiers, serial)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-28 12:01:29 +02:00
|
|
|
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 {
|
|
|
|
|
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 WaylandFocus for PointerFocusTarget {
|
|
|
|
|
fn wl_surface(&self) -> Option<WlSurface> {
|
2022-09-22 18:15:05 +02:00
|
|
|
Some(match self {
|
2022-09-28 12:01:29 +02:00
|
|
|
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(),
|
2022-09-22 18:15:05 +02:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
fn same_client_as(&self, object_id: &ObjectId) -> bool {
|
|
|
|
|
match self {
|
2022-09-28 12:01:29 +02:00
|
|
|
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),
|
2022-09-22 18:15:05 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-28 12:01:29 +02:00
|
|
|
impl From<CosmicMapped> for PointerFocusTarget {
|
|
|
|
|
fn from(w: CosmicMapped) -> Self {
|
|
|
|
|
PointerFocusTarget::Element(w)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl From<Window> for PointerFocusTarget {
|
2022-09-22 18:15:05 +02:00
|
|
|
fn from(w: Window) -> Self {
|
2022-09-28 12:01:29 +02:00
|
|
|
PointerFocusTarget::Fullscreen(w)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl From<LayerSurface> for PointerFocusTarget {
|
|
|
|
|
fn from(l: LayerSurface) -> Self {
|
|
|
|
|
PointerFocusTarget::LayerSurface(l)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl From<PopupKind> for PointerFocusTarget {
|
|
|
|
|
fn from(p: PopupKind) -> Self {
|
|
|
|
|
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)
|
2022-09-22 18:15:05 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-28 12:01:29 +02:00
|
|
|
impl From<LayerSurface> for KeyboardFocusTarget {
|
2022-09-22 18:15:05 +02:00
|
|
|
fn from(l: LayerSurface) -> Self {
|
2022-09-28 12:01:29 +02:00
|
|
|
KeyboardFocusTarget::LayerSurface(l)
|
2022-09-22 18:15:05 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-28 12:01:29 +02:00
|
|
|
impl From<PopupKind> for KeyboardFocusTarget {
|
2022-09-22 18:15:05 +02:00
|
|
|
fn from(p: PopupKind) -> Self {
|
2022-09-28 12:01:29 +02:00
|
|
|
KeyboardFocusTarget::Popup(p)
|
2022-09-22 18:15:05 +02:00
|
|
|
}
|
|
|
|
|
}
|