refactor(webkit): improve WebKit integration for gesture handling and initialization
Enhance touchpad gesture detection and WebView initialization patterns to better support content filtering at startup.
- commit
- 377b106162e402488d190c68606830227b3f6ed9
- author
- bnema · · 2025-12-06 20:52 UTC
- parent
- b6ebf7a
- signature
- unsigned
2 files · +33 -2
M pkg/webkit/touchpad_gestures.go +3 -2
| @@ -25,8 +25,9 @@ func (w *WebView) AttachTouchpadGestures() { | |||
| 25 | 25 | // Create gesture controller for swipe detection | |
| 26 | 26 | gestureSwipe := gtk.NewGestureSwipe() | |
| 27 | 27 | ||
| 28 | - | // Set to capture phase to intercept before WebView processes | |
| 29 | - | gestureSwipe.SetPropagationPhase(gtk.PhaseCapture) | |
| 28 | + | // Use bubble phase instead of capture to not interfere with scroll events | |
| 29 | + | // This lets normal scrolling work while still detecting navigation swipes | |
| 30 | + | gestureSwipe.SetPropagationPhase(gtk.PhaseBubble) | |
| 30 | 31 | ||
| 31 | 32 | // Set to require touchpad (2 fingers minimum for touchpad gestures) | |
| 32 | 33 | // This prevents single-finger drags from triggering navigation | |
| @@ -25,8 +25,9 @@ func (w *WebView) AttachTouchpadGestures() { | |||||
| 25 | // Create gesture controller for swipe detection | 25 | // Create gesture controller for swipe detection | ||
| 26 | gestureSwipe := gtk.NewGestureSwipe() | 26 | gestureSwipe := gtk.NewGestureSwipe() | ||
| 27 | 27 | ||||
| 28 | - | // Set to capture phase to intercept before WebView processes | 28 | + | // Use bubble phase instead of capture to not interfere with scroll events |
| 29 | - | gestureSwipe.SetPropagationPhase(gtk.PhaseCapture) | 29 | + | // This lets normal scrolling work while still detecting navigation swipes |
| 30 | + | gestureSwipe.SetPropagationPhase(gtk.PhaseBubble) | |||
| 30 | 31 | ||||
| 31 | // Set to require touchpad (2 fingers minimum for touchpad gestures) | 32 | // Set to require touchpad (2 fingers minimum for touchpad gestures) | ||
| 32 | // This prevents single-finger drags from triggering navigation | 33 | // This prevents single-finger drags from triggering navigation | ||
M pkg/webkit/webview.go +30 -0
| @@ -203,6 +203,20 @@ func (w *WebView) applyConfig() error { | |||
| 203 | 203 | // Enable hardware acceleration if configured | |
| 204 | 204 | settings.SetHardwareAccelerationPolicy(webkit.HardwareAccelerationPolicyAlways) | |
| 205 | 205 | ||
| 206 | + | // Media performance optimizations | |
| 207 | + | // Force hardware decoding for video content types via GStreamer VA-API/NVDEC | |
| 208 | + | settings.SetMediaContentTypesRequiringHardwareSupport("video/mp4;video/webm;video/x-h264;video/av01") | |
| 209 | + | // Enable media capabilities API for efficient codec queries | |
| 210 | + | settings.SetEnableMediaCapabilities(true) | |
| 211 | + | // Enable MediaSource Extensions for adaptive streaming (YouTube, Twitch) | |
| 212 | + | settings.SetEnableMediasource(true) | |
| 213 | + | // GPU-accelerated 2D canvas for image-heavy pages | |
| 214 | + | settings.SetEnable2DCanvasAcceleration(true) | |
| 215 | + | // Allow inline video playback (no forced fullscreen) | |
| 216 | + | settings.SetMediaPlaybackAllowsInline(true) | |
| 217 | + | // Require user gesture for autoplay (browser standard) | |
| 218 | + | settings.SetMediaPlaybackRequiresUserGesture(true) | |
| 219 | + | ||
| 206 | 220 | // Performance optimizations for faster page transitions | |
| 207 | 221 | // Enable page cache for instant back/forward navigation (bfcache) | |
| 208 | 222 | settings.SetEnablePageCache(w.config.EnablePageCache) | |
| @@ -210,6 +224,22 @@ func (w *WebView) applyConfig() error { | |||
| 210 | 224 | // Enable smooth scrolling for better UX | |
| 211 | 225 | settings.SetEnableSmoothScrolling(w.config.EnableSmoothScrolling) | |
| 212 | 226 | ||
| 227 | + | // Enable fullscreen API (required for video fullscreen) | |
| 228 | + | settings.SetEnableFullscreen(true) | |
| 229 | + | ||
| 230 | + | // Web app storage APIs | |
| 231 | + | settings.SetEnableHtml5LocalStorage(true) // localStorage/sessionStorage | |
| 232 | + | settings.SetEnableHtml5Database(true) // IndexedDB | |
| 233 | + | ||
| 234 | + | // Web Audio API for games and audio apps | |
| 235 | + | settings.SetEnableWebaudio(true) | |
| 236 | + | ||
| 237 | + | // Touchpad swipe gestures for back/forward navigation | |
| 238 | + | settings.SetEnableBackForwardNavigationGestures(true) | |
| 239 | + | ||
| 240 | + | // WebKit compatibility hacks for popular broken sites | |
| 241 | + | settings.SetEnableSiteSpecificQuirks(true) | |
| 242 | + | ||
| 213 | 243 | // Disable console messages to stdout to prevent page script flooding | |
| 214 | 244 | // This stops malicious/buggy pages from spamming the terminal with console.log() | |
| 215 | 245 | // Inspector/DevTools console (F12) will still show all messages | |
| @@ -203,6 +203,20 @@ func (w *WebView) applyConfig() error { | |||||
| 203 | // Enable hardware acceleration if configured | 203 | // Enable hardware acceleration if configured | ||
| 204 | settings.SetHardwareAccelerationPolicy(webkit.HardwareAccelerationPolicyAlways) | 204 | settings.SetHardwareAccelerationPolicy(webkit.HardwareAccelerationPolicyAlways) | ||
| 205 | 205 | ||||
| 206 | + | // Media performance optimizations | |||
| 207 | + | // Force hardware decoding for video content types via GStreamer VA-API/NVDEC | |||
| 208 | + | settings.SetMediaContentTypesRequiringHardwareSupport("video/mp4;video/webm;video/x-h264;video/av01") | |||
| 209 | + | // Enable media capabilities API for efficient codec queries | |||
| 210 | + | settings.SetEnableMediaCapabilities(true) | |||
| 211 | + | // Enable MediaSource Extensions for adaptive streaming (YouTube, Twitch) | |||
| 212 | + | settings.SetEnableMediasource(true) | |||
| 213 | + | // GPU-accelerated 2D canvas for image-heavy pages | |||
| 214 | + | settings.SetEnable2DCanvasAcceleration(true) | |||
| 215 | + | // Allow inline video playback (no forced fullscreen) | |||
| 216 | + | settings.SetMediaPlaybackAllowsInline(true) | |||
| 217 | + | // Require user gesture for autoplay (browser standard) | |||
| 218 | + | settings.SetMediaPlaybackRequiresUserGesture(true) | |||
| 219 | + | ||||
| 206 | // Performance optimizations for faster page transitions | 220 | // Performance optimizations for faster page transitions | ||
| 207 | // Enable page cache for instant back/forward navigation (bfcache) | 221 | // Enable page cache for instant back/forward navigation (bfcache) | ||
| 208 | settings.SetEnablePageCache(w.config.EnablePageCache) | 222 | settings.SetEnablePageCache(w.config.EnablePageCache) | ||
| @@ -210,6 +224,22 @@ func (w *WebView) applyConfig() error { | |||||
| 210 | // Enable smooth scrolling for better UX | 224 | // Enable smooth scrolling for better UX | ||
| 211 | settings.SetEnableSmoothScrolling(w.config.EnableSmoothScrolling) | 225 | settings.SetEnableSmoothScrolling(w.config.EnableSmoothScrolling) | ||
| 212 | 226 | ||||
| 227 | + | // Enable fullscreen API (required for video fullscreen) | |||
| 228 | + | settings.SetEnableFullscreen(true) | |||
| 229 | + | ||||
| 230 | + | // Web app storage APIs | |||
| 231 | + | settings.SetEnableHtml5LocalStorage(true) // localStorage/sessionStorage | |||
| 232 | + | settings.SetEnableHtml5Database(true) // IndexedDB | |||
| 233 | + | ||||
| 234 | + | // Web Audio API for games and audio apps | |||
| 235 | + | settings.SetEnableWebaudio(true) | |||
| 236 | + | ||||
| 237 | + | // Touchpad swipe gestures for back/forward navigation | |||
| 238 | + | settings.SetEnableBackForwardNavigationGestures(true) | |||
| 239 | + | ||||
| 240 | + | // WebKit compatibility hacks for popular broken sites | |||
| 241 | + | settings.SetEnableSiteSpecificQuirks(true) | |||
| 242 | + | ||||
| 213 | // Disable console messages to stdout to prevent page script flooding | 243 | // Disable console messages to stdout to prevent page script flooding | ||
| 214 | // This stops malicious/buggy pages from spamming the terminal with console.log() | 244 | // This stops malicious/buggy pages from spamming the terminal with console.log() | ||
| 215 | // Inspector/DevTools console (F12) will still show all messages | 245 | // Inspector/DevTools console (F12) will still show all messages | ||