diff options
| author | Ivan Molodetskikh <yalterz@gmail.com> | 2023-09-08 17:54:02 +0400 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2023-09-08 23:53:56 +0400 |
| commit | d52ca23caa4345ddf768da5af24f47eae6fd4738 (patch) | |
| tree | c0e3f3f4c99b0dfd5bd739e349890081cba2187e /src/dbus/mutter_display_config.rs | |
| parent | bd0ecf917489a84efa51bb1272ca27039256fe21 (diff) | |
| download | niri-d52ca23caa4345ddf768da5af24f47eae6fd4738.tar.gz niri-d52ca23caa4345ddf768da5af24f47eae6fd4738.tar.bz2 niri-d52ca23caa4345ddf768da5af24f47eae6fd4738.zip | |
Add initial monitor screencast portal impl
DmaBuf monitor screencasting through xdg-dekstop-portal-gnome!
Somewhat limited currently, e.g. the cursor is always embedded. But gets
most of the job done.
Diffstat (limited to 'src/dbus/mutter_display_config.rs')
| -rw-r--r-- | src/dbus/mutter_display_config.rs | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/src/dbus/mutter_display_config.rs b/src/dbus/mutter_display_config.rs new file mode 100644 index 00000000..1807f01d --- /dev/null +++ b/src/dbus/mutter_display_config.rs @@ -0,0 +1,88 @@ +use std::collections::HashMap; +use std::sync::{Arc, Mutex}; + +use serde::Serialize; +use smithay::output::Output; +use zbus::zvariant::{OwnedValue, Type}; +use zbus::{dbus_interface, fdo}; + +pub struct DisplayConfig { + connectors: Arc<Mutex<HashMap<String, Output>>>, +} + +#[derive(Serialize, Type)] +pub struct Monitor { + names: (String, String, String, String), + modes: Vec<Mode>, + properties: HashMap<String, OwnedValue>, +} + +#[derive(Serialize, Type)] +pub struct Mode { + id: String, + width: i32, + height: i32, + refresh_rate: f64, + preferred_scale: f64, + supported_scales: Vec<f64>, + properties: HashMap<String, OwnedValue>, +} + +#[derive(Serialize, Type)] +pub struct LogicalMonitor { + x: i32, + y: i32, + scale: f64, + transform: u32, + is_primary: bool, + monitors: Vec<(String, String, String, String)>, + properties: HashMap<String, OwnedValue>, +} + +#[dbus_interface(name = "org.gnome.Mutter.DisplayConfig")] +impl DisplayConfig { + async fn get_current_state( + &self, + ) -> fdo::Result<( + u32, + Vec<Monitor>, + Vec<LogicalMonitor>, + HashMap<String, OwnedValue>, + )> { + // Construct the DBus response. + let monitors: Vec<Monitor> = self + .connectors + .lock() + .unwrap() + .keys() + .map(|c| Monitor { + names: (c.clone(), String::new(), String::new(), String::new()), + modes: vec![], + properties: HashMap::new(), + }) + .collect(); + + let logical_monitors = monitors + .iter() + .map(|m| LogicalMonitor { + x: 0, + y: 0, + scale: 1., + transform: 0, + is_primary: false, + monitors: vec![m.names.clone()], + properties: HashMap::new(), + }) + .collect(); + + Ok((0, monitors, logical_monitors, HashMap::new())) + } + + // FIXME: monitors-changed signal. +} + +impl DisplayConfig { + pub fn new(connectors: Arc<Mutex<HashMap<String, Output>>>) -> Self { + Self { connectors } + } +} |
