niri: Fix Output global creation and removal
Browse files at this commitdbcd6678778568459c4ad0324ec5cce271821bcdParent: 9fc731c1 changed file +24 -6
- src/niri.rs +24 -6
src/niri.rsmodified+24 -6
| @@ -36,6 +36,7 @@ use smithay::input::pointer::{CursorImageAttributes, CursorImageStatus, MotionEv | ||
| 36 | 36 | use smithay::input::{Seat, SeatState}; |
| 37 | 37 | use smithay::output::Output; |
| 38 | 38 | use smithay::reexports::calloop::generic::Generic; |
| 39 | +use smithay::reexports::calloop::timer::{TimeoutAction, Timer}; | |
| 39 | 40 | use smithay::reexports::calloop::{self, Idle, Interest, LoopHandle, LoopSignal, Mode, PostAction}; |
| 40 | 41 | use smithay::reexports::nix::libc::CLOCK_MONOTONIC; |
| 41 | 42 | use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel::WmCapabilities; |
| @@ -583,6 +584,8 @@ impl Niri { | ||
| 583 | 584 | } |
| 584 | 585 | |
| 585 | 586 | pub fn add_output(&mut self, output: Output, refresh_interval: Option<Duration>) { |
| 587 | + let global = output.create_global::<State>(&self.display_handle); | |
| 588 | + | |
| 586 | 589 | let x = self |
| 587 | 590 | .global_space |
| 588 | 591 | .outputs() |
| @@ -595,7 +598,7 @@ impl Niri { | ||
| 595 | 598 | self.monitor_set.add_output(output.clone()); |
| 596 | 599 | |
| 597 | 600 | let state = OutputState { |
| 598 | - global: output.create_global::<State>(&self.display_handle), | |
| 601 | + global, | |
| 599 | 602 | queued_redraw: None, |
| 600 | 603 | waiting_for_vblank: false, |
| 601 | 604 | frame_clock: FrameClock::new(refresh_interval), |
| @@ -605,16 +608,31 @@ impl Niri { | ||
| 605 | 608 | } |
| 606 | 609 | |
| 607 | 610 | pub fn remove_output(&mut self, output: &Output) { |
| 608 | - let mut state = self.output_state.remove(output).unwrap(); | |
| 609 | - self.display_handle.remove_global::<State>(state.global); | |
| 611 | + self.monitor_set.remove_output(output); | |
| 612 | + self.global_space.unmap_output(output); | |
| 613 | + // FIXME: reposition outputs so they are adjacent. | |
| 610 | 614 | |
| 615 | + let mut state = self.output_state.remove(output).unwrap(); | |
| 611 | 616 | if let Some(idle) = state.queued_redraw.take() { |
| 612 | 617 | idle.cancel(); |
| 613 | 618 | } |
| 614 | 619 | |
| 615 | - self.monitor_set.remove_output(output); | |
| 616 | - self.global_space.unmap_output(output); | |
| 617 | - // FIXME: reposition outputs so they are adjacent. | |
| 620 | + // Disable the output global and remove some time later to give the clients some time to | |
| 621 | + // process it. | |
| 622 | + let global = state.global; | |
| 623 | + self.display_handle.disable_global::<State>(global.clone()); | |
| 624 | + self.event_loop | |
| 625 | + .insert_source( | |
| 626 | + Timer::from_duration(Duration::from_secs(10)), | |
| 627 | + move |_, _, data| { | |
| 628 | + data.state | |
| 629 | + .niri | |
| 630 | + .display_handle | |
| 631 | + .remove_global::<State>(global.clone()); | |
| 632 | + TimeoutAction::Drop | |
| 633 | + }, | |
| 634 | + ) | |
| 635 | + .unwrap(); | |
| 618 | 636 | } |
| 619 | 637 | |
| 620 | 638 | pub fn output_resized(&mut self, output: Output) { |