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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
use super::Client;
use crate::{
    requests::ui::{
        OpenSourceProjector, OpenSourceProjectorInternal, OpenVideoMixProjector,
        OpenVideoMixProjectorInternal, Request,
    },
    responses::ui as responses,
    Result,
};

/// API functions related to the user interface.
pub struct Ui<'a> {
    pub(super) client: &'a Client,
}

impl<'a> Ui<'a> {
    /// Gets whether studio is enabled.
    #[doc(alias = "GetStudioModeEnabled")]
    pub async fn studio_mode_enabled(&self) -> Result<bool> {
        self.client
            .send_message::<_, responses::StudioModeEnabled>(Request::GetStudioModeEnabled)
            .await
            .map(|sme| sme.enabled)
    }

    /// Enables or disables studio mode.
    ///
    /// - `enabled`: Enable or disable the studio mode.
    #[doc(alias = "SetStudioModeEnabled")]
    pub async fn set_studio_mode_enabled(&self, enabled: bool) -> Result<()> {
        self.client
            .send_message(Request::SetStudioModeEnabled { enabled })
            .await
    }

    /// Opens the properties dialog of an input.
    #[doc(alias = "OpenInputPropertiesDialog")]
    pub async fn open_properties_dialog(&self, input: &str) -> Result<()> {
        self.client
            .send_message(Request::OpenInputPropertiesDialog { input })
            .await
    }

    /// Opens the filters dialog of an input.
    #[doc(alias = "OpenInputFiltersDialog")]
    pub async fn open_filters_dialog(&self, input: &str) -> Result<()> {
        self.client
            .send_message(Request::OpenInputFiltersDialog { input })
            .await
    }

    /// Opens the interact dialog of an input.
    #[doc(alias = "OpenInputInteractDialog")]
    pub async fn open_interact_dialog(&self, input: &str) -> Result<()> {
        self.client
            .send_message(Request::OpenInputInteractDialog { input })
            .await
    }

    /// Gets a list of connected monitors and information about them.
    #[doc(alias = "GetMonitorList")]
    pub async fn list_monitors(&self) -> Result<Vec<responses::Monitor>> {
        self.client
            .send_message::<_, responses::MonitorList>(Request::GetMonitorList)
            .await
            .map(|ml| ml.monitors)
    }

    /// Open a projector for a specific output video mix.
    #[doc(alias = "OpenVideoMixProjector")]
    pub async fn open_video_mix_projector(&self, open: OpenVideoMixProjector) -> Result<()> {
        self.client
            .send_message(Request::OpenVideoMixProjector(
                OpenVideoMixProjectorInternal {
                    r#type: open.r#type,
                    location: open.location.map(Into::into),
                },
            ))
            .await
    }

    /// Opens a projector for a source.
    #[doc(alias = "OpenSourceProjector")]
    pub async fn open_source_projector(&self, open: OpenSourceProjector<'a>) -> Result<()> {
        self.client
            .send_message(Request::OpenSourceProjector(OpenSourceProjectorInternal {
                source: open.source,
                location: open.location.map(Into::into),
            }))
            .await
    }
}