Skip to content

Commit 56e7632

Browse files
committed
Fix Linux minimum-size restoration and verify KDE desktop behavior
Use core 18d2a41 to derive GTK minimums from content requisitions. Add a stock Flutter reproduction and private KWin verification with fractional scaling and XWayland coverage. Fixes #35
1 parent 41e0096 commit 56e7632

6 files changed

Lines changed: 208 additions & 9 deletions

‎tools/gui/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ runner) lives in [`.agents/skills/`](../../.agents/skills); read
1010

1111
| Script | Example | Platform | Covers |
1212
| --- | --- | --- | --- |
13+
| `window_minimum_restore_flutter.dart` / `build_minimum_restore_flutter.py` | stock Flutter runner and core `window_minimum_restore_linux_test` (#35) | Linux Wayland / XWayland | No input: hidden-window minimum-size restoration, three maximize/restore cycles, minimum/maximum enforcement and host size-request preservation. Private KWin, Breeze and verified 125% output scaling; see [results and commands](window_minimum_restore_verification.md). |
1314
| `verify_owned_file_dialog_windows.ps1` | core cross-thread HWND and COM dialog tests (#29) | Windows | No input: deterministic cross-thread registration stall, deferred property notifications and destruction cleanup, real owned/unowned save/open dialogs with automatic cancellation, preserved modality and existing window regressions. See [results and commands](owned_file_dialog_verification.md). |
1415
| `verify_protocol_handler.py` / `verify_protocol_handler_windows.ps1` | protocol_handler submodule example, fixture `protocol_handler_flutter.dart` | Android / iOS / macOS / Windows | No desktop input: real OS cold/warm URL activation, registration, object listeners and stream subscribers, cleanup, duplicate activations and queued replay. See [migration verification and commands](protocol_handler_verification.md). |
1516
| `window_manager_windows_reports_test.ps1` | fixtures built by `build_window_manager_reports.py` | Windows | Legacy asynchronous close (#593), native-free/getCurrent/listener resize comparisons (#596), optional owner-guarded real resize drags. See [commands, results and limits](window_manager_reports_verification.md). |
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env python3
2+
"""Build #35 in a freshly generated Flutter app, without runner modifications."""
3+
import json
4+
from pathlib import Path
5+
import shutil
6+
import subprocess
7+
8+
ROOT = Path(__file__).resolve().parents[2]
9+
APP = ROOT / 'core/build/minimum-restore-flutter'
10+
11+
def main():
12+
flutter = shutil.which('flutter')
13+
assert flutter, 'Flutter must be on PATH'
14+
if not (APP / 'pubspec.yaml').exists():
15+
subprocess.run([flutter, 'create', '--empty', '--platforms=linux',
16+
'--project-name=minimum_restore', str(APP)], check=True)
17+
pubspec = '''name: minimum_restore
18+
environment:
19+
sdk: ^3.14.0
20+
dependencies:
21+
flutter:
22+
sdk: flutter
23+
window_manager: 0.7.0
24+
dependency_overrides:
25+
'''
26+
for name in ('window_manager', 'nativeapi', 'nativeapi_flutter', 'cnativeapi'):
27+
pubspec += f' {name}:\n path: {json.dumps(str(ROOT / "bindings/dart" / name))}\n'
28+
(APP / 'pubspec.yaml').write_text(pubspec)
29+
shutil.copyfile(ROOT / 'tools/gui/window_minimum_restore_flutter.dart', APP / 'lib/main.dart')
30+
subprocess.run([flutter, 'pub', 'get'], cwd=APP, check=True)
31+
subprocess.run([flutter, 'build', 'linux', '--debug'], cwd=APP, check=True)
32+
print('BUNDLE', APP / 'build/linux/x64/debug/bundle', flush=True)
33+
34+
if __name__ == '__main__':
35+
main()

‎tools/gui/window_manager_kwin_test.py‎

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ def main():
2323
parser.add_argument('--kwin', default=shutil.which('kwin_wayland'))
2424
parser.add_argument('--environment-json', type=Path)
2525
parser.add_argument('--flutter', action='store_true', help='Run the built FlView fixture')
26+
parser.add_argument('--scale', type=float, default=1, help='Actual output scale (requires kscreen-doctor)')
27+
parser.add_argument('--kscreen-doctor', help='Path to kscreen-doctor for fractional scaling')
28+
parser.add_argument('--width', default='1536')
29+
parser.add_argument('--height', default='1000')
30+
parser.add_argument('--backend', choices=('wayland', 'x11'), default='wayland')
31+
parser.add_argument('--timeout', type=int, default=90)
32+
parser.add_argument('--command', nargs=argparse.REMAINDER, help='Run a custom no-input regression')
2633
args = parser.parse_args()
2734
assert args.kwin, 'Install KWin or provide --kwin'
2835
env = os.environ.copy()
@@ -40,36 +47,55 @@ def main():
4047
folder.mkdir(mode=0o700)
4148
env[key] = str(folder)
4249
env.update(WAYLAND_DISPLAY='nativeapi-test-kwin', GUI_TEST_PRIVATE_WAYLAND='1',
43-
XDG_CURRENT_DESKTOP='KDE', XDG_SESSION_TYPE='wayland', GDK_BACKEND='wayland',
50+
XDG_CURRENT_DESKTOP='KDE', XDG_SESSION_TYPE='wayland', GDK_BACKEND=args.backend,
4451
KWIN_COMPOSE='O2', LIBGL_ALWAYS_SOFTWARE='1', GSETTINGS_BACKEND='keyfile')
4552
test = 'window_manager_linux_flutter_test.py' if args.flutter else 'window_manager_linux_reports.py'
4653
# KWin receives one executable for --exit-with-session. This generated
4754
# entry point uses Python repr for paths, avoiding shell interpolation.
4855
session = Path(scratch) / 'run-test'
49-
session.write_text('#!/usr/bin/python3\nimport os\nos.execv(' + repr('/usr/bin/python3') +
50-
', ["python3", ' + repr(str(ROOT / 'tools/gui' / test)) + '])\n')
56+
command = args.command or ['/usr/bin/python3', str(ROOT / 'tools/gui' / test)]
57+
setup = ''
58+
if args.scale != 1:
59+
doctor = args.kscreen_doctor or str(Path(args.kwin).with_name('kscreen-doctor').resolve())
60+
setup = ('os.environ["QT_QPA_PLATFORM"] = "wayland"\n'
61+
'doctor = ' + repr(doctor) + '\n'
62+
'config = json.loads(subprocess.check_output([doctor, "-j"]))\n'
63+
'output_id = config["outputs"][0]["id"]\n'
64+
'subprocess.run([doctor, f"output.{output_id}.scale.' + str(args.scale) + '"], check=True)\n'
65+
'config = json.loads(subprocess.check_output([doctor, "-j"]))\n'
66+
'Path(' + repr(str(output / 'outputs.json')) + ').write_text(json.dumps(config, indent=2))\n'
67+
'assert abs(config["outputs"][0]["scale"] - ' + repr(args.scale) + ') < 0.01, config\n')
68+
session.write_text('#!/usr/bin/python3\nimport subprocess, json, os\nfrom pathlib import Path\n' + setup +
69+
'with open(' + repr(str(output / 'client.log')) + ', "w") as log:\n'
70+
' result = subprocess.run(' + repr(command) + ', stdout=log, stderr=subprocess.STDOUT)\n'
71+
'Path(' + repr(str(output / 'exit-code')) + ').write_text(str(result.returncode))\n')
5172
session.chmod(0o700)
5273
with (output / 'kwin.log').open('w') as log:
5374
proc = subprocess.Popen(['dbus-run-session', '--', args.kwin, '--virtual',
54-
'--width', '1536', '--height', '1000', '--socket', env['WAYLAND_DISPLAY'],
75+
'--width', args.width, '--height', args.height,
76+
'--socket', env['WAYLAND_DISPLAY'],
5577
'--no-lockscreen', '--no-global-shortcuts', '--no-kactivities',
78+
*(['--xwayland'] if args.backend == 'x11' else []),
5679
'--exit-with-session', str(session)], env=env, stdout=log,
5780
stderr=subprocess.STDOUT, start_new_session=True)
5881
try:
59-
code = proc.wait(timeout=90)
82+
code = proc.wait(timeout=args.timeout)
6083
finally:
6184
try:
6285
os.killpg(proc.pid, signal.SIGTERM)
6386
except ProcessLookupError:
6487
pass
65-
text = (output / 'kwin.log').read_text()
88+
text = (output / 'client.log').read_text() if (output / 'client.log').exists() else ''
6689
for line in text.splitlines():
6790
if line.startswith(('PASS ', 'FAIL ', '{"passed"', 'RESULT')):
6891
print(line, flush=True)
6992
print('KWIN_LOG', output / 'kwin.log', flush=True)
93+
print('CLIENT_LOG', output / 'client.log', flush=True)
7094
# A compositor exit before launching its client is not a passing suite.
71-
assert ('PASS ' in text or 'FAIL ' in text) and ('"failed"' in text or 'RESULT ' in text), text[-4000:]
72-
raise SystemExit(code or int('FAIL ' in text))
95+
assert ('PASS ' in text or 'FAIL ' in text) and (
96+
args.command or '"failed"' in text or 'RESULT ' in text), text[-4000:]
97+
client_code = int((output / 'exit-code').read_text())
98+
raise SystemExit(code or client_code or int('FAIL ' in text))
7399

74100

75101
if __name__ == '__main__':
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import 'dart:io';
2+
3+
import 'package:flutter/widgets.dart';
4+
import 'package:window_manager/window_manager.dart';
5+
6+
Future<void> main() async {
7+
WidgetsFlutterBinding.ensureInitialized();
8+
final window = WindowManager.instance.getCurrent()!;
9+
final minimum = Platform.environment['WM_SKIP_MINIMUM'] != '1';
10+
window.titleBarStyle = TitleBarStyle.hidden;
11+
if (minimum) window.minimumSize = const Size(800, 600).toNative();
12+
window.setSize(const Size(800, 600).toNative(), false);
13+
window.title = 'NativeAPI minimum size regression';
14+
runApp(
15+
const Directionality(
16+
textDirection: TextDirection.ltr,
17+
child: ColoredBox(
18+
color: Color(0xFF244865),
19+
child: Center(child: Text('800 x 600')),
20+
),
21+
),
22+
);
23+
window.show();
24+
await Future<void>.delayed(const Duration(seconds: 1));
25+
window.setSize(const Size(800, 600).toNative(), false);
26+
await Future<void>.delayed(const Duration(seconds: 1));
27+
var failures = 0;
28+
void checkSize(String phase) {
29+
final size = window.size.toSize();
30+
final ok = (size.width - 800).abs() <= 2 && (size.height - 600).abs() <= 2;
31+
stdout.writeln('${ok ? "PASS" : "FAIL"} minimum=$minimum $phase $size');
32+
if (!ok) failures++;
33+
}
34+
35+
checkSize('initial');
36+
for (var cycle = 1; cycle <= 3; cycle++) {
37+
window.maximize();
38+
await Future<void>.delayed(const Duration(seconds: 1));
39+
stdout.writeln('SIZE maximized=${window.size.toSize()}');
40+
window.unmaximize();
41+
await Future<void>.delayed(const Duration(seconds: 1));
42+
checkSize('restored cycle=$cycle');
43+
}
44+
stdout.writeln('RESULT failures=$failures');
45+
window.close();
46+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# Hidden-window minimum size restoration (#35)
2+
3+
Verified on 2026-11-14. The regression was reproduced on `omarchy` with GTK
4+
3.24.52 and a private KWin 6.8.1 Wayland compositor. These tests do not use the
5+
logged-on desktop or inject mouse/keyboard input.
6+
7+
## Cause and fix
8+
9+
The previous minimum hint included the difference between the GDK surface and
10+
the visible frame. For a hidden-title-bar window this includes the 132-pixel
11+
shadow gutter on each side. During a maximize transition, that surface minimum
12+
can outlive the gutter it describes. GDK constrains the configure with the stale
13+
minimum and loses the normal restore size.
14+
15+
GTK windows with content now express the minimum through the content widget's
16+
size request. GTK derives its surface minimum from that requisition and the
17+
current decorations in the same layout pass. The public minimum remains a frame
18+
size: visible decorations are subtracted when calculating the content request.
19+
The implementation preserves the host's previous size request, restores it when
20+
the minimum is cleared, follows replacement children, and keeps the request on
21+
the native window rather than on a temporary C++ wrapper. Maximum and aspect
22+
ratio hints retain their existing behavior; windows without content and bare
23+
GDK windows retain the surface-hint path.
24+
25+
Relevant GTK implementation:
26+
[GtkWindow geometry hints and requisitions](https://github.com/GNOME/gtk/blob/3.24.52/gtk/gtkwindow.c)
27+
and [Wayland configure constraints and saved sizes](https://github.com/GNOME/gtk/blob/3.24.52/gdk/wayland/gdkwindow-wayland.c).
28+
29+
## Results
30+
31+
| Scenario | Before | Fixed |
32+
| --- | --- | --- |
33+
| Native GTK, minimum 800×600, three maximize/restore cycles | 1280×864 after every restore | 800×600 after every restore |
34+
| Same native test without minimum | 800×600 | 800×600 |
35+
| Native GTK, Breeze, Wayland, 125% output scaling | — | 48 checks passed |
36+
| Native GTK, Breeze, XWayland, 125% output scaling | — | 48 checks passed |
37+
| Existing size-constraint suite, Wayland | — | 36 checks passed |
38+
| Existing size-constraint suite, Breeze, XWayland | — | 48 checks passed |
39+
| Existing content aspect-ratio suite, Wayland | — | 9 checks passed |
40+
| Flutter 3.50 stock runner, Breeze, Wayland, minimum enabled/omitted | — | Initial size and all three restores are 800×600 in both runs |
41+
| Same Flutter binary, XWayland, minimum enabled/omitted | — | Initial size and all three restores are 800×600 in both runs |
42+
43+
The new native test covers windows with and without an application header bar,
44+
both minimum-size modes, below-minimum and above-maximum resize requests,
45+
clearing the minimum, and preserving the host's existing widget size request.
46+
It measures native geometry, not screenshots. Interactive resize drags are not
47+
part of this test.
48+
49+
The Flutter fixture is built in a freshly generated project with an unmodified
50+
Linux runner, using Flutter 3.50.0 / Dart 3.14.0 and local `window_manager` 0.7.0
51+
plus the local nativeapi packages. Its Linux bundle was built on `ubuntu-nuc`
52+
and executed on `omarchy` against GTK 3.24.52. The compositor's saved
53+
`outputs.json` confirms scale 1.25 on a 1920×1000 output (1536×800 logical).
54+
Flutter logged subsurface-frame timeout warnings during some transitions, but
55+
the settled initial/restore geometry checks passed. Fedora 45 and KWin 6.8.2
56+
were not independently tested.
57+
58+
The older GTK 3.24.41 / KWin 5.27.11 setup on `ubuntu-nuc` did not reproduce the
59+
native restoration failure. The failing baseline used core `1f3c8f5`; no package
60+
release is part of this fix.
61+
62+
## Reproduce
63+
64+
On a Linux host with GTK development packages, Flutter, KWin and kscreen-doctor:
65+
66+
```bash
67+
cmake -S core -B core/build -DNATIVEAPI_BUILD_EXAMPLES=OFF -DBUILD_TESTING=ON
68+
cmake --build core/build --target window_minimum_restore_linux_test window_size_constraints_linux_test window_aspect_ratio_linux_test -j6
69+
python3 tools/gui/build_minimum_restore_flutter.py
70+
71+
GTK_THEME=Breeze python3 tools/gui/window_manager_kwin_test.py --scale 1.25 --width 1920 --height 1000 --command core/build/tests/window_minimum_restore_linux_test
72+
GTK_THEME=Breeze python3 tools/gui/window_manager_kwin_test.py --scale 1.25 --width 1920 --height 1000 --command core/build/minimum-restore-flutter/build/linux/x64/debug/bundle/minimum_restore
73+
```
74+
75+
Add `--backend x11` before `--command` to run the client through the private
76+
XWayland server. Set `WM_SKIP_MINIMUM=1` for the Flutter control. For extracted
77+
KWin packages, provide `--kwin <path>` and `--environment-json <paths.json>`;
78+
`--kscreen-doctor <path>` overrides its location. The runner verifies the actual
79+
output scale, retains compositor/client logs, native exit status and output
80+
configuration under `core/build/window-manager-kwin/<run-id>`, and fails on
81+
`FAIL` output even if a Flutter window exits with status zero.
82+
83+
Recorded runs on `omarchy`:
84+
85+
- Native baseline: `1794666475766643792`.
86+
- Native Breeze Wayland: `1794666920544885957`.
87+
- Native Breeze XWayland: `1794666799177312944`.
88+
- Existing constraints: `1794666673585545866`; aspect ratio: `1794666697894478020`.
89+
- Existing constraints on XWayland: `1794667024894672839`.
90+
- Flutter Wayland with minimum: `1794666920304680859`; control: `1794666986824772499`.
91+
- Flutter XWayland with minimum: `1794666987953511038`; control: `1794667026079410430`.

0 commit comments

Comments
 (0)