Skip to main content

windows_ccd/
device_id.rs

1use crate::windows::{DISPLAYCONFIG_PATH_SOURCE_INFO, DISPLAYCONFIG_PATH_TARGET_INFO, LUID};
2
3/// A convenience type to obtain and pass a display device `adapterId` and `id`.
4#[derive(Debug, Clone, Copy, PartialEq)]
5pub struct DeviceId {
6    /// The device `adapterId`.
7    pub adapter_id: LUID,
8
9    /// The identifier on the specified adapter.
10    pub id: u32,
11}
12
13impl Eq for DeviceId {}
14
15impl PartialOrd for DeviceId {
16    fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
17        Some(self.cmp(other))
18    }
19}
20
21impl Ord for DeviceId {
22    fn cmp(&self, other: &Self) -> std::cmp::Ordering {
23        let key = |did: &DeviceId| (did.adapter_id.HighPart, did.adapter_id.LowPart, did.id);
24        key(self).cmp(&key(other))
25    }
26}
27
28impl From<DISPLAYCONFIG_PATH_SOURCE_INFO> for DeviceId {
29    fn from(value: DISPLAYCONFIG_PATH_SOURCE_INFO) -> Self {
30        DeviceId {
31            adapter_id: value.adapterId,
32            id: value.id,
33        }
34    }
35}
36
37impl From<DISPLAYCONFIG_PATH_TARGET_INFO> for DeviceId {
38    fn from(value: DISPLAYCONFIG_PATH_TARGET_INFO) -> Self {
39        DeviceId {
40            adapter_id: value.adapterId,
41            id: value.id,
42        }
43    }
44}