metal: allow changing the connector mode
This commit is contained in:
parent
558bea47b7
commit
98b6eba81c
9 changed files with 124 additions and 4 deletions
|
|
@ -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 });
|
||||
|
|
|
|||
|
|
@ -356,6 +356,10 @@ pub enum ClientMessage<'a> {
|
|||
ConnectorModes {
|
||||
connector: Connector,
|
||||
},
|
||||
ConnectorSetMode {
|
||||
connector: Connector,
|
||||
mode: WireMode,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue