diff options
| author | gibberish <gbjgms@gmail.com> | 2025-06-16 17:23:29 +0700 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2025-08-27 09:17:58 +0300 |
| commit | e038b8770a17b67cbf9c9d007a1f3a9ac0b53c60 (patch) | |
| tree | 3a23444922e8b794ecb584374b39e71c2c661caf /src | |
| parent | f6f4bf97c368d9a8539137896f786291d859cadf (diff) | |
| download | niri-e038b8770a17b67cbf9c9d007a1f3a9ac0b53c60.tar.gz niri-e038b8770a17b67cbf9c9d007a1f3a9ac0b53c60.tar.bz2 niri-e038b8770a17b67cbf9c9d007a1f3a9ac0b53c60.zip | |
Fix focus=false for move-column-to-workspace*, add to move-window-to-workspace-up/down
Diffstat (limited to 'src')
| -rw-r--r-- | src/input/mod.rs | 8 | ||||
| -rw-r--r-- | src/layout/mod.rs | 8 | ||||
| -rw-r--r-- | src/layout/monitor.rs | 35 | ||||
| -rw-r--r-- | src/layout/tests.rs | 66 | ||||
| -rw-r--r-- | src/tests/floating.rs | 4 | ||||
| -rw-r--r-- | src/ui/hotkey_overlay.rs | 12 |
6 files changed, 98 insertions, 35 deletions
diff --git a/src/input/mod.rs b/src/input/mod.rs index 724825e1..95d84b87 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -1138,14 +1138,14 @@ impl State { // FIXME: granular self.niri.queue_redraw_all(); } - Action::MoveWindowToWorkspaceDown => { - self.niri.layout.move_to_workspace_down(); + Action::MoveWindowToWorkspaceDown(focus) => { + self.niri.layout.move_to_workspace_down(focus); self.maybe_warp_cursor_to_focus(); // FIXME: granular self.niri.queue_redraw_all(); } - Action::MoveWindowToWorkspaceUp => { - self.niri.layout.move_to_workspace_up(); + Action::MoveWindowToWorkspaceUp(focus) => { + self.niri.layout.move_to_workspace_up(focus); self.maybe_warp_cursor_to_focus(); // FIXME: granular self.niri.queue_redraw_all(); diff --git a/src/layout/mod.rs b/src/layout/mod.rs index 52e3173b..d2653086 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -2178,18 +2178,18 @@ impl<W: LayoutElement> Layout<W> { workspace.focus_window_up_or_bottom(); } - pub fn move_to_workspace_up(&mut self) { + pub fn move_to_workspace_up(&mut self, focus: bool) { let Some(monitor) = self.active_monitor() else { return; }; - monitor.move_to_workspace_up(); + monitor.move_to_workspace_up(focus); } - pub fn move_to_workspace_down(&mut self) { + pub fn move_to_workspace_down(&mut self, focus: bool) { let Some(monitor) = self.active_monitor() else { return; }; - monitor.move_to_workspace_down(); + monitor.move_to_workspace_down(focus); } pub fn move_to_workspace( diff --git a/src/layout/monitor.rs b/src/layout/monitor.rs index 01602001..5dc0aed6 100644 --- a/src/layout/monitor.rs +++ b/src/layout/monitor.rs @@ -601,13 +601,13 @@ impl<W: LayoutElement> Monitor<W> { pub fn move_down_or_to_workspace_down(&mut self) { if !self.active_workspace().move_down() { - self.move_to_workspace_down(); + self.move_to_workspace_down(true); } } pub fn move_up_or_to_workspace_up(&mut self) { if !self.active_workspace().move_up() { - self.move_to_workspace_up(); + self.move_to_workspace_up(true); } } @@ -623,7 +623,7 @@ impl<W: LayoutElement> Monitor<W> { } } - pub fn move_to_workspace_up(&mut self) { + pub fn move_to_workspace_up(&mut self, focus: bool) { let source_workspace_idx = self.active_workspace_idx; let new_idx = source_workspace_idx.saturating_sub(1); @@ -637,13 +637,19 @@ impl<W: LayoutElement> Monitor<W> { return; }; + let activate = if focus { + ActivateWindow::Yes + } else { + ActivateWindow::Smart + }; + self.add_tile( removed.tile, MonitorAddWindowTarget::Workspace { id: new_id, column_idx: None, }, - ActivateWindow::Yes, + activate, true, removed.width, removed.is_full_width, @@ -651,7 +657,7 @@ impl<W: LayoutElement> Monitor<W> { ); } - pub fn move_to_workspace_down(&mut self) { + pub fn move_to_workspace_down(&mut self, focus: bool) { let source_workspace_idx = self.active_workspace_idx; let new_idx = min(source_workspace_idx + 1, self.workspaces.len() - 1); @@ -665,13 +671,19 @@ impl<W: LayoutElement> Monitor<W> { return; }; + let activate = if focus { + ActivateWindow::Yes + } else { + ActivateWindow::Smart + }; + self.add_tile( removed.tile, MonitorAddWindowTarget::Workspace { id: new_id, column_idx: None, }, - ActivateWindow::Yes, + activate, true, removed.width, removed.is_full_width, @@ -748,7 +760,7 @@ impl<W: LayoutElement> Monitor<W> { let workspace = &mut self.workspaces[source_workspace_idx]; if workspace.floating_is_active() { - self.move_to_workspace_up(); + self.move_to_workspace_up(activate); return; } @@ -769,7 +781,7 @@ impl<W: LayoutElement> Monitor<W> { let workspace = &mut self.workspaces[source_workspace_idx]; if workspace.floating_is_active() { - self.move_to_workspace_down(); + self.move_to_workspace_down(activate); return; } @@ -790,7 +802,12 @@ impl<W: LayoutElement> Monitor<W> { let workspace = &mut self.workspaces[source_workspace_idx]; if workspace.floating_is_active() { - self.move_to_workspace(None, idx, ActivateWindow::Smart); + let activate = if activate { + ActivateWindow::Smart + } else { + ActivateWindow::No + }; + self.move_to_workspace(None, idx, activate); return; } diff --git a/src/layout/tests.rs b/src/layout/tests.rs index 04823a54..ab2f1f66 100644 --- a/src/layout/tests.rs +++ b/src/layout/tests.rs @@ -497,8 +497,8 @@ enum Op { FocusWorkspace(#[proptest(strategy = "0..=4usize")] usize), FocusWorkspaceAutoBackAndForth(#[proptest(strategy = "0..=4usize")] usize), FocusWorkspacePrevious, - MoveWindowToWorkspaceDown, - MoveWindowToWorkspaceUp, + MoveWindowToWorkspaceDown(bool), + MoveWindowToWorkspaceUp(bool), MoveWindowToWorkspace { #[proptest(strategy = "proptest::option::of(1..=5usize)")] window_id: Option<usize>, @@ -1113,8 +1113,8 @@ impl Op { layout.switch_workspace_auto_back_and_forth(idx) } Op::FocusWorkspacePrevious => layout.switch_workspace_previous(), - Op::MoveWindowToWorkspaceDown => layout.move_to_workspace_down(), - Op::MoveWindowToWorkspaceUp => layout.move_to_workspace_up(), + Op::MoveWindowToWorkspaceDown(focus) => layout.move_to_workspace_down(focus), + Op::MoveWindowToWorkspaceUp(focus) => layout.move_to_workspace_up(focus), Op::MoveWindowToWorkspace { window_id, workspace_idx, @@ -1615,8 +1615,8 @@ fn operations_dont_panic() { Op::FocusWorkspaceUp, Op::FocusWorkspace(1), Op::FocusWorkspace(2), - Op::MoveWindowToWorkspaceDown, - Op::MoveWindowToWorkspaceUp, + Op::MoveWindowToWorkspaceDown(true), + Op::MoveWindowToWorkspaceUp(true), Op::MoveWindowToWorkspace { window_id: None, workspace_idx: 1, @@ -1671,7 +1671,7 @@ fn operations_from_starting_state_dont_panic() { Op::AddWindow { params: TestWindowParams::new(1), }, - Op::MoveWindowToWorkspaceDown, + Op::MoveWindowToWorkspaceDown(true), Op::AddWindow { params: TestWindowParams::new(2), }, @@ -1786,8 +1786,8 @@ fn operations_from_starting_state_dont_panic() { Op::FocusWorkspace(1), Op::FocusWorkspace(2), Op::FocusWorkspace(3), - Op::MoveWindowToWorkspaceDown, - Op::MoveWindowToWorkspaceUp, + Op::MoveWindowToWorkspaceDown(true), + Op::MoveWindowToWorkspaceUp(true), Op::MoveWindowToWorkspace { window_id: None, workspace_idx: 1, @@ -3366,7 +3366,7 @@ fn move_pending_unfullscreen_window_out_of_active_column() { Op::ConsumeWindowIntoColumn, // Window 1 is now pending unfullscreen. // Moving it out should reset view_offset_before_fullscreen. - Op::MoveWindowToWorkspaceDown, + Op::MoveWindowToWorkspaceDown(true), ]; check_ops(&ops); @@ -3583,6 +3583,52 @@ fn unfullscreen_view_offset_not_reset_during_ongoing_gesture() { check_ops(&ops); } +#[test] +fn move_column_to_workspace_down_focus_false_on_floating_window() { + let ops = [ + Op::AddOutput(1), + Op::AddWindow { + params: TestWindowParams::new(1), + }, + Op::AddWindow { + params: TestWindowParams::new(2), + }, + Op::ToggleWindowFloating { id: None }, + Op::MoveColumnToWorkspaceDown(false), + ]; + + let layout = check_ops(&ops); + + let MonitorSet::Normal { monitors, .. } = layout.monitor_set else { + unreachable!() + }; + + assert_eq!(monitors[0].active_workspace_idx, 0); +} + +#[test] +fn move_column_to_workspace_focus_false_on_floating_window() { + let ops = [ + Op::AddOutput(1), + Op::AddWindow { + params: TestWindowParams::new(1), + }, + Op::AddWindow { + params: TestWindowParams::new(2), + }, + Op::ToggleWindowFloating { id: None }, + Op::MoveColumnToWorkspace(1, false), + ]; + + let layout = check_ops(&ops); + + let MonitorSet::Normal { monitors, .. } = layout.monitor_set else { + unreachable!() + }; + + assert_eq!(monitors[0].active_workspace_idx, 0); +} + fn parent_id_causes_loop(layout: &Layout<TestWindow>, id: usize, mut parent_id: usize) -> bool { if parent_id == id { return true; diff --git a/src/tests/floating.rs b/src/tests/floating.rs index 81e507f1..b2eaabfb 100644 --- a/src/tests/floating.rs +++ b/src/tests/floating.rs @@ -349,7 +349,7 @@ fn moving_across_workspaces_doesnt_cancel_resize() { // Move to a different workspace before the window has a chance to respond. This will remove it // from one floating layout and add into a different one, potentially causing a size request. - f.niri().layout.move_to_workspace_down(); + f.niri().layout.move_to_workspace_down(true); // Drop the Activated state to force a configure. f.niri_focus_output(2); f.double_roundtrip(id); @@ -369,7 +369,7 @@ fn moving_across_workspaces_doesnt_cancel_resize() { // Focus, adding Activated, and move to workspace down, causing removing and adding to a // floating layout. f.niri_focus_output(1); - f.niri().layout.move_to_workspace_down(); + f.niri().layout.move_to_workspace_down(true); f.double_roundtrip(id); // This should request the current size (300 × 300) since the window responded to the change. diff --git a/src/ui/hotkey_overlay.rs b/src/ui/hotkey_overlay.rs index 6b7a4cd4..783b71ef 100644 --- a/src/ui/hotkey_overlay.rs +++ b/src/ui/hotkey_overlay.rs @@ -228,9 +228,9 @@ fn collect_actions(config: &Config) -> Vec<&Action> { actions.push(&bind.action); } else if binds .iter() - .any(|bind| matches!(bind.action, Action::MoveWindowToWorkspaceDown)) + .any(|bind| matches!(bind.action, Action::MoveWindowToWorkspaceDown(_))) { - actions.push(&Action::MoveWindowToWorkspaceDown); + actions.push(&Action::MoveWindowToWorkspaceDown(true)); } else { actions.push(&Action::MoveColumnToWorkspaceDown(true)); } @@ -243,9 +243,9 @@ fn collect_actions(config: &Config) -> Vec<&Action> { actions.push(&bind.action); } else if binds .iter() - .any(|bind| matches!(bind.action, Action::MoveWindowToWorkspaceUp)) + .any(|bind| matches!(bind.action, Action::MoveWindowToWorkspaceUp(_))) { - actions.push(&Action::MoveWindowToWorkspaceUp); + actions.push(&Action::MoveWindowToWorkspaceUp(true)); } else { actions.push(&Action::MoveColumnToWorkspaceUp(true)); } @@ -468,8 +468,8 @@ fn action_name(action: &Action) -> String { Action::FocusWorkspaceUp => String::from("Switch Workspace Up"), Action::MoveColumnToWorkspaceDown(_) => String::from("Move Column to Workspace Down"), Action::MoveColumnToWorkspaceUp(_) => String::from("Move Column to Workspace Up"), - Action::MoveWindowToWorkspaceDown => String::from("Move Window to Workspace Down"), - Action::MoveWindowToWorkspaceUp => String::from("Move Window to Workspace Up"), + Action::MoveWindowToWorkspaceDown(_) => String::from("Move Window to Workspace Down"), + Action::MoveWindowToWorkspaceUp(_) => String::from("Move Window to Workspace Up"), Action::SwitchPresetColumnWidth => String::from("Switch Preset Column Widths"), Action::MaximizeColumn => String::from("Maximize Column"), Action::ConsumeOrExpelWindowLeft => String::from("Consume or Expel Window Left"), |
