From ba1d50cdfcccc5893c9f837de7260e4eb684da3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=BF=E7=99=BD=E5=8F=94?= <11794527+absfan@user.noreply.gitee.com> Date: Tue, 3 Nov 2026 10:53:40 +0800 Subject: [PATCH] fix-ui-preserve-acrylic-after-browser-navigation --- docs/testing/2026-11-03-ui-issue16.md | 18 +++++++++ .../trial_task_center/ui/dsh_native.py | 6 ++- tests/ui/test_acrylic_material.py | 13 ++++++ tools/accept_acrylic_ui.py | 40 ++++++++++++++++++- 4 files changed, 74 insertions(+), 3 deletions(-) create mode 100644 docs/testing/2026-11-03-ui-issue16.md diff --git a/docs/testing/2026-11-03-ui-issue16.md b/docs/testing/2026-11-03-ui-issue16.md new file mode 100644 index 0000000..7022ba0 --- /dev/null +++ b/docs/testing/2026-11-03-ui-issue16.md @@ -0,0 +1,18 @@ +# Issue #16: Acrylic after returning from the browser workspace + +Scope: UI rendering only. Provider/model configuration, runtime protocol, tools and task operations are unchanged. + +The browser workspace previously shared its native composition parent with the Acrylic main window. Showing a real QWebEngineView made the parent surface opaque; hiding the browser did not restore the live backdrop. The alpha-buffer size, transparency attribute and Acrylic property still reported enabled. Reapplying Windows composition alone did not fix the rendering. + +The browser workspace now uses `WA_NativeWindow` so Chromium composes into its own child native surface. This keeps its opaque browser background separate from the task-center backdrop and retains the existing stacked-page navigation. + +Validation on Windows 11 build 26200, 125% scaling: + +- Regression test uses a real QWebEngineView and checks its native composition parent. It failed before the fix and passed afterward. +- `python -m pytest -q tests/ui --tb=short --junitxml=build/issue16-ui-tests.xml`: **172 passed**. +- `python tools/accept_acrylic_ui.py --output build/issue16-final --webengine-roundtrip`: passed. The test uses sample projects and an owned changing backdrop. It displays a local HTML page in real Chromium, without launching the Harness server, model requests or CAD. +- Before the fix, changing the background after returning produced a sidebar pixel difference of **0.0**. After the fix, two consecutive round trips each produced **20.79** (threshold > 2); the solid table difference stayed **0.0** (threshold < 1.5). +- With reduced transparency enabled, the same navigation produced a sidebar difference of **0.0** as expected. Search, empty results, solid fallback, 980×700 layout and visible stop controls also passed. +- An initial focused run reported one existing Qt fixture teardown race (`TrialTaskCenterWindow already deleted`); the subsequent complete UI run passed without errors. + +Screenshots and machine-readable results are local artifacts under `build/issue16-final/`. No release package was built. PR #15 is synchronized with main `3cec9ad`; unrelated main-workspace changes were left untouched. diff --git a/src/dx_productivity/trial_task_center/ui/dsh_native.py b/src/dx_productivity/trial_task_center/ui/dsh_native.py index 826a4eb..61a2ee1 100644 --- a/src/dx_productivity/trial_task_center/ui/dsh_native.py +++ b/src/dx_productivity/trial_task_center/ui/dsh_native.py @@ -5,7 +5,7 @@ import json import codecs from pathlib import Path -from PySide6.QtCore import QProcess, QProcessEnvironment, QTimer, QUrl, Signal +from PySide6.QtCore import QProcess, QProcessEnvironment, QTimer, QUrl, Signal, Qt from PySide6.QtWebEngineCore import QWebEnginePage, QWebEngineProfile, QWebEngineSettings from PySide6.QtWebEngineWidgets import QWebEngineView from PySide6.QtWidgets import QLabel, QPushButton, QVBoxLayout, QWidget @@ -37,6 +37,10 @@ class NativeHarnessView(QWidget): def __init__(self, data_root: Path, parent=None): super().__init__(parent) + # Give Chromium its own native composition boundary. Otherwise its + # texture compositor turns the shared Acrylic top-level surface opaque, + # even after this workspace is hidden again. + self.setAttribute(Qt.WidgetAttribute.WA_NativeWindow) self.setObjectName('dshNativeWorkspace') self.setStyleSheet('QWidget#dshNativeWorkspace {background:white;}') self.data_root = Path(data_root) diff --git a/tests/ui/test_acrylic_material.py b/tests/ui/test_acrylic_material.py index a7bc773..25cb114 100644 --- a/tests/ui/test_acrylic_material.py +++ b/tests/ui/test_acrylic_material.py @@ -93,6 +93,19 @@ def test_repeated_refresh_does_not_reconfigure_composition(qtbot): assert len(backend.calls)==1 +def test_webengine_has_its_own_native_composition_parent(qtbot, tmp_path): + from PySide6.QtCore import Qt + from PySide6.QtWidgets import QVBoxLayout + from dx_productivity.trial_task_center.ui.dsh_native import NativeHarnessView + window=QWidget();qtbot.addWidget(window) + window.setAttribute(Qt.WidgetAttribute.WA_TranslucentBackground) + view=NativeHarnessView(tmp_path,window) + QVBoxLayout(window).addWidget(view) + window.show() + # The browser must compose into its child HWND, not the Acrylic HWND. + assert view.web.nativeParentWidget() is view + + def test_deferred_material_refresh_never_uses_a_destroyed_window(qtbot,qapp): from PySide6.QtCore import QCoreApplication,QEvent window=QWidget() # This test owns destruction rather than pytest-qt teardown. diff --git a/tools/accept_acrylic_ui.py b/tools/accept_acrylic_ui.py index 3fe01bb..b4cf31d 100644 --- a/tools/accept_acrylic_ui.py +++ b/tools/accept_acrylic_ui.py @@ -16,8 +16,8 @@ import time os.environ.pop('QT_QPA_PLATFORM',None) sys.path.insert(0,str(Path(__file__).resolve().parents[1]/'src')) -from PySide6.QtCore import Qt,QRectF -from PySide6.QtGui import QColor,QFont,QPainter,QLinearGradient,QPen +from PySide6.QtCore import Qt,QRectF,QPoint +from PySide6.QtGui import QColor,QFont,QPainter,QLinearGradient,QPen,QCursor from PySide6.QtWidgets import QApplication,QWidget,QToolTip from PIL import ImageGrab,ImageChops,ImageStat from dx_productivity.trial_task_center.store import TaskStore @@ -29,6 +29,7 @@ from dx_productivity.trial_task_center.target_plan import ComponentTarget,Target def main(): parser=argparse.ArgumentParser(description=__doc__) parser.add_argument('--output',type=Path,default=Path('build/acrylic-acceptance')) + parser.add_argument('--webengine-roundtrip',action='store_true') args=parser.parse_args();out=args.output.resolve();out.mkdir(parents=True,exist_ok=True) app=QApplication([]);app.setFont(QFont('Microsoft YaHei UI',9)) def settle(seconds=.2): @@ -80,6 +81,7 @@ def main(): assert window.property('acrylicEnabled'),'Native Acrylic not available under current system policy' report['native_enabled']=True def capture(name): + QCursor.setPos(window.mapToGlobal(QPoint(12,12))) settle(.7) QToolTip.hideText();settle(.12) geo=window.geometry();scale=screen.devicePixelRatio() @@ -121,6 +123,31 @@ def main(): assert report['right_header_backdrop_difference']>2,report assert report['right_execution_backdrop_difference']>2,report assert report['opaque_table_backdrop_difference']<1.5,report + if args.webengine_roundtrip: + from dx_productivity.trial_task_center.ui.dsh_native import NativeHarnessView + report['before_webengine_surface']={'alpha':window.windowHandle().format().alphaBufferSize(), + 'translucent':window.testAttribute(Qt.WidgetAttribute.WA_TranslucentBackground), + 'acrylic':window.property('acrylicEnabled'),'contrast':window.property('highContrastFallback')} + def create_view(): + view=NativeHarnessView(root/'dsh',window) + view.start=lambda:None # Real Chromium surface; no server, model or CAD. + view.web.setHtml('Owned DSH WebEngine surface') + return view + window._create_dsh_view=create_view + for index in range(2): + window.dsh_action.trigger();settle(2) + window.task_center_action.trigger();settle(1) + report['after_webengine_surface']={'alpha':window.windowHandle().format().alphaBufferSize(), + 'translucent':window.testAttribute(Qt.WidgetAttribute.WA_TranslucentBackground), + 'acrylic':window.property('acrylicEnabled'),'contrast':window.property('highContrastFallback')} + background.phase=0;background.update();capture(f'roundtrip-{index}-a') + background.phase=1;background.update();capture(f'roundtrip-{index}-b') + delta=ImageChops.difference(captures[f'roundtrip-{index}-a'],captures[f'roundtrip-{index}-b']) + report[f'roundtrip_{index}_sidebar_difference']=mean(delta.crop(sidebar)) + report[f'roundtrip_{index}_table_difference']=mean(delta.crop(table)) + (out/'roundtrip-probe.json').write_text(json.dumps(report,indent=2),encoding='utf8') + assert report[f'roundtrip_{index}_sidebar_difference']>2,report + assert report[f'roundtrip_{index}_table_difference']<1.5,report window.plan_panel.find_text.setText('RV');window.plan_panel.find() report['visible_search_feedback']=window.plan_panel.find_result.isVisible() assert '2 / 6'in window.plan_panel.find_result.text() @@ -136,6 +163,15 @@ def main(): report['solid_sidebar_mean']=ImageStat.Stat(solid.crop(sidebar)).mean assert min(report['solid_sidebar_mean'])>200,report report['solid_fallback']=True + if args.webengine_roundtrip: + window.dsh_action.trigger();settle(.3) + window.task_center_action.trigger();settle(.3) + assert not window.property('acrylicEnabled') + background.phase=0;background.update();capture('roundtrip-solid-a') + background.phase=1;background.update();capture('roundtrip-solid-b') + delta=ImageChops.difference(captures['roundtrip-solid-a'],captures['roundtrip-solid-b']) + report['roundtrip_reduced_sidebar_difference']=mean(delta.crop(sidebar)) + assert report['roundtrip_reduced_sidebar_difference']<1.5,report window.reduced_transparency_button.setChecked(False);settle(.3) window.resize(980,700);capture('native-app-compact') report['compact_size']=[window.width(),window.height()]