forge
Explore
Log in

Don't you dare go Hollow

screencast: Emit MonitorsChanged

Browse files at this commit

ab9706cb30c26dafe46c807f0cf073e594c84ef0Ivan MolodetskikhParent: 05f2a37
src/backend/tty.rsmodified+10 -6
@@ -710,13 +710,8 @@ impl Tty {
710710 let sequence_delta_plot_name =
711711 tracy_client::PlotName::new_leak(format!("{output_name} sequence delta"));
712712
713- self.enabled_outputs
714- .lock()
715- .unwrap()
716- .insert(output_name.clone(), output.clone());
717-
718713 let surface = Surface {
719- name: output_name,
714+ name: output_name.clone(),
720715 compositor,
721716 dmabuf_feedback,
722717 vblank_frame: None,
@@ -730,6 +725,13 @@ impl Tty {
730725
731726 niri.add_output(output.clone(), Some(refresh_interval(mode)));
732727
728+ self.enabled_outputs
729+ .lock()
730+ .unwrap()
731+ .insert(output_name, output.clone());
732+ #[cfg(feature = "dbus")]
733+ niri.on_enabled_outputs_changed();
734+
733735 // Power on all monitors if necessary and queue a redraw on the new one.
734736 niri.event_loop.insert_idle(move |state| {
735737 state.niri.activate_monitors(&state.backend);
@@ -769,6 +771,8 @@ impl Tty {
769771 };
770772
771773 self.enabled_outputs.lock().unwrap().remove(&surface.name);
774+ #[cfg(feature = "dbus")]
775+ niri.on_enabled_outputs_changed();
772776 }
773777
774778 fn on_vblank(
src/dbus/mutter_display_config.rsmodified+3 -2
@@ -5,7 +5,7 @@ use serde::Serialize;
55 use smithay::output::Output;
66 use zbus::fdo::RequestNameFlags;
77 use zbus::zvariant::{self, OwnedValue, Type};
8-use zbus::{dbus_interface, fdo};
8+use zbus::{dbus_interface, fdo, SignalContext};
99
1010 use super::Start;
1111
@@ -112,7 +112,8 @@ impl DisplayConfig {
112112 Ok((0, monitors, logical_monitors, HashMap::new()))
113113 }
114114
115- // FIXME: monitors-changed signal.
115+ #[dbus_interface(signal)]
116+ pub async fn monitors_changed(ctxt: &SignalContext<'_>) -> zbus::Result<()>;
116117 }
117118
118119 impl DisplayConfig {
src/niri.rsmodified+38 -0
@@ -2759,6 +2759,44 @@ impl Niri {
27592759 constraint.activate();
27602760 });
27612761 }
2762+
2763+ #[cfg(feature = "dbus")]
2764+ pub fn on_enabled_outputs_changed(&self) {
2765+ let _span = tracy_client::span!("Niri::on_enabled_outputs_changed");
2766+
2767+ let Some(dbus) = &self.dbus else { return };
2768+ let Some(conn_display_config) = dbus.conn_display_config.clone() else {
2769+ return;
2770+ };
2771+
2772+ let res = thread::Builder::new()
2773+ .name("DisplayConfig MonitorsChanged Emitter".to_owned())
2774+ .spawn(move || {
2775+ use crate::dbus::mutter_display_config::DisplayConfig;
2776+ let _span = tracy_client::span!("MonitorsChanged");
2777+ let iface = match conn_display_config
2778+ .object_server()
2779+ .interface::<_, DisplayConfig>("/org/gnome/Mutter/DisplayConfig")
2780+ {
2781+ Ok(iface) => iface,
2782+ Err(err) => {
2783+ warn!("error getting DisplayConfig interface: {err:?}");
2784+ return;
2785+ }
2786+ };
2787+
2788+ async_io::block_on(async move {
2789+ if let Err(err) = DisplayConfig::monitors_changed(iface.signal_context()).await
2790+ {
2791+ warn!("error emitting MonitorsChanged: {err:?}");
2792+ }
2793+ });
2794+ });
2795+
2796+ if let Err(err) = res {
2797+ warn!("error spawning a thread to send MonitorsChanged: {err:?}");
2798+ }
2799+ }
27622800 }
27632801
27642802 pub struct ClientState {