Reimplement focus-previous-window with MRU focus timestamps
Browse files at this commitaecbd679e39a321495964995fa1e37d84bd91ddfParent: 3769e5d2 changed files +13 -30
- src/input/mod.rs +13 -1
- src/niri.rs +0 -29
src/input/mod.rsmodified+13 -1
| @@ -779,7 +779,19 @@ impl State { | |||
| 779 | self.niri.queue_redraw_all(); | 779 | self.niri.queue_redraw_all(); |
| 780 | } | 780 | } |
| 781 | Action::FocusWindowPrevious => { | 781 | Action::FocusWindowPrevious => { |
| 782 | - if let Some(window) = self.niri.previously_focused_window.clone() { | 782 | + let current = self.niri.layout.focus().map(|win| win.id()); |
| 783 | + if let Some(window) = self | ||
| 784 | + .niri | ||
| 785 | + .layout | ||
| 786 | + .windows() | ||
| 787 | + .map(|(_, win)| win) | ||
| 788 | + .filter(|win| Some(win.id()) != current) | ||
| 789 | + .max_by_key(|win| win.get_focus_timestamp()) | ||
| 790 | + .map(|win| win.window.clone()) | ||
| 791 | + { | ||
| 792 | + // Commit current focus so repeated focus-window-previous works as expected. | ||
| 793 | + self.niri.mru_apply_keyboard_commit(); | ||
| 794 | + | ||
| 783 | self.focus_window(&window); | 795 | self.focus_window(&window); |
| 784 | } | 796 | } |
| 785 | } | 797 | } |
src/niri.rsmodified+0 -29
| @@ -325,7 +325,6 @@ pub struct Niri { | |||
| 325 | pub bind_repeat_timer: Option<RegistrationToken>, | 325 | pub bind_repeat_timer: Option<RegistrationToken>, |
| 326 | pub keyboard_focus: KeyboardFocus, | 326 | pub keyboard_focus: KeyboardFocus, |
| 327 | pub layer_shell_on_demand_focus: Option<LayerSurface>, | 327 | pub layer_shell_on_demand_focus: Option<LayerSurface>, |
| 328 | - pub previously_focused_window: Option<Window>, | ||
| 329 | pub idle_inhibiting_surfaces: HashSet<WlSurface>, | 328 | pub idle_inhibiting_surfaces: HashSet<WlSurface>, |
| 330 | pub is_fdo_idle_inhibited: Arc<AtomicBool>, | 329 | pub is_fdo_idle_inhibited: Arc<AtomicBool>, |
| 331 | pub keyboard_shortcuts_inhibiting_surfaces: HashMap<WlSurface, KeyboardShortcutsInhibitor>, | 330 | pub keyboard_shortcuts_inhibiting_surfaces: HashMap<WlSurface, KeyboardShortcutsInhibitor>, |
| @@ -1232,14 +1231,12 @@ impl State { | |||
| 1232 | ); | 1231 | ); |
| 1233 | 1232 | ||
| 1234 | // Tell the windows their new focus state for window rule purposes. | 1233 | // Tell the windows their new focus state for window rule purposes. |
| 1235 | - let mut previous_focus = None; | ||
| 1236 | if let KeyboardFocus::Layout { | 1234 | if let KeyboardFocus::Layout { |
| 1237 | surface: Some(surface), | 1235 | surface: Some(surface), |
| 1238 | } = &self.niri.keyboard_focus | 1236 | } = &self.niri.keyboard_focus |
| 1239 | { | 1237 | { |
| 1240 | if let Some((mapped, _)) = self.niri.layout.find_window_and_output_mut(surface) { | 1238 | if let Some((mapped, _)) = self.niri.layout.find_window_and_output_mut(surface) { |
| 1241 | mapped.set_is_focused(false); | 1239 | mapped.set_is_focused(false); |
| 1242 | - previous_focus = Some(mapped.window.clone()); | ||
| 1243 | } | 1240 | } |
| 1244 | } | 1241 | } |
| 1245 | if let KeyboardFocus::Layout { | 1242 | if let KeyboardFocus::Layout { |
| @@ -1283,31 +1280,6 @@ impl State { | |||
| 1283 | } | 1280 | } |
| 1284 | } | 1281 | } |
| 1285 | 1282 | ||
| 1286 | - // Update the previous focus but only when staying focused on the layout. | ||
| 1287 | - // | ||
| 1288 | - // Case 1: opening and closing exclusive-keyboard layer-shell (e.g. app launcher). This | ||
| 1289 | - // involves going from Layout to LayerShell, then from LayerShell to Layout. The | ||
| 1290 | - // previously focused window should stay unchanged. | ||
| 1291 | - // | ||
| 1292 | - // Case 1.5: opening layer-shell, in the background switching layout focus, closing | ||
| 1293 | - // layer-shell. With the current logic, this won't update the previously focused | ||
| 1294 | - // window, which is incorrect. But this case should be rare. | ||
| 1295 | - // | ||
| 1296 | - // Case 2: switching to an empty workspace, then hitting FocusWindowPrevious. The focus | ||
| 1297 | - // should go to the window that was just focused. The keyboard focus goes from Layout | ||
| 1298 | - // (with Some surface) to Layout (with None surface), so we update the previously | ||
| 1299 | - // focused window. | ||
| 1300 | - // | ||
| 1301 | - // FIXME: Ideally this should happen inside Layout itself, then there wouldn't be any | ||
| 1302 | - // problems with layer-shell, etc. Or a similar problem now with the Overview where we | ||
| 1303 | - // don't update the previously focused window because the keyboard focus is on the | ||
| 1304 | - // Overview rather than on the Layout. | ||
| 1305 | - if matches!(self.niri.keyboard_focus, KeyboardFocus::Layout { .. }) | ||
| 1306 | - && matches!(focus, KeyboardFocus::Layout { .. }) | ||
| 1307 | - { | ||
| 1308 | - self.niri.previously_focused_window = previous_focus; | ||
| 1309 | - } | ||
| 1310 | - | ||
| 1311 | if let Some(grab) = self.niri.popup_grab.as_mut() { | 1283 | if let Some(grab) = self.niri.popup_grab.as_mut() { |
| 1312 | if grab.has_keyboard_grab && Some(&grab.root) != focus.surface() { | 1284 | if grab.has_keyboard_grab && Some(&grab.root) != focus.surface() { |
| 1313 | trace!( | 1285 | trace!( |
| @@ -2787,7 +2759,6 @@ impl Niri { | |||
| 2787 | seat, | 2759 | seat, |
| 2788 | keyboard_focus: KeyboardFocus::Layout { surface: None }, | 2760 | keyboard_focus: KeyboardFocus::Layout { surface: None }, |
| 2789 | layer_shell_on_demand_focus: None, | 2761 | layer_shell_on_demand_focus: None, |
| 2790 | - previously_focused_window: None, | ||
| 2791 | idle_inhibiting_surfaces: HashSet::new(), | 2762 | idle_inhibiting_surfaces: HashSet::new(), |
| 2792 | is_fdo_idle_inhibited: Arc::new(AtomicBool::new(false)), | 2763 | is_fdo_idle_inhibited: Arc::new(AtomicBool::new(false)), |
| 2793 | keyboard_shortcuts_inhibiting_surfaces: HashMap::new(), | 2764 | keyboard_shortcuts_inhibiting_surfaces: HashMap::new(), |