sideview 0.5.0__tar.gz → 0.6.0__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.0}/CHANGELOG.md +12 -0
  2. {sideview-0.5.0 → sideview-0.6.0}/PKG-INFO +1 -1
  3. {sideview-0.5.0 → sideview-0.6.0}/docs/quick/README.md +19 -1
  4. {sideview-0.5.0 → sideview-0.6.0}/native/linux/webview_host.cpp +22 -2
  5. {sideview-0.5.0 → sideview-0.6.0}/native/macos/webview_host.mm +90 -2
  6. {sideview-0.5.0 → sideview-0.6.0}/pyproject.toml +2 -2
  7. sideview-0.6.0/scripts/validate_covered_capture.py +318 -0
  8. {sideview-0.5.0 → sideview-0.6.0}/scripts/validate_quick.py +39 -11
  9. {sideview-0.5.0 → sideview-0.6.0}/src/sideview/_backend.py +7 -1
  10. {sideview-0.5.0 → sideview-0.6.0}/src/sideview/quick/__init__.py +15 -2
  11. {sideview-0.5.0 → sideview-0.6.0}/src/sideview/quick/_projection.py +63 -21
  12. {sideview-0.5.0 → sideview-0.6.0}/tests/test_quick_browser.py +32 -0
  13. {sideview-0.5.0 → sideview-0.6.0}/CONTRIBUTING.md +0 -0
  14. {sideview-0.5.0 → sideview-0.6.0}/LICENSE +0 -0
  15. {sideview-0.5.0 → sideview-0.6.0}/README.md +0 -0
  16. {sideview-0.5.0 → sideview-0.6.0}/SECURITY.md +0 -0
  17. {sideview-0.5.0 → sideview-0.6.0}/examples/quick/Browser.qml +0 -0
  18. {sideview-0.5.0 → sideview-0.6.0}/examples/quick/Projections.qml +0 -0
  19. {sideview-0.5.0 → sideview-0.6.0}/examples/quick/Shell.qml +0 -0
  20. {sideview-0.5.0 → sideview-0.6.0}/examples/quick/page.html +0 -0
  21. {sideview-0.5.0 → sideview-0.6.0}/examples/quick/run.py +0 -0
  22. {sideview-0.5.0 → sideview-0.6.0}/examples/simple_browser.py +0 -0
  23. {sideview-0.5.0 → sideview-0.6.0}/native/CMakeLists.txt +0 -0
  24. {sideview-0.5.0 → sideview-0.6.0}/native/native_webview.h +0 -0
  25. {sideview-0.5.0 → sideview-0.6.0}/native/win32/webview_host.cpp +0 -0
  26. {sideview-0.5.0 → sideview-0.6.0}/release-please-config.json +0 -0
  27. {sideview-0.5.0 → sideview-0.6.0}/scripts/benchmark_frame_stream.py +0 -0
  28. {sideview-0.5.0 → sideview-0.6.0}/scripts/benchmark_quick.py +0 -0
  29. {sideview-0.5.0 → sideview-0.6.0}/scripts/benchmark_workload.py +0 -0
  30. {sideview-0.5.0 → sideview-0.6.0}/scripts/build_linux.sh +0 -0
  31. {sideview-0.5.0 → sideview-0.6.0}/scripts/build_windows.ps1 +0 -0
  32. {sideview-0.5.0 → sideview-0.6.0}/scripts/validate_distribution.py +0 -0
  33. {sideview-0.5.0 → sideview-0.6.0}/scripts/validate_pull_request_title.py +0 -0
  34. {sideview-0.5.0 → sideview-0.6.0}/scripts/validate_windows_native_bounds.py +0 -0
  35. {sideview-0.5.0 → sideview-0.6.0}/src/sideview/__init__.py +0 -0
  36. {sideview-0.5.0 → sideview-0.6.0}/src/sideview/_controller.py +0 -0
  37. {sideview-0.5.0 → sideview-0.6.0}/src/sideview/py.typed +0 -0
  38. {sideview-0.5.0 → sideview-0.6.0}/src/sideview/quick/SideView.qml +0 -0
  39. {sideview-0.5.0 → sideview-0.6.0}/src/sideview/quick/_browser.py +0 -0
  40. {sideview-0.5.0 → sideview-0.6.0}/src/sideview/quick/_frames.py +0 -0
  41. {sideview-0.5.0 → sideview-0.6.0}/src/sideview/widget.py +0 -0
  42. {sideview-0.5.0 → sideview-0.6.0}/tests/conftest.py +0 -0
  43. {sideview-0.5.0 → sideview-0.6.0}/tests/test_browser_controller.py +0 -0
  44. {sideview-0.5.0 → sideview-0.6.0}/tests/test_imports.py +0 -0
  45. {sideview-0.5.0 → sideview-0.6.0}/tests/test_native_bounds.py +0 -0
  46. {sideview-0.5.0 → sideview-0.6.0}/tests/test_quick_frames.py +0 -0
  47. {sideview-0.5.0 → sideview-0.6.0}/tests/test_release_tooling.py +0 -0
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.6.0](https://github.com/AlexsanderMe/SideView/compare/v0.5.0...v0.6.0) (2026-12-01)
4
+
5
+
6
+ ### Features
7
+
8
+ * **quick:** expose live browser frames to nonvisual consumers ([#18](https://github.com/AlexsanderMe/SideView/issues/18)) ([a9acb20](https://github.com/AlexsanderMe/SideView/commit/a9acb209ca20586709133b958188284bb77d721d))
9
+
10
+
11
+ ### Build System
12
+
13
+ * **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))
14
+
3
15
  ## [0.5.0](https://github.com/AlexsanderMe/SideView/compare/v0.4.1...v0.5.0) (2026-11-30)
4
16
 
5
17
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sideview
3
- Version: 0.5.0
3
+ Version: 0.6.0
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,7 +133,25 @@ 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
156
  item is hidden. This is supported with WebView2 on Windows. The source
139
157
  window must stay visible and the source item must remain instantiated.
@@ -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,10 +1,13 @@
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>
7
8
  #include <cmath>
9
+ #include <cstdlib>
10
+ #include <cstring>
8
11
  #include <memory>
9
12
 
10
13
  @interface NWVNavigationDelegate : NSObject <WKNavigationDelegate>
@@ -23,10 +26,32 @@
23
26
  @property(nonatomic, assign) void *host;
24
27
  @end
25
28
 
29
+ @interface NWVCaptureParkingView : NSView
30
+ @end
31
+
32
+ @implementation NWVCaptureParkingView
33
+
34
+ - (NSView *)hitTest:(NSPoint)point {
35
+ (void)point;
36
+ return nil;
37
+ }
38
+
39
+ - (BOOL)isAccessibilityHidden {
40
+ return YES;
41
+ }
42
+
43
+ - (NSArray *)accessibilityChildren {
44
+ return @[];
45
+ }
46
+
47
+ @end
48
+
26
49
  namespace {
27
50
 
28
51
  struct Host : std::enable_shared_from_this<Host> {
52
+ __weak NSView *presentationParent = nil;
29
53
  NSView *container = nil;
54
+ NWVCaptureParkingView *captureParkingView = nil;
30
55
  NWVWebView *webview = nil;
31
56
  WKWebsiteDataStore *dataStore = nil;
32
57
  WKUserContentController *userContentController = nil;
@@ -123,6 +148,56 @@ void resize_host(Host *host, int width, int height) {
123
148
  [host->webview setFrame:frame];
124
149
  }
125
150
 
151
+ bool supports_hidden_projection() {
152
+ // Enable the candidate only in native qualification until the Cocoa run passes.
153
+ return [] {
154
+ const auto *value = std::getenv("SIDEVIEW_EXPERIMENTAL_COCOA_HIDDEN_CAPTURE");
155
+ return value && std::strcmp(value, "1") == 0;
156
+ }();
157
+ }
158
+
159
+ void set_quick_rendering(Host *host, bool render) {
160
+ NSView *parent = host->presentationParent;
161
+ if (!render || !parent) {
162
+ host->container.hidden = YES;
163
+ [host->captureParkingView removeFromSuperview];
164
+ return;
165
+ }
166
+
167
+ if (![parent isHiddenOrHasHiddenAncestor]) {
168
+ if (host->container.superview != parent) {
169
+ [parent addSubview:host->container];
170
+ host->container.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
171
+ host->container.frame = parent.bounds;
172
+ [host->captureParkingView removeFromSuperview];
173
+ }
174
+ host->container.hidden = NO;
175
+ return;
176
+ }
177
+
178
+ NSView *contentView = parent.window.contentView;
179
+ if (!contentView) {
180
+ host->container.hidden = YES;
181
+ return;
182
+ }
183
+
184
+ // Keep the WKWebView in the same NSWindow, outside Qt's hidden NSView.
185
+ // The parent clips the full viewport and has no mouse or accessibility target.
186
+ if (!host->captureParkingView) {
187
+ host->captureParkingView = [[NWVCaptureParkingView alloc] initWithFrame:NSZeroRect];
188
+ host->captureParkingView.wantsLayer = YES;
189
+ host->captureParkingView.layer.masksToBounds = YES;
190
+ }
191
+ if (host->captureParkingView.superview != contentView) {
192
+ [contentView addSubview:host->captureParkingView positioned:NSWindowBelow relativeTo:nil];
193
+ }
194
+ if (host->container.superview != host->captureParkingView) {
195
+ host->container.autoresizingMask = NSViewNotSizable;
196
+ [host->captureParkingView addSubview:host->container];
197
+ }
198
+ host->container.hidden = NO;
199
+ }
200
+
126
201
  void run_on_main_sync(dispatch_block_t block) {
127
202
  if ([NSThread isMainThread]) {
128
203
  block();
@@ -392,6 +467,7 @@ NWV_EXPORT void *nwv_create(void *parent_view, const nwv_options *options) {
392
467
 
393
468
  run_on_main_sync(^{
394
469
  NSView *parent = (__bridge NSView *)parent_view;
470
+ host->presentationParent = parent;
395
471
 
396
472
  NSRect frame = parent.bounds;
397
473
  host->container = [[NSView alloc] initWithFrame:frame];
@@ -477,6 +553,8 @@ NWV_EXPORT void nwv_destroy(void *handle) {
477
553
  [host->userContentController removeScriptMessageHandlerForName:@"nativeWebView"];
478
554
  [host->webview removeFromSuperview];
479
555
  [host->container removeFromSuperview];
556
+ [host->captureParkingView removeFromSuperview];
557
+ host->captureParkingView = nil;
480
558
  host->webview = nil;
481
559
  host->dataStore = nil;
482
560
  host->userContentController = nil;
@@ -666,11 +744,19 @@ NWV_EXPORT int nwv_quick_stop(void *handle) {
666
744
  return 1;
667
745
  }
668
746
 
747
+ NWV_EXPORT int nwv_quick_supports_hidden_projection() {
748
+ return supports_hidden_projection();
749
+ }
750
+
669
751
  NWV_EXPORT void nwv_quick_set_visible(void *handle, int visible) {
670
752
  auto host = get_host(handle);
671
753
  if (host && !host->destroyed) {
672
754
  run_on_main_sync(^{
673
- host->container.hidden = visible == 0;
755
+ if (supports_hidden_projection()) {
756
+ set_quick_rendering(host.get(), visible != 0);
757
+ } else {
758
+ host->container.hidden = visible == 0;
759
+ }
674
760
  });
675
761
  }
676
762
  }
@@ -686,7 +772,9 @@ NWV_EXPORT int nwv_quick_focus(void *handle, int reason) {
686
772
  }
687
773
  __block BOOL accepted = NO;
688
774
  run_on_main_sync(^{
689
- if (![host->webview isHiddenOrHasHiddenAncestor]) {
775
+ NSView *parent = host->presentationParent;
776
+ if (parent && host->container.superview == parent
777
+ && ![host->webview isHiddenOrHasHiddenAncestor]) {
690
778
  accepted = [host->webview.window makeFirstResponder:host->webview];
691
779
  }
692
780
  });
@@ -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.0"
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,318 @@
1
+ """Check fresh WebKit frames while the native Quick browser is covered."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ import os
7
+ import sys
8
+ import traceback
9
+ from argparse import ArgumentParser
10
+ from functools import partial
11
+ from http.server import ThreadingHTTPServer
12
+ from pathlib import Path
13
+ from tempfile import TemporaryDirectory
14
+ from threading import Thread
15
+
16
+ import shiboken6
17
+ from PySide6.QtCore import QByteArray, QObject, QPoint, QTimer, QUrl
18
+ from PySide6.QtGui import QColor, QGuiApplication, QImage, QWindow
19
+ from PySide6.QtQml import QQmlApplicationEngine
20
+ from validate_quick import _QuietHandler, wait_until
21
+
22
+ from sideview.quick import SideViewFrameOutput, register_types
23
+
24
+ QML = b"""
25
+ import QtQuick
26
+ import SideView
27
+
28
+ Window {
29
+ id: root
30
+ visible: true
31
+ width: 480
32
+ height: 320
33
+ required property url home
34
+ required property string profileRoot
35
+ SideView {
36
+ id: browser
37
+ objectName: "browser"
38
+ anchors.fill: parent
39
+ url: root.home
40
+ sessionId: "covered-capture"
41
+ sessionDataRoot: root.profileRoot
42
+ projectionMaxFps: 15
43
+ }
44
+ Rectangle {
45
+ objectName: "operatorOverlay"
46
+ anchors.fill: parent
47
+ visible: browser.overlayState === "snapshot" || browser.overlayState === "placeholder"
48
+ color: "#e6b831"
49
+ }
50
+ }
51
+ """
52
+
53
+ PAGE = """<!doctype html><meta charset="utf-8"><title>Covered capture</title>
54
+ <style>html, body { margin: 0; height: 100%; background: #d94838 }</style>
55
+ <script>
56
+ window.repaints = 0;
57
+ window.repaint = (color) => requestAnimationFrame(() => {
58
+ document.body.style.backgroundColor = color;
59
+ window.repaints++;
60
+ });
61
+ </script>
62
+ """
63
+
64
+
65
+ def matches(image: QImage, x: int, y: int, color: str) -> bool:
66
+ if image.isNull():
67
+ return False
68
+ return all(
69
+ abs(actual - expected) <= 10
70
+ for actual, expected in zip(
71
+ image.pixelColor(x, y).getRgb(), QColor(color).getRgb(), strict=True
72
+ )
73
+ )
74
+
75
+
76
+ def verify(root: QWindow, *, expect_unsupported: bool, check_screen: bool) -> None:
77
+ browser = root.findChild(QObject, "browser")
78
+ overlay = root.findChild(QObject, "operatorOverlay")
79
+
80
+ def ready() -> bool:
81
+ assert browser.property("initializationState") != "error", browser.property("errorString")
82
+ return browser.property("title") == "Covered capture"
83
+
84
+ wait_until(ready, "initial document", timeout=35)
85
+ host = browser.property("hostWindow")
86
+ assert host is not None, "no native child after the document loaded"
87
+ host_id = host.winId()
88
+ output = SideViewFrameOutput(root)
89
+ frames = 0
90
+ latest = QImage()
91
+ scripts = {}
92
+ failures = []
93
+
94
+ def receive(image: QImage) -> None:
95
+ nonlocal frames, latest
96
+ if not image.isNull():
97
+ frames += 1
98
+ latest = image
99
+
100
+ output.frameChanged.connect(receive)
101
+ browser.javaScriptFinished.connect(
102
+ lambda id_, result, error: scripts.update({id_: (result, error)})
103
+ )
104
+ browser.projectionFailed.connect(failures.append)
105
+
106
+ def evaluate(script: str):
107
+ request = browser.runJavaScript(script)
108
+ assert request, browser.property("errorString")
109
+ wait_until(lambda: request in scripts, "JavaScript response")
110
+ result, error = scripts.pop(request)
111
+ assert not error, error
112
+ return result
113
+
114
+ def frame_is(color: str) -> bool:
115
+ return matches(latest, latest.width() // 2, latest.height() // 2, color)
116
+
117
+ def screen_is(color: str) -> bool:
118
+ if not check_screen:
119
+ return True
120
+ screen = root.screen()
121
+ center = root.mapToGlobal(QPoint(root.width() // 2, root.height() // 2))
122
+ offset = center - screen.geometry().topLeft()
123
+ image = screen.grabWindow(0, offset.x(), offset.y(), 1, 1).toImage()
124
+ return matches(image, 0, 0, color)
125
+
126
+ def same_host() -> bool:
127
+ return (
128
+ shiboken6.isValid(host)
129
+ and browser.property("hostWindow") is host
130
+ and host.winId() == host_id
131
+ )
132
+
133
+ def covered() -> bool:
134
+ return (
135
+ root.isVisible()
136
+ and same_host()
137
+ and browser.property("overlayState") in {"snapshot", "placeholder"}
138
+ and overlay.property("visible")
139
+ and not browser.property("nativeHostVisible")
140
+ and not host.isVisible()
141
+ )
142
+
143
+ def restored() -> bool:
144
+ return (
145
+ root.isVisible()
146
+ and same_host()
147
+ and browser.property("overlayState") == "native"
148
+ and not overlay.property("visible")
149
+ and browser.property("nativeHostVisible")
150
+ and host.isVisible()
151
+ )
152
+
153
+ transitions = []
154
+
155
+ def record_state() -> None:
156
+ state = (
157
+ browser.property("overlayState"),
158
+ browser.property("nativeHostVisible"),
159
+ host.isVisible() if shiboken6.isValid(host) else None,
160
+ )
161
+ if not transitions or state != transitions[-1]:
162
+ transitions.append(state)
163
+
164
+ browser.overlayStateChanged.connect(record_state)
165
+ browser.nativeHostVisibleChanged.connect(record_state)
166
+ host.visibleChanged.connect(record_state)
167
+
168
+ def wait_for_state(predicate, description: str) -> None:
169
+ try:
170
+ wait_until(predicate, description)
171
+ except AssertionError as error:
172
+ raise AssertionError(
173
+ f"{error}. (overlayState, nativeHostVisible, child visible)={transitions!r}, "
174
+ f"overlay visible={overlay.property('visible')}, same host={same_host()}, "
175
+ f"root visible={root.isVisible()}, mode={browser.property('projectionMode')}, "
176
+ f"projection errors={failures!r}"
177
+ ) from error
178
+
179
+ def repaint(color: str, repaint_count: int, *, under_cover: bool = False) -> None:
180
+ before = frames
181
+ presentation = covered if under_cover else restored
182
+ description = f"new {color} frame under cover" if under_cover else f"new {color} frame"
183
+
184
+ def new_frame() -> bool:
185
+ assert presentation(), "host changed presentation while waiting for new pixels"
186
+ return frames > before and frame_is(color)
187
+
188
+ assert presentation()
189
+ evaluate(f"window.repaint({json.dumps(color)}); true")
190
+ try:
191
+ wait_for_state(new_frame, description)
192
+ except AssertionError as error:
193
+ visibility, count = evaluate("[document.visibilityState, window.repaints]")
194
+ raise AssertionError(
195
+ f"{error}. Page visibility={visibility}, rAF repaints={count}, "
196
+ f"frames={frames - before}, projection errors={failures!r}"
197
+ ) from error
198
+ assert evaluate("window.repaints") == repaint_count
199
+
200
+ output.source = browser
201
+ output.active = True
202
+ wait_until(lambda: frame_is("#d94838"), "original output pixels")
203
+ wait_until(lambda: screen_is("#d94838"), "original screen pixels")
204
+ supported = browser.property("capabilities")["hiddenCapture"]
205
+ expected = not expect_unsupported
206
+ assert supported == expected, (
207
+ f"{QGuiApplication.platformName()} advertised hiddenCapture={supported}; "
208
+ f"expected {expected}"
209
+ )
210
+
211
+ wait_for_state(restored, "initial native presentation")
212
+ counts = 0
213
+ for iteration in range(2):
214
+ transitions.clear()
215
+ record_state()
216
+ browser.setProperty("overlayRequested", True)
217
+ wait_for_state(covered, "covered overlay and hidden native child")
218
+ print(f"Overlay cycle {iteration + 1} covered via {browser.property('overlayState')}.")
219
+ wait_until(lambda: screen_is("#e6b831"), "operator overlay pixels")
220
+ if supported:
221
+ for color in ("#295cc5", "#45a857", "#b73583"):
222
+ counts += 1
223
+ repaint(color, counts, under_cover=True)
224
+ assert covered()
225
+ assert screen_is("#e6b831"), "native browser leaked through the overlay"
226
+ output.active = False
227
+ wait_until(
228
+ lambda: browser.property("projectionMode") == "inactive",
229
+ "last output disconnected under cover",
230
+ )
231
+ assert covered()
232
+ output.active = True
233
+ counts += 1
234
+ repaint("#245a56", counts, under_cover=True)
235
+ assert covered()
236
+ else:
237
+ assert browser.property("projectionMode") == "inactive"
238
+
239
+ browser.setProperty("overlayRequested", False)
240
+ wait_for_state(restored, "restored native presentation on the same host")
241
+ color = "#ce642a" if iteration == 0 else "#97369d"
242
+ counts += 1
243
+ repaint(color, counts)
244
+ wait_until(partial(screen_is, color), "restored page pixels")
245
+
246
+ output.active = False
247
+ wait_until(lambda: browser.property("projectionMode") == "inactive", "output stopped")
248
+
249
+
250
+ def main() -> int:
251
+ app = QGuiApplication(sys.argv)
252
+ parser = ArgumentParser(description=__doc__)
253
+ parser.add_argument("--expect-unsupported", action="store_true")
254
+ parser.add_argument(
255
+ "--check-screen",
256
+ action="store_true",
257
+ help="also sample the real screen, which must show the test window unobstructed",
258
+ )
259
+ args = parser.parse_args(app.arguments()[1:])
260
+ if app.platformName() == "cocoa":
261
+ # Exercise the Cocoa candidate in this process while the production
262
+ # capability remains gated on native qualification.
263
+ os.environ["SIDEVIEW_EXPERIMENTAL_COCOA_HIDDEN_CAPTURE"] = (
264
+ "0" if args.expect_unsupported else "1"
265
+ )
266
+ app.setQuitOnLastWindowClosed(False)
267
+ register_types()
268
+ with TemporaryDirectory(prefix="sideview-covered-", ignore_cleanup_errors=True) as directory:
269
+ folder = Path(directory)
270
+ (folder / "index.html").write_text(PAGE, encoding="utf-8")
271
+ handler = partial(_QuietHandler, directory=str(folder))
272
+ with ThreadingHTTPServer(("127.0.0.1", 0), handler) as server:
273
+ thread = Thread(target=server.serve_forever, daemon=True)
274
+ thread.start()
275
+ engine = QQmlApplicationEngine()
276
+ try:
277
+ engine.setInitialProperties(
278
+ {
279
+ "home": QUrl(f"http://127.0.0.1:{server.server_port}/index.html"),
280
+ "profileRoot": str(folder / "profile"),
281
+ }
282
+ )
283
+ engine.loadData(QByteArray(QML), QUrl.fromLocalFile(str(folder / "Capture.qml")))
284
+ if not engine.rootObjects():
285
+ return 1
286
+ root = engine.rootObjects()[0]
287
+
288
+ def run() -> None:
289
+ try:
290
+ verify(
291
+ root,
292
+ expect_unsupported=args.expect_unsupported,
293
+ check_screen=args.check_screen,
294
+ )
295
+ except Exception:
296
+ traceback.print_exc()
297
+ app.exit(1)
298
+ else:
299
+ app.quit()
300
+
301
+ QTimer.singleShot(0, run)
302
+ result = app.exec()
303
+ if shiboken6.isValid(root):
304
+ root.close()
305
+ finally:
306
+ shiboken6.delete(engine)
307
+ app.processEvents()
308
+ server.shutdown()
309
+ thread.join()
310
+ if result == 0:
311
+ print(
312
+ f"SideView covered frame validation passed ({app.platformName()}, {app.applicationVersion() or 'local build'})"
313
+ )
314
+ return result
315
+
316
+
317
+ if __name__ == "__main__":
318
+ 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