use bevy::prelude::Entity; use processing::prelude::*; use pyo3::{exceptions::PyRuntimeError, prelude::*}; #[pyclass(unsendable)] pub struct Monitor { pub(crate) entity: Entity, } #[pymethods] impl Monitor { /// Opaque id for this object. pub fn id(&self) -> u64 { self.entity.to_bits() } #[getter] pub fn width(&self) -> PyResult { monitor_width(self.entity).map_err(|e| PyRuntimeError::new_err(format!("{e}"))) } #[getter] pub fn height(&self) -> PyResult { monitor_height(self.entity).map_err(|e| PyRuntimeError::new_err(format!("{e}"))) } #[getter] pub fn scale_factor(&self) -> PyResult { monitor_scale_factor(self.entity).map_err(|e| PyRuntimeError::new_err(format!("{e}"))) } #[getter] pub fn refresh_rate_millihertz(&self) -> PyResult> { monitor_refresh_rate_millihertz(self.entity) .map_err(|e| PyRuntimeError::new_err(format!("{e}"))) } #[getter] pub fn name(&self) -> PyResult> { monitor_name(self.entity).map_err(|e| PyRuntimeError::new_err(format!("{e}"))) } #[getter] pub fn position(&self) -> PyResult<(i32, i32)> { let p = monitor_position(self.entity).map_err(|e| PyRuntimeError::new_err(format!("{e}")))?; Ok((p.x, p.y)) } #[getter] pub fn workarea(&self) -> PyResult<(i32, i32, i32, i32)> { let r = monitor_workarea(self.entity).map_err(|e| PyRuntimeError::new_err(format!("{e}")))?; Ok((r.min.x, r.min.y, r.width(), r.height())) } } pub fn primary() -> PyResult> { let entity = monitor_primary().map_err(|e| PyRuntimeError::new_err(format!("{e}")))?; Ok(entity.map(|entity| Monitor { entity })) } pub fn list() -> PyResult> { let entities = monitor_list().map_err(|e| PyRuntimeError::new_err(format!("{e}")))?; Ok(entities .into_iter() .map(|entity| Monitor { entity }) .collect()) }