Linux: `setPosition` and `setAlignment` cancel a `setSize` call that comes before them
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 73/100
Hướng nghiên cứu
Bắt đầu từ lib/src/legacy/window_manager.dart và đọc setPosition cùng với setBounds; báo cáo chỉ ra cách việc đọc các giới hạn đã lỗi thời có thể ghi đè thay đổi kích thước đang chờ xử lý. Xem xét bản vá đính kèm window_manager-setposition-fix.patch và tái hiện thứ tự gọi trên Linux bằng ứng dụng Flutter được cung cấp. Hoàn tất khi việc định vị sau setSize vẫn giữ nguyên kích thước 1920 × 1080 đã yêu cầu; báo cáo cho biết bản sửa được đề xuất đã được kiểm tra thủ công.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
(This issue report is AI-generated)
Summary
On Linux, the legacy call windowManager.setPosition(...) can cancel a
windowManager.setSize(...) call that comes right before it. The methods
setAlignment and center call setPosition, so they have the same problem.
The cause is in lib/src/legacy/window_manager.dart. The setPosition method
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.
I measured a real application (not the repro below) with the same call order.
With 0.5.2, the window was 1920 x 1080.
Scope of the check
- All measurements come from one machine: a Linux desktop (details below).
- I did not test other Linux window managers (for example GNOME or KDE), macOS,
Windows, or Wayland. - I ran the repro below exactly as written one time. Seven runs of the repro and
of a real application, all with the unchangedwindow_manager, gave the same
result.
Environment
- window_manager 0.7.0 (hosted). The code is the same on
main(checked 2026-11-16). - nativeapi / cnativeapi / nativeapi_flutter 0.6.1
- Flutter 3.50.0 stable, Dart 3.14.0
- LMDE 7, X11 session, Cinnamon 6.6.9 (window manager Muffin 6.6.3), GTK 3.24.49
- The app comes from
flutter create --empty --platforms=linux. The runner has
no changes. It setsgtk_window_set_default_size(window, 1280, 720)and shows
the window inactivate.
Steps to reproduce
- Create a new project in an empty folder:
flutter create --empty --platforms=linux --project-name wm_size_repro . - Add the package:
flutter pub add window_manager:0.7.0 - Replace the content of
lib/main.dartwith this code:
// ignore_for_file: deprecated_member_use
import 'package:flutter/widgets.dart';
import 'package:window_manager/legacy.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await windowManager.ensureInitialized();
await windowManager.waitUntilReadyToShow(
const WindowOptions(size: Size(1920, 1080)),
() async {
await windowManager.show();
await windowManager.focus();
},
);
await windowManager.setAlignment(Alignment.topLeft);
for (var i = 0; i < 12; i++) {
await Future<void>.delayed(const Duration(milliseconds: 250));
debugPrint('size=${await windowManager.getSize()}');
}
runApp(const Directionality(
textDirection: TextDirection.ltr,
child: Center(child: Text('repro')),
));
}
- Start the app:
flutter run -d linux - Read the 12
size=lines in the console. - Find the window:
xwininfo -root -tree | grep wm_size_repro
(The toolxwininfois in the packagex11-utils.) - Measure the window:
xwininfo -id <window id>
Use the id of the entry with the large size. Do not use the 10x10 entries.
Expected
The window is 1920 x 1080 and sits at the top-left of the work area.
(A real application gave this result with 0.5.2.)
Actual
All 12 size= lines show Size(1280.0, 752.0). The real X window is
1280 x 720, at x 2160 and y 467 (the top-left of the work area).
The getSize() value is 32 px higher than the X window. This is probably the
title bar of the window manager. I did not measure the title bar.
What I measured
The table shows the real window size from xwininfo. All rows come from the
same machine and the same app.
| Calls | Window |
|---|---|
setSize, show, focus, then setAlignment(topLeft) (the repro above) |
1280 x 720 (wrong) |
The same calls without setAlignment |
1920 x 1080 |
setAlignment(topLeft) first, then setSize, show, focus |
1920 x 1080 at the top-left |
Failing order, with a 300 ms wait before setAlignment |
1920 x 1080 |
Native API only: Window.setSize(...), then Window.position = ... in the same turn |
1920 x 1080 |
| The repro above with the patch below | 1920 x 1080 at the top-left |
nativeapi main (commit 17922b4, 2026-11-16) gives the same wrong result.
For this test, I made a one-line change to window_manager main (a new case
for WindowScaleFactorChangedEvent in a switch) so that the code compiles.
Thus the problem is not in nativeapi.
I first suspected nativeapi. I changed Window::SetPosition there to repeat
the last resize after the move. The window stayed at the wrong size, so that
was the wrong place.
Cause
Future<void> setPosition(Offset position, {bool animate = false}) async {
await setBounds(null, position: position, animate: animate);
}
Future<void> setBounds(Rect? bounds, {Offset? position, Size? size, bool animate = false}) async {
...
final current = window.bounds.toRect(); // old size, not applied yet
final target = bounds ?? Rect.fromLTWH(
position?.dx ?? current.left,
position?.dy ?? current.top,
size?.width ?? current.width, // old width
size?.height ?? current.height, // old height
);
...
window.bounds = target.toNative(); // writes the old size
}
The package documentation, in the section "Upgrading from 0.5.x", says:
"Geometry changes on platforms without native frame animation are immediate."
Thus the code can expect that a size change is in effect when the next call
reads it. On Linux (X11), this is not true. The window manager applies the size
a few milliseconds later, and window.bounds returns the old size until then.
Suggested fix
When animate is false, move only the position:
Future<void> setPosition(Offset position, {bool animate = false}) async {
final window = _target;
if (window == null) return;
if (!animate) {
window.position = position.toNative();
return;
}
await setBounds(null, position: position, animate: animate);
}
The patch is in the file window_manager-setposition-fix.patch. I tested it by
hand on Linux (X11) with the repro above. I did not write a unit test.
Not tested
- macOS, Windows, Wayland, and other Linux window managers. The
setBounds
method 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. - The animated case (
animate: true). The patch does not change it.
Work-around for apps
Call setAlignment or setPosition before the size request. This is safe for
a top-left position, because the position does not depend on the window size.
In my tests (the third row of the table), this order gave 1920 x 1080.
- Ngôn ngữ chính
- TypeScript
- Star
- 186
- Fork
- 16
- Merge trung bình
- 1 giờ 45 phút
- Pull request đã merge (30 ngày)
- 5
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của libnativeapi/nativeapi
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 38/100
libnativeapi/nativeapi#30 · 2 bình luận · 1 reaction ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
libnativeapi/nativeapi#25 ·
Tất cả issue của libnativeapi/nativeapi
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
vercel-labs/ui#809 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bot:ai-assisted component:platform-js status:untriaged
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 74/100
midnightntwrk/platform-js#38 ·
-
[bug] Second false positive on high-cost plugin alert: detection only compares patch entry id, community plugin dsh-auto | [bug] 高成本插件告警第二次误报:检测只比对 patch 条目 id,社区插件 dsh-auto-review 被认成 @deepseek-ai/dsh-experimental-auto-reviewCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
ranxianglei/billion-context#7068 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
vendor: bump whisper.cpp past 6a8addd — the current pin aborts the app on a failed Metal initĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
mybigday/whisper.rn#348 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
six-group/six-webcomponents#600 ·