forge
Explore
Log in

Don't you dare go Hollow

Draw the layout as inactive when layer-shell has focus

Browse files at this commit

a13b9298c66f45e571533731e2a690a23534df01Ivan MolodetskikhParent: 0c5e046
src/layout/mod.rsmodified+19 -3
@@ -211,6 +211,11 @@ pub trait LayoutElement {
211211 pub struct Layout<W: LayoutElement> {
212212 /// Monitors and workspaes in the layout.
213213 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,
214219 /// Configurable properties of the layout.
215220 options: Rc<Options>,
216221 }
@@ -354,6 +359,7 @@ impl<W: LayoutElement> Layout<W> {
354359 pub fn with_options(options: Options) -> Self {
355360 Self {
356361 monitor_set: MonitorSet::NoOutputs { workspaces: vec![] },
362+ is_active: true,
357363 options: Rc::new(options),
358364 }
359365 }
@@ -369,6 +375,7 @@ impl<W: LayoutElement> Layout<W> {
369375
370376 Self {
371377 monitor_set: MonitorSet::NoOutputs { workspaces },
378+ is_active: true,
372379 options: opts,
373380 }
374381 }
@@ -1899,7 +1906,8 @@ impl<W: LayoutElement> Layout<W> {
18991906
19001907 for (idx, mon) in monitors.iter_mut().enumerate() {
19011908 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);
19031911 }
19041912 }
19051913 }
@@ -2590,9 +2598,11 @@ impl<W: LayoutElement> Layout<W> {
25902598 }
25912599 }
25922600
2593- pub fn refresh(&mut self) {
2601+ pub fn refresh(&mut self, is_active: bool) {
25942602 let _span = tracy_client::span!("Layout::refresh");
25952603
2604+ self.is_active = is_active;
2605+
25962606 match &mut self.monitor_set {
25972607 MonitorSet::Normal {
25982608 monitors,
@@ -2600,7 +2610,7 @@ impl<W: LayoutElement> Layout<W> {
26002610 ..
26012611 } => {
26022612 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;
26042614 for (ws_idx, ws) in mon.workspaces.iter_mut().enumerate() {
26052615 ws.refresh(is_active);
26062616
@@ -3097,6 +3107,9 @@ mod tests {
30973107 id: Option<usize>,
30983108 },
30993109 Communicate(#[proptest(strategy = "1..=5usize")] usize),
3110+ Refresh {
3111+ is_active: bool,
3112+ },
31003113 MoveWorkspaceToOutput(#[proptest(strategy = "1..=5u8")] u8),
31013114 ViewOffsetGestureBegin {
31023115 #[proptest(strategy = "1..=5usize")]
@@ -3547,6 +3560,9 @@ mod tests {
35473560 layout.update_window(&id, None);
35483561 }
35493562 }
3563+ Op::Refresh { is_active } => {
3564+ layout.refresh(is_active);
3565+ }
35503566 Op::MoveWorkspaceToOutput(id) => {
35513567 let name = format!("output{id}");
35523568 let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else {
src/niri.rsmodified+24 -4
@@ -541,14 +541,17 @@ impl State {
541541 self.notify_blocker_cleared();
542542
543543 // 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+
545551 self.niri.cursor_manager.check_cursor_image_surface_alive();
546552 self.niri.refresh_pointer_outputs();
547- self.niri.popups.cleanup();
548553 self.niri.global_space.refresh();
549554 self.niri.refresh_idle_inhibit();
550- self.refresh_popup_grab();
551- self.update_keyboard_focus();
552555 self.refresh_pointer_focus();
553556 foreign_toplevel::refresh(self);
554557 self.niri.refresh_window_rules();
@@ -2825,6 +2828,23 @@ impl Niri {
28252828 }
28262829 }
28272830
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+
28282848 pub fn refresh_idle_inhibit(&mut self) {
28292849 let _span = tracy_client::span!("Niri::refresh_idle_inhibit");
28302850