1
0
Fork 0
forked from wry/wry

metal: allow changing the connector mode

This commit is contained in:
Julian Orth 2024-03-04 17:18:44 +01:00
parent 558bea47b7
commit 98b6eba81c
9 changed files with 124 additions and 4 deletions

View file

@ -570,6 +570,10 @@ impl Client {
}
}
pub fn connector_set_mode(&self, connector: Connector, mode: WireMode) {
self.send(&ClientMessage::ConnectorSetMode { connector, mode });
}
pub fn connector_modes(&self, connector: Connector) -> Vec<Mode> {
let res = self.send_with_response(&ClientMessage::ConnectorModes { connector });
get_response!(res, Vec::new(), ConnectorModes { modes });

View file

@ -356,6 +356,10 @@ pub enum ClientMessage<'a> {
ConnectorModes {
connector: Connector,
},
ConnectorSetMode {
connector: Connector,
mode: WireMode,
},
}
#[derive(Serialize, Deserialize, Debug)]

View file

@ -9,6 +9,7 @@ use {
CON_VIRTUAL, CON_WRITEBACK,
},
PciId,
_private::WireMode,
},
serde::{Deserialize, Serialize},
std::str::FromStr,
@ -112,6 +113,42 @@ impl Connector {
get!(Mode::zeroed()).connector_mode(self)
}
/// Tries to set the mode of the connector.
///
/// If the refresh rate is not specified, tries to use the first mode with the given
/// width and height.
///
/// The default mode is the first mode advertised by the connector. This is usually
/// the native mode.
pub fn set_mode(self, width: i32, height: i32, refresh_millihz: Option<u32>) {
if !self.exists() {
log::warn!("set_mode called on a connector that does not exist");
return;
}
let refresh_millihz = match refresh_millihz {
Some(r) => r,
_ => match self
.modes()
.iter()
.find(|m| m.width == width && m.height == height)
{
Some(m) => m.refresh_millihz,
_ => {
log::warn!("Could not find any mode with width {width} and height {height}");
return;
}
},
};
get!().connector_set_mode(
self,
WireMode {
width,
height,
refresh_millihz,
},
)
}
/// Returns the available modes of the connector.
pub fn modes(self) -> Vec<Mode> {
if !self.exists() {