sf-compositor: the protocols gamescope needs, so Steam can start
gamescope (which hosts the Steam client) refuses to run nested without
wp_presentation, zwp_relative_pointer_manager_v1 and
zwp_pointer_constraints_v1 ("Couldn't create Wayland objects"), so Steam
quit right away.
- presentation-time with real feedback: on DRM with the page flip's
kernel timestamp and sequence, on winit when the frame is submitted;
- relative pointer and pointer constraints (the seat gets a wl_pointer;
no pointer device is attached, the cursor theme is blank).
Tested in the install VM: gamescope now gets past the Wayland setup; it
stops later only because the VM has no hardware Vulkan (llvmpipe lacks
VK_EXT_physical_device_drm). YouTube (Chromium, which uses presentation
feedback too) still renders and takes input.
Shell 0.3.1.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
//! Compositor state: Wayland protocol handlers, which window is visible,
|
||||
//! the switch animation, the volume OSD and the render element list.
|
||||
//!
|
||||
//! Besides what a kiosk needs, it offers what nested compositors need:
|
||||
//! gamescope (which hosts Steam) refuses to start without presentation-time,
|
||||
//! relative pointer and pointer constraints (and dmabuf, viewporter).
|
||||
|
||||
use std::ffi::OsString;
|
||||
use std::io::Write;
|
||||
@@ -16,25 +20,31 @@ use smithay::backend::renderer::gles::GlesRenderer;
|
||||
use smithay::backend::renderer::utils::on_commit_buffer_handler;
|
||||
use smithay::backend::session::Session;
|
||||
use smithay::backend::session::libseat::LibSeatSession;
|
||||
use smithay::desktop::utils::OutputPresentationFeedback;
|
||||
use smithay::desktop::{PopupKind, PopupManager, Space, Window, find_popup_root_surface, get_popup_toplevel_coords};
|
||||
use smithay::input::keyboard::{FilterResult, XkbConfig, keysyms};
|
||||
use smithay::input::pointer::PointerHandle;
|
||||
use smithay::input::{Seat, SeatHandler, SeatState};
|
||||
use smithay::output::Output;
|
||||
use smithay::reexports::calloop::generic::Generic;
|
||||
use smithay::reexports::calloop::timer::{TimeoutAction, Timer};
|
||||
use smithay::reexports::calloop::{EventLoop, Interest, LoopHandle, LoopSignal, Mode, PostAction};
|
||||
use smithay::reexports::wayland_protocols::wp::presentation_time::server::wp_presentation_feedback;
|
||||
use smithay::reexports::wayland_protocols::xdg::decoration::zv1::server::zxdg_toplevel_decoration_v1;
|
||||
use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel;
|
||||
use smithay::reexports::wayland_server::backend::{ClientData, ClientId, DisconnectReason};
|
||||
use smithay::reexports::wayland_server::protocol::{wl_buffer, wl_output, wl_seat, wl_surface::WlSurface};
|
||||
use smithay::reexports::wayland_server::{Client, Display, DisplayHandle, Resource};
|
||||
use smithay::utils::{IsAlive, Logical, Physical, Point, Rectangle, SERIAL_COUNTER, Scale, Serial, Size};
|
||||
use smithay::utils::{Clock, IsAlive, Logical, Monotonic, Physical, Point, Rectangle, SERIAL_COUNTER, Scale, Serial, Size};
|
||||
use smithay::wayland::buffer::BufferHandler;
|
||||
use smithay::wayland::compositor::{
|
||||
CompositorClientState, CompositorHandler, CompositorState, get_parent, is_sync_subsurface, with_states,
|
||||
};
|
||||
use smithay::wayland::dmabuf::{DmabufGlobal, DmabufHandler, DmabufState, ImportNotifier};
|
||||
use smithay::wayland::output::{OutputHandler, OutputManagerState};
|
||||
use smithay::wayland::pointer_constraints::{PointerConstraintsHandler, PointerConstraintsState};
|
||||
use smithay::wayland::presentation::PresentationState;
|
||||
use smithay::wayland::relative_pointer::RelativePointerManagerState;
|
||||
use smithay::wayland::selection::SelectionHandler;
|
||||
use smithay::wayland::selection::data_device::{
|
||||
ClientDndGrabHandler, DataDeviceHandler, DataDeviceState, ServerDndGrabHandler, set_data_device_focus,
|
||||
@@ -47,8 +57,9 @@ use smithay::wayland::shm::{ShmHandler, ShmState};
|
||||
use smithay::wayland::socket::ListeningSocketSource;
|
||||
use smithay::wayland::viewporter::ViewporterState;
|
||||
use smithay::{
|
||||
delegate_compositor, delegate_data_device, delegate_dmabuf, delegate_output, delegate_seat, delegate_shm,
|
||||
delegate_viewporter, delegate_xdg_decoration, delegate_xdg_shell,
|
||||
delegate_compositor, delegate_data_device, delegate_dmabuf, delegate_output, delegate_pointer_constraints,
|
||||
delegate_presentation, delegate_relative_pointer, delegate_seat, delegate_shm, delegate_viewporter,
|
||||
delegate_xdg_decoration, delegate_xdg_shell,
|
||||
};
|
||||
|
||||
use crate::output_mgmt::{OutputMgmtState, PendingConfig};
|
||||
@@ -175,6 +186,14 @@ pub struct State {
|
||||
pub viewporter_state: ViewporterState,
|
||||
#[allow(dead_code)]
|
||||
pub decoration_state: XdgDecorationState,
|
||||
#[allow(dead_code)]
|
||||
pub presentation_state: PresentationState,
|
||||
#[allow(dead_code)]
|
||||
pub relative_pointer_state: RelativePointerManagerState,
|
||||
#[allow(dead_code)]
|
||||
pub pointer_constraints_state: PointerConstraintsState,
|
||||
/// The clock presentation feedback is given in (CLOCK_MONOTONIC).
|
||||
pub clock: Clock<Monotonic>,
|
||||
pub output_mgmt: OutputMgmtState,
|
||||
pub pending_configs: Vec<PendingConfig>,
|
||||
pub popups: PopupManager,
|
||||
@@ -288,12 +307,19 @@ impl State {
|
||||
let data_device_state = DataDeviceState::new::<Self>(&dh);
|
||||
let viewporter_state = ViewporterState::new::<Self>(&dh);
|
||||
let decoration_state = XdgDecorationState::new::<Self>(&dh);
|
||||
let clock = Clock::<Monotonic>::new();
|
||||
let presentation_state = PresentationState::new::<Self>(&dh, clock.id() as u32);
|
||||
let relative_pointer_state = RelativePointerManagerState::new::<Self>(&dh);
|
||||
let pointer_constraints_state = PointerConstraintsState::new::<Self>(&dh);
|
||||
let output_mgmt = OutputMgmtState::new(&dh);
|
||||
|
||||
let mut seat: Seat<Self> = seat_state.new_wl_seat(&dh, "seat0");
|
||||
// Same repeat as cage/wlroots: 600 ms delay, 25 per second.
|
||||
seat.add_keyboard(XkbConfig::default(), 600, 25)
|
||||
.map_err(|e| anyhow::anyhow!("keyboard: {e:?}"))?;
|
||||
// No pointer device is ever attached (the cursor theme is blank), but
|
||||
// relative pointer and pointer constraints work on a wl_pointer.
|
||||
seat.add_pointer();
|
||||
|
||||
let socket = ListeningSocketSource::new_auto()?;
|
||||
let socket_name = socket.socket_name().to_os_string();
|
||||
@@ -331,6 +357,10 @@ impl State {
|
||||
dmabuf_global: None,
|
||||
viewporter_state,
|
||||
decoration_state,
|
||||
presentation_state,
|
||||
relative_pointer_state,
|
||||
pointer_constraints_state,
|
||||
clock,
|
||||
output_mgmt,
|
||||
pending_configs: vec![],
|
||||
popups: PopupManager::default(),
|
||||
@@ -695,21 +725,37 @@ impl State {
|
||||
out
|
||||
}
|
||||
|
||||
/// Frame callbacks for what is on screen (hidden apps get none, so they idle).
|
||||
pub fn send_frames(&self) {
|
||||
let Some(output) = self.output.as_ref() else { return };
|
||||
let time = self.start.elapsed();
|
||||
// The held-back app draws too, so its page is ready when it shows.
|
||||
/// Windows that get frame callbacks: what is on screen, and the
|
||||
/// held-back app (it draws, so its page is ready when it shows).
|
||||
fn shown(&self) -> Vec<&Window> {
|
||||
let mut shown: Vec<&Window> = self.visible.iter().chain(self.held.iter()).collect();
|
||||
if let Some(t) = &self.transition {
|
||||
shown.push(&t.over);
|
||||
shown.extend(t.under.iter());
|
||||
}
|
||||
for w in shown {
|
||||
shown
|
||||
}
|
||||
|
||||
/// Frame callbacks for what is on screen (hidden apps get none, so they idle).
|
||||
pub fn send_frames(&self) {
|
||||
let Some(output) = self.output.as_ref() else { return };
|
||||
let time = self.start.elapsed();
|
||||
for w in self.shown() {
|
||||
w.send_frame(output, time, Some(Duration::ZERO), |_, _| Some(output.clone()));
|
||||
}
|
||||
}
|
||||
|
||||
/// Presentation feedback requests of the frame being rendered; answered
|
||||
/// when it is on screen (`presented`) or dropped if it never gets there.
|
||||
pub fn presentation_feedback(&self) -> Option<OutputPresentationFeedback> {
|
||||
let output = self.output.as_ref()?;
|
||||
let mut feedback = OutputPresentationFeedback::new(output);
|
||||
for w in self.shown() {
|
||||
w.take_presentation_feedback(&mut feedback, |_, _| Some(output.clone()), |_, _| wp_presentation_feedback::Kind::Vsync);
|
||||
}
|
||||
Some(feedback)
|
||||
}
|
||||
|
||||
pub fn output_mgmt_refresh(&mut self) {
|
||||
let info = crate::output_mgmt::HeadInfo::from_state(self);
|
||||
self.output_mgmt.update(&self.dh, info);
|
||||
@@ -935,6 +981,12 @@ impl ServerDndGrabHandler for State {}
|
||||
|
||||
impl OutputHandler for State {}
|
||||
|
||||
impl PointerConstraintsHandler for State {
|
||||
// There is no pointer to lock or confine; the requests are accepted.
|
||||
fn new_constraint(&mut self, _surface: &WlSurface, _pointer: &PointerHandle<Self>) {}
|
||||
fn cursor_position_hint(&mut self, _surface: &WlSurface, _pointer: &PointerHandle<Self>, _location: Point<f64, Logical>) {}
|
||||
}
|
||||
|
||||
impl DmabufHandler for State {
|
||||
fn dmabuf_state(&mut self) -> &mut DmabufState {
|
||||
&mut self.dmabuf_state
|
||||
@@ -960,3 +1012,6 @@ delegate_data_device!(State);
|
||||
delegate_output!(State);
|
||||
delegate_dmabuf!(State);
|
||||
delegate_viewporter!(State);
|
||||
delegate_presentation!(State);
|
||||
delegate_relative_pointer!(State);
|
||||
delegate_pointer_constraints!(State);
|
||||
|
||||
Reference in New Issue
Block a user