fix(cef): retry viewport sync after resize
- commit
- fdc933da07c1d35d06850c51e488bb2189711e73
- author
- brice · · 2026-06-20 14:16 UTC
- parent
- 09bc82a
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
2 files · +24 -4
M internal/infrastructure/cef/webview_viewport.go +14 -3
| @@ -94,7 +94,11 @@ func (wv *WebView) syncViewportOnGTK(ctx context.Context) { | |||
| 94 | 94 | if wv == nil { | |
| 95 | 95 | return | |
| 96 | 96 | } | |
| 97 | - | wv.syncViewportNowOnGTK(ctx, wv.takeViewportSyncReason()) | |
| 97 | + | reason := wv.takeViewportSyncReason() | |
| 98 | + | ctx = wv.viewportSyncContext(ctx) | |
| 99 | + | if wv.syncViewportNowOnGTK(ctx, reason) { | |
| 100 | + | wv.scheduleResizeRepaintPulse(ctx, reason) | |
| 101 | + | } | |
| 98 | 102 | } | |
| 99 | 103 | ||
| 100 | 104 | func (wv *WebView) syncViewportNowOnGTK(ctx context.Context, reason string) bool { | |
| @@ -148,6 +152,12 @@ func (wv *WebView) scheduleResizeRepaintPulse(ctx context.Context, reason string | |||
| 148 | 152 | if wv == nil || wv.destroyed.Load() { | |
| 149 | 153 | return | |
| 150 | 154 | } | |
| 155 | + | visible := true | |
| 156 | + | if wv.viewBridge != nil { | |
| 157 | + | if widget := wv.viewBridge.Widget(); widget != nil { | |
| 158 | + | visible = widget.IsVisible() | |
| 159 | + | } | |
| 160 | + | } | |
| 151 | 161 | seq := wv.viewportResizePulseSeq.Add(1) | |
| 152 | 162 | for _, delayMs := range [...]int64{16, 48} { | |
| 153 | 163 | task := cefNewTask(cefTaskFunc(func() { | |
| @@ -160,12 +170,13 @@ func (wv *WebView) scheduleResizeRepaintPulse(ctx context.Context, reason string | |||
| 160 | 170 | if host == nil { | |
| 161 | 171 | return | |
| 162 | 172 | } | |
| 163 | - | host.Invalidate(purecef.PaintElementTypePetView) | |
| 173 | + | notifyBrowserViewportSync(host, visible) | |
| 164 | 174 | logging.FromContext(ctx).Debug(). | |
| 165 | 175 | Uint64("webview_id", uint64(wv.id)). | |
| 166 | 176 | Int64("delay_ms", delayMs). | |
| 177 | + | Bool("visible", visible). | |
| 167 | 178 | Str("reason", reason). | |
| 168 | - | Msg("cef: delayed resize repaint pulse") | |
| 179 | + | Msg("cef: delayed resize viewport sync") | |
| 169 | 180 | })) | |
| 170 | 181 | if task == nil { | |
| 171 | 182 | continue | |
| @@ -94,7 +94,11 @@ func (wv *WebView) syncViewportOnGTK(ctx context.Context) { | |||||
| 94 | if wv == nil { | 94 | if wv == nil { | ||
| 95 | return | 95 | return | ||
| 96 | } | 96 | } | ||
| 97 | - | wv.syncViewportNowOnGTK(ctx, wv.takeViewportSyncReason()) | 97 | + | reason := wv.takeViewportSyncReason() |
| 98 | + | ctx = wv.viewportSyncContext(ctx) | |||
| 99 | + | if wv.syncViewportNowOnGTK(ctx, reason) { | |||
| 100 | + | wv.scheduleResizeRepaintPulse(ctx, reason) | |||
| 101 | + | } | |||
| 98 | } | 102 | } | ||
| 99 | 103 | ||||
| 100 | func (wv *WebView) syncViewportNowOnGTK(ctx context.Context, reason string) bool { | 104 | func (wv *WebView) syncViewportNowOnGTK(ctx context.Context, reason string) bool { | ||
| @@ -148,6 +152,12 @@ func (wv *WebView) scheduleResizeRepaintPulse(ctx context.Context, reason string | |||||
| 148 | if wv == nil || wv.destroyed.Load() { | 152 | if wv == nil || wv.destroyed.Load() { | ||
| 149 | return | 153 | return | ||
| 150 | } | 154 | } | ||
| 155 | + | visible := true | |||
| 156 | + | if wv.viewBridge != nil { | |||
| 157 | + | if widget := wv.viewBridge.Widget(); widget != nil { | |||
| 158 | + | visible = widget.IsVisible() | |||
| 159 | + | } | |||
| 160 | + | } | |||
| 151 | seq := wv.viewportResizePulseSeq.Add(1) | 161 | seq := wv.viewportResizePulseSeq.Add(1) | ||
| 152 | for _, delayMs := range [...]int64{16, 48} { | 162 | for _, delayMs := range [...]int64{16, 48} { | ||
| 153 | task := cefNewTask(cefTaskFunc(func() { | 163 | task := cefNewTask(cefTaskFunc(func() { | ||
| @@ -160,12 +170,13 @@ func (wv *WebView) scheduleResizeRepaintPulse(ctx context.Context, reason string | |||||
| 160 | if host == nil { | 170 | if host == nil { | ||
| 161 | return | 171 | return | ||
| 162 | } | 172 | } | ||
| 163 | - | host.Invalidate(purecef.PaintElementTypePetView) | 173 | + | notifyBrowserViewportSync(host, visible) |
| 164 | logging.FromContext(ctx).Debug(). | 174 | logging.FromContext(ctx).Debug(). | ||
| 165 | Uint64("webview_id", uint64(wv.id)). | 175 | Uint64("webview_id", uint64(wv.id)). | ||
| 166 | Int64("delay_ms", delayMs). | 176 | Int64("delay_ms", delayMs). | ||
| 177 | + | Bool("visible", visible). | |||
| 167 | Str("reason", reason). | 178 | Str("reason", reason). | ||
| 168 | - | Msg("cef: delayed resize repaint pulse") | 179 | + | Msg("cef: delayed resize viewport sync") |
| 169 | })) | 180 | })) | ||
| 170 | if task == nil { | 181 | if task == nil { | ||
| 171 | continue | 182 | continue | ||
M internal/infrastructure/cef/webview_viewport_test.go +10 -1
| @@ -450,5 +450,14 @@ func TestScheduleResizeRepaintPulse_CoalescesToLatestSequence(t *testing.T) { | |||
| 450 | 450 | ||
| 451 | 451 | scheduled[2].Execute() | |
| 452 | 452 | scheduled[3].Execute() | |
| 453 | - | require.Equal(t, []string{"Invalidate", "Invalidate"}, host.calls) | |
| 453 | + | require.Equal(t, []string{ | |
| 454 | + | "WasHidden", | |
| 455 | + | "NotifyScreenInfoChanged", | |
| 456 | + | "WasResized", | |
| 457 | + | "Invalidate", | |
| 458 | + | "WasHidden", | |
| 459 | + | "NotifyScreenInfoChanged", | |
| 460 | + | "WasResized", | |
| 461 | + | "Invalidate", | |
| 462 | + | }, host.calls) | |
| 454 | 463 | } | |
| @@ -450,5 +450,14 @@ func TestScheduleResizeRepaintPulse_CoalescesToLatestSequence(t *testing.T) { | |||||
| 450 | 450 | ||||
| 451 | scheduled[2].Execute() | 451 | scheduled[2].Execute() | ||
| 452 | scheduled[3].Execute() | 452 | scheduled[3].Execute() | ||
| 453 | - | require.Equal(t, []string{"Invalidate", "Invalidate"}, host.calls) | 453 | + | require.Equal(t, []string{ |
| 454 | + | "WasHidden", | |||
| 455 | + | "NotifyScreenInfoChanged", | |||
| 456 | + | "WasResized", | |||
| 457 | + | "Invalidate", | |||
| 458 | + | "WasHidden", | |||
| 459 | + | "NotifyScreenInfoChanged", | |||
| 460 | + | "WasResized", | |||
| 461 | + | "Invalidate", | |||
| 462 | + | }, host.calls) | |||
| 454 | } | 463 | } | ||