Skip to content

fix(legacy): do not cancel a pending setSize in setPosition on Linux - #609

Open
mockturtl wants to merge 2 commits into
leanflutter:mainfrom
mockturtl:fix/37-linux-setsize-order
Open

mockturtl wants to merge 2 commits into
leanflutter:mainfrom
mockturtl:fix/37-linux-setsize-order

Conversation

@mockturtl

@mockturtl mockturtl commented Nov 17, 2026 •

Copy link
Copy Markdown

Merge order: merge #607 first. The second commit of this PR uses debugBindWindow from #607. Until #607 is in main, the tests of this PR do not compile. The first commit stands alone, and its tests pass.

Summary

On Linux (X11), the legacy setPosition can cancel a setSize call that comes right before it. The methods setAlignment and center call setPosition, so they have the same problem. This PR makes setPosition move only the position when animate is false.

Issue: libnativeapi/nativeapi#37 (the README says to report issues there).
Refs libnativeapi/nativeapi#37

Cause

setPosition calls setBounds(null, position: position). The setBounds method reads window.bounds (the position and the current size). It changes the position and writes the whole rectangle to the window.

After a setSize call, the window manager applies the new size a few milliseconds later. Until then, window.bounds returns the old size. Then setBounds writes the old size to the window, and the new size is lost.

Change

The PR has two commits.

  1. fix(legacy): do not cancel a pending setSize in setPosition on Linux
    • lib/src/legacy/window_manager.dart: when animate is false, setPosition sets window.position. It does not call setBounds. The animated path does not change.
    • lib/src/legacy/window_manager.dart: a temporary debugTarget setter, marked @visibleForTesting. A test uses it to replace the native window with a fake.
    • test/legacy_set_position_test.dart: five new tests.
    • CHANGELOG.md: one entry under "Unreleased".
  2. test(legacy): use debugBindWindow in the setPosition tests

After both commits, this PR adds no test hook.

Tests

The tests use a fake native window. The fake applies a size request later, like the window manager on Linux. Until then, its bounds returns the old size.

  • With animate false: the code calls only set position. It does not read or write the bounds.
  • With animate false: a move after setSize(1920 x 1080) does not change the requested size. This holds after several moves.
  • With animate true: the call animates with the current size, or writes the bounds if the platform has no animation. This behavior does not change.

I did a mutation check with #607 applied. I changed setPosition back to the setBounds call. Then the three tests for animate: false failed, and the two tests for animate: true passed. After I restored the fix, all five tests passed. The five tests of #607 passed in both runs.

How I checked it by hand

  • Machine: LMDE 7, X11, Cinnamon 6.6.9 (Muffin 6.6.3), GTK 3.24.49.
  • App: a new project from flutter create --empty --platforms=linux, with window_manager 0.7.0 and the stock runner.
  • Without this change, the real window is 1280 x 720 after setSize(1920 x 1080), show, focus and setAlignment(topLeft). The reproduction is in the issue.
  • With this change, the same code gives a 1920 x 1080 window at the top-left of the work area.

Not checked

Notes for the maintainers

🤖 Generated with Claude Code

mockturtl and others added 2 commits November 16, 2026 22:52
setPosition called setBounds(null, position: ...). setBounds reads
window.bounds, replaces the position and writes the whole rectangle back.
After a setSize call, the window manager applies the new size a few
milliseconds later. Until then, window.bounds returns the old size, so
setBounds wrote the old size back and cancelled the new one. On Linux
(X11), this broke setAlignment, setPosition and center after setSize.

When animate is false, move only the position. The animated path does not
change.

Add WindowManager.debugTarget (visible for testing), so that a test can
replace the native window with a fake. Add tests for setPosition. With the
old code, the three tests for animate false fail. With the fix, all five
pass.

debugTarget is a temporary test hook. The open PR
leanflutter#607 adds debugBindWindow(window) for the same
job. When that PR merges, the tests will use debugBindWindow and
debugTarget will go away. The open PR leanflutter#606 also
changes the _target getter, so a conflict with debugTarget is likely.

Checked by hand on Linux (X11, Cinnamon 6.6.9 with Muffin 6.6.3). Not
tested on macOS, Windows or Wayland.

Refs libnativeapi/nativeapi#37

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Replace the temporary WindowManager.debugTarget setter with
debugBindWindow(window). The open PR leanflutter#607 adds
debugBindWindow for the same job.

This commit needs leanflutter#607. Without leanflutter#607, the tests do not compile. Merge leanflutter#607
before this commit. The previous commit stands alone, and its tests pass
with debugTarget.

The tests check the same behavior as before. I ran them with leanflutter#607 applied
on top of this branch. The five tests of legacy_set_position_test.dart
pass, and so do the five tests of leanflutter#607. With setPosition reverted, exactly
the three tests for animate false fail. Tested on Linux (X11) only.

Refs libnativeapi/nativeapi#37

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
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.

1 participant