chore(docs): remove outdated migration and progress documentation for webkit package
- commit
- b1d198d5bb8363e05727a317882b0f7a8bbd2df4
- author
- bamen · · 2025-10-14 18:22 UTC
- parent
- 81fd4c5
- signature
- unsigned
5 files · +1 -1065
D docs/gotk4-migration-plan.md +0 -410
| @@ -1,410 +0,0 @@ | |||
| 1 | - | # Migration Plan: Manual GTK4 CGO → gotk4 + Regeneration Strategy | |
| 2 | - | ||
| 3 | - | ## YES, You Can Regenerate gotk4-webkitgtk Bindings! | |
| 4 | - | ||
| 5 | - | ### Current State | |
| 6 | - | - **gotk4-webkitgtk**: Last updated Jan 8, 2024 (~1 year old) | |
| 7 | - | - **gotk4**: Actively maintained (last update Jul 3, 2025) | |
| 8 | - | - **Status**: ✅ **WORKS WITH LATEST GOTK4** (confirmed by recent test) | |
| 9 | - | - **WebKitGTK 6.0**: ✅ **SUPPORTED** (import path: `webkit/v6`) | |
| 10 | - | ||
| 11 | - | ### Good News from Research | |
| 12 | - | The last comment on the compatibility issue (recent) confirms: | |
| 13 | - | ```go | |
| 14 | - | import webkit "github.com/diamondburned/gotk4-webkitgtk/pkg/webkit/v6" | |
| 15 | - | // Works perfectly with gotk4 v0.3.2! | |
| 16 | - | ``` | |
| 17 | - | ||
| 18 | - | --- | |
| 19 | - | ||
| 20 | - | ## Option 1: Use Existing gotk4-webkitgtk (RECOMMENDED) | |
| 21 | - | ||
| 22 | - | ### Why This Works | |
| 23 | - | - Bindings were regenerated Jan 2024 with GTK4 WebKitGTK | |
| 24 | - | - Compatible with latest gotk4 (v0.3.2+) | |
| 25 | - | - Already supports webkitgtk-6.0 | |
| 26 | - | - **No need to regenerate unless you need bleeding-edge APIs** | |
| 27 | - | ||
| 28 | - | ### Migration Steps | |
| 29 | - | ```bash | |
| 30 | - | # Add dependencies | |
| 31 | - | go get github.com/diamondburned/gotk4/pkg@latest | |
| 32 | - | go get github.com/diamondburned/gotk4-webkitgtk/pkg@latest | |
| 33 | - | ||
| 34 | - | # Imports will be: | |
| 35 | - | import ( | |
| 36 | - | "github.com/diamondburned/gotk4/pkg/gtk/v4" | |
| 37 | - | "github.com/diamondburned/gotk4/pkg/gdk/v4" | |
| 38 | - | webkit "github.com/diamondburned/gotk4-webkitgtk/pkg/webkit/v6" | |
| 39 | - | ) | |
| 40 | - | ``` | |
| 41 | - | ||
| 42 | - | --- | |
| 43 | - | ||
| 44 | - | ## Option 2: Regenerate Bindings for Latest WebKitGTK | |
| 45 | - | ||
| 46 | - | ### When to Regenerate | |
| 47 | - | - Need WebKitGTK APIs added after Jan 2024 | |
| 48 | - | - Want to contribute upstream improvements | |
| 49 | - | - Customize bindings for your specific needs | |
| 50 | - | ||
| 51 | - | ### How to Regenerate (3 Methods) | |
| 52 | - | ||
| 53 | - | #### Method A: Using Nix (Recommended by gotk4 maintainer) | |
| 54 | - | ||
| 55 | - | ```bash | |
| 56 | - | # 1. Install Nix (if not already) | |
| 57 | - | curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install | |
| 58 | - | ||
| 59 | - | # 2. Clone gotk4-webkitgtk | |
| 60 | - | git clone https://github.com/diamondburned/gotk4-webkitgtk.git | |
| 61 | - | cd gotk4-webkitgtk | |
| 62 | - | ||
| 63 | - | # 3. Update shell.nix to use webkitgtk_6_0 (already configured!) | |
| 64 | - | # See: buildInputs includes webkitgtk_6_0 | |
| 65 | - | ||
| 66 | - | # 4. Enter Nix environment | |
| 67 | - | nix-shell | |
| 68 | - | ||
| 69 | - | # 5. Regenerate bindings | |
| 70 | - | go generate | |
| 71 | - | ||
| 72 | - | # Bindings will be regenerated with your system's WebKitGTK version! | |
| 73 | - | ``` | |
| 74 | - | ||
| 75 | - | #### Method B: Fork abergmeier's Updated Generator | |
| 76 | - | ||
| 77 | - | A community member already fixed the generator: | |
| 78 | - | ```bash | |
| 79 | - | # Clone the updated fork | |
| 80 | - | git clone https://github.com/abergmeier/gotk4-webkitgtk.git -b webkitv6 | |
| 81 | - | cd gotk4-webkitgtk | |
| 82 | - | ||
| 83 | - | # This fork uses gotk4-adwaita's newer genmain package | |
| 84 | - | # Should work with latest WebKitGTK 6.0 | |
| 85 | - | ``` | |
| 86 | - | ||
| 87 | - | #### Method C: Update Generator Yourself | |
| 88 | - | ||
| 89 | - | Follow gotk4-adwaita's pattern: | |
| 90 | - | ```bash | |
| 91 | - | # 1. Clone both repos | |
| 92 | - | git clone https://github.com/diamondburned/gotk4-adwaita.git | |
| 93 | - | git clone https://github.com/diamondburned/gotk4-webkitgtk.git | |
| 94 | - | ||
| 95 | - | # 2. Compare generator.go files | |
| 96 | - | # gotk4-adwaita uses newer genmain package | |
| 97 | - | # gotk4-webkitgtk uses older girgen directly | |
| 98 | - | ||
| 99 | - | # 3. Update gotk4-webkitgtk/generator.go to match adwaita pattern | |
| 100 | - | # Key changes needed: | |
| 101 | - | # - Import "github.com/diamondburned/gotk4/gir/cmd/genmain" | |
| 102 | - | # - Use genmain.Main() instead of direct girgen calls | |
| 103 | - | # - Add preprocessors for module name fixes (soup, javascriptcore) | |
| 104 | - | # - Add TLS protocol version polyfill | |
| 105 | - | ``` | |
| 106 | - | ||
| 107 | - | --- | |
| 108 | - | ||
| 109 | - | ## Migration Plan: From Manual CGO to gotk4 | |
| 110 | - | ||
| 111 | - | ### Phase 1: Proof of Concept (1-2 days) | |
| 112 | - | ||
| 113 | - | Test gotk4 compatibility with simple example: | |
| 114 | - | ||
| 115 | - | ```go | |
| 116 | - | package main | |
| 117 | - | ||
| 118 | - | import ( | |
| 119 | - | "os" | |
| 120 | - | webkit "github.com/diamondburned/gotk4-webkitgtk/pkg/webkit/v6" | |
| 121 | - | "github.com/diamondburned/gotk4/pkg/gio/v2" | |
| 122 | - | "github.com/diamondburned/gotk4/pkg/gtk/v4" | |
| 123 | - | ) | |
| 124 | - | ||
| 125 | - | func main() { | |
| 126 | - | app := gtk.NewApplication("com.dumber.test", gio.ApplicationDefaultFlags) | |
| 127 | - | ||
| 128 | - | app.ConnectActivate(func() { | |
| 129 | - | window := gtk.NewApplicationWindow(app) | |
| 130 | - | window.SetTitle("Dumb Browser Test") | |
| 131 | - | window.SetDefaultSize(1024, 768) | |
| 132 | - | ||
| 133 | - | webView := webkit.NewWebView() | |
| 134 | - | webView.LoadURI("https://example.com") | |
| 135 | - | ||
| 136 | - | // Type-safe, clean API! | |
| 137 | - | webView.ConnectLoadChanged(func(event webkit.LoadEvent) { | |
| 138 | - | uri := webView.URI() | |
| 139 | - | println("Loaded:", uri) | |
| 140 | - | }) | |
| 141 | - | ||
| 142 | - | window.SetChild(webView) | |
| 143 | - | window.Present() | |
| 144 | - | }) | |
| 145 | - | ||
| 146 | - | os.Exit(app.Run(os.Args)) | |
| 147 | - | } | |
| 148 | - | ``` | |
| 149 | - | ||
| 150 | - | **Test this builds and runs on your system!** | |
| 151 | - | ||
| 152 | - | ### Phase 2: Core Migration (2-3 weeks) | |
| 153 | - | ||
| 154 | - | #### File-by-file replacement strategy: | |
| 155 | - | ||
| 156 | - | 1. **Window wrapper** (`pkg/webkit/window.go`) | |
| 157 | - | ```go | |
| 158 | - | // Before | |
| 159 | - | type Window struct { | |
| 160 | - | win *C.GtkWidget | |
| 161 | - | } | |
| 162 | - | ||
| 163 | - | // After | |
| 164 | - | type Window struct { | |
| 165 | - | win *gtk.ApplicationWindow | |
| 166 | - | } | |
| 167 | - | ``` | |
| 168 | - | ||
| 169 | - | 2. **Widget helpers** (workspace_widgets_cgo.go) | |
| 170 | - | - ~1350 lines → ~300 lines | |
| 171 | - | - All `C.gtk_*` → `gtk.*` methods | |
| 172 | - | ||
| 173 | - | 3. **Event controllers** (keyboard_cgo.go) | |
| 174 | - | - No more `//export` functions! | |
| 175 | - | - Direct Go closures | |
| 176 | - | ||
| 177 | - | 4. **WebView core** (webview_cgo.go) | |
| 178 | - | - Simplified from 2800 lines | |
| 179 | - | - Type-safe signal connections | |
| 180 | - | ||
| 181 | - | ### Phase 3: Advanced Features (1-2 weeks) | |
| 182 | - | ||
| 183 | - | - UserContentManager integration | |
| 184 | - | - Custom URI schemes | |
| 185 | - | - Content filtering | |
| 186 | - | - Shortcuts system | |
| 187 | - | ||
| 188 | - | --- | |
| 189 | - | ||
| 190 | - | ## Key Differences: Manual CGO vs gotk4 | |
| 191 | - | ||
| 192 | - | ### Memory Management | |
| 193 | - | ```go | |
| 194 | - | // Before: Manual reference counting | |
| 195 | - | C.g_object_ref(widget) | |
| 196 | - | defer C.g_object_unref(widget) | |
| 197 | - | ||
| 198 | - | // After: Automatic (Go GC integrated) | |
| 199 | - | widget := gtk.NewLabel("text") | |
| 200 | - | // That's it! GC handles cleanup | |
| 201 | - | ``` | |
| 202 | - | ||
| 203 | - | ### Type Safety | |
| 204 | - | ```go | |
| 205 | - | // Before: Runtime panics | |
| 206 | - | widget := (*C.GtkWidget)(unsafe.Pointer(ptr)) | |
| 207 | - | ||
| 208 | - | // After: Compile-time safety | |
| 209 | - | widget := obj.Cast().(gtk.Widgetter) | |
| 210 | - | ``` | |
| 211 | - | ||
| 212 | - | ### Signal Connections | |
| 213 | - | ```go | |
| 214 | - | // Before: C bridge + export | |
| 215 | - | //export goOnTitleChanged | |
| 216 | - | func goOnTitleChanged(id C.ulong, ctitle *C.char) { | |
| 217 | - | title := C.GoString(ctitle) | |
| 218 | - | // handle... | |
| 219 | - | } | |
| 220 | - | ||
| 221 | - | // After: Direct Go closure | |
| 222 | - | webView.ConnectTitleChanged(func(title string) { | |
| 223 | - | // handle... | |
| 224 | - | }) | |
| 225 | - | ``` | |
| 226 | - | ||
| 227 | - | --- | |
| 228 | - | ||
| 229 | - | ## Recommended Approach | |
| 230 | - | ||
| 231 | - | ### For Your Project (Dumb Browser): | |
| 232 | - | ||
| 233 | - | 1. **Start with existing gotk4-webkitgtk** (Jan 2024 version) | |
| 234 | - | - It's recent enough for WebKitGTK 6.0 | |
| 235 | - | - Already compatible with latest gotk4 | |
| 236 | - | - Proven to work (see GitHub issue) | |
| 237 | - | ||
| 238 | - | 2. **Only regenerate if** you need specific APIs added after Jan 2024 | |
| 239 | - | - Use Nix method (most reliable) | |
| 240 | - | - Or use abergmeier's fork (already updated) | |
| 241 | - | ||
| 242 | - | 3. **Parallel implementation** | |
| 243 | - | - Keep `webkit_cgo` build tag for current code | |
| 244 | - | - Add `gotk4` build tag for new implementation | |
| 245 | - | - Switch when stable | |
| 246 | - | ||
| 247 | - | ### Expected Timeline | |
| 248 | - | ||
| 249 | - | | Phase | Original Estimate | With Existing Bindings | | |
| 250 | - | |-------|------------------|------------------------| | |
| 251 | - | | Setup | 1-2 days | ✅ 1 day (no regen needed) | | |
| 252 | - | | Core Migration | 10-14 days | 10-14 days | | |
| 253 | - | | Advanced Features | 7-10 days | 7-10 days | | |
| 254 | - | | Testing | 3-5 days | 3-5 days | | |
| 255 | - | | **Total** | **21-31 days** | **21-30 days** | | |
| 256 | - | ||
| 257 | - | --- | |
| 258 | - | ||
| 259 | - | ## Gotcha: Known Issues (From Research) | |
| 260 | - | ||
| 261 | - | ### Fixed Issues ✅ | |
| 262 | - | - ❌ "Not usable with gotk4" - **FIXED** (works with v0.3.2+) | |
| 263 | - | - ❌ Module name bugs (soup, javascriptcore) - **FIXED** in community forks | |
| 264 | - | - ❌ Missing TLSProtocolVersion - **WORKAROUND** available | |
| 265 | - | ||
| 266 | - | ### Potential Issues | |
| 267 | - | - If regenerating: Generator is outdated (use adwaita's genmain pattern) | |
| 268 | - | - Nix learning curve (but Docker alternative exists) | |
| 269 | - | ||
| 270 | - | --- | |
| 271 | - | ||
| 272 | - | ## Decision Matrix | |
| 273 | - | ||
| 274 | - | | Scenario | Recommendation | | |
| 275 | - | |----------|---------------| | |
| 276 | - | | **Just want to use gotk4** | Use existing gotk4-webkitgtk pkg | | |
| 277 | - | | **Need latest WebKitGTK APIs** | Regenerate with Nix | | |
| 278 | - | | **Want to contribute upstream** | Update generator + regenerate | | |
| 279 | - | | **Avoid Nix** | Use abergmeier's fork | | |
| 280 | - | ||
| 281 | - | --- | |
| 282 | - | ||
| 283 | - | ## Final Recommendation | |
| 284 | - | ||
| 285 | - | ✅ **USE EXISTING gotk4-webkitgtk** - It works great! | |
| 286 | - | ||
| 287 | - | Only regenerate if you: | |
| 288 | - | - Have Nix experience | |
| 289 | - | - Need bleeding-edge WebKitGTK APIs | |
| 290 | - | - Want to contribute improvements | |
| 291 | - | ||
| 292 | - | The Jan 2024 bindings support WebKitGTK 6.0 and work with latest gotk4. **This is sufficient for your migration.** | |
| 293 | - | ||
| 294 | - | --- | |
| 295 | - | ||
| 296 | - | ## Migration Architecture | |
| 297 | - | ||
| 298 | - | ### Current CGO Architecture | |
| 299 | - | ``` | |
| 300 | - | pkg/webkit/ | |
| 301 | - | ├── window_cgo.go (~60 lines - Window wrapper) | |
| 302 | - | ├── workspace_widgets_cgo.go (~1350 lines - Widget helpers) | |
| 303 | - | ├── keyboard_cgo.go (~814 lines - Event controllers) | |
| 304 | - | ├── shortcuts_cgo.go (~566 lines - Shortcut system) | |
| 305 | - | ├── webview_cgo.go (~2800 lines - WebView core) | |
| 306 | - | └── [15+ other _cgo.go files] | |
| 307 | - | ||
| 308 | - | Total: ~5000+ lines of manual CGO bindings | |
| 309 | - | ``` | |
| 310 | - | ||
| 311 | - | ### Target gotk4 Architecture | |
| 312 | - | ``` | |
| 313 | - | pkg/webkit/ | |
| 314 | - | ├── window_gotk4.go (~40 lines - Window wrapper) | |
| 315 | - | ├── widgets_gotk4.go (~300 lines - Widget helpers) | |
| 316 | - | ├── events_gotk4.go (~200 lines - Event controllers) | |
| 317 | - | ├── shortcuts_gotk4.go (~150 lines - Shortcut system) | |
| 318 | - | ├── webview_gotk4.go (~800 lines - WebView core) | |
| 319 | - | └── [Simplified files] | |
| 320 | - | ||
| 321 | - | Total: ~1500-2000 lines of idiomatic Go | |
| 322 | - | Reduction: 60-70% | |
| 323 | - | ``` | |
| 324 | - | ||
| 325 | - | --- | |
| 326 | - | ||
| 327 | - | ## Code Size Comparison | |
| 328 | - | ||
| 329 | - | ### Before: Manual CGO | |
| 330 | - | - **Lines of Code**: ~5000+ | |
| 331 | - | - **C Bridge Functions**: 50+ | |
| 332 | - | - **Export Functions**: 15+ | |
| 333 | - | - **Unsafe Pointers**: Everywhere | |
| 334 | - | - **Manual Memory Management**: Yes | |
| 335 | - | - **Type Safety**: Runtime only | |
| 336 | - | ||
| 337 | - | ### After: gotk4 | |
| 338 | - | - **Lines of Code**: ~1500-2000 | |
| 339 | - | - **C Bridge Functions**: 0 (handled by gotk4) | |
| 340 | - | - **Export Functions**: 0 | |
| 341 | - | - **Unsafe Pointers**: Minimal (internal to gotk4) | |
| 342 | - | - **Manual Memory Management**: No (automatic) | |
| 343 | - | - **Type Safety**: Compile-time | |
| 344 | - | ||
| 345 | - | --- | |
| 346 | - | ||
| 347 | - | ## Expected Benefits | |
| 348 | - | ||
| 349 | - | ### Code Quality | |
| 350 | - | - ✅ 60-70% code reduction | |
| 351 | - | - ✅ Compile-time type safety | |
| 352 | - | - ✅ No manual memory management | |
| 353 | - | - ✅ Idiomatic Go patterns | |
| 354 | - | - ✅ Better IDE support | |
| 355 | - | ||
| 356 | - | ### Maintainability | |
| 357 | - | - ✅ Auto-generated bindings (easy to update) | |
| 358 | - | - ✅ Less bug surface area | |
| 359 | - | - ✅ Standard Go error handling | |
| 360 | - | - ✅ No C header dependencies in Go code | |
| 361 | - | ||
| 362 | - | ### Performance | |
| 363 | - | - ✅ Same or better runtime performance | |
| 364 | - | - ✅ Faster compilation (less CGO) | |
| 365 | - | - ✅ Better GC integration | |
| 366 | - | ||
| 367 | - | --- | |
| 368 | - | ||
| 369 | - | ## Success Criteria | |
| 370 | - | ||
| 371 | - | - ✅ All 23 files in `internal/app/browser/` compile with gotk4 | |
| 372 | - | - ✅ Startup time remains <500ms | |
| 373 | - | - ✅ No memory leaks in 24h stress test | |
| 374 | - | - ✅ All shortcuts work correctly | |
| 375 | - | - ✅ Multi-pane workspace functions properly | |
| 376 | - | - ✅ WebView lifecycle (create/destroy/reparent) stable | |
| 377 | - | - ✅ Code is cleaner and more maintainable | |
| 378 | - | ||
| 379 | - | --- | |
| 380 | - | ||
| 381 | - | ## Resources | |
| 382 | - | ||
| 383 | - | ### Documentation | |
| 384 | - | - [gotk4 Documentation](https://pkg.go.dev/github.com/diamondburned/gotk4/pkg) | |
| 385 | - | - [gotk4-webkitgtk Documentation](https://pkg.go.dev/github.com/diamondburned/gotk4-webkitgtk/pkg) | |
| 386 | - | - [gotk4 Examples](https://github.com/diamondburned/gotk4-examples) | |
| 387 | - | - [GTK4 Documentation](https://docs.gtk.org/gtk4/) | |
| 388 | - | - [WebKitGTK Documentation](https://webkitgtk.org/reference/webkit2gtk/stable/) | |
| 389 | - | ||
| 390 | - | ### Repositories | |
| 391 | - | - [gotk4 Main](https://github.com/diamondburned/gotk4) | |
| 392 | - | - [gotk4-webkitgtk Official](https://github.com/diamondburned/gotk4-webkitgtk) | |
| 393 | - | - [gotk4-webkitgtk Fork (abergmeier)](https://github.com/abergmeier/gotk4-webkitgtk/tree/webkitv6) | |
| 394 | - | - [gotk4-adwaita (Generator Reference)](https://github.com/diamondburned/gotk4-adwaita) | |
| 395 | - | ||
| 396 | - | ### Community | |
| 397 | - | - [gotk4 Matrix Room](https://matrix.to/#/#gotk4:matrix.org) | |
| 398 | - | - [GitHub Issues](https://github.com/diamondburned/gotk4/issues) | |
| 399 | - | ||
| 400 | - | --- | |
| 401 | - | ||
| 402 | - | ## Next Steps | |
| 403 | - | ||
| 404 | - | 1. ✅ **[DONE]** Research gotk4-webkitgtk compatibility | |
| 405 | - | 2. ✅ **[DONE]** Document migration plan | |
| 406 | - | 3. ⏭️ **[NEXT]** Test proof-of-concept example | |
| 407 | - | 4. ⏭️ Add gotk4 dependencies to project | |
| 408 | - | 5. ⏭️ Begin Phase 1: Core Infrastructure migration | |
| 409 | - | ||
| 410 | - | **Ready to start Phase 1!** | |
| @@ -1,410 +0,0 @@ | |||||
| 1 | - | # Migration Plan: Manual GTK4 CGO → gotk4 + Regeneration Strategy | |||
| 2 | - | ||||
| 3 | - | ## YES, You Can Regenerate gotk4-webkitgtk Bindings! | |||
| 4 | - | ||||
| 5 | - | ### Current State | |||
| 6 | - | - **gotk4-webkitgtk**: Last updated Jan 8, 2024 (~1 year old) | |||
| 7 | - | - **gotk4**: Actively maintained (last update Jul 3, 2025) | |||
| 8 | - | - **Status**: ✅ **WORKS WITH LATEST GOTK4** (confirmed by recent test) | |||
| 9 | - | - **WebKitGTK 6.0**: ✅ **SUPPORTED** (import path: `webkit/v6`) | |||
| 10 | - | ||||
| 11 | - | ### Good News from Research | |||
| 12 | - | The last comment on the compatibility issue (recent) confirms: | |||
| 13 | - | ```go | |||
| 14 | - | import webkit "github.com/diamondburned/gotk4-webkitgtk/pkg/webkit/v6" | |||
| 15 | - | // Works perfectly with gotk4 v0.3.2! | |||
| 16 | - | ``` | |||
| 17 | - | ||||
| 18 | - | --- | |||
| 19 | - | ||||
| 20 | - | ## Option 1: Use Existing gotk4-webkitgtk (RECOMMENDED) | |||
| 21 | - | ||||
| 22 | - | ### Why This Works | |||
| 23 | - | - Bindings were regenerated Jan 2024 with GTK4 WebKitGTK | |||
| 24 | - | - Compatible with latest gotk4 (v0.3.2+) | |||
| 25 | - | - Already supports webkitgtk-6.0 | |||
| 26 | - | - **No need to regenerate unless you need bleeding-edge APIs** | |||
| 27 | - | ||||
| 28 | - | ### Migration Steps | |||
| 29 | - | ```bash | |||
| 30 | - | # Add dependencies | |||
| 31 | - | go get github.com/diamondburned/gotk4/pkg@latest | |||
| 32 | - | go get github.com/diamondburned/gotk4-webkitgtk/pkg@latest | |||
| 33 | - | ||||
| 34 | - | # Imports will be: | |||
| 35 | - | import ( | |||
| 36 | - | "github.com/diamondburned/gotk4/pkg/gtk/v4" | |||
| 37 | - | "github.com/diamondburned/gotk4/pkg/gdk/v4" | |||
| 38 | - | webkit "github.com/diamondburned/gotk4-webkitgtk/pkg/webkit/v6" | |||
| 39 | - | ) | |||
| 40 | - | ``` | |||
| 41 | - | ||||
| 42 | - | --- | |||
| 43 | - | ||||
| 44 | - | ## Option 2: Regenerate Bindings for Latest WebKitGTK | |||
| 45 | - | ||||
| 46 | - | ### When to Regenerate | |||
| 47 | - | - Need WebKitGTK APIs added after Jan 2024 | |||
| 48 | - | - Want to contribute upstream improvements | |||
| 49 | - | - Customize bindings for your specific needs | |||
| 50 | - | ||||
| 51 | - | ### How to Regenerate (3 Methods) | |||
| 52 | - | ||||
| 53 | - | #### Method A: Using Nix (Recommended by gotk4 maintainer) | |||
| 54 | - | ||||
| 55 | - | ```bash | |||
| 56 | - | # 1. Install Nix (if not already) | |||
| 57 | - | curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install | |||
| 58 | - | ||||
| 59 | - | # 2. Clone gotk4-webkitgtk | |||
| 60 | - | git clone https://github.com/diamondburned/gotk4-webkitgtk.git | |||
| 61 | - | cd gotk4-webkitgtk | |||
| 62 | - | ||||
| 63 | - | # 3. Update shell.nix to use webkitgtk_6_0 (already configured!) | |||
| 64 | - | # See: buildInputs includes webkitgtk_6_0 | |||
| 65 | - | ||||
| 66 | - | # 4. Enter Nix environment | |||
| 67 | - | nix-shell | |||
| 68 | - | ||||
| 69 | - | # 5. Regenerate bindings | |||
| 70 | - | go generate | |||
| 71 | - | ||||
| 72 | - | # Bindings will be regenerated with your system's WebKitGTK version! | |||
| 73 | - | ``` | |||
| 74 | - | ||||
| 75 | - | #### Method B: Fork abergmeier's Updated Generator | |||
| 76 | - | ||||
| 77 | - | A community member already fixed the generator: | |||
| 78 | - | ```bash | |||
| 79 | - | # Clone the updated fork | |||
| 80 | - | git clone https://github.com/abergmeier/gotk4-webkitgtk.git -b webkitv6 | |||
| 81 | - | cd gotk4-webkitgtk | |||
| 82 | - | ||||
| 83 | - | # This fork uses gotk4-adwaita's newer genmain package | |||
| 84 | - | # Should work with latest WebKitGTK 6.0 | |||
| 85 | - | ``` | |||
| 86 | - | ||||
| 87 | - | #### Method C: Update Generator Yourself | |||
| 88 | - | ||||
| 89 | - | Follow gotk4-adwaita's pattern: | |||
| 90 | - | ```bash | |||
| 91 | - | # 1. Clone both repos | |||
| 92 | - | git clone https://github.com/diamondburned/gotk4-adwaita.git | |||
| 93 | - | git clone https://github.com/diamondburned/gotk4-webkitgtk.git | |||
| 94 | - | ||||
| 95 | - | # 2. Compare generator.go files | |||
| 96 | - | # gotk4-adwaita uses newer genmain package | |||
| 97 | - | # gotk4-webkitgtk uses older girgen directly | |||
| 98 | - | ||||
| 99 | - | # 3. Update gotk4-webkitgtk/generator.go to match adwaita pattern | |||
| 100 | - | # Key changes needed: | |||
| 101 | - | # - Import "github.com/diamondburned/gotk4/gir/cmd/genmain" | |||
| 102 | - | # - Use genmain.Main() instead of direct girgen calls | |||
| 103 | - | # - Add preprocessors for module name fixes (soup, javascriptcore) | |||
| 104 | - | # - Add TLS protocol version polyfill | |||
| 105 | - | ``` | |||
| 106 | - | ||||
| 107 | - | --- | |||
| 108 | - | ||||
| 109 | - | ## Migration Plan: From Manual CGO to gotk4 | |||
| 110 | - | ||||
| 111 | - | ### Phase 1: Proof of Concept (1-2 days) | |||
| 112 | - | ||||
| 113 | - | Test gotk4 compatibility with simple example: | |||
| 114 | - | ||||
| 115 | - | ```go | |||
| 116 | - | package main | |||
| 117 | - | ||||
| 118 | - | import ( | |||
| 119 | - | "os" | |||
| 120 | - | webkit "github.com/diamondburned/gotk4-webkitgtk/pkg/webkit/v6" | |||
| 121 | - | "github.com/diamondburned/gotk4/pkg/gio/v2" | |||
| 122 | - | "github.com/diamondburned/gotk4/pkg/gtk/v4" | |||
| 123 | - | ) | |||
| 124 | - | ||||
| 125 | - | func main() { | |||
| 126 | - | app := gtk.NewApplication("com.dumber.test", gio.ApplicationDefaultFlags) | |||
| 127 | - | ||||
| 128 | - | app.ConnectActivate(func() { | |||
| 129 | - | window := gtk.NewApplicationWindow(app) | |||
| 130 | - | window.SetTitle("Dumb Browser Test") | |||
| 131 | - | window.SetDefaultSize(1024, 768) | |||
| 132 | - | ||||
| 133 | - | webView := webkit.NewWebView() | |||
| 134 | - | webView.LoadURI("https://example.com") | |||
| 135 | - | ||||
| 136 | - | // Type-safe, clean API! | |||
| 137 | - | webView.ConnectLoadChanged(func(event webkit.LoadEvent) { | |||
| 138 | - | uri := webView.URI() | |||
| 139 | - | println("Loaded:", uri) | |||
| 140 | - | }) | |||
| 141 | - | ||||
| 142 | - | window.SetChild(webView) | |||
| 143 | - | window.Present() | |||
| 144 | - | }) | |||
| 145 | - | ||||
| 146 | - | os.Exit(app.Run(os.Args)) | |||
| 147 | - | } | |||
| 148 | - | ``` | |||
| 149 | - | ||||
| 150 | - | **Test this builds and runs on your system!** | |||
| 151 | - | ||||
| 152 | - | ### Phase 2: Core Migration (2-3 weeks) | |||
| 153 | - | ||||
| 154 | - | #### File-by-file replacement strategy: | |||
| 155 | - | ||||
| 156 | - | 1. **Window wrapper** (`pkg/webkit/window.go`) | |||
| 157 | - | ```go | |||
| 158 | - | // Before | |||
| 159 | - | type Window struct { | |||
| 160 | - | win *C.GtkWidget | |||
| 161 | - | } | |||
| 162 | - | ||||
| 163 | - | // After | |||
| 164 | - | type Window struct { | |||
| 165 | - | win *gtk.ApplicationWindow | |||
| 166 | - | } | |||
| 167 | - | ``` | |||
| 168 | - | ||||
| 169 | - | 2. **Widget helpers** (workspace_widgets_cgo.go) | |||
| 170 | - | - ~1350 lines → ~300 lines | |||
| 171 | - | - All `C.gtk_*` → `gtk.*` methods | |||
| 172 | - | ||||
| 173 | - | 3. **Event controllers** (keyboard_cgo.go) | |||
| 174 | - | - No more `//export` functions! | |||
| 175 | - | - Direct Go closures | |||
| 176 | - | ||||
| 177 | - | 4. **WebView core** (webview_cgo.go) | |||
| 178 | - | - Simplified from 2800 lines | |||
| 179 | - | - Type-safe signal connections | |||
| 180 | - | ||||
| 181 | - | ### Phase 3: Advanced Features (1-2 weeks) | |||
| 182 | - | ||||
| 183 | - | - UserContentManager integration | |||
| 184 | - | - Custom URI schemes | |||
| 185 | - | - Content filtering | |||
| 186 | - | - Shortcuts system | |||
| 187 | - | ||||
| 188 | - | --- | |||
| 189 | - | ||||
| 190 | - | ## Key Differences: Manual CGO vs gotk4 | |||
| 191 | - | ||||
| 192 | - | ### Memory Management | |||
| 193 | - | ```go | |||
| 194 | - | // Before: Manual reference counting | |||
| 195 | - | C.g_object_ref(widget) | |||
| 196 | - | defer C.g_object_unref(widget) | |||
| 197 | - | ||||
| 198 | - | // After: Automatic (Go GC integrated) | |||
| 199 | - | widget := gtk.NewLabel("text") | |||
| 200 | - | // That's it! GC handles cleanup | |||
| 201 | - | ``` | |||
| 202 | - | ||||
| 203 | - | ### Type Safety | |||
| 204 | - | ```go | |||
| 205 | - | // Before: Runtime panics | |||
| 206 | - | widget := (*C.GtkWidget)(unsafe.Pointer(ptr)) | |||
| 207 | - | ||||
| 208 | - | // After: Compile-time safety | |||
| 209 | - | widget := obj.Cast().(gtk.Widgetter) | |||
| 210 | - | ``` | |||
| 211 | - | ||||
| 212 | - | ### Signal Connections | |||
| 213 | - | ```go | |||
| 214 | - | // Before: C bridge + export | |||
| 215 | - | //export goOnTitleChanged | |||
| 216 | - | func goOnTitleChanged(id C.ulong, ctitle *C.char) { | |||
| 217 | - | title := C.GoString(ctitle) | |||
| 218 | - | // handle... | |||
| 219 | - | } | |||
| 220 | - | ||||
| 221 | - | // After: Direct Go closure | |||
| 222 | - | webView.ConnectTitleChanged(func(title string) { | |||
| 223 | - | // handle... | |||
| 224 | - | }) | |||
| 225 | - | ``` | |||
| 226 | - | ||||
| 227 | - | --- | |||
| 228 | - | ||||
| 229 | - | ## Recommended Approach | |||
| 230 | - | ||||
| 231 | - | ### For Your Project (Dumb Browser): | |||
| 232 | - | ||||
| 233 | - | 1. **Start with existing gotk4-webkitgtk** (Jan 2024 version) | |||
| 234 | - | - It's recent enough for WebKitGTK 6.0 | |||
| 235 | - | - Already compatible with latest gotk4 | |||
| 236 | - | - Proven to work (see GitHub issue) | |||
| 237 | - | ||||
| 238 | - | 2. **Only regenerate if** you need specific APIs added after Jan 2024 | |||
| 239 | - | - Use Nix method (most reliable) | |||
| 240 | - | - Or use abergmeier's fork (already updated) | |||
| 241 | - | ||||
| 242 | - | 3. **Parallel implementation** | |||
| 243 | - | - Keep `webkit_cgo` build tag for current code | |||
| 244 | - | - Add `gotk4` build tag for new implementation | |||
| 245 | - | - Switch when stable | |||
| 246 | - | ||||
| 247 | - | ### Expected Timeline | |||
| 248 | - | ||||
| 249 | - | | Phase | Original Estimate | With Existing Bindings | | |||
| 250 | - | |-------|------------------|------------------------| | |||
| 251 | - | | Setup | 1-2 days | ✅ 1 day (no regen needed) | | |||
| 252 | - | | Core Migration | 10-14 days | 10-14 days | | |||
| 253 | - | | Advanced Features | 7-10 days | 7-10 days | | |||
| 254 | - | | Testing | 3-5 days | 3-5 days | | |||
| 255 | - | | **Total** | **21-31 days** | **21-30 days** | | |||
| 256 | - | ||||
| 257 | - | --- | |||
| 258 | - | ||||
| 259 | - | ## Gotcha: Known Issues (From Research) | |||
| 260 | - | ||||
| 261 | - | ### Fixed Issues ✅ | |||
| 262 | - | - ❌ "Not usable with gotk4" - **FIXED** (works with v0.3.2+) | |||
| 263 | - | - ❌ Module name bugs (soup, javascriptcore) - **FIXED** in community forks | |||
| 264 | - | - ❌ Missing TLSProtocolVersion - **WORKAROUND** available | |||
| 265 | - | ||||
| 266 | - | ### Potential Issues | |||
| 267 | - | - If regenerating: Generator is outdated (use adwaita's genmain pattern) | |||
| 268 | - | - Nix learning curve (but Docker alternative exists) | |||
| 269 | - | ||||
| 270 | - | --- | |||
| 271 | - | ||||
| 272 | - | ## Decision Matrix | |||
| 273 | - | ||||
| 274 | - | | Scenario | Recommendation | | |||
| 275 | - | |----------|---------------| | |||
| 276 | - | | **Just want to use gotk4** | Use existing gotk4-webkitgtk pkg | | |||
| 277 | - | | **Need latest WebKitGTK APIs** | Regenerate with Nix | | |||
| 278 | - | | **Want to contribute upstream** | Update generator + regenerate | | |||
| 279 | - | | **Avoid Nix** | Use abergmeier's fork | | |||
| 280 | - | ||||
| 281 | - | --- | |||
| 282 | - | ||||
| 283 | - | ## Final Recommendation | |||
| 284 | - | ||||
| 285 | - | ✅ **USE EXISTING gotk4-webkitgtk** - It works great! | |||
| 286 | - | ||||
| 287 | - | Only regenerate if you: | |||
| 288 | - | - Have Nix experience | |||
| 289 | - | - Need bleeding-edge WebKitGTK APIs | |||
| 290 | - | - Want to contribute improvements | |||
| 291 | - | ||||
| 292 | - | The Jan 2024 bindings support WebKitGTK 6.0 and work with latest gotk4. **This is sufficient for your migration.** | |||
| 293 | - | ||||
| 294 | - | --- | |||
| 295 | - | ||||
| 296 | - | ## Migration Architecture | |||
| 297 | - | ||||
| 298 | - | ### Current CGO Architecture | |||
| 299 | - | ``` | |||
| 300 | - | pkg/webkit/ | |||
| 301 | - | ├── window_cgo.go (~60 lines - Window wrapper) | |||
| 302 | - | ├── workspace_widgets_cgo.go (~1350 lines - Widget helpers) | |||
| 303 | - | ├── keyboard_cgo.go (~814 lines - Event controllers) | |||
| 304 | - | ├── shortcuts_cgo.go (~566 lines - Shortcut system) | |||
| 305 | - | ├── webview_cgo.go (~2800 lines - WebView core) | |||
| 306 | - | └── [15+ other _cgo.go files] | |||
| 307 | - | ||||
| 308 | - | Total: ~5000+ lines of manual CGO bindings | |||
| 309 | - | ``` | |||
| 310 | - | ||||
| 311 | - | ### Target gotk4 Architecture | |||
| 312 | - | ``` | |||
| 313 | - | pkg/webkit/ | |||
| 314 | - | ├── window_gotk4.go (~40 lines - Window wrapper) | |||
| 315 | - | ├── widgets_gotk4.go (~300 lines - Widget helpers) | |||
| 316 | - | ├── events_gotk4.go (~200 lines - Event controllers) | |||
| 317 | - | ├── shortcuts_gotk4.go (~150 lines - Shortcut system) | |||
| 318 | - | ├── webview_gotk4.go (~800 lines - WebView core) | |||
| 319 | - | └── [Simplified files] | |||
| 320 | - | ||||
| 321 | - | Total: ~1500-2000 lines of idiomatic Go | |||
| 322 | - | Reduction: 60-70% | |||
| 323 | - | ``` | |||
| 324 | - | ||||
| 325 | - | --- | |||
| 326 | - | ||||
| 327 | - | ## Code Size Comparison | |||
| 328 | - | ||||
| 329 | - | ### Before: Manual CGO | |||
| 330 | - | - **Lines of Code**: ~5000+ | |||
| 331 | - | - **C Bridge Functions**: 50+ | |||
| 332 | - | - **Export Functions**: 15+ | |||
| 333 | - | - **Unsafe Pointers**: Everywhere | |||
| 334 | - | - **Manual Memory Management**: Yes | |||
| 335 | - | - **Type Safety**: Runtime only | |||
| 336 | - | ||||
| 337 | - | ### After: gotk4 | |||
| 338 | - | - **Lines of Code**: ~1500-2000 | |||
| 339 | - | - **C Bridge Functions**: 0 (handled by gotk4) | |||
| 340 | - | - **Export Functions**: 0 | |||
| 341 | - | - **Unsafe Pointers**: Minimal (internal to gotk4) | |||
| 342 | - | - **Manual Memory Management**: No (automatic) | |||
| 343 | - | - **Type Safety**: Compile-time | |||
| 344 | - | ||||
| 345 | - | --- | |||
| 346 | - | ||||
| 347 | - | ## Expected Benefits | |||
| 348 | - | ||||
| 349 | - | ### Code Quality | |||
| 350 | - | - ✅ 60-70% code reduction | |||
| 351 | - | - ✅ Compile-time type safety | |||
| 352 | - | - ✅ No manual memory management | |||
| 353 | - | - ✅ Idiomatic Go patterns | |||
| 354 | - | - ✅ Better IDE support | |||
| 355 | - | ||||
| 356 | - | ### Maintainability | |||
| 357 | - | - ✅ Auto-generated bindings (easy to update) | |||
| 358 | - | - ✅ Less bug surface area | |||
| 359 | - | - ✅ Standard Go error handling | |||
| 360 | - | - ✅ No C header dependencies in Go code | |||
| 361 | - | ||||
| 362 | - | ### Performance | |||
| 363 | - | - ✅ Same or better runtime performance | |||
| 364 | - | - ✅ Faster compilation (less CGO) | |||
| 365 | - | - ✅ Better GC integration | |||
| 366 | - | ||||
| 367 | - | --- | |||
| 368 | - | ||||
| 369 | - | ## Success Criteria | |||
| 370 | - | ||||
| 371 | - | - ✅ All 23 files in `internal/app/browser/` compile with gotk4 | |||
| 372 | - | - ✅ Startup time remains <500ms | |||
| 373 | - | - ✅ No memory leaks in 24h stress test | |||
| 374 | - | - ✅ All shortcuts work correctly | |||
| 375 | - | - ✅ Multi-pane workspace functions properly | |||
| 376 | - | - ✅ WebView lifecycle (create/destroy/reparent) stable | |||
| 377 | - | - ✅ Code is cleaner and more maintainable | |||
| 378 | - | ||||
| 379 | - | --- | |||
| 380 | - | ||||
| 381 | - | ## Resources | |||
| 382 | - | ||||
| 383 | - | ### Documentation | |||
| 384 | - | - [gotk4 Documentation](https://pkg.go.dev/github.com/diamondburned/gotk4/pkg) | |||
| 385 | - | - [gotk4-webkitgtk Documentation](https://pkg.go.dev/github.com/diamondburned/gotk4-webkitgtk/pkg) | |||
| 386 | - | - [gotk4 Examples](https://github.com/diamondburned/gotk4-examples) | |||
| 387 | - | - [GTK4 Documentation](https://docs.gtk.org/gtk4/) | |||
| 388 | - | - [WebKitGTK Documentation](https://webkitgtk.org/reference/webkit2gtk/stable/) | |||
| 389 | - | ||||
| 390 | - | ### Repositories | |||
| 391 | - | - [gotk4 Main](https://github.com/diamondburned/gotk4) | |||
| 392 | - | - [gotk4-webkitgtk Official](https://github.com/diamondburned/gotk4-webkitgtk) | |||
| 393 | - | - [gotk4-webkitgtk Fork (abergmeier)](https://github.com/abergmeier/gotk4-webkitgtk/tree/webkitv6) | |||
| 394 | - | - [gotk4-adwaita (Generator Reference)](https://github.com/diamondburned/gotk4-adwaita) | |||
| 395 | - | ||||
| 396 | - | ### Community | |||
| 397 | - | - [gotk4 Matrix Room](https://matrix.to/#/#gotk4:matrix.org) | |||
| 398 | - | - [GitHub Issues](https://github.com/diamondburned/gotk4/issues) | |||
| 399 | - | ||||
| 400 | - | --- | |||
| 401 | - | ||||
| 402 | - | ## Next Steps | |||
| 403 | - | ||||
| 404 | - | 1. ✅ **[DONE]** Research gotk4-webkitgtk compatibility | |||
| 405 | - | 2. ✅ **[DONE]** Document migration plan | |||
| 406 | - | 3. ⏭️ **[NEXT]** Test proof-of-concept example | |||
| 407 | - | 4. ⏭️ Add gotk4 dependencies to project | |||
| 408 | - | 5. ⏭️ Begin Phase 1: Core Infrastructure migration | |||
| 409 | - | ||||
| 410 | - | **Ready to start Phase 1!** | |||
D docs/new-webkit-package-design.md +0 -175
| @@ -1,175 +0,0 @@ | |||
| 1 | - | # New webkit Package Design (gotk4-based) | |
| 2 | - | ||
| 3 | - | ## Package Structure | |
| 4 | - | ||
| 5 | - | ``` | |
| 6 | - | pkg/webkit/ | |
| 7 | - | ├── webview.go # WebView wrapper around gotk4-webkitgtk | |
| 8 | - | ├── window.go # Window wrapper around gtk.Window | |
| 9 | - | ├── widgets.go # Widget helpers (Box, Paned, Label, Image) | |
| 10 | - | ├── mainloop.go # GTK main loop management | |
| 11 | - | ├── shortcuts.go # Keyboard shortcut handling | |
| 12 | - | ├── config.go # WebView configuration | |
| 13 | - | ├── memory.go # Memory management (if needed) | |
| 14 | - | ├── types.go # Common types (WindowType, WindowFeatures, etc.) | |
| 15 | - | ├── errors.go # Error definitions | |
| 16 | - | ||
| 17 | - | ``` | |
| 18 | - | ||
| 19 | - | ## Core Types | |
| 20 | - | ||
| 21 | - | ### WebView | |
| 22 | - | ```go | |
| 23 | - | type WebView struct { | |
| 24 | - | view *webkit.WebView // gotk4-webkitgtk WebView | |
| 25 | - | ||
| 26 | - | // Event handlers | |
| 27 | - | onScriptMessage func(string) | |
| 28 | - | onTitleChanged func(string) | |
| 29 | - | onURIChanged func(string) | |
| 30 | - | onPopup func(string) *WebView | |
| 31 | - | onClose func() | |
| 32 | - | ||
| 33 | - | // State | |
| 34 | - | id uint64 | |
| 35 | - | destroyed bool | |
| 36 | - | config *Config | |
| 37 | - | } | |
| 38 | - | ``` | |
| 39 | - | ||
| 40 | - | ### Window | |
| 41 | - | ```go | |
| 42 | - | type Window struct { | |
| 43 | - | win *gtk.Window | |
| 44 | - | ||
| 45 | - | // Shortcuts (if needed at window level) | |
| 46 | - | shortcuts map[string]func() | |
| 47 | - | } | |
| 48 | - | ``` | |
| 49 | - | ||
| 50 | - | ### Widget Helpers | |
| 51 | - | Replace uintptr-based API with proper gotk4 types: | |
| 52 | - | ```go | |
| 53 | - | // Instead of: func NewPaned(orientation Orientation) uintptr | |
| 54 | - | func NewPaned(orientation gtk.Orientation) *gtk.Paned | |
| 55 | - | ||
| 56 | - | // Instead of: func PanedSetStartChild(paned uintptr, child uintptr) | |
| 57 | - | func (p *Paned) SetStartChild(child gtk.Widgetter) | |
| 58 | - | ``` | |
| 59 | - | ||
| 60 | - | ## API Design Philosophy | |
| 61 | - | ||
| 62 | - | ### 1. Type-Safe Widgets | |
| 63 | - | - No more `uintptr` for widgets | |
| 64 | - | - Use gotk4's proper types (`gtk.Widgetter`, `gtk.Widget`, etc.) | |
| 65 | - | - Compile-time type checking | |
| 66 | - | ||
| 67 | - | ### 2. Idiomatic Go | |
| 68 | - | - Methods instead of functions where appropriate | |
| 69 | - | - Use Go interfaces for polymorphism | |
| 70 | - | - Standard error handling (no `ErrNotImplemented` stubs) | |
| 71 | - | ||
| 72 | - | ### 3. Clean Event Handling | |
| 73 | - | - Use Go closures directly (no CGO export functions) | |
| 74 | - | - Type-safe callbacks | |
| 75 | - | - Clear handler registration | |
| 76 | - | ||
| 77 | - | ## Migration Path | |
| 78 | - | ||
| 79 | - | ### Phase 1: Core Types (This PR) | |
| 80 | - | 1. Remove old `pkg/webkit/` | |
| 81 | - | 2. Create new structure with gotk4 | |
| 82 | - | 3. Implement WebView, Window basics | |
| 83 | - | 4. Implement Widget helpers | |
| 84 | - | ||
| 85 | - | ### Phase 2: Update Callers | |
| 86 | - | 1. Update `internal/app/browser/` to use new API | |
| 87 | - | 2. Convert uintptr-based code to gotk4 types | |
| 88 | - | 3. Update workspace manager | |
| 89 | - | ||
| 90 | - | ### Phase 3: Advanced Features | |
| 91 | - | 1. Shortcuts system | |
| 92 | - | 2. Content filtering integration | |
| 93 | - | 3. Memory management | |
| 94 | - | 4. Custom URI schemes | |
| 95 | - | ||
| 96 | - | ## Key API Changes | |
| 97 | - | ||
| 98 | - | ### Before (CGO + uintptr) | |
| 99 | - | ```go | |
| 100 | - | // Creating WebView | |
| 101 | - | view := webkit.NewWebView(cfg) | |
| 102 | - | widget := view.Widget() // returns uintptr | |
| 103 | - | ||
| 104 | - | // Creating paned | |
| 105 | - | paned := webkit.NewPaned(webkit.OrientationHorizontal) // returns uintptr | |
| 106 | - | webkit.PanedSetStartChild(paned, widget) | |
| 107 | - | ||
| 108 | - | // Window child | |
| 109 | - | window.SetChild(widget) // takes uintptr | |
| 110 | - | ``` | |
| 111 | - | ||
| 112 | - | ### After (gotk4) | |
| 113 | - | ```go | |
| 114 | - | // Creating WebView | |
| 115 | - | view := webkit.NewWebView(cfg) | |
| 116 | - | widget := view.AsWidget() // returns gtk.Widgetter | |
| 117 | - | ||
| 118 | - | // Creating paned | |
| 119 | - | paned := webkit.NewPaned(gtk.OrientationHorizontal) // returns *Paned | |
| 120 | - | paned.SetStartChild(widget) | |
| 121 | - | ||
| 122 | - | // Window child | |
| 123 | - | window.SetChild(widget) // takes gtk.Widgetter | |
| 124 | - | ``` | |
| 125 | - | ||
| 126 | - | ## Backwards Compatibility Bridge | |
| 127 | - | ||
| 128 | - | For gradual migration, provide conversion helpers: | |
| 129 | - | ```go | |
| 130 | - | // In internal/convert.go | |
| 131 | - | func WidgetToPtr(w gtk.Widgetter) uintptr | |
| 132 | - | func PtrToWidget(ptr uintptr) gtk.Widgetter | |
| 133 | - | ``` | |
| 134 | - | ||
| 135 | - | This allows mixing old and new code during migration. | |
| 136 | - | ||
| 137 | - | ## Benefits | |
| 138 | - | ||
| 139 | - | ### Code Reduction | |
| 140 | - | - **Estimated**: ~5000 lines → ~1500 lines (70% reduction) | |
| 141 | - | - No CGO bridge functions | |
| 142 | - | - No export functions | |
| 143 | - | - Simpler widget management | |
| 144 | - | ||
| 145 | - | ### Type Safety | |
| 146 | - | - Compile-time checking | |
| 147 | - | - No runtime `uintptr` casting | |
| 148 | - | - Clear widget ownership | |
| 149 | - | ||
| 150 | - | ### Maintainability | |
| 151 | - | - Auto-generated bindings (easy to update) | |
| 152 | - | - Standard Go patterns | |
| 153 | - | - Better IDE support | |
| 154 | - | - Clear error messages | |
| 155 | - | ||
| 156 | - | ## Implementation Order | |
| 157 | - | ||
| 158 | - | 1. ✅ Design document | |
| 159 | - | 2. ⏭️ types.go + errors.go (simple types, no dependencies) | |
| 160 | - | 3. ⏭️ mainloop.go (GTK initialization and main loop) | |
| 161 | - | 4. ⏭️ window.go (basic window wrapper) | |
| 162 | - | 5. ⏭️ widgets.go (Paned, Box, Label, Image helpers) | |
| 163 | - | 6. ⏭️ webview.go (WebView wrapper with event handlers) | |
| 164 | - | 7. ⏭️ shortcuts.go (keyboard shortcut system) | |
| 165 | - | 8. ⏭️ config.go + memory.go (configuration and memory management) | |
| 166 | - | ||
| 167 | - | ## Success Criteria | |
| 168 | - | ||
| 169 | - | - ✅ All webkit package tests pass | |
| 170 | - | - ✅ Browser starts up successfully | |
| 171 | - | - ✅ WebView loads pages correctly | |
| 172 | - | - ✅ Multi-pane workspace works | |
| 173 | - | - ✅ Keyboard shortcuts functional | |
| 174 | - | - ✅ No memory leaks | |
| 175 | - | - ✅ Startup time < 500ms maintained | |
| @@ -1,175 +0,0 @@ | |||||
| 1 | - | # New webkit Package Design (gotk4-based) | |||
| 2 | - | ||||
| 3 | - | ## Package Structure | |||
| 4 | - | ||||
| 5 | - | ``` | |||
| 6 | - | pkg/webkit/ | |||
| 7 | - | ├── webview.go # WebView wrapper around gotk4-webkitgtk | |||
| 8 | - | ├── window.go # Window wrapper around gtk.Window | |||
| 9 | - | ├── widgets.go # Widget helpers (Box, Paned, Label, Image) | |||
| 10 | - | ├── mainloop.go # GTK main loop management | |||
| 11 | - | ├── shortcuts.go # Keyboard shortcut handling | |||
| 12 | - | ├── config.go # WebView configuration | |||
| 13 | - | ├── memory.go # Memory management (if needed) | |||
| 14 | - | ├── types.go # Common types (WindowType, WindowFeatures, etc.) | |||
| 15 | - | ├── errors.go # Error definitions | |||
| 16 | - | ||||
| 17 | - | ``` | |||
| 18 | - | ||||
| 19 | - | ## Core Types | |||
| 20 | - | ||||
| 21 | - | ### WebView | |||
| 22 | - | ```go | |||
| 23 | - | type WebView struct { | |||
| 24 | - | view *webkit.WebView // gotk4-webkitgtk WebView | |||
| 25 | - | ||||
| 26 | - | // Event handlers | |||
| 27 | - | onScriptMessage func(string) | |||
| 28 | - | onTitleChanged func(string) | |||
| 29 | - | onURIChanged func(string) | |||
| 30 | - | onPopup func(string) *WebView | |||
| 31 | - | onClose func() | |||
| 32 | - | ||||
| 33 | - | // State | |||
| 34 | - | id uint64 | |||
| 35 | - | destroyed bool | |||
| 36 | - | config *Config | |||
| 37 | - | } | |||
| 38 | - | ``` | |||
| 39 | - | ||||
| 40 | - | ### Window | |||
| 41 | - | ```go | |||
| 42 | - | type Window struct { | |||
| 43 | - | win *gtk.Window | |||
| 44 | - | ||||
| 45 | - | // Shortcuts (if needed at window level) | |||
| 46 | - | shortcuts map[string]func() | |||
| 47 | - | } | |||
| 48 | - | ``` | |||
| 49 | - | ||||
| 50 | - | ### Widget Helpers | |||
| 51 | - | Replace uintptr-based API with proper gotk4 types: | |||
| 52 | - | ```go | |||
| 53 | - | // Instead of: func NewPaned(orientation Orientation) uintptr | |||
| 54 | - | func NewPaned(orientation gtk.Orientation) *gtk.Paned | |||
| 55 | - | ||||
| 56 | - | // Instead of: func PanedSetStartChild(paned uintptr, child uintptr) | |||
| 57 | - | func (p *Paned) SetStartChild(child gtk.Widgetter) | |||
| 58 | - | ``` | |||
| 59 | - | ||||
| 60 | - | ## API Design Philosophy | |||
| 61 | - | ||||
| 62 | - | ### 1. Type-Safe Widgets | |||
| 63 | - | - No more `uintptr` for widgets | |||
| 64 | - | - Use gotk4's proper types (`gtk.Widgetter`, `gtk.Widget`, etc.) | |||
| 65 | - | - Compile-time type checking | |||
| 66 | - | ||||
| 67 | - | ### 2. Idiomatic Go | |||
| 68 | - | - Methods instead of functions where appropriate | |||
| 69 | - | - Use Go interfaces for polymorphism | |||
| 70 | - | - Standard error handling (no `ErrNotImplemented` stubs) | |||
| 71 | - | ||||
| 72 | - | ### 3. Clean Event Handling | |||
| 73 | - | - Use Go closures directly (no CGO export functions) | |||
| 74 | - | - Type-safe callbacks | |||
| 75 | - | - Clear handler registration | |||
| 76 | - | ||||
| 77 | - | ## Migration Path | |||
| 78 | - | ||||
| 79 | - | ### Phase 1: Core Types (This PR) | |||
| 80 | - | 1. Remove old `pkg/webkit/` | |||
| 81 | - | 2. Create new structure with gotk4 | |||
| 82 | - | 3. Implement WebView, Window basics | |||
| 83 | - | 4. Implement Widget helpers | |||
| 84 | - | ||||
| 85 | - | ### Phase 2: Update Callers | |||
| 86 | - | 1. Update `internal/app/browser/` to use new API | |||
| 87 | - | 2. Convert uintptr-based code to gotk4 types | |||
| 88 | - | 3. Update workspace manager | |||
| 89 | - | ||||
| 90 | - | ### Phase 3: Advanced Features | |||
| 91 | - | 1. Shortcuts system | |||
| 92 | - | 2. Content filtering integration | |||
| 93 | - | 3. Memory management | |||
| 94 | - | 4. Custom URI schemes | |||
| 95 | - | ||||
| 96 | - | ## Key API Changes | |||
| 97 | - | ||||
| 98 | - | ### Before (CGO + uintptr) | |||
| 99 | - | ```go | |||
| 100 | - | // Creating WebView | |||
| 101 | - | view := webkit.NewWebView(cfg) | |||
| 102 | - | widget := view.Widget() // returns uintptr | |||
| 103 | - | ||||
| 104 | - | // Creating paned | |||
| 105 | - | paned := webkit.NewPaned(webkit.OrientationHorizontal) // returns uintptr | |||
| 106 | - | webkit.PanedSetStartChild(paned, widget) | |||
| 107 | - | ||||
| 108 | - | // Window child | |||
| 109 | - | window.SetChild(widget) // takes uintptr | |||
| 110 | - | ``` | |||
| 111 | - | ||||
| 112 | - | ### After (gotk4) | |||
| 113 | - | ```go | |||
| 114 | - | // Creating WebView | |||
| 115 | - | view := webkit.NewWebView(cfg) | |||
| 116 | - | widget := view.AsWidget() // returns gtk.Widgetter | |||
| 117 | - | ||||
| 118 | - | // Creating paned | |||
| 119 | - | paned := webkit.NewPaned(gtk.OrientationHorizontal) // returns *Paned | |||
| 120 | - | paned.SetStartChild(widget) | |||
| 121 | - | ||||
| 122 | - | // Window child | |||
| 123 | - | window.SetChild(widget) // takes gtk.Widgetter | |||
| 124 | - | ``` | |||
| 125 | - | ||||
| 126 | - | ## Backwards Compatibility Bridge | |||
| 127 | - | ||||
| 128 | - | For gradual migration, provide conversion helpers: | |||
| 129 | - | ```go | |||
| 130 | - | // In internal/convert.go | |||
| 131 | - | func WidgetToPtr(w gtk.Widgetter) uintptr | |||
| 132 | - | func PtrToWidget(ptr uintptr) gtk.Widgetter | |||
| 133 | - | ``` | |||
| 134 | - | ||||
| 135 | - | This allows mixing old and new code during migration. | |||
| 136 | - | ||||
| 137 | - | ## Benefits | |||
| 138 | - | ||||
| 139 | - | ### Code Reduction | |||
| 140 | - | - **Estimated**: ~5000 lines → ~1500 lines (70% reduction) | |||
| 141 | - | - No CGO bridge functions | |||
| 142 | - | - No export functions | |||
| 143 | - | - Simpler widget management | |||
| 144 | - | ||||
| 145 | - | ### Type Safety | |||
| 146 | - | - Compile-time checking | |||
| 147 | - | - No runtime `uintptr` casting | |||
| 148 | - | - Clear widget ownership | |||
| 149 | - | ||||
| 150 | - | ### Maintainability | |||
| 151 | - | - Auto-generated bindings (easy to update) | |||
| 152 | - | - Standard Go patterns | |||
| 153 | - | - Better IDE support | |||
| 154 | - | - Clear error messages | |||
| 155 | - | ||||
| 156 | - | ## Implementation Order | |||
| 157 | - | ||||
| 158 | - | 1. ✅ Design document | |||
| 159 | - | 2. ⏭️ types.go + errors.go (simple types, no dependencies) | |||
| 160 | - | 3. ⏭️ mainloop.go (GTK initialization and main loop) | |||
| 161 | - | 4. ⏭️ window.go (basic window wrapper) | |||
| 162 | - | 5. ⏭️ widgets.go (Paned, Box, Label, Image helpers) | |||
| 163 | - | 6. ⏭️ webview.go (WebView wrapper with event handlers) | |||
| 164 | - | 7. ⏭️ shortcuts.go (keyboard shortcut system) | |||
| 165 | - | 8. ⏭️ config.go + memory.go (configuration and memory management) | |||
| 166 | - | ||||
| 167 | - | ## Success Criteria | |||
| 168 | - | ||||
| 169 | - | - ✅ All webkit package tests pass | |||
| 170 | - | - ✅ Browser starts up successfully | |||
| 171 | - | - ✅ WebView loads pages correctly | |||
| 172 | - | - ✅ Multi-pane workspace works | |||
| 173 | - | - ✅ Keyboard shortcuts functional | |||
| 174 | - | - ✅ No memory leaks | |||
| 175 | - | - ✅ Startup time < 500ms maintained | |||
D docs/webkit-migration-progress.md +0 -181
| @@ -1,181 +0,0 @@ | |||
| 1 | - | # WebKit Package Migration Progress | |
| 2 | - | ||
| 3 | - | ## ✅ Completed | |
| 4 | - | ||
| 5 | - | ### 1. New webkit Package (pkg/webkit/) | |
| 6 | - | - ✅ Complete rewrite with gotk4 | |
| 7 | - | - ✅ 90% code reduction (~5000 lines → ~500 lines) | |
| 8 | - | - ✅ Files: errors.go, types.go, mainloop.go, window.go, widgets.go, webview.go | |
| 9 | - | - ✅ Type-safe API with gtk.Widgetter | |
| 10 | - | - ✅ Automatic memory management (Go GC) | |
| 11 | - | ||
| 12 | - | ### 2. Core Type Updates | |
| 13 | - | - ✅ `paneNode.container`: `uintptr` → `gtk.Widgetter` | |
| 14 | - | - ✅ `paneNode.titleBar`: `uintptr` → `gtk.Widgetter` | |
| 15 | - | - ✅ `paneNode.stackWrapper`: `uintptr` → `gtk.Widgetter` | |
| 16 | - | - ✅ `paneNode.orientation`: `webkit.Orientation` → `gtk.Orientation` | |
| 17 | - | - ✅ Added `gtk/v4` imports to workspace files | |
| 18 | - | ||
| 19 | - | ### 3. Workspace Utility Functions (workspace_utils.go) | |
| 20 | - | - ✅ `initializePaneWidgets()`: Now accepts `gtk.Widgetter` instead of `uintptr` | |
| 21 | - | - ✅ `setContainer()`: Updated to work with `gtk.Widgetter` | |
| 22 | - | - ✅ `setTitleBar()`: Updated to work with `gtk.Widgetter` | |
| 23 | - | - ✅ `setStackWrapper()`: Updated to work with `gtk.Widgetter` | |
| 24 | - | - ✅ `mapDirection()`: Returns `gtk.Orientation` instead of `webkit.Orientation` | |
| 25 | - | ||
| 26 | - | ## 🚧 In Progress / TODO | |
| 27 | - | ||
| 28 | - | ### Files Needing Updates (by priority) | |
| 29 | - | ||
| 30 | - | #### Priority 1: Core Workspace Operations | |
| 31 | - | 1. **workspace_manager.go** (69 lines) | |
| 32 | - | - Update `pendingIdle` map type | |
| 33 | - | - Update widget comparisons (`== 0` → `== nil`) | |
| 34 | - | - Update `Window.SetChild()` calls | |
| 35 | - | ||
| 36 | - | 2. **stacked_panes.go** (23 files total) | |
| 37 | - | - Update all `webkit.NewBox()` → `gtk.NewBox()` | |
| 38 | - | - Update all `webkit.BoxAppend()` → `box.Append()` | |
| 39 | - | - Update all `webkit.PanedSetStartChild()` → `paned.SetStartChild()` | |
| 40 | - | - Update widget null checks (`ptr != 0` → `widget != nil`) | |
| 41 | - | - Update `titleBarToPane map[uintptr]*paneNode` → `map[uint64]*paneNode` or alternative | |
| 42 | - | ||
| 43 | - | 3. **workspace_pane_ops.go** | |
| 44 | - | - Update `SplitPane()` function | |
| 45 | - | - Update `webkit.NewPaned()` calls | |
| 46 | - | - Update paned child setting operations | |
| 47 | - | - Update widget show/hide calls | |
| 48 | - | ||
| 49 | - | #### Priority 2: Navigation and Focus | |
| 50 | - | 4. **workspace_navigation.go** | |
| 51 | - | - Update hover handlers | |
| 52 | - | - Update widget geometry functions | |
| 53 | - | ||
| 54 | - | 5. **focus_state_machine.go** | |
| 55 | - | - Update GTK event controller attachments | |
| 56 | - | ||
| 57 | - | #### Priority 3: Supporting Files | |
| 58 | - | 6. **workspace_utils.go** (remaining) | |
| 59 | - | - Update `PaneBorderContext` struct | |
| 60 | - | - Update `determineBorderContext()` function | |
| 61 | - | - Update all border application code | |
| 62 | - | ||
| 63 | - | 7. **workspace_pane_close.go** | |
| 64 | - | - Update cleanup operations | |
| 65 | - | - Update widget unparenting | |
| 66 | - | ||
| 67 | - | 8. **workspace_idle.go** | |
| 68 | - | - Update idle callbacks | |
| 69 | - | ||
| 70 | - | ### Key Patterns to Update | |
| 71 | - | ||
| 72 | - | #### Widget Creation | |
| 73 | - | ```go | |
| 74 | - | // Old | |
| 75 | - | paned := webkit.NewPaned(orientation) | |
| 76 | - | ||
| 77 | - | // New | |
| 78 | - | paned := gtk.NewPaned(orientation) // or webkit.NewPaned(orientation).AsWidget() | |
| 79 | - | ``` | |
| 80 | - | ||
| 81 | - | #### Widget Operations | |
| 82 | - | ```go | |
| 83 | - | // Old | |
| 84 | - | webkit.PanedSetStartChild(paned, child) | |
| 85 | - | ||
| 86 | - | // New - Option 1: Type assertion | |
| 87 | - | if p, ok := paned.(*gtk.Paned); ok { | |
| 88 | - | p.SetStartChild(child) | |
| 89 | - | } | |
| 90 | - | ||
| 91 | - | // New - Option 2: Store concrete types | |
| 92 | - | paned := gtk.NewPaned(orientation) // Store as *gtk.Paned | |
| 93 | - | paned.SetStartChild(child) | |
| 94 | - | ``` | |
| 95 | - | ||
| 96 | - | #### Null Checks | |
| 97 | - | ```go | |
| 98 | - | // Old | |
| 99 | - | if container == 0 { } | |
| 100 | - | if webkit.WidgetIsValid(container) { } | |
| 101 | - | ||
| 102 | - | // New | |
| 103 | - | if container == nil { } | |
| 104 | - | if container != nil { } | |
| 105 | - | ``` | |
| 106 | - | ||
| 107 | - | #### Widget Comparisons | |
| 108 | - | ```go | |
| 109 | - | // Old | |
| 110 | - | node.container = 0 | |
| 111 | - | parent := webkit.WidgetGetParent(widget) | |
| 112 | - | if parent != 0 { } | |
| 113 | - | ||
| 114 | - | // New | |
| 115 | - | node.container = nil | |
| 116 | - | parent := widget.Parent() | |
| 117 | - | if parent != nil { } | |
| 118 | - | ``` | |
| 119 | - | ||
| 120 | - | #### Maps with Widget Keys | |
| 121 | - | ```go | |
| 122 | - | // Old | |
| 123 | - | pendingIdle map[uintptr][]*paneNode | |
| 124 | - | ||
| 125 | - | // New - Option 1: Use interface{} | |
| 126 | - | pendingIdle map[interface{}][]*paneNode | |
| 127 | - | ||
| 128 | - | // New - Option 2: Use string keys (widget pointer address) | |
| 129 | - | pendingIdle map[string][]*paneNode | |
| 130 | - | ||
| 131 | - | // New - Option 3: Use generic comparable constraint | |
| 132 | - | ``` | |
| 133 | - | ||
| 134 | - | ## Migration Strategy | |
| 135 | - | ||
| 136 | - | ### Approach | |
| 137 | - | We're doing a **clean break** from the old CGO code, NOT maintaining compatibility. | |
| 138 | - | ||
| 139 | - | ### Process | |
| 140 | - | 1. ✅ Update type definitions first | |
| 141 | - | 2. ✅ Update utility functions | |
| 142 | - | 3. 🚧 Update each file incrementally | |
| 143 | - | 4. ⏳ Fix compilation errors as we go | |
| 144 | - | 5. ⏳ Test each subsystem | |
| 145 | - | ||
| 146 | - | ### Files Can Be Updated in Parallel | |
| 147 | - | Since we're breaking compatibility anyway, we can update files one at a time and fix compilation errors iteratively. The codebase doesn't need to compile at every step. | |
| 148 | - | ||
| 149 | - | ## Remaining Work Estimate | |
| 150 | - | ||
| 151 | - | - **stacked_panes.go**: ~100 locations need updating (2-3 hours) | |
| 152 | - | - **workspace_pane_ops.go**: ~50 locations (1-2 hours) | |
| 153 | - | - **workspace_utils.go**: ~30 locations (1 hour) | |
| 154 | - | - **workspace_manager.go**: ~20 locations (1 hour) | |
| 155 | - | - **workspace_navigation.go**: ~15 locations (1 hour) | |
| 156 | - | - **Other files**: ~50 locations combined (2 hours) | |
| 157 | - | ||
| 158 | - | **Total estimate**: 8-11 hours of focused work | |
| 159 | - | ||
| 160 | - | ## Benefits Already Achieved | |
| 161 | - | ||
| 162 | - | ✅ Type safety - compile-time checking instead of runtime crashes | |
| 163 | - | ✅ Cleaner code - no more uintptr casting | |
| 164 | - | ✅ Better IDE support - autocomplete and refactoring work | |
| 165 | - | ✅ Automatic memory management - no manual ref counting | |
| 166 | - | ✅ Easier debugging - stack traces show actual types | |
| 167 | - | ✅ Future-proof - auto-generated bindings stay up to date | |
| 168 | - | ||
| 169 | - | ## Next Steps | |
| 170 | - | ||
| 171 | - | 1. Update `stacked_panes.go` - most widget operations are here | |
| 172 | - | 2. Update `workspace_pane_ops.go` - split/close operations | |
| 173 | - | 3. Update remaining workspace files | |
| 174 | - | 4. Fix all compilation errors | |
| 175 | - | 5. Test browser functionality | |
| 176 | - | 6. Update any missing webkit package functions as needed | |
| 177 | - | ||
| 178 | - | --- | |
| 179 | - | ||
| 180 | - | **Current Status**: Core types updated, utility functions migrated ✅ | |
| 181 | - | **Next**: Update stacked_panes.go widget operations 🚧 | |
| @@ -1,181 +0,0 @@ | |||||
| 1 | - | # WebKit Package Migration Progress | |||
| 2 | - | ||||
| 3 | - | ## ✅ Completed | |||
| 4 | - | ||||
| 5 | - | ### 1. New webkit Package (pkg/webkit/) | |||
| 6 | - | - ✅ Complete rewrite with gotk4 | |||
| 7 | - | - ✅ 90% code reduction (~5000 lines → ~500 lines) | |||
| 8 | - | - ✅ Files: errors.go, types.go, mainloop.go, window.go, widgets.go, webview.go | |||
| 9 | - | - ✅ Type-safe API with gtk.Widgetter | |||
| 10 | - | - ✅ Automatic memory management (Go GC) | |||
| 11 | - | ||||
| 12 | - | ### 2. Core Type Updates | |||
| 13 | - | - ✅ `paneNode.container`: `uintptr` → `gtk.Widgetter` | |||
| 14 | - | - ✅ `paneNode.titleBar`: `uintptr` → `gtk.Widgetter` | |||
| 15 | - | - ✅ `paneNode.stackWrapper`: `uintptr` → `gtk.Widgetter` | |||
| 16 | - | - ✅ `paneNode.orientation`: `webkit.Orientation` → `gtk.Orientation` | |||
| 17 | - | - ✅ Added `gtk/v4` imports to workspace files | |||
| 18 | - | ||||
| 19 | - | ### 3. Workspace Utility Functions (workspace_utils.go) | |||
| 20 | - | - ✅ `initializePaneWidgets()`: Now accepts `gtk.Widgetter` instead of `uintptr` | |||
| 21 | - | - ✅ `setContainer()`: Updated to work with `gtk.Widgetter` | |||
| 22 | - | - ✅ `setTitleBar()`: Updated to work with `gtk.Widgetter` | |||
| 23 | - | - ✅ `setStackWrapper()`: Updated to work with `gtk.Widgetter` | |||
| 24 | - | - ✅ `mapDirection()`: Returns `gtk.Orientation` instead of `webkit.Orientation` | |||
| 25 | - | ||||
| 26 | - | ## 🚧 In Progress / TODO | |||
| 27 | - | ||||
| 28 | - | ### Files Needing Updates (by priority) | |||
| 29 | - | ||||
| 30 | - | #### Priority 1: Core Workspace Operations | |||
| 31 | - | 1. **workspace_manager.go** (69 lines) | |||
| 32 | - | - Update `pendingIdle` map type | |||
| 33 | - | - Update widget comparisons (`== 0` → `== nil`) | |||
| 34 | - | - Update `Window.SetChild()` calls | |||
| 35 | - | ||||
| 36 | - | 2. **stacked_panes.go** (23 files total) | |||
| 37 | - | - Update all `webkit.NewBox()` → `gtk.NewBox()` | |||
| 38 | - | - Update all `webkit.BoxAppend()` → `box.Append()` | |||
| 39 | - | - Update all `webkit.PanedSetStartChild()` → `paned.SetStartChild()` | |||
| 40 | - | - Update widget null checks (`ptr != 0` → `widget != nil`) | |||
| 41 | - | - Update `titleBarToPane map[uintptr]*paneNode` → `map[uint64]*paneNode` or alternative | |||
| 42 | - | ||||
| 43 | - | 3. **workspace_pane_ops.go** | |||
| 44 | - | - Update `SplitPane()` function | |||
| 45 | - | - Update `webkit.NewPaned()` calls | |||
| 46 | - | - Update paned child setting operations | |||
| 47 | - | - Update widget show/hide calls | |||
| 48 | - | ||||
| 49 | - | #### Priority 2: Navigation and Focus | |||
| 50 | - | 4. **workspace_navigation.go** | |||
| 51 | - | - Update hover handlers | |||
| 52 | - | - Update widget geometry functions | |||
| 53 | - | ||||
| 54 | - | 5. **focus_state_machine.go** | |||
| 55 | - | - Update GTK event controller attachments | |||
| 56 | - | ||||
| 57 | - | #### Priority 3: Supporting Files | |||
| 58 | - | 6. **workspace_utils.go** (remaining) | |||
| 59 | - | - Update `PaneBorderContext` struct | |||
| 60 | - | - Update `determineBorderContext()` function | |||
| 61 | - | - Update all border application code | |||
| 62 | - | ||||
| 63 | - | 7. **workspace_pane_close.go** | |||
| 64 | - | - Update cleanup operations | |||
| 65 | - | - Update widget unparenting | |||
| 66 | - | ||||
| 67 | - | 8. **workspace_idle.go** | |||
| 68 | - | - Update idle callbacks | |||
| 69 | - | ||||
| 70 | - | ### Key Patterns to Update | |||
| 71 | - | ||||
| 72 | - | #### Widget Creation | |||
| 73 | - | ```go | |||
| 74 | - | // Old | |||
| 75 | - | paned := webkit.NewPaned(orientation) | |||
| 76 | - | ||||
| 77 | - | // New | |||
| 78 | - | paned := gtk.NewPaned(orientation) // or webkit.NewPaned(orientation).AsWidget() | |||
| 79 | - | ``` | |||
| 80 | - | ||||
| 81 | - | #### Widget Operations | |||
| 82 | - | ```go | |||
| 83 | - | // Old | |||
| 84 | - | webkit.PanedSetStartChild(paned, child) | |||
| 85 | - | ||||
| 86 | - | // New - Option 1: Type assertion | |||
| 87 | - | if p, ok := paned.(*gtk.Paned); ok { | |||
| 88 | - | p.SetStartChild(child) | |||
| 89 | - | } | |||
| 90 | - | ||||
| 91 | - | // New - Option 2: Store concrete types | |||
| 92 | - | paned := gtk.NewPaned(orientation) // Store as *gtk.Paned | |||
| 93 | - | paned.SetStartChild(child) | |||
| 94 | - | ``` | |||
| 95 | - | ||||
| 96 | - | #### Null Checks | |||
| 97 | - | ```go | |||
| 98 | - | // Old | |||
| 99 | - | if container == 0 { } | |||
| 100 | - | if webkit.WidgetIsValid(container) { } | |||
| 101 | - | ||||
| 102 | - | // New | |||
| 103 | - | if container == nil { } | |||
| 104 | - | if container != nil { } | |||
| 105 | - | ``` | |||
| 106 | - | ||||
| 107 | - | #### Widget Comparisons | |||
| 108 | - | ```go | |||
| 109 | - | // Old | |||
| 110 | - | node.container = 0 | |||
| 111 | - | parent := webkit.WidgetGetParent(widget) | |||
| 112 | - | if parent != 0 { } | |||
| 113 | - | ||||
| 114 | - | // New | |||
| 115 | - | node.container = nil | |||
| 116 | - | parent := widget.Parent() | |||
| 117 | - | if parent != nil { } | |||
| 118 | - | ``` | |||
| 119 | - | ||||
| 120 | - | #### Maps with Widget Keys | |||
| 121 | - | ```go | |||
| 122 | - | // Old | |||
| 123 | - | pendingIdle map[uintptr][]*paneNode | |||
| 124 | - | ||||
| 125 | - | // New - Option 1: Use interface{} | |||
| 126 | - | pendingIdle map[interface{}][]*paneNode | |||
| 127 | - | ||||
| 128 | - | // New - Option 2: Use string keys (widget pointer address) | |||
| 129 | - | pendingIdle map[string][]*paneNode | |||
| 130 | - | ||||
| 131 | - | // New - Option 3: Use generic comparable constraint | |||
| 132 | - | ``` | |||
| 133 | - | ||||
| 134 | - | ## Migration Strategy | |||
| 135 | - | ||||
| 136 | - | ### Approach | |||
| 137 | - | We're doing a **clean break** from the old CGO code, NOT maintaining compatibility. | |||
| 138 | - | ||||
| 139 | - | ### Process | |||
| 140 | - | 1. ✅ Update type definitions first | |||
| 141 | - | 2. ✅ Update utility functions | |||
| 142 | - | 3. 🚧 Update each file incrementally | |||
| 143 | - | 4. ⏳ Fix compilation errors as we go | |||
| 144 | - | 5. ⏳ Test each subsystem | |||
| 145 | - | ||||
| 146 | - | ### Files Can Be Updated in Parallel | |||
| 147 | - | Since we're breaking compatibility anyway, we can update files one at a time and fix compilation errors iteratively. The codebase doesn't need to compile at every step. | |||
| 148 | - | ||||
| 149 | - | ## Remaining Work Estimate | |||
| 150 | - | ||||
| 151 | - | - **stacked_panes.go**: ~100 locations need updating (2-3 hours) | |||
| 152 | - | - **workspace_pane_ops.go**: ~50 locations (1-2 hours) | |||
| 153 | - | - **workspace_utils.go**: ~30 locations (1 hour) | |||
| 154 | - | - **workspace_manager.go**: ~20 locations (1 hour) | |||
| 155 | - | - **workspace_navigation.go**: ~15 locations (1 hour) | |||
| 156 | - | - **Other files**: ~50 locations combined (2 hours) | |||
| 157 | - | ||||
| 158 | - | **Total estimate**: 8-11 hours of focused work | |||
| 159 | - | ||||
| 160 | - | ## Benefits Already Achieved | |||
| 161 | - | ||||
| 162 | - | ✅ Type safety - compile-time checking instead of runtime crashes | |||
| 163 | - | ✅ Cleaner code - no more uintptr casting | |||
| 164 | - | ✅ Better IDE support - autocomplete and refactoring work | |||
| 165 | - | ✅ Automatic memory management - no manual ref counting | |||
| 166 | - | ✅ Easier debugging - stack traces show actual types | |||
| 167 | - | ✅ Future-proof - auto-generated bindings stay up to date | |||
| 168 | - | ||||
| 169 | - | ## Next Steps | |||
| 170 | - | ||||
| 171 | - | 1. Update `stacked_panes.go` - most widget operations are here | |||
| 172 | - | 2. Update `workspace_pane_ops.go` - split/close operations | |||
| 173 | - | 3. Update remaining workspace files | |||
| 174 | - | 4. Fix all compilation errors | |||
| 175 | - | 5. Test browser functionality | |||
| 176 | - | 6. Update any missing webkit package functions as needed | |||
| 177 | - | ||||
| 178 | - | --- | |||
| 179 | - | ||||
| 180 | - | **Current Status**: Core types updated, utility functions migrated ✅ | |||
| 181 | - | **Next**: Update stacked_panes.go widget operations 🚧 | |||
D docs/webkit-migration-status.md +0 -298
| @@ -1,298 +0,0 @@ | |||
| 1 | - | # WebKit Package Migration Status | |
| 2 | - | ||
| 3 | - | ## ✅ Completed: New gotk4-based webkit Package | |
| 4 | - | ||
| 5 | - | ### What Was Done | |
| 6 | - | ||
| 7 | - | We completely replaced the old CGO-based `pkg/webkit` package with a clean, gotk4-based implementation. | |
| 8 | - | ||
| 9 | - | ### New Package Structure | |
| 10 | - | ||
| 11 | - | ``` | |
| 12 | - | pkg/webkit/ | |
| 13 | - | ├── errors.go # Error definitions | |
| 14 | - | ├── types.go # WindowType, WindowFeatures, Config | |
| 15 | - | ├── mainloop.go # GTK main loop management | |
| 16 | - | ├── window.go # Window wrapper (gtk.Window) | |
| 17 | - | ├── widgets.go # Widget helpers (Paned, Box, Label, Image) | |
| 18 | - | └── webview.go # WebView wrapper (webkit/v6) | |
| 19 | - | ``` | |
| 20 | - | ||
| 21 | - | ### Key Improvements | |
| 22 | - | ||
| 23 | - | #### 1. Correct gotk4-webkitgtk Import | |
| 24 | - | ```go | |
| 25 | - | // Correct import path for WebKitGTK 6.0 with GTK4: | |
| 26 | - | import webkit "github.com/diamondburned/gotk4-webkitgtk/pkg/webkit/v6" | |
| 27 | - | ||
| 28 | - | // NOT webkit2/v6 (that doesn't exist!) | |
| 29 | - | ``` | |
| 30 | - | ||
| 31 | - | #### 2. Type-Safe API | |
| 32 | - | ```go | |
| 33 | - | // Old (CGO): uintptr-based | |
| 34 | - | widget := view.Widget() // returns uintptr | |
| 35 | - | window.SetChild(widget) // takes uintptr | |
| 36 | - | ||
| 37 | - | // New (gotk4): Type-safe | |
| 38 | - | widget := view.AsWidget() // returns gtk.Widgetter | |
| 39 | - | window.SetChild(widget) // takes gtk.Widgetter | |
| 40 | - | ``` | |
| 41 | - | ||
| 42 | - | #### 3. Simplified Event Handling | |
| 43 | - | ```go | |
| 44 | - | // Old (CGO): Export functions + C bridge | |
| 45 | - | //export goOnTitleChanged | |
| 46 | - | func goOnTitleChanged(id C.ulong, ctitle *C.char) { ... } | |
| 47 | - | ||
| 48 | - | // New (gotk4): Direct Go closures | |
| 49 | - | view.RegisterTitleChangedHandler(func(title string) { | |
| 50 | - | // Handle title change | |
| 51 | - | }) | |
| 52 | - | ``` | |
| 53 | - | ||
| 54 | - | #### 4. Automatic Memory Management | |
| 55 | - | ```go | |
| 56 | - | // Old (CGO): Manual reference counting | |
| 57 | - | C.g_object_ref(widget) | |
| 58 | - | defer C.g_object_unref(widget) | |
| 59 | - | ||
| 60 | - | // New (gotk4): Automatic (Go GC) | |
| 61 | - | widget := gtk.NewLabel("text") | |
| 62 | - | // That's it! No manual cleanup needed | |
| 63 | - | ``` | |
| 64 | - | ||
| 65 | - | ### Code Reduction | |
| 66 | - | ||
| 67 | - | - **Before**: ~5000 lines of manual CGO bindings | |
| 68 | - | - **After**: ~500 lines of clean Go code | |
| 69 | - | - **Reduction**: 90%! | |
| 70 | - | ||
| 71 | - | ### API Overview | |
| 72 | - | ||
| 73 | - | #### WebView | |
| 74 | - | ```go | |
| 75 | - | type WebView struct { | |
| 76 | - | view *webkit.WebView | |
| 77 | - | id uint64 | |
| 78 | - | // Event handlers as function fields | |
| 79 | - | } | |
| 80 | - | ||
| 81 | - | // Core methods | |
| 82 | - | func NewWebView(cfg *Config) (*WebView, error) | |
| 83 | - | func (w *WebView) LoadURL(url string) error | |
| 84 | - | func (w *WebView) GetCurrentURL() string | |
| 85 | - | func (w *WebView) GoBack() error | |
| 86 | - | func (w *WebView) AsWidget() gtk.Widgetter | |
| 87 | - | ||
| 88 | - | // Event registration | |
| 89 | - | func (w *WebView) RegisterTitleChangedHandler(func(string)) | |
| 90 | - | func (w *WebView) RegisterURIChangedHandler(func(string)) | |
| 91 | - | func (w *WebView) RegisterPopupHandler(func(string) *WebView) | |
| 92 | - | // ... etc | |
| 93 | - | ``` | |
| 94 | - | ||
| 95 | - | #### Window | |
| 96 | - | ```go | |
| 97 | - | type Window struct { | |
| 98 | - | win *gtk.Window | |
| 99 | - | } | |
| 100 | - | ||
| 101 | - | func NewWindow(title string) (*Window, error) | |
| 102 | - | func (w *Window) SetChild(child gtk.Widgetter) | |
| 103 | - | func (w *Window) Show() | |
| 104 | - | func (w *Window) Present() | |
| 105 | - | ``` | |
| 106 | - | ||
| 107 | - | #### Widgets | |
| 108 | - | ```go | |
| 109 | - | // Paned (split container) | |
| 110 | - | type Paned struct { paned *gtk.Paned } | |
| 111 | - | func NewPaned(orientation gtk.Orientation) *Paned | |
| 112 | - | func (p *Paned) SetStartChild(child gtk.Widgetter) | |
| 113 | - | func (p *Paned) AsWidget() gtk.Widgetter | |
| 114 | - | ||
| 115 | - | // Box (linear layout) | |
| 116 | - | type Box struct { box *gtk.Box } | |
| 117 | - | func NewBox(orientation gtk.Orientation, spacing int) *Box | |
| 118 | - | func (b *Box) Append(child gtk.Widgetter) | |
| 119 | - | ||
| 120 | - | // Label, Image (similar pattern) | |
| 121 | - | ``` | |
| 122 | - | ||
| 123 | - | ### Dependencies Added | |
| 124 | - | ||
| 125 | - | ```go | |
| 126 | - | require ( | |
| 127 | - | github.com/diamondburned/gotk4/pkg v0.3.1 | |
| 128 | - | github.com/diamondburned/gotk4-webkitgtk/pkg v0.0.0-20240108031600-dee1973cf440 | |
| 129 | - | ) | |
| 130 | - | ``` | |
| 131 | - | ||
| 132 | - | ## 🚧 Next Steps | |
| 133 | - | ||
| 134 | - | ### 1. Update internal/app Callers | |
| 135 | - | ||
| 136 | - | The `internal/app/browser` package needs to be updated to use the new API. Key changes: | |
| 137 | - | ||
| 138 | - | #### Widget Pointer Migration | |
| 139 | - | ```go | |
| 140 | - | // Old: uintptr-based | |
| 141 | - | var container uintptr | |
| 142 | - | container = webkit.NewPaned(webkit.OrientationHorizontal) | |
| 143 | - | webkit.PanedSetStartChild(container, childWidget) | |
| 144 | - | ||
| 145 | - | // New: Type-safe | |
| 146 | - | paned := webkit.NewPaned(gtk.OrientationHorizontal) | |
| 147 | - | paned.SetStartChild(childWidget) | |
| 148 | - | ``` | |
| 149 | - | ||
| 150 | - | #### WebView Creation | |
| 151 | - | ```go | |
| 152 | - | // Old | |
| 153 | - | view := webkit.NewWebView(cfg) | |
| 154 | - | widget := view.Widget() | |
| 155 | - | ||
| 156 | - | // New | |
| 157 | - | view := webkit.NewWebView(cfg) | |
| 158 | - | widget := view.AsWidget() | |
| 159 | - | ``` | |
| 160 | - | ||
| 161 | - | #### Window Child Setting | |
| 162 | - | ```go | |
| 163 | - | // Old | |
| 164 | - | window.SetChild(widget) // widget is uintptr | |
| 165 | - | ||
| 166 | - | // New | |
| 167 | - | window.SetChild(widget) // widget is gtk.Widgetter | |
| 168 | - | ``` | |
| 169 | - | ||
| 170 | - | ### 2. Files to Update | |
| 171 | - | ||
| 172 | - | Based on grep analysis, these files use webkit package: | |
| 173 | - | ||
| 174 | - | - `internal/app/browser/workspace_manager.go` | |
| 175 | - | - `internal/app/browser/workspace_pane_ops.go` | |
| 176 | - | - `internal/app/browser/stacked_panes.go` | |
| 177 | - | - `internal/app/browser/browser.go` | |
| 178 | - | - `internal/app/browser/webview.go` | |
| 179 | - | - `internal/app/browser/pane.go` | |
| 180 | - | - `internal/app/browser/shortcuts.go` | |
| 181 | - | - `internal/app/browser/window_shortcuts.go` | |
| 182 | - | - `internal/app/messaging/handler.go` | |
| 183 | - | - `internal/app/control/*.go` | |
| 184 | - | - ~23 files total | |
| 185 | - | ||
| 186 | - | ### 3. Migration Strategy | |
| 187 | - | ||
| 188 | - | #### Phase 1: Update Type Declarations | |
| 189 | - | - Change all `uintptr` widget fields to proper types | |
| 190 | - | - Update struct definitions in workspace manager | |
| 191 | - | ||
| 192 | - | #### Phase 2: Update Widget Operations | |
| 193 | - | - Replace function calls with method calls | |
| 194 | - | - Convert widget creation/manipulation | |
| 195 | - | ||
| 196 | - | #### Phase 3: Update Event Handlers | |
| 197 | - | - Migrate callback registrations | |
| 198 | - | - Remove any CGO export functions | |
| 199 | - | ||
| 200 | - | #### Phase 4: Testing | |
| 201 | - | - Compile and test each subsystem | |
| 202 | - | - Verify all functionality works | |
| 203 | - | - Run integration tests | |
| 204 | - | ||
| 205 | - | ### 4. Breaking Changes to Handle | |
| 206 | - | ||
| 207 | - | #### Widget Handles | |
| 208 | - | Most code uses `uintptr` for widget handles. These need to become proper types: | |
| 209 | - | ||
| 210 | - | ```go | |
| 211 | - | // Old | |
| 212 | - | type BrowserPane struct { | |
| 213 | - | container uintptr | |
| 214 | - | webView *webkit.WebView | |
| 215 | - | } | |
| 216 | - | ||
| 217 | - | // New | |
| 218 | - | type BrowserPane struct { | |
| 219 | - | container *webkit.Paned // or *webkit.Box, depending on type | |
| 220 | - | webView *webkit.WebView | |
| 221 | - | } | |
| 222 | - | ``` | |
| 223 | - | ||
| 224 | - | #### Widget Storage | |
| 225 | - | The workspace manager stores widgets as `uintptr`. Options: | |
| 226 | - | ||
| 227 | - | 1. **Convert to interface{}**: Store as `interface{}` and type assert | |
| 228 | - | 2. **Convert to gtk.Widgetter**: Store the common interface | |
| 229 | - | 3. **Keep concrete types**: Store specific types (*Paned, *Box, etc.) | |
| 230 | - | ||
| 231 | - | **Recommendation**: Use `gtk.Widgetter` interface for flexibility. | |
| 232 | - | ||
| 233 | - | ## Expected Benefits | |
| 234 | - | ||
| 235 | - | ### Performance | |
| 236 | - | - ✅ Same or better runtime performance | |
| 237 | - | - ✅ Faster compilation (less CGO overhead) | |
| 238 | - | - ✅ Better memory management (GC integrated) | |
| 239 | - | ||
| 240 | - | ### Code Quality | |
| 241 | - | - ✅ 90% code reduction | |
| 242 | - | - ✅ Compile-time type safety | |
| 243 | - | - ✅ Better IDE support (autocomplete, refactoring) | |
| 244 | - | - ✅ Standard Go patterns | |
| 245 | - | ||
| 246 | - | ### Maintainability | |
| 247 | - | - ✅ Auto-generated bindings (easy to update) | |
| 248 | - | - ✅ Less bug surface area | |
| 249 | - | - ✅ Clear ownership semantics | |
| 250 | - | - ✅ Better error messages | |
| 251 | - | ||
| 252 | - | ## Challenges to Address | |
| 253 | - | ||
| 254 | - | ### 1. Widget Type Conversions | |
| 255 | - | Need to handle different widget types properly: | |
| 256 | - | - Paned (split containers) | |
| 257 | - | - Box (linear layouts) | |
| 258 | - | - Labels, Images | |
| 259 | - | - WebViews | |
| 260 | - | ||
| 261 | - | ### 2. Workspace Manager Complexity | |
| 262 | - | The workspace manager heavily uses uintptr for widget management. This needs careful refactoring. | |
| 263 | - | ||
| 264 | - | ### 3. Legacy Code Patterns | |
| 265 | - | Some patterns from CGO days need to be unlearned: | |
| 266 | - | - No more manual ref counting | |
| 267 | - | - No more unsafe.Pointer casts | |
| 268 | - | - Trust the type system! | |
| 269 | - | ||
| 270 | - | ## Resources | |
| 271 | - | ||
| 272 | - | - [gotk4 Documentation](https://pkg.go.dev/github.com/diamondburned/gotk4/pkg) | |
| 273 | - | - [gotk4-webkitgtk Documentation](https://pkg.go.dev/github.com/diamondburned/gotk4-webkitgtk/pkg) | |
| 274 | - | - [Migration Plan](./gotk4-migration-plan.md) | |
| 275 | - | - [Package Design](./new-webkit-package-design.md) | |
| 276 | - | ||
| 277 | - | ## Timeline Estimate | |
| 278 | - | ||
| 279 | - | - **Phase 1** (Type declarations): 1-2 days | |
| 280 | - | - **Phase 2** (Widget operations): 3-5 days | |
| 281 | - | - **Phase 3** (Event handlers): 2-3 days | |
| 282 | - | - **Phase 4** (Testing): 2-3 days | |
| 283 | - | - **Total**: ~8-13 days | |
| 284 | - | ||
| 285 | - | ## Success Criteria | |
| 286 | - | ||
| 287 | - | - ✅ All files in `internal/app` compile | |
| 288 | - | - ✅ Browser starts successfully | |
| 289 | - | - ✅ WebView loads pages | |
| 290 | - | - ✅ Multi-pane workspace works | |
| 291 | - | - ✅ All keyboard shortcuts functional | |
| 292 | - | - ✅ No memory leaks | |
| 293 | - | - ✅ Startup time < 500ms maintained | |
| 294 | - | ||
| 295 | - | --- | |
| 296 | - | ||
| 297 | - | **Status**: New webkit package complete ✅ | |
| 298 | - | **Next**: Update internal/app callers 🚧 | |
| @@ -1,298 +0,0 @@ | |||||
| 1 | - | # WebKit Package Migration Status | |||
| 2 | - | ||||
| 3 | - | ## ✅ Completed: New gotk4-based webkit Package | |||
| 4 | - | ||||
| 5 | - | ### What Was Done | |||
| 6 | - | ||||
| 7 | - | We completely replaced the old CGO-based `pkg/webkit` package with a clean, gotk4-based implementation. | |||
| 8 | - | ||||
| 9 | - | ### New Package Structure | |||
| 10 | - | ||||
| 11 | - | ``` | |||
| 12 | - | pkg/webkit/ | |||
| 13 | - | ├── errors.go # Error definitions | |||
| 14 | - | ├── types.go # WindowType, WindowFeatures, Config | |||
| 15 | - | ├── mainloop.go # GTK main loop management | |||
| 16 | - | ├── window.go # Window wrapper (gtk.Window) | |||
| 17 | - | ├── widgets.go # Widget helpers (Paned, Box, Label, Image) | |||
| 18 | - | └── webview.go # WebView wrapper (webkit/v6) | |||
| 19 | - | ``` | |||
| 20 | - | ||||
| 21 | - | ### Key Improvements | |||
| 22 | - | ||||
| 23 | - | #### 1. Correct gotk4-webkitgtk Import | |||
| 24 | - | ```go | |||
| 25 | - | // Correct import path for WebKitGTK 6.0 with GTK4: | |||
| 26 | - | import webkit "github.com/diamondburned/gotk4-webkitgtk/pkg/webkit/v6" | |||
| 27 | - | ||||
| 28 | - | // NOT webkit2/v6 (that doesn't exist!) | |||
| 29 | - | ``` | |||
| 30 | - | ||||
| 31 | - | #### 2. Type-Safe API | |||
| 32 | - | ```go | |||
| 33 | - | // Old (CGO): uintptr-based | |||
| 34 | - | widget := view.Widget() // returns uintptr | |||
| 35 | - | window.SetChild(widget) // takes uintptr | |||
| 36 | - | ||||
| 37 | - | // New (gotk4): Type-safe | |||
| 38 | - | widget := view.AsWidget() // returns gtk.Widgetter | |||
| 39 | - | window.SetChild(widget) // takes gtk.Widgetter | |||
| 40 | - | ``` | |||
| 41 | - | ||||
| 42 | - | #### 3. Simplified Event Handling | |||
| 43 | - | ```go | |||
| 44 | - | // Old (CGO): Export functions + C bridge | |||
| 45 | - | //export goOnTitleChanged | |||
| 46 | - | func goOnTitleChanged(id C.ulong, ctitle *C.char) { ... } | |||
| 47 | - | ||||
| 48 | - | // New (gotk4): Direct Go closures | |||
| 49 | - | view.RegisterTitleChangedHandler(func(title string) { | |||
| 50 | - | // Handle title change | |||
| 51 | - | }) | |||
| 52 | - | ``` | |||
| 53 | - | ||||
| 54 | - | #### 4. Automatic Memory Management | |||
| 55 | - | ```go | |||
| 56 | - | // Old (CGO): Manual reference counting | |||
| 57 | - | C.g_object_ref(widget) | |||
| 58 | - | defer C.g_object_unref(widget) | |||
| 59 | - | ||||
| 60 | - | // New (gotk4): Automatic (Go GC) | |||
| 61 | - | widget := gtk.NewLabel("text") | |||
| 62 | - | // That's it! No manual cleanup needed | |||
| 63 | - | ``` | |||
| 64 | - | ||||
| 65 | - | ### Code Reduction | |||
| 66 | - | ||||
| 67 | - | - **Before**: ~5000 lines of manual CGO bindings | |||
| 68 | - | - **After**: ~500 lines of clean Go code | |||
| 69 | - | - **Reduction**: 90%! | |||
| 70 | - | ||||
| 71 | - | ### API Overview | |||
| 72 | - | ||||
| 73 | - | #### WebView | |||
| 74 | - | ```go | |||
| 75 | - | type WebView struct { | |||
| 76 | - | view *webkit.WebView | |||
| 77 | - | id uint64 | |||
| 78 | - | // Event handlers as function fields | |||
| 79 | - | } | |||
| 80 | - | ||||
| 81 | - | // Core methods | |||
| 82 | - | func NewWebView(cfg *Config) (*WebView, error) | |||
| 83 | - | func (w *WebView) LoadURL(url string) error | |||
| 84 | - | func (w *WebView) GetCurrentURL() string | |||
| 85 | - | func (w *WebView) GoBack() error | |||
| 86 | - | func (w *WebView) AsWidget() gtk.Widgetter | |||
| 87 | - | ||||
| 88 | - | // Event registration | |||
| 89 | - | func (w *WebView) RegisterTitleChangedHandler(func(string)) | |||
| 90 | - | func (w *WebView) RegisterURIChangedHandler(func(string)) | |||
| 91 | - | func (w *WebView) RegisterPopupHandler(func(string) *WebView) | |||
| 92 | - | // ... etc | |||
| 93 | - | ``` | |||
| 94 | - | ||||
| 95 | - | #### Window | |||
| 96 | - | ```go | |||
| 97 | - | type Window struct { | |||
| 98 | - | win *gtk.Window | |||
| 99 | - | } | |||
| 100 | - | ||||
| 101 | - | func NewWindow(title string) (*Window, error) | |||
| 102 | - | func (w *Window) SetChild(child gtk.Widgetter) | |||
| 103 | - | func (w *Window) Show() | |||
| 104 | - | func (w *Window) Present() | |||
| 105 | - | ``` | |||
| 106 | - | ||||
| 107 | - | #### Widgets | |||
| 108 | - | ```go | |||
| 109 | - | // Paned (split container) | |||
| 110 | - | type Paned struct { paned *gtk.Paned } | |||
| 111 | - | func NewPaned(orientation gtk.Orientation) *Paned | |||
| 112 | - | func (p *Paned) SetStartChild(child gtk.Widgetter) | |||
| 113 | - | func (p *Paned) AsWidget() gtk.Widgetter | |||
| 114 | - | ||||
| 115 | - | // Box (linear layout) | |||
| 116 | - | type Box struct { box *gtk.Box } | |||
| 117 | - | func NewBox(orientation gtk.Orientation, spacing int) *Box | |||
| 118 | - | func (b *Box) Append(child gtk.Widgetter) | |||
| 119 | - | ||||
| 120 | - | // Label, Image (similar pattern) | |||
| 121 | - | ``` | |||
| 122 | - | ||||
| 123 | - | ### Dependencies Added | |||
| 124 | - | ||||
| 125 | - | ```go | |||
| 126 | - | require ( | |||
| 127 | - | github.com/diamondburned/gotk4/pkg v0.3.1 | |||
| 128 | - | github.com/diamondburned/gotk4-webkitgtk/pkg v0.0.0-20240108031600-dee1973cf440 | |||
| 129 | - | ) | |||
| 130 | - | ``` | |||
| 131 | - | ||||
| 132 | - | ## 🚧 Next Steps | |||
| 133 | - | ||||
| 134 | - | ### 1. Update internal/app Callers | |||
| 135 | - | ||||
| 136 | - | The `internal/app/browser` package needs to be updated to use the new API. Key changes: | |||
| 137 | - | ||||
| 138 | - | #### Widget Pointer Migration | |||
| 139 | - | ```go | |||
| 140 | - | // Old: uintptr-based | |||
| 141 | - | var container uintptr | |||
| 142 | - | container = webkit.NewPaned(webkit.OrientationHorizontal) | |||
| 143 | - | webkit.PanedSetStartChild(container, childWidget) | |||
| 144 | - | ||||
| 145 | - | // New: Type-safe | |||
| 146 | - | paned := webkit.NewPaned(gtk.OrientationHorizontal) | |||
| 147 | - | paned.SetStartChild(childWidget) | |||
| 148 | - | ``` | |||
| 149 | - | ||||
| 150 | - | #### WebView Creation | |||
| 151 | - | ```go | |||
| 152 | - | // Old | |||
| 153 | - | view := webkit.NewWebView(cfg) | |||
| 154 | - | widget := view.Widget() | |||
| 155 | - | ||||
| 156 | - | // New | |||
| 157 | - | view := webkit.NewWebView(cfg) | |||
| 158 | - | widget := view.AsWidget() | |||
| 159 | - | ``` | |||
| 160 | - | ||||
| 161 | - | #### Window Child Setting | |||
| 162 | - | ```go | |||
| 163 | - | // Old | |||
| 164 | - | window.SetChild(widget) // widget is uintptr | |||
| 165 | - | ||||
| 166 | - | // New | |||
| 167 | - | window.SetChild(widget) // widget is gtk.Widgetter | |||
| 168 | - | ``` | |||
| 169 | - | ||||
| 170 | - | ### 2. Files to Update | |||
| 171 | - | ||||
| 172 | - | Based on grep analysis, these files use webkit package: | |||
| 173 | - | ||||
| 174 | - | - `internal/app/browser/workspace_manager.go` | |||
| 175 | - | - `internal/app/browser/workspace_pane_ops.go` | |||
| 176 | - | - `internal/app/browser/stacked_panes.go` | |||
| 177 | - | - `internal/app/browser/browser.go` | |||
| 178 | - | - `internal/app/browser/webview.go` | |||
| 179 | - | - `internal/app/browser/pane.go` | |||
| 180 | - | - `internal/app/browser/shortcuts.go` | |||
| 181 | - | - `internal/app/browser/window_shortcuts.go` | |||
| 182 | - | - `internal/app/messaging/handler.go` | |||
| 183 | - | - `internal/app/control/*.go` | |||
| 184 | - | - ~23 files total | |||
| 185 | - | ||||
| 186 | - | ### 3. Migration Strategy | |||
| 187 | - | ||||
| 188 | - | #### Phase 1: Update Type Declarations | |||
| 189 | - | - Change all `uintptr` widget fields to proper types | |||
| 190 | - | - Update struct definitions in workspace manager | |||
| 191 | - | ||||
| 192 | - | #### Phase 2: Update Widget Operations | |||
| 193 | - | - Replace function calls with method calls | |||
| 194 | - | - Convert widget creation/manipulation | |||
| 195 | - | ||||
| 196 | - | #### Phase 3: Update Event Handlers | |||
| 197 | - | - Migrate callback registrations | |||
| 198 | - | - Remove any CGO export functions | |||
| 199 | - | ||||
| 200 | - | #### Phase 4: Testing | |||
| 201 | - | - Compile and test each subsystem | |||
| 202 | - | - Verify all functionality works | |||
| 203 | - | - Run integration tests | |||
| 204 | - | ||||
| 205 | - | ### 4. Breaking Changes to Handle | |||
| 206 | - | ||||
| 207 | - | #### Widget Handles | |||
| 208 | - | Most code uses `uintptr` for widget handles. These need to become proper types: | |||
| 209 | - | ||||
| 210 | - | ```go | |||
| 211 | - | // Old | |||
| 212 | - | type BrowserPane struct { | |||
| 213 | - | container uintptr | |||
| 214 | - | webView *webkit.WebView | |||
| 215 | - | } | |||
| 216 | - | ||||
| 217 | - | // New | |||
| 218 | - | type BrowserPane struct { | |||
| 219 | - | container *webkit.Paned // or *webkit.Box, depending on type | |||
| 220 | - | webView *webkit.WebView | |||
| 221 | - | } | |||
| 222 | - | ``` | |||
| 223 | - | ||||
| 224 | - | #### Widget Storage | |||
| 225 | - | The workspace manager stores widgets as `uintptr`. Options: | |||
| 226 | - | ||||
| 227 | - | 1. **Convert to interface{}**: Store as `interface{}` and type assert | |||
| 228 | - | 2. **Convert to gtk.Widgetter**: Store the common interface | |||
| 229 | - | 3. **Keep concrete types**: Store specific types (*Paned, *Box, etc.) | |||
| 230 | - | ||||
| 231 | - | **Recommendation**: Use `gtk.Widgetter` interface for flexibility. | |||
| 232 | - | ||||
| 233 | - | ## Expected Benefits | |||
| 234 | - | ||||
| 235 | - | ### Performance | |||
| 236 | - | - ✅ Same or better runtime performance | |||
| 237 | - | - ✅ Faster compilation (less CGO overhead) | |||
| 238 | - | - ✅ Better memory management (GC integrated) | |||
| 239 | - | ||||
| 240 | - | ### Code Quality | |||
| 241 | - | - ✅ 90% code reduction | |||
| 242 | - | - ✅ Compile-time type safety | |||
| 243 | - | - ✅ Better IDE support (autocomplete, refactoring) | |||
| 244 | - | - ✅ Standard Go patterns | |||
| 245 | - | ||||
| 246 | - | ### Maintainability | |||
| 247 | - | - ✅ Auto-generated bindings (easy to update) | |||
| 248 | - | - ✅ Less bug surface area | |||
| 249 | - | - ✅ Clear ownership semantics | |||
| 250 | - | - ✅ Better error messages | |||
| 251 | - | ||||
| 252 | - | ## Challenges to Address | |||
| 253 | - | ||||
| 254 | - | ### 1. Widget Type Conversions | |||
| 255 | - | Need to handle different widget types properly: | |||
| 256 | - | - Paned (split containers) | |||
| 257 | - | - Box (linear layouts) | |||
| 258 | - | - Labels, Images | |||
| 259 | - | - WebViews | |||
| 260 | - | ||||
| 261 | - | ### 2. Workspace Manager Complexity | |||
| 262 | - | The workspace manager heavily uses uintptr for widget management. This needs careful refactoring. | |||
| 263 | - | ||||
| 264 | - | ### 3. Legacy Code Patterns | |||
| 265 | - | Some patterns from CGO days need to be unlearned: | |||
| 266 | - | - No more manual ref counting | |||
| 267 | - | - No more unsafe.Pointer casts | |||
| 268 | - | - Trust the type system! | |||
| 269 | - | ||||
| 270 | - | ## Resources | |||
| 271 | - | ||||
| 272 | - | - [gotk4 Documentation](https://pkg.go.dev/github.com/diamondburned/gotk4/pkg) | |||
| 273 | - | - [gotk4-webkitgtk Documentation](https://pkg.go.dev/github.com/diamondburned/gotk4-webkitgtk/pkg) | |||
| 274 | - | - [Migration Plan](./gotk4-migration-plan.md) | |||
| 275 | - | - [Package Design](./new-webkit-package-design.md) | |||
| 276 | - | ||||
| 277 | - | ## Timeline Estimate | |||
| 278 | - | ||||
| 279 | - | - **Phase 1** (Type declarations): 1-2 days | |||
| 280 | - | - **Phase 2** (Widget operations): 3-5 days | |||
| 281 | - | - **Phase 3** (Event handlers): 2-3 days | |||
| 282 | - | - **Phase 4** (Testing): 2-3 days | |||
| 283 | - | - **Total**: ~8-13 days | |||
| 284 | - | ||||
| 285 | - | ## Success Criteria | |||
| 286 | - | ||||
| 287 | - | - ✅ All files in `internal/app` compile | |||
| 288 | - | - ✅ Browser starts successfully | |||
| 289 | - | - ✅ WebView loads pages | |||
| 290 | - | - ✅ Multi-pane workspace works | |||
| 291 | - | - ✅ All keyboard shortcuts functional | |||
| 292 | - | - ✅ No memory leaks | |||
| 293 | - | - ✅ Startup time < 500ms maintained | |||
| 294 | - | ||||
| 295 | - | --- | |||
| 296 | - | ||||
| 297 | - | **Status**: New webkit package complete ✅ | |||
| 298 | - | **Next**: Update internal/app callers 🚧 | |||
M gui/src/injected/bootstrap.ts +1 -1
| @@ -16,7 +16,7 @@ import type { Suggestion } from "../components/omnibox/types"; | |||
| 16 | 16 | declare global { | |
| 17 | 17 | interface Window { | |
| 18 | 18 | __dumber_gui?: DumberGUI; | |
| 19 | - | __dumber_gui_ready?: boolean; | |
| 19 | + | __dumber_gui_ready?: boo | |
| 20 | 20 | __dumber_gui_ready_for?: Document | null; | |
| 21 | 21 | __dumber_showToast?: ( | |
| 22 | 22 | message: string, | |
| @@ -16,7 +16,7 @@ import type { Suggestion } from "../components/omnibox/types"; | |||||
| 16 | declare global { | 16 | declare global { | ||
| 17 | interface Window { | 17 | interface Window { | ||
| 18 | __dumber_gui?: DumberGUI; | 18 | __dumber_gui?: DumberGUI; | ||
| 19 | - | __dumber_gui_ready?: boolean; | 19 | + | __dumber_gui_ready?: boo |
| 20 | __dumber_gui_ready_for?: Document | null; | 20 | __dumber_gui_ready_for?: Document | null; | ||
| 21 | __dumber_showToast?: ( | 21 | __dumber_showToast?: ( | ||
| 22 | message: string, | 22 | message: string, | ||