Repository navigation
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
On Linux (X11), the legacy
setPositioncan cancel asetSizecall that comes right before it. The methodssetAlignmentandcentercallsetPosition, so they have the same problem. This PR makessetPositionmove only the position whenanimateis false.Issue: libnativeapi/nativeapi#37 (the README says to report issues there).
Refs libnativeapi/nativeapi#37
Cause
setPositioncallssetBounds(null, position: position). ThesetBoundsmethod readswindow.bounds(the position and the current size). It changes the position and writes the whole rectangle to the window.After a
setSizecall, the window manager applies the new size a few milliseconds later. Until then,window.boundsreturns the old size. ThensetBoundswrites the old size to the window, and the new size is lost.Change
The PR has two commits.
fix(legacy): do not cancel a pending setSize in setPosition on Linuxlib/src/legacy/window_manager.dart: whenanimateis false,setPositionsetswindow.position. It does not callsetBounds. The animated path does not change.lib/src/legacy/window_manager.dart: a temporarydebugTargetsetter, 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".test(legacy): use debugBindWindow in the setPosition testsdebugTarget. The tests usedebugBindWindowfrom perf(legacy): skip the native bounds read when setBounds gets a full Rect #607.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
boundsreturns the old size.animatefalse: the code calls onlyset position. It does not read or write the bounds.animatefalse: a move aftersetSize(1920 x 1080)does not change the requested size. This holds after several moves.animatetrue: 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
setPositionback to thesetBoundscall. Then the three tests foranimate: falsefailed, and the two tests foranimate: truepassed. After I restored the fix, all five tests passed. The five tests of #607 passed in both runs.How I checked it by hand
flutter create --empty --platforms=linux, with window_manager 0.7.0 and the stock runner.setSize(1920 x 1080),show,focusandsetAlignment(topLeft). The reproduction is in the issue.Not checked
setBoundsmethod reads the size and writes it back on all platforms. It causes a problem only if the window manager appliessetSizeafter the next call reads the size. I do not know which platforms do this.animate: true). I did not change it.dart analyzeand the tests on my machine only.main. I ran them on a local branch with perf(legacy): skip the native bounds read when setBounds gets a full Rect #607 applied on top of this one.Notes for the maintainers
nativeapi 0.5.10, and its own tests do not compile on Flutter 3.50. Rebase perf(legacy): skip the native bounds read when setBounds gets a full Rect #607 ontomainfirst.debugTarget.bindWindow(window). If fix(legacy): resolve the window late and add bindWindow #606 merges first, the tests can usebindWindowinstead. I will change them if you prefer that.🤖 Generated with Claude Code