@@ -1223,40 +1223,46 @@ impl WindowManager { |
| 1223 | 1223 | let preferred = self.directional_focus_memory.get(&(focused, direction)).copied(); |
| 1224 | 1224 | |
| 1225 | 1225 | if let Some(target) = Node::find_adjacent(&geometries, focused, direction, preferred) { |
| 1226 | + // Check if memory was used (preferred matched target) or default algorithm was used |
| 1227 | + let used_memory = preferred == Some(target); |
| 1228 | + |
| 1226 | 1229 | // Store the directional focus memory for next time |
| 1227 | 1230 | self.directional_focus_memory.insert((focused, direction), target); |
| 1228 | 1231 | |
| 1229 | | - // Store reverse direction only if windows are aligned (same row/column) |
| 1230 | | - // This enables "back" navigation without breaking natural movement |
| 1231 | | - if let (Some((_, from_rect)), Some((_, to_rect))) = ( |
| 1232 | | - geometries.iter().find(|(w, _)| *w == focused), |
| 1233 | | - geometries.iter().find(|(w, _)| *w == target), |
| 1234 | | - ) { |
| 1235 | | - let dominated = match direction { |
| 1236 | | - // For Left/Right: store reverse if windows share vertical space (same row) |
| 1237 | | - Direction::Left | Direction::Right => { |
| 1238 | | - let overlap_start = from_rect.y.max(to_rect.y); |
| 1239 | | - let overlap_end = (from_rect.y + from_rect.height as i16) |
| 1240 | | - .min(to_rect.y + to_rect.height as i16); |
| 1241 | | - overlap_start < overlap_end |
| 1242 | | - } |
| 1243 | | - // For Up/Down: store reverse if windows share horizontal space (same column) |
| 1244 | | - Direction::Up | Direction::Down => { |
| 1245 | | - let overlap_start = from_rect.x.max(to_rect.x); |
| 1246 | | - let overlap_end = (from_rect.x + from_rect.width as i16) |
| 1247 | | - .min(to_rect.x + to_rect.width as i16); |
| 1248 | | - overlap_start < overlap_end |
| 1249 | | - } |
| 1250 | | - }; |
| 1251 | | - |
| 1252 | | - if dominated { |
| 1253 | | - let opposite = match direction { |
| 1254 | | - Direction::Left => Direction::Right, |
| 1255 | | - Direction::Right => Direction::Left, |
| 1256 | | - Direction::Up => Direction::Down, |
| 1257 | | - Direction::Down => Direction::Up, |
| 1232 | + // Store reverse direction only if: |
| 1233 | + // 1. Default algorithm was used (not memory-assisted jump that skipped windows) |
| 1234 | + // 2. Windows are aligned (same row/column) |
| 1235 | + if !used_memory { |
| 1236 | + if let (Some((_, from_rect)), Some((_, to_rect))) = ( |
| 1237 | + geometries.iter().find(|(w, _)| *w == focused), |
| 1238 | + geometries.iter().find(|(w, _)| *w == target), |
| 1239 | + ) { |
| 1240 | + let dominated = match direction { |
| 1241 | + // For Left/Right: store reverse if windows share vertical space (same row) |
| 1242 | + Direction::Left | Direction::Right => { |
| 1243 | + let overlap_start = from_rect.y.max(to_rect.y); |
| 1244 | + let overlap_end = (from_rect.y + from_rect.height as i16) |
| 1245 | + .min(to_rect.y + to_rect.height as i16); |
| 1246 | + overlap_start < overlap_end |
| 1247 | + } |
| 1248 | + // For Up/Down: store reverse if windows share horizontal space (same column) |
| 1249 | + Direction::Up | Direction::Down => { |
| 1250 | + let overlap_start = from_rect.x.max(to_rect.x); |
| 1251 | + let overlap_end = (from_rect.x + from_rect.width as i16) |
| 1252 | + .min(to_rect.x + to_rect.width as i16); |
| 1253 | + overlap_start < overlap_end |
| 1254 | + } |
| 1258 | 1255 | }; |
| 1259 | | - self.directional_focus_memory.insert((target, opposite), focused); |
| 1256 | + |
| 1257 | + if dominated { |
| 1258 | + let opposite = match direction { |
| 1259 | + Direction::Left => Direction::Right, |
| 1260 | + Direction::Right => Direction::Left, |
| 1261 | + Direction::Up => Direction::Down, |
| 1262 | + Direction::Down => Direction::Up, |
| 1263 | + }; |
| 1264 | + self.directional_focus_memory.insert((target, opposite), focused); |
| 1265 | + } |
| 1260 | 1266 | } |
| 1261 | 1267 | } |
| 1262 | 1268 | |