refactor(browser): migrate workspace_utils.go to gotk4 API
- commit
- 364f0513024d967251e587307e8c7ddc3c350d48
- author
- bamen · · 2025-10-09 05:39 UTC
- parent
- 99570ca
- signature
- unsigned
1 file · +29 -22
M internal/app/browser/workspace_utils.go +29 -22
| @@ -6,6 +6,7 @@ import ( | |||
| 6 | 6 | "log" | |
| 7 | 7 | ||
| 8 | 8 | "github.com/bnema/dumber/pkg/webkit" | |
| 9 | + | "github.com/diamondburned/gotk4/pkg/glib/v2" | |
| 9 | 10 | "github.com/diamondburned/gotk4/pkg/gtk/v4" | |
| 10 | 11 | ) | |
| 11 | 12 | ||
| @@ -98,10 +99,10 @@ func (wm *WorkspaceManager) setStackWrapper(node *paneNode, widget gtk.Widgetter | |||
| 98 | 99 | ||
| 99 | 100 | // PaneBorderContext holds the context for applying borders to any pane type | |
| 100 | 101 | type PaneBorderContext struct { | |
| 101 | - | webViewWidget uintptr // The WebView's native widget (for margin) | |
| 102 | - | borderContainer uintptr // The container that gets background color | |
| 103 | - | cssClasses []string // Additional CSS classes to apply | |
| 104 | - | paneType string // Description for debugging | |
| 102 | + | webViewWidget gtk.Widgetter // The WebView's native widget (for margin) | |
| 103 | + | borderContainer gtk.Widgetter // The container that gets background color | |
| 104 | + | cssClasses []string // Additional CSS classes to apply | |
| 105 | + | paneType string // Description for debugging | |
| 105 | 106 | } | |
| 106 | 107 | ||
| 107 | 108 | // determineBorderContext analyzes a pane node and determines the correct border context | |
| @@ -155,18 +156,21 @@ func (wm *WorkspaceManager) applyActivePaneBorder(ctx *PaneBorderContext) { | |||
| 155 | 156 | } | |
| 156 | 157 | ||
| 157 | 158 | // Apply margin to WebView widget (creates space for border) | |
| 158 | - | if ctx.webViewWidget != 0 && webkit.WidgetIsValid(ctx.webViewWidget) { | |
| 159 | - | webkit.WidgetSetMargin(ctx.webViewWidget, 2) | |
| 159 | + | if ctx.webViewWidget != nil { | |
| 160 | + | ctx.webViewWidget.SetMarginTop(2) | |
| 161 | + | ctx.webViewWidget.SetMarginBottom(2) | |
| 162 | + | ctx.webViewWidget.SetMarginStart(2) | |
| 163 | + | ctx.webViewWidget.SetMarginEnd(2) | |
| 160 | 164 | } | |
| 161 | 165 | ||
| 162 | 166 | // Apply CSS classes to border container | |
| 163 | - | if ctx.borderContainer != 0 && webkit.WidgetIsValid(ctx.borderContainer) { | |
| 167 | + | if ctx.borderContainer != nil { | |
| 164 | 168 | for _, class := range ctx.cssClasses { | |
| 165 | - | webkit.WidgetAddCSSClass(ctx.borderContainer, class) | |
| 169 | + | ctx.borderContainer.AddCSSClass(class) | |
| 166 | 170 | } | |
| 167 | 171 | } | |
| 168 | 172 | ||
| 169 | - | log.Printf("[workspace] Applied active border: type=%s webView=%#x container=%#x", | |
| 173 | + | log.Printf("[workspace] Applied active border: type=%s webView=%p container=%p", | |
| 170 | 174 | ctx.paneType, ctx.webViewWidget, ctx.borderContainer) | |
| 171 | 175 | } | |
| 172 | 176 | ||
| @@ -182,26 +186,29 @@ func (wm *WorkspaceManager) removeActivePaneBorder(node *paneNode) { | |||
| 182 | 186 | } | |
| 183 | 187 | ||
| 184 | 188 | // Remove margin from WebView widget | |
| 185 | - | if ctx.webViewWidget != 0 && webkit.WidgetIsValid(ctx.webViewWidget) { | |
| 186 | - | webkit.WidgetSetMargin(ctx.webViewWidget, 0) | |
| 189 | + | if ctx.webViewWidget != nil { | |
| 190 | + | ctx.webViewWidget.SetMarginTop(0) | |
| 191 | + | ctx.webViewWidget.SetMarginBottom(0) | |
| 192 | + | ctx.webViewWidget.SetMarginStart(0) | |
| 193 | + | ctx.webViewWidget.SetMarginEnd(0) | |
| 187 | 194 | } | |
| 188 | 195 | ||
| 189 | 196 | // Remove CSS classes from border container | |
| 190 | - | if ctx.borderContainer != 0 && webkit.WidgetIsValid(ctx.borderContainer) { | |
| 197 | + | if ctx.borderContainer != nil { | |
| 191 | 198 | for _, class := range ctx.cssClasses { | |
| 192 | - | webkit.WidgetRemoveCSSClass(ctx.borderContainer, class) | |
| 199 | + | ctx.borderContainer.RemoveCSSClass(class) | |
| 193 | 200 | } | |
| 194 | 201 | } | |
| 195 | 202 | ||
| 196 | - | log.Printf("[workspace] Removed active border: type=%s webView=%#x container=%#x", | |
| 203 | + | log.Printf("[workspace] Removed active border: type=%s webView=%p container=%p", | |
| 197 | 204 | ctx.paneType, ctx.webViewWidget, ctx.borderContainer) | |
| 198 | 205 | } | |
| 199 | 206 | ||
| 200 | 207 | // Widget cleanup utilities | |
| 201 | 208 | ||
| 202 | 209 | // cleanupWidget safely invalidates and cleans up a widget | |
| 203 | - | func (wm *WorkspaceManager) cleanupWidget(ptr uintptr) { | |
| 204 | - | if ptr == 0 { | |
| 210 | + | func (wm *WorkspaceManager) cleanupWidget(widget gtk.Widgetter) { | |
| 211 | + | if widget == nil { | |
| 205 | 212 | return | |
| 206 | 213 | } | |
| 207 | 214 | ||
| @@ -217,7 +224,7 @@ func (wm *WorkspaceManager) scheduleIdleGuarded(fn func() bool, nodes ...*paneNo | |||
| 217 | 224 | } | |
| 218 | 225 | guards := uniquePaneNodes(nodes...) | |
| 219 | 226 | var handle uintptr | |
| 220 | - | handle = webkit.IdleAdd(func() bool { | |
| 227 | + | handle = uintptr(glib.IdleAdd(func() bool { | |
| 221 | 228 | defer wm.releaseIdleHandle(handle) | |
| 222 | 229 | for _, node := range guards { | |
| 223 | 230 | if node == nil { | |
| @@ -228,7 +235,7 @@ func (wm *WorkspaceManager) scheduleIdleGuarded(fn func() bool, nodes ...*paneNo | |||
| 228 | 235 | } | |
| 229 | 236 | } | |
| 230 | 237 | return fn() | |
| 231 | - | }) | |
| 238 | + | })) | |
| 232 | 239 | if handle != 0 { | |
| 233 | 240 | wm.registerIdleHandle(handle, guards...) | |
| 234 | 241 | } | |
| @@ -302,7 +309,7 @@ func (wm *WorkspaceManager) cancelIdleHandle(handle uintptr) { | |||
| 302 | 309 | return | |
| 303 | 310 | } | |
| 304 | 311 | wm.releaseIdleHandle(handle) | |
| 305 | - | webkit.IdleRemove(handle) | |
| 312 | + | glib.SourceRemove(uint(handle)) | |
| 306 | 313 | } | |
| 307 | 314 | ||
| 308 | 315 | func (wm *WorkspaceManager) cancelIdleHandles(node *paneNode) { | |
| @@ -329,7 +336,7 @@ func formatPaneInfo(node *paneNode) string { | |||
| 329 | 336 | ||
| 330 | 337 | var info string | |
| 331 | 338 | if node.isLeaf { | |
| 332 | - | info = fmt.Sprintf("leaf(container=%#x", node.container) | |
| 339 | + | info = fmt.Sprintf("leaf(container=%p", node.container) | |
| 333 | 340 | if node.pane != nil && node.pane.webView != nil { | |
| 334 | 341 | info += fmt.Sprintf(" webview=%s", node.pane.webView.ID()) | |
| 335 | 342 | } | |
| @@ -338,10 +345,10 @@ func formatPaneInfo(node *paneNode) string { | |||
| 338 | 345 | } | |
| 339 | 346 | info += ")" | |
| 340 | 347 | } else if node.isStacked { | |
| 341 | - | info = fmt.Sprintf("stack(panes=%d active=%d container=%#x)", | |
| 348 | + | info = fmt.Sprintf("stack(panes=%d active=%d container=%p)", | |
| 342 | 349 | len(node.stackedPanes), node.activeStackIndex, node.container) | |
| 343 | 350 | } else { | |
| 344 | - | info = fmt.Sprintf("branch(container=%#x orientation=%v)", | |
| 351 | + | info = fmt.Sprintf("branch(container=%p orientation=%v)", | |
| 345 | 352 | node.container, node.orientation) | |
| 346 | 353 | } | |
| 347 | 354 | ||
| @@ -6,6 +6,7 @@ import ( | |||||
| 6 | "log" | 6 | "log" | ||
| 7 | 7 | ||||
| 8 | "github.com/bnema/dumber/pkg/webkit" | 8 | "github.com/bnema/dumber/pkg/webkit" | ||
| 9 | + | "github.com/diamondburned/gotk4/pkg/glib/v2" | |||
| 9 | "github.com/diamondburned/gotk4/pkg/gtk/v4" | 10 | "github.com/diamondburned/gotk4/pkg/gtk/v4" | ||
| 10 | ) | 11 | ) | ||
| 11 | 12 | ||||
| @@ -98,10 +99,10 @@ func (wm *WorkspaceManager) setStackWrapper(node *paneNode, widget gtk.Widgetter | |||||
| 98 | 99 | ||||
| 99 | // PaneBorderContext holds the context for applying borders to any pane type | 100 | // PaneBorderContext holds the context for applying borders to any pane type | ||
| 100 | type PaneBorderContext struct { | 101 | type PaneBorderContext struct { | ||
| 101 | - | webViewWidget uintptr // The WebView's native widget (for margin) | 102 | + | webViewWidget gtk.Widgetter // The WebView's native widget (for margin) |
| 102 | - | borderContainer uintptr // The container that gets background color | 103 | + | borderContainer gtk.Widgetter // The container that gets background color |
| 103 | - | cssClasses []string // Additional CSS classes to apply | 104 | + | cssClasses []string // Additional CSS classes to apply |
| 104 | - | paneType string // Description for debugging | 105 | + | paneType string // Description for debugging |
| 105 | } | 106 | } | ||
| 106 | 107 | ||||
| 107 | // determineBorderContext analyzes a pane node and determines the correct border context | 108 | // determineBorderContext analyzes a pane node and determines the correct border context | ||
| @@ -155,18 +156,21 @@ func (wm *WorkspaceManager) applyActivePaneBorder(ctx *PaneBorderContext) { | |||||
| 155 | } | 156 | } | ||
| 156 | 157 | ||||
| 157 | // Apply margin to WebView widget (creates space for border) | 158 | // Apply margin to WebView widget (creates space for border) | ||
| 158 | - | if ctx.webViewWidget != 0 && webkit.WidgetIsValid(ctx.webViewWidget) { | 159 | + | if ctx.webViewWidget != nil { |
| 159 | - | webkit.WidgetSetMargin(ctx.webViewWidget, 2) | 160 | + | ctx.webViewWidget.SetMarginTop(2) |
| 161 | + | ctx.webViewWidget.SetMarginBottom(2) | |||
| 162 | + | ctx.webViewWidget.SetMarginStart(2) | |||
| 163 | + | ctx.webViewWidget.SetMarginEnd(2) | |||
| 160 | } | 164 | } | ||
| 161 | 165 | ||||
| 162 | // Apply CSS classes to border container | 166 | // Apply CSS classes to border container | ||
| 163 | - | if ctx.borderContainer != 0 && webkit.WidgetIsValid(ctx.borderContainer) { | 167 | + | if ctx.borderContainer != nil { |
| 164 | for _, class := range ctx.cssClasses { | 168 | for _, class := range ctx.cssClasses { | ||
| 165 | - | webkit.WidgetAddCSSClass(ctx.borderContainer, class) | 169 | + | ctx.borderContainer.AddCSSClass(class) |
| 166 | } | 170 | } | ||
| 167 | } | 171 | } | ||
| 168 | 172 | ||||
| 169 | - | log.Printf("[workspace] Applied active border: type=%s webView=%#x container=%#x", | 173 | + | log.Printf("[workspace] Applied active border: type=%s webView=%p container=%p", |
| 170 | ctx.paneType, ctx.webViewWidget, ctx.borderContainer) | 174 | ctx.paneType, ctx.webViewWidget, ctx.borderContainer) | ||
| 171 | } | 175 | } | ||
| 172 | 176 | ||||
| @@ -182,26 +186,29 @@ func (wm *WorkspaceManager) removeActivePaneBorder(node *paneNode) { | |||||
| 182 | } | 186 | } | ||
| 183 | 187 | ||||
| 184 | // Remove margin from WebView widget | 188 | // Remove margin from WebView widget | ||
| 185 | - | if ctx.webViewWidget != 0 && webkit.WidgetIsValid(ctx.webViewWidget) { | 189 | + | if ctx.webViewWidget != nil { |
| 186 | - | webkit.WidgetSetMargin(ctx.webViewWidget, 0) | 190 | + | ctx.webViewWidget.SetMarginTop(0) |
| 191 | + | ctx.webViewWidget.SetMarginBottom(0) | |||
| 192 | + | ctx.webViewWidget.SetMarginStart(0) | |||
| 193 | + | ctx.webViewWidget.SetMarginEnd(0) | |||
| 187 | } | 194 | } | ||
| 188 | 195 | ||||
| 189 | // Remove CSS classes from border container | 196 | // Remove CSS classes from border container | ||
| 190 | - | if ctx.borderContainer != 0 && webkit.WidgetIsValid(ctx.borderContainer) { | 197 | + | if ctx.borderContainer != nil { |
| 191 | for _, class := range ctx.cssClasses { | 198 | for _, class := range ctx.cssClasses { | ||
| 192 | - | webkit.WidgetRemoveCSSClass(ctx.borderContainer, class) | 199 | + | ctx.borderContainer.RemoveCSSClass(class) |
| 193 | } | 200 | } | ||
| 194 | } | 201 | } | ||
| 195 | 202 | ||||
| 196 | - | log.Printf("[workspace] Removed active border: type=%s webView=%#x container=%#x", | 203 | + | log.Printf("[workspace] Removed active border: type=%s webView=%p container=%p", |
| 197 | ctx.paneType, ctx.webViewWidget, ctx.borderContainer) | 204 | ctx.paneType, ctx.webViewWidget, ctx.borderContainer) | ||
| 198 | } | 205 | } | ||
| 199 | 206 | ||||
| 200 | // Widget cleanup utilities | 207 | // Widget cleanup utilities | ||
| 201 | 208 | ||||
| 202 | // cleanupWidget safely invalidates and cleans up a widget | 209 | // cleanupWidget safely invalidates and cleans up a widget | ||
| 203 | - | func (wm *WorkspaceManager) cleanupWidget(ptr uintptr) { | 210 | + | func (wm *WorkspaceManager) cleanupWidget(widget gtk.Widgetter) { |
| 204 | - | if ptr == 0 { | 211 | + | if widget == nil { |
| 205 | return | 212 | return | ||
| 206 | } | 213 | } | ||
| 207 | 214 | ||||
| @@ -217,7 +224,7 @@ func (wm *WorkspaceManager) scheduleIdleGuarded(fn func() bool, nodes ...*paneNo | |||||
| 217 | } | 224 | } | ||
| 218 | guards := uniquePaneNodes(nodes...) | 225 | guards := uniquePaneNodes(nodes...) | ||
| 219 | var handle uintptr | 226 | var handle uintptr | ||
| 220 | - | handle = webkit.IdleAdd(func() bool { | 227 | + | handle = uintptr(glib.IdleAdd(func() bool { |
| 221 | defer wm.releaseIdleHandle(handle) | 228 | defer wm.releaseIdleHandle(handle) | ||
| 222 | for _, node := range guards { | 229 | for _, node := range guards { | ||
| 223 | if node == nil { | 230 | if node == nil { | ||
| @@ -228,7 +235,7 @@ func (wm *WorkspaceManager) scheduleIdleGuarded(fn func() bool, nodes ...*paneNo | |||||
| 228 | } | 235 | } | ||
| 229 | } | 236 | } | ||
| 230 | return fn() | 237 | return fn() | ||
| 231 | - | }) | 238 | + | })) |
| 232 | if handle != 0 { | 239 | if handle != 0 { | ||
| 233 | wm.registerIdleHandle(handle, guards...) | 240 | wm.registerIdleHandle(handle, guards...) | ||
| 234 | } | 241 | } | ||
| @@ -302,7 +309,7 @@ func (wm *WorkspaceManager) cancelIdleHandle(handle uintptr) { | |||||
| 302 | return | 309 | return | ||
| 303 | } | 310 | } | ||
| 304 | wm.releaseIdleHandle(handle) | 311 | wm.releaseIdleHandle(handle) | ||
| 305 | - | webkit.IdleRemove(handle) | 312 | + | glib.SourceRemove(uint(handle)) |
| 306 | } | 313 | } | ||
| 307 | 314 | ||||
| 308 | func (wm *WorkspaceManager) cancelIdleHandles(node *paneNode) { | 315 | func (wm *WorkspaceManager) cancelIdleHandles(node *paneNode) { | ||
| @@ -329,7 +336,7 @@ func formatPaneInfo(node *paneNode) string { | |||||
| 329 | 336 | ||||
| 330 | var info string | 337 | var info string | ||
| 331 | if node.isLeaf { | 338 | if node.isLeaf { | ||
| 332 | - | info = fmt.Sprintf("leaf(container=%#x", node.container) | 339 | + | info = fmt.Sprintf("leaf(container=%p", node.container) |
| 333 | if node.pane != nil && node.pane.webView != nil { | 340 | if node.pane != nil && node.pane.webView != nil { | ||
| 334 | info += fmt.Sprintf(" webview=%s", node.pane.webView.ID()) | 341 | info += fmt.Sprintf(" webview=%s", node.pane.webView.ID()) | ||
| 335 | } | 342 | } | ||
| @@ -338,10 +345,10 @@ func formatPaneInfo(node *paneNode) string { | |||||
| 338 | } | 345 | } | ||
| 339 | info += ")" | 346 | info += ")" | ||
| 340 | } else if node.isStacked { | 347 | } else if node.isStacked { | ||
| 341 | - | info = fmt.Sprintf("stack(panes=%d active=%d container=%#x)", | 348 | + | info = fmt.Sprintf("stack(panes=%d active=%d container=%p)", |
| 342 | len(node.stackedPanes), node.activeStackIndex, node.container) | 349 | len(node.stackedPanes), node.activeStackIndex, node.container) | ||
| 343 | } else { | 350 | } else { | ||
| 344 | - | info = fmt.Sprintf("branch(container=%#x orientation=%v)", | 351 | + | info = fmt.Sprintf("branch(container=%p orientation=%v)", |
| 345 | node.container, node.orientation) | 352 | node.container, node.orientation) | ||
| 346 | } | 353 | } | ||
| 347 | 354 | ||||