diff --git a/shell/src/lib.rs b/shell/src/lib.rs index be86d8e..7db40ca 100644 --- a/shell/src/lib.rs +++ b/shell/src/lib.rs @@ -50,6 +50,8 @@ pub struct Output { pub transform: Option, pub modes: Vec, pub current: Option, + pub adaptive_sync: Option, + pub adaptive_sync_availability: Option, } impl Output { @@ -67,6 +69,8 @@ impl Output { transform: None, modes: Vec::new(), current: None, + adaptive_sync: None, + adaptive_sync_availability: None, } } } @@ -116,6 +120,66 @@ impl TryFrom<&str> for Transform { } } +#[derive(Clone, Copy, Debug, Eq, PartialEq)] +pub enum AdaptiveSyncState { + Always, + Auto, + Disabled, +} + +impl Display for AdaptiveSyncState { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_str(match self { + AdaptiveSyncState::Always => "true", + AdaptiveSyncState::Auto => "automatic", + AdaptiveSyncState::Disabled => "false", + }) + } +} + +impl TryFrom<&str> for AdaptiveSyncState { + type Error = &'static str; + + fn try_from(value: &str) -> Result { + Ok(match value { + "true" => AdaptiveSyncState::Always, + "automatic" => AdaptiveSyncState::Auto, + "false" => AdaptiveSyncState::Disabled, + _ => return Err("unknown adaptive_sync state variant"), + }) + } +} + +#[derive(Clone, Copy, Debug, Eq, PartialEq)] +pub enum AdaptiveSyncAvailability { + Supported, + RequiresModeset, + Unsupported, +} + +impl Display for AdaptiveSyncAvailability { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_str(match self { + AdaptiveSyncAvailability::Supported => "true", + AdaptiveSyncAvailability::RequiresModeset => "requires_modeset", + AdaptiveSyncAvailability::Unsupported => "false", + }) + } +} + +impl TryFrom<&str> for AdaptiveSyncAvailability { + type Error = &'static str; + + fn try_from(value: &str) -> Result { + Ok(match value { + "true" => AdaptiveSyncAvailability::Supported, + "requires_modeset" => AdaptiveSyncAvailability::RequiresModeset, + "false" => AdaptiveSyncAvailability::Unsupported, + _ => return Err("unknown adaptive_sync availability variant"), + }) + } +} + #[derive(thiserror::Error, Debug)] pub enum Error { #[error("`cosmic-randr` KDL format error")] @@ -245,6 +309,23 @@ pub async fn list() -> Result { } } + "adaptive_sync" => { + if let Some(entry) = node.entries().first() { + if let Some(string) = entry.value().as_string() { + output.adaptive_sync = AdaptiveSyncState::try_from(string).ok(); + } + } + } + + "adaptive_sync_support" => { + if let Some(entry) = node.entries().first() { + if let Some(string) = entry.value().as_string() { + output.adaptive_sync_availability = + AdaptiveSyncAvailability::try_from(string).ok(); + } + } + } + // Switch to parsing output modes. "modes" => { let Some(children) = node.children() else {