#8112·wezterm

Wayland: first compositor snap/tile after launch is reverted on hidpi outputs (simple_dpi_change misclassification)

Author: gggirouxCreated Aug 28, 2026Updated Sep 25, 2026
Labelsbugvariant: Waylandneeds:triage

What Operating System(s) are you seeing this problem on?

Linux Wayland

Which Wayland compositor or X11 Window manager(s) are you using?

Linux (Ubuntu 26.04), labwc (wlroots) Wayland session.

Setup detail that matters: mixed-scale multi-monitor — one output at scale 1.5 (4K), one at scale 1.0.

WezTerm version

20260827-135150-08e50ca2 (built from main @ 08e50ca); also reproduced on the 20260716 and 20260826 nightlies.

Did you try the latest nightly build to see if the issue is better (or worse!) than your current version?

Yes, and I updated the version box above to show the version of the nightly that I tried

Describe the bug

Launch a wezterm window on the hidpi output and immediately snap it with a compositor keybind (labwc SnapToEdge, i.e. super+left). The window snaps, then instantly reverts to (approximately) its original size. Other apps snap normally. Only the first snap after launch is affected; subsequent snaps to a different edge stick.

Root cause (traced)

On Wayland, wezterm doesn't process scale changes when they happen (CompositorHandler::scale_factor_changed is a no-op), so it discovers the real DPI only on the first user-driven configure — which is the snap. That configure therefore carries a dpi change (96 → 192) and a real size change (the tile) at the same time.

scaling_changed() in wezterm-gui/src/termwindow/resize.rs then evaluates simple_dpi_change. Its first branch compares dpi_adjusted() values — which are physical inches — using close_enough()'s 10-unit tolerance, which was written for the raw-pixel branch next to it. Ten inches swallows almost any tile: in my trace, 8.5"×6.1" vs 13.3"×14.4" still counted as "close enough". The resize is misclassified as pure dpi bookkeeping, rows/cols are preserved, and the speculative set_inner_size() overrides the compositor's tile size — undoing the snap.

The comment above that code explicitly says the tiled case should not preserve rows/cols; the tolerance defeats the intent.

Trace of the failure (WEZTERM_LOG=window=trace,wezterm_gui::termwindow=trace):

Pending configure: w:1276, h1380      # labwc tile: TILED_LEFT|TILED_TOP|TILED_BOTTOM
Resized { pixel_width: 2552, pixel_height: 2760, dpi: 192 }
dpi_changed=true, font_scale_changed=false scale_changed=true simple_dpi_change=true   # <- misclassified
scale changed so resize from 820x583@96dpi to 1558x1140@192dpi preserving RowsAndCols { rows: 24, cols: 80 }
Pending configure: w:779, h570        # wezterm's set_inner_size wins; snap undone

To Reproduce

  1. Two outputs with different scales (1.5 and 1.0 here); labwc or any wlroots compositor with a snap/tile keybind.
  2. Launch wezterm on the scaled output.
  3. Immediately snap it (e.g. SnapToEdge left).
  4. Window tiles, then reverts to its pre-snap size.

Configuration

no config

Expected Behavior

The window adopts and keeps the compositor's tile size (this is what happens on the second and later snaps, once the dpi has settled).

Logs

Trace of the failure (WEZTERM_LOG=window=trace,wezterm_gui::termwindow=trace):

Pending configure: w:1276, h1380      # labwc tile: TILED_LEFT|TILED_TOP|TILED_BOTTOM
Resized { pixel_width: 2552, pixel_height: 2760, dpi: 192 }
dpi_changed=true, font_scale_changed=false scale_changed=true simple_dpi_change=true   # <- misclassified
scale changed so resize from 820x583@96dpi to 1558x1140@192dpi preserving RowsAndCols { rows: 24, cols: 80 }
Pending configure: w:779, h570        # wezterm's set_inner_size wins; snap undone

Anything else?

Proposed fix (tested)

Use an inch-appropriate tolerance for the inch-scale branch of simple_dpi_change; a genuine same-physical-size dpi transition differs by well under an inch, a tile by several:

diff
--- a/wezterm-gui/src/termwindow/resize.rs
+++ b/wezterm-gui/src/termwindow/resize.rs
@@ -362,15 +362,28 @@ impl super::TermWindow {
             diff < 10.
         }

+        /// The dpi_adjusted values compared below are physical inches, not
+        /// pixels, so the 10-unit pixel tolerance above is far too coarse
+        /// for them: a compositor tile/snap that arrives together with a
+        /// dpi change (eg: the first configure on a hidpi output) differs
+        /// by several inches but still passed the 10 "inch" test, was
+        /// misclassified as a pure dpi change, and the window then snapped
+        /// back to its previous size. A genuine same-physical-size dpi
+        /// transition differs by well under an inch.
+        fn close_enough_inches(a: f32, b: f32) -> bool {
+            let diff = (a - b).abs();
+            diff < 1.
+        }
+
         // Distinguish between eg: dpi being detected as double the initial dpi (where
         // the pixel dimensions don't change), and the dpi change being detected, but
         // where the window manager also decides to tile/resize the window.
         // In the latter case, we don't want to preserve the terminal rows/cols.
         let simple_dpi_change = dimensions.dpi != self.dimensions.dpi
-            && ((close_enough(
+            && ((close_enough_inches(
                 dpi_adjusted(dimensions.pixel_height, dimensions.dpi),
                 dpi_adjusted(self.dimensions.pixel_height, self.dimensions.dpi),
-            ) && close_enough(
+            ) && close_enough_inches(
                 dpi_adjusted(dimensions.pixel_width, dimensions.dpi),
                 dpi_adjusted(self.dimensions.pixel_width, self.dimensions.dpi),
             )) || (close_enough(

With this applied, the same repro logs simple_dpi_change=false and the window keeps the tiled size. The raw-pixel branch (the Windows few-pixels case) is untouched. Happy to send this as a PR.

Possibly related

The same "dpi discovered on first snap" sequence can also end in a fatal protocol error when the window shares a busy process: a frame rendered at the old odd-height size (820x583) gets committed after set_buffer_scale(2) — wl_surface error 2: Buffer size (820x583) is not divisible by scale (2). That looks like the same family as #6233 / #2445 / #3234; I can share details and a mitigation (keeping buffer dimensions even) in those threads if useful.