sideview 0.5.0__tar.gz → 0.6.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. {sideview-0.5.0 → sideview-0.6.1}/CHANGELOG.md +19 -0
  2. {sideview-0.5.0 → sideview-0.6.1}/PKG-INFO +1 -1
  3. {sideview-0.5.0 → sideview-0.6.1}/docs/quick/README.md +23 -4
  4. {sideview-0.5.0 → sideview-0.6.1}/native/linux/webview_host.cpp +22 -2
  5. {sideview-0.5.0 → sideview-0.6.1}/native/macos/webview_host.mm +76 -2
  6. {sideview-0.5.0 → sideview-0.6.1}/pyproject.toml +2 -2
  7. sideview-0.6.1/scripts/validate_covered_capture.py +311 -0
  8. {sideview-0.5.0 → sideview-0.6.1}/scripts/validate_quick.py +39 -11
  9. {sideview-0.5.0 → sideview-0.6.1}/src/sideview/_backend.py +7 -1
  10. {sideview-0.5.0 → sideview-0.6.1}/src/sideview/quick/__init__.py +15 -2
  11. {sideview-0.5.0 → sideview-0.6.1}/src/sideview/quick/_projection.py +63 -21
  12. {sideview-0.5.0 → sideview-0.6.1}/tests/test_quick_browser.py +32 -0
  13. {sideview-0.5.0 → sideview-0.6.1}/CONTRIBUTING.md +0 -0
  14. {sideview-0.5.0 → sideview-0.6.1}/LICENSE +0 -0
  15. {sideview-0.5.0 → sideview-0.6.1}/README.md +0 -0
  16. {sideview-0.5.0 → sideview-0.6.1}/SECURITY.md +0 -0
  17. {sideview-0.5.0 → sideview-0.6.1}/examples/quick/Browser.qml +0 -0
  18. {sideview-0.5.0 → sideview-0.6.1}/examples/quick/Projections.qml +0 -0
  19. {sideview-0.5.0 → sideview-0.6.1}/examples/quick/Shell.qml +0 -0
  20. {sideview-0.5.0 → sideview-0.6.1}/examples/quick/page.html +0 -0
  21. {sideview-0.5.0 → sideview-0.6.1}/examples/quick/run.py +0 -0
  22. {sideview-0.5.0 → sideview-0.6.1}/examples/simple_browser.py +0 -0
  23. {sideview-0.5.0 → sideview-0.6.1}/native/CMakeLists.txt +0 -0
  24. {sideview-0.5.0 → sideview-0.6.1}/native/native_webview.h +0 -0
  25. {sideview-0.5.0 → sideview-0.6.1}/native/win32/webview_host.cpp +0 -0
  26. {sideview-0.5.0 → sideview-0.6.1}/release-please-config.json +0 -0
  27. {sideview-0.5.0 → sideview-0.6.1}/scripts/benchmark_frame_stream.py +0 -0
  28. {sideview-0.5.0 → sideview-0.6.1}/scripts/benchmark_quick.py +0 -0
  29. {sideview-0.5.0 → sideview-0.6.1}/scripts/benchmark_workload.py +0 -0
  30. {sideview-0.5.0 → sideview-0.6.1}/scripts/build_linux.sh +0 -0
  31. {sideview-0.5.0 → sideview-0.6.1}/scripts/build_windows.ps1 +0 -0
  32. {sideview-0.5.0 → sideview-0.6.1}/scripts/validate_distribution.py +0 -0
  33. {sideview-0.5.0 → sideview-0.6.1}/scripts/validate_pull_request_title.py +0 -0
  34. {sideview-0.5.0 → sideview-0.6.1}/scripts/validate_windows_native_bounds.py +0 -0
  35. {sideview-0.5.0 → sideview-0.6.1}/src/sideview/__init__.py +0 -0
  36. {sideview-0.5.0 → sideview-0.6.1}/src/sideview/_controller.py +0 -0
  37. {sideview-0.5.0 → sideview-0.6.1}/src/sideview/py.typed +0 -0
  38. {sideview-0.5.0 → sideview-0.6.1}/src/sideview/quick/SideView.qml +0 -0
  39. {sideview-0.5.0 → sideview-0.6.1}/src/sideview/quick/_browser.py +0 -0
  40. {sideview-0.5.0 → sideview-0.6.1}/src/sideview/quick/_frames.py +0 -0
  41. {sideview-0.5.0 → sideview-0.6.1}/src/sideview/widget.py +0 -0
  42. {sideview-0.5.0 → sideview-0.6.1}/tests/conftest.py +0 -0
  43. {sideview-0.5.0 → sideview-0.6.1}/tests/test_browser_controller.py +0 -0
  44. {sideview-0.5.0 → sideview-0.6.1}/tests/test_imports.py +0 -0
  45. {sideview-0.5.0 → sideview-0.6.1}/tests/test_native_bounds.py +0 -0
  46. {sideview-0.5.0 → sideview-0.6.1}/tests/test_quick_frames.py +0 -0
  47. {sideview-0.5.0 → sideview-0.6.1}/tests/test_release_tooling.py +0 -0
