From d52ca23caa4345ddf768da5af24f47eae6fd4738 Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Fri, 8 Sep 2023 17:54:02 +0400 Subject: 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. --- src/dbus/mutter_display_config.rs | 88 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 src/dbus/mutter_display_config.rs (limited to 'src/dbus/mutter_display_config.rs') 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>>, +} + +#[derive(Serialize, Type)] +pub struct Monitor { + names: (String, String, String, String), + modes: Vec, + properties: HashMap, +} + +#[derive(Serialize, Type)] +pub struct Mode { + id: String, + width: i32, + height: i32, + refresh_rate: f64, + preferred_scale: f64, + supported_scales: Vec, + properties: HashMap, +} + +#[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, +} + +#[dbus_interface(name = "org.gnome.Mutter.DisplayConfig")] +impl DisplayConfig { + async fn get_current_state( + &self, + ) -> fdo::Result<( + u32, + Vec, + Vec, + HashMap, + )> { + // Construct the DBus response. + let monitors: Vec = 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>>) -> Self { + Self { connectors } + } +} -- cgit