config: tell the config about drm devices
This commit is contained in:
parent
99fcd63438
commit
e27cf29693
23 changed files with 581 additions and 50 deletions
|
|
@ -9,12 +9,12 @@ use {
|
|||
},
|
||||
drm::{
|
||||
connector_type::{ConnectorType, CON_UNKNOWN},
|
||||
Connector, Mode,
|
||||
Connector, DrmDevice, Mode,
|
||||
},
|
||||
input::{acceleration::AccelProfile, capability::Capability, InputDevice, Seat},
|
||||
keyboard::keymap::Keymap,
|
||||
theme::Color,
|
||||
Axis, Command, Direction, LogLevel, ModifiedKeySym, Timer, Workspace,
|
||||
Axis, Command, Direction, LogLevel, ModifiedKeySym, PciId, Timer, Workspace,
|
||||
},
|
||||
std::{
|
||||
cell::{Cell, RefCell},
|
||||
|
|
@ -40,6 +40,8 @@ pub(crate) struct Client {
|
|||
on_connector_connected: RefCell<Option<Rc<dyn Fn(Connector)>>>,
|
||||
on_graphics_initialized: Cell<Option<Box<dyn FnOnce()>>>,
|
||||
on_new_connector: RefCell<Option<Rc<dyn Fn(Connector)>>>,
|
||||
on_new_drm_device: RefCell<Option<Rc<dyn Fn(DrmDevice)>>>,
|
||||
on_del_drm_device: RefCell<Option<Rc<dyn Fn(DrmDevice)>>>,
|
||||
bufs: RefCell<Vec<Vec<u8>>>,
|
||||
reload: Cell<bool>,
|
||||
}
|
||||
|
|
@ -124,6 +126,8 @@ pub unsafe extern "C" fn init(
|
|||
on_connector_connected: Default::default(),
|
||||
on_graphics_initialized: Default::default(),
|
||||
on_new_connector: Default::default(),
|
||||
on_new_drm_device: Default::default(),
|
||||
on_del_drm_device: Default::default(),
|
||||
bufs: Default::default(),
|
||||
reload: Cell::new(false),
|
||||
});
|
||||
|
|
@ -400,6 +404,36 @@ impl Client {
|
|||
self.send(&ClientMessage::ConnectorSetPosition { connector, x, y });
|
||||
}
|
||||
|
||||
pub fn device_connectors(&self, device: DrmDevice) -> Vec<Connector> {
|
||||
let res = self.send_with_response(&ClientMessage::GetDeviceConnectors { device });
|
||||
get_response!(res, vec![], GetDeviceConnectors, connectors);
|
||||
connectors
|
||||
}
|
||||
|
||||
pub fn drm_device_syspath(&self, device: DrmDevice) -> String {
|
||||
let res = self.send_with_response(&ClientMessage::GetDrmDeviceSyspath { device });
|
||||
get_response!(res, String::new(), GetDrmDeviceSyspath, syspath);
|
||||
syspath
|
||||
}
|
||||
|
||||
pub fn drm_device_vendor(&self, device: DrmDevice) -> String {
|
||||
let res = self.send_with_response(&ClientMessage::GetDrmDeviceVendor { device });
|
||||
get_response!(res, String::new(), GetDrmDeviceVendor, vendor);
|
||||
vendor
|
||||
}
|
||||
|
||||
pub fn drm_device_model(&self, device: DrmDevice) -> String {
|
||||
let res = self.send_with_response(&ClientMessage::GetDrmDeviceModel { device });
|
||||
get_response!(res, String::new(), GetDrmDeviceModel, model);
|
||||
model
|
||||
}
|
||||
|
||||
pub fn drm_device_pci_id(&self, device: DrmDevice) -> PciId {
|
||||
let res = self.send_with_response(&ClientMessage::GetDrmDevicePciId { device });
|
||||
get_response!(res, Default::default(), GetDrmDevicePciId, pci_id);
|
||||
pci_id
|
||||
}
|
||||
|
||||
pub fn connector_connected(&self, connector: Connector) -> bool {
|
||||
let res = self.send_with_response(&ClientMessage::ConnectorConnected { connector });
|
||||
get_response!(res, false, ConnectorConnected, connected);
|
||||
|
|
@ -429,6 +463,20 @@ impl Client {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn drm_devices(&self) -> Vec<DrmDevice> {
|
||||
let res = self.send_with_response(&ClientMessage::GetDrmDevices);
|
||||
get_response!(res, vec![], GetDrmDevices, devices);
|
||||
devices
|
||||
}
|
||||
|
||||
pub fn on_new_drm_device<F: Fn(DrmDevice) + 'static>(&self, f: F) {
|
||||
*self.on_new_drm_device.borrow_mut() = Some(Rc::new(f));
|
||||
}
|
||||
|
||||
pub fn on_del_drm_device<F: Fn(DrmDevice) + 'static>(&self, f: F) {
|
||||
*self.on_del_drm_device.borrow_mut() = Some(Rc::new(f));
|
||||
}
|
||||
|
||||
pub fn on_new_connector<F: Fn(Connector) + 'static>(&self, f: F) {
|
||||
*self.on_new_connector.borrow_mut() = Some(Rc::new(f));
|
||||
}
|
||||
|
|
@ -591,6 +639,18 @@ impl Client {
|
|||
ServerMessage::Clear => {
|
||||
// only used by test config
|
||||
}
|
||||
ServerMessage::NewDrmDev { device } => {
|
||||
let handler = self.on_new_drm_device.borrow_mut();
|
||||
if let Some(handler) = handler.deref() {
|
||||
handler(device);
|
||||
}
|
||||
}
|
||||
ServerMessage::DelDrmDev { device } => {
|
||||
let handler = self.on_del_drm_device.borrow_mut();
|
||||
if let Some(handler) = handler.deref() {
|
||||
handler(device);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
use {
|
||||
crate::{
|
||||
drm::{connector_type::ConnectorType, Connector},
|
||||
drm::{connector_type::ConnectorType, Connector, DrmDevice},
|
||||
input::{acceleration::AccelProfile, capability::Capability, InputDevice, Seat},
|
||||
keyboard::{keymap::Keymap, mods::Modifiers, syms::KeySym},
|
||||
theme::Color,
|
||||
Axis, Direction, LogLevel, Timer, Workspace,
|
||||
Axis, Direction, LogLevel, PciId, Timer, Workspace,
|
||||
},
|
||||
bincode::{BorrowDecode, Decode, Encode},
|
||||
std::time::Duration,
|
||||
|
|
@ -46,6 +46,12 @@ pub enum ServerMessage {
|
|||
timer: Timer,
|
||||
},
|
||||
Clear,
|
||||
NewDrmDev {
|
||||
device: DrmDevice,
|
||||
},
|
||||
DelDrmDev {
|
||||
device: DrmDevice,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Encode, BorrowDecode, Debug)]
|
||||
|
|
@ -241,6 +247,22 @@ pub enum ClientMessage<'a> {
|
|||
seat: Seat,
|
||||
},
|
||||
Reload,
|
||||
GetDeviceConnectors {
|
||||
device: DrmDevice,
|
||||
},
|
||||
GetDrmDeviceSyspath {
|
||||
device: DrmDevice,
|
||||
},
|
||||
GetDrmDeviceVendor {
|
||||
device: DrmDevice,
|
||||
},
|
||||
GetDrmDeviceModel {
|
||||
device: DrmDevice,
|
||||
},
|
||||
GetDrmDevices,
|
||||
GetDrmDevicePciId {
|
||||
device: DrmDevice,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Encode, Decode, Debug)]
|
||||
|
|
@ -303,6 +325,24 @@ pub enum Response {
|
|||
GetFullscreen {
|
||||
fullscreen: bool,
|
||||
},
|
||||
GetDeviceConnectors {
|
||||
connectors: Vec<Connector>,
|
||||
},
|
||||
GetDrmDeviceSyspath {
|
||||
syspath: String,
|
||||
},
|
||||
GetDrmDeviceVendor {
|
||||
vendor: String,
|
||||
},
|
||||
GetDrmDeviceModel {
|
||||
model: String,
|
||||
},
|
||||
GetDrmDevices {
|
||||
devices: Vec<DrmDevice>,
|
||||
},
|
||||
GetDrmDevicePciId {
|
||||
pci_id: PciId,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Encode, Decode, Debug)]
|
||||
|
|
|
|||
|
|
@ -1,9 +1,12 @@
|
|||
use {
|
||||
crate::drm::connector_type::{
|
||||
ConnectorType, CON_9PIN_DIN, CON_COMPONENT, CON_COMPOSITE, CON_DISPLAY_PORT, CON_DPI,
|
||||
CON_DSI, CON_DVIA, CON_DVID, CON_DVII, CON_EDP, CON_EMBEDDED_WINDOW, CON_HDMIA, CON_HDMIB,
|
||||
CON_LVDS, CON_SPI, CON_SVIDEO, CON_TV, CON_UNKNOWN, CON_USB, CON_VGA, CON_VIRTUAL,
|
||||
CON_WRITEBACK,
|
||||
crate::{
|
||||
drm::connector_type::{
|
||||
ConnectorType, CON_9PIN_DIN, CON_COMPONENT, CON_COMPOSITE, CON_DISPLAY_PORT, CON_DPI,
|
||||
CON_DSI, CON_DVIA, CON_DVID, CON_DVII, CON_EDP, CON_EMBEDDED_WINDOW, CON_HDMIA,
|
||||
CON_HDMIB, CON_LVDS, CON_SPI, CON_SVIDEO, CON_TV, CON_UNKNOWN, CON_USB, CON_VGA,
|
||||
CON_VIRTUAL, CON_WRITEBACK,
|
||||
},
|
||||
PciId,
|
||||
},
|
||||
bincode::{Decode, Encode},
|
||||
std::str::FromStr,
|
||||
|
|
@ -88,6 +91,18 @@ impl Connector {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn drm_devices() -> Vec<DrmDevice> {
|
||||
get!().drm_devices()
|
||||
}
|
||||
|
||||
pub fn on_new_drm_device<F: Fn(DrmDevice) + 'static>(f: F) {
|
||||
get!().on_new_drm_device(f)
|
||||
}
|
||||
|
||||
pub fn on_drm_device_removed<F: Fn(DrmDevice) + 'static>(f: F) {
|
||||
get!().on_del_drm_device(f)
|
||||
}
|
||||
|
||||
pub fn on_new_connector<F: Fn(Connector) + 'static>(f: F) {
|
||||
get!().on_new_connector(f)
|
||||
}
|
||||
|
|
@ -186,3 +201,28 @@ pub mod connector_type {
|
|||
pub const CON_USB: ConnectorType = ConnectorType(20);
|
||||
pub const CON_EMBEDDED_WINDOW: ConnectorType = ConnectorType(u32::MAX);
|
||||
}
|
||||
|
||||
#[derive(Encode, Decode, Copy, Clone, Debug, Hash, Eq, PartialEq)]
|
||||
pub struct DrmDevice(pub u64);
|
||||
|
||||
impl DrmDevice {
|
||||
pub fn connectors(self) -> Vec<Connector> {
|
||||
get!().device_connectors(self)
|
||||
}
|
||||
|
||||
pub fn syspath(self) -> String {
|
||||
get!().drm_device_syspath(self)
|
||||
}
|
||||
|
||||
pub fn vendor(self) -> String {
|
||||
get!().drm_device_vendor(self)
|
||||
}
|
||||
|
||||
pub fn model(self) -> String {
|
||||
get!().drm_device_model(self)
|
||||
}
|
||||
|
||||
pub fn pci_id(self) -> PciId {
|
||||
get!().drm_device_pci_id(self)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -156,9 +156,7 @@ pub fn get_seats() -> Vec<Seat> {
|
|||
}
|
||||
|
||||
pub fn input_devices() -> Vec<InputDevice> {
|
||||
let mut res = vec![];
|
||||
(|| res = get!().get_input_devices(None))();
|
||||
res
|
||||
get!().get_input_devices(None)
|
||||
}
|
||||
|
||||
pub fn remove_all_seats() {}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,11 @@
|
|||
use {
|
||||
crate::keyboard::{keymap::Keymap, ModifiedKeySym},
|
||||
bincode::{Decode, Encode},
|
||||
std::{collections::HashMap, time::Duration},
|
||||
std::{
|
||||
collections::HashMap,
|
||||
fmt::{Debug, Display, Formatter},
|
||||
time::Duration,
|
||||
},
|
||||
};
|
||||
|
||||
#[macro_use]
|
||||
|
|
@ -129,3 +133,15 @@ pub fn reload() {
|
|||
pub fn is_reload() -> bool {
|
||||
get!(false).is_reload()
|
||||
}
|
||||
|
||||
#[derive(Encode, Decode, Debug, Copy, Clone, Hash, Eq, PartialEq, Default)]
|
||||
pub struct PciId {
|
||||
pub vendor: u32,
|
||||
pub model: u32,
|
||||
}
|
||||
|
||||
impl Display for PciId {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{:04x}:{:04x}", self.vendor, self.model)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue