Repository navigation
Expand file tree
/
Copy pathmonitor.rs
More file actions
69 lines (58 loc) · 1.99 KB
/
Copy pathmonitor.rs
File metadata and controls
69 lines (58 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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<u32> {
monitor_width(self.entity).map_err(|e| PyRuntimeError::new_err(format!("{e}")))
}
#[getter]
pub fn height(&self) -> PyResult<u32> {
monitor_height(self.entity).map_err(|e| PyRuntimeError::new_err(format!("{e}")))
}
#[getter]
pub fn scale_factor(&self) -> PyResult<f64> {
monitor_scale_factor(self.entity).map_err(|e| PyRuntimeError::new_err(format!("{e}")))
}
#[getter]
pub fn refresh_rate_millihertz(&self) -> PyResult<Option<u32>> {
monitor_refresh_rate_millihertz(self.entity)
.map_err(|e| PyRuntimeError::new_err(format!("{e}")))
}
#[getter]
pub fn name(&self) -> PyResult<Option<String>> {
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<Option<Monitor>> {
let entity = monitor_primary().map_err(|e| PyRuntimeError::new_err(format!("{e}")))?;
Ok(entity.map(|entity| Monitor { entity }))
}
pub fn list() -> PyResult<Vec<Monitor>> {
let entities = monitor_list().map_err(|e| PyRuntimeError::new_err(format!("{e}")))?;
Ok(entities
.into_iter()
.map(|entity| Monitor { entity })
.collect())
}