diff --git a/src/server/clientside.rs b/src/server/clientside.rs index 664c909..5209d2d 100644 --- a/src/server/clientside.rs +++ b/src/server/clientside.rs @@ -196,6 +196,8 @@ delegate_noop!(MyWorld: WlSubsurface); delegate_noop!(MyWorld: WpLinuxDrmSyncobjManagerV1); delegate_noop!(MyWorld: WpLinuxDrmSyncobjSurfaceV1); delegate_noop!(MyWorld: WpLinuxDrmSyncobjTimelineV1); +delegate_noop!(MyWorld: wayland_protocols::wp::tearing_control::v1::client::wp_tearing_control_manager_v1::WpTearingControlManagerV1); +delegate_noop!(MyWorld: wayland_protocols::wp::tearing_control::v1::client::wp_tearing_control_v1::WpTearingControlV1); impl Dispatch for MyWorld { fn event( diff --git a/src/server/dispatch.rs b/src/server/dispatch.rs index 3815022..a28870a 100644 --- a/src/server/dispatch.rs +++ b/src/server/dispatch.rs @@ -9,6 +9,7 @@ use wayland_protocols::{ fractional_scale::v1::client::wp_fractional_scale_v1::WpFractionalScaleV1, linux_dmabuf::zv1::{client as c_dmabuf, server as s_dmabuf}, linux_drm_syncobj::v1::{client as c_sync, server as s_sync}, + tearing_control::v1::{client as c_tear, server as s_tear}, pointer_constraints::zv1::{ client::zwp_confined_pointer_v1::ZwpConfinedPointerV1 as ConfinedPointerClient, client::zwp_locked_pointer_v1::ZwpLockedPointerV1 as LockedPointerClient, @@ -1428,6 +1429,80 @@ global_dispatch_no_events!( s_sync::wp_linux_drm_syncobj_manager_v1::WpLinuxDrmSyncobjManagerV1, c_sync::wp_linux_drm_syncobj_manager_v1::WpLinuxDrmSyncobjManagerV1 ); +global_dispatch_no_events!( + s_tear::wp_tearing_control_manager_v1::WpTearingControlManagerV1, + c_tear::wp_tearing_control_manager_v1::WpTearingControlManagerV1 +); + +// Tearing control: Xwayland asks for it per window and marks its asynchronous presents, so the +// compositor may show a game's picture without waiting for the refresh. The object is made on +// the compositor's own surface behind the X11 window's surface. +impl + Dispatch< + s_tear::wp_tearing_control_manager_v1::WpTearingControlManagerV1, + ClientGlobalWrapper, + > for InnerServerState +{ + fn request( + state: &mut Self, + _: &Client, + _: &s_tear::wp_tearing_control_manager_v1::WpTearingControlManagerV1, + request: ::Request, + client: &ClientGlobalWrapper, + _: &DisplayHandle, + data_init: &mut wayland_server::DataInit<'_, Self>, + ) { + use s_tear::wp_tearing_control_manager_v1::Request; + match request { + Request::GetTearingControl { id, surface } => { + let c_surface = state + .world + .get::<&client::wl_surface::WlSurface>(surface.data().copied().unwrap()) + .unwrap(); + let control = client.get_tearing_control(&c_surface, &state.qh, ()); + data_init.init(id, control); + } + Request::Destroy => { + client.destroy(); + } + other => warn!("unhandled tearing control manager request: {other:?}"), + } + } +} + +impl + Dispatch< + s_tear::wp_tearing_control_v1::WpTearingControlV1, + c_tear::wp_tearing_control_v1::WpTearingControlV1, + > for InnerServerState +{ + fn request( + _: &mut Self, + _: &Client, + _: &s_tear::wp_tearing_control_v1::WpTearingControlV1, + request: ::Request, + client: &c_tear::wp_tearing_control_v1::WpTearingControlV1, + _: &DisplayHandle, + _: &mut wayland_server::DataInit<'_, Self>, + ) { + use s_tear::wp_tearing_control_v1::{PresentationHint, Request}; + match request { + Request::SetPresentationHint { hint } => { + let hint = match hint { + wayland_server::WEnum::Value(PresentationHint::Async) => { + c_tear::wp_tearing_control_v1::PresentationHint::Async + } + _ => c_tear::wp_tearing_control_v1::PresentationHint::Vsync, + }; + client.set_presentation_hint(hint); + } + Request::Destroy => { + client.destroy(); + } + other => warn!("unhandled tearing control request: {other:?}"), + } + } +} impl GlobalDispatch for InnerServerState { fn bind( diff --git a/src/server/mod.rs b/src/server/mod.rs index a436331..936f5a8 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -387,7 +387,8 @@ fn handle_new_globals<'a, S: X11Selection + 'static>( ZxdgOutputManagerV1, ZwpPointerConstraintsV1, ZwpTabletManagerV2, - WpLinuxDrmSyncobjManagerV1 + WpLinuxDrmSyncobjManagerV1, + wayland_protocols::wp::tearing_control::v1::server::wp_tearing_control_manager_v1::WpTearingControlManagerV1 ]; } } @@ -475,6 +476,8 @@ pub struct InnerServerState { unfocus: bool, last_focused_toplevel: Option, last_hovered: Option, + /// fullscreen asked for (_NET_WM_STATE) before the window had its toplevel: applied when it gets one + early_fullscreen: HashSet, xdg_wm_base: XdgWmBase, compositor: client::wl_compositor::WlCompositor, @@ -577,6 +580,7 @@ impl ServerState> { unfocus: false, last_focused_toplevel: None, last_hovered: None, + early_fullscreen: HashSet::new(), xdg_wm_base, compositor, subcompositor, @@ -1204,6 +1208,27 @@ impl InnerServerState { return; }; + use crate::xstate::SetState; + let early = match data.get::<&SurfaceRole>() { + None => true, + Some(role) => matches!(&*role, SurfaceRole::Toplevel(None)), + }; + if early { + // the client asked before its window was shown (SDL does): remembered for the toplevel + let on = match state { + SetState::Add => true, + SetState::Remove => false, + SetState::Toggle => !self.early_fullscreen.contains(&window), + }; + if on { + self.early_fullscreen.insert(window); + } else { + self.early_fullscreen.remove(&window); + } + debug!("fullscreen {on} for {window:?} kept until it has a toplevel"); + return; + } + let Some(role) = data.get::<&SurfaceRole>() else { warn!("Tried to set window without role fullscreen: {window:?}"); return; @@ -1214,7 +1239,6 @@ impl InnerServerState { return; }; - use crate::xstate::SetState; match state { SetState::Add => toplevel.toplevel.set_fullscreen(None), SetState::Remove => toplevel.toplevel.unset_fullscreen(), @@ -1346,6 +1370,7 @@ impl InnerServerState { } pub fn destroy_window(&mut self, window: x::Window) { + self.early_fullscreen.remove(&window); if let Some(id) = self.windows.remove(&window) { self.world.remove::<(x::Window, WindowData)>(id).unwrap(); if self.world.entity(id).unwrap().is_empty() { @@ -1418,6 +1443,10 @@ impl InnerServerState { } splash = window_data.attrs.role == WindowRole::Splash; + if self.early_fullscreen.remove(&window) { + fullscreen = true; + popup_for = None; + } let (width, height) = (window_data.attrs.dims.width, window_data.attrs.dims.height); for (_, dimensions) in self.world.query::<&OutputDimensions>().iter() { if dimensions.width == width as i32 && dimensions.height == height as i32 {