feat: implement Zellij-style stacked panes
Add comprehensive stacked panes functionality matching Zellij's behavior: - Ctrl+P → 's' stacks panes instead of splitting - Alt+Up/Down navigates between stacked panes - Collapsed panes show title bars with "Page Title - domain" - Active pane shows full WebView with complete interaction - GTK4 CSS styling for visual feedback and theming - Proper widget hierarchy and focus management - Immediate new pane activation with smooth UX flow Technical implementation: - Extended paneNode structure with stacking fields - Added GTK4 bindings for GtkBox, GtkLabel, visibility functions - Implemented WebView title extraction via webkit_web_view_get_title - Created stack containers with vertical box layout - Added proper widget parenting and cleanup logic - Fixed GTK widget parent assertion errors - Optimized focus workflow to eliminate intermediate states This enables Zellij-like workspace management for better productivity with multiple web contexts in a single window.
- commit
- f3aa007809a3f150287f142d6d9c3c95da550989
- author
- bamen · · 2025-09-25 05:18 UTC
- parent
- a85e2e5
- signature
- unsigned
10 files · +820 -6
M .gitignore +1 -0
| @@ -71,6 +71,7 @@ node_modules/ | |||
| 71 | 71 | CLAUDE.md | |
| 72 | 72 | .claude/ | |
| 73 | 73 | memory/ | |
| 74 | + | notes/ | |
| 74 | 75 | scripts/ | |
| 75 | 76 | !scripts/generate-types.js | |
| 76 | 77 | specs/ | |
| @@ -71,6 +71,7 @@ node_modules/ | |||||
| 71 | CLAUDE.md | 71 | CLAUDE.md | ||
| 72 | .claude/ | 72 | .claude/ | ||
| 73 | memory/ | 73 | memory/ | ||
| 74 | + | notes/ | |||
| 74 | scripts/ | 75 | scripts/ | ||
| 75 | !scripts/generate-types.js | 76 | !scripts/generate-types.js | ||
| 76 | specs/ | 77 | specs/ | ||
M CHANGELOG.md +1 -0
| @@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file. | |||
| 6 | 6 | ||
| 7 | 7 | ### Added | |
| 8 | 8 | - **Pin/favorite sites**: Pin websites from history or quick access to prioritize them in "Jump back in" section. Uses localStorage persistence with star icons for pin/unpin actions | |
| 9 | + | - **Zellij-style stacked panes**: Added Ctrl+P → 's' to stack panes instead of splitting, with Alt+Up/Down navigation between stacked panes. Features collapsed title bars showing "Page Title - domain" for inactive panes and full WebView interaction for the active pane. Includes GTK4 CSS styling for proper visual feedback | |
| 9 | 10 | ||
| 10 | 11 | ### Changed | |
| 11 | 12 | - **History item layout**: Removed "• domain" from titles, now highlight domain within the full URL using same color as title text | |
| @@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file. | |||||
| 6 | 6 | ||||
| 7 | ### Added | 7 | ### Added | ||
| 8 | - **Pin/favorite sites**: Pin websites from history or quick access to prioritize them in "Jump back in" section. Uses localStorage persistence with star icons for pin/unpin actions | 8 | - **Pin/favorite sites**: Pin websites from history or quick access to prioritize them in "Jump back in" section. Uses localStorage persistence with star icons for pin/unpin actions | ||
| 9 | + | - **Zellij-style stacked panes**: Added Ctrl+P → 's' to stack panes instead of splitting, with Alt+Up/Down navigation between stacked panes. Features collapsed title bars showing "Page Title - domain" for inactive panes and full WebView interaction for the active pane. Includes GTK4 CSS styling for proper visual feedback | |||
| 9 | 10 | ||||
| 10 | ### Changed | 11 | ### Changed | ||
| 11 | - **History item layout**: Removed "• domain" from titles, now highlight domain within the full URL using same color as title text | 12 | - **History item layout**: Removed "• domain" from titles, now highlight domain within the full URL using same color as title text | ||
M gui/src/injected/modules/workspace.ts +9 -0
| @@ -80,6 +80,7 @@ const DEFAULT_CONFIG: WorkspaceConfigNormalized = { | |||
| 80 | 80 | l: "split-left", | |
| 81 | 81 | u: "split-up", | |
| 82 | 82 | d: "split-down", | |
| 83 | + | s: "stack-pane", | |
| 83 | 84 | x: "close-pane", | |
| 84 | 85 | enter: "confirm", | |
| 85 | 86 | escape: "cancel", | |
| @@ -339,6 +340,14 @@ class WorkspaceController implements WorkspaceRuntime { | |||
| 339 | 340 | this.showToast("Split pane downwards"); | |
| 340 | 341 | this.exitPaneMode("split-down"); | |
| 341 | 342 | break; | |
| 343 | + | case "stack-pane": | |
| 344 | + | this.emitWorkspaceEvent("pane-stack", { | |
| 345 | + | config: this.config, | |
| 346 | + | }); | |
| 347 | + | this.bridge({ event: "pane-stack" }); | |
| 348 | + | this.showToast("Stacked pane"); | |
| 349 | + | this.exitPaneMode("stack-pane"); | |
| 350 | + | break; | |
| 342 | 351 | case "close-pane": | |
| 343 | 352 | this.emitWorkspaceEvent("pane-closed", { key, config: this.config }); | |
| 344 | 353 | this.bridge({ event: "pane-close", action }); | |
| @@ -80,6 +80,7 @@ const DEFAULT_CONFIG: WorkspaceConfigNormalized = { | |||||
| 80 | l: "split-left", | 80 | l: "split-left", | ||
| 81 | u: "split-up", | 81 | u: "split-up", | ||
| 82 | d: "split-down", | 82 | d: "split-down", | ||
| 83 | + | s: "stack-pane", | |||
| 83 | x: "close-pane", | 84 | x: "close-pane", | ||
| 84 | enter: "confirm", | 85 | enter: "confirm", | ||
| 85 | escape: "cancel", | 86 | escape: "cancel", | ||
| @@ -339,6 +340,14 @@ class WorkspaceController implements WorkspaceRuntime { | |||||
| 339 | this.showToast("Split pane downwards"); | 340 | this.showToast("Split pane downwards"); | ||
| 340 | this.exitPaneMode("split-down"); | 341 | this.exitPaneMode("split-down"); | ||
| 341 | break; | 342 | break; | ||
| 343 | + | case "stack-pane": | |||
| 344 | + | this.emitWorkspaceEvent("pane-stack", { | |||
| 345 | + | config: this.config, | |||
| 346 | + | }); | |||
| 347 | + | this.bridge({ event: "pane-stack" }); | |||
| 348 | + | this.showToast("Stacked pane"); | |||
| 349 | + | this.exitPaneMode("stack-pane"); | |||
| 350 | + | break; | |||
| 342 | case "close-pane": | 351 | case "close-pane": | ||
| 343 | this.emitWorkspaceEvent("pane-closed", { key, config: this.config }); | 352 | this.emitWorkspaceEvent("pane-closed", { key, config: this.config }); | ||
| 344 | this.bridge({ event: "pane-close", action }); | 353 | this.bridge({ event: "pane-close", action }); | ||
M internal/app/browser/workspace_manager.go +549 -3
| @@ -19,7 +19,7 @@ type paneNode struct { | |||
| 19 | 19 | parent *paneNode | |
| 20 | 20 | left *paneNode | |
| 21 | 21 | right *paneNode | |
| 22 | - | container uintptr // GtkPaned for branch nodes, stable WebView container for leaves | |
| 22 | + | container uintptr // GtkPaned for branch nodes, GtkBox for stacked nodes, stable WebView container for leaves | |
| 23 | 23 | orientation webkit.Orientation | |
| 24 | 24 | isLeaf bool | |
| 25 | 25 | isPopup bool // Deprecated: use windowType instead | |
| @@ -30,6 +30,11 @@ type paneNode struct { | |||
| 30 | 30 | parentPane *paneNode // Parent for related views | |
| 31 | 31 | autoClose bool // Auto-close on OAuth success | |
| 32 | 32 | hoverToken uintptr | |
| 33 | + | // Stacked panes support | |
| 34 | + | isStacked bool // Whether this node contains stacked panes | |
| 35 | + | stackedPanes []*paneNode // List of stacked panes (if isStacked) | |
| 36 | + | activeStackIndex int // Index of currently visible pane in stack | |
| 37 | + | titleBar uintptr // GtkBox for title bar (when collapsed) | |
| 33 | 38 | } | |
| 34 | 39 | ||
| 35 | 40 | // WorkspaceManager coordinates Zellij-style pane operations. | |
| @@ -214,6 +219,28 @@ func (wm *WorkspaceManager) OnWorkspaceMessage(source *webkit.WebView, msg messa | |||
| 214 | 219 | } | |
| 215 | 220 | wm.clonePaneState(node, newNode) | |
| 216 | 221 | wm.splitting = false | |
| 222 | + | case "pane-stack": | |
| 223 | + | wm.focusNode(node) | |
| 224 | + | if last, ok := wm.lastSplitMsg[source]; ok { | |
| 225 | + | if time.Since(last) < 200*time.Millisecond { | |
| 226 | + | log.Printf("[workspace] stack ignored: debounce (%.0fms)", time.Since(last).Seconds()*1000) | |
| 227 | + | return | |
| 228 | + | } | |
| 229 | + | } | |
| 230 | + | if wm.splitting { | |
| 231 | + | log.Printf("[workspace] stack ignored: operation already in progress") | |
| 232 | + | return | |
| 233 | + | } | |
| 234 | + | wm.splitting = true | |
| 235 | + | wm.lastSplitMsg[source] = time.Now() | |
| 236 | + | newNode, err := wm.stackPane(node) | |
| 237 | + | if err != nil { | |
| 238 | + | log.Printf("[workspace] stack failed: %v", err) | |
| 239 | + | wm.splitting = false | |
| 240 | + | return | |
| 241 | + | } | |
| 242 | + | wm.clonePaneState(node, newNode) | |
| 243 | + | wm.splitting = false | |
| 217 | 244 | case "create-pane": | |
| 218 | 245 | log.Printf("[workspace] create-pane requested: url=%s action=%s requestId=%s", msg.URL, msg.Action, msg.RequestID) | |
| 219 | 246 | ||
| @@ -360,6 +387,22 @@ func (wm *WorkspaceManager) focusNode(node *paneNode) { | |||
| 360 | 387 | return | |
| 361 | 388 | } | |
| 362 | 389 | ||
| 390 | + | // Handle stacked pane focus: ensure the pane is active in its stack | |
| 391 | + | if node.parent != nil && node.parent.isStacked { | |
| 392 | + | stackNode := node.parent | |
| 393 | + | // Find the index of this node in the stack | |
| 394 | + | for i, stackedPane := range stackNode.stackedPanes { | |
| 395 | + | if stackedPane == node { | |
| 396 | + | if stackNode.activeStackIndex != i { | |
| 397 | + | stackNode.activeStackIndex = i | |
| 398 | + | wm.updateStackVisibility(stackNode) | |
| 399 | + | log.Printf("[workspace] updated stack focus: activeIndex=%d for pane=%p", i, node) | |
| 400 | + | } | |
| 401 | + | break | |
| 402 | + | } | |
| 403 | + | } | |
| 404 | + | } | |
| 405 | + | ||
| 363 | 406 | previous := wm.active | |
| 364 | 407 | var previousContainer uintptr | |
| 365 | 408 | var previousWebView *webkit.WebView | |
| @@ -452,6 +495,28 @@ func (wm *WorkspaceManager) focusNode(node *paneNode) { | |||
| 452 | 495 | } | |
| 453 | 496 | } | |
| 454 | 497 | ||
| 498 | + | // Helper functions for stacked pane CSS colors | |
| 499 | + | func getStackTitleBg(isDark bool) string { | |
| 500 | + | if isDark { | |
| 501 | + | return "#404040" | |
| 502 | + | } | |
| 503 | + | return "#f0f0f0" | |
| 504 | + | } | |
| 505 | + | ||
| 506 | + | func getStackTitleHoverBg(isDark bool) string { | |
| 507 | + | if isDark { | |
| 508 | + | return "#505050" | |
| 509 | + | } | |
| 510 | + | return "#e0e0e0" | |
| 511 | + | } | |
| 512 | + | ||
| 513 | + | func getStackTitleTextColor(isDark bool) string { | |
| 514 | + | if isDark { | |
| 515 | + | return "#ffffff" | |
| 516 | + | } | |
| 517 | + | return "#333333" | |
| 518 | + | } | |
| 519 | + | ||
| 455 | 520 | // generateActivePaneCSS generates the CSS for workspace panes based on config | |
| 456 | 521 | func (wm *WorkspaceManager) generateActivePaneCSS() string { | |
| 457 | 522 | cfg := config.Get() | |
| @@ -489,6 +554,38 @@ func (wm *WorkspaceManager) generateActivePaneCSS() string { | |||
| 489 | 554 | ||
| 490 | 555 | .workspace-pane.workspace-multi-pane.workspace-pane-active { | |
| 491 | 556 | border-color: %s; | |
| 557 | + | } | |
| 558 | + | ||
| 559 | + | /* Stacked panes styling */ | |
| 560 | + | .stacked-pane-container { | |
| 561 | + | background-color: %s; | |
| 562 | + | border-radius: %dpx; | |
| 563 | + | } | |
| 564 | + | ||
| 565 | + | .stacked-pane-title { | |
| 566 | + | background-color: %s; | |
| 567 | + | border-bottom: 1px solid %s; | |
| 568 | + | padding: 4px 8px; | |
| 569 | + | min-height: 24px; | |
| 570 | + | transition: background-color %dms ease-in-out; | |
| 571 | + | } | |
| 572 | + | ||
| 573 | + | .stacked-pane-title:hover { | |
| 574 | + | background-color: %s; | |
| 575 | + | } | |
| 576 | + | ||
| 577 | + | .stacked-pane-title-text { | |
| 578 | + | font-size: 12px; | |
| 579 | + | color: %s; | |
| 580 | + | font-weight: 500; | |
| 581 | + | } | |
| 582 | + | ||
| 583 | + | .stacked-pane-active { | |
| 584 | + | /* Active pane is fully visible */ | |
| 585 | + | } | |
| 586 | + | ||
| 587 | + | .stacked-pane-collapsed { | |
| 588 | + | /* Collapsed panes are hidden - handled in code via widget visibility */ | |
| 492 | 589 | }`, | |
| 493 | 590 | windowBackgroundColor, | |
| 494 | 591 | windowBackgroundColor, | |
| @@ -500,6 +597,14 @@ func (wm *WorkspaceManager) generateActivePaneCSS() string { | |||
| 500 | 597 | inactiveBorderColor, | |
| 501 | 598 | styling.BorderRadius, | |
| 502 | 599 | styling.BorderColor, | |
| 600 | + | // Additional parameters for stacked pane styles | |
| 601 | + | windowBackgroundColor, // stacked-pane-container background | |
| 602 | + | styling.BorderRadius, // stacked-pane-container border-radius | |
| 603 | + | getStackTitleBg(isDark), // stacked-pane-title background | |
| 604 | + | inactiveBorderColor, // stacked-pane-title border-bottom | |
| 605 | + | styling.TransitionDuration, // stacked-pane-title transition | |
| 606 | + | getStackTitleHoverBg(isDark), // stacked-pane-title:hover background | |
| 607 | + | getStackTitleTextColor(isDark), // stacked-pane-title-text color | |
| 503 | 608 | ) | |
| 504 | 609 | ||
| 505 | 610 | // Log the actual CSS being generated | |
| @@ -592,17 +697,97 @@ func (wm *WorkspaceManager) detachHover(node *paneNode) { | |||
| 592 | 697 | } | |
| 593 | 698 | ||
| 594 | 699 | // FocusNeighbor moves focus to the nearest pane in the requested direction using the | |
| 595 | - | // actual widget geometry to determine adjacency. | |
| 700 | + | // actual widget geometry to determine adjacency. For stacked panes, "up" and "down" | |
| 701 | + | // navigate within the stack. | |
| 596 | 702 | func (wm *WorkspaceManager) FocusNeighbor(direction string) bool { | |
| 597 | 703 | if wm == nil { | |
| 598 | 704 | return false | |
| 599 | 705 | } | |
| 600 | 706 | switch strings.ToLower(direction) { | |
| 601 | - | case "left", "right", "up", "down": | |
| 707 | + | case "up", "down": | |
| 708 | + | // Check if current pane is part of a stack and handle stack navigation | |
| 709 | + | if wm.navigateStack(strings.ToLower(direction)) { | |
| 710 | + | return true | |
| 711 | + | } | |
| 712 | + | // Fall back to regular adjacency navigation | |
| 602 | 713 | return wm.focusAdjacent(strings.ToLower(direction)) | |
| 714 | + | case "left", "right": | |
| 715 | + | return wm.focusAdjacent(strings.ToLower(direction)) | |
| 716 | + | default: | |
| 717 | + | return false | |
| 718 | + | } | |
| 719 | + | } | |
| 720 | + | ||
| 721 | + | // navigateStack handles navigation within a stacked pane container. | |
| 722 | + | func (wm *WorkspaceManager) navigateStack(direction string) bool { | |
| 723 | + | if wm.active == nil { | |
| 724 | + | return false | |
| 725 | + | } | |
| 726 | + | ||
| 727 | + | // Find the stack container this pane belongs to | |
| 728 | + | var stackNode *paneNode | |
| 729 | + | current := wm.active | |
| 730 | + | ||
| 731 | + | // Check if current pane is directly in a stack | |
| 732 | + | if current.parent != nil && current.parent.isStacked { | |
| 733 | + | stackNode = current.parent | |
| 734 | + | } else { | |
| 735 | + | // Current pane might be the stack container itself if it was the first pane converted to stack | |
| 736 | + | if current.isStacked { | |
| 737 | + | stackNode = current | |
| 738 | + | } | |
| 739 | + | } | |
| 740 | + | ||
| 741 | + | if stackNode == nil || !stackNode.isStacked || len(stackNode.stackedPanes) <= 1 { | |
| 742 | + | return false // Not in a stack or stack has only one pane | |
| 743 | + | } | |
| 744 | + | ||
| 745 | + | // Find current pane's index in the stack | |
| 746 | + | currentIndex := -1 | |
| 747 | + | for i, pane := range stackNode.stackedPanes { | |
| 748 | + | if pane == current || (pane.pane != nil && current.pane != nil && pane.pane.webView == current.pane.webView) { | |
| 749 | + | currentIndex = i | |
| 750 | + | break | |
| 751 | + | } | |
| 752 | + | } | |
| 753 | + | ||
| 754 | + | if currentIndex == -1 { | |
| 755 | + | log.Printf("[workspace] navigateStack: current pane not found in stack") | |
| 756 | + | return false | |
| 757 | + | } | |
| 758 | + | ||
| 759 | + | // Calculate new index based on direction | |
| 760 | + | var newIndex int | |
| 761 | + | switch direction { | |
| 762 | + | case "up": | |
| 763 | + | newIndex = currentIndex - 1 | |
| 764 | + | if newIndex < 0 { | |
| 765 | + | newIndex = len(stackNode.stackedPanes) - 1 // Wrap to last | |
| 766 | + | } | |
| 767 | + | case "down": | |
| 768 | + | newIndex = currentIndex + 1 | |
| 769 | + | if newIndex >= len(stackNode.stackedPanes) { | |
| 770 | + | newIndex = 0 // Wrap to first | |
| 771 | + | } | |
| 603 | 772 | default: | |
| 604 | 773 | return false | |
| 605 | 774 | } | |
| 775 | + | ||
| 776 | + | if newIndex == currentIndex { | |
| 777 | + | return false // No change | |
| 778 | + | } | |
| 779 | + | ||
| 780 | + | // Update active stack index and visibility | |
| 781 | + | stackNode.activeStackIndex = newIndex | |
| 782 | + | wm.updateStackVisibility(stackNode) | |
| 783 | + | ||
| 784 | + | // Focus the new active pane | |
| 785 | + | newActivePane := stackNode.stackedPanes[newIndex] | |
| 786 | + | wm.focusNode(newActivePane) | |
| 787 | + | ||
| 788 | + | log.Printf("[workspace] navigated stack: direction=%s from=%d to=%d stackSize=%d", | |
| 789 | + | direction, currentIndex, newIndex, len(stackNode.stackedPanes)) | |
| 790 | + | return true | |
| 606 | 791 | } | |
| 607 | 792 | ||
| 608 | 793 | const focusEpsilon = 1e-3 | |
| @@ -1041,6 +1226,227 @@ func (wm *WorkspaceManager) splitNode(target *paneNode, direction string) (*pane | |||
| 1041 | 1226 | return newLeaf, nil | |
| 1042 | 1227 | } | |
| 1043 | 1228 | ||
| 1229 | + | // stackPane creates a new pane stacked on top of the target pane. | |
| 1230 | + | // Similar to splitNode but creates a stack container instead of a paned widget. | |
| 1231 | + | func (wm *WorkspaceManager) stackPane(target *paneNode) (*paneNode, error) { | |
| 1232 | + | if target == nil || !target.isLeaf || target.pane == nil { | |
| 1233 | + | return nil, errors.New("stack target must be a leaf pane") | |
| 1234 | + | } | |
| 1235 | + | ||
| 1236 | + | newView, err := wm.createWebView() | |
| 1237 | + | if err != nil { | |
| 1238 | + | return nil, err | |
| 1239 | + | } | |
| 1240 | + | ||
| 1241 | + | newPane, err := wm.createPane(newView) | |
| 1242 | + | if err != nil { | |
| 1243 | + | return nil, err | |
| 1244 | + | } | |
| 1245 | + | ||
| 1246 | + | if handler := newPane.MessageHandler(); handler != nil { | |
| 1247 | + | handler.SetWorkspaceObserver(wm) | |
| 1248 | + | } | |
| 1249 | + | ||
| 1250 | + | newContainer := newPane.webView.RootWidget() | |
| 1251 | + | if newContainer == 0 { | |
| 1252 | + | return nil, errors.New("new pane missing container") | |
| 1253 | + | } | |
| 1254 | + | webkit.WidgetSetHExpand(newContainer, true) | |
| 1255 | + | webkit.WidgetSetVExpand(newContainer, true) | |
| 1256 | + | webkit.WidgetRealizeInContainer(newContainer) | |
| 1257 | + | ||
| 1258 | + | // If target is not already stacked, convert it to a stacked node | |
| 1259 | + | if !target.isStacked { | |
| 1260 | + | log.Printf("[workspace] converting pane to stacked: %p", target) | |
| 1261 | + | ||
| 1262 | + | // Create a vertical box container for the stack | |
| 1263 | + | stackContainer := webkit.NewBox(webkit.OrientationVertical, 0) | |
| 1264 | + | if stackContainer == 0 { | |
| 1265 | + | return nil, errors.New("failed to create stack container") | |
| 1266 | + | } | |
| 1267 | + | webkit.WidgetSetHExpand(stackContainer, true) | |
| 1268 | + | webkit.WidgetSetVExpand(stackContainer, true) | |
| 1269 | + | ||
| 1270 | + | // Get the existing container and parent info | |
| 1271 | + | existingContainer := target.container | |
| 1272 | + | parent := target.parent | |
| 1273 | + | ||
| 1274 | + | // Detach existing container from its parent | |
| 1275 | + | if parent == nil { | |
| 1276 | + | // Target is the root - remove it from window | |
| 1277 | + | if wm.window != nil { | |
| 1278 | + | wm.window.SetChild(0) | |
| 1279 | + | } | |
| 1280 | + | } else if parent.container != 0 { | |
| 1281 | + | // Target has a parent - unparent it | |
| 1282 | + | if parent.left == target { | |
| 1283 | + | webkit.PanedSetStartChild(parent.container, 0) | |
| 1284 | + | } else if parent.right == target { | |
| 1285 | + | webkit.PanedSetEndChild(parent.container, 0) | |
| 1286 | + | } | |
| 1287 | + | } | |
| 1288 | + | ||
| 1289 | + | webkit.WidgetUnparent(existingContainer) | |
| 1290 | + | ||
| 1291 | + | // Create title bar for the existing pane | |
| 1292 | + | titleBar := wm.createTitleBar(target) | |
| 1293 | + | ||
| 1294 | + | // Add ONLY the title bar for the first pane to the stack container initially | |
| 1295 | + | // The webview content will be added when this pane becomes active | |
| 1296 | + | webkit.BoxAppend(stackContainer, titleBar) | |
| 1297 | + | webkit.BoxAppend(stackContainer, existingContainer) | |
| 1298 | + | ||
| 1299 | + | // Convert target to a stacked node but keep it as a leaf for content management | |
| 1300 | + | target.isStacked = true | |
| 1301 | + | target.isLeaf = true // Keep as leaf so updateStackVisibility works correctly | |
| 1302 | + | target.container = existingContainer // Keep original container for visibility control | |
| 1303 | + | target.titleBar = titleBar | |
| 1304 | + | ||
| 1305 | + | // Create a parent stacked container node | |
| 1306 | + | stackNode := &paneNode{ | |
| 1307 | + | isStacked: true, | |
| 1308 | + | isLeaf: false, | |
| 1309 | + | container: stackContainer, | |
| 1310 | + | stackedPanes: []*paneNode{target}, | |
| 1311 | + | activeStackIndex: 1, // NEW PANE WILL BE ACTIVE (index 1) | |
| 1312 | + | parent: parent, | |
| 1313 | + | } | |
| 1314 | + | ||
| 1315 | + | // Update target's parent to be the stack node | |
| 1316 | + | target.parent = stackNode | |
| 1317 | + | ||
| 1318 | + | // Update parent references | |
| 1319 | + | if parent == nil { | |
| 1320 | + | wm.root = stackNode | |
| 1321 | + | if wm.window != nil { | |
| 1322 | + | wm.window.SetChild(stackContainer) | |
| 1323 | + | } | |
| 1324 | + | } else { | |
| 1325 | + | if parent.left == target { | |
| 1326 | + | parent.left = stackNode | |
| 1327 | + | webkit.PanedSetStartChild(parent.container, stackContainer) | |
| 1328 | + | } else if parent.right == target { | |
| 1329 | + | parent.right = stackNode | |
| 1330 | + | webkit.PanedSetEndChild(parent.container, stackContainer) | |
| 1331 | + | } | |
| 1332 | + | } | |
| 1333 | + | ||
| 1334 | + | // Update target to point to the stack node for further operations | |
| 1335 | + | target = stackNode | |
| 1336 | + | } | |
| 1337 | + | ||
| 1338 | + | // Create new leaf node for the new pane | |
| 1339 | + | newLeaf := &paneNode{ | |
| 1340 | + | pane: newPane, | |
| 1341 | + | parent: target, | |
| 1342 | + | container: newContainer, | |
| 1343 | + | isLeaf: true, | |
| 1344 | + | } | |
| 1345 | + | ||
| 1346 | + | // Create title bar for the new pane | |
| 1347 | + | newTitleBar := wm.createTitleBar(newLeaf) | |
| 1348 | + | newLeaf.titleBar = newTitleBar | |
| 1349 | + | ||
| 1350 | + | // Add new pane to the stack | |
| 1351 | + | target.stackedPanes = append(target.stackedPanes, newLeaf) | |
| 1352 | + | webkit.BoxAppend(target.container, newTitleBar) | |
| 1353 | + | ||
| 1354 | + | // Unparent the new container before adding it to the stack | |
| 1355 | + | webkit.WidgetUnparent(newContainer) | |
| 1356 | + | webkit.BoxAppend(target.container, newContainer) | |
| 1357 | + | ||
| 1358 | + | // Ensure the activeStackIndex is correct (should be 1 for the new pane) | |
| 1359 | + | target.activeStackIndex = len(target.stackedPanes) - 1 | |
| 1360 | + | ||
| 1361 | + | // Update workspace state FIRST | |
| 1362 | + | wm.viewToNode[newPane.webView] = newLeaf | |
| 1363 | + | wm.ensureHover(newLeaf) | |
| 1364 | + | wm.app.panes = append(wm.app.panes, newPane) | |
| 1365 | + | if newPane.zoomController != nil { | |
| 1366 | + | newPane.zoomController.ApplyInitialZoom() | |
| 1367 | + | } | |
| 1368 | + | ||
| 1369 | + | // Update CSS classes | |
| 1370 | + | wm.ensurePaneBaseClasses() | |
| 1371 | + | ||
| 1372 | + | // Show the new container immediately | |
| 1373 | + | webkit.WidgetShow(newContainer) | |
| 1374 | + | ||
| 1375 | + | // Update stack visibility to show the new pane as active | |
| 1376 | + | wm.updateStackVisibility(target) | |
| 1377 | + | ||
| 1378 | + | // Focus the new pane IMMEDIATELY (not in IdleAdd) | |
| 1379 | + | wm.focusNode(newLeaf) | |
| 1380 | + | ||
| 1381 | + | log.Printf("[workspace] stacked new pane: target=%p newLeaf=%p stackSize=%d activeIndex=%d", target, newLeaf, len(target.stackedPanes), target.activeStackIndex) | |
| 1382 | + | return newLeaf, nil | |
| 1383 | + | } | |
| 1384 | + | ||
| 1385 | + | // createTitleBar creates a title bar widget for a pane in a stack. | |
| 1386 | + | func (wm *WorkspaceManager) createTitleBar(pane *paneNode) uintptr { | |
| 1387 | + | titleBox := webkit.NewBox(webkit.OrientationHorizontal, 8) | |
| 1388 | + | if titleBox == 0 { | |
| 1389 | + | log.Printf("[workspace] failed to create title bar box") | |
| 1390 | + | return 0 | |
| 1391 | + | } | |
| 1392 | + | ||
| 1393 | + | webkit.WidgetSetHExpand(titleBox, true) | |
| 1394 | + | webkit.WidgetSetVExpand(titleBox, false) | |
| 1395 | + | ||
| 1396 | + | // Create label for page title and domain | |
| 1397 | + | title := "New Tab" | |
| 1398 | + | if pane.pane != nil && pane.pane.webView != nil { | |
| 1399 | + | if pageTitle := pane.pane.webView.GetTitle(); pageTitle != "" { | |
| 1400 | + | title = pageTitle | |
| 1401 | + | } | |
| 1402 | + | } | |
| 1403 | + | ||
| 1404 | + | label := webkit.NewLabel(title) | |
| 1405 | + | if label != 0 { | |
| 1406 | + | webkit.LabelSetEllipsize(label, webkit.EllipsizeEnd) | |
| 1407 | + | webkit.WidgetSetHExpand(label, true) | |
| 1408 | + | webkit.BoxAppend(titleBox, label) | |
| 1409 | + | } | |
| 1410 | + | ||
| 1411 | + | // Add CSS classes | |
| 1412 | + | webkit.WidgetAddCSSClass(titleBox, "stacked-pane-title") | |
| 1413 | + | webkit.WidgetAddCSSClass(label, "stacked-pane-title-text") | |
| 1414 | + | ||
| 1415 | + | log.Printf("[workspace] created title bar: box=%#x label=%#x title=%s", titleBox, label, title) | |
| 1416 | + | return titleBox | |
| 1417 | + | } | |
| 1418 | + | ||
| 1419 | + | // updateStackVisibility updates the visibility of panes in a stack. | |
| 1420 | + | func (wm *WorkspaceManager) updateStackVisibility(stackNode *paneNode) { | |
| 1421 | + | if !stackNode.isStacked || len(stackNode.stackedPanes) == 0 { | |
| 1422 | + | return | |
| 1423 | + | } | |
| 1424 | + | ||
| 1425 | + | activeIndex := stackNode.activeStackIndex | |
| 1426 | + | if activeIndex < 0 || activeIndex >= len(stackNode.stackedPanes) { | |
| 1427 | + | activeIndex = 0 | |
| 1428 | + | stackNode.activeStackIndex = activeIndex | |
| 1429 | + | } | |
| 1430 | + | ||
| 1431 | + | log.Printf("[workspace] updating stack visibility: activeIndex=%d stackSize=%d", activeIndex, len(stackNode.stackedPanes)) | |
| 1432 | + | ||
| 1433 | + | for i, pane := range stackNode.stackedPanes { | |
| 1434 | + | if i == activeIndex { | |
| 1435 | + | // Show active pane's content, hide its title bar | |
| 1436 | + | webkit.WidgetSetVisible(pane.container, true) | |
| 1437 | + | webkit.WidgetSetVisible(pane.titleBar, false) | |
| 1438 | + | webkit.WidgetAddCSSClass(pane.container, "stacked-pane-active") | |
| 1439 | + | webkit.WidgetRemoveCSSClass(pane.container, "stacked-pane-collapsed") | |
| 1440 | + | } else { | |
| 1441 | + | // Hide inactive pane's content, show its title bar | |
| 1442 | + | webkit.WidgetSetVisible(pane.container, false) | |
| 1443 | + | webkit.WidgetSetVisible(pane.titleBar, true) | |
| 1444 | + | webkit.WidgetAddCSSClass(pane.container, "stacked-pane-collapsed") | |
| 1445 | + | webkit.WidgetRemoveCSSClass(pane.container, "stacked-pane-active") | |
| 1446 | + | } | |
| 1447 | + | } | |
| 1448 | + | } | |
| 1449 | + | ||
| 1044 | 1450 | func (wm *WorkspaceManager) clonePaneState(_ *paneNode, target *paneNode) { | |
| 1045 | 1451 | if wm == nil || target == nil { | |
| 1046 | 1452 | return | |
| @@ -1086,6 +1492,11 @@ func (wm *WorkspaceManager) closePane(node *paneNode) error { | |||
| 1086 | 1492 | return errors.New("close target missing webview") | |
| 1087 | 1493 | } | |
| 1088 | 1494 | ||
| 1495 | + | // Handle closing panes in a stack | |
| 1496 | + | if node.parent != nil && node.parent.isStacked { | |
| 1497 | + | return wm.closeStackedPane(node) | |
| 1498 | + | } | |
| 1499 | + | ||
| 1089 | 1500 | if node.parent != nil && node.parent.container != 0 { | |
| 1090 | 1501 | if node.parent.left == node { | |
| 1091 | 1502 | webkit.PanedSetStartChild(node.parent.container, 0) | |
| @@ -1466,6 +1877,141 @@ func (wm *WorkspaceManager) findReplacementRoot(excludeNode *paneNode) *paneNode | |||
| 1466 | 1877 | return nil | |
| 1467 | 1878 | } | |
| 1468 | 1879 | ||
| 1880 | + | // closeStackedPane handles closing a pane that is part of a stack. | |
| 1881 | + | func (wm *WorkspaceManager) closeStackedPane(node *paneNode) error { | |
| 1882 | + | if node.parent == nil || !node.parent.isStacked { | |
| 1883 | + | return errors.New("node is not part of a stacked pane") | |
| 1884 | + | } | |
| 1885 | + | ||
| 1886 | + | stackNode := node.parent | |
| 1887 | + | ||
| 1888 | + | // Find the index of the node to be closed | |
| 1889 | + | nodeIndex := -1 | |
| 1890 | + | for i, stackedPane := range stackNode.stackedPanes { | |
| 1891 | + | if stackedPane == node { | |
| 1892 | + | nodeIndex = i | |
| 1893 | + | break | |
| 1894 | + | } | |
| 1895 | + | } | |
| 1896 | + | ||
| 1897 | + | if nodeIndex == -1 { | |
| 1898 | + | return errors.New("node not found in stack") | |
| 1899 | + | } | |
| 1900 | + | ||
| 1901 | + | log.Printf("[workspace] closing stacked pane: index=%d stackSize=%d", nodeIndex, len(stackNode.stackedPanes)) | |
| 1902 | + | ||
| 1903 | + | // Clean up the pane | |
| 1904 | + | wm.detachHover(node) | |
| 1905 | + | delete(wm.viewToNode, node.pane.webView) | |
| 1906 | + | ||
| 1907 | + | // Remove from app.panes | |
| 1908 | + | for i, pane := range wm.app.panes { | |
| 1909 | + | if pane == node.pane { | |
| 1910 | + | wm.app.panes = append(wm.app.panes[:i], wm.app.panes[i+1:]...) | |
| 1911 | + | break | |
| 1912 | + | } | |
| 1913 | + | } | |
| 1914 | + | ||
| 1915 | + | // Remove the pane's widgets from the stack container | |
| 1916 | + | if node.titleBar != 0 { | |
| 1917 | + | webkit.BoxRemove(stackNode.container, node.titleBar) | |
| 1918 | + | } | |
| 1919 | + | if node.container != 0 { | |
| 1920 | + | webkit.BoxRemove(stackNode.container, node.container) | |
| 1921 | + | webkit.WidgetUnparent(node.container) | |
| 1922 | + | } | |
| 1923 | + | ||
| 1924 | + | // Clean up the pane | |
| 1925 | + | node.pane.Cleanup() | |
| 1926 | + | ||
| 1927 | + | // Remove from the stack | |
| 1928 | + | stackNode.stackedPanes = append(stackNode.stackedPanes[:nodeIndex], stackNode.stackedPanes[nodeIndex+1:]...) | |
| 1929 | + | ||
| 1930 | + | // Handle the remaining panes in the stack | |
| 1931 | + | if len(stackNode.stackedPanes) == 0 { | |
| 1932 | + | // No panes left in stack - this should not happen normally | |
| 1933 | + | log.Printf("[workspace] warning: empty stack after closing pane") | |
| 1934 | + | return errors.New("stack became empty") | |
| 1935 | + | } else if len(stackNode.stackedPanes) == 1 { | |
| 1936 | + | // Only one pane left - convert back to a regular pane | |
| 1937 | + | lastPane := stackNode.stackedPanes[0] | |
| 1938 | + | ||
| 1939 | + | // Remove the title bar since we're going back to single pane | |
| 1940 | + | if lastPane.titleBar != 0 { | |
| 1941 | + | webkit.BoxRemove(stackNode.container, lastPane.titleBar) | |
| 1942 | + | } | |
| 1943 | + | ||
| 1944 | + | // Replace the stack container with the pane's container | |
| 1945 | + | parent := stackNode.parent | |
| 1946 | + | lastPaneContainer := lastPane.container | |
| 1947 | + | ||
| 1948 | + | // Unparent from stack container | |
| 1949 | + | webkit.BoxRemove(stackNode.container, lastPaneContainer) | |
| 1950 | + | webkit.WidgetUnparent(lastPaneContainer) | |
| 1951 | + | ||
| 1952 | + | // Convert back to regular pane structure | |
| 1953 | + | lastPane.parent = parent | |
| 1954 | + | lastPane.isStacked = false | |
| 1955 | + | lastPane.stackedPanes = nil | |
| 1956 | + | lastPane.titleBar = 0 | |
| 1957 | + | stackNode.isStacked = false | |
| 1958 | + | stackNode.stackedPanes = nil | |
| 1959 | + | stackNode.container = lastPaneContainer | |
| 1960 | + | stackNode.isLeaf = true | |
| 1961 | + | stackNode.pane = lastPane.pane | |
| 1962 | + | ||
| 1963 | + | // Update parent references | |
| 1964 | + | if parent == nil { | |
| 1965 | + | wm.root = stackNode | |
| 1966 | + | if wm.window != nil { | |
| 1967 | + | wm.window.SetChild(lastPaneContainer) | |
| 1968 | + | } | |
| 1969 | + | } else { | |
| 1970 | + | if parent.left == stackNode { | |
| 1971 | + | webkit.PanedSetStartChild(parent.container, lastPaneContainer) | |
| 1972 | + | } else if parent.right == stackNode { | |
| 1973 | + | webkit.PanedSetEndChild(parent.container, lastPaneContainer) | |
| 1974 | + | } | |
| 1975 | + | } | |
| 1976 | + | ||
| 1977 | + | // Update the viewToNode mapping | |
| 1978 | + | wm.viewToNode[lastPane.pane.webView] = stackNode | |
| 1979 | + | ||
| 1980 | + | // Focus the remaining pane if it was the active one being closed | |
| 1981 | + | if wm.active == node { | |
| 1982 | + | wm.focusNode(stackNode) | |
| 1983 | + | } | |
| 1984 | + | ||
| 1985 | + | log.Printf("[workspace] converted single-pane stack back to regular pane") | |
| 1986 | + | } else { | |
| 1987 | + | // Multiple panes remain in stack - adjust active index | |
| 1988 | + | if stackNode.activeStackIndex >= nodeIndex && stackNode.activeStackIndex > 0 { | |
| 1989 | + | stackNode.activeStackIndex-- | |
| 1990 | + | } | |
| 1991 | + | if stackNode.activeStackIndex >= len(stackNode.stackedPanes) { | |
| 1992 | + | stackNode.activeStackIndex = len(stackNode.stackedPanes) - 1 | |
| 1993 | + | } | |
| 1994 | + | ||
| 1995 | + | // Update visibility for remaining panes | |
| 1996 | + | wm.updateStackVisibility(stackNode) | |
| 1997 | + | ||
| 1998 | + | // Focus the new active pane if we closed the currently active one | |
| 1999 | + | if wm.active == node { | |
| 2000 | + | newActivePaneInStack := stackNode.stackedPanes[stackNode.activeStackIndex] | |
| 2001 | + | wm.focusNode(newActivePaneInStack) | |
| 2002 | + | } | |
| 2003 | + | ||
| 2004 | + | log.Printf("[workspace] closed pane from stack: remaining=%d activeIndex=%d", | |
| 2005 | + | len(stackNode.stackedPanes), stackNode.activeStackIndex) | |
| 2006 | + | } | |
| 2007 | + | ||
| 2008 | + | // Update CSS classes after pane count changes | |
| 2009 | + | wm.ensurePaneBaseClasses() | |
| 2010 | + | log.Printf("[workspace] stacked pane closed; panes remaining=%d", len(wm.app.panes)) | |
| 2011 | + | ||
| 2012 | + | return nil | |
| 2013 | + | } | |
| 2014 | + | ||
| 1469 | 2015 | func (wm *WorkspaceManager) updateMainPane() { | |
| 1470 | 2016 | if len(wm.app.panes) == 1 { | |
| 1471 | 2017 | if leaf := wm.viewToNode[wm.app.panes[0].webView]; leaf != nil { | |
| @@ -19,7 +19,7 @@ type paneNode struct { | |||||
| 19 | parent *paneNode | 19 | parent *paneNode | ||
| 20 | left *paneNode | 20 | left *paneNode | ||
| 21 | right *paneNode | 21 | right *paneNode | ||
| 22 | - | container uintptr // GtkPaned for branch nodes, stable WebView container for leaves | 22 | + | container uintptr // GtkPaned for branch nodes, GtkBox for stacked nodes, stable WebView container for leaves |
| 23 | orientation webkit.Orientation | 23 | orientation webkit.Orientation | ||
| 24 | isLeaf bool | 24 | isLeaf bool | ||
| 25 | isPopup bool // Deprecated: use windowType instead | 25 | isPopup bool // Deprecated: use windowType instead | ||
| @@ -30,6 +30,11 @@ type paneNode struct { | |||||
| 30 | parentPane *paneNode // Parent for related views | 30 | parentPane *paneNode // Parent for related views | ||
| 31 | autoClose bool // Auto-close on OAuth success | 31 | autoClose bool // Auto-close on OAuth success | ||
| 32 | hoverToken uintptr | 32 | hoverToken uintptr | ||
| 33 | + | // Stacked panes support | |||
| 34 | + | isStacked bool // Whether this node contains stacked panes | |||
| 35 | + | stackedPanes []*paneNode // List of stacked panes (if isStacked) | |||
| 36 | + | activeStackIndex int // Index of currently visible pane in stack | |||
| 37 | + | titleBar uintptr // GtkBox for title bar (when collapsed) | |||
| 33 | } | 38 | } | ||
| 34 | 39 | ||||
| 35 | // WorkspaceManager coordinates Zellij-style pane operations. | 40 | // WorkspaceManager coordinates Zellij-style pane operations. | ||
| @@ -214,6 +219,28 @@ func (wm *WorkspaceManager) OnWorkspaceMessage(source *webkit.WebView, msg messa | |||||
| 214 | } | 219 | } | ||
| 215 | wm.clonePaneState(node, newNode) | 220 | wm.clonePaneState(node, newNode) | ||
| 216 | wm.splitting = false | 221 | wm.splitting = false | ||
| 222 | + | case "pane-stack": | |||
| 223 | + | wm.focusNode(node) | |||
| 224 | + | if last, ok := wm.lastSplitMsg[source]; ok { | |||
| 225 | + | if time.Since(last) < 200*time.Millisecond { | |||
| 226 | + | log.Printf("[workspace] stack ignored: debounce (%.0fms)", time.Since(last).Seconds()*1000) | |||
| 227 | + | return | |||
| 228 | + | } | |||
| 229 | + | } | |||
| 230 | + | if wm.splitting { | |||
| 231 | + | log.Printf("[workspace] stack ignored: operation already in progress") | |||
| 232 | + | return | |||
| 233 | + | } | |||
| 234 | + | wm.splitting = true | |||
| 235 | + | wm.lastSplitMsg[source] = time.Now() | |||
| 236 | + | newNode, err := wm.stackPane(node) | |||
| 237 | + | if err != nil { | |||
| 238 | + | log.Printf("[workspace] stack failed: %v", err) | |||
| 239 | + | wm.splitting = false | |||
| 240 | + | return | |||
| 241 | + | } | |||
| 242 | + | wm.clonePaneState(node, newNode) | |||
| 243 | + | wm.splitting = false | |||
| 217 | case "create-pane": | 244 | case "create-pane": | ||
| 218 | log.Printf("[workspace] create-pane requested: url=%s action=%s requestId=%s", msg.URL, msg.Action, msg.RequestID) | 245 | log.Printf("[workspace] create-pane requested: url=%s action=%s requestId=%s", msg.URL, msg.Action, msg.RequestID) | ||
| 219 | 246 | ||||
| @@ -360,6 +387,22 @@ func (wm *WorkspaceManager) focusNode(node *paneNode) { | |||||
| 360 | return | 387 | return | ||
| 361 | } | 388 | } | ||
| 362 | 389 | ||||
| 390 | + | // Handle stacked pane focus: ensure the pane is active in its stack | |||
| 391 | + | if node.parent != nil && node.parent.isStacked { | |||
| 392 | + | stackNode := node.parent | |||
| 393 | + | // Find the index of this node in the stack | |||
| 394 | + | for i, stackedPane := range stackNode.stackedPanes { | |||
| 395 | + | if stackedPane == node { | |||
| 396 | + | if stackNode.activeStackIndex != i { | |||
| 397 | + | stackNode.activeStackIndex = i | |||
| 398 | + | wm.updateStackVisibility(stackNode) | |||
| 399 | + | log.Printf("[workspace] updated stack focus: activeIndex=%d for pane=%p", i, node) | |||
| 400 | + | } | |||
| 401 | + | break | |||
| 402 | + | } | |||
| 403 | + | } | |||
| 404 | + | } | |||
| 405 | + | ||||
| 363 | previous := wm.active | 406 | previous := wm.active | ||
| 364 | var previousContainer uintptr | 407 | var previousContainer uintptr | ||
| 365 | var previousWebView *webkit.WebView | 408 | var previousWebView *webkit.WebView | ||
| @@ -452,6 +495,28 @@ func (wm *WorkspaceManager) focusNode(node *paneNode) { | |||||
| 452 | } | 495 | } | ||
| 453 | } | 496 | } | ||
| 454 | 497 | ||||
| 498 | + | // Helper functions for stacked pane CSS colors | |||
| 499 | + | func getStackTitleBg(isDark bool) string { | |||
| 500 | + | if isDark { | |||
| 501 | + | return "#404040" | |||
| 502 | + | } | |||
| 503 | + | return "#f0f0f0" | |||
| 504 | + | } | |||
| 505 | + | ||||
| 506 | + | func getStackTitleHoverBg(isDark bool) string { | |||
| 507 | + | if isDark { | |||
| 508 | + | return "#505050" | |||
| 509 | + | } | |||
| 510 | + | return "#e0e0e0" | |||
| 511 | + | } | |||
| 512 | + | ||||
| 513 | + | func getStackTitleTextColor(isDark bool) string { | |||
| 514 | + | if isDark { | |||
| 515 | + | return "#ffffff" | |||
| 516 | + | } | |||
| 517 | + | return "#333333" | |||
| 518 | + | } | |||
| 519 | + | ||||
| 455 | // generateActivePaneCSS generates the CSS for workspace panes based on config | 520 | // generateActivePaneCSS generates the CSS for workspace panes based on config | ||
| 456 | func (wm *WorkspaceManager) generateActivePaneCSS() string { | 521 | func (wm *WorkspaceManager) generateActivePaneCSS() string { | ||
| 457 | cfg := config.Get() | 522 | cfg := config.Get() | ||
| @@ -489,6 +554,38 @@ func (wm *WorkspaceManager) generateActivePaneCSS() string { | |||||
| 489 | 554 | ||||
| 490 | .workspace-pane.workspace-multi-pane.workspace-pane-active { | 555 | .workspace-pane.workspace-multi-pane.workspace-pane-active { | ||
| 491 | border-color: %s; | 556 | border-color: %s; | ||
| 557 | + | } | |||
| 558 | + | ||||
| 559 | + | /* Stacked panes styling */ | |||
| 560 | + | .stacked-pane-container { | |||
| 561 | + | background-color: %s; | |||
| 562 | + | border-radius: %dpx; | |||
| 563 | + | } | |||
| 564 | + | ||||
| 565 | + | .stacked-pane-title { | |||
| 566 | + | background-color: %s; | |||
| 567 | + | border-bottom: 1px solid %s; | |||
| 568 | + | padding: 4px 8px; | |||
| 569 | + | min-height: 24px; | |||
| 570 | + | transition: background-color %dms ease-in-out; | |||
| 571 | + | } | |||
| 572 | + | ||||
| 573 | + | .stacked-pane-title:hover { | |||
| 574 | + | background-color: %s; | |||
| 575 | + | } | |||
| 576 | + | ||||
| 577 | + | .stacked-pane-title-text { | |||
| 578 | + | font-size: 12px; | |||
| 579 | + | color: %s; | |||
| 580 | + | font-weight: 500; | |||
| 581 | + | } | |||
| 582 | + | ||||
| 583 | + | .stacked-pane-active { | |||
| 584 | + | /* Active pane is fully visible */ | |||
| 585 | + | } | |||
| 586 | + | ||||
| 587 | + | .stacked-pane-collapsed { | |||
| 588 | + | /* Collapsed panes are hidden - handled in code via widget visibility */ | |||
| 492 | }`, | 589 | }`, | ||
| 493 | windowBackgroundColor, | 590 | windowBackgroundColor, | ||
| 494 | windowBackgroundColor, | 591 | windowBackgroundColor, | ||
| @@ -500,6 +597,14 @@ func (wm *WorkspaceManager) generateActivePaneCSS() string { | |||||
| 500 | inactiveBorderColor, | 597 | inactiveBorderColor, | ||
| 501 | styling.BorderRadius, | 598 | styling.BorderRadius, | ||
| 502 | styling.BorderColor, | 599 | styling.BorderColor, | ||
| 600 | + | // Additional parameters for stacked pane styles | |||
| 601 | + | windowBackgroundColor, // stacked-pane-container background | |||
| 602 | + | styling.BorderRadius, // stacked-pane-container border-radius | |||
| 603 | + | getStackTitleBg(isDark), // stacked-pane-title background | |||
| 604 | + | inactiveBorderColor, // stacked-pane-title border-bottom | |||
| 605 | + | styling.TransitionDuration, // stacked-pane-title transition | |||
| 606 | + | getStackTitleHoverBg(isDark), // stacked-pane-title:hover background | |||
| 607 | + | getStackTitleTextColor(isDark), // stacked-pane-title-text color | |||
| 503 | ) | 608 | ) | ||
| 504 | 609 | ||||
| 505 | // Log the actual CSS being generated | 610 | // Log the actual CSS being generated | ||
| @@ -592,17 +697,97 @@ func (wm *WorkspaceManager) detachHover(node *paneNode) { | |||||
| 592 | } | 697 | } | ||
| 593 | 698 | ||||
| 594 | // FocusNeighbor moves focus to the nearest pane in the requested direction using the | 699 | // FocusNeighbor moves focus to the nearest pane in the requested direction using the | ||
| 595 | - | // actual widget geometry to determine adjacency. | 700 | + | // actual widget geometry to determine adjacency. For stacked panes, "up" and "down" |
| 701 | + | // navigate within the stack. | |||
| 596 | func (wm *WorkspaceManager) FocusNeighbor(direction string) bool { | 702 | func (wm *WorkspaceManager) FocusNeighbor(direction string) bool { | ||
| 597 | if wm == nil { | 703 | if wm == nil { | ||
| 598 | return false | 704 | return false | ||
| 599 | } | 705 | } | ||
| 600 | switch strings.ToLower(direction) { | 706 | switch strings.ToLower(direction) { | ||
| 601 | - | case "left", "right", "up", "down": | 707 | + | case "up", "down": |
| 708 | + | // Check if current pane is part of a stack and handle stack navigation | |||
| 709 | + | if wm.navigateStack(strings.ToLower(direction)) { | |||
| 710 | + | return true | |||
| 711 | + | } | |||
| 712 | + | // Fall back to regular adjacency navigation | |||
| 602 | return wm.focusAdjacent(strings.ToLower(direction)) | 713 | return wm.focusAdjacent(strings.ToLower(direction)) | ||
| 714 | + | case "left", "right": | |||
| 715 | + | return wm.focusAdjacent(strings.ToLower(direction)) | |||
| 716 | + | default: | |||
| 717 | + | return false | |||
| 718 | + | } | |||
| 719 | + | } | |||
| 720 | + | ||||
| 721 | + | // navigateStack handles navigation within a stacked pane container. | |||
| 722 | + | func (wm *WorkspaceManager) navigateStack(direction string) bool { | |||
| 723 | + | if wm.active == nil { | |||
| 724 | + | return false | |||
| 725 | + | } | |||
| 726 | + | ||||
| 727 | + | // Find the stack container this pane belongs to | |||
| 728 | + | var stackNode *paneNode | |||
| 729 | + | current := wm.active | |||
| 730 | + | ||||
| 731 | + | // Check if current pane is directly in a stack | |||
| 732 | + | if current.parent != nil && current.parent.isStacked { | |||
| 733 | + | stackNode = current.parent | |||
| 734 | + | } else { | |||
| 735 | + | // Current pane might be the stack container itself if it was the first pane converted to stack | |||
| 736 | + | if current.isStacked { | |||
| 737 | + | stackNode = current | |||
| 738 | + | } | |||
| 739 | + | } | |||
| 740 | + | ||||
| 741 | + | if stackNode == nil || !stackNode.isStacked || len(stackNode.stackedPanes) <= 1 { | |||
| 742 | + | return false // Not in a stack or stack has only one pane | |||
| 743 | + | } | |||
| 744 | + | ||||
| 745 | + | // Find current pane's index in the stack | |||
| 746 | + | currentIndex := -1 | |||
| 747 | + | for i, pane := range stackNode.stackedPanes { | |||
| 748 | + | if pane == current || (pane.pane != nil && current.pane != nil && pane.pane.webView == current.pane.webView) { | |||
| 749 | + | currentIndex = i | |||
| 750 | + | break | |||
| 751 | + | } | |||
| 752 | + | } | |||
| 753 | + | ||||
| 754 | + | if currentIndex == -1 { | |||
| 755 | + | log.Printf("[workspace] navigateStack: current pane not found in stack") | |||
| 756 | + | return false | |||
| 757 | + | } | |||
| 758 | + | ||||
| 759 | + | // Calculate new index based on direction | |||
| 760 | + | var newIndex int | |||
| 761 | + | switch direction { | |||
| 762 | + | case "up": | |||
| 763 | + | newIndex = currentIndex - 1 | |||
| 764 | + | if newIndex < 0 { | |||
| 765 | + | newIndex = len(stackNode.stackedPanes) - 1 // Wrap to last | |||
| 766 | + | } | |||
| 767 | + | case "down": | |||
| 768 | + | newIndex = currentIndex + 1 | |||
| 769 | + | if newIndex >= len(stackNode.stackedPanes) { | |||
| 770 | + | newIndex = 0 // Wrap to first | |||
| 771 | + | } | |||
| 603 | default: | 772 | default: | ||
| 604 | return false | 773 | return false | ||
| 605 | } | 774 | } | ||
| 775 | + | ||||
| 776 | + | if newIndex == currentIndex { | |||
| 777 | + | return false // No change | |||
| 778 | + | } | |||
| 779 | + | ||||
| 780 | + | // Update active stack index and visibility | |||
| 781 | + | stackNode.activeStackIndex = newIndex | |||
| 782 | + | wm.updateStackVisibility(stackNode) | |||
| 783 | + | ||||
| 784 | + | // Focus the new active pane | |||
| 785 | + | newActivePane := stackNode.stackedPanes[newIndex] | |||
| 786 | + | wm.focusNode(newActivePane) | |||
| 787 | + | ||||
| 788 | + | log.Printf("[workspace] navigated stack: direction=%s from=%d to=%d stackSize=%d", | |||
| 789 | + | direction, currentIndex, newIndex, len(stackNode.stackedPanes)) | |||
| 790 | + | return true | |||
| 606 | } | 791 | } | ||
| 607 | 792 | ||||
| 608 | const focusEpsilon = 1e-3 | 793 | const focusEpsilon = 1e-3 | ||
| @@ -1041,6 +1226,227 @@ func (wm *WorkspaceManager) splitNode(target *paneNode, direction string) (*pane | |||||
| 1041 | return newLeaf, nil | 1226 | return newLeaf, nil | ||
| 1042 | } | 1227 | } | ||
| 1043 | 1228 | ||||
| 1229 | + | // stackPane creates a new pane stacked on top of the target pane. | |||
| 1230 | + | // Similar to splitNode but creates a stack container instead of a paned widget. | |||
| 1231 | + | func (wm *WorkspaceManager) stackPane(target *paneNode) (*paneNode, error) { | |||
| 1232 | + | if target == nil || !target.isLeaf || target.pane == nil { | |||
| 1233 | + | return nil, errors.New("stack target must be a leaf pane") | |||
| 1234 | + | } | |||
| 1235 | + | ||||
| 1236 | + | newView, err := wm.createWebView() | |||
| 1237 | + | if err != nil { | |||
| 1238 | + | return nil, err | |||
| 1239 | + | } | |||
| 1240 | + | ||||
| 1241 | + | newPane, err := wm.createPane(newView) | |||
| 1242 | + | if err != nil { | |||
| 1243 | + | return nil, err | |||
| 1244 | + | } | |||
| 1245 | + | ||||
| 1246 | + | if handler := newPane.MessageHandler(); handler != nil { | |||
| 1247 | + | handler.SetWorkspaceObserver(wm) | |||
| 1248 | + | } | |||
| 1249 | + | ||||
| 1250 | + | newContainer := newPane.webView.RootWidget() | |||
| 1251 | + | if newContainer == 0 { | |||
| 1252 | + | return nil, errors.New("new pane missing container") | |||
| 1253 | + | } | |||
| 1254 | + | webkit.WidgetSetHExpand(newContainer, true) | |||
| 1255 | + | webkit.WidgetSetVExpand(newContainer, true) | |||
| 1256 | + | webkit.WidgetRealizeInContainer(newContainer) | |||
| 1257 | + | ||||
| 1258 | + | // If target is not already stacked, convert it to a stacked node | |||
| 1259 | + | if !target.isStacked { | |||
| 1260 | + | log.Printf("[workspace] converting pane to stacked: %p", target) | |||
| 1261 | + | ||||
| 1262 | + | // Create a vertical box container for the stack | |||
| 1263 | + | stackContainer := webkit.NewBox(webkit.OrientationVertical, 0) | |||
| 1264 | + | if stackContainer == 0 { | |||
| 1265 | + | return nil, errors.New("failed to create stack container") | |||
| 1266 | + | } | |||
| 1267 | + | webkit.WidgetSetHExpand(stackContainer, true) | |||
| 1268 | + | webkit.WidgetSetVExpand(stackContainer, true) | |||
| 1269 | + | ||||
| 1270 | + | // Get the existing container and parent info | |||
| 1271 | + | existingContainer := target.container | |||
| 1272 | + | parent := target.parent | |||
| 1273 | + | ||||
| 1274 | + | // Detach existing container from its parent | |||
| 1275 | + | if parent == nil { | |||
| 1276 | + | // Target is the root - remove it from window | |||
| 1277 | + | if wm.window != nil { | |||
| 1278 | + | wm.window.SetChild(0) | |||
| 1279 | + | } | |||
| 1280 | + | } else if parent.container != 0 { | |||
| 1281 | + | // Target has a parent - unparent it | |||
| 1282 | + | if parent.left == target { | |||
| 1283 | + | webkit.PanedSetStartChild(parent.container, 0) | |||
| 1284 | + | } else if parent.right == target { | |||
| 1285 | + | webkit.PanedSetEndChild(parent.container, 0) | |||
| 1286 | + | } | |||
| 1287 | + | } | |||
| 1288 | + | ||||
| 1289 | + | webkit.WidgetUnparent(existingContainer) | |||
| 1290 | + | ||||
| 1291 | + | // Create title bar for the existing pane | |||
| 1292 | + | titleBar := wm.createTitleBar(target) | |||
| 1293 | + | ||||
| 1294 | + | // Add ONLY the title bar for the first pane to the stack container initially | |||
| 1295 | + | // The webview content will be added when this pane becomes active | |||
| 1296 | + | webkit.BoxAppend(stackContainer, titleBar) | |||
| 1297 | + | webkit.BoxAppend(stackContainer, existingContainer) | |||
| 1298 | + | ||||
| 1299 | + | // Convert target to a stacked node but keep it as a leaf for content management | |||
| 1300 | + | target.isStacked = true | |||
| 1301 | + | target.isLeaf = true // Keep as leaf so updateStackVisibility works correctly | |||
| 1302 | + | target.container = existingContainer // Keep original container for visibility control | |||
| 1303 | + | target.titleBar = titleBar | |||
| 1304 | + | ||||
| 1305 | + | // Create a parent stacked container node | |||
| 1306 | + | stackNode := &paneNode{ | |||
| 1307 | + | isStacked: true, | |||
| 1308 | + | isLeaf: false, | |||
| 1309 | + | container: stackContainer, | |||
| 1310 | + | stackedPanes: []*paneNode{target}, | |||
| 1311 | + | activeStackIndex: 1, // NEW PANE WILL BE ACTIVE (index 1) | |||
| 1312 | + | parent: parent, | |||
| 1313 | + | } | |||
| 1314 | + | ||||
| 1315 | + | // Update target's parent to be the stack node | |||
| 1316 | + | target.parent = stackNode | |||
| 1317 | + | ||||
| 1318 | + | // Update parent references | |||
| 1319 | + | if parent == nil { | |||
| 1320 | + | wm.root = stackNode | |||
| 1321 | + | if wm.window != nil { | |||
| 1322 | + | wm.window.SetChild(stackContainer) | |||
| 1323 | + | } | |||
| 1324 | + | } else { | |||
| 1325 | + | if parent.left == target { | |||
| 1326 | + | parent.left = stackNode | |||
| 1327 | + | webkit.PanedSetStartChild(parent.container, stackContainer) | |||
| 1328 | + | } else if parent.right == target { | |||
| 1329 | + | parent.right = stackNode | |||
| 1330 | + | webkit.PanedSetEndChild(parent.container, stackContainer) | |||
| 1331 | + | } | |||
| 1332 | + | } | |||
| 1333 | + | ||||
| 1334 | + | // Update target to point to the stack node for further operations | |||
| 1335 | + | target = stackNode | |||
| 1336 | + | } | |||
| 1337 | + | ||||
| 1338 | + | // Create new leaf node for the new pane | |||
| 1339 | + | newLeaf := &paneNode{ | |||
| 1340 | + | pane: newPane, | |||
| 1341 | + | parent: target, | |||
| 1342 | + | container: newContainer, | |||
| 1343 | + | isLeaf: true, | |||
| 1344 | + | } | |||
| 1345 | + | ||||
| 1346 | + | // Create title bar for the new pane | |||
| 1347 | + | newTitleBar := wm.createTitleBar(newLeaf) | |||
| 1348 | + | newLeaf.titleBar = newTitleBar | |||
| 1349 | + | ||||
| 1350 | + | // Add new pane to the stack | |||
| 1351 | + | target.stackedPanes = append(target.stackedPanes, newLeaf) | |||
| 1352 | + | webkit.BoxAppend(target.container, newTitleBar) | |||
| 1353 | + | ||||
| 1354 | + | // Unparent the new container before adding it to the stack | |||
| 1355 | + | webkit.WidgetUnparent(newContainer) | |||
| 1356 | + | webkit.BoxAppend(target.container, newContainer) | |||
| 1357 | + | ||||
| 1358 | + | // Ensure the activeStackIndex is correct (should be 1 for the new pane) | |||
| 1359 | + | target.activeStackIndex = len(target.stackedPanes) - 1 | |||
| 1360 | + | ||||
| 1361 | + | // Update workspace state FIRST | |||
| 1362 | + | wm.viewToNode[newPane.webView] = newLeaf | |||
| 1363 | + | wm.ensureHover(newLeaf) | |||
| 1364 | + | wm.app.panes = append(wm.app.panes, newPane) | |||
| 1365 | + | if newPane.zoomController != nil { | |||
| 1366 | + | newPane.zoomController.ApplyInitialZoom() | |||
| 1367 | + | } | |||
| 1368 | + | ||||
| 1369 | + | // Update CSS classes | |||
| 1370 | + | wm.ensurePaneBaseClasses() | |||
| 1371 | + | ||||
| 1372 | + | // Show the new container immediately | |||
| 1373 | + | webkit.WidgetShow(newContainer) | |||
| 1374 | + | ||||
| 1375 | + | // Update stack visibility to show the new pane as active | |||
| 1376 | + | wm.updateStackVisibility(target) | |||
| 1377 | + | ||||
| 1378 | + | // Focus the new pane IMMEDIATELY (not in IdleAdd) | |||
| 1379 | + | wm.focusNode(newLeaf) | |||
| 1380 | + | ||||
| 1381 | + | log.Printf("[workspace] stacked new pane: target=%p newLeaf=%p stackSize=%d activeIndex=%d", target, newLeaf, len(target.stackedPanes), target.activeStackIndex) | |||
| 1382 | + | return newLeaf, nil | |||
| 1383 | + | } | |||
| 1384 | + | ||||
| 1385 | + | // createTitleBar creates a title bar widget for a pane in a stack. | |||
| 1386 | + | func (wm *WorkspaceManager) createTitleBar(pane *paneNode) uintptr { | |||
| 1387 | + | titleBox := webkit.NewBox(webkit.OrientationHorizontal, 8) | |||
| 1388 | + | if titleBox == 0 { | |||
| 1389 | + | log.Printf("[workspace] failed to create title bar box") | |||
| 1390 | + | return 0 | |||
| 1391 | + | } | |||
| 1392 | + | ||||
| 1393 | + | webkit.WidgetSetHExpand(titleBox, true) | |||
| 1394 | + | webkit.WidgetSetVExpand(titleBox, false) | |||
| 1395 | + | ||||
| 1396 | + | // Create label for page title and domain | |||
| 1397 | + | title := "New Tab" | |||
| 1398 | + | if pane.pane != nil && pane.pane.webView != nil { | |||
| 1399 | + | if pageTitle := pane.pane.webView.GetTitle(); pageTitle != "" { | |||
| 1400 | + | title = pageTitle | |||
| 1401 | + | } | |||
| 1402 | + | } | |||
| 1403 | + | ||||
| 1404 | + | label := webkit.NewLabel(title) | |||
| 1405 | + | if label != 0 { | |||
| 1406 | + | webkit.LabelSetEllipsize(label, webkit.EllipsizeEnd) | |||
| 1407 | + | webkit.WidgetSetHExpand(label, true) | |||
| 1408 | + | webkit.BoxAppend(titleBox, label) | |||
| 1409 | + | } | |||
| 1410 | + | ||||
| 1411 | + | // Add CSS classes | |||
| 1412 | + | webkit.WidgetAddCSSClass(titleBox, "stacked-pane-title") | |||
| 1413 | + | webkit.WidgetAddCSSClass(label, "stacked-pane-title-text") | |||
| 1414 | + | ||||
| 1415 | + | log.Printf("[workspace] created title bar: box=%#x label=%#x title=%s", titleBox, label, title) | |||
| 1416 | + | return titleBox | |||
| 1417 | + | } | |||
| 1418 | + | ||||
| 1419 | + | // updateStackVisibility updates the visibility of panes in a stack. | |||
| 1420 | + | func (wm *WorkspaceManager) updateStackVisibility(stackNode *paneNode) { | |||
| 1421 | + | if !stackNode.isStacked || len(stackNode.stackedPanes) == 0 { | |||
| 1422 | + | return | |||
| 1423 | + | } | |||
| 1424 | + | ||||
| 1425 | + | activeIndex := stackNode.activeStackIndex | |||
| 1426 | + | if activeIndex < 0 || activeIndex >= len(stackNode.stackedPanes) { | |||
| 1427 | + | activeIndex = 0 | |||
| 1428 | + | stackNode.activeStackIndex = activeIndex | |||
| 1429 | + | } | |||
| 1430 | + | ||||
| 1431 | + | log.Printf("[workspace] updating stack visibility: activeIndex=%d stackSize=%d", activeIndex, len(stackNode.stackedPanes)) | |||
| 1432 | + | ||||
| 1433 | + | for i, pane := range stackNode.stackedPanes { | |||
| 1434 | + | if i == activeIndex { | |||
| 1435 | + | // Show active pane's content, hide its title bar | |||
| 1436 | + | webkit.WidgetSetVisible(pane.container, true) | |||
| 1437 | + | webkit.WidgetSetVisible(pane.titleBar, false) | |||
| 1438 | + | webkit.WidgetAddCSSClass(pane.container, "stacked-pane-active") | |||
| 1439 | + | webkit.WidgetRemoveCSSClass(pane.container, "stacked-pane-collapsed") | |||
| 1440 | + | } else { | |||
| 1441 | + | // Hide inactive pane's content, show its title bar | |||
| 1442 | + | webkit.WidgetSetVisible(pane.container, false) | |||
| 1443 | + | webkit.WidgetSetVisible(pane.titleBar, true) | |||
| 1444 | + | webkit.WidgetAddCSSClass(pane.container, "stacked-pane-collapsed") | |||
| 1445 | + | webkit.WidgetRemoveCSSClass(pane.container, "stacked-pane-active") | |||
| 1446 | + | } | |||
| 1447 | + | } | |||
| 1448 | + | } | |||
| 1449 | + | ||||
| 1044 | func (wm *WorkspaceManager) clonePaneState(_ *paneNode, target *paneNode) { | 1450 | func (wm *WorkspaceManager) clonePaneState(_ *paneNode, target *paneNode) { | ||
| 1045 | if wm == nil || target == nil { | 1451 | if wm == nil || target == nil { | ||
| 1046 | return | 1452 | return | ||
| @@ -1086,6 +1492,11 @@ func (wm *WorkspaceManager) closePane(node *paneNode) error { | |||||
| 1086 | return errors.New("close target missing webview") | 1492 | return errors.New("close target missing webview") | ||
| 1087 | } | 1493 | } | ||
| 1088 | 1494 | ||||
| 1495 | + | // Handle closing panes in a stack | |||
| 1496 | + | if node.parent != nil && node.parent.isStacked { | |||
| 1497 | + | return wm.closeStackedPane(node) | |||
| 1498 | + | } | |||
| 1499 | + | ||||
| 1089 | if node.parent != nil && node.parent.container != 0 { | 1500 | if node.parent != nil && node.parent.container != 0 { | ||
| 1090 | if node.parent.left == node { | 1501 | if node.parent.left == node { | ||
| 1091 | webkit.PanedSetStartChild(node.parent.container, 0) | 1502 | webkit.PanedSetStartChild(node.parent.container, 0) | ||
| @@ -1466,6 +1877,141 @@ func (wm *WorkspaceManager) findReplacementRoot(excludeNode *paneNode) *paneNode | |||||
| 1466 | return nil | 1877 | return nil | ||
| 1467 | } | 1878 | } | ||
| 1468 | 1879 | ||||
| 1880 | + | // closeStackedPane handles closing a pane that is part of a stack. | |||
| 1881 | + | func (wm *WorkspaceManager) closeStackedPane(node *paneNode) error { | |||
| 1882 | + | if node.parent == nil || !node.parent.isStacked { | |||
| 1883 | + | return errors.New("node is not part of a stacked pane") | |||
| 1884 | + | } | |||
| 1885 | + | ||||
| 1886 | + | stackNode := node.parent | |||
| 1887 | + | ||||
| 1888 | + | // Find the index of the node to be closed | |||
| 1889 | + | nodeIndex := -1 | |||
| 1890 | + | for i, stackedPane := range stackNode.stackedPanes { | |||
| 1891 | + | if stackedPane == node { | |||
| 1892 | + | nodeIndex = i | |||
| 1893 | + | break | |||
| 1894 | + | } | |||
| 1895 | + | } | |||
| 1896 | + | ||||
| 1897 | + | if nodeIndex == -1 { | |||
| 1898 | + | return errors.New("node not found in stack") | |||
| 1899 | + | } | |||
| 1900 | + | ||||
| 1901 | + | log.Printf("[workspace] closing stacked pane: index=%d stackSize=%d", nodeIndex, len(stackNode.stackedPanes)) | |||
| 1902 | + | ||||
| 1903 | + | // Clean up the pane | |||
| 1904 | + | wm.detachHover(node) | |||
| 1905 | + | delete(wm.viewToNode, node.pane.webView) | |||
| 1906 | + | ||||
| 1907 | + | // Remove from app.panes | |||
| 1908 | + | for i, pane := range wm.app.panes { | |||
| 1909 | + | if pane == node.pane { | |||
| 1910 | + | wm.app.panes = append(wm.app.panes[:i], wm.app.panes[i+1:]...) | |||
| 1911 | + | break | |||
| 1912 | + | } | |||
| 1913 | + | } | |||
| 1914 | + | ||||
| 1915 | + | // Remove the pane's widgets from the stack container | |||
| 1916 | + | if node.titleBar != 0 { | |||
| 1917 | + | webkit.BoxRemove(stackNode.container, node.titleBar) | |||
| 1918 | + | } | |||
| 1919 | + | if node.container != 0 { | |||
| 1920 | + | webkit.BoxRemove(stackNode.container, node.container) | |||
| 1921 | + | webkit.WidgetUnparent(node.container) | |||
| 1922 | + | } | |||
| 1923 | + | ||||
| 1924 | + | // Clean up the pane | |||
| 1925 | + | node.pane.Cleanup() | |||
| 1926 | + | ||||
| 1927 | + | // Remove from the stack | |||
| 1928 | + | stackNode.stackedPanes = append(stackNode.stackedPanes[:nodeIndex], stackNode.stackedPanes[nodeIndex+1:]...) | |||
| 1929 | + | ||||
| 1930 | + | // Handle the remaining panes in the stack | |||
| 1931 | + | if len(stackNode.stackedPanes) == 0 { | |||
| 1932 | + | // No panes left in stack - this should not happen normally | |||
| 1933 | + | log.Printf("[workspace] warning: empty stack after closing pane") | |||
| 1934 | + | return errors.New("stack became empty") | |||
| 1935 | + | } else if len(stackNode.stackedPanes) == 1 { | |||
| 1936 | + | // Only one pane left - convert back to a regular pane | |||
| 1937 | + | lastPane := stackNode.stackedPanes[0] | |||
| 1938 | + | ||||
| 1939 | + | // Remove the title bar since we're going back to single pane | |||
| 1940 | + | if lastPane.titleBar != 0 { | |||
| 1941 | + | webkit.BoxRemove(stackNode.container, lastPane.titleBar) | |||
| 1942 | + | } | |||
| 1943 | + | ||||
| 1944 | + | // Replace the stack container with the pane's container | |||
| 1945 | + | parent := stackNode.parent | |||
| 1946 | + | lastPaneContainer := lastPane.container | |||
| 1947 | + | ||||
| 1948 | + | // Unparent from stack container | |||
| 1949 | + | webkit.BoxRemove(stackNode.container, lastPaneContainer) | |||
| 1950 | + | webkit.WidgetUnparent(lastPaneContainer) | |||
| 1951 | + | ||||
| 1952 | + | // Convert back to regular pane structure | |||
| 1953 | + | lastPane.parent = parent | |||
| 1954 | + | lastPane.isStacked = false | |||
| 1955 | + | lastPane.stackedPanes = nil | |||
| 1956 | + | lastPane.titleBar = 0 | |||
| 1957 | + | stackNode.isStacked = false | |||
| 1958 | + | stackNode.stackedPanes = nil | |||
| 1959 | + | stackNode.container = lastPaneContainer | |||
| 1960 | + | stackNode.isLeaf = true | |||
| 1961 | + | stackNode.pane = lastPane.pane | |||
| 1962 | + | ||||
| 1963 | + | // Update parent references | |||
| 1964 | + | if parent == nil { | |||
| 1965 | + | wm.root = stackNode | |||
| 1966 | + | if wm.window != nil { | |||
| 1967 | + | wm.window.SetChild(lastPaneContainer) | |||
| 1968 | + | } | |||
| 1969 | + | } else { | |||
| 1970 | + | if parent.left == stackNode { | |||
| 1971 | + | webkit.PanedSetStartChild(parent.container, lastPaneContainer) | |||
| 1972 | + | } else if parent.right == stackNode { | |||
| 1973 | + | webkit.PanedSetEndChild(parent.container, lastPaneContainer) | |||
| 1974 | + | } | |||
| 1975 | + | } | |||
| 1976 | + | ||||
| 1977 | + | // Update the viewToNode mapping | |||
| 1978 | + | wm.viewToNode[lastPane.pane.webView] = stackNode | |||
| 1979 | + | ||||
| 1980 | + | // Focus the remaining pane if it was the active one being closed | |||
| 1981 | + | if wm.active == node { | |||
| 1982 | + | wm.focusNode(stackNode) | |||
| 1983 | + | } | |||
| 1984 | + | ||||
| 1985 | + | log.Printf("[workspace] converted single-pane stack back to regular pane") | |||
| 1986 | + | } else { | |||
| 1987 | + | // Multiple panes remain in stack - adjust active index | |||
| 1988 | + | if stackNode.activeStackIndex >= nodeIndex && stackNode.activeStackIndex > 0 { | |||
| 1989 | + | stackNode.activeStackIndex-- | |||
| 1990 | + | } | |||
| 1991 | + | if stackNode.activeStackIndex >= len(stackNode.stackedPanes) { | |||
| 1992 | + | stackNode.activeStackIndex = len(stackNode.stackedPanes) - 1 | |||
| 1993 | + | } | |||
| 1994 | + | ||||
| 1995 | + | // Update visibility for remaining panes | |||
| 1996 | + | wm.updateStackVisibility(stackNode) | |||
| 1997 | + | ||||
| 1998 | + | // Focus the new active pane if we closed the currently active one | |||
| 1999 | + | if wm.active == node { | |||
| 2000 | + | newActivePaneInStack := stackNode.stackedPanes[stackNode.activeStackIndex] | |||
| 2001 | + | wm.focusNode(newActivePaneInStack) | |||
| 2002 | + | } | |||
| 2003 | + | ||||
| 2004 | + | log.Printf("[workspace] closed pane from stack: remaining=%d activeIndex=%d", | |||
| 2005 | + | len(stackNode.stackedPanes), stackNode.activeStackIndex) | |||
| 2006 | + | } | |||
| 2007 | + | ||||
| 2008 | + | // Update CSS classes after pane count changes | |||
| 2009 | + | wm.ensurePaneBaseClasses() | |||
| 2010 | + | log.Printf("[workspace] stacked pane closed; panes remaining=%d", len(wm.app.panes)) | |||
| 2011 | + | ||||
| 2012 | + | return nil | |||
| 2013 | + | } | |||
| 2014 | + | ||||
| 1469 | func (wm *WorkspaceManager) updateMainPane() { | 2015 | func (wm *WorkspaceManager) updateMainPane() { | ||
| 1470 | if len(wm.app.panes) == 1 { | 2016 | if len(wm.app.panes) == 1 { | ||
| 1471 | if leaf := wm.viewToNode[wm.app.panes[0].webView]; leaf != nil { | 2017 | if leaf := wm.viewToNode[wm.app.panes[0].webView]; leaf != nil { | ||
M internal/services/browser.go +0 -1
| @@ -589,7 +589,6 @@ func zoomKeyFromURL(raw string) string { | |||
| 589 | 589 | // ZoomKeyForLog exposes the derived zoom key (host or raw URL) for logging from other packages. | |
| 590 | 590 | func ZoomKeyForLog(raw string) string { return zoomKeyFromURL(raw) } | |
| 591 | 591 | ||
| 592 | - | ||
| 593 | 592 | // handleFaviconChanged processes favicon data received from WebKit (legacy binary data method) | |
| 594 | 593 | func (s *BrowserService) handleFaviconChanged(pageURL string, pngData []byte) { | |
| 595 | 594 | log.Printf("[favicon] Processing favicon for %s, data size: %d bytes", pageURL, len(pngData)) | |
| @@ -589,7 +589,6 @@ func zoomKeyFromURL(raw string) string { | |||||
| 589 | // ZoomKeyForLog exposes the derived zoom key (host or raw URL) for logging from other packages. | 589 | // ZoomKeyForLog exposes the derived zoom key (host or raw URL) for logging from other packages. | ||
| 590 | func ZoomKeyForLog(raw string) string { return zoomKeyFromURL(raw) } | 590 | func ZoomKeyForLog(raw string) string { return zoomKeyFromURL(raw) } | ||
| 591 | 591 | ||||
| 592 | - | ||||
| 593 | // handleFaviconChanged processes favicon data received from WebKit (legacy binary data method) | 592 | // handleFaviconChanged processes favicon data received from WebKit (legacy binary data method) | ||
| 594 | func (s *BrowserService) handleFaviconChanged(pageURL string, pngData []byte) { | 593 | func (s *BrowserService) handleFaviconChanged(pageURL string, pngData []byte) { | ||
| 595 | log.Printf("[favicon] Processing favicon for %s, data size: %d bytes", pageURL, len(pngData)) | 594 | log.Printf("[favicon] Processing favicon for %s, data size: %d bytes", pageURL, len(pngData)) | ||
M pkg/webkit/memory.go +13 -2
| @@ -27,6 +27,7 @@ type WebViewMemoryManager struct { | |||
| 27 | 27 | recycleThreshold int | |
| 28 | 28 | monitoringInterval time.Duration | |
| 29 | 29 | stopMonitoring chan struct{} | |
| 30 | + | lastLoggedMemory int64 | |
| 30 | 31 | } | |
| 31 | 32 | ||
| 32 | 33 | // NewWebViewMemoryManager creates a new memory manager | |
| @@ -105,9 +106,19 @@ func (mgr *WebViewMemoryManager) checkMemoryUsage() { | |||
| 105 | 106 | totalMemory += proc.VmRSS | |
| 106 | 107 | } | |
| 107 | 108 | ||
| 109 | + | // Only log if memory usage changed by more than 10MB (10240 KB) | |
| 110 | + | const memoryChangeThreshold = 10240 // 10MB in KB | |
| 108 | 111 | if mgr.enableMonitoring { | |
| 109 | - | log.Printf("[webkit] Memory usage: %d processes, total %.1f MB RSS", | |
| 110 | - | len(processes), float64(totalMemory)/1024.0) | |
| 112 | + | memoryDiff := totalMemory - mgr.lastLoggedMemory | |
| 113 | + | if memoryDiff < 0 { | |
| 114 | + | memoryDiff = -memoryDiff | |
| 115 | + | } | |
| 116 | + | ||
| 117 | + | if mgr.lastLoggedMemory == 0 || memoryDiff >= memoryChangeThreshold { | |
| 118 | + | log.Printf("[webkit] Memory usage: %d processes, total %.1f MB RSS", | |
| 119 | + | len(processes), float64(totalMemory)/1024.0) | |
| 120 | + | mgr.lastLoggedMemory = totalMemory | |
| 121 | + | } | |
| 111 | 122 | } | |
| 112 | 123 | ||
| 113 | 124 | // Check for recycling needs | |
| @@ -27,6 +27,7 @@ type WebViewMemoryManager struct { | |||||
| 27 | recycleThreshold int | 27 | recycleThreshold int | ||
| 28 | monitoringInterval time.Duration | 28 | monitoringInterval time.Duration | ||
| 29 | stopMonitoring chan struct{} | 29 | stopMonitoring chan struct{} | ||
| 30 | + | lastLoggedMemory int64 | |||
| 30 | } | 31 | } | ||
| 31 | 32 | ||||
| 32 | // NewWebViewMemoryManager creates a new memory manager | 33 | // NewWebViewMemoryManager creates a new memory manager | ||
| @@ -105,9 +106,19 @@ func (mgr *WebViewMemoryManager) checkMemoryUsage() { | |||||
| 105 | totalMemory += proc.VmRSS | 106 | totalMemory += proc.VmRSS | ||
| 106 | } | 107 | } | ||
| 107 | 108 | ||||
| 109 | + | // Only log if memory usage changed by more than 10MB (10240 KB) | |||
| 110 | + | const memoryChangeThreshold = 10240 // 10MB in KB | |||
| 108 | if mgr.enableMonitoring { | 111 | if mgr.enableMonitoring { | ||
| 109 | - | log.Printf("[webkit] Memory usage: %d processes, total %.1f MB RSS", | 112 | + | memoryDiff := totalMemory - mgr.lastLoggedMemory |
| 110 | - | len(processes), float64(totalMemory)/1024.0) | 113 | + | if memoryDiff < 0 { |
| 114 | + | memoryDiff = -memoryDiff | |||
| 115 | + | } | |||
| 116 | + | ||||
| 117 | + | if mgr.lastLoggedMemory == 0 || memoryDiff >= memoryChangeThreshold { | |||
| 118 | + | log.Printf("[webkit] Memory usage: %d processes, total %.1f MB RSS", | |||
| 119 | + | len(processes), float64(totalMemory)/1024.0) | |||
| 120 | + | mgr.lastLoggedMemory = totalMemory | |||
| 121 | + | } | |||
| 111 | } | 122 | } | ||
| 112 | 123 | ||||
| 113 | // Check for recycling needs | 124 | // Check for recycling needs | ||
M pkg/webkit/webview.go +3 -0
| @@ -125,6 +125,9 @@ func (w *WebView) Window() *Window { return w.window } | |||
| 125 | 125 | // GetCurrentURL returns the last requested URL (non-CGO build approximation). | |
| 126 | 126 | func (w *WebView) GetCurrentURL() string { return w.url } | |
| 127 | 127 | ||
| 128 | + | // GetTitle returns a stub page title. | |
| 129 | + | func (w *WebView) GetTitle() string { return "New Tab" } | |
| 130 | + | ||
| 128 | 131 | // GoBack is not supported in the non-CGO stub. | |
| 129 | 132 | func (w *WebView) GoBack() error { return ErrNotImplemented } | |
| 130 | 133 | ||
| @@ -125,6 +125,9 @@ func (w *WebView) Window() *Window { return w.window } | |||||
| 125 | // GetCurrentURL returns the last requested URL (non-CGO build approximation). | 125 | // GetCurrentURL returns the last requested URL (non-CGO build approximation). | ||
| 126 | func (w *WebView) GetCurrentURL() string { return w.url } | 126 | func (w *WebView) GetCurrentURL() string { return w.url } | ||
| 127 | 127 | ||||
| 128 | + | // GetTitle returns a stub page title. | |||
| 129 | + | func (w *WebView) GetTitle() string { return "New Tab" } | |||
| 130 | + | ||||
| 128 | // GoBack is not supported in the non-CGO stub. | 131 | // GoBack is not supported in the non-CGO stub. | ||
| 129 | func (w *WebView) GoBack() error { return ErrNotImplemented } | 132 | func (w *WebView) GoBack() error { return ErrNotImplemented } | ||
| 130 | 133 | ||||
M pkg/webkit/webview_cgo.go +12 -0
| @@ -1696,6 +1696,18 @@ func (w *WebView) GetCurrentURL() string { | |||
| 1696 | 1696 | return C.GoString((*C.char)(unsafe.Pointer(uri))) | |
| 1697 | 1697 | } | |
| 1698 | 1698 | ||
| 1699 | + | // GetTitle returns the current page title from WebKit. | |
| 1700 | + | func (w *WebView) GetTitle() string { | |
| 1701 | + | if w == nil || w.native == nil || w.native.wv == nil { | |
| 1702 | + | return "" | |
| 1703 | + | } | |
| 1704 | + | title := C.webkit_web_view_get_title(w.native.wv) | |
| 1705 | + | if title == nil { | |
| 1706 | + | return "" | |
| 1707 | + | } | |
| 1708 | + | return C.GoString((*C.char)(unsafe.Pointer(title))) | |
| 1709 | + | } | |
| 1710 | + | ||
| 1699 | 1711 | func (w *WebView) GoBack() error { | |
| 1700 | 1712 | if w == nil || w.native == nil || w.native.wv == nil { | |
| 1701 | 1713 | return ErrNotImplemented | |
| @@ -1696,6 +1696,18 @@ func (w *WebView) GetCurrentURL() string { | |||||
| 1696 | return C.GoString((*C.char)(unsafe.Pointer(uri))) | 1696 | return C.GoString((*C.char)(unsafe.Pointer(uri))) | ||
| 1697 | } | 1697 | } | ||
| 1698 | 1698 | ||||
| 1699 | + | // GetTitle returns the current page title from WebKit. | |||
| 1700 | + | func (w *WebView) GetTitle() string { | |||
| 1701 | + | if w == nil || w.native == nil || w.native.wv == nil { | |||
| 1702 | + | return "" | |||
| 1703 | + | } | |||
| 1704 | + | title := C.webkit_web_view_get_title(w.native.wv) | |||
| 1705 | + | if title == nil { | |||
| 1706 | + | return "" | |||
| 1707 | + | } | |||
| 1708 | + | return C.GoString((*C.char)(unsafe.Pointer(title))) | |||
| 1709 | + | } | |||
| 1710 | + | ||||
| 1699 | func (w *WebView) GoBack() error { | 1711 | func (w *WebView) GoBack() error { | ||
| 1700 | if w == nil || w.native == nil || w.native.wv == nil { | 1712 | if w == nil || w.native == nil || w.native.wv == nil { | ||
| 1701 | return ErrNotImplemented | 1713 | return ErrNotImplemented | ||
M pkg/webkit/workspace_widgets_cgo.go +188 -0
| @@ -147,6 +147,72 @@ static void widget_remove_css_class(GtkWidget* widget, const char* name) { | |||
| 147 | 147 | if (!widget || !name) return; | |
| 148 | 148 | gtk_widget_remove_css_class(widget, name); | |
| 149 | 149 | } | |
| 150 | + | ||
| 151 | + | // GtkBox helpers for stacked panes | |
| 152 | + | static GtkWidget* box_new(GtkOrientation orientation, int spacing) { | |
| 153 | + | return gtk_box_new(orientation, spacing); | |
| 154 | + | } | |
| 155 | + | ||
| 156 | + | static void box_append(GtkWidget* box, GtkWidget* child) { | |
| 157 | + | if (!box || !child) return; | |
| 158 | + | gtk_box_append(GTK_BOX(box), child); | |
| 159 | + | } | |
| 160 | + | ||
| 161 | + | static void box_prepend(GtkWidget* box, GtkWidget* child) { | |
| 162 | + | if (!box || !child) return; | |
| 163 | + | gtk_box_prepend(GTK_BOX(box), child); | |
| 164 | + | } | |
| 165 | + | ||
| 166 | + | static void box_remove(GtkWidget* box, GtkWidget* child) { | |
| 167 | + | if (!box || !child) return; | |
| 168 | + | gtk_box_remove(GTK_BOX(box), child); | |
| 169 | + | } | |
| 170 | + | ||
| 171 | + | static void box_insert_child_after(GtkWidget* box, GtkWidget* child, GtkWidget* sibling) { | |
| 172 | + | if (!box || !child) return; | |
| 173 | + | gtk_box_insert_child_after(GTK_BOX(box), child, sibling); | |
| 174 | + | } | |
| 175 | + | ||
| 176 | + | // Widget visibility helpers for stacked panes | |
| 177 | + | static void widget_set_visible(GtkWidget* widget, gboolean visible) { | |
| 178 | + | if (!widget) return; | |
| 179 | + | gtk_widget_set_visible(widget, visible); | |
| 180 | + | } | |
| 181 | + | ||
| 182 | + | static gboolean widget_get_visible(GtkWidget* widget) { | |
| 183 | + | if (!widget) return FALSE; | |
| 184 | + | return gtk_widget_get_visible(widget); | |
| 185 | + | } | |
| 186 | + | ||
| 187 | + | static void widget_hide(GtkWidget* widget) { | |
| 188 | + | if (!widget) return; | |
| 189 | + | gtk_widget_set_visible(widget, FALSE); | |
| 190 | + | } | |
| 191 | + | ||
| 192 | + | static void widget_show(GtkWidget* widget) { | |
| 193 | + | if (!widget) return; | |
| 194 | + | gtk_widget_set_visible(widget, TRUE); | |
| 195 | + | } | |
| 196 | + | ||
| 197 | + | // Label helpers for title bars | |
| 198 | + | static GtkWidget* label_new(const char* text) { | |
| 199 | + | return gtk_label_new(text); | |
| 200 | + | } | |
| 201 | + | ||
| 202 | + | static void label_set_text(GtkWidget* label, const char* text) { | |
| 203 | + | if (!label || !text) return; | |
| 204 | + | gtk_label_set_text(GTK_LABEL(label), text); | |
| 205 | + | } | |
| 206 | + | ||
| 207 | + | static const char* label_get_text(GtkWidget* label) { | |
| 208 | + | if (!label) return NULL; | |
| 209 | + | return gtk_label_get_text(GTK_LABEL(label)); | |
| 210 | + | } | |
| 211 | + | ||
| 212 | + | static void label_set_ellipsize(GtkWidget* label, int mode) { | |
| 213 | + | if (!label) return; | |
| 214 | + | gtk_label_set_ellipsize(GTK_LABEL(label), (PangoEllipsizeMode)mode); | |
| 215 | + | } | |
| 150 | 216 | */ | |
| 151 | 217 | import "C" | |
| 152 | 218 | ||
| @@ -546,3 +612,125 @@ func goHoverCallback(handle C.uintptr_t) { | |||
| 546 | 612 | fn() | |
| 547 | 613 | } | |
| 548 | 614 | } | |
| 615 | + | ||
| 616 | + | // GtkBox functions for stacked panes | |
| 617 | + | ||
| 618 | + | // NewBox creates a new GtkBox widget with the specified orientation and spacing. | |
| 619 | + | func NewBox(orientation Orientation, spacing int) uintptr { | |
| 620 | + | box := C.box_new(C.GtkOrientation(orientation), C.int(spacing)) | |
| 621 | + | return uintptr(unsafe.Pointer(box)) | |
| 622 | + | } | |
| 623 | + | ||
| 624 | + | // BoxAppend adds a child widget to the end of a GtkBox. | |
| 625 | + | func BoxAppend(box uintptr, child uintptr) { | |
| 626 | + | if box == 0 || child == 0 { | |
| 627 | + | return | |
| 628 | + | } | |
| 629 | + | log.Printf("[workspace] BoxAppend box=%#x child=%#x", box, child) | |
| 630 | + | C.box_append((*C.GtkWidget)(unsafe.Pointer(box)), (*C.GtkWidget)(unsafe.Pointer(child))) | |
| 631 | + | } | |
| 632 | + | ||
| 633 | + | // BoxPrepend adds a child widget to the beginning of a GtkBox. | |
| 634 | + | func BoxPrepend(box uintptr, child uintptr) { | |
| 635 | + | if box == 0 || child == 0 { | |
| 636 | + | return | |
| 637 | + | } | |
| 638 | + | log.Printf("[workspace] BoxPrepend box=%#x child=%#x", box, child) | |
| 639 | + | C.box_prepend((*C.GtkWidget)(unsafe.Pointer(box)), (*C.GtkWidget)(unsafe.Pointer(child))) | |
| 640 | + | } | |
| 641 | + | ||
| 642 | + | // BoxRemove removes a child widget from a GtkBox. | |
| 643 | + | func BoxRemove(box uintptr, child uintptr) { | |
| 644 | + | if box == 0 || child == 0 { | |
| 645 | + | return | |
| 646 | + | } | |
| 647 | + | log.Printf("[workspace] BoxRemove box=%#x child=%#x", box, child) | |
| 648 | + | C.box_remove((*C.GtkWidget)(unsafe.Pointer(box)), (*C.GtkWidget)(unsafe.Pointer(child))) | |
| 649 | + | } | |
| 650 | + | ||
| 651 | + | // BoxInsertChildAfter inserts a child widget after a sibling in a GtkBox. | |
| 652 | + | func BoxInsertChildAfter(box uintptr, child uintptr, sibling uintptr) { | |
| 653 | + | if box == 0 || child == 0 { | |
| 654 | + | return | |
| 655 | + | } | |
| 656 | + | log.Printf("[workspace] BoxInsertChildAfter box=%#x child=%#x sibling=%#x", box, child, sibling) | |
| 657 | + | C.box_insert_child_after((*C.GtkWidget)(unsafe.Pointer(box)), (*C.GtkWidget)(unsafe.Pointer(child)), (*C.GtkWidget)(unsafe.Pointer(sibling))) | |
| 658 | + | } | |
| 659 | + | ||
| 660 | + | // Widget visibility functions for stacked panes | |
| 661 | + | ||
| 662 | + | // WidgetSetVisible sets the visibility state of a widget. | |
| 663 | + | func WidgetSetVisible(widget uintptr, visible bool) { | |
| 664 | + | if widget == 0 { | |
| 665 | + | return | |
| 666 | + | } | |
| 667 | + | log.Printf("[workspace] WidgetSetVisible widget=%#x visible=%v", widget, visible) | |
| 668 | + | C.widget_set_visible((*C.GtkWidget)(unsafe.Pointer(widget)), goBool(visible)) | |
| 669 | + | } | |
| 670 | + | ||
| 671 | + | // WidgetGetVisible returns the visibility state of a widget. | |
| 672 | + | func WidgetGetVisible(widget uintptr) bool { | |
| 673 | + | if widget == 0 { | |
| 674 | + | return false | |
| 675 | + | } | |
| 676 | + | return C.widget_get_visible((*C.GtkWidget)(unsafe.Pointer(widget))) != 0 | |
| 677 | + | } | |
| 678 | + | ||
| 679 | + | // WidgetHide hides a widget. | |
| 680 | + | func WidgetHide(widget uintptr) { | |
| 681 | + | if widget == 0 { | |
| 682 | + | return | |
| 683 | + | } | |
| 684 | + | log.Printf("[workspace] WidgetHide widget=%#x", widget) | |
| 685 | + | C.widget_hide((*C.GtkWidget)(unsafe.Pointer(widget))) | |
| 686 | + | } | |
| 687 | + | ||
| 688 | + | // Label functions for title bars | |
| 689 | + | ||
| 690 | + | // NewLabel creates a new GtkLabel widget with the specified text. | |
| 691 | + | func NewLabel(text string) uintptr { | |
| 692 | + | cstr := C.CString(text) | |
| 693 | + | defer C.free(unsafe.Pointer(cstr)) | |
| 694 | + | label := C.label_new(cstr) | |
| 695 | + | return uintptr(unsafe.Pointer(label)) | |
| 696 | + | } | |
| 697 | + | ||
| 698 | + | // LabelSetText sets the text of a GtkLabel. | |
| 699 | + | func LabelSetText(label uintptr, text string) { | |
| 700 | + | if label == 0 { | |
| 701 | + | return | |
| 702 | + | } | |
| 703 | + | cstr := C.CString(text) | |
| 704 | + | defer C.free(unsafe.Pointer(cstr)) | |
| 705 | + | C.label_set_text((*C.GtkWidget)(unsafe.Pointer(label)), cstr) | |
| 706 | + | } | |
| 707 | + | ||
| 708 | + | // LabelGetText returns the text of a GtkLabel. | |
| 709 | + | func LabelGetText(label uintptr) string { | |
| 710 | + | if label == 0 { | |
| 711 | + | return "" | |
| 712 | + | } | |
| 713 | + | cstr := C.label_get_text((*C.GtkWidget)(unsafe.Pointer(label))) | |
| 714 | + | if cstr == nil { | |
| 715 | + | return "" | |
| 716 | + | } | |
| 717 | + | return C.GoString(cstr) | |
| 718 | + | } | |
| 719 | + | ||
| 720 | + | // EllipsizeMode represents PangoEllipsizeMode values. | |
| 721 | + | type EllipsizeMode int | |
| 722 | + | ||
| 723 | + | const ( | |
| 724 | + | EllipsizeNone EllipsizeMode = 0 // PANGO_ELLIPSIZE_NONE | |
| 725 | + | EllipsizeStart EllipsizeMode = 1 // PANGO_ELLIPSIZE_START | |
| 726 | + | EllipsizeMiddle EllipsizeMode = 2 // PANGO_ELLIPSIZE_MIDDLE | |
| 727 | + | EllipsizeEnd EllipsizeMode = 3 // PANGO_ELLIPSIZE_END | |
| 728 | + | ) | |
| 729 | + | ||
| 730 | + | // LabelSetEllipsize sets the ellipsization mode for a GtkLabel. | |
| 731 | + | func LabelSetEllipsize(label uintptr, mode EllipsizeMode) { | |
| 732 | + | if label == 0 { | |
| 733 | + | return | |
| 734 | + | } | |
| 735 | + | C.label_set_ellipsize((*C.GtkWidget)(unsafe.Pointer(label)), C.int(mode)) | |
| 736 | + | } | |
| @@ -147,6 +147,72 @@ static void widget_remove_css_class(GtkWidget* widget, const char* name) { | |||||
| 147 | if (!widget || !name) return; | 147 | if (!widget || !name) return; | ||
| 148 | gtk_widget_remove_css_class(widget, name); | 148 | gtk_widget_remove_css_class(widget, name); | ||
| 149 | } | 149 | } | ||
| 150 | + | ||||
| 151 | + | // GtkBox helpers for stacked panes | |||
| 152 | + | static GtkWidget* box_new(GtkOrientation orientation, int spacing) { | |||
| 153 | + | return gtk_box_new(orientation, spacing); | |||
| 154 | + | } | |||
| 155 | + | ||||
| 156 | + | static void box_append(GtkWidget* box, GtkWidget* child) { | |||
| 157 | + | if (!box || !child) return; | |||
| 158 | + | gtk_box_append(GTK_BOX(box), child); | |||
| 159 | + | } | |||
| 160 | + | ||||
| 161 | + | static void box_prepend(GtkWidget* box, GtkWidget* child) { | |||
| 162 | + | if (!box || !child) return; | |||
| 163 | + | gtk_box_prepend(GTK_BOX(box), child); | |||
| 164 | + | } | |||
| 165 | + | ||||
| 166 | + | static void box_remove(GtkWidget* box, GtkWidget* child) { | |||
| 167 | + | if (!box || !child) return; | |||
| 168 | + | gtk_box_remove(GTK_BOX(box), child); | |||
| 169 | + | } | |||
| 170 | + | ||||
| 171 | + | static void box_insert_child_after(GtkWidget* box, GtkWidget* child, GtkWidget* sibling) { | |||
| 172 | + | if (!box || !child) return; | |||
| 173 | + | gtk_box_insert_child_after(GTK_BOX(box), child, sibling); | |||
| 174 | + | } | |||
| 175 | + | ||||
| 176 | + | // Widget visibility helpers for stacked panes | |||
| 177 | + | static void widget_set_visible(GtkWidget* widget, gboolean visible) { | |||
| 178 | + | if (!widget) return; | |||
| 179 | + | gtk_widget_set_visible(widget, visible); | |||
| 180 | + | } | |||
| 181 | + | ||||
| 182 | + | static gboolean widget_get_visible(GtkWidget* widget) { | |||
| 183 | + | if (!widget) return FALSE; | |||
| 184 | + | return gtk_widget_get_visible(widget); | |||
| 185 | + | } | |||
| 186 | + | ||||
| 187 | + | static void widget_hide(GtkWidget* widget) { | |||
| 188 | + | if (!widget) return; | |||
| 189 | + | gtk_widget_set_visible(widget, FALSE); | |||
| 190 | + | } | |||
| 191 | + | ||||
| 192 | + | static void widget_show(GtkWidget* widget) { | |||
| 193 | + | if (!widget) return; | |||
| 194 | + | gtk_widget_set_visible(widget, TRUE); | |||
| 195 | + | } | |||
| 196 | + | ||||
| 197 | + | // Label helpers for title bars | |||
| 198 | + | static GtkWidget* label_new(const char* text) { | |||
| 199 | + | return gtk_label_new(text); | |||
| 200 | + | } | |||
| 201 | + | ||||
| 202 | + | static void label_set_text(GtkWidget* label, const char* text) { | |||
| 203 | + | if (!label || !text) return; | |||
| 204 | + | gtk_label_set_text(GTK_LABEL(label), text); | |||
| 205 | + | } | |||
| 206 | + | ||||
| 207 | + | static const char* label_get_text(GtkWidget* label) { | |||
| 208 | + | if (!label) return NULL; | |||
| 209 | + | return gtk_label_get_text(GTK_LABEL(label)); | |||
| 210 | + | } | |||
| 211 | + | ||||
| 212 | + | static void label_set_ellipsize(GtkWidget* label, int mode) { | |||
| 213 | + | if (!label) return; | |||
| 214 | + | gtk_label_set_ellipsize(GTK_LABEL(label), (PangoEllipsizeMode)mode); | |||
| 215 | + | } | |||
| 150 | */ | 216 | */ | ||
| 151 | import "C" | 217 | import "C" | ||
| 152 | 218 | ||||
| @@ -546,3 +612,125 @@ func goHoverCallback(handle C.uintptr_t) { | |||||
| 546 | fn() | 612 | fn() | ||
| 547 | } | 613 | } | ||
| 548 | } | 614 | } | ||
| 615 | + | ||||
| 616 | + | // GtkBox functions for stacked panes | |||
| 617 | + | ||||
| 618 | + | // NewBox creates a new GtkBox widget with the specified orientation and spacing. | |||
| 619 | + | func NewBox(orientation Orientation, spacing int) uintptr { | |||
| 620 | + | box := C.box_new(C.GtkOrientation(orientation), C.int(spacing)) | |||
| 621 | + | return uintptr(unsafe.Pointer(box)) | |||
| 622 | + | } | |||
| 623 | + | ||||
| 624 | + | // BoxAppend adds a child widget to the end of a GtkBox. | |||
| 625 | + | func BoxAppend(box uintptr, child uintptr) { | |||
| 626 | + | if box == 0 || child == 0 { | |||
| 627 | + | return | |||
| 628 | + | } | |||
| 629 | + | log.Printf("[workspace] BoxAppend box=%#x child=%#x", box, child) | |||
| 630 | + | C.box_append((*C.GtkWidget)(unsafe.Pointer(box)), (*C.GtkWidget)(unsafe.Pointer(child))) | |||
| 631 | + | } | |||
| 632 | + | ||||
| 633 | + | // BoxPrepend adds a child widget to the beginning of a GtkBox. | |||
| 634 | + | func BoxPrepend(box uintptr, child uintptr) { | |||
| 635 | + | if box == 0 || child == 0 { | |||
| 636 | + | return | |||
| 637 | + | } | |||
| 638 | + | log.Printf("[workspace] BoxPrepend box=%#x child=%#x", box, child) | |||
| 639 | + | C.box_prepend((*C.GtkWidget)(unsafe.Pointer(box)), (*C.GtkWidget)(unsafe.Pointer(child))) | |||
| 640 | + | } | |||
| 641 | + | ||||
| 642 | + | // BoxRemove removes a child widget from a GtkBox. | |||
| 643 | + | func BoxRemove(box uintptr, child uintptr) { | |||
| 644 | + | if box == 0 || child == 0 { | |||
| 645 | + | return | |||
| 646 | + | } | |||
| 647 | + | log.Printf("[workspace] BoxRemove box=%#x child=%#x", box, child) | |||
| 648 | + | C.box_remove((*C.GtkWidget)(unsafe.Pointer(box)), (*C.GtkWidget)(unsafe.Pointer(child))) | |||
| 649 | + | } | |||
| 650 | + | ||||
| 651 | + | // BoxInsertChildAfter inserts a child widget after a sibling in a GtkBox. | |||
| 652 | + | func BoxInsertChildAfter(box uintptr, child uintptr, sibling uintptr) { | |||
| 653 | + | if box == 0 || child == 0 { | |||
| 654 | + | return | |||
| 655 | + | } | |||
| 656 | + | log.Printf("[workspace] BoxInsertChildAfter box=%#x child=%#x sibling=%#x", box, child, sibling) | |||
| 657 | + | C.box_insert_child_after((*C.GtkWidget)(unsafe.Pointer(box)), (*C.GtkWidget)(unsafe.Pointer(child)), (*C.GtkWidget)(unsafe.Pointer(sibling))) | |||
| 658 | + | } | |||
| 659 | + | ||||
| 660 | + | // Widget visibility functions for stacked panes | |||
| 661 | + | ||||
| 662 | + | // WidgetSetVisible sets the visibility state of a widget. | |||
| 663 | + | func WidgetSetVisible(widget uintptr, visible bool) { | |||
| 664 | + | if widget == 0 { | |||
| 665 | + | return | |||
| 666 | + | } | |||
| 667 | + | log.Printf("[workspace] WidgetSetVisible widget=%#x visible=%v", widget, visible) | |||
| 668 | + | C.widget_set_visible((*C.GtkWidget)(unsafe.Pointer(widget)), goBool(visible)) | |||
| 669 | + | } | |||
| 670 | + | ||||
| 671 | + | // WidgetGetVisible returns the visibility state of a widget. | |||
| 672 | + | func WidgetGetVisible(widget uintptr) bool { | |||
| 673 | + | if widget == 0 { | |||
| 674 | + | return false | |||
| 675 | + | } | |||
| 676 | + | return C.widget_get_visible((*C.GtkWidget)(unsafe.Pointer(widget))) != 0 | |||
| 677 | + | } | |||
| 678 | + | ||||
| 679 | + | // WidgetHide hides a widget. | |||
| 680 | + | func WidgetHide(widget uintptr) { | |||
| 681 | + | if widget == 0 { | |||
| 682 | + | return | |||
| 683 | + | } | |||
| 684 | + | log.Printf("[workspace] WidgetHide widget=%#x", widget) | |||
| 685 | + | C.widget_hide((*C.GtkWidget)(unsafe.Pointer(widget))) | |||
| 686 | + | } | |||
| 687 | + | ||||
| 688 | + | // Label functions for title bars | |||
| 689 | + | ||||
| 690 | + | // NewLabel creates a new GtkLabel widget with the specified text. | |||
| 691 | + | func NewLabel(text string) uintptr { | |||
| 692 | + | cstr := C.CString(text) | |||
| 693 | + | defer C.free(unsafe.Pointer(cstr)) | |||
| 694 | + | label := C.label_new(cstr) | |||
| 695 | + | return uintptr(unsafe.Pointer(label)) | |||
| 696 | + | } | |||
| 697 | + | ||||
| 698 | + | // LabelSetText sets the text of a GtkLabel. | |||
| 699 | + | func LabelSetText(label uintptr, text string) { | |||
| 700 | + | if label == 0 { | |||
| 701 | + | return | |||
| 702 | + | } | |||
| 703 | + | cstr := C.CString(text) | |||
| 704 | + | defer C.free(unsafe.Pointer(cstr)) | |||
| 705 | + | C.label_set_text((*C.GtkWidget)(unsafe.Pointer(label)), cstr) | |||
| 706 | + | } | |||
| 707 | + | ||||
| 708 | + | // LabelGetText returns the text of a GtkLabel. | |||
| 709 | + | func LabelGetText(label uintptr) string { | |||
| 710 | + | if label == 0 { | |||
| 711 | + | return "" | |||
| 712 | + | } | |||
| 713 | + | cstr := C.label_get_text((*C.GtkWidget)(unsafe.Pointer(label))) | |||
| 714 | + | if cstr == nil { | |||
| 715 | + | return "" | |||
| 716 | + | } | |||
| 717 | + | return C.GoString(cstr) | |||
| 718 | + | } | |||
| 719 | + | ||||
| 720 | + | // EllipsizeMode represents PangoEllipsizeMode values. | |||
| 721 | + | type EllipsizeMode int | |||
| 722 | + | ||||
| 723 | + | const ( | |||
| 724 | + | EllipsizeNone EllipsizeMode = 0 // PANGO_ELLIPSIZE_NONE | |||
| 725 | + | EllipsizeStart EllipsizeMode = 1 // PANGO_ELLIPSIZE_START | |||
| 726 | + | EllipsizeMiddle EllipsizeMode = 2 // PANGO_ELLIPSIZE_MIDDLE | |||
| 727 | + | EllipsizeEnd EllipsizeMode = 3 // PANGO_ELLIPSIZE_END | |||
| 728 | + | ) | |||
| 729 | + | ||||
| 730 | + | // LabelSetEllipsize sets the ellipsization mode for a GtkLabel. | |||
| 731 | + | func LabelSetEllipsize(label uintptr, mode EllipsizeMode) { | |||
| 732 | + | if label == 0 { | |||
| 733 | + | return | |||
| 734 | + | } | |||
| 735 | + | C.label_set_ellipsize((*C.GtkWidget)(unsafe.Pointer(label)), C.int(mode)) | |||
| 736 | + | } | |||
M pkg/webkit/workspace_widgets_stub.go +44 -0
| @@ -186,3 +186,47 @@ func AddCSSProvider(css string) {} | |||
| 186 | 186 | func WidgetAddCSSClass(widget uintptr, class string) {} | |
| 187 | 187 | ||
| 188 | 188 | func WidgetRemoveCSSClass(widget uintptr, class string) {} | |
| 189 | + | ||
| 190 | + | // GtkBox functions for stacked panes (stub implementations) | |
| 191 | + | ||
| 192 | + | func NewBox(orientation Orientation, spacing int) uintptr { | |
| 193 | + | return newWidgetHandle() | |
| 194 | + | } | |
| 195 | + | ||
| 196 | + | func BoxAppend(box uintptr, child uintptr) {} | |
| 197 | + | ||
| 198 | + | func BoxPrepend(box uintptr, child uintptr) {} | |
| 199 | + | ||
| 200 | + | func BoxRemove(box uintptr, child uintptr) {} | |
| 201 | + | ||
| 202 | + | func BoxInsertChildAfter(box uintptr, child uintptr, sibling uintptr) {} | |
| 203 | + | ||
| 204 | + | // Widget visibility functions for stacked panes (stub implementations) | |
| 205 | + | ||
| 206 | + | func WidgetSetVisible(widget uintptr, visible bool) {} | |
| 207 | + | ||
| 208 | + | func WidgetGetVisible(widget uintptr) bool { return true } | |
| 209 | + | ||
| 210 | + | func WidgetHide(widget uintptr) {} | |
| 211 | + | ||
| 212 | + | // Label functions for title bars (stub implementations) | |
| 213 | + | ||
| 214 | + | func NewLabel(text string) uintptr { | |
| 215 | + | return newWidgetHandle() | |
| 216 | + | } | |
| 217 | + | ||
| 218 | + | func LabelSetText(label uintptr, text string) {} | |
| 219 | + | ||
| 220 | + | func LabelGetText(label uintptr) string { return "" } | |
| 221 | + | ||
| 222 | + | // EllipsizeMode represents PangoEllipsizeMode values in stub builds. | |
| 223 | + | type EllipsizeMode int | |
| 224 | + | ||
| 225 | + | const ( | |
| 226 | + | EllipsizeNone EllipsizeMode = 0 | |
| 227 | + | EllipsizeStart EllipsizeMode = 1 | |
| 228 | + | EllipsizeMiddle EllipsizeMode = 2 | |
| 229 | + | EllipsizeEnd EllipsizeMode = 3 | |
| 230 | + | ) | |
| 231 | + | ||
| 232 | + | func LabelSetEllipsize(label uintptr, mode EllipsizeMode) {} | |
| @@ -186,3 +186,47 @@ func AddCSSProvider(css string) {} | |||||
| 186 | func WidgetAddCSSClass(widget uintptr, class string) {} | 186 | func WidgetAddCSSClass(widget uintptr, class string) {} | ||
| 187 | 187 | ||||
| 188 | func WidgetRemoveCSSClass(widget uintptr, class string) {} | 188 | func WidgetRemoveCSSClass(widget uintptr, class string) {} | ||
| 189 | + | ||||
| 190 | + | // GtkBox functions for stacked panes (stub implementations) | |||
| 191 | + | ||||
| 192 | + | func NewBox(orientation Orientation, spacing int) uintptr { | |||
| 193 | + | return newWidgetHandle() | |||
| 194 | + | } | |||
| 195 | + | ||||
| 196 | + | func BoxAppend(box uintptr, child uintptr) {} | |||
| 197 | + | ||||
| 198 | + | func BoxPrepend(box uintptr, child uintptr) {} | |||
| 199 | + | ||||
| 200 | + | func BoxRemove(box uintptr, child uintptr) {} | |||
| 201 | + | ||||
| 202 | + | func BoxInsertChildAfter(box uintptr, child uintptr, sibling uintptr) {} | |||
| 203 | + | ||||
| 204 | + | // Widget visibility functions for stacked panes (stub implementations) | |||
| 205 | + | ||||
| 206 | + | func WidgetSetVisible(widget uintptr, visible bool) {} | |||
| 207 | + | ||||
| 208 | + | func WidgetGetVisible(widget uintptr) bool { return true } | |||
| 209 | + | ||||
| 210 | + | func WidgetHide(widget uintptr) {} | |||
| 211 | + | ||||
| 212 | + | // Label functions for title bars (stub implementations) | |||
| 213 | + | ||||
| 214 | + | func NewLabel(text string) uintptr { | |||
| 215 | + | return newWidgetHandle() | |||
| 216 | + | } | |||
| 217 | + | ||||
| 218 | + | func LabelSetText(label uintptr, text string) {} | |||
| 219 | + | ||||
| 220 | + | func LabelGetText(label uintptr) string { return "" } | |||
| 221 | + | ||||
| 222 | + | // EllipsizeMode represents PangoEllipsizeMode values in stub builds. | |||
| 223 | + | type EllipsizeMode int | |||
| 224 | + | ||||
| 225 | + | const ( | |||
| 226 | + | EllipsizeNone EllipsizeMode = 0 | |||
| 227 | + | EllipsizeStart EllipsizeMode = 1 | |||
| 228 | + | EllipsizeMiddle EllipsizeMode = 2 | |||
| 229 | + | EllipsizeEnd EllipsizeMode = 3 | |||
| 230 | + | ) | |||
| 231 | + | ||||
| 232 | + | func LabelSetEllipsize(label uintptr, mode EllipsizeMode) {} | |||