Files
server/src/wayland/util.rs
Schmarni 0ebfc1153e chore(wayland): update waynest
Signed-off-by: Schmarni <marnistromer@gmail.com>
2025-09-30 22:32:09 +02:00

51 lines
1.3 KiB
Rust

#![allow(unused)]
use super::{Message, MessageSink, display::Display};
use crate::wayland::{Client, WaylandError, WaylandResult};
use std::{fmt::Debug, sync::Arc};
use waynest::ObjectId;
use waynest_protocols::server::core::wayland::wl_display::WlDisplay;
use waynest_server::{Client as _, RequestDispatcher};
pub trait ClientExt {
fn message_sink(&self) -> MessageSink;
fn display(&self) -> Arc<Display>;
fn try_get<D: RequestDispatcher>(&self, id: ObjectId) -> WaylandResult<Arc<D>>;
}
impl ClientExt for Client {
fn message_sink(&self) -> MessageSink {
self.get::<Display>(ObjectId::DISPLAY)
.unwrap()
.message_sink
.clone()
}
fn display(&self) -> Arc<Display> {
self.get::<Display>(ObjectId::DISPLAY).unwrap()
}
fn try_get<D: RequestDispatcher>(&self, id: ObjectId) -> WaylandResult<Arc<D>> {
self.get::<D>(id).ok_or(WaylandError::MissingObject(id))
}
}
#[derive(Debug, Default)]
pub struct DoubleBuffer<State: Debug + Clone> {
pub current: State,
pub pending: State,
}
impl<State: Debug + Clone> DoubleBuffer<State> {
pub fn new(initial_state: State) -> Self {
DoubleBuffer {
current: initial_state.clone(),
pending: initial_state,
}
}
pub fn apply(&mut self) {
self.current = self.pending.clone();
}
pub fn current(&self) -> &State {
&self.current
}
}