forge
Explore
Log in

Don't you dare go Hollow

Expose more info in DisplayConfig impl

Browse files at this commit

e276c906bf4bea27dc8173815ff373d04c20caafIvan MolodetskikhParent: 571768a
Needed for the new xdp-gnome.
src/backend/mod.rsmodified+3 -9
@@ -31,6 +31,8 @@ pub enum RenderResult {
31 Skipped,31 Skipped,
32 }32 }
33 33
34+pub type IpcOutputMap = HashMap<String, (niri_ipc::Output, Option<Output>)>;
35+
34 impl Backend {36 impl Backend {
35 pub fn init(&mut self, niri: &mut Niri) {37 pub fn init(&mut self, niri: &mut Niri) {
36 match self {38 match self {
@@ -110,21 +112,13 @@ impl Backend {
110 }112 }
111 }113 }
112 114
113- pub fn ipc_outputs(&self) -> Arc<Mutex<HashMap<String, niri_ipc::Output>>> {115+ pub fn ipc_outputs(&self) -> Arc<Mutex<IpcOutputMap>> {
114 match self {116 match self {
115 Backend::Tty(tty) => tty.ipc_outputs(),117 Backend::Tty(tty) => tty.ipc_outputs(),
116 Backend::Winit(winit) => winit.ipc_outputs(),118 Backend::Winit(winit) => winit.ipc_outputs(),
117 }119 }
118 }120 }
119 121
120- #[cfg_attr(not(feature = "dbus"), allow(unused))]
121- pub fn enabled_outputs(&self) -> Arc<Mutex<HashMap<String, Output>>> {
122- match self {
123- Backend::Tty(tty) => tty.enabled_outputs(),
124- Backend::Winit(winit) => winit.enabled_outputs(),
125- }
126- }
127-
128 #[cfg(feature = "xdp-gnome-screencast")]122 #[cfg(feature = "xdp-gnome-screencast")]
129 pub fn gbm_device(123 pub fn gbm_device(
130 &self,124 &self,
src/backend/tty.rsmodified+21 -28
@@ -55,7 +55,7 @@ use smithay_drm_extras::edid::EdidInfo;
55 use wayland_protocols::wp::linux_dmabuf::zv1::server::zwp_linux_dmabuf_feedback_v1::TrancheFlags;55 use wayland_protocols::wp::linux_dmabuf::zv1::server::zwp_linux_dmabuf_feedback_v1::TrancheFlags;
56 use wayland_protocols::wp::presentation_time::server::wp_presentation_feedback;56 use wayland_protocols::wp::presentation_time::server::wp_presentation_feedback;
57 57
58-use super::RenderResult;58+use super::{IpcOutputMap, RenderResult};
59 use crate::frame_clock::FrameClock;59 use crate::frame_clock::FrameClock;
60 use crate::niri::{Niri, RedrawState, State};60 use crate::niri::{Niri, RedrawState, State};
61 use crate::render_helpers::renderer::AsGlesRenderer;61 use crate::render_helpers::renderer::AsGlesRenderer;
@@ -84,8 +84,7 @@ pub struct Tty {
84 update_output_config_on_resume: bool,84 update_output_config_on_resume: bool,
85 // Whether the debug tinting is enabled.85 // Whether the debug tinting is enabled.
86 debug_tint: bool,86 debug_tint: bool,
87- ipc_outputs: Arc<Mutex<HashMap<String, niri_ipc::Output>>>,87+ ipc_outputs: Arc<Mutex<IpcOutputMap>>,
88- enabled_outputs: Arc<Mutex<HashMap<String, Output>>>,
89 }88 }
90 89
91 pub type TtyRenderer<'render> = MultiRenderer<90 pub type TtyRenderer<'render> = MultiRenderer<
@@ -293,7 +292,6 @@ impl Tty {
293 update_output_config_on_resume: false,292 update_output_config_on_resume: false,
294 debug_tint: false,293 debug_tint: false,
295 ipc_outputs: Arc::new(Mutex::new(HashMap::new())),294 ipc_outputs: Arc::new(Mutex::new(HashMap::new())),
296- enabled_outputs: Arc::new(Mutex::new(HashMap::new())),
297 })295 })
298 }296 }
299 297
@@ -430,7 +428,7 @@ impl Tty {
430 self.on_output_config_changed(niri);428 self.on_output_config_changed(niri);
431 }429 }
432 430
433- self.refresh_ipc_outputs();431+ self.refresh_ipc_outputs(niri);
434 432
435 niri.idle_notifier_state.notify_activity(&niri.seat);433 niri.idle_notifier_state.notify_activity(&niri.seat);
436 niri.monitors_active = true;434 niri.monitors_active = true;
@@ -580,7 +578,7 @@ impl Tty {
580 }578 }
581 }579 }
582 580
583- self.refresh_ipc_outputs();581+ self.refresh_ipc_outputs(niri);
584 }582 }
585 583
586 fn device_removed(&mut self, device_id: dev_t, niri: &mut Niri) {584 fn device_removed(&mut self, device_id: dev_t, niri: &mut Niri) {
@@ -644,7 +642,7 @@ impl Tty {
644 self.gpu_manager.as_mut().remove_node(&device.render_node);642 self.gpu_manager.as_mut().remove_node(&device.render_node);
645 niri.event_loop.remove(device.token);643 niri.event_loop.remove(device.token);
646 644
647- self.refresh_ipc_outputs();645+ self.refresh_ipc_outputs(niri);
648 }646 }
649 647
650 fn connector_connected(648 fn connector_connected(
@@ -874,13 +872,6 @@ impl Tty {
874 872
875 niri.add_output(output.clone(), Some(refresh_interval(mode)));873 niri.add_output(output.clone(), Some(refresh_interval(mode)));
876 874
877- self.enabled_outputs
878- .lock()
879- .unwrap()
880- .insert(output_name, output.clone());
881- #[cfg(feature = "dbus")]
882- niri.on_enabled_outputs_changed();
883-
884 // Power on all monitors if necessary and queue a redraw on the new one.875 // Power on all monitors if necessary and queue a redraw on the new one.
885 niri.event_loop.insert_idle(move |state| {876 niri.event_loop.insert_idle(move |state| {
886 state.niri.activate_monitors(&mut state.backend);877 state.niri.activate_monitors(&mut state.backend);
@@ -918,10 +909,6 @@ impl Tty {
918 } else {909 } else {
919 error!("missing output for crtc {crtc:?}");910 error!("missing output for crtc {crtc:?}");
920 };911 };
921-
922- self.enabled_outputs.lock().unwrap().remove(&surface.name);
923- #[cfg(feature = "dbus")]
924- niri.on_enabled_outputs_changed();
925 }912 }
926 913
927 fn on_vblank(914 fn on_vblank(
@@ -1341,12 +1328,12 @@ impl Tty {
1341 }1328 }
1342 }1329 }
1343 1330
1344- fn refresh_ipc_outputs(&self) {1331+ fn refresh_ipc_outputs(&self, niri: &mut Niri) {
1345 let _span = tracy_client::span!("Tty::refresh_ipc_outputs");1332 let _span = tracy_client::span!("Tty::refresh_ipc_outputs");
1346 1333
1347 let mut ipc_outputs = HashMap::new();1334 let mut ipc_outputs = HashMap::new();
1348 1335
1349- for device in self.devices.values() {1336+ for (node, device) in &self.devices {
1350 for (connector, crtc) in device.drm_scanner.crtcs() {1337 for (connector, crtc) in device.drm_scanner.crtcs() {
1351 let connector_name = format!(1338 let connector_name = format!(
1352 "{}-{}",1339 "{}-{}",
@@ -1397,7 +1384,16 @@ impl Tty {
1397 }1384 }
1398 }1385 }
1399 1386
1400- let output = niri_ipc::Output {1387+ let output = niri
1388+ .global_space
1389+ .outputs()
1390+ .find(|output| {
1391+ let tty_state: &TtyOutputState = output.user_data().get().unwrap();
1392+ tty_state.node == *node && tty_state.crtc == crtc
1393+ })
1394+ .cloned();
1395+
1396+ let ipc_output = niri_ipc::Output {
1401 name: connector_name.clone(),1397 name: connector_name.clone(),
1402 make,1398 make,
1403 model,1399 model,
@@ -1406,22 +1402,19 @@ impl Tty {
1406 current_mode,1402 current_mode,
1407 };1403 };
1408 1404
1409- ipc_outputs.insert(connector_name, output);1405+ ipc_outputs.insert(connector_name, (ipc_output, output));
1410 }1406 }
1411 }1407 }
1412 1408
1413 let mut guard = self.ipc_outputs.lock().unwrap();1409 let mut guard = self.ipc_outputs.lock().unwrap();
1414 *guard = ipc_outputs;1410 *guard = ipc_outputs;
1411+ niri.ipc_outputs_changed = true;
1415 }1412 }
1416 1413
1417- pub fn ipc_outputs(&self) -> Arc<Mutex<HashMap<String, niri_ipc::Output>>> {1414+ pub fn ipc_outputs(&self) -> Arc<Mutex<IpcOutputMap>> {
1418 self.ipc_outputs.clone()1415 self.ipc_outputs.clone()
1419 }1416 }
1420 1417
1421- pub fn enabled_outputs(&self) -> Arc<Mutex<HashMap<String, Output>>> {
1422- self.enabled_outputs.clone()
1423- }
1424-
1425 #[cfg(feature = "xdp-gnome-screencast")]1418 #[cfg(feature = "xdp-gnome-screencast")]
1426 pub fn primary_gbm_device(&self) -> Option<GbmDevice<DrmDeviceFd>> {1419 pub fn primary_gbm_device(&self) -> Option<GbmDevice<DrmDeviceFd>> {
1427 self.devices.get(&self.primary_node).map(|d| d.gbm.clone())1420 self.devices.get(&self.primary_node).map(|d| d.gbm.clone())
@@ -1585,7 +1578,7 @@ impl Tty {
1585 }1578 }
1586 }1579 }
1587 1580
1588- self.refresh_ipc_outputs();1581+ self.refresh_ipc_outputs(niri);
1589 }1582 }
1590 1583
1591 pub fn get_device_from_node(&mut self, node: DrmNode) -> Option<&mut OutputDevice> {1584 pub fn get_device_from_node(&mut self, node: DrmNode) -> Option<&mut OutputDevice> {
src/backend/winit.rsmodified+20 -27
@@ -17,7 +17,7 @@ use smithay::reexports::wayland_protocols::wp::presentation_time::server::wp_pre
17 use smithay::reexports::winit::dpi::LogicalSize;17 use smithay::reexports::winit::dpi::LogicalSize;
18 use smithay::reexports::winit::window::WindowBuilder;18 use smithay::reexports::winit::window::WindowBuilder;
19 19
20-use super::RenderResult;20+use super::{IpcOutputMap, RenderResult};
21 use crate::niri::{Niri, RedrawState, State};21 use crate::niri::{Niri, RedrawState, State};
22 use crate::render_helpers::{shaders, RenderTarget};22 use crate::render_helpers::{shaders, RenderTarget};
23 use crate::utils::get_monotonic_time;23 use crate::utils::get_monotonic_time;
@@ -27,8 +27,7 @@ pub struct Winit {
27 output: Output,27 output: Output,
28 backend: WinitGraphicsBackend<GlesRenderer>,28 backend: WinitGraphicsBackend<GlesRenderer>,
29 damage_tracker: OutputDamageTracker,29 damage_tracker: OutputDamageTracker,
30- ipc_outputs: Arc<Mutex<HashMap<String, niri_ipc::Output>>>,30+ ipc_outputs: Arc<Mutex<IpcOutputMap>>,
31- enabled_outputs: Arc<Mutex<HashMap<String, Output>>>,
32 }31 }
33 32
34 impl Winit {33 impl Winit {
@@ -62,23 +61,21 @@ impl Winit {
62 let physical_properties = output.physical_properties();61 let physical_properties = output.physical_properties();
63 let ipc_outputs = Arc::new(Mutex::new(HashMap::from([(62 let ipc_outputs = Arc::new(Mutex::new(HashMap::from([(
64 "winit".to_owned(),63 "winit".to_owned(),
65- niri_ipc::Output {64+ (
66- name: output.name(),65+ niri_ipc::Output {
67- make: physical_properties.make,66+ name: output.name(),
68- model: physical_properties.model,67+ make: physical_properties.make,
69- physical_size: None,68+ model: physical_properties.model,
70- modes: vec![niri_ipc::Mode {69+ physical_size: None,
71- width: backend.window_size().w.clamp(0, u16::MAX as i32) as u16,70+ modes: vec![niri_ipc::Mode {
72- height: backend.window_size().h.clamp(0, u16::MAX as i32) as u16,71+ width: backend.window_size().w.clamp(0, u16::MAX as i32) as u16,
73- refresh_rate: 60_000,72+ height: backend.window_size().h.clamp(0, u16::MAX as i32) as u16,
74- }],73+ refresh_rate: 60_000,
75- current_mode: Some(0),74+ }],
76- },75+ current_mode: Some(0),
77- )])));76+ },
78-77+ Some(output.clone()),
79- let enabled_outputs = Arc::new(Mutex::new(HashMap::from([(78+ ),
80- "winit".to_owned(),
81- output.clone(),
82 )])));79 )])));
83 80
84 let damage_tracker = OutputDamageTracker::from_output(&output);81 let damage_tracker = OutputDamageTracker::from_output(&output);
@@ -99,9 +96,10 @@ impl Winit {
99 96
100 {97 {
101 let mut ipc_outputs = winit.ipc_outputs.lock().unwrap();98 let mut ipc_outputs = winit.ipc_outputs.lock().unwrap();
102- let mode = &mut ipc_outputs.get_mut("winit").unwrap().modes[0];99+ let mode = &mut ipc_outputs.get_mut("winit").unwrap().0.modes[0];
103 mode.width = size.w.clamp(0, u16::MAX as i32) as u16;100 mode.width = size.w.clamp(0, u16::MAX as i32) as u16;
104 mode.height = size.h.clamp(0, u16::MAX as i32) as u16;101 mode.height = size.h.clamp(0, u16::MAX as i32) as u16;
102+ state.niri.ipc_outputs_changed = true;
105 }103 }
106 104
107 state.niri.output_resized(&winit.output);105 state.niri.output_resized(&winit.output);
@@ -119,7 +117,6 @@ impl Winit {
119 backend,117 backend,
120 damage_tracker,118 damage_tracker,
121 ipc_outputs,119 ipc_outputs,
122- enabled_outputs,
123 })120 })
124 }121 }
125 122
@@ -230,11 +227,7 @@ impl Winit {
230 }227 }
231 }228 }
232 229
233- pub fn ipc_outputs(&self) -> Arc<Mutex<HashMap<String, niri_ipc::Output>>> {230+ pub fn ipc_outputs(&self) -> Arc<Mutex<IpcOutputMap>> {
234 self.ipc_outputs.clone()231 self.ipc_outputs.clone()
235 }232 }
236-
237- pub fn enabled_outputs(&self) -> Arc<Mutex<HashMap<String, Output>>> {
238- self.enabled_outputs.clone()
239- }
240 }233 }
src/dbus/mod.rsmodified+2 -2
@@ -47,7 +47,7 @@ impl DBusServers {
47 }47 }
48 48
49 if is_session_instance || config.debug.dbus_interfaces_in_non_session_instances {49 if is_session_instance || config.debug.dbus_interfaces_in_non_session_instances {
50- let display_config = DisplayConfig::new(backend.enabled_outputs());50+ let display_config = DisplayConfig::new(backend.ipc_outputs());
51 dbus.conn_display_config = try_start(display_config);51 dbus.conn_display_config = try_start(display_config);
52 52
53 let screen_saver = ScreenSaver::new(niri.is_fdo_idle_inhibited.clone());53 let screen_saver = ScreenSaver::new(niri.is_fdo_idle_inhibited.clone());
@@ -80,7 +80,7 @@ impl DBusServers {
80 }80 }
81 })81 })
82 .unwrap();82 .unwrap();
83- let screen_cast = ScreenCast::new(backend.enabled_outputs(), to_niri);83+ let screen_cast = ScreenCast::new(backend.ipc_outputs(), to_niri);
84 dbus.conn_screen_cast = try_start(screen_cast);84 dbus.conn_screen_cast = try_start(screen_cast);
85 } else {85 } else {
86 warn!("disabling screencast support because we couldn't start PipeWire");86 warn!("disabling screencast support because we couldn't start PipeWire");
src/dbus/mutter_display_config.rsmodified+74 -28
@@ -2,15 +2,16 @@ use std::collections::HashMap;
2 use std::sync::{Arc, Mutex};2 use std::sync::{Arc, Mutex};
3 3
4 use serde::Serialize;4 use serde::Serialize;
5-use smithay::output::Output;5+use smithay::utils::Transform;
6 use zbus::fdo::RequestNameFlags;6 use zbus::fdo::RequestNameFlags;
7 use zbus::zvariant::{self, OwnedValue, Type};7 use zbus::zvariant::{self, OwnedValue, Type};
8 use zbus::{dbus_interface, fdo, SignalContext};8 use zbus::{dbus_interface, fdo, SignalContext};
9 9
10 use super::Start;10 use super::Start;
11+use crate::backend::IpcOutputMap;
11 12
12 pub struct DisplayConfig {13 pub struct DisplayConfig {
13- enabled_outputs: Arc<Mutex<HashMap<String, Output>>>,14+ ipc_outputs: Arc<Mutex<IpcOutputMap>>,
14 }15 }
15 16
16 #[derive(Serialize, Type)]17 #[derive(Serialize, Type)]
@@ -53,12 +54,17 @@ impl DisplayConfig {
53 HashMap<String, OwnedValue>,54 HashMap<String, OwnedValue>,
54 )> {55 )> {
55 // Construct the DBus response.56 // Construct the DBus response.
56- let mut monitors: Vec<Monitor> = self57+ let mut monitors: Vec<(Monitor, LogicalMonitor)> = self
57- .enabled_outputs58+ .ipc_outputs
58 .lock()59 .lock()
59 .unwrap()60 .unwrap()
60- .keys()61+ .iter()
61- .map(|c| {62+ // Take only enabled outputs.
63+ .filter_map(|(c, (ipc, output))| {
64+ ipc.current_mode?;
65+ output.as_ref().map(move |output| (c, (ipc, output)))
66+ })
67+ .map(|(c, (ipc, output))| {
62 // Loosely matches the check in Mutter.68 // Loosely matches the check in Mutter.
63 let is_laptop_panel = matches!(c.get(..4), Some("eDP-" | "LVDS" | "DSI-"));69 let is_laptop_panel = matches!(c.get(..4), Some("eDP-" | "LVDS" | "DSI-"));
64 70
@@ -78,38 +84,78 @@ impl DisplayConfig {
78 OwnedValue::from(is_laptop_panel),84 OwnedValue::from(is_laptop_panel),
79 );85 );
80 86
81- Monitor {87+ let mut modes: Vec<Mode> = ipc
88+ .modes
89+ .iter()
90+ .map(|m| {
91+ let niri_ipc::Mode {
92+ width,
93+ height,
94+ refresh_rate,
95+ } = *m;
96+ let refresh = refresh_rate as f64 / 1000.;
97+
98+ Mode {
99+ id: format!("{width}x{height}@{refresh:.3}"),
100+ width: i32::from(width),
101+ height: i32::from(height),
102+ refresh_rate: refresh,
103+ preferred_scale: 1.,
104+ supported_scales: vec![1., 2., 3.],
105+ properties: HashMap::new(),
106+ }
107+ })
108+ .collect();
109+ modes[ipc.current_mode.unwrap()]
110+ .properties
111+ .insert(String::from("is-current"), OwnedValue::from(true));
112+
113+ let monitor = Monitor {
82 names: (c.clone(), String::new(), String::new(), serial),114 names: (c.clone(), String::new(), String::new(), serial),
83- modes: vec![],115+ modes,
84 properties,116 properties,
85- }117+ };
118+
119+ let loc = output.current_location();
120+
121+ let transform = match output.current_transform() {
122+ Transform::Normal => 0,
123+ Transform::_90 => 1,
124+ Transform::_180 => 2,
125+ Transform::_270 => 3,
126+ Transform::Flipped => 4,
127+ Transform::Flipped90 => 5,
128+ Transform::Flipped180 => 6,
129+ Transform::Flipped270 => 7,
130+ };
131+
132+ let logical_monitor = LogicalMonitor {
133+ x: loc.x,
134+ y: loc.y,
135+ scale: output.current_scale().fractional_scale(),
136+ transform,
137+ is_primary: false,
138+ monitors: vec![monitor.names.clone()],
139+ properties: HashMap::new(),
140+ };
141+
142+ (monitor, logical_monitor)
86 })143 })
87 .collect();144 .collect();
88 145
89 // Sort the built-in monitor first, then by connector name.146 // Sort the built-in monitor first, then by connector name.
90 monitors.sort_unstable_by(|a, b| {147 monitors.sort_unstable_by(|a, b| {
91- let a_is_builtin = a.properties.contains_key("display-name");148+ let a_is_builtin = a.0.properties.contains_key("display-name");
92- let b_is_builtin = b.properties.contains_key("display-name");149+ let b_is_builtin = b.0.properties.contains_key("display-name");
93 a_is_builtin150 a_is_builtin
94 .cmp(&b_is_builtin)151 .cmp(&b_is_builtin)
95 .reverse()152 .reverse()
96- .then_with(|| a.names.0.cmp(&b.names.0))153+ .then_with(|| a.0.names.0.cmp(&b.0.names.0))
97 });154 });
98 155
99- let logical_monitors = monitors156+ let (monitors, logical_monitors) = monitors.into_iter().unzip();
100- .iter()157+ let properties = HashMap::from([(String::from("layout-mode"), OwnedValue::from(1u32))]);
101- .map(|m| LogicalMonitor {158+ Ok((0, monitors, logical_monitors, properties))
102- x: 0,
103- y: 0,
104- scale: 1.,
105- transform: 0,
106- is_primary: false,
107- monitors: vec![m.names.clone()],
108- properties: HashMap::new(),
109- })
110- .collect();
111-
112- Ok((0, monitors, logical_monitors, HashMap::new()))
113 }159 }
114 160
115 #[dbus_interface(signal)]161 #[dbus_interface(signal)]
@@ -117,8 +163,8 @@ impl DisplayConfig {
117 }163 }
118 164
119 impl DisplayConfig {165 impl DisplayConfig {
120- pub fn new(enabled_outputs: Arc<Mutex<HashMap<String, Output>>>) -> Self {166+ pub fn new(ipc_outputs: Arc<Mutex<IpcOutputMap>>) -> Self {
121- Self { enabled_outputs }167+ Self { ipc_outputs }
122 }168 }
123 }169 }
124 170
src/dbus/mutter_screen_cast.rsmodified+10 -12
@@ -10,11 +10,12 @@ use zbus::zvariant::{DeserializeDict, OwnedObjectPath, SerializeDict, Type, Valu
10 use zbus::{dbus_interface, fdo, InterfaceRef, ObjectServer, SignalContext};10 use zbus::{dbus_interface, fdo, InterfaceRef, ObjectServer, SignalContext};
11 11
12 use super::Start;12 use super::Start;
13+use crate::backend::IpcOutputMap;
13 use crate::utils::output_size;14 use crate::utils::output_size;
14 15
15 #[derive(Clone)]16 #[derive(Clone)]
16 pub struct ScreenCast {17 pub struct ScreenCast {
17- enabled_outputs: Arc<Mutex<HashMap<String, Output>>>,18+ ipc_outputs: Arc<Mutex<IpcOutputMap>>,
18 to_niri: calloop::channel::Sender<ScreenCastToNiri>,19 to_niri: calloop::channel::Sender<ScreenCastToNiri>,
19 #[allow(clippy::type_complexity)]20 #[allow(clippy::type_complexity)]
20 sessions: Arc<Mutex<Vec<(Session, InterfaceRef<Session>)>>>,21 sessions: Arc<Mutex<Vec<(Session, InterfaceRef<Session>)>>>,
@@ -23,7 +24,7 @@ pub struct ScreenCast {
23 #[derive(Clone)]24 #[derive(Clone)]
24 pub struct Session {25 pub struct Session {
25 id: usize,26 id: usize,
26- enabled_outputs: Arc<Mutex<HashMap<String, Output>>>,27+ ipc_outputs: Arc<Mutex<IpcOutputMap>>,
27 to_niri: calloop::channel::Sender<ScreenCastToNiri>,28 to_niri: calloop::channel::Sender<ScreenCastToNiri>,
28 #[allow(clippy::type_complexity)]29 #[allow(clippy::type_complexity)]
29 streams: Arc<Mutex<Vec<(Stream, InterfaceRef<Stream>)>>>,30 streams: Arc<Mutex<Vec<(Stream, InterfaceRef<Stream>)>>>,
@@ -92,11 +93,7 @@ impl ScreenCast {
92 let path = format!("/org/gnome/Mutter/ScreenCast/Session/u{}", session_id);93 let path = format!("/org/gnome/Mutter/ScreenCast/Session/u{}", session_id);
93 let path = OwnedObjectPath::try_from(path).unwrap();94 let path = OwnedObjectPath::try_from(path).unwrap();
94 95
95- let session = Session::new(96+ let session = Session::new(session_id, self.ipc_outputs.clone(), self.to_niri.clone());
96- session_id,
97- self.enabled_outputs.clone(),
98- self.to_niri.clone(),
99- );
100 match server.at(&path, session.clone()).await {97 match server.at(&path, session.clone()).await {
101 Ok(true) => {98 Ok(true) => {
102 let iface = server.interface(&path).await.unwrap();99 let iface = server.interface(&path).await.unwrap();
@@ -163,7 +160,8 @@ impl Session {
163 ) -> fdo::Result<OwnedObjectPath> {160 ) -> fdo::Result<OwnedObjectPath> {
164 debug!(connector, ?properties, "record_monitor");161 debug!(connector, ?properties, "record_monitor");
165 162
166- let Some(output) = self.enabled_outputs.lock().unwrap().get(connector).cloned() else {163+ let Some((_, Some(output))) = self.ipc_outputs.lock().unwrap().get(connector).cloned()
164+ else {
167 return Err(fdo::Error::Failed("no such monitor".to_owned()));165 return Err(fdo::Error::Failed("no such monitor".to_owned()));
168 };166 };
169 167
@@ -212,11 +210,11 @@ impl Stream {
212 210
213 impl ScreenCast {211 impl ScreenCast {
214 pub fn new(212 pub fn new(
215- enabled_outputs: Arc<Mutex<HashMap<String, Output>>>,213+ ipc_outputs: Arc<Mutex<IpcOutputMap>>,
216 to_niri: calloop::channel::Sender<ScreenCastToNiri>,214 to_niri: calloop::channel::Sender<ScreenCastToNiri>,
217 ) -> Self {215 ) -> Self {
218 Self {216 Self {
219- enabled_outputs,217+ ipc_outputs,
220 to_niri,218 to_niri,
221 sessions: Arc::new(Mutex::new(vec![])),219 sessions: Arc::new(Mutex::new(vec![])),
222 }220 }
@@ -241,12 +239,12 @@ impl Start for ScreenCast {
241 impl Session {239 impl Session {
242 pub fn new(240 pub fn new(
243 id: usize,241 id: usize,
244- enabled_outputs: Arc<Mutex<HashMap<String, Output>>>,242+ ipc_outputs: Arc<Mutex<IpcOutputMap>>,
245 to_niri: calloop::channel::Sender<ScreenCastToNiri>,243 to_niri: calloop::channel::Sender<ScreenCastToNiri>,
246 ) -> Self {244 ) -> Self {
247 Self {245 Self {
248 id,246 id,
249- enabled_outputs,247+ ipc_outputs,
250 streams: Arc::new(Mutex::new(vec![])),248 streams: Arc::new(Mutex::new(vec![])),
251 to_niri,249 to_niri,
252 }250 }
src/ipc/server.rsmodified+7 -3
@@ -1,4 +1,3 @@
1-use std::collections::HashMap;
2 use std::os::unix::net::{UnixListener, UnixStream};1 use std::os::unix::net::{UnixListener, UnixStream};
3 use std::path::PathBuf;2 use std::path::PathBuf;
4 use std::sync::{Arc, Mutex};3 use std::sync::{Arc, Mutex};
@@ -14,6 +13,7 @@ use smithay::reexports::calloop::generic::Generic;
14 use smithay::reexports::calloop::{Interest, LoopHandle, Mode, PostAction};13 use smithay::reexports::calloop::{Interest, LoopHandle, Mode, PostAction};
15 use smithay::reexports::rustix::fs::unlink;14 use smithay::reexports::rustix::fs::unlink;
16 15
16+use crate::backend::IpcOutputMap;
17 use crate::niri::State;17 use crate::niri::State;
18 18
19 pub struct IpcServer {19 pub struct IpcServer {
@@ -22,7 +22,7 @@ pub struct IpcServer {
22 22
23 struct ClientCtx {23 struct ClientCtx {
24 event_loop: LoopHandle<'static, State>,24 event_loop: LoopHandle<'static, State>,
25- ipc_outputs: Arc<Mutex<HashMap<String, niri_ipc::Output>>>,25+ ipc_outputs: Arc<Mutex<IpcOutputMap>>,
26 }26 }
27 27
28 impl IpcServer {28 impl IpcServer {
@@ -125,7 +125,11 @@ fn process(ctx: &ClientCtx, buf: &str) -> anyhow::Result<Response> {
125 125
126 let response = match request {126 let response = match request {
127 Request::Outputs => {127 Request::Outputs => {
128- let ipc_outputs = ctx.ipc_outputs.lock().unwrap().clone();128+ let ipc_outputs = ctx.ipc_outputs.lock().unwrap();
129+ let ipc_outputs = ipc_outputs
130+ .iter()
131+ .map(|(name, (ipc, _))| (name.clone(), ipc.clone()))
132+ .collect();
129 Response::Outputs(ipc_outputs)133 Response::Outputs(ipc_outputs)
130 }134 }
131 Request::Action(action) => {135 Request::Action(action) => {
src/niri.rsmodified+16 -2
@@ -228,6 +228,7 @@ pub struct Niri {
228 pub inhibit_power_key_fd: Option<zbus::zvariant::OwnedFd>,228 pub inhibit_power_key_fd: Option<zbus::zvariant::OwnedFd>,
229 229
230 pub ipc_server: Option<IpcServer>,230 pub ipc_server: Option<IpcServer>,
231+ pub ipc_outputs_changed: bool,
231 232
232 // Casts are dropped before PipeWire to prevent a double-free (yay).233 // Casts are dropped before PipeWire to prevent a double-free (yay).
233 pub casts: Vec<Cast>,234 pub casts: Vec<Cast>,
@@ -458,6 +459,7 @@ impl State {
458 self.refresh_pointer_focus();459 self.refresh_pointer_focus();
459 foreign_toplevel::refresh(self);460 foreign_toplevel::refresh(self);
460 self.niri.refresh_window_rules();461 self.niri.refresh_window_rules();
462+ self.niri.check_ipc_output_changed();
461 }463 }
462 464
463 pub fn move_cursor(&mut self, location: Point<f64, Logical>) {465 pub fn move_cursor(&mut self, location: Point<f64, Logical>) {
@@ -916,6 +918,7 @@ impl State {
916 Some(output::Scale::Integer(scale)),918 Some(output::Scale::Integer(scale)),
917 None,919 None,
918 );920 );
921+ self.niri.ipc_outputs_changed = true;
919 resized_outputs.push(output.clone());922 resized_outputs.push(output.clone());
920 }923 }
921 }924 }
@@ -1352,6 +1355,7 @@ impl Niri {
1352 inhibit_power_key_fd: None,1355 inhibit_power_key_fd: None,
1353 1356
1354 ipc_server,1357 ipc_server,
1358+ ipc_outputs_changed: false,
1355 1359
1356 pipewire,1360 pipewire,
1357 casts: vec![],1361 casts: vec![],
@@ -1490,6 +1494,7 @@ impl Niri {
1490 new_position.x, new_position.y1494 new_position.x, new_position.y
1491 );1495 );
1492 output.change_current_state(None, None, None, Some(new_position));1496 output.change_current_state(None, None, None, Some(new_position));
1497+ self.ipc_outputs_changed = true;
1493 self.queue_redraw(&output);1498 self.queue_redraw(&output);
1494 }1499 }
1495 }1500 }
@@ -3433,9 +3438,18 @@ impl Niri {
3433 });3438 });
3434 }3439 }
3435 3440
3441+ pub fn check_ipc_output_changed(&mut self) {
3442+ if self.ipc_outputs_changed {
3443+ self.ipc_outputs_changed = false;
3444+
3445+ #[cfg(feature = "dbus")]
3446+ self.on_ipc_outputs_changed();
3447+ }
3448+ }
3449+
3436 #[cfg(feature = "dbus")]3450 #[cfg(feature = "dbus")]
3437- pub fn on_enabled_outputs_changed(&self) {3451+ pub fn on_ipc_outputs_changed(&self) {
3438- let _span = tracy_client::span!("Niri::on_enabled_outputs_changed");3452+ let _span = tracy_client::span!("Niri::on_ipc_outputs_changed");
3439 3453
3440 let Some(dbus) = &self.dbus else { return };3454 let Some(dbus) = &self.dbus else { return };
3441 let Some(conn_display_config) = dbus.conn_display_config.clone() else {3455 let Some(conn_display_config) = dbus.conn_display_config.clone() else {