Draw the layout as inactive when layer-shell has focus

This commit is contained in:
Ivan Molodetskikh
2024-10-15 10:43:58 +03:00
parent 0c5e046820
commit a13b9298c6
2 changed files with 44 additions and 8 deletions
+19 -3
View File
@@ -211,6 +211,11 @@ pub trait LayoutElement {
pub struct Layout<W: LayoutElement> {
/// Monitors and workspaes in the layout.
monitor_set: MonitorSet<W>,
/// Whether the layout should draw as active.
///
/// This normally indicates that the layout has keyboard focus, but not always. E.g. when the
/// screenshot UI is open, it keeps the layout drawing as active.
is_active: bool,
/// Configurable properties of the layout.
options: Rc<Options>,
}
@@ -354,6 +359,7 @@ impl<W: LayoutElement> Layout<W> {
pub fn with_options(options: Options) -> Self {
Self {
monitor_set: MonitorSet::NoOutputs { workspaces: vec![] },
is_active: true,
options: Rc::new(options),
}
}
@@ -369,6 +375,7 @@ impl<W: LayoutElement> Layout<W> {
Self {
monitor_set: MonitorSet::NoOutputs { workspaces },
is_active: true,
options: opts,
}
}
@@ -1899,7 +1906,8 @@ impl<W: LayoutElement> Layout<W> {
for (idx, mon) in monitors.iter_mut().enumerate() {
if output.map_or(true, |output| mon.output == *output) {
mon.update_render_elements(idx == *active_monitor_idx);
let is_active = self.is_active && idx == *active_monitor_idx;
mon.update_render_elements(is_active);
}
}
}
@@ -2590,9 +2598,11 @@ impl<W: LayoutElement> Layout<W> {
}
}
pub fn refresh(&mut self) {
pub fn refresh(&mut self, is_active: bool) {
let _span = tracy_client::span!("Layout::refresh");
self.is_active = is_active;
match &mut self.monitor_set {
MonitorSet::Normal {
monitors,
@@ -2600,7 +2610,7 @@ impl<W: LayoutElement> Layout<W> {
..
} => {
for (idx, mon) in monitors.iter_mut().enumerate() {
let is_active = idx == *active_monitor_idx;
let is_active = self.is_active && idx == *active_monitor_idx;
for (ws_idx, ws) in mon.workspaces.iter_mut().enumerate() {
ws.refresh(is_active);
@@ -3097,6 +3107,9 @@ mod tests {
id: Option<usize>,
},
Communicate(#[proptest(strategy = "1..=5usize")] usize),
Refresh {
is_active: bool,
},
MoveWorkspaceToOutput(#[proptest(strategy = "1..=5u8")] u8),
ViewOffsetGestureBegin {
#[proptest(strategy = "1..=5usize")]
@@ -3547,6 +3560,9 @@ mod tests {
layout.update_window(&id, None);
}
}
Op::Refresh { is_active } => {
layout.refresh(is_active);
}
Op::MoveWorkspaceToOutput(id) => {
let name = format!("output{id}");
let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else {
+25 -5
View File
@@ -541,14 +541,17 @@ impl State {
self.notify_blocker_cleared();
// These should be called periodically, before flushing the clients.
self.niri.layout.refresh();
self.niri.cursor_manager.check_cursor_image_surface_alive();
self.niri.refresh_pointer_outputs();
self.niri.popups.cleanup();
self.niri.global_space.refresh();
self.niri.refresh_idle_inhibit();
self.refresh_popup_grab();
self.update_keyboard_focus();
// Needs to be called after updating the keyboard focus.
self.niri.refresh_layout();
self.niri.cursor_manager.check_cursor_image_surface_alive();
self.niri.refresh_pointer_outputs();
self.niri.global_space.refresh();
self.niri.refresh_idle_inhibit();
self.refresh_pointer_focus();
foreign_toplevel::refresh(self);
self.niri.refresh_window_rules();
@@ -2825,6 +2828,23 @@ impl Niri {
}
}
pub fn refresh_layout(&mut self) {
let layout_is_active = match &self.keyboard_focus {
KeyboardFocus::Layout { .. } => true,
KeyboardFocus::LayerShell { .. } => false,
// Draw layout as active in these cases to reduce unnecessary window animations.
// There's no confusion because these are both fullscreen modes.
//
// FIXME: when going into the screenshot UI from a layer-shell focus, and then back to
// layer-shell, the layout will briefly draw as active, despite never having focus.
KeyboardFocus::LockScreen { .. } => true,
KeyboardFocus::ScreenshotUi => true,
};
self.layout.refresh(layout_is_active);
}
pub fn refresh_idle_inhibit(&mut self) {
let _span = tracy_client::span!("Niri::refresh_idle_inhibit");