Draw the layout as inactive when layer-shell has focus
Browse files at this commita13b9298c66f45e571533731e2a690a23534df01Parent: 0c5e0462 changed files +43 -7
- src/layout/mod.rs +19 -3
- src/niri.rs +24 -4
src/layout/mod.rsmodified+19 -3
| @@ -211,6 +211,11 @@ pub trait LayoutElement { | ||
| 211 | 211 | pub struct Layout<W: LayoutElement> { |
| 212 | 212 | /// Monitors and workspaes in the layout. |
| 213 | 213 | monitor_set: MonitorSet<W>, |
| 214 | + /// Whether the layout should draw as active. | |
| 215 | + /// | |
| 216 | + /// This normally indicates that the layout has keyboard focus, but not always. E.g. when the | |
| 217 | + /// screenshot UI is open, it keeps the layout drawing as active. | |
| 218 | + is_active: bool, | |
| 214 | 219 | /// Configurable properties of the layout. |
| 215 | 220 | options: Rc<Options>, |
| 216 | 221 | } |
| @@ -354,6 +359,7 @@ impl<W: LayoutElement> Layout<W> { | ||
| 354 | 359 | pub fn with_options(options: Options) -> Self { |
| 355 | 360 | Self { |
| 356 | 361 | monitor_set: MonitorSet::NoOutputs { workspaces: vec![] }, |
| 362 | + is_active: true, | |
| 357 | 363 | options: Rc::new(options), |
| 358 | 364 | } |
| 359 | 365 | } |
| @@ -369,6 +375,7 @@ impl<W: LayoutElement> Layout<W> { | ||
| 369 | 375 | |
| 370 | 376 | Self { |
| 371 | 377 | monitor_set: MonitorSet::NoOutputs { workspaces }, |
| 378 | + is_active: true, | |
| 372 | 379 | options: opts, |
| 373 | 380 | } |
| 374 | 381 | } |
| @@ -1899,7 +1906,8 @@ impl<W: LayoutElement> Layout<W> { | ||
| 1899 | 1906 | |
| 1900 | 1907 | for (idx, mon) in monitors.iter_mut().enumerate() { |
| 1901 | 1908 | if output.map_or(true, |output| mon.output == *output) { |
| 1902 | - mon.update_render_elements(idx == *active_monitor_idx); | |
| 1909 | + let is_active = self.is_active && idx == *active_monitor_idx; | |
| 1910 | + mon.update_render_elements(is_active); | |
| 1903 | 1911 | } |
| 1904 | 1912 | } |
| 1905 | 1913 | } |
| @@ -2590,9 +2598,11 @@ impl<W: LayoutElement> Layout<W> { | ||
| 2590 | 2598 | } |
| 2591 | 2599 | } |
| 2592 | 2600 | |
| 2593 | - pub fn refresh(&mut self) { | |
| 2601 | + pub fn refresh(&mut self, is_active: bool) { | |
| 2594 | 2602 | let _span = tracy_client::span!("Layout::refresh"); |
| 2595 | 2603 | |
| 2604 | + self.is_active = is_active; | |
| 2605 | + | |
| 2596 | 2606 | match &mut self.monitor_set { |
| 2597 | 2607 | MonitorSet::Normal { |
| 2598 | 2608 | monitors, |
| @@ -2600,7 +2610,7 @@ impl<W: LayoutElement> Layout<W> { | ||
| 2600 | 2610 | .. |
| 2601 | 2611 | } => { |
| 2602 | 2612 | for (idx, mon) in monitors.iter_mut().enumerate() { |
| 2603 | - let is_active = idx == *active_monitor_idx; | |
| 2613 | + let is_active = self.is_active && idx == *active_monitor_idx; | |
| 2604 | 2614 | for (ws_idx, ws) in mon.workspaces.iter_mut().enumerate() { |
| 2605 | 2615 | ws.refresh(is_active); |
| 2606 | 2616 | |
| @@ -3097,6 +3107,9 @@ mod tests { | ||
| 3097 | 3107 | id: Option<usize>, |
| 3098 | 3108 | }, |
| 3099 | 3109 | Communicate(#[proptest(strategy = "1..=5usize")] usize), |
| 3110 | + Refresh { | |
| 3111 | + is_active: bool, | |
| 3112 | + }, | |
| 3100 | 3113 | MoveWorkspaceToOutput(#[proptest(strategy = "1..=5u8")] u8), |
| 3101 | 3114 | ViewOffsetGestureBegin { |
| 3102 | 3115 | #[proptest(strategy = "1..=5usize")] |
| @@ -3547,6 +3560,9 @@ mod tests { | ||
| 3547 | 3560 | layout.update_window(&id, None); |
| 3548 | 3561 | } |
| 3549 | 3562 | } |
| 3563 | + Op::Refresh { is_active } => { | |
| 3564 | + layout.refresh(is_active); | |
| 3565 | + } | |
| 3550 | 3566 | Op::MoveWorkspaceToOutput(id) => { |
| 3551 | 3567 | let name = format!("output{id}"); |
| 3552 | 3568 | let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else { |
src/niri.rsmodified+24 -4
| @@ -541,14 +541,17 @@ impl State { | ||
| 541 | 541 | self.notify_blocker_cleared(); |
| 542 | 542 | |
| 543 | 543 | // These should be called periodically, before flushing the clients. |
| 544 | - self.niri.layout.refresh(); | |
| 544 | + self.niri.popups.cleanup(); | |
| 545 | + self.refresh_popup_grab(); | |
| 546 | + self.update_keyboard_focus(); | |
| 547 | + | |
| 548 | + // Needs to be called after updating the keyboard focus. | |
| 549 | + self.niri.refresh_layout(); | |
| 550 | + | |
| 545 | 551 | self.niri.cursor_manager.check_cursor_image_surface_alive(); |
| 546 | 552 | self.niri.refresh_pointer_outputs(); |
| 547 | - self.niri.popups.cleanup(); | |
| 548 | 553 | self.niri.global_space.refresh(); |
| 549 | 554 | self.niri.refresh_idle_inhibit(); |
| 550 | - self.refresh_popup_grab(); | |
| 551 | - self.update_keyboard_focus(); | |
| 552 | 555 | self.refresh_pointer_focus(); |
| 553 | 556 | foreign_toplevel::refresh(self); |
| 554 | 557 | self.niri.refresh_window_rules(); |
| @@ -2825,6 +2828,23 @@ impl Niri { | ||
| 2825 | 2828 | } |
| 2826 | 2829 | } |
| 2827 | 2830 | |
| 2831 | + pub fn refresh_layout(&mut self) { | |
| 2832 | + let layout_is_active = match &self.keyboard_focus { | |
| 2833 | + KeyboardFocus::Layout { .. } => true, | |
| 2834 | + KeyboardFocus::LayerShell { .. } => false, | |
| 2835 | + | |
| 2836 | + // Draw layout as active in these cases to reduce unnecessary window animations. | |
| 2837 | + // There's no confusion because these are both fullscreen modes. | |
| 2838 | + // | |
| 2839 | + // FIXME: when going into the screenshot UI from a layer-shell focus, and then back to | |
| 2840 | + // layer-shell, the layout will briefly draw as active, despite never having focus. | |
| 2841 | + KeyboardFocus::LockScreen { .. } => true, | |
| 2842 | + KeyboardFocus::ScreenshotUi => true, | |
| 2843 | + }; | |
| 2844 | + | |
| 2845 | + self.layout.refresh(layout_is_active); | |
| 2846 | + } | |
| 2847 | + | |
| 2828 | 2848 | pub fn refresh_idle_inhibit(&mut self) { |
| 2829 | 2849 | let _span = tracy_client::span!("Niri::refresh_idle_inhibit"); |
| 2830 | 2850 |