mm_client_common/
display_params.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Copyright 2024 Colin Marc <hi@colinmarc.com>
//
// SPDX-License-Identifier: MIT

use mm_protocol as protocol;

use crate::{pixel_scale::PixelScale, validation::*};

#[derive(Debug, Clone, PartialEq, Eq, uniffi::Record)]
pub struct DisplayParams {
    pub width: u32,
    pub height: u32,
    pub framerate: u32,
    pub ui_scale: PixelScale,
}

impl TryFrom<protocol::VirtualDisplayParameters> for DisplayParams {
    type Error = ValidationError;

    fn try_from(msg: protocol::VirtualDisplayParameters) -> Result<Self, Self::Error> {
        let res = required_field!(msg.resolution)?;

        Ok(DisplayParams {
            width: res.width,
            height: res.height,
            framerate: msg.framerate_hz,
            ui_scale: required_field!(msg.ui_scale)?.try_into()?,
        })
    }
}

impl From<DisplayParams> for protocol::VirtualDisplayParameters {
    fn from(value: DisplayParams) -> Self {
        protocol::VirtualDisplayParameters {
            resolution: Some(protocol::Size {
                width: value.width,
                height: value.height,
            }),
            framerate_hz: value.framerate,
            ui_scale: Some(value.ui_scale.into()),
        }
    }
}