1
0
Fork 0
forked from wry/wry
wry/src/backend.rs

261 lines
7.4 KiB
Rust

use {
crate::{
async_engine::SpawnedFuture,
backend::transaction::{
BackendConnectorTransaction, BackendConnectorTransactionError,
BackendConnectorTransactionType, BackendConnectorTransactionTypeDyn,
},
drm_feedback::DrmFeedback,
format::Format,
gfx_api::{FdSync, GfxApi, GfxFramebuffer},
video::drm::{ConnectorType, DrmConnector, DrmError, DrmVersion},
},
std::{
any::Any,
error::Error,
fmt::{Debug, Display, Formatter},
rc::Rc,
},
uapi::{OwnedFd, c},
};
pub mod transaction;
pub use jay_output_types::{
BackendColorSpace, BackendConnectorState, BackendConnectorStateSerial,
BackendConnectorStateSerials, BackendEotfs, BackendGammaLut, BackendGammaLutElement,
BackendLuminance, CONCAP_CONNECTOR, CONCAP_MODE_SETTING, CONCAP_PHYSICAL_DISPLAY,
ConnectorCaps, ConnectorId, ConnectorIds, DrmDeviceId, DrmDeviceIds, Mode, MonitorInfo,
OutputId,
};
pub use jay_input_types::{
AXIS_120, AxisSource, ButtonState, InputDeviceAccelProfile, InputDeviceCapability,
InputDeviceClickMethod, InputDeviceGroupId, InputDeviceGroupIds, InputDeviceId,
InputDeviceIds, InputEvent, KeyState, Leds, PadButtonState, ScrollAxis, SwitchEvent, TabletId,
TabletIds, TabletInit, TabletPadGroupInit, TabletPadId, TabletPadIds, TabletPadInit,
TabletRingEventSource, TabletStripEventSource, TabletTool2dChange, TabletToolCapability,
TabletToolChanges, TabletToolId, TabletToolIds, TabletToolInit, TabletToolPositionChange,
TabletToolType, TabletToolWheelChange, ToolButtonState, TransformMatrix,
};
pub trait Backend: Any {
fn run(self: Rc<Self>) -> SpawnedFuture<Result<(), Box<dyn Error>>>;
fn clear(&self) {
// nothing
}
fn switch_to(&self, vtnr: u32) {
let _ = vtnr;
}
fn import_environment(&self) -> bool {
false
}
fn supports_presentation_feedback(&self) -> bool {
false
}
fn get_input_fds(&self) -> Vec<Rc<OwnedFd>> {
vec![]
}
}
#[derive(Copy, Clone, Debug)]
pub struct ConnectorKernelId {
pub ty: ConnectorType,
pub idx: u32,
}
impl Display for ConnectorKernelId {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{}-{}", self.ty, self.idx)
}
}
pub trait Connector: Any {
fn id(&self) -> ConnectorId;
fn kernel_id(&self) -> ConnectorKernelId;
fn event(&self) -> Option<ConnectorEvent>;
fn on_change(&self, cb: Rc<dyn Fn()>);
fn damage(&self);
fn drm_dev(&self) -> Option<DrmDeviceId>;
fn effectively_locked(&self) -> bool;
fn state(&self) -> BackendConnectorState;
fn caps(&self) -> ConnectorCaps {
ConnectorCaps::none()
}
fn drm_feedback(&self) -> Option<Rc<DrmFeedback>> {
None
}
fn drm_object_id(&self) -> Option<DrmConnector> {
None
}
fn before_non_desktop_override_update(&self, overrd: Option<bool>) {
let _ = overrd;
}
fn transaction_type(&self) -> Box<dyn BackendConnectorTransactionTypeDyn> {
#[derive(Hash, Eq, PartialEq)]
struct UnimplementedConnectorTransactionType;
impl BackendConnectorTransactionType for UnimplementedConnectorTransactionType {}
Box::new(UnimplementedConnectorTransactionType)
}
fn create_transaction(
&self,
) -> Result<Box<dyn BackendConnectorTransaction>, BackendConnectorTransactionError> {
Err(BackendConnectorTransactionError::TransactionsNotSupported(
self.kernel_id(),
))
}
fn gamma_lut_size(&self) -> Option<u32> {
None
}
fn name(&self) -> String {
self.kernel_id().to_string()
}
}
#[derive(Debug)]
pub enum ConnectorEvent {
Connected(MonitorInfo),
HardwareCursor(Option<Rc<dyn HardwareCursor>>),
Disconnected,
Removed,
Unavailable,
Available,
State(BackendConnectorState),
FormatsChanged(Rc<Vec<&'static Format>>),
}
pub trait HardwareCursorUpdate {
fn set_enabled(&mut self, enabled: bool);
fn get_buffer(&self) -> Rc<dyn GfxFramebuffer>;
fn set_position(&mut self, x: i32, y: i32);
fn swap_buffer(&mut self, sync: Option<FdSync>);
fn size(&self) -> (i32, i32);
}
pub trait HardwareCursor: Debug {
fn damage(&self);
}
pub trait InputDevice {
fn id(&self) -> InputDeviceId;
fn removed(&self) -> bool;
fn event(&self) -> Option<InputEvent>;
fn on_change(&self, cb: Rc<dyn Fn()>);
fn grab(&self, grab: bool);
fn has_capability(&self, cap: InputDeviceCapability) -> bool;
fn left_handed(&self) -> Option<bool> {
None
}
fn set_left_handed(&self, left_handed: bool);
fn accel_profile(&self) -> Option<InputDeviceAccelProfile> {
None
}
fn set_accel_profile(&self, profile: InputDeviceAccelProfile);
fn accel_speed(&self) -> Option<f64> {
None
}
fn set_accel_speed(&self, speed: f64);
fn transform_matrix(&self) -> Option<TransformMatrix> {
None
}
fn set_transform_matrix(&self, matrix: TransformMatrix);
fn calibration_matrix(&self) -> Option<[[f32; 3]; 2]> {
None
}
fn set_calibration_matrix(&self, m: [[f32; 3]; 2]) {
let _ = m;
}
fn name(&self) -> Rc<String>;
fn dev_t(&self) -> Option<c::dev_t> {
None
}
fn tap_enabled(&self) -> Option<bool> {
None
}
fn set_tap_enabled(&self, enabled: bool);
fn drag_enabled(&self) -> Option<bool> {
None
}
fn set_drag_enabled(&self, enabled: bool);
fn drag_lock_enabled(&self) -> Option<bool> {
None
}
fn set_drag_lock_enabled(&self, enabled: bool);
fn natural_scrolling_enabled(&self) -> Option<bool> {
None
}
fn set_natural_scrolling_enabled(&self, enabled: bool);
fn click_method(&self) -> Option<InputDeviceClickMethod> {
None
}
fn set_click_method(&self, method: InputDeviceClickMethod);
fn middle_button_emulation_enabled(&self) -> Option<bool> {
None
}
fn set_middle_button_emulation_enabled(&self, enabled: bool);
fn tablet_info(&self) -> Option<Box<TabletInit>> {
None
}
fn tablet_pad_info(&self) -> Option<Box<TabletPadInit>> {
None
}
fn set_enabled_leds(&self, leds: Leds) {
let _ = leds;
}
}
pub enum BackendEvent {
NewDrmDevice(Rc<dyn BackendDrmDevice>),
NewConnector(Rc<dyn Connector>),
NewInputDevice(Rc<dyn InputDevice>),
DevicesEnumerated,
}
pub enum DrmEvent {
#[expect(dead_code)]
Removed,
GfxApiChanged,
}
pub trait BackendDrmDevice {
fn id(&self) -> DrmDeviceId;
fn event(&self) -> Option<DrmEvent>;
fn on_change(&self, cb: Rc<dyn Fn()>);
fn dev_t(&self) -> c::dev_t;
fn make_render_device(&self);
fn set_gfx_api(&self, api: GfxApi);
fn gtx_api(&self) -> GfxApi;
fn version(&self) -> Result<DrmVersion, DrmError>;
fn set_direct_scanout_enabled(&self, enabled: bool);
fn is_render_device(&self) -> bool;
fn direct_scanout_enabled(&self) -> bool {
false
}
fn gfx_fast_ram_access(&self) -> bool {
false
}
fn create_lease(
self: Rc<Self>,
lessee: Rc<dyn BackendDrmLessee>,
connector_ids: &[ConnectorId],
) {
let _ = lessee;
let _ = connector_ids;
}
fn set_flip_margin(&self, margin: u64) {
let _ = margin;
}
}
pub trait BackendDrmLease {
fn fd(&self) -> &Rc<OwnedFd>;
}
pub trait BackendDrmLessee {
fn created(&self, lease: Rc<dyn BackendDrmLease>);
}