1
0
Fork 0
forked from wry/wry

config: add Connector::set_enabled

This commit is contained in:
Julian Orth 2022-07-26 21:52:52 +02:00
parent 4bbca6abdc
commit 30aa6de35c
8 changed files with 61 additions and 4 deletions

View file

@ -440,6 +440,10 @@ impl Client {
self.send(&ClientMessage::ConnectorSetPosition { connector, x, y });
}
pub fn connector_set_enabled(&self, connector: Connector, enabled: bool) {
self.send(&ClientMessage::ConnectorSetEnabled { connector, enabled });
}
pub fn device_connectors(&self, device: DrmDevice) -> Vec<Connector> {
let res = self.send_with_response(&ClientMessage::GetDeviceConnectors { device });
get_response!(res, vec![], GetDeviceConnectors { connectors });

View file

@ -308,6 +308,10 @@ pub enum ClientMessage<'a> {
DisablePointerConstraint {
seat: Seat,
},
ConnectorSetEnabled {
connector: Connector,
enabled: bool,
},
}
#[derive(Encode, Decode, Debug)]

View file

@ -147,6 +147,17 @@ impl Connector {
}
get!().connector_set_position(self, x, y);
}
/// Enables or disables the connector.
///
/// By default, all connectors are enabled.
pub fn set_enabled(self, enabled: bool) {
if !self.exists() {
log::warn!("set_enabled called on a connector that does not exist");
return;
}
get!().connector_set_enabled(self, enabled);
}
}
/// Returns all available DRM devices.

View file

@ -81,6 +81,7 @@ pub trait Connector {
fn on_change(&self, cb: Rc<dyn Fn()>);
fn damage(&self);
fn drm_dev(&self) -> Option<DrmDeviceId>;
fn set_enabled(&self, enabled: bool);
}
#[derive(Debug)]

View file

@ -52,4 +52,8 @@ impl Connector for DummyOutput {
fn drm_dev(&self) -> Option<DrmDeviceId> {
None
}
fn set_enabled(&self, _enabled: bool) {
// nothing
}
}

View file

@ -153,6 +153,8 @@ pub struct MetalConnector {
pub buffers: CloneCell<Option<Rc<[RenderBuffer; 2]>>>,
pub next_buffer: NumCell<usize>,
pub enabled: Cell<bool>,
pub can_present: Cell<bool>,
pub has_damage: Cell<bool>,
pub cursor_changed: Cell<bool>,
@ -300,7 +302,7 @@ impl MetalConnector {
fn connected(&self) -> bool {
let dd = self.display.borrow_mut();
dd.connection == ConnectorStatus::Connected && self.primary_plane.get().is_some()
self.enabled.get() && dd.connection == ConnectorStatus::Connected && self.primary_plane.get().is_some()
}
fn send_event(&self, event: ConnectorEvent) {
@ -434,6 +436,19 @@ impl Connector for MetalConnector {
fn drm_dev(&self) -> Option<DrmDeviceId> {
Some(self.dev.id)
}
fn set_enabled(&self, enabled: bool) {
if self.enabled.replace(enabled) != enabled {
if self.display.borrow_mut().connection == ConnectorStatus::Connected {
if let Some(dev) = self.backend.device_holder.drm_devices.get(&self.dev.devnum) {
if let Err(e) = self.backend.handle_drm_change_(&dev, true) {
dev.unprocessed_change.set(true);
log::error!("Could not dis/enable connector: {}", ErrorFmt(e));
}
}
}
}
}
}
#[derive(Debug)]
@ -533,6 +548,7 @@ fn create_connector(
events: Default::default(),
buffers: Default::default(),
next_buffer: Default::default(),
enabled: Cell::new(true),
can_present: Cell::new(true),
has_damage: Cell::new(true),
primary_plane: Default::default(),
@ -959,7 +975,7 @@ impl MetalBackend {
let mut old = c.display.borrow_mut();
mem::swap(old.deref_mut(), &mut dd);
if c.connect_sent.get() {
if old.connection != ConnectorStatus::Connected || !old.is_same_monitor(&dd) {
if !c.enabled.get() || old.connection != ConnectorStatus::Connected || !old.is_same_monitor(&dd) {
c.send_event(ConnectorEvent::Disconnected);
c.connect_sent.set(false);
} else if preserve_any {
@ -1451,7 +1467,7 @@ impl MetalBackend {
for connector in dev.connectors.lock().values() {
let dd = connector.display.borrow_mut();
if dd.connection != ConnectorStatus::Connected {
if !connector.enabled.get() || dd.connection != ConnectorStatus::Connected {
if dd.crtc_id.value.get().is_some() {
log::debug!("Connector is not connected but has an assigned crtc");
return false;
@ -1586,7 +1602,7 @@ impl MetalBackend {
changes: &mut Change,
) -> Result<(), MetalError> {
let dd = connector.display.borrow_mut();
if dd.connection != ConnectorStatus::Connected {
if !connector.enabled.get() || dd.connection != ConnectorStatus::Connected {
return Ok(());
}
let crtc = 'crtc: {

View file

@ -968,6 +968,10 @@ impl Connector for XOutput {
fn drm_dev(&self) -> Option<DrmDeviceId> {
None
}
fn set_enabled(&self, _enabled: bool) {
// nothing
}
}
struct XSeat {

View file

@ -686,6 +686,16 @@ impl ConfigProxyHandler {
Ok(())
}
fn handle_connector_set_enabled(
&self,
connector: Connector,
enabled: bool,
) -> Result<(), CphError> {
let connector = self.get_connector(connector)?;
connector.connector.set_enabled(enabled);
Ok(())
}
fn handle_get_connector(
&self,
ty: jay_config::video::connector_type::ConnectorType,
@ -1125,6 +1135,9 @@ impl ConfigProxyHandler {
ClientMessage::ConnectorSetPosition { connector, x, y } => self
.handle_connector_set_position(connector, x, y)
.wrn("connector_set_position")?,
ClientMessage::ConnectorSetEnabled { connector, enabled } => self
.handle_connector_set_enabled(connector, enabled)
.wrn("connector_set_enabled")?,
ClientMessage::Close { seat } => self.handle_close(seat).wrn("close")?,
ClientMessage::SetStatus { status } => self.handle_set_status(status),
ClientMessage::GetTimer { name } => self.handle_get_timer(name).wrn("get_timer")?,