| 1 | use std::{ |
| 2 | fmt::Debug, |
| 3 | hash::{Hash, Hasher}, |
| 4 | }; |
| 5 | |
| 6 | use anyhow::Context as _; |
| 7 | use uuid::Uuid; |
| 8 | use wayland_backend::client::ObjectId; |
| 9 | |
| 10 | use crate::{Bounds, DisplayId, Pixels, PlatformDisplay}; |
| 11 | |
| 12 | #[derive(Debug, Clone)] |
| 13 | pub(crate) struct WaylandDisplay { |
| 14 | |
| 15 | pub id: ObjectId, |
| 16 | pub name: Option<String>, |
| 17 | pub bounds: Bounds<Pixels>, |
| 18 | } |
| 19 | |
| 20 | impl Hash for WaylandDisplay { |
| 21 | fn hash<H: Hasher>(&self, state: &mut H) { |
| 22 | self.id.hash(state); |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | impl 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 | } |