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