Add ext-session-lock protocol
This commit is contained in:
parent
7300e23ce8
commit
f0277eabae
7 changed files with 325 additions and 73 deletions
|
|
@ -8,6 +8,7 @@ use indexmap::IndexSet;
|
|||
use smithay::{
|
||||
desktop::{layer_map_for_output, PopupUngrabStrategy},
|
||||
input::Seat,
|
||||
output::Output,
|
||||
utils::{IsAlive, Serial, SERIAL_COUNTER},
|
||||
wayland::seat::WaylandFocus,
|
||||
};
|
||||
|
|
@ -217,55 +218,11 @@ impl Common {
|
|||
|
||||
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)
|
||||
&& workspace.get_fullscreen().is_none()
|
||||
{
|
||||
continue; // Focus is valid
|
||||
} else {
|
||||
trace!("Wrong Window, focus fixup");
|
||||
}
|
||||
}
|
||||
KeyboardFocusTarget::LayerSurface(layer) => {
|
||||
if layer_map_for_output(&output).layers().any(|l| l == &layer) {
|
||||
continue; // Focus is valid
|
||||
}
|
||||
}
|
||||
KeyboardFocusTarget::Group(WindowGroup { node, .. }) => {
|
||||
if state
|
||||
.common
|
||||
.shell
|
||||
.workspaces
|
||||
.active(&output)
|
||||
.1
|
||||
.tiling_layer
|
||||
.has_node(&node)
|
||||
{
|
||||
continue; // Focus is valid,
|
||||
}
|
||||
}
|
||||
KeyboardFocusTarget::Fullscreen(window) => {
|
||||
let workspace = state.common.shell.active_space(&output);
|
||||
let focus_stack = workspace.focus_stack.get(&seat);
|
||||
|
||||
if focus_stack
|
||||
.last()
|
||||
.map(|m| m.has_active_window(&window))
|
||||
.unwrap_or(false)
|
||||
&& workspace.get_fullscreen().is_some()
|
||||
{
|
||||
continue; // Focus is valid
|
||||
} else {
|
||||
trace!("Wrong Window, focus fixup");
|
||||
}
|
||||
}
|
||||
KeyboardFocusTarget::Popup(_) => {
|
||||
continue; // Focus is valid
|
||||
}
|
||||
};
|
||||
if focus_target_is_valid(state, &seat, &output, target) {
|
||||
continue; // Focus is valid
|
||||
} else {
|
||||
trace!("Wrong Window, focus fixup");
|
||||
}
|
||||
} else {
|
||||
if let KeyboardFocusTarget::Popup(_) = target {
|
||||
if let Some(popup_grab) = seat
|
||||
|
|
@ -319,24 +276,7 @@ impl Common {
|
|||
}
|
||||
|
||||
// update keyboard focus
|
||||
let target = state
|
||||
.common
|
||||
.shell
|
||||
.active_space(&output)
|
||||
.get_fullscreen()
|
||||
.cloned()
|
||||
.map(KeyboardFocusTarget::Fullscreen)
|
||||
.or_else(|| {
|
||||
state
|
||||
.common
|
||||
.shell
|
||||
.active_space(&output)
|
||||
.focus_stack
|
||||
.get(&seat)
|
||||
.last()
|
||||
.cloned()
|
||||
.map(KeyboardFocusTarget::from)
|
||||
});
|
||||
let target = update_focus_target(state, &seat, &output);
|
||||
if let Some(keyboard) = seat.get_keyboard() {
|
||||
debug!("Restoring focus to {:?}", target.as_ref());
|
||||
keyboard.set_focus(state, target.clone(), SERIAL_COUNTER.next_serial());
|
||||
|
|
@ -349,3 +289,72 @@ impl Common {
|
|||
state.common.shell.update_active(seats.iter())
|
||||
}
|
||||
}
|
||||
|
||||
fn focus_target_is_valid(
|
||||
state: &mut State,
|
||||
seat: &Seat<State>,
|
||||
output: &Output,
|
||||
target: KeyboardFocusTarget,
|
||||
) -> bool {
|
||||
if state.common.session_lock.is_some() {
|
||||
return matches!(target, KeyboardFocusTarget::LockSurface(_));
|
||||
}
|
||||
|
||||
match target {
|
||||
KeyboardFocusTarget::Element(mapped) => {
|
||||
let workspace = state.common.shell.active_space(&output);
|
||||
let focus_stack = workspace.focus_stack.get(&seat);
|
||||
focus_stack.last().map(|m| m == &mapped).unwrap_or(false)
|
||||
&& workspace.get_fullscreen().is_none()
|
||||
}
|
||||
KeyboardFocusTarget::LayerSurface(layer) => {
|
||||
layer_map_for_output(&output).layers().any(|l| l == &layer)
|
||||
}
|
||||
KeyboardFocusTarget::Group(WindowGroup { node, .. }) => state
|
||||
.common
|
||||
.shell
|
||||
.workspaces
|
||||
.active(&output)
|
||||
.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);
|
||||
|
||||
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(
|
||||
state: &mut State,
|
||||
seat: &Seat<State>,
|
||||
output: &Output,
|
||||
) -> Option<KeyboardFocusTarget> {
|
||||
if let Some(session_lock) = &state.common.session_lock {
|
||||
session_lock
|
||||
.surfaces
|
||||
.get(output)
|
||||
.cloned()
|
||||
.map(KeyboardFocusTarget::from)
|
||||
} else if let Some(surface) = state.common.shell.active_space(&output).get_fullscreen() {
|
||||
Some(KeyboardFocusTarget::Fullscreen(surface.clone()))
|
||||
} else {
|
||||
state
|
||||
.common
|
||||
.shell
|
||||
.active_space(&output)
|
||||
.focus_stack
|
||||
.get(&seat)
|
||||
.last()
|
||||
.cloned()
|
||||
.map(KeyboardFocusTarget::from)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ use smithay::{
|
|||
},
|
||||
reexports::wayland_server::{backend::ObjectId, protocol::wl_surface::WlSurface, Resource},
|
||||
utils::{IsAlive, Serial},
|
||||
wayland::seat::WaylandFocus,
|
||||
wayland::{seat::WaylandFocus, session_lock::LockSurface},
|
||||
xwayland::X11Surface,
|
||||
};
|
||||
|
||||
|
|
@ -33,6 +33,7 @@ pub enum PointerFocusTarget {
|
|||
Popup(PopupKind),
|
||||
OverrideRedirect(X11Surface),
|
||||
ResizeFork(ResizeForkTarget),
|
||||
LockSurface(LockSurface),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
|
|
@ -42,6 +43,7 @@ pub enum KeyboardFocusTarget {
|
|||
Group(WindowGroup),
|
||||
LayerSurface(LayerSurface),
|
||||
Popup(PopupKind),
|
||||
LockSurface(LockSurface),
|
||||
}
|
||||
|
||||
// TODO: This should be TryFrom, but PopupGrab needs to be able to convert. Fix this in smithay
|
||||
|
|
@ -52,6 +54,7 @@ impl From<KeyboardFocusTarget> for PointerFocusTarget {
|
|||
KeyboardFocusTarget::Fullscreen(elem) => PointerFocusTarget::Fullscreen(elem),
|
||||
KeyboardFocusTarget::LayerSurface(layer) => PointerFocusTarget::LayerSurface(layer),
|
||||
KeyboardFocusTarget::Popup(popup) => PointerFocusTarget::Popup(popup),
|
||||
KeyboardFocusTarget::LockSurface(lock) => PointerFocusTarget::LockSurface(lock),
|
||||
_ => unreachable!("A window grab cannot start a popup grab"),
|
||||
}
|
||||
}
|
||||
|
|
@ -65,6 +68,7 @@ impl TryFrom<PointerFocusTarget> for KeyboardFocusTarget {
|
|||
PointerFocusTarget::Fullscreen(surf) => Ok(KeyboardFocusTarget::Fullscreen(surf)),
|
||||
PointerFocusTarget::LayerSurface(layer) => Ok(KeyboardFocusTarget::LayerSurface(layer)),
|
||||
PointerFocusTarget::Popup(popup) => Ok(KeyboardFocusTarget::Popup(popup)),
|
||||
PointerFocusTarget::LockSurface(lock) => Ok(KeyboardFocusTarget::LockSurface(lock)),
|
||||
_ => Err(()),
|
||||
}
|
||||
}
|
||||
|
|
@ -102,6 +106,7 @@ impl IsAlive for PointerFocusTarget {
|
|||
PointerFocusTarget::Popup(p) => p.alive(),
|
||||
PointerFocusTarget::OverrideRedirect(s) => s.alive(),
|
||||
PointerFocusTarget::ResizeFork(f) => f.alive(),
|
||||
PointerFocusTarget::LockSurface(l) => l.alive(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -114,6 +119,7 @@ impl IsAlive for KeyboardFocusTarget {
|
|||
KeyboardFocusTarget::Group(g) => g.alive.upgrade().is_some(),
|
||||
KeyboardFocusTarget::LayerSurface(l) => l.alive(),
|
||||
KeyboardFocusTarget::Popup(p) => p.alive(),
|
||||
KeyboardFocusTarget::LockSurface(l) => l.alive(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -127,6 +133,9 @@ impl PointerTarget<State> for PointerFocusTarget {
|
|||
PointerFocusTarget::Popup(p) => PointerTarget::enter(p.wl_surface(), seat, data, event),
|
||||
PointerFocusTarget::OverrideRedirect(s) => PointerTarget::enter(s, seat, data, event),
|
||||
PointerFocusTarget::ResizeFork(f) => PointerTarget::enter(f, seat, data, event),
|
||||
PointerFocusTarget::LockSurface(l) => {
|
||||
PointerTarget::enter(l.wl_surface(), seat, data, event)
|
||||
}
|
||||
}
|
||||
}
|
||||
fn motion(&self, seat: &Seat<State>, data: &mut State, event: &MotionEvent) {
|
||||
|
|
@ -139,6 +148,9 @@ impl PointerTarget<State> for PointerFocusTarget {
|
|||
}
|
||||
PointerFocusTarget::OverrideRedirect(s) => PointerTarget::motion(s, seat, data, event),
|
||||
PointerFocusTarget::ResizeFork(f) => PointerTarget::motion(f, seat, data, event),
|
||||
PointerFocusTarget::LockSurface(l) => {
|
||||
PointerTarget::motion(l.wl_surface(), seat, data, event)
|
||||
}
|
||||
}
|
||||
}
|
||||
fn relative_motion(&self, seat: &Seat<State>, data: &mut State, event: &RelativeMotionEvent) {
|
||||
|
|
@ -159,6 +171,9 @@ impl PointerTarget<State> for PointerFocusTarget {
|
|||
PointerFocusTarget::ResizeFork(f) => {
|
||||
PointerTarget::relative_motion(f, seat, data, event)
|
||||
}
|
||||
PointerFocusTarget::LockSurface(l) => {
|
||||
PointerTarget::relative_motion(l.wl_surface(), seat, data, event)
|
||||
}
|
||||
}
|
||||
}
|
||||
fn button(&self, seat: &Seat<State>, data: &mut State, event: &ButtonEvent) {
|
||||
|
|
@ -171,6 +186,9 @@ impl PointerTarget<State> for PointerFocusTarget {
|
|||
}
|
||||
PointerFocusTarget::OverrideRedirect(s) => PointerTarget::button(s, seat, data, event),
|
||||
PointerFocusTarget::ResizeFork(f) => PointerTarget::button(f, seat, data, event),
|
||||
PointerFocusTarget::LockSurface(l) => {
|
||||
PointerTarget::button(l.wl_surface(), seat, data, event)
|
||||
}
|
||||
}
|
||||
}
|
||||
fn axis(&self, seat: &Seat<State>, data: &mut State, frame: AxisFrame) {
|
||||
|
|
@ -181,6 +199,9 @@ impl PointerTarget<State> for PointerFocusTarget {
|
|||
PointerFocusTarget::Popup(p) => PointerTarget::axis(p.wl_surface(), seat, data, frame),
|
||||
PointerFocusTarget::OverrideRedirect(s) => PointerTarget::axis(s, seat, data, frame),
|
||||
PointerFocusTarget::ResizeFork(f) => PointerTarget::axis(f, seat, data, frame),
|
||||
PointerFocusTarget::LockSurface(l) => {
|
||||
PointerTarget::axis(l.wl_surface(), seat, data, frame)
|
||||
}
|
||||
}
|
||||
}
|
||||
fn frame(&self, seat: &Seat<State>, data: &mut State) {
|
||||
|
|
@ -191,6 +212,7 @@ impl PointerTarget<State> for PointerFocusTarget {
|
|||
PointerFocusTarget::Popup(p) => PointerTarget::frame(p.wl_surface(), seat, data),
|
||||
PointerFocusTarget::OverrideRedirect(s) => PointerTarget::frame(s, seat, data),
|
||||
PointerFocusTarget::ResizeFork(f) => PointerTarget::frame(f, seat, data),
|
||||
PointerFocusTarget::LockSurface(l) => PointerTarget::frame(l.wl_surface(), seat, data),
|
||||
}
|
||||
}
|
||||
fn leave(&self, seat: &Seat<State>, data: &mut State, serial: Serial, time: u32) {
|
||||
|
|
@ -207,6 +229,9 @@ impl PointerTarget<State> for PointerFocusTarget {
|
|||
PointerTarget::leave(s, seat, data, serial, time)
|
||||
}
|
||||
PointerFocusTarget::ResizeFork(f) => PointerTarget::leave(f, seat, data, serial, time),
|
||||
PointerFocusTarget::LockSurface(l) => {
|
||||
PointerTarget::leave(l.wl_surface(), seat, data, serial, time)
|
||||
}
|
||||
}
|
||||
}
|
||||
fn gesture_swipe_begin(
|
||||
|
|
@ -234,6 +259,9 @@ impl PointerTarget<State> for PointerFocusTarget {
|
|||
PointerFocusTarget::ResizeFork(f) => {
|
||||
PointerTarget::gesture_swipe_begin(f, seat, data, event)
|
||||
}
|
||||
PointerFocusTarget::LockSurface(l) => {
|
||||
PointerTarget::gesture_swipe_begin(l.wl_surface(), seat, data, event)
|
||||
}
|
||||
}
|
||||
}
|
||||
fn gesture_swipe_update(
|
||||
|
|
@ -261,6 +289,9 @@ impl PointerTarget<State> for PointerFocusTarget {
|
|||
PointerFocusTarget::ResizeFork(f) => {
|
||||
PointerTarget::gesture_swipe_update(f, seat, data, event)
|
||||
}
|
||||
PointerFocusTarget::LockSurface(l) => {
|
||||
PointerTarget::gesture_swipe_update(l.wl_surface(), seat, data, event)
|
||||
}
|
||||
}
|
||||
}
|
||||
fn gesture_swipe_end(
|
||||
|
|
@ -288,6 +319,9 @@ impl PointerTarget<State> for PointerFocusTarget {
|
|||
PointerFocusTarget::ResizeFork(f) => {
|
||||
PointerTarget::gesture_swipe_end(f, seat, data, event)
|
||||
}
|
||||
PointerFocusTarget::LockSurface(l) => {
|
||||
PointerTarget::gesture_swipe_end(l.wl_surface(), seat, data, event)
|
||||
}
|
||||
}
|
||||
}
|
||||
fn gesture_pinch_begin(
|
||||
|
|
@ -315,6 +349,9 @@ impl PointerTarget<State> for PointerFocusTarget {
|
|||
PointerFocusTarget::ResizeFork(f) => {
|
||||
PointerTarget::gesture_pinch_begin(f, seat, data, event)
|
||||
}
|
||||
PointerFocusTarget::LockSurface(l) => {
|
||||
PointerTarget::gesture_pinch_begin(l.wl_surface(), seat, data, event)
|
||||
}
|
||||
}
|
||||
}
|
||||
fn gesture_pinch_update(
|
||||
|
|
@ -342,6 +379,9 @@ impl PointerTarget<State> for PointerFocusTarget {
|
|||
PointerFocusTarget::ResizeFork(f) => {
|
||||
PointerTarget::gesture_pinch_update(f, seat, data, event)
|
||||
}
|
||||
PointerFocusTarget::LockSurface(l) => {
|
||||
PointerTarget::gesture_pinch_update(l.wl_surface(), seat, data, event)
|
||||
}
|
||||
}
|
||||
}
|
||||
fn gesture_pinch_end(
|
||||
|
|
@ -369,6 +409,9 @@ impl PointerTarget<State> for PointerFocusTarget {
|
|||
PointerFocusTarget::ResizeFork(f) => {
|
||||
PointerTarget::gesture_pinch_end(f, seat, data, event)
|
||||
}
|
||||
PointerFocusTarget::LockSurface(l) => {
|
||||
PointerTarget::gesture_pinch_end(l.wl_surface(), seat, data, event)
|
||||
}
|
||||
}
|
||||
}
|
||||
fn gesture_hold_begin(
|
||||
|
|
@ -396,6 +439,9 @@ impl PointerTarget<State> for PointerFocusTarget {
|
|||
PointerFocusTarget::ResizeFork(f) => {
|
||||
PointerTarget::gesture_hold_begin(f, seat, data, event)
|
||||
}
|
||||
PointerFocusTarget::LockSurface(l) => {
|
||||
PointerTarget::gesture_hold_begin(l.wl_surface(), seat, data, event)
|
||||
}
|
||||
}
|
||||
}
|
||||
fn gesture_hold_end(&self, seat: &Seat<State>, data: &mut State, event: &GestureHoldEndEvent) {
|
||||
|
|
@ -416,6 +462,9 @@ impl PointerTarget<State> for PointerFocusTarget {
|
|||
PointerFocusTarget::ResizeFork(f) => {
|
||||
PointerTarget::gesture_hold_end(f, seat, data, event)
|
||||
}
|
||||
PointerFocusTarget::LockSurface(l) => {
|
||||
PointerTarget::gesture_hold_end(l.wl_surface(), seat, data, event)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -440,6 +489,9 @@ impl KeyboardTarget<State> for KeyboardFocusTarget {
|
|||
KeyboardFocusTarget::Popup(p) => {
|
||||
KeyboardTarget::enter(p.wl_surface(), seat, data, keys, serial)
|
||||
}
|
||||
KeyboardFocusTarget::LockSurface(l) => {
|
||||
KeyboardTarget::enter(l.wl_surface(), seat, data, keys, serial)
|
||||
}
|
||||
}
|
||||
}
|
||||
fn leave(&self, seat: &Seat<State>, data: &mut State, serial: Serial) {
|
||||
|
|
@ -451,6 +503,9 @@ impl KeyboardTarget<State> for KeyboardFocusTarget {
|
|||
KeyboardFocusTarget::Popup(p) => {
|
||||
KeyboardTarget::leave(p.wl_surface(), seat, data, serial)
|
||||
}
|
||||
KeyboardFocusTarget::LockSurface(l) => {
|
||||
KeyboardTarget::leave(l.wl_surface(), seat, data, serial)
|
||||
}
|
||||
}
|
||||
}
|
||||
fn key(
|
||||
|
|
@ -476,6 +531,9 @@ impl KeyboardTarget<State> for KeyboardFocusTarget {
|
|||
KeyboardFocusTarget::Popup(p) => {
|
||||
KeyboardTarget::key(p.wl_surface(), seat, data, key, state, serial, time)
|
||||
}
|
||||
KeyboardFocusTarget::LockSurface(l) => {
|
||||
KeyboardTarget::key(l.wl_surface(), seat, data, key, state, serial, time)
|
||||
}
|
||||
}
|
||||
}
|
||||
fn modifiers(
|
||||
|
|
@ -499,6 +557,9 @@ impl KeyboardTarget<State> for KeyboardFocusTarget {
|
|||
KeyboardFocusTarget::Popup(p) => {
|
||||
KeyboardTarget::modifiers(p.wl_surface(), seat, data, modifiers, serial)
|
||||
}
|
||||
KeyboardFocusTarget::LockSurface(l) => {
|
||||
KeyboardTarget::modifiers(l.wl_surface(), seat, data, modifiers, serial)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -511,6 +572,7 @@ impl WaylandFocus for KeyboardFocusTarget {
|
|||
KeyboardFocusTarget::Group(_) => None,
|
||||
KeyboardFocusTarget::LayerSurface(l) => Some(l.wl_surface().clone()),
|
||||
KeyboardFocusTarget::Popup(p) => Some(p.wl_surface().clone()),
|
||||
KeyboardFocusTarget::LockSurface(l) => Some(l.wl_surface().clone()),
|
||||
}
|
||||
}
|
||||
fn same_client_as(&self, object_id: &ObjectId) -> bool {
|
||||
|
|
@ -520,6 +582,7 @@ impl WaylandFocus for KeyboardFocusTarget {
|
|||
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),
|
||||
KeyboardFocusTarget::LockSurface(l) => l.wl_surface().id().same_client_as(object_id),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -537,6 +600,7 @@ impl WaylandFocus for PointerFocusTarget {
|
|||
PointerFocusTarget::ResizeFork(_) => {
|
||||
return None;
|
||||
}
|
||||
PointerFocusTarget::LockSurface(l) => l.wl_surface().clone(),
|
||||
})
|
||||
}
|
||||
fn same_client_as(&self, object_id: &ObjectId) -> bool {
|
||||
|
|
@ -547,6 +611,7 @@ impl WaylandFocus for PointerFocusTarget {
|
|||
PointerFocusTarget::Popup(p) => p.wl_surface().id().same_client_as(object_id),
|
||||
PointerFocusTarget::OverrideRedirect(s) => WaylandFocus::same_client_as(s, object_id),
|
||||
PointerFocusTarget::ResizeFork(_) => false,
|
||||
PointerFocusTarget::LockSurface(l) => l.wl_surface().id().same_client_as(object_id),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -587,6 +652,12 @@ impl From<ResizeForkTarget> for PointerFocusTarget {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<LockSurface> for PointerFocusTarget {
|
||||
fn from(l: LockSurface) -> Self {
|
||||
PointerFocusTarget::LockSurface(l)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<CosmicMapped> for KeyboardFocusTarget {
|
||||
fn from(w: CosmicMapped) -> Self {
|
||||
KeyboardFocusTarget::Element(w)
|
||||
|
|
@ -616,3 +687,9 @@ impl From<PopupKind> for KeyboardFocusTarget {
|
|||
KeyboardFocusTarget::Popup(p)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<LockSurface> for KeyboardFocusTarget {
|
||||
fn from(l: LockSurface) -> Self {
|
||||
KeyboardFocusTarget::LockSurface(l)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue