Make move-window-to-workspace focus=false work across monitors too
Browse files at this commitd91499486e505bba1e1764e1e055ce1ec5eda7fbParent: f7106f95 changed files +81 -37
- src/handlers/mod.rs +7 -3
- src/handlers/xdg_shell.rs +7 -3
- src/input/mod.rs +54 -26
- src/layout/mod.rs +7 -4
- src/layout/tests.rs +6 -1
src/handlers/mod.rsmodified+7 -3
| @@ -76,6 +76,7 @@ use smithay::{ | |||
| 76 | }; | 76 | }; |
| 77 | 77 | ||
| 78 | pub use crate::handlers::xdg_shell::KdeDecorationsModeState; | 78 | pub use crate::handlers::xdg_shell::KdeDecorationsModeState; |
| 79 | +use crate::layout::ActivateWindow; | ||
| 79 | use crate::niri::{DndIcon, NewClient, State}; | 80 | use crate::niri::{DndIcon, NewClient, State}; |
| 80 | use crate::protocols::foreign_toplevel::{ | 81 | use crate::protocols::foreign_toplevel::{ |
| 81 | self, ForeignToplevelHandler, ForeignToplevelManagerState, | 82 | self, ForeignToplevelHandler, ForeignToplevelManagerState, |
| @@ -551,9 +552,12 @@ impl ForeignToplevelHandler for State { | |||
| 551 | 552 | ||
| 552 | if let Some(requested_output) = wl_output.as_ref().and_then(Output::from_resource) { | 553 | if let Some(requested_output) = wl_output.as_ref().and_then(Output::from_resource) { |
| 553 | if Some(&requested_output) != current_output { | 554 | if Some(&requested_output) != current_output { |
| 554 | - self.niri | 555 | + self.niri.layout.move_to_output( |
| 555 | - .layout | 556 | + Some(&window), |
| 556 | - .move_to_output(Some(&window), &requested_output, None); | 557 | + &requested_output, |
| 558 | + None, | ||
| 559 | + ActivateWindow::Smart, | ||
| 560 | + ); | ||
| 557 | } | 561 | } |
| 558 | } | 562 | } |
| 559 | 563 | ||
src/handlers/xdg_shell.rsmodified+7 -3
| @@ -43,6 +43,7 @@ use crate::input::resize_grab::ResizeGrab; | |||
| 43 | use crate::input::touch_move_grab::TouchMoveGrab; | 43 | use crate::input::touch_move_grab::TouchMoveGrab; |
| 44 | use crate::input::touch_resize_grab::TouchResizeGrab; | 44 | use crate::input::touch_resize_grab::TouchResizeGrab; |
| 45 | use crate::input::{PointerOrTouchStartData, DOUBLE_CLICK_TIME}; | 45 | use crate::input::{PointerOrTouchStartData, DOUBLE_CLICK_TIME}; |
| 46 | +use crate::layout::ActivateWindow; | ||
| 46 | use crate::niri::{CastTarget, PopupGrabState, State}; | 47 | use crate::niri::{CastTarget, PopupGrabState, State}; |
| 47 | use crate::utils::transaction::Transaction; | 48 | use crate::utils::transaction::Transaction; |
| 48 | use crate::utils::{ | 49 | use crate::utils::{ |
| @@ -445,9 +446,12 @@ impl XdgShellHandler for State { | |||
| 445 | 446 | ||
| 446 | if let Some(requested_output) = requested_output { | 447 | if let Some(requested_output) = requested_output { |
| 447 | if Some(&requested_output) != current_output { | 448 | if Some(&requested_output) != current_output { |
| 448 | - self.niri | 449 | + self.niri.layout.move_to_output( |
| 449 | - .layout | 450 | + Some(&window), |
| 450 | - .move_to_output(Some(&window), &requested_output, None); | 451 | + &requested_output, |
| 452 | + None, | ||
| 453 | + ActivateWindow::Smart, | ||
| 454 | + ); | ||
| 451 | } | 455 | } |
| 452 | } | 456 | } |
| 453 | 457 | ||
src/input/mod.rsmodified+54 -26
| @@ -1104,18 +1104,25 @@ impl State { | |||
| 1104 | } | 1104 | } |
| 1105 | } | 1105 | } |
| 1106 | 1106 | ||
| 1107 | + let activate = if focus { | ||
| 1108 | + ActivateWindow::Smart | ||
| 1109 | + } else { | ||
| 1110 | + ActivateWindow::No | ||
| 1111 | + }; | ||
| 1112 | + | ||
| 1107 | if let Some(output) = output { | 1113 | if let Some(output) = output { |
| 1108 | - self.niri.layout.move_to_output(None, &output, Some(index)); | 1114 | + self.niri |
| 1115 | + .layout | ||
| 1116 | + .move_to_output(None, &output, Some(index), activate); | ||
| 1109 | 1117 | ||
| 1110 | - if !self.maybe_warp_cursor_to_focus_centered() { | 1118 | + if focus { |
| 1111 | - self.move_cursor_to_output(&output); | 1119 | + if !self.maybe_warp_cursor_to_focus_centered() { |
| 1120 | + self.move_cursor_to_output(&output); | ||
| 1121 | + } | ||
| 1122 | + } else { | ||
| 1123 | + self.maybe_warp_cursor_to_focus(); | ||
| 1112 | } | 1124 | } |
| 1113 | } else { | 1125 | } else { |
| 1114 | - let activate = if focus { | ||
| 1115 | - ActivateWindow::Smart | ||
| 1116 | - } else { | ||
| 1117 | - ActivateWindow::No | ||
| 1118 | - }; | ||
| 1119 | self.niri.layout.move_to_workspace(None, index, activate); | 1126 | self.niri.layout.move_to_workspace(None, index, activate); |
| 1120 | self.maybe_warp_cursor_to_focus(); | 1127 | self.maybe_warp_cursor_to_focus(); |
| 1121 | } | 1128 | } |
| @@ -1141,10 +1148,19 @@ impl State { | |||
| 1141 | .active_output() | 1148 | .active_output() |
| 1142 | .is_some_and(|active| output.as_ref() == Some(active)); | 1149 | .is_some_and(|active| output.as_ref() == Some(active)); |
| 1143 | 1150 | ||
| 1151 | + let activate = if focus { | ||
| 1152 | + ActivateWindow::Smart | ||
| 1153 | + } else { | ||
| 1154 | + ActivateWindow::No | ||
| 1155 | + }; | ||
| 1156 | + | ||
| 1144 | if let Some(output) = output { | 1157 | if let Some(output) = output { |
| 1145 | - self.niri | 1158 | + self.niri.layout.move_to_output( |
| 1146 | - .layout | 1159 | + Some(&window), |
| 1147 | - .move_to_output(Some(&window), &output, Some(index)); | 1160 | + &output, |
| 1161 | + Some(index), | ||
| 1162 | + activate, | ||
| 1163 | + ); | ||
| 1148 | 1164 | ||
| 1149 | // If the active output changed (window was moved and focused). | 1165 | // If the active output changed (window was moved and focused). |
| 1150 | #[allow(clippy::collapsible_if)] | 1166 | #[allow(clippy::collapsible_if)] |
| @@ -1156,11 +1172,6 @@ impl State { | |||
| 1156 | } | 1172 | } |
| 1157 | } | 1173 | } |
| 1158 | } else { | 1174 | } else { |
| 1159 | - let activate = if focus { | ||
| 1160 | - ActivateWindow::Smart | ||
| 1161 | - } else { | ||
| 1162 | - ActivateWindow::No | ||
| 1163 | - }; | ||
| 1164 | self.niri | 1175 | self.niri |
| 1165 | .layout | 1176 | .layout |
| 1166 | .move_to_workspace(Some(&window), index, activate); | 1177 | .move_to_workspace(Some(&window), index, activate); |
| @@ -1458,7 +1469,9 @@ impl State { | |||
| 1458 | } | 1469 | } |
| 1459 | Action::MoveWindowToMonitorLeft => { | 1470 | Action::MoveWindowToMonitorLeft => { |
| 1460 | if let Some(output) = self.niri.output_left() { | 1471 | if let Some(output) = self.niri.output_left() { |
| 1461 | - self.niri.layout.move_to_output(None, &output, None); | 1472 | + self.niri |
| 1473 | + .layout | ||
| 1474 | + .move_to_output(None, &output, None, ActivateWindow::Smart); | ||
| 1462 | self.niri.layout.focus_output(&output); | 1475 | self.niri.layout.focus_output(&output); |
| 1463 | if !self.maybe_warp_cursor_to_focus_centered() { | 1476 | if !self.maybe_warp_cursor_to_focus_centered() { |
| 1464 | self.move_cursor_to_output(&output); | 1477 | self.move_cursor_to_output(&output); |
| @@ -1467,7 +1480,9 @@ impl State { | |||
| 1467 | } | 1480 | } |
| 1468 | Action::MoveWindowToMonitorRight => { | 1481 | Action::MoveWindowToMonitorRight => { |
| 1469 | if let Some(output) = self.niri.output_right() { | 1482 | if let Some(output) = self.niri.output_right() { |
| 1470 | - self.niri.layout.move_to_output(None, &output, None); | 1483 | + self.niri |
| 1484 | + .layout | ||
| 1485 | + .move_to_output(None, &output, None, ActivateWindow::Smart); | ||
| 1471 | self.niri.layout.focus_output(&output); | 1486 | self.niri.layout.focus_output(&output); |
| 1472 | if !self.maybe_warp_cursor_to_focus_centered() { | 1487 | if !self.maybe_warp_cursor_to_focus_centered() { |
| 1473 | self.move_cursor_to_output(&output); | 1488 | self.move_cursor_to_output(&output); |
| @@ -1476,7 +1491,9 @@ impl State { | |||
| 1476 | } | 1491 | } |
| 1477 | Action::MoveWindowToMonitorDown => { | 1492 | Action::MoveWindowToMonitorDown => { |
| 1478 | if let Some(output) = self.niri.output_down() { | 1493 | if let Some(output) = self.niri.output_down() { |
| 1479 | - self.niri.layout.move_to_output(None, &output, None); | 1494 | + self.niri |
| 1495 | + .layout | ||
| 1496 | + .move_to_output(None, &output, None, ActivateWindow::Smart); | ||
| 1480 | self.niri.layout.focus_output(&output); | 1497 | self.niri.layout.focus_output(&output); |
| 1481 | if !self.maybe_warp_cursor_to_focus_centered() { | 1498 | if !self.maybe_warp_cursor_to_focus_centered() { |
| 1482 | self.move_cursor_to_output(&output); | 1499 | self.move_cursor_to_output(&output); |
| @@ -1485,7 +1502,9 @@ impl State { | |||
| 1485 | } | 1502 | } |
| 1486 | Action::MoveWindowToMonitorUp => { | 1503 | Action::MoveWindowToMonitorUp => { |
| 1487 | if let Some(output) = self.niri.output_up() { | 1504 | if let Some(output) = self.niri.output_up() { |
| 1488 | - self.niri.layout.move_to_output(None, &output, None); | 1505 | + self.niri |
| 1506 | + .layout | ||
| 1507 | + .move_to_output(None, &output, None, ActivateWindow::Smart); | ||
| 1489 | self.niri.layout.focus_output(&output); | 1508 | self.niri.layout.focus_output(&output); |
| 1490 | if !self.maybe_warp_cursor_to_focus_centered() { | 1509 | if !self.maybe_warp_cursor_to_focus_centered() { |
| 1491 | self.move_cursor_to_output(&output); | 1510 | self.move_cursor_to_output(&output); |
| @@ -1494,7 +1513,9 @@ impl State { | |||
| 1494 | } | 1513 | } |
| 1495 | Action::MoveWindowToMonitorPrevious => { | 1514 | Action::MoveWindowToMonitorPrevious => { |
| 1496 | if let Some(output) = self.niri.output_previous() { | 1515 | if let Some(output) = self.niri.output_previous() { |
| 1497 | - self.niri.layout.move_to_output(None, &output, None); | 1516 | + self.niri |
| 1517 | + .layout | ||
| 1518 | + .move_to_output(None, &output, None, ActivateWindow::Smart); | ||
| 1498 | self.niri.layout.focus_output(&output); | 1519 | self.niri.layout.focus_output(&output); |
| 1499 | if !self.maybe_warp_cursor_to_focus_centered() { | 1520 | if !self.maybe_warp_cursor_to_focus_centered() { |
| 1500 | self.move_cursor_to_output(&output); | 1521 | self.move_cursor_to_output(&output); |
| @@ -1503,7 +1524,9 @@ impl State { | |||
| 1503 | } | 1524 | } |
| 1504 | Action::MoveWindowToMonitorNext => { | 1525 | Action::MoveWindowToMonitorNext => { |
| 1505 | if let Some(output) = self.niri.output_next() { | 1526 | if let Some(output) = self.niri.output_next() { |
| 1506 | - self.niri.layout.move_to_output(None, &output, None); | 1527 | + self.niri |
| 1528 | + .layout | ||
| 1529 | + .move_to_output(None, &output, None, ActivateWindow::Smart); | ||
| 1507 | self.niri.layout.focus_output(&output); | 1530 | self.niri.layout.focus_output(&output); |
| 1508 | if !self.maybe_warp_cursor_to_focus_centered() { | 1531 | if !self.maybe_warp_cursor_to_focus_centered() { |
| 1509 | self.move_cursor_to_output(&output); | 1532 | self.move_cursor_to_output(&output); |
| @@ -1512,7 +1535,9 @@ impl State { | |||
| 1512 | } | 1535 | } |
| 1513 | Action::MoveWindowToMonitor(output) => { | 1536 | Action::MoveWindowToMonitor(output) => { |
| 1514 | if let Some(output) = self.niri.output_by_name_match(&output).cloned() { | 1537 | if let Some(output) = self.niri.output_by_name_match(&output).cloned() { |
| 1515 | - self.niri.layout.move_to_output(None, &output, None); | 1538 | + self.niri |
| 1539 | + .layout | ||
| 1540 | + .move_to_output(None, &output, None, ActivateWindow::Smart); | ||
| 1516 | self.niri.layout.focus_output(&output); | 1541 | self.niri.layout.focus_output(&output); |
| 1517 | if !self.maybe_warp_cursor_to_focus_centered() { | 1542 | if !self.maybe_warp_cursor_to_focus_centered() { |
| 1518 | self.move_cursor_to_output(&output); | 1543 | self.move_cursor_to_output(&output); |
| @@ -1531,9 +1556,12 @@ impl State { | |||
| 1531 | .active_output() | 1556 | .active_output() |
| 1532 | .is_some_and(|active| output == *active); | 1557 | .is_some_and(|active| output == *active); |
| 1533 | 1558 | ||
| 1534 | - self.niri | 1559 | + self.niri.layout.move_to_output( |
| 1535 | - .layout | 1560 | + Some(&window), |
| 1536 | - .move_to_output(Some(&window), &output, None); | 1561 | + &output, |
| 1562 | + None, | ||
| 1563 | + ActivateWindow::Smart, | ||
| 1564 | + ); | ||
| 1537 | 1565 | ||
| 1538 | // If the active output changed (window was moved and focused). | 1566 | // If the active output changed (window was moved and focused). |
| 1539 | #[allow(clippy::collapsible_if)] | 1567 | #[allow(clippy::collapsible_if)] |
src/layout/mod.rsmodified+7 -4
| @@ -3199,6 +3199,7 @@ impl<W: LayoutElement> Layout<W> { | |||
| 3199 | window: Option<&W::Id>, | 3199 | window: Option<&W::Id>, |
| 3200 | output: &Output, | 3200 | output: &Output, |
| 3201 | target_ws_idx: Option<usize>, | 3201 | target_ws_idx: Option<usize>, |
| 3202 | + activate: ActivateWindow, | ||
| 3202 | ) { | 3203 | ) { |
| 3203 | if let Some(InteractiveMoveState::Moving(move_)) = &mut self.interactive_move { | 3204 | if let Some(InteractiveMoveState::Moving(move_)) = &mut self.interactive_move { |
| 3204 | if window.is_none() || window == Some(move_.tile.window().id()) { | 3205 | if window.is_none() || window == Some(move_.tile.window().id()) { |
| @@ -3241,9 +3242,11 @@ impl<W: LayoutElement> Layout<W> { | |||
| 3241 | let ws_id = monitors[new_idx].workspaces[workspace_idx].id(); | 3242 | let ws_id = monitors[new_idx].workspaces[workspace_idx].id(); |
| 3242 | 3243 | ||
| 3243 | let mon = &mut monitors[mon_idx]; | 3244 | let mon = &mut monitors[mon_idx]; |
| 3244 | - let activate = window.map_or(true, |win| { | 3245 | + let activate = activate.map_smart(|| { |
| 3245 | - mon_idx == *active_monitor_idx | 3246 | + window.map_or(true, |win| { |
| 3246 | - && mon.active_window().map(|win| win.id()) == Some(win) | 3247 | + mon_idx == *active_monitor_idx |
| 3248 | + && mon.active_window().map(|win| win.id()) == Some(win) | ||
| 3249 | + }) | ||
| 3247 | }); | 3250 | }); |
| 3248 | let activate = if activate { | 3251 | let activate = if activate { |
| 3249 | ActivateWindow::Yes | 3252 | ActivateWindow::Yes |
| @@ -3302,7 +3305,7 @@ impl<W: LayoutElement> Layout<W> { | |||
| 3302 | let ws = current.active_workspace(); | 3305 | let ws = current.active_workspace(); |
| 3303 | 3306 | ||
| 3304 | if ws.floating_is_active() { | 3307 | if ws.floating_is_active() { |
| 3305 | - self.move_to_output(None, output, None); | 3308 | + self.move_to_output(None, output, None, ActivateWindow::Smart); |
| 3306 | return; | 3309 | return; |
| 3307 | } | 3310 | } |
| 3308 | 3311 | ||
src/layout/tests.rsmodified+6 -1
| @@ -1081,7 +1081,12 @@ impl Op { | |||
| 1081 | 1081 | ||
| 1082 | let window_id = window_id.filter(|id| layout.has_window(id)); | 1082 | let window_id = window_id.filter(|id| layout.has_window(id)); |
| 1083 | let target_ws_idx = target_ws_idx.filter(|idx| mon.workspaces.len() > *idx); | 1083 | let target_ws_idx = target_ws_idx.filter(|idx| mon.workspaces.len() > *idx); |
| 1084 | - layout.move_to_output(window_id.as_ref(), &output, target_ws_idx); | 1084 | + layout.move_to_output( |
| 1085 | + window_id.as_ref(), | ||
| 1086 | + &output, | ||
| 1087 | + target_ws_idx, | ||
| 1088 | + ActivateWindow::Smart, | ||
| 1089 | + ); | ||
| 1085 | } | 1090 | } |
| 1086 | Op::MoveColumnToOutput(id) => { | 1091 | Op::MoveColumnToOutput(id) => { |
| 1087 | let name = format!("output{id}"); | 1092 | let name = format!("output{id}"); |