Skip to content

Commit

Permalink
WIP commit-timing
Browse files Browse the repository at this point in the history
  • Loading branch information
ids1024 committed Oct 18, 2024
1 parent b6aa22f commit f30e979
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 0 deletions.
4 changes: 4 additions & 0 deletions anvil/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ use smithay::{
},
utils::{Clock, Logical, Monotonic, Point, Rectangle},
wayland::{
commit_timing::CommitTimingState,
compositor::{get_parent, with_states, CompositorClientState, CompositorState},
dmabuf::DmabufFeedback,
fifo::FifoState,
Expand Down Expand Up @@ -568,6 +569,8 @@ smithay::delegate_single_pixel_buffer!(@<BackendData: Backend + 'static> AnvilSt

smithay::delegate_fifo!(@<BackendData: Backend + 'static> AnvilState<BackendData>);

smithay::delegate_commit_timing!(@<BackendData: Backend + 'static> AnvilState<BackendData>);

impl<BackendData: Backend + 'static> AnvilState<BackendData> {
pub fn init(
display: Display<AnvilState<BackendData>>,
Expand Down Expand Up @@ -648,6 +651,7 @@ impl<BackendData: Backend + 'static> AnvilState<BackendData> {
.map_or(true, |client_state| client_state.security_context.is_none())
});
FifoState::new::<Self, _>(&dh, |_| true);
CommitTimingState::new::<Self, _>(&dh, |_| true);

// init input
let seat_name = backend_data.seat_name();
Expand Down
143 changes: 143 additions & 0 deletions src/wayland/commit_timing.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
use std::time::Duration;
use wayland_protocols::wp::commit_timing::v1::server::{wp_commit_timer_v1, wp_commit_timing_manager_v1};
use wayland_server::{
backend::GlobalId, protocol::wl_surface, Client, DataInit, Dispatch, DisplayHandle, GlobalDispatch, New,
Resource, WEnum, Weak,
};

pub struct CommitTimingState {}

impl CommitTimingState {
pub fn new<D, F>(display: &DisplayHandle, filter: F) -> Self
where
D: GlobalDispatch<
wp_commit_timing_manager_v1::WpCommitTimingManagerV1,
CommitTimingManagerGlobalData,
>,
D: Dispatch<wp_commit_timing_manager_v1::WpCommitTimingManagerV1, ()>,
D: Dispatch<wp_commit_timer_v1::WpCommitTimerV1, CommitTimerData>,
D: 'static,
F: for<'c> Fn(&'c Client) -> bool + Send + Sync + 'static,
{
let data = CommitTimingManagerGlobalData {
filter: Box::new(filter),
};
display.create_global::<D, wp_commit_timing_manager_v1::WpCommitTimingManagerV1, _>(1, data);

Self {}
}
}

#[allow(missing_debug_implementations)]
#[doc(hidden)]
pub struct CommitTimingManagerGlobalData {
/// Filter whether the clients can view global.
filter: Box<dyn for<'c> Fn(&'c Client) -> bool + Send + Sync>,
}

impl<D> GlobalDispatch<wp_commit_timing_manager_v1::WpCommitTimingManagerV1, CommitTimingManagerGlobalData, D>
for CommitTimingState
where
D: GlobalDispatch<wp_commit_timing_manager_v1::WpCommitTimingManagerV1, CommitTimingManagerGlobalData>,
D: Dispatch<wp_commit_timing_manager_v1::WpCommitTimingManagerV1, ()>,
D: 'static,
{
fn bind(
_state: &mut D,
_display: &DisplayHandle,
_client: &Client,
manager: New<wp_commit_timing_manager_v1::WpCommitTimingManagerV1>,
_global_data: &CommitTimingManagerGlobalData,
data_init: &mut DataInit<'_, D>,
) {
data_init.init(manager, ());
}

fn can_view(client: Client, global_data: &CommitTimingManagerGlobalData) -> bool {
(global_data.filter)(&client)
}
}

#[doc(hidden)]
pub struct CommitTimerData {
surface: Weak<wl_surface::WlSurface>,
}

impl<D> Dispatch<wp_commit_timing_manager_v1::WpCommitTimingManagerV1, (), D> for CommitTimingState
where
D: Dispatch<wp_commit_timing_manager_v1::WpCommitTimingManagerV1, ()>,
D: Dispatch<wp_commit_timer_v1::WpCommitTimerV1, CommitTimerData>,
D: 'static,
{
fn request(
state: &mut D,
_client: &wayland_server::Client,
_proxy: &wp_commit_timing_manager_v1::WpCommitTimingManagerV1,
request: wp_commit_timing_manager_v1::Request,
_data: &(),
_dh: &DisplayHandle,
data_init: &mut wayland_server::DataInit<'_, D>,
) {
match request {
wp_commit_timing_manager_v1::Request::GetTimer { id, surface } => {
// TODO CommitTimerExists
data_init.init(
id,
CommitTimerData {
surface: surface.downgrade(),
},
);
}
wp_commit_timing_manager_v1::Request::Destroy => {}
_ => unreachable!(),
}
}
}

impl<D> Dispatch<wp_commit_timer_v1::WpCommitTimerV1, CommitTimerData, D> for CommitTimingState
where
D: Dispatch<wp_commit_timer_v1::WpCommitTimerV1, CommitTimerData>,
D: 'static,
{
fn request(
state: &mut D,
_client: &wayland_server::Client,
_proxy: &wp_commit_timer_v1::WpCommitTimerV1,
request: wp_commit_timer_v1::Request,
_data: &CommitTimerData,
_dh: &DisplayHandle,
data_init: &mut wayland_server::DataInit<'_, D>,
) {
match request {
wp_commit_timer_v1::Request::SetTimestamp {
tv_sec_hi,
tv_sec_lo,
tv_nsec,
} => {
let secs = (u64::from(tv_sec_hi) << 32) + u64::from(tv_sec_lo);
let duration = Duration::new(secs, tv_nsec);
}
wp_commit_timer_v1::Request::Destroy => {}
_ => unreachable!(),
}
}
}

#[allow(missing_docs)]
#[macro_export]
macro_rules! delegate_commit_timing {
($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => {
$crate::reexports::wayland_server::delegate_global_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [
$crate::reexports::wayland_protocols::wp::commit_timing::v1::server::wp_commit_timing_manager_v1::WpCommitTimingManagerV1: $crate::wayland::commit_timing::CommitTimingManagerGlobalData
] => $crate::wayland::commit_timing::CommitTimingState);

$crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [
$crate::reexports::wayland_protocols::wp::commit_timing::v1::server::wp_commit_timing_manager_v1::WpCommitTimingManagerV1: ()
] => $crate::wayland::commit_timing::CommitTimingState);

$crate::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [
$crate::reexports::wayland_protocols::wp::commit_timing::v1::server::wp_commit_timer_v1::WpCommitTimerV1: $crate::wayland::commit_timing::CommitTimerData
] => $crate::wayland::commit_timing::CommitTimingState);
};
}
//use wayland_protocols::wp::commit_timing::v1::server::{wp_commit_timer_v1, wp_commit_timing_manager_v1};
1 change: 1 addition & 0 deletions src/wayland/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@

pub mod alpha_modifier;
pub mod buffer;
pub mod commit_timing;
pub mod compositor;
pub mod content_type;
pub mod cursor_shape;
Expand Down

0 comments on commit f30e979

Please sign in to comment.