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.

View file

@ -375,6 +375,7 @@ fn create_dummy_output(state: &Rc<State>) {
async_event: Default::default(),
}),
0,
Vec::new(),
&backend::Mode {
width: 0,
height: 0,

View file

@ -27,6 +27,7 @@ use {
_private::{
bincode_ops,
ipc::{ClientMessage, Response, ServerMessage},
WireMode,
},
input::{
acceleration::{AccelProfile, ACCEL_PROFILE_ADAPTIVE, ACCEL_PROFILE_FLAT},
@ -694,6 +695,24 @@ impl ConfigProxyHandler {
Ok(())
}
fn handle_connector_modes(&self, connector: Connector) -> Result<(), CphError> {
let connector = self.get_output(connector)?;
self.respond(Response::ConnectorModes {
modes: connector
.node
.global
.modes
.iter()
.map(|m| WireMode {
width: m.width,
height: m.height,
refresh_millihz: m.refresh_rate_millihz,
})
.collect(),
});
Ok(())
}
fn handle_set_cursor_size(&self, seat: Seat, size: i32) -> Result<(), CphError> {
let seat = self.get_seat(seat)?;
if size < 0 {
@ -1369,6 +1388,9 @@ impl ConfigProxyHandler {
ClientMessage::SetDoubleClickDistance { dist } => {
self.handle_set_double_click_distance(dist)
}
ClientMessage::ConnectorModes { connector } => self
.handle_connector_modes(connector)
.wrn("connector_modes")?,
}
Ok(())
}

View file

@ -66,6 +66,7 @@ pub struct WlOutputGlobal {
pub pos: Cell<Rect>,
pub output_id: Rc<OutputId>,
pub mode: Cell<backend::Mode>,
pub modes: Vec<backend::Mode>,
pub node: CloneCell<Option<Rc<OutputNode>>>,
pub width_mm: i32,
pub height_mm: i32,
@ -96,6 +97,7 @@ impl WlOutputGlobal {
state: &Rc<State>,
connector: &Rc<ConnectorData>,
x1: i32,
modes: Vec<backend::Mode>,
mode: &backend::Mode,
manufacturer: &str,
product: &str,
@ -122,6 +124,7 @@ impl WlOutputGlobal {
pos: Cell::new(Rect::new_sized(x1, 0, width, height).unwrap()),
output_id,
mode: Cell::new(*mode),
modes,
node: Default::default(),
width_mm,
height_mm,

View file

@ -94,6 +94,7 @@ impl ConnectorHandler {
&self.state,
&self.data,
x1,
info.modes.clone(),
&info.initial_mode,
&info.manufacturer,
&info.product,