screencast: Emit MonitorsChanged
Browse files at this commitab9706cb30c26dafe46c807f0cf073e594c84ef0Parent: 05f2a373 changed files +51 -8
- src/backend/tty.rs +10 -6
- src/dbus/mutter_display_config.rs +3 -2
- src/niri.rs +38 -0
src/backend/tty.rsmodified+10 -6
| @@ -710,13 +710,8 @@ impl Tty { | ||
| 710 | 710 | let sequence_delta_plot_name = |
| 711 | 711 | tracy_client::PlotName::new_leak(format!("{output_name} sequence delta")); |
| 712 | 712 | |
| 713 | - self.enabled_outputs | |
| 714 | - .lock() | |
| 715 | - .unwrap() | |
| 716 | - .insert(output_name.clone(), output.clone()); | |
| 717 | - | |
| 718 | 713 | let surface = Surface { |
| 719 | - name: output_name, | |
| 714 | + name: output_name.clone(), | |
| 720 | 715 | compositor, |
| 721 | 716 | dmabuf_feedback, |
| 722 | 717 | vblank_frame: None, |
| @@ -730,6 +725,13 @@ impl Tty { | ||
| 730 | 725 | |
| 731 | 726 | niri.add_output(output.clone(), Some(refresh_interval(mode))); |
| 732 | 727 | |
| 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 | + | |
| 733 | 735 | // Power on all monitors if necessary and queue a redraw on the new one. |
| 734 | 736 | niri.event_loop.insert_idle(move |state| { |
| 735 | 737 | state.niri.activate_monitors(&state.backend); |
| @@ -769,6 +771,8 @@ impl Tty { | ||
| 769 | 771 | }; |
| 770 | 772 | |
| 771 | 773 | self.enabled_outputs.lock().unwrap().remove(&surface.name); |
| 774 | + #[cfg(feature = "dbus")] | |
| 775 | + niri.on_enabled_outputs_changed(); | |
| 772 | 776 | } |
| 773 | 777 | |
| 774 | 778 | fn on_vblank( |
src/dbus/mutter_display_config.rsmodified+3 -2
| @@ -5,7 +5,7 @@ use serde::Serialize; | ||
| 5 | 5 | use smithay::output::Output; |
| 6 | 6 | use zbus::fdo::RequestNameFlags; |
| 7 | 7 | use zbus::zvariant::{self, OwnedValue, Type}; |
| 8 | -use zbus::{dbus_interface, fdo}; | |
| 8 | +use zbus::{dbus_interface, fdo, SignalContext}; | |
| 9 | 9 | |
| 10 | 10 | use super::Start; |
| 11 | 11 | |
| @@ -112,7 +112,8 @@ impl DisplayConfig { | ||
| 112 | 112 | Ok((0, monitors, logical_monitors, HashMap::new())) |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | - // FIXME: monitors-changed signal. | |
| 115 | + #[dbus_interface(signal)] | |
| 116 | + pub async fn monitors_changed(ctxt: &SignalContext<'_>) -> zbus::Result<()>; | |
| 116 | 117 | } |
| 117 | 118 | |
| 118 | 119 | impl DisplayConfig { |
src/niri.rsmodified+38 -0
| @@ -2759,6 +2759,44 @@ impl Niri { | ||
| 2759 | 2759 | constraint.activate(); |
| 2760 | 2760 | }); |
| 2761 | 2761 | } |
| 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 | + } | |
| 2762 | 2800 | } |
| 2763 | 2801 | |
| 2764 | 2802 | pub struct ClientState { |