Skip to content

Fix terminal origin jump when switching tabs#1517

Closed
0x0aa wants to merge 23 commits into
raphamorim:mainfrom
0x0aa:fix-jumpy
Closed

Fix terminal origin jump when switching tabs#1517
0x0aa wants to merge 23 commits into
raphamorim:mainfrom
0x0aa:fix-jumpy

Conversation

@0x0aa
Copy link
Copy Markdown
Contributor

@0x0aa 0x0aa commented Apr 15, 2026

Summary

Fixes #1513 — with multiple tabs open, the terminal content in different tabs could land at slightly different top-left origins, so switching between tabs produced a visible jump.

Reproduced on Arch Linux / Sway (Wayland) at display scale 1.0. The affected code paths in layout/mod.rs and screen/mod.rs are platform-independent, so the fix should apply equally across platforms.

The bug

ContextGrid::apply_taffy_layout positioned every panel using Taffy's layout_rect:

let [abs_x, abs_y, width, height] = item.layout_rect;
let x = (abs_x + self.scaled_margin.left) / scale;
let y = (abs_y + self.scaled_margin.top) / scale;

For a single-panel grid that rect isn't (0, 0) — Taffy gives the panel node a non-zero location based on the panel's own margin/padding, and the root container's gap. That offset then got added to scaled_margin on top of the window margin, so single-panel tabs ended up shifted away from the origin used when the first tab is set up in Screen::new (which writes renderer.margin directly to sugarloaf.set_position). The offset was small and only visible when flipping between tabs.

A second, narrower mismatch existed in Screen::create_tab: it fed current_grid().scaled_margin.left (physical pixels) into sugarloaf.set_position, which expects logical pixels. At scale 1.0 the two happen to agree, but on HiDPI displays the new tab landed at a different x than tab 1.

The fix

  • layout/mod.rs: in apply_taffy_layout, when there's only one panel, bypass Taffy's layout_rect and use (0, 0) with the full available area minus the window margin. This is what actually resolves the cross-tab jump. Multi-panel grids still use Taffy's rect — they need it for split positioning and clipping.
  • screen/mod.rs: create_tab now uses self.renderer.margin.left (logical margin), matching the position set for the first tab in Screen::new. This aligns the initial rich-text position with tab 1 on HiDPI.

Test plan

  • With multiple tabs open (no splits): switch between them — the top-left of the terminal content stays fixed, no jump across tabs.
  • With non-zero panel margin/padding in config: same scenario — origin still stays fixed across tabs.
  • With a split pane and multiple tabs: switch between a single-panel tab and a split tab — both share the same top-left origin; split borders and clipping look unchanged.

Debugging and the proposed fix were generated with the assistance of Claude — please review critically.

raphamorim and others added 15 commits April 18, 2026 10:26
Switch `set_system_backdrop` from the Windows 11 22H2+ DWM backdrop
attribute (`DWMWA_SYSTEMBACKDROP_TYPE`) to the legacy `SetWindow
CompositionAttribute` path with `ACCENT_ENABLE_BLURBEHIND`. The DWM
path requires Windows 11 build 22523+; the legacy path works on
Windows 10 v1809+ and every Windows 11 build, giving a consistent
blur across all supported Windows versions.

Dynamic-loads `SetWindowCompositionAttribute` from user32.dll via
`GetProcAddress`; the symbol isn't in the public SDK. Falls back to
a no-op when the function isn't present.

Uses `AccentFlags = 2` (undocumented "use gradient color") so the
tint renders properly — matches Tauri's `window-vibrancy` crate.
Without it, blur ignores the gradient color and picks a washed-out
default.

Co-authored-by: NSPC911 <NSPC911@users.noreply.github.com>
Flake lock file updates:

• Updated input 'flake-parts':
    'github:hercules-ci/flake-parts/f20dc5d' (2026-03-01)
  → 'github:hercules-ci/flake-parts/3107b77' (2026-04-01)
• Updated input 'flake-parts/nixpkgs-lib':
    'github:nix-community/nixpkgs.lib/c185c7a' (2026-03-01)
  → 'github:nix-community/nixpkgs.lib/333c4e0' (2026-03-29)
• Updated input 'nixpkgs':
    'github:NixOS/nixpkgs/b40629e' (2026-03-18)
  → 'github:NixOS/nixpkgs/4bd9165' (2026-04-14)
• Updated input 'rust-overlay':
    'github:oxalica/rust-overlay/c807e83' (2026-03-21)
  → 'github:oxalica/rust-overlay/e611106' (2026-04-18)
@0x0aa 0x0aa changed the title Fix strange offset at top left Fix terminal origin jump when switching tabs Apr 20, 2026
raphamorim and others added 8 commits April 21, 2026 21:05
* docs: add documentation to test_poll.rs

* chore: remove test_echo_server.rs (fully commented out, no functional tests)

* chore: remove test_close_on_drop.rs (fully commented out, no functional tests)

* chore: remove test_double_register.rs (fully commented out, no functional tests)

* chore: remove test_broken_pipe.rs (uses deprecated corcovado::deprecated module that no longer exists)
@0x0aa
Copy link
Copy Markdown
Contributor Author

0x0aa commented May 5, 2026

Fixed in main

@0x0aa 0x0aa closed this May 5, 2026
@0x0aa 0x0aa deleted the fix-jumpy branch May 5, 2026 21:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Strange offset at top left for some tabs

2 participants