Skip to main content

screencapturekit/cm/
frame_status.rs

1//! Frame status for captured screen content
2
3use std::fmt;
4
5/// Frame status for captured screen content
6///
7/// Indicates the state of a frame captured by `ScreenCaptureKit`.
8/// This maps to Apple's `SCFrameStatus` enum.
9#[repr(i32)]
10#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
11pub enum SCFrameStatus {
12    /// Frame contains complete content
13    #[default]
14    Complete = 0,
15    /// Frame is idle (no changes)
16    Idle = 1,
17    /// Frame is blank
18    Blank = 2,
19    /// Frame is suspended
20    Suspended = 3,
21    /// Started (first frame)
22    Started = 4,
23    /// Stopped (last frame)
24    Stopped = 5,
25    Unknown(i32),
26}
27
28impl SCFrameStatus {
29    /// Create from raw i32 value
30    pub const fn from_raw(value: i32) -> Self {
31        match value {
32            0 => Self::Complete,
33            1 => Self::Idle,
34            2 => Self::Blank,
35            3 => Self::Suspended,
36            4 => Self::Started,
37            5 => Self::Stopped,
38            other => Self::Unknown(other),
39        }
40    }
41
42    pub const fn raw(self) -> i32 {
43        match self {
44            Self::Complete => 0,
45            Self::Idle => 1,
46            Self::Blank => 2,
47            Self::Suspended => 3,
48            Self::Started => 4,
49            Self::Stopped => 5,
50            Self::Unknown(raw) => raw,
51        }
52    }
53
54    /// Returns true if the frame contains actual content
55    pub const fn has_content(self) -> bool {
56        matches!(self, Self::Complete | Self::Started)
57    }
58
59    /// Returns true if the frame is complete
60    pub const fn is_complete(self) -> bool {
61        matches!(self, Self::Complete)
62    }
63}
64
65impl fmt::Display for SCFrameStatus {
66    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
67        match self {
68            Self::Complete => write!(f, "Complete"),
69            Self::Idle => write!(f, "Idle"),
70            Self::Blank => write!(f, "Blank"),
71            Self::Suspended => write!(f, "Suspended"),
72            Self::Started => write!(f, "Started"),
73            Self::Stopped => write!(f, "Stopped"),
74            Self::Unknown(raw) => write!(f, "Unknown({raw})"),
75        }
76    }
77}