1use std::{
2 fmt::Debug,
3 hash::{Hash, Hasher},
4};
5
6use uuid::Uuid;
7use wayland_backend::client::ObjectId;
8
9use crate::{Bounds, DisplayId, Pixels, PlatformDisplay};
10
11#[derive(Debug, Clone)]
12pub(crate) struct WaylandDisplay {
13 /// The ID of the wl_output object
14 pub id: ObjectId,
15 pub name: Option<String>,
16 pub bounds: Bounds<Pixels>,
17}
18
19impl Hash for WaylandDisplay {
20 fn hash<H: Hasher>(&self, state: &mut H) {
21 self.id.hash(state);
22 }
23}
24
25impl PlatformDisplay for WaylandDisplay {
26 fn id(&self) -> DisplayId {
27 DisplayId(self.id.protocol_id())
28 }
29
30 fn uuid(&self) -> anyhow::Result<Uuid> {
31 if let Some(name) = &self.name {
32 Ok(Uuid::new_v5(&Uuid::NAMESPACE_DNS, name.as_bytes()))
33 } else {
34 Err(anyhow::anyhow!("Wayland display does not have a name"))
35 }
36 }
37
38 fn bounds(&self) -> Bounds<Pixels> {
39 self.bounds
40 }
41}