feat: route input to layer shell surfaces
This commit is contained in:
1 parent
41e493728c
commit
f2ef8de74f
3 files changed
+107
-4
No files matched your search
@@ -5,7 +5,9 @@ use smithay::{
|
|||||||
output::Output,
|
output::Output,
|
||||||
reexports::wayland_server::protocol::{wl_output::WlOutput, wl_surface::WlSurface},
|
reexports::wayland_server::protocol::{wl_output::WlOutput, wl_surface::WlSurface},
|
||||||
wayland::shell::{
|
wayland::shell::{
|
||||||
wlr_layer::{Layer, LayerSurface, WlrLayerShellHandler, WlrLayerShellState},
|
wlr_layer::{
|
||||||
|
KeyboardInteractivity, Layer, LayerSurface, WlrLayerShellHandler, WlrLayerShellState,
|
||||||
|
},
|
||||||
xdg::PopupSurface,
|
xdg::PopupSurface,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -57,6 +59,7 @@ impl WlrLayerShellHandler for Ferese {
|
|||||||
else {
|
else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
let restore_focus = layer_has_keyboard_focus(self, &layer);
|
||||||
let outputs = self.space.outputs().cloned().collect::<Vec<_>>();
|
let outputs = self.space.outputs().cloned().collect::<Vec<_>>();
|
||||||
|
|
||||||
for output in outputs {
|
for output in outputs {
|
||||||
@@ -64,6 +67,9 @@ impl WlrLayerShellHandler for Ferese {
|
|||||||
}
|
}
|
||||||
|
|
||||||
self.relayout();
|
self.relayout();
|
||||||
|
if restore_focus {
|
||||||
|
self.restore_keyboard_focus();
|
||||||
|
}
|
||||||
crate::backends::direct::render_all(self);
|
crate::backends::direct::render_all(self);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -86,5 +92,35 @@ pub fn handle_commit(state: &mut Ferese, surface: &WlSurface) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let policy = layer.cached_state();
|
||||||
|
if policy.keyboard_interactivity == KeyboardInteractivity::Exclusive
|
||||||
|
&& matches!(policy.layer, Layer::Top | Layer::Overlay)
|
||||||
|
{
|
||||||
|
state
|
||||||
|
.seat
|
||||||
|
.get_keyboard()
|
||||||
|
.expect("seat has a keyboard")
|
||||||
|
.set_focus(
|
||||||
|
state,
|
||||||
|
Some(layer.wl_surface().clone()),
|
||||||
|
smithay::utils::SERIAL_COUNTER.next_serial(),
|
||||||
|
);
|
||||||
|
} else if !layer.can_receive_keyboard_focus() && layer_has_keyboard_focus(state, &layer) {
|
||||||
|
state.restore_keyboard_focus();
|
||||||
|
}
|
||||||
|
|
||||||
state.relayout();
|
state.relayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn layer_has_keyboard_focus(state: &Ferese, layer: &DesktopLayerSurface) -> bool {
|
||||||
|
state
|
||||||
|
.seat
|
||||||
|
.get_keyboard()
|
||||||
|
.and_then(|keyboard| keyboard.current_focus())
|
||||||
|
.and_then(|surface| {
|
||||||
|
state
|
||||||
|
.space
|
||||||
|
.layer_for_surface(&surface, WindowSurfaceType::ALL)
|
||||||
|
})
|
||||||
|
.is_some_and(|focused| focused == *layer)
|
||||||
|
}
|
||||||
@@ -247,8 +247,16 @@ impl Ferese {
|
|||||||
fn focus_window_under_pointer(&mut self, serial: Serial) {
|
fn focus_window_under_pointer(&mut self, serial: Serial) {
|
||||||
let pointer = self.seat.get_pointer().expect("seat has a pointer");
|
let pointer = self.seat.get_pointer().expect("seat has a pointer");
|
||||||
let keyboard = self.seat.get_keyboard().expect("seat has a keyboard");
|
let keyboard = self.seat.get_keyboard().expect("seat has a keyboard");
|
||||||
|
let position = pointer.current_location();
|
||||||
|
|
||||||
if let Some(window) = self.window_under_visual(pointer.current_location()) {
|
if let Some((layer, _, _)) = self.layer_under(position) {
|
||||||
|
if layer.can_receive_keyboard_focus() {
|
||||||
|
keyboard.set_focus(self, Some(layer.wl_surface().clone()), serial);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(window) = self.window_under_visual(position) {
|
||||||
self.focused_window = self.window_ids.get(&window).copied();
|
self.focused_window = self.window_ids.get(&window).copied();
|
||||||
if let Some(focused) = self.focused_window
|
if let Some(focused) = self.focused_window
|
||||||
&& let Err(error) = self.workspaces.focus_window(focused)
|
&& let Err(error) = self.workspaces.focus_window(focused)
|
||||||
|
|||||||
+61
-2
@@ -12,7 +12,10 @@ use ferese_layout::{Axis, Direction, GapConfig, LayoutResult, Rect, SizeConstrai
|
|||||||
|
|
||||||
use smithay::{
|
use smithay::{
|
||||||
backend::drm::DrmEventTime,
|
backend::drm::DrmEventTime,
|
||||||
desktop::{PopupManager, Space, Window, WindowSurfaceType, utils::send_frames_surface_tree},
|
desktop::{
|
||||||
|
LayerSurface, PopupManager, Space, Window, WindowSurfaceType, layer_map_for_output,
|
||||||
|
utils::send_frames_surface_tree,
|
||||||
|
},
|
||||||
input::{Seat, SeatState, pointer::CursorImageStatus},
|
input::{Seat, SeatState, pointer::CursorImageStatus},
|
||||||
output::Output,
|
output::Output,
|
||||||
reexports::{
|
reexports::{
|
||||||
@@ -33,6 +36,7 @@ use smithay::{
|
|||||||
presentation::PresentationState,
|
presentation::PresentationState,
|
||||||
relative_pointer::RelativePointerManagerState,
|
relative_pointer::RelativePointerManagerState,
|
||||||
selection::{data_device::DataDeviceState, primary_selection::PrimarySelectionState},
|
selection::{data_device::DataDeviceState, primary_selection::PrimarySelectionState},
|
||||||
|
shell::wlr_layer::Layer,
|
||||||
shell::wlr_layer::WlrLayerShellState,
|
shell::wlr_layer::WlrLayerShellState,
|
||||||
shell::xdg::decoration::XdgDecorationState,
|
shell::xdg::decoration::XdgDecorationState,
|
||||||
shell::xdg::{SurfaceCachedState, XdgShellState},
|
shell::xdg::{SurfaceCachedState, XdgShellState},
|
||||||
@@ -171,6 +175,33 @@ impl Ferese {
|
|||||||
pub fn surface_under(
|
pub fn surface_under(
|
||||||
&self,
|
&self,
|
||||||
position: Point<f64, Logical>,
|
position: Point<f64, Logical>,
|
||||||
|
) -> Option<(WlSurface, Point<f64, Logical>)> {
|
||||||
|
self.layer_surface_under(position, &[Layer::Overlay, Layer::Top])
|
||||||
|
.map(|(_, surface, origin)| (surface, origin))
|
||||||
|
.or_else(|| self.window_surface_under(position))
|
||||||
|
.or_else(|| {
|
||||||
|
self.layer_surface_under(position, &[Layer::Bottom, Layer::Background])
|
||||||
|
.map(|(_, surface, origin)| (surface, origin))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn layer_under(
|
||||||
|
&self,
|
||||||
|
position: Point<f64, Logical>,
|
||||||
|
) -> Option<(LayerSurface, WlSurface, Point<f64, Logical>)> {
|
||||||
|
if let Some(layer) = self.layer_surface_under(position, &[Layer::Overlay, Layer::Top]) {
|
||||||
|
return Some(layer);
|
||||||
|
}
|
||||||
|
if self.window_surface_under(position).is_some() {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.layer_surface_under(position, &[Layer::Bottom, Layer::Background])
|
||||||
|
}
|
||||||
|
|
||||||
|
fn window_surface_under(
|
||||||
|
&self,
|
||||||
|
position: Point<f64, Logical>,
|
||||||
) -> Option<(WlSurface, Point<f64, Logical>)> {
|
) -> Option<(WlSurface, Point<f64, Logical>)> {
|
||||||
self.space.elements().rev().find_map(|window| {
|
self.space.elements().rev().find_map(|window| {
|
||||||
let id = self.window_ids.get(window)?;
|
let id = self.window_ids.get(window)?;
|
||||||
@@ -196,6 +227,34 @@ impl Ferese {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn layer_surface_under(
|
||||||
|
&self,
|
||||||
|
position: Point<f64, Logical>,
|
||||||
|
layers: &[Layer],
|
||||||
|
) -> Option<(LayerSurface, WlSurface, Point<f64, Logical>)> {
|
||||||
|
let output = self.space.output_under(position).next()?;
|
||||||
|
let output_geometry = self.space.output_geometry(output)?;
|
||||||
|
let output_position = position - output_geometry.loc.to_f64();
|
||||||
|
let map = layer_map_for_output(output);
|
||||||
|
|
||||||
|
for requested in layers {
|
||||||
|
for layer in map.layers_on(*requested).rev() {
|
||||||
|
let geometry = map.layer_geometry(layer)?;
|
||||||
|
let layer_position = output_position - geometry.loc.to_f64();
|
||||||
|
let Some((surface, surface_location)) =
|
||||||
|
layer.surface_under(layer_position, WindowSurfaceType::ALL)
|
||||||
|
else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
let origin = output_geometry.loc + geometry.loc + surface_location;
|
||||||
|
|
||||||
|
return Some((layer.clone(), surface, origin.to_f64()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
pub fn send_cursor_frame(&self, output: &Output) {
|
pub fn send_cursor_frame(&self, output: &Output) {
|
||||||
let CursorImageStatus::Surface(surface) = &self.cursor_status else {
|
let CursorImageStatus::Surface(surface) = &self.cursor_status else {
|
||||||
return;
|
return;
|
||||||
@@ -694,7 +753,7 @@ impl Ferese {
|
|||||||
self.restore_keyboard_focus();
|
self.restore_keyboard_focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn restore_keyboard_focus(&mut self) {
|
pub(crate) fn restore_keyboard_focus(&mut self) {
|
||||||
let surface = self.focused_window.and_then(|focused| {
|
let surface = self.focused_window.and_then(|focused| {
|
||||||
self.window_ids.iter().find_map(|(window, id)| {
|
self.window_ids.iter().find_map(|(window, id)| {
|
||||||
(*id == focused)
|
(*id == focused)
|
||||||
|
|||||||
Reference in new issue
Block a user