1
0
Fork 0
forked from wry/wry

config: allow retrieving the modes

This commit is contained in:
Julian Orth 2024-03-04 16:09:53 +01:00
parent 2ab7b43f74
commit 558bea47b7
8 changed files with 73 additions and 3 deletions

View file

@ -2,7 +2,12 @@ pub mod client;
pub mod ipc;
mod logging;
use {bincode::Options, std::marker::PhantomData};
use {
crate::video::Mode,
bincode::Options,
serde::{Deserialize, Serialize},
std::marker::PhantomData,
};
pub const VERSION: u32 = 1;
@ -36,3 +41,20 @@ pub fn bincode_ops() -> impl Options {
pub trait Config {
extern "C" fn configure();
}
#[derive(Serialize, Deserialize, Debug)]
pub struct WireMode {
pub width: i32,
pub height: i32,
pub refresh_millihz: u32,
}
impl WireMode {
pub fn to_mode(self) -> Mode {
Mode {
width: self.width,
height: self.height,
refresh_millihz: self.refresh_millihz,
}
}
}

View file

@ -5,7 +5,7 @@ use {
_private::{
bincode_ops,
ipc::{ClientMessage, InitMessage, Response, ServerMessage},
logging, Config, ConfigEntry, ConfigEntryGen, VERSION,
logging, Config, ConfigEntry, ConfigEntryGen, WireMode, VERSION,
},
exec::Command,
input::{acceleration::AccelProfile, capability::Capability, InputDevice, Seat},
@ -570,6 +570,12 @@ impl Client {
}
}
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 });
modes.into_iter().map(WireMode::to_mode).collect()
}
pub fn connector_size(&self, connector: Connector) -> (i32, i32) {
let res = self.send_with_response(&ClientMessage::ConnectorSize { connector });
get_response!(res, (0, 0), ConnectorSize { width, height });

View file

@ -7,6 +7,7 @@ use {
timer::Timer,
video::{connector_type::ConnectorType, Connector, DrmDevice, GfxApi, Transform},
Axis, Direction, PciId, Workspace,
_private::WireMode,
},
serde::{Deserialize, Serialize},
std::time::Duration,
@ -352,6 +353,9 @@ pub enum ClientMessage<'a> {
SetDoubleClickDistance {
dist: i32,
},
ConnectorModes {
connector: Connector,
},
}
#[derive(Serialize, Deserialize, Debug)]
@ -454,6 +458,9 @@ pub enum Response {
GetWorkspaceCapture {
capture: bool,
},
ConnectorModes {
modes: Vec<WireMode>,
},
}
#[derive(Serialize, Deserialize, Debug)]

View file

@ -21,7 +21,7 @@ use {
/// - width in pixels
/// - height in pixels
/// - refresh rate in mhz.
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
#[derive(Serialize, Deserialize, Copy, Clone, Debug, Hash, Eq, PartialEq)]
pub struct Mode {
pub(crate) width: i32,
pub(crate) height: i32,
@ -112,6 +112,14 @@ impl Connector {
get!(Mode::zeroed()).connector_mode(self)
}
/// Returns the available modes of the connector.
pub fn modes(self) -> Vec<Mode> {
if !self.exists() {
return Vec::new();
}
get!(Vec::new()).connector_modes(self)
}
/// Returns the logical width of the connector.
///
/// The returned value will be different from `mode().width()` if the scale is not 1.