@@ -1,5 +1,24 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.6.1](https://github.com/AlexsanderMe/SideView/compare/v0.6.0...v0.6.1) (2026-12-01)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * **quick:** keep WKWebView frame outputs live while covered ([#20](https://github.com/AlexsanderMe/SideView/issues/20)) ([586a067](https://github.com/AlexsanderMe/SideView/commit/586a067f175f7d5c27952ed6efa02d59e2515b53))
9
+
10
+ ## [0.6.0](https://github.com/AlexsanderMe/SideView/compare/v0.5.0...v0.6.0) (2026-12-01)
11
+
12
+
13
+ ### Features
14
+
15
+ * **quick:** expose live browser frames to nonvisual consumers ([#18](https://github.com/AlexsanderMe/SideView/issues/18)) ([a9acb20](https://github.com/AlexsanderMe/SideView/commit/a9acb209ca20586709133b958188284bb77d721d))
16
+
17
+
18
+ ### Build System
19
+
20
+ * **deps-dev:** bump scikit-build-core from 1.0.3 to 1.1.0 in the python-build-and-development group ([#11](https://github.com/AlexsanderMe/SideView/issues/11)) ([b68868d](https://github.com/AlexsanderMe/SideView/commit/b68868d51001725118cf1d5060510a43c36f8a74))
21
+
3
22
  ## [0.5.0](https://github.com/AlexsanderMe/SideView/compare/v0.4.1...v0.5.0) (2026-11-30)
4
23
 
5
24
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sideview
3
- Version: 0.5.0
3
+ Version: 0.6.1
4
4
  Summary: A lightweight native webview for PySide6 with Qt Widgets and Qt Quick/QML support.
5
5
  Keywords: pyside6,qt,webview,webview2,webkit,webkitgtk
6
6
  Author: AlexsanderMe
@@ -133,11 +133,30 @@ production is paused.
133
133
  projections. Projections are visual previews. Interact with the web page
134
134
  in the source view.
135
135
 
136
- When `capabilities.hiddenCapture` is true, a visible projection keeps the
136
+ For an encoder or other nonvisual consumer, create a `SideViewFrameOutput`
137
+ on the GUI thread. It shares the same decoded frames and limits as the visual
138
+ projections. The type is available in Python and in the SideView QML module.
139
+
140
+ ```python
141
+ from sideview.quick import SideViewFrameOutput
142
+
143
+ output = SideViewFrameOutput(parent)
144
+ output.frameChanged.connect(consume_image)
145
+ output.source = browser
146
+ output.active = True
147
+ ```
148
+
149
+ `frameChanged(QImage)` delivers the current image on activation if available.
150
+ A null image invalidates the previous frame. Keep the GUI-thread callback short.
151
+ Set `active = False` to stop deliveries. Replacing the source or destroying the
152
+ output releases its demand, and other consumers keep their subscriptions.
153
+
154
+ When `capabilities.hiddenCapture` is true, an active frame output or visible projection keeps the
137
155
  initialized browser rendering while its native child is covered or its QML
138
- item is hidden. This is supported with WebView2 on Windows. The source
139
- window must stay visible and the source item must remain instantiated.
140
- Other backends hold the last frame until the source is visible again.
156
+ item is hidden. This is supported by WebView2 on Windows, WKWebView on macOS,
157
+ and WebKitGTK on Linux with XCB. The source window must stay visible and the
158
+ source item must remain instantiated. If the capability is unavailable, the
159
+ output holds the last frame until the source is visible again.
141
160
 
142
161
  Keep the browser item alive and leave its viewport in place when drawing a
143
162
  QML drawer or menu over the browser.
@@ -47,6 +47,8 @@ struct Host {
47
47
  void *capture_user_data = nullptr;
48
48
  uintptr_t native_view = 0;
49
49
  int references = 1;
50
+ bool quick = false;
51
+ bool quick_window_unmapped = false;
50
52
  bool context_menu_enabled = true;
51
53
  bool navigation_failed = false;
52
54
  bool script_handler_registered = false;
@@ -306,6 +308,16 @@ void on_webview_destroy(GtkWidget *widget, Host *host) {
306
308
  GdkFilterReturn on_plug_xevent(GdkXEvent *native_event, GdkEvent *, gpointer data) {
307
309
  const auto *event = static_cast<const XEvent *>(native_event);
308
310
  auto *host = static_cast<Host *>(data);
311
+ if (host->quick && event->type == UnmapNotify
312
+ && event->xunmap.window == host->native_view) {
313
+ host->quick_window_unmapped = true;
314
+ return GDK_FILTER_REMOVE;
315
+ }
316
+ if (host->quick_window_unmapped && event->type == MapNotify
317
+ && event->xmap.window == host->native_view) {
318
+ host->quick_window_unmapped = false;
319
+ return GDK_FILTER_REMOVE;
320
+ }
309
321
  if (event->type != DestroyNotify || event->xdestroywindow.window != host->native_view) {
310
322
  return GDK_FILTER_CONTINUE;
311
323
  }
@@ -696,6 +708,7 @@ Host *create_host(const nwv_options *options, bool show_immediately) {
696
708
  }
697
709
 
698
710
  auto *host = new Host();
711
+ host->quick = !show_immediately;
699
712
  host->session = acquire_session(options);
700
713
  if (!host->session) {
701
714
  delete host;
@@ -1001,10 +1014,17 @@ NWV_EXPORT int nwv_quick_stop(void *handle) {
1001
1014
  return 1;
1002
1015
  }
1003
1016
 
1017
+ NWV_EXPORT int nwv_quick_supports_hidden_projection() {
1018
+ return 1;
1019
+ }
1020
+
1004
1021
  NWV_EXPORT void nwv_quick_set_visible(void *handle, int visible) {
1005
1022
  auto *host = static_cast<Host *>(handle);
1006
- if (host && !host->destroyed && host->plug) {
1007
- gtk_widget_set_visible(host->plug, visible != 0);
1023
+ if (host && !host->destroyed && host->plug && host->webview) {
1024
+ if (visible && !gtk_widget_get_visible(host->plug)) {
1025
+ gtk_widget_show(host->plug);
1026
+ }
1027
+ gtk_widget_set_visible(GTK_WIDGET(host->webview), visible != 0);
1008
1028
  }
1009
1029
  }
1010
1030
 
@@ -1,6 +1,7 @@
1
1
  #include "../native_webview.h"
2
2
 
3
3
  #import <Cocoa/Cocoa.h>
4
+ #import <QuartzCore/CALayer.h>
4
5
  #import <WebKit/WebKit.h>
5
6
 
6
7
  #include <algorithm>
@@ -23,10 +24,32 @@
23
24
  @property(nonatomic, assign) void *host;
24
25
  @end
25
26
 
27
+ @interface NWVCaptureParkingView : NSView
28
+ @end
29
+
30
+ @implementation NWVCaptureParkingView
31
+
32
+ - (NSView *)hitTest:(NSPoint)point {
33
+ (void)point;
34
+ return nil;
35
+ }
36
+
37
+ - (BOOL)isAccessibilityHidden {
38
+ return YES;
39
+ }
40
+
41
+ - (NSArray *)accessibilityChildren {
42
+ return @[];
43
+ }
44
+
45
+ @end
46
+
26
47
  namespace {
27
48
 
28
49
  struct Host : std::enable_shared_from_this<Host> {
50
+ __weak NSView *presentationParent = nil;
29
51
  NSView *container = nil;
52
+ NWVCaptureParkingView *captureParkingView = nil;
30
53
  NWVWebView *webview = nil;
31
54
  WKWebsiteDataStore *dataStore = nil;
32
55
  WKUserContentController *userContentController = nil;
@@ -123,6 +146,48 @@ void resize_host(Host *host, int width, int height) {
123
146
  [host->webview setFrame:frame];
124
147
  }
125
148
 
149
+ void set_quick_rendering(Host *host, bool render) {
150
+ NSView *parent = host->presentationParent;
151
+ if (!render || !parent) {
152
+ host->container.hidden = YES;
153
+ [host->captureParkingView removeFromSuperview];
154
+ return;
155
+ }
156
+
157
+ if (![parent isHiddenOrHasHiddenAncestor]) {
158
+ if (host->container.superview != parent) {
159
+ [parent addSubview:host->container];
160
+ host->container.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
161
+ host->container.frame = parent.bounds;
162
+ [host->captureParkingView removeFromSuperview];
163
+ }
164
+ host->container.hidden = NO;
165
+ return;
166
+ }
167
+
168
+ NSView *contentView = parent.window.contentView;
169
+ if (!contentView) {
170
+ host->container.hidden = YES;
171
+ return;
172
+ }
173
+
174
+ // Keep the WKWebView in the same NSWindow, outside Qt's hidden NSView.
175
+ // The parent clips the full viewport and has no mouse or accessibility target.
176
+ if (!host->captureParkingView) {
177
+ host->captureParkingView = [[NWVCaptureParkingView alloc] initWithFrame:NSZeroRect];
178
+ host->captureParkingView.wantsLayer = YES;
179
+ host->captureParkingView.layer.masksToBounds = YES;
180
+ }
181
+ if (host->captureParkingView.superview != contentView) {
182
+ [contentView addSubview:host->captureParkingView positioned:NSWindowBelow relativeTo:nil];
183
+ }
184
+ if (host->container.superview != host->captureParkingView) {
185
+ host->container.autoresizingMask = NSViewNotSizable;
186
+ [host->captureParkingView addSubview:host->container];
187
+ }
188
+ host->container.hidden = NO;
189
+ }
190
+
126
191
  void run_on_main_sync(dispatch_block_t block) {
127
192
  if ([NSThread isMainThread]) {
128
193
  block();
@@ -392,6 +457,7 @@ NWV_EXPORT void *nwv_create(void *parent_view, const nwv_options *options) {
392
457
 
393
458
  run_on_main_sync(^{
394
459
  NSView *parent = (__bridge NSView *)parent_view;
460
+ host->presentationParent = parent;
395
461
 
396
462
  NSRect frame = parent.bounds;
397
463
  host->container = [[NSView alloc] initWithFrame:frame];
@@ -477,6 +543,8 @@ NWV_EXPORT void nwv_destroy(void *handle) {
477
543
  [host->userContentController removeScriptMessageHandlerForName:@"nativeWebView"];
478
544
  [host->webview removeFromSuperview];
479
545
  [host->container removeFromSuperview];
546
+ [host->captureParkingView removeFromSuperview];
547
+ host->captureParkingView = nil;
480
548
  host->webview = nil;
481
549
  host->dataStore = nil;
482
550
  host->userContentController = nil;
@@ -666,11 +734,15 @@ NWV_EXPORT int nwv_quick_stop(void *handle) {
666
734
  return 1;
667
735
  }
668
736
 
737
+ NWV_EXPORT int nwv_quick_supports_hidden_projection() {
738
+ return 1;
739
+ }
740
+
669
741
  NWV_EXPORT void nwv_quick_set_visible(void *handle, int visible) {
670
742
  auto host = get_host(handle);
671
743
  if (host && !host->destroyed) {
672
744
  run_on_main_sync(^{
673
- host->container.hidden = visible == 0;
745
+ set_quick_rendering(host.get(), visible != 0);
674
746
  });
675
747
  }
676
748
  }
@@ -686,7 +758,9 @@ NWV_EXPORT int nwv_quick_focus(void *handle, int reason) {
686
758
  }
687
759
  __block BOOL accepted = NO;
688
760
  run_on_main_sync(^{
689
- if (![host->webview isHiddenOrHasHiddenAncestor]) {
761
+ NSView *parent = host->presentationParent;
762
+ if (parent && host->container.superview == parent
763
+ && ![host->webview isHiddenOrHasHiddenAncestor]) {
690
764
  accepted = [host->webview.window makeFirstResponder:host->webview];
691
765
  }
692
766
  });
@@ -1,10 +1,10 @@
1
1
  [build-system]
2
- requires = ["scikit-build-core==1.0.3"]
2
+ requires = ["scikit-build-core==1.1.0"]
3
3
  build-backend = "scikit_build_core.build"
4
4
 
5
5
  [project]
6
6
  name = "sideview"
7
- version = "0.5.0"
7
+ version = "0.6.1"
8
8
  description = "A lightweight native webview for PySide6 with Qt Widgets and Qt Quick/QML support."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -0,0 +1,311 @@
1
+ """Check fresh WebKit frames while the native Quick browser is covered."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ import sys
7
+ import traceback
8
+ from argparse import ArgumentParser
9
+ from functools import partial
10
+ from http.server import ThreadingHTTPServer
11
+ from pathlib import Path
12
+ from tempfile import TemporaryDirectory
13
+ from threading import Thread
14
+
15
+ import shiboken6
16
+ from PySide6.QtCore import QByteArray, QObject, QPoint, QTimer, QUrl
17
+ from PySide6.QtGui import QColor, QGuiApplication, QImage, QWindow
18
+ from PySide6.QtQml import QQmlApplicationEngine
19
+ from validate_quick import _QuietHandler, wait_until
20
+
21
+ from sideview.quick import SideViewFrameOutput, register_types
22
+
23
+ QML = b"""
24
+ import QtQuick
25
+ import SideView
26
+
27
+ Window {
28
+ id: root
29
+ visible: true
30
+ width: 480
31
+ height: 320
32
+ required property url home
33
+ required property string profileRoot
34
+ SideView {
35
+ id: browser
36
+ objectName: "browser"
37
+ anchors.fill: parent
38
+ url: root.home
39
+ sessionId: "covered-capture"
40
+ sessionDataRoot: root.profileRoot
41
+ projectionMaxFps: 15
42
+ }
43
+ Rectangle {
44
+ objectName: "operatorOverlay"
45
+ anchors.fill: parent
46
+ visible: browser.overlayState === "snapshot" || browser.overlayState === "placeholder"
47
+ color: "#e6b831"
48
+ }
49
+ }
50
+ """
51
+
52
+ PAGE = """<!doctype html><meta charset="utf-8"><title>Covered capture</title>
53
+ <style>html, body { margin: 0; height: 100%; background: #d94838 }</style>
54
+ <script>
55
+ window.repaints = 0;
56
+ window.repaint = (color) => requestAnimationFrame(() => {
57
+ document.body.style.backgroundColor = color;
58
+ window.repaints++;
59
+ });
60
+ </script>
61
+ """
62
+
63
+
64
+ def matches(image: QImage, x: int, y: int, color: str) -> bool:
65
+ if image.isNull():
66
+ return False
67
+ return all(
68
+ abs(actual - expected) <= 10
69
+ for actual, expected in zip(
70
+ image.pixelColor(x, y).getRgb(), QColor(color).getRgb(), strict=True
71
+ )
72
+ )
73
+
74
+
75
+ def verify(root: QWindow, *, expect_unsupported: bool, check_screen: bool) -> None:
76
+ browser = root.findChild(QObject, "browser")
77
+ overlay = root.findChild(QObject, "operatorOverlay")
78
+
79
+ def ready() -> bool:
80
+ assert browser.property("initializationState") != "error", browser.property("errorString")
81
+ return browser.property("title") == "Covered capture"
82
+
83
+ wait_until(ready, "initial document", timeout=35)
84
+ host = browser.property("hostWindow")
85
+ assert host is not None, "no native child after the document loaded"
86
+ host_id = host.winId()
87
+ output = SideViewFrameOutput(root)
88
+ frames = 0
89
+ latest = QImage()
90
+ scripts = {}
91
+ failures = []
92
+
93
+ def receive(image: QImage) -> None:
94
+ nonlocal frames, latest
95
+ if not image.isNull():
96
+ frames += 1
97
+ latest = image
98
+
99
+ output.frameChanged.connect(receive)
100
+ browser.javaScriptFinished.connect(
101
+ lambda id_, result, error: scripts.update({id_: (result, error)})
102
+ )
103
+ browser.projectionFailed.connect(failures.append)
104
+
105
+ def evaluate(script: str):
106
+ request = browser.runJavaScript(script)
107
+ assert request, browser.property("errorString")
108
+ wait_until(lambda: request in scripts, "JavaScript response")
109
+ result, error = scripts.pop(request)
110
+ assert not error, error
111
+ return result
112
+
113
+ def frame_is(color: str) -> bool:
114
+ return matches(latest, latest.width() // 2, latest.height() // 2, color)
115
+
116
+ def screen_is(color: str) -> bool:
117
+ if not check_screen:
118
+ return True
119
+ screen = root.screen()
120
+ center = root.mapToGlobal(QPoint(root.width() // 2, root.height() // 2))
121
+ offset = center - screen.geometry().topLeft()
122
+ image = screen.grabWindow(0, offset.x(), offset.y(), 1, 1).toImage()
123
+ return matches(image, 0, 0, color)
124
+
125
+ def same_host() -> bool:
126
+ return (
127
+ shiboken6.isValid(host)
128
+ and browser.property("hostWindow") is host
129
+ and host.winId() == host_id
130
+ )
131
+
132
+ def covered() -> bool:
133
+ return (
134
+ root.isVisible()
135
+ and same_host()
136
+ and browser.property("overlayState") in {"snapshot", "placeholder"}
137
+ and overlay.property("visible")
138
+ and not browser.property("nativeHostVisible")
139
+ and not host.isVisible()
140
+ )
141
+
142
+ def restored() -> bool:
143
+ return (
144
+ root.isVisible()
145
+ and same_host()
146
+ and browser.property("overlayState") == "native"
147
+ and not overlay.property("visible")
148
+ and browser.property("nativeHostVisible")
149
+ and host.isVisible()
150
+ )
151
+
152
+ transitions = []
153
+
154
+ def record_state() -> None:
155
+ state = (
156
+ browser.property("overlayState"),
157
+ browser.property("nativeHostVisible"),
158
+ host.isVisible() if shiboken6.isValid(host) else None,
159
+ )
160
+ if not transitions or state != transitions[-1]:
161
+ transitions.append(state)
162
+
163
+ browser.overlayStateChanged.connect(record_state)
164
+ browser.nativeHostVisibleChanged.connect(record_state)
165
+ host.visibleChanged.connect(record_state)
166
+
167
+ def wait_for_state(predicate, description: str) -> None:
168
+ try:
169
+ wait_until(predicate, description)
170
+ except AssertionError as error:
171
+ raise AssertionError(
172
+ f"{error}. (overlayState, nativeHostVisible, child visible)={transitions!r}, "
173
+ f"overlay visible={overlay.property('visible')}, same host={same_host()}, "
174
+ f"root visible={root.isVisible()}, mode={browser.property('projectionMode')}, "
175
+ f"projection errors={failures!r}"
176
+ ) from error
177
+
178
+ def repaint(color: str, repaint_count: int, *, under_cover: bool = False) -> None:
179
+ before = frames
180
+ presentation = covered if under_cover else restored
181
+ description = f"new {color} frame under cover" if under_cover else f"new {color} frame"
182
+
183
+ def new_frame() -> bool:
184
+ assert presentation(), "host changed presentation while waiting for new pixels"
185
+ return frames > before and frame_is(color)
186
+
187
+ assert presentation()
188
+ evaluate(f"window.repaint({json.dumps(color)}); true")
189
+ try:
190
+ wait_for_state(new_frame, description)
191
+ except AssertionError as error:
192
+ visibility, count = evaluate("[document.visibilityState, window.repaints]")
193
+ raise AssertionError(
194
+ f"{error}. Page visibility={visibility}, rAF repaints={count}, "
195
+ f"frames={frames - before}, projection errors={failures!r}"
196
+ ) from error
197
+ assert evaluate("window.repaints") == repaint_count
198
+
199
+ output.source = browser
200
+ output.active = True
201
+ wait_until(lambda: frame_is("#d94838"), "original output pixels")
202
+ wait_until(lambda: screen_is("#d94838"), "original screen pixels")
203
+ supported = browser.property("capabilities")["hiddenCapture"]
204
+ expected = not expect_unsupported
205
+ assert supported == expected, (
206
+ f"{QGuiApplication.platformName()} advertised hiddenCapture={supported}; "
207
+ f"expected {expected}"
208
+ )
209
+
210
+ wait_for_state(restored, "initial native presentation")
211
+ counts = 0
212
+ for iteration in range(2):
213
+ transitions.clear()
214
+ record_state()
215
+ browser.setProperty("overlayRequested", True)
216
+ wait_for_state(covered, "covered overlay and hidden native child")
217
+ print(f"Overlay cycle {iteration + 1} covered via {browser.property('overlayState')}.")
218
+ wait_until(lambda: screen_is("#e6b831"), "operator overlay pixels")
219
+ if supported:
220
+ for color in ("#295cc5", "#45a857", "#b73583"):
221
+ counts += 1
222
+ repaint(color, counts, under_cover=True)
223
+ assert covered()
224
+ assert screen_is("#e6b831"), "native browser leaked through the overlay"
225
+ output.active = False
226
+ wait_until(
227
+ lambda: browser.property("projectionMode") == "inactive",
228
+ "last output disconnected under cover",
229
+ )
230
+ assert covered()
231
+ output.active = True
232
+ counts += 1
233
+ repaint("#245a56", counts, under_cover=True)
234
+ assert covered()
235
+ else:
236
+ assert browser.property("projectionMode") == "inactive"
237
+
238
+ browser.setProperty("overlayRequested", False)
239
+ wait_for_state(restored, "restored native presentation on the same host")
240
+ color = "#ce642a" if iteration == 0 else "#97369d"
241
+ counts += 1
242
+ repaint(color, counts)
243
+ wait_until(partial(screen_is, color), "restored page pixels")
244
+
245
+ output.active = False
246
+ wait_until(lambda: browser.property("projectionMode") == "inactive", "output stopped")
247
+
248
+
249
+ def main() -> int:
250
+ app = QGuiApplication(sys.argv)
251
+ parser = ArgumentParser(description=__doc__)
252
+ parser.add_argument("--expect-unsupported", action="store_true")
253
+ parser.add_argument(
254
+ "--check-screen",
255
+ action="store_true",
256
+ help="also sample the real screen, which must show the test window unobstructed",
257
+ )
258
+ args = parser.parse_args(app.arguments()[1:])
259
+ app.setQuitOnLastWindowClosed(False)
260
+ register_types()
261
+ with TemporaryDirectory(prefix="sideview-covered-", ignore_cleanup_errors=True) as directory:
262
+ folder = Path(directory)
263
+ (folder / "index.html").write_text(PAGE, encoding="utf-8")
264
+ handler = partial(_QuietHandler, directory=str(folder))
265
+ with ThreadingHTTPServer(("127.0.0.1", 0), handler) as server:
266
+ thread = Thread(target=server.serve_forever, daemon=True)
267
+ thread.start()
268
+ engine = QQmlApplicationEngine()
269
+ try:
270
+ engine.setInitialProperties(
271
+ {
272
+ "home": QUrl(f"http://127.0.0.1:{server.server_port}/index.html"),
273
+ "profileRoot": str(folder / "profile"),
274
+ }
275
+ )
276
+ engine.loadData(QByteArray(QML), QUrl.fromLocalFile(str(folder / "Capture.qml")))
277
+ if not engine.rootObjects():
278
+ return 1
279
+ root = engine.rootObjects()[0]
280
+
281
+ def run() -> None:
282
+ try:
283
+ verify(
284
+ root,
285
+ expect_unsupported=args.expect_unsupported,
286
+ check_screen=args.check_screen,
287
+ )
288
+ except Exception:
289
+ traceback.print_exc()
290
+ app.exit(1)
291
+ else:
292
+ app.quit()
293
+
294
+ QTimer.singleShot(0, run)
295
+ result = app.exec()
296
+ if shiboken6.isValid(root):
297
+ root.close()
298
+ finally:
299
+ shiboken6.delete(engine)
300
+ app.processEvents()
301
+ server.shutdown()
302
+ thread.join()
303
+ if result == 0:
304
+ print(
305
+ f"SideView covered frame validation passed ({app.platformName()}, {app.applicationVersion() or 'local build'})"
306
+ )
307
+ return result
308
+
309
+
310
+ if __name__ == "__main__":
311
+ raise SystemExit(main())
@@ -18,7 +18,7 @@ from PySide6.QtCore import QByteArray, QEventLoop, QObject, QTimer, QUrl
18
18
  from PySide6.QtGui import QColor, QGuiApplication, QImage, QWindow
19
19
  from PySide6.QtQml import QQmlApplicationEngine
20
20
 
21
- from sideview.quick import register_types
21
+ from sideview.quick import SideViewFrameOutput, register_types
22
22
 
23
23
  QML = b"""
24
24
  import QtQuick
@@ -293,15 +293,15 @@ def run(root: QWindow) -> None:
293
293
  wait_until(lambda: ready() and navigations, "recreated native browser")
294
294
  assert evaluate("location.pathname") == "/index.html"
295
295
 
296
- if hidden_capture:
297
- navigations = []
298
- browser.navigationFinished.connect(navigations.append)
299
- static_url = browser.property("url")
300
- static_url.setQuery("static")
301
- root.setProperty("showPreviews", True)
302
- browser.setProperty("url", static_url)
303
- wait_until(lambda: static_url in navigations, "navigation to static test page")
296
+ navigations = []
297
+ browser.navigationFinished.connect(navigations.append)
298
+ static_url = browser.property("url")
299
+ static_url.setQuery("static")
300
+ root.setProperty("showPreviews", hidden_capture)
301
+ browser.setProperty("url", static_url)
302
+ wait_until(lambda: static_url in navigations, "navigation to static test page")
304
303
 
304
+ if hidden_capture:
305
305
  wait_until(lambda: preview_has_color("#d68139"), "initial static frame")
306
306
  root.setProperty("showBrowser", False)
307
307
  wait_until(lambda: not browser.property("hostWindow").isVisible(), "hidden static page")
@@ -311,6 +311,30 @@ def run(root: QWindow) -> None:
311
311
  root.setProperty("showBrowser", True)
312
312
  wait_until(lambda: browser.property("hostWindow").isVisible(), "restored static page")
313
313
 
314
+ # A nonvisual consumer has its own lifetime and needs no projection window.
315
+ root.setProperty("showPreviews", False)
316
+ output = SideViewFrameOutput(root)
317
+ latest = QImage()
318
+
319
+ def receive(image: QImage) -> None:
320
+ nonlocal latest
321
+ latest = image
322
+
323
+ output.frameChanged.connect(receive)
324
+ output.source = browser
325
+ output.active = True
326
+ evaluate('document.body.style.background = "#2470ce"')
327
+ wait_until(lambda: matches_color(latest, "#2470ce"), "external consumer pixels")
328
+ if hidden_capture:
329
+ browser.setProperty("overlayRequested", True)
330
+ wait_until(lambda: not browser.property("nativeHostVisible"), "covered operator view")
331
+ evaluate('document.body.style.background = "#a5326e"')
332
+ wait_until(lambda: matches_color(latest, "#a5326e"), "new external pixels under overlay")
333
+ browser.setProperty("overlayRequested", False)
334
+ wait_until(lambda: browser.property("nativeHostVisible"), "restored operator view")
335
+ output.active = False
336
+ wait_until(lambda: browser.property("projectionMode") == "inactive", "external output stopped")
337
+
314
338
  # Closing immediately after request submission exercises callback invalidation.
315
339
  assert browser.runJavaScript("1 + 2")
316
340
  assert browser.captureFrame()
@@ -350,8 +374,10 @@ def validate(app: QGuiApplication, *, expect_unavailable: bool) -> int:
350
374
  if not roots:
351
375
  return 1
352
376
  root = roots[0]
377
+ verified = False
353
378
 
354
379
  def verify() -> None:
380
+ nonlocal verified
355
381
  try:
356
382
  if expect_unavailable:
357
383
  verify_unavailable(root)
@@ -361,13 +387,15 @@ def validate(app: QGuiApplication, *, expect_unavailable: bool) -> int:
361
387
  traceback.print_exc()
362
388
  app.exit(1)
363
389
  else:
390
+ verified = True
364
391
  app.quit()
365
392
 
366
393
  QTimer.singleShot(0, verify)
367
394
  try:
368
- result = app.exec()
395
+ result = app.exec() or int(not verified)
369
396
  finally:
370
- root.close()
397
+ if shiboken6.isValid(root):
398
+ root.close()
371
399
  finally:
372
400
  shiboken6.delete(engine)
373
401
  app.processEvents()
@@ -155,7 +155,10 @@ class NativeBackend:
155
155
 
156
156
  @property
157
157
  def supports_hidden_projection(self) -> bool:
158
- return self.uses_native_stream
158
+ return self.uses_native_stream or (
159
+ self._quick_supports_hidden_projection is not None
160
+ and bool(self._quick_supports_hidden_projection())
161
+ )
159
162
 
160
163
  @property
161
164
  def supports_focus_traversal(self) -> bool:
@@ -496,6 +499,9 @@ class NativeBackend:
496
499
  [pointer, integer, pointer, self._javascript_callback_type, pointer],
497
500
  integer,
498
501
  )
502
+ self._quick_supports_hidden_projection = self._optional(
503
+ "nwv_quick_supports_hidden_projection", [], integer
504
+ )
499
505
  self._quick_stop = self._optional("nwv_quick_stop", [pointer], integer)
500
506
  self._quick_set_visible = self._optional("nwv_quick_set_visible", [pointer, integer], None)
501
507
  self._quick_parent_moved = self._optional("nwv_quick_parent_moved", [pointer], None)
@@ -1,10 +1,14 @@
1
1
  from pathlib import Path
2
+ from typing import TYPE_CHECKING
2
3
 
3
4
  from PySide6 import QtCore, QtGui
4
5
  from PySide6.QtQml import qmlRegisterType
5
6
 
6
7
  from .._backend import NativeWebViewError
7
8
 
9
+ if TYPE_CHECKING:
10
+ from ._projection import SideViewFrameOutput
11
+
8
12
  _registered = False
9
13
 
10
14
 
@@ -21,14 +25,23 @@ def register_types() -> None:
21
25
 
22
26
  from ._browser import QuickBrowser
23
27
  from ._frames import FrameItem
24
- from ._projection import SideViewProjection
28
+ from ._projection import SideViewFrameOutput, SideViewProjection
25
29
 
26
30
  qmlRegisterType(QuickBrowser, "SideView.Internal", 1, 0, "BrowserItem")
27
31
  qmlRegisterType(FrameItem, "SideView.Internal", 1, 0, "FrameItem")
28
32
  component = Path(__file__).resolve().with_name("SideView.qml")
29
33
  qmlRegisterType(QtCore.QUrl.fromLocalFile(str(component)), "SideView", 1, 0, "SideView")
30
34
  qmlRegisterType(SideViewProjection, "SideView", 1, 0, "SideViewProjection")
35
+ qmlRegisterType(SideViewFrameOutput, "SideView", 1, 0, "SideViewFrameOutput")
31
36
  _registered = True
32
37
 
33
38
 
34
- __all__ = ["register_types"]
39
+ def __getattr__(name: str):
40
+ if name == "SideViewFrameOutput":
41
+ from ._projection import SideViewFrameOutput
42
+
43
+ return SideViewFrameOutput
44
+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
45
+
46
+
47
+ __all__ = ["SideViewFrameOutput", "register_types"]
@@ -9,20 +9,35 @@ from ._browser import QuickBrowser
9
9
  from ._frames import FrameItem, FrameProducer
10
10
 
11
11
 
12
- class SideViewProjection(FrameItem):
12
+ class SideViewFrameOutput(QObject):
13
+ """GUI-thread subscription to the decoded frames of a SideView."""
14
+
13
15
  sourceChanged = Signal()
16
+ activeChanged = Signal()
17
+ frameChanged = Signal(QImage, arguments=["frame"])
14
18
 
15
- def __init__(self, parent: QQuickItem | None = None) -> None:
19
+ def __init__(self, parent: QObject | None = None) -> None:
16
20
  super().__init__(parent)
21
+ self._active = False
17
22
  self._source: QuickBrowser | None = None
18
23
  self._source_producer: FrameProducer | None = None
19
24
  self._source_connections = []
20
25
  self._frame_connection = None
21
- self._projection_window: QWindow | None = None
22
- self._visibility_timer = QTimer(self, singleShot=True)
23
- self._visibility_timer.timeout.connect(self._sync_demand)
24
- self.visibleChanged.connect(self._sync_demand)
25
- self.windowChanged.connect(self._projection_window_changed)
26
+
27
+ @Property(bool, notify=activeChanged)
28
+ def active(self) -> bool:
29
+ return self._active
30
+
31
+ @active.setter
32
+ def active(self, value: bool) -> None:
33
+ if self._active == value:
34
+ return
35
+ self._active = value
36
+ if self._source is not None:
37
+ self._source._set_projection_demand(self, value)
38
+ if value:
39
+ self._receive_frame(self._source_producer.latest if self._source_producer else QImage())
40
+ self.activeChanged.emit()
26
41
 
27
42
  @Property(QQuickItem, notify=sourceChanged)
28
43
  def source(self) -> QQuickItem | None:
@@ -31,7 +46,7 @@ class SideViewProjection(FrameItem):
31
46
  @source.setter
32
47
  def source(self, source: QuickBrowser | None) -> None:
33
48
  if source is not None and not isinstance(source, QuickBrowser):
34
- raise TypeError("SideViewProjection.source must be a SideView.")
49
+ raise TypeError("source must be a SideView.")
35
50
  if source is self._source:
36
51
  return
37
52
  if self._source is not None:
@@ -45,8 +60,9 @@ class SideViewProjection(FrameItem):
45
60
  source.ready.connect(self._sync_source),
46
61
  source.destroyed.connect(self._source_destroyed),
47
62
  ]
63
+ if source is not None:
64
+ source._set_projection_demand(self, self._active)
48
65
  self._sync_source()
49
- self._sync_demand()
50
66
  self.sourceChanged.emit()
51
67
 
52
68
  @Slot()
@@ -67,7 +83,35 @@ class SideViewProjection(FrameItem):
67
83
  self._frame_connection = (
68
84
  producer.frameChanged.connect(self._receive_frame) if producer is not None else None
69
85
  )
70
- self.set_frame(producer.latest if producer is not None else QImage())
86
+ self._receive_frame(producer.latest if producer is not None else QImage())
87
+
88
+ @Slot(QImage)
89
+ def _receive_frame(self, frame: QImage) -> None:
90
+ if self._active:
91
+ self.frameChanged.emit(frame)
92
+
93
+
94
+ class SideViewProjection(FrameItem):
95
+ sourceChanged = Signal()
96
+
97
+ def __init__(self, parent: QQuickItem | None = None) -> None:
98
+ super().__init__(parent)
99
+ self._output = SideViewFrameOutput(self)
100
+ self._output.sourceChanged.connect(self.sourceChanged)
101
+ self._output.frameChanged.connect(self._receive_frame)
102
+ self._projection_window: QWindow | None = None
103
+ self._visibility_timer = QTimer(self, singleShot=True)
104
+ self._visibility_timer.timeout.connect(self._sync_demand)
105
+ self.visibleChanged.connect(self._sync_demand)
106
+ self.windowChanged.connect(self._projection_window_changed)
107
+
108
+ @Property(QQuickItem, notify=sourceChanged)
109
+ def source(self) -> QQuickItem | None:
110
+ return self._output.source
111
+
112
+ @source.setter
113
+ def source(self, source: QuickBrowser | None) -> None:
114
+ self._output.source = source
71
115
 
72
116
  @Slot(QImage)
73
117
  def _receive_frame(self, frame: QImage) -> None:
@@ -96,17 +140,15 @@ class SideViewProjection(FrameItem):
96
140
  @Slot()
97
141
  def _sync_demand(self, *_args) -> None:
98
142
  window = self._projection_window
99
- if self._source is not None:
100
- active = bool(
101
- window is not None
102
- and shiboken6.isValid(window)
103
- and window.isVisible()
104
- and window.visibility() != QWindow.Visibility.Minimized
105
- and self.isVisible()
106
- and self.width() > 0
107
- and self.height() > 0
108
- )
109
- self._source._set_projection_demand(self, active)
143
+ self._output.active = bool(
144
+ window is not None
145
+ and shiboken6.isValid(window)
146
+ and window.isVisible()
147
+ and window.visibility() != QWindow.Visibility.Minimized
148
+ and self.isVisible()
149
+ and self.width() > 0
150
+ and self.height() > 0
151
+ )
110
152
 
111
153
  def geometryChange(self, new: QRectF, old: QRectF) -> None:
112
154
  super().geometryChange(new, old)
@@ -299,6 +299,38 @@ def test_destroyed_projection_source_is_cleared(app):
299
299
  shiboken6.delete(projection)
300
300
 
301
301
 
302
+ @requires_quick_qml
303
+ def test_nonvisual_outputs_share_capture_and_release_independently(load_browser, monkeypatch):
304
+ backend = _QuickBackend()
305
+ backend.supports_hidden_projection = True
306
+ _use_backend(monkeypatch, backend)
307
+ window, browser = load_browser()
308
+ outputs = [quick.SideViewFrameOutput(window) for _ in range(2)]
309
+ received = [[], []]
310
+ for output, frames in zip(outputs, received, strict=True):
311
+ output.frameChanged.connect(lambda frame, frames=frames: frames.append(frame.cacheKey()))
312
+ output.source = browser
313
+ output.active = True
314
+ _wait_for(lambda: len(backend.snapshots) == 1)
315
+ image = _encoded_frame("JPEG")
316
+ backend.finish_capture(backend.snapshots[-1], True, image, "")
317
+ _wait_for(lambda: all(any(frames) for frames in received))
318
+ assert received[0][-1] == received[1][-1]
319
+
320
+ outputs[0].active = False
321
+ count = len(received[0])
322
+ browser.overlayRequested = True
323
+ _wait_for(lambda: browser.overlayState in {"snapshot", "placeholder"})
324
+ assert not browser.nativeHostVisible
325
+ _wait_for(lambda: len(backend.snapshots) >= 2)
326
+ second_count = len(received[1])
327
+ backend.finish_capture(backend.snapshots[-1], True, image, "")
328
+ _wait_for(lambda: len(received[1]) > second_count)
329
+ assert len(received[0]) == count
330
+ shiboken6.delete(outputs[1])
331
+ _wait_for(lambda: browser.projectionMode == "inactive")
332
+
333
+
302
334
  @requires_quick_qml
303
335
  def test_validation_closes_window_and_engine_before_profile_cleanup(app, monkeypatch):
304
336
  from scripts import validate_quick
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes