From 5f9560a566f02c5407541b5fd0edff3076fa8584 Mon Sep 17 00:00:00 2001 From: Colin Neilens Date: Wed, 11 Nov 2026 17:47:27 -0700 Subject: [PATCH] Add Windows sidebar workspace footer Signed-off-by: Colin Neilens Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Signed-off-by: Colin Neilens --- .../windows/Tests/ValidationRunner.Tests.ps1 | 7 +- Tools/windows/uia-live-gate.ps1 | 20 +- graphcode-windows/src/App.zig | 210 ++++++++++++++---- graphcode-windows/src/MainWindow.zig | 60 +++++ graphcode-windows/src/Sidebar.zig | 120 +++++++++- 5 files changed, 368 insertions(+), 49 deletions(-) diff --git a/Tools/windows/Tests/ValidationRunner.Tests.ps1 b/Tools/windows/Tests/ValidationRunner.Tests.ps1 index d8f24448..df34a618 100644 --- a/Tools/windows/Tests/ValidationRunner.Tests.ps1 +++ b/Tools/windows/Tests/ValidationRunner.Tests.ps1 @@ -3706,11 +3706,16 @@ try { 'wire-node-1000000000000000001', 'mark-entry-1000000000000000002', 'overview-wire-node-1000000000000000003', - 'overview-mark-entry-1000000000000000004')) { + 'overview-mark-entry-1000000000000000004', + 'workspace-footer-1000000000000000005')) { if (-not (Test-MultiProjectSourceSupportedChromeId $identity 'owned')) { throw "RED: multi-project observer rejects stable recovery control $identity" } } + if ($uiaLiveGateSource -notmatch "workspace-footer-" -or + $uiaLiveGateSource -notmatch "Sidebar workspace footer was exposed more than once") { + throw "RED: UIA live gate does not admit the owned sidebar workspace footer and reject duplicates" + } if (Test-MultiProjectSourceSupportedChromeId 'future-unknown-control-1000000000000000005' 'owned') { throw "RED: multi-project observer weakens its census by accepting an unknown element" } diff --git a/Tools/windows/uia-live-gate.ps1 b/Tools/windows/uia-live-gate.ps1 index 1a21e3c5..cccc367a 100644 --- a/Tools/windows/uia-live-gate.ps1 +++ b/Tools/windows/uia-live-gate.ps1 @@ -4170,6 +4170,7 @@ function Test-MultiProjectSourceSupportedChromeId([string] $identity, [string] $ "overview-destination", "quick-chats-destination") $chromePrefixes = @("sidebar-section-", "project-row-", "project-new-loop-", "project-disclosure-", "quick-chats-header-", "quick-chat-new-", "quick-chats-disclosure-", "quick-chat-row-", "sidebar-update-banner-", + "workspace-footer-", "header-attention-", "header-worktree-", "header-jump-", "header-toggle-panel-", "canvas-attention-review-", "wire-node-", "mark-entry-", "overview-wire-node-", "overview-mark-entry-", "workspace-show-graph-", "workspace-stop-", "workspace-toggle-panel-", "workspace-detail-sparkline-", @@ -6412,11 +6413,7 @@ try { "$($expected.Name) was not exposed under the Workspace lifecycle menu" $null = $element.GetCurrentPattern([System.Windows.Automation.InvokePattern]::Pattern) } - $workspaceSwitches = @(Get-DirectChildren $workspaces $rawWalker | - Where-Object { $_.Current.AutomationId -match '^workspace-switch-' }) - Require ($workspaceSwitches.Count -ge 1) "Workspace lifecycle menu did not expose the current workspace" - $expectedWorkspaceIds = @($workspaceLifecycle.Id) + - @($workspaceSwitches | ForEach-Object { $_.Current.AutomationId }) + $expectedWorkspaceIds = @($workspaceLifecycle.Id) $null = @(Assert-FragmentLinks $workspaces $rawWalker $expectedWorkspaceIds "RawView Workspaces") $null = @(Assert-FragmentLinks $workspaces $controlWalker $expectedWorkspaceIds "ControlView Workspaces") @@ -6424,6 +6421,19 @@ try { $loops = Find-FragmentById $root "loops" $rawWalker $graph = Find-FragmentById $root "graph" $rawWalker Require (($null -ne $projects) -and ($null -ne $loops) -and ($null -ne $graph)) "missing Projects, Loops, or Graph fragments" + $workspaceFooters = @(Get-DirectChildren $projects $rawWalker | + Where-Object { $_.Current.AutomationId -match '^workspace-footer-' }) + Require ($workspaceFooters.Count -le 1) "Sidebar workspace footer was exposed more than once" + if ($workspaceFooters.Count -eq 1) { + $workspaceFooter = $workspaceFooters[0] + Require (-not [string]::IsNullOrWhiteSpace($workspaceFooter.Current.Name)) ` + "Sidebar workspace footer omitted the current workspace name" + $workspaceFooterBounds = $workspaceFooter.Current.BoundingRectangle + Require (($workspaceFooterBounds.Width -gt 0) -and ($workspaceFooterBounds.Height -gt 0) -and + ($workspaceFooterBounds.Right -le $projects.Current.BoundingRectangle.Right)) ` + "Sidebar workspace footer was not contained by the sidebar rail" + $null = $workspaceFooter.GetCurrentPattern([System.Windows.Automation.InvokePattern]::Pattern) + } $connectionAlert = $root.FindFirst( [System.Windows.Automation.TreeScope]::Descendants, (New-Object System.Windows.Automation.PropertyCondition( diff --git a/graphcode-windows/src/App.zig b/graphcode-windows/src/App.zig index 426f500f..5932de16 100644 --- a/graphcode-windows/src/App.zig +++ b/graphcode-windows/src/App.zig @@ -1600,7 +1600,7 @@ const UiaDynamicTarget = union(enum) { workspace_toggle_panel, workspace_tab: usize, workspace_tab_close: usize, - workspace_switch: usize, + workspace_footer, workspace_restart_session: []const u8, header_attention, canvas_attention, @@ -7988,8 +7988,78 @@ pub const App = struct { return self.update_state.state == .available and self.update_version.len != 0; } + fn sidebarWorkspaceFooter(self: *const App) ?WorkspaceLifecycle.Workspace { + if (!self.workspace_controls.rail_visible or !self.workspace_identity_valid) return null; + const list = self.workspace_list orelse return null; + var current: ?WorkspaceLifecycle.Workspace = null; + for (list.items) |workspace| { + if (std.mem.eql(u8, workspace.identity, self.workspace_identity)) { + current = workspace; + break; + } + } + const workspace = current orelse return null; + if (workspace.is_default and list.items.len == 1) return null; + return workspace; + } + + fn showSidebarWorkspaceFooterMenu(self: *App, logical_anchor: c.RECT) bool { + if (self.sidebarWorkspaceFooter() == null) return false; + const list = self.workspace_list orelse return false; + const items = self.allocator.alloc(MainWindow.WorkspaceItem, list.items.len) catch { + self.setStatus("Workspace switcher could not be prepared"); + return false; + }; + defer self.allocator.free(items); + const paths = self.allocator.alloc([]u8, list.items.len) catch { + self.setStatus("Workspace switcher could not be prepared"); + return false; + }; + for (list.items, items, paths, 0..) |workspace, *item, *path, index| { + path.* = self.allocator.dupe(u8, workspace.path) catch { + for (paths[0..index]) |owned| self.allocator.free(owned); + self.allocator.free(paths); + self.setStatus("Workspace switcher could not be prepared"); + return false; + }; + item.* = .{ + .name = workspace.name, + .is_current = std.mem.eql(u8, workspace.identity, self.workspace_identity), + }; + } + defer { + for (paths) |path| self.allocator.free(path); + self.allocator.free(paths); + } + var anchor = c.POINT{ + .x = physicalCoordinate(@divTrunc(logical_anchor.left + logical_anchor.right, 2), self.dpi), + .y = physicalCoordinate(logical_anchor.top, self.dpi), + }; + if (c.ClientToScreen(self.window.hwnd, &anchor) == 0) { + self.setStatus("Unable to position workspace switcher"); + return false; + } + const command = MainWindow.showWorkspaceFooterMenu(self.window.hwnd, items, anchor) orelse return true; + if (command >= MainWindow.workspace_command_base and command <= MainWindow.workspace_command_limit) { + const index = command - MainWindow.workspace_command_base; + if (index < paths.len) self.launchWorkspace(paths[index]); + return true; + } + return switch (MainWindow.commandFromId(command) orelse return false) { + .workspace_new => blk: { + self.createWorkspace(); + break :blk true; + }, + .workspace_manage => blk: { + self.manageWorkspaces(); + break :blk true; + }, + else => false, + }; + } + /// Bottom edge of the scrollable sidebar content: the sidebar viewport minus the footer - /// (status line, update banner, error footer) that is drawn over its lower edge. + /// (status line, workspace row, update banner, error footer) drawn over its lower edge. fn sidebarContentBottom(self: *App, client_bottom: i32) i32 { const viewport_bottom = GraphCanvas.sidebarBottom(client_bottom, self.workspace_controls, self.surface); const footer = Sidebar.effectiveFooter(viewport_bottom, self.updateBannerShown(), self.ingress_error.len != 0); @@ -9730,28 +9800,25 @@ pub const App = struct { .bottom = bounds.bottom, }) catch return; } - if (self.workspace_list) |list| { - for (list.items, 0..) |workspace, index| { - const identity = std.fmt.allocPrint(self.allocator, "workspace-switch:{s}", .{workspace.path}) catch return; - owned_identities.append(identity) catch { - self.allocator.free(identity); - return; - }; - const row_top: i32 = 34 + @as(i32, @intCast(index * 30)); - const bounds = (AccessibilityBounds{ .logical = .{ .left = 250, .top = row_top, .right = 500, .bottom = row_top + 28 } }).physicalRect(self.dpi); - elements.append(.{ - .identity = identity, - .name = workspace.name, - .parent = 21, - .selected = self.workspace_identity_valid and std.mem.eql(u8, workspace.identity, self.workspace_identity), - .eligible = self.workspace_identity_valid, - .invokable = self.workspace_identity_valid, - .left = bounds.left, - .top = bounds.top, - .right = bounds.right, - .bottom = bounds.bottom, - }) catch return; - } + if (self.sidebarWorkspaceFooter()) |workspace| { + const identity = std.fmt.allocPrint(self.allocator, "workspace-footer:{s}", .{workspace.path}) catch return; + owned_identities.append(identity) catch { + self.allocator.free(identity); + return; + }; + const bounds = (AccessibilityBounds{ .logical = Sidebar.workspaceFooterRect(footer_viewport_bottom) }).physicalRect(self.dpi); + elements.append(.{ + .identity = identity, + .name = workspace.name, + .parent = 1, + .selected = false, + .eligible = true, + .invokable = true, + .left = bounds.left, + .top = bounds.top, + .right = bounds.right, + .bottom = bounds.bottom, + }) catch return; } if (rail_presentation.mode == .overlay) { const overlay_left = physicalCoordinate(rail_presentation.rail_right, self.dpi); @@ -10073,14 +10140,12 @@ pub const App = struct { target = .{ .activity = index }; } } - if (self.workspace_list) |list| { - for (list.items, 0..) |workspace, workspace_index| { - const workspace_identity = std.fmt.allocPrint(self.allocator, "workspace-switch:{s}", .{workspace.path}) catch return false; - defer self.allocator.free(workspace_identity); - if (Accessibility.worktreeIdentityPayload(workspace_identity) == payload) { - if (target != null) return false; - target = .{ .workspace_switch = workspace_index }; - } + if (self.sidebarWorkspaceFooter()) |workspace| { + const workspace_identity = std.fmt.allocPrint(self.allocator, "workspace-footer:{s}", .{workspace.path}) catch return false; + defer self.allocator.free(workspace_identity); + if (Accessibility.worktreeIdentityPayload(workspace_identity) == payload) { + if (target != null) return false; + target = .workspace_footer; } } const resolved = target orelse return false; @@ -10197,11 +10262,16 @@ pub const App = struct { }, .workspace_tab => |index| if (self.workspace) |workspace| workspace.selectTab(index) catch return false, .workspace_tab_close => |index| if (self.workspace) |workspace| workspace.closeTab(index) catch return false, - .workspace_switch => |index| { - const list = self.workspace_list orelse return false; - if (index >= list.items.len) return false; - self.launchWorkspace(list.items[index].path); + .workspace_footer => { + if (!self.workspace_controls.rail_visible) return false; + const client = logicalClientRect(self.window.hwnd, self.dpi); + if (!self.showSidebarWorkspaceFooterMenu( + Sidebar.workspaceFooterRect( + GraphCanvas.sidebarBottom(client.bottom, self.workspace_controls, self.surface), + ), + )) return false; }, + .header_attention => return self.invokeHeader(.review_attention), .canvas_attention => { if (!GraphCanvas.attentionRailShown(&self.model, self.surface)) return false; @@ -11084,6 +11154,14 @@ fn onWindowMessage( const offered_version = if (app.update_state.state == .available) app.update_version else ""; GraphCanvas.paint(hdc, logical_right, logical_bottom, &app.model, inspection, app.selected_worktree_path, app.sidebar_scroll, app.status(), offered_version, app.ingress_error, app.connectionFailureVisible(), app.worktree_state, app.declared_entry_ids.items, app.kept_worktree_paths.items, app.allocator, &app.canvas, &app.sidebar_state, app.sidebar_hover_y, app.workspace_controls, app.surface, app.selection_active, app.workspaceQuickChatID()); app.update_lock.unlock(); + if (app.workspace_controls.rail_visible) if (app.sidebarWorkspaceFooter()) |workspace| { + Sidebar.drawWorkspaceFooter( + hdc, + GraphCanvas.sidebarBottom(logical_bottom, app.workspace_controls, app.surface), + workspace.name, + app.allocator, + ); + }; if (app.workspace_controls.panel_visible or app.surface == .workspace) { if (app.surface == .workspace) { if (app.workspaceQuickChatID()) |chat_id| { @@ -11470,6 +11548,22 @@ fn onWindowMessage( if (app.header_focus != null) app.leaveHeader(false); const rail_presentation = WorkspaceControls.railPresentation(client.right, app.workspace_controls); const overlay_rail_hit = overlayRailOwnsPointer(x, y, rail_presentation); + if (app.workspace_controls.rail_visible and + app.sidebarWorkspaceFooter() != null and + Sidebar.workspaceFooterAt( + x, + y, + GraphCanvas.sidebarBottom(client.bottom, app.workspace_controls, app.surface), + )) + { + _ = app.showSidebarWorkspaceFooterMenu( + Sidebar.workspaceFooterRect( + GraphCanvas.sidebarBottom(client.bottom, app.workspace_controls, app.surface), + ), + ); + result.* = 0; + return true; + } const canvas_bounds = GraphCanvas.renderBounds(client.right, client.bottom, app.workspace_controls); const rail_bounds = GraphCanvas.attentionRailLayout(.{ .left = canvas_bounds.left, .top = canvas_bounds.top, .right = canvas_bounds.right, .bottom = canvas_bounds.bottom }); if (!overlay_rail_hit and GraphCanvas.attentionRailShown(&app.model, app.surface) and @@ -14419,6 +14513,35 @@ fn deinitFooterLayoutApp(app: *App) void { deinitOverviewTestApp(app); } +test "sidebar workspace footer follows macOS current and known workspace visibility" { + var default = [_]WorkspaceLifecycle.Workspace{ + .{ .name = "Default", .path = "default", .identity = "default", .is_default = true }, + }; + var multiple = [_]WorkspaceLifecycle.Workspace{ + .{ .name = "Default", .path = "default", .identity = "default", .is_default = true }, + .{ .name = "Fixture", .path = "fixture", .identity = "fixture", .is_default = false }, + }; + var app: App = undefined; + app.workspace_controls = .{ .rail_visible = true }; + app.workspace_identity_valid = true; + app.workspace_identity = @constCast("default"); + app.workspace_list = .{ .items = &default }; + try std.testing.expect(app.sidebarWorkspaceFooter() == null); + + default[0].is_default = false; + try std.testing.expectEqualStrings("Default", app.sidebarWorkspaceFooter().?.name); + + app.workspace_list = .{ .items = &multiple }; + try std.testing.expectEqualStrings("Default", app.sidebarWorkspaceFooter().?.name); + app.workspace_identity = @constCast("fixture"); + try std.testing.expectEqualStrings("Fixture", app.sidebarWorkspaceFooter().?.name); + app.workspace_identity_valid = false; + try std.testing.expect(app.sidebarWorkspaceFooter() == null); + app.workspace_identity_valid = true; + app.workspace_controls.rail_visible = false; + try std.testing.expect(app.sidebarWorkspaceFooter() == null); +} + /// A project with loops, eight Worktrees rows, two Needs-you entries, an Activity card, and /// Quick Chats: enough sidebar content to run past the bottom of every case's viewport. fn footerLayoutApp(case: FooterLayoutCase, controls: WorkspaceControls.State, update: bool, ingress: bool) !App { @@ -23606,6 +23729,9 @@ fn expectDpiAccessibilityWithMetrics(surface: GraphCanvas.Surface, canvas: ?[3][ .{ .name = "Fixture", .path = "B", .identity = "b", .is_default = false }, }; app.workspace_list = .{ .items = &workspaces }; + app.workspace_identity = try allocator.dupe(u8, "b"); + defer allocator.free(app.workspace_identity); + app.workspace_identity_valid = true; var workspace: TerminalWorkspace.Workspace = .{ .parent = null, .allocator = allocator, @@ -23652,7 +23778,6 @@ test "DPI UIA logical cards headers sidebar and direct inserts scale once" { const common = [_]DpiExpectedElement{ // 42px content inset + Graph/Quick Chats/chat slots + 18px caption gap. .{ .identity = "sidebar-section:local", .bounds = .{ .{ 12, 156, 208, 180 }, .{ 18, 234, 312, 270 }, .{ 24, 312, 416, 360 } } }, - .{ .identity = "workspace-switch:B", .bounds = .{ .{ 250, 34, 500, 62 }, .{ 375, 51, 750, 93 }, .{ 500, 68, 1000, 124 } } }, }; // The footer is anchored to the sidebar's visible bottom, which the workspace panel // shortens on every surface except the workspace itself. @@ -23664,9 +23789,18 @@ test "DPI UIA logical cards headers sidebar and direct inserts scale once" { .identity = "sidebar-error-footer:ingress", .bounds = .{ .{ 8, 816, 212, 858 }, .{ 12, 1224, 318, 1287 }, .{ 16, 1632, 424, 1716 } }, }; + const workspace_footer_above_panel = DpiExpectedElement{ + .identity = "workspace-footer:B", + .bounds = .{ .{ 0, 614, 220, 650 }, .{ 0, 921, 330, 975 }, .{ 0, 1228, 440, 1300 } }, + }; + const workspace_footer_full_height = DpiExpectedElement{ + .identity = "workspace-footer:B", + .bounds = .{ .{ 0, 864, 220, 900 }, .{ 0, 1296, 330, 1350 }, .{ 0, 1728, 440, 1800 } }, + }; for ([_]GraphCanvas.Surface{ .project, .overview, .quick_chats, .workspace }) |surface| { const footer = if (surface == .workspace) footer_full_height else footer_above_panel; - try expectDpiAccessibility(surface, null, &(common ++ [_]DpiExpectedElement{footer})); + const workspace_footer = if (surface == .workspace) workspace_footer_full_height else workspace_footer_above_panel; + try expectDpiAccessibility(surface, null, &(common ++ [_]DpiExpectedElement{ footer, workspace_footer })); if (surface != .workspace) try expectDpiAccessibility(surface, null, &(graph_header ++ [_]DpiExpectedElement{ .{ .identity = "header-toggle-panel:control" }, .{ .identity = "workspace-toolbar:A" }, diff --git a/graphcode-windows/src/MainWindow.zig b/graphcode-windows/src/MainWindow.zig index 4bcd7785..379f1595 100644 --- a/graphcode-windows/src/MainWindow.zig +++ b/graphcode-windows/src/MainWindow.zig @@ -754,6 +754,39 @@ fn workspaceCycleAvailable(workspaces: []const WorkspaceItem) bool { return workspaces.len > 1 or (workspaces.len == 1 and !workspaces[0].is_current); } +pub fn createWorkspaceFooterMenu(workspaces: []const WorkspaceItem) ?c.HMENU { + const menu = c.CreatePopupMenu() orelse return null; + for (workspaces[0..@min(workspaces.len, workspace_command_limit - workspace_command_base + 1)], 0..) |item, index| { + const command = workspace_command_base + index; + append(menu, item.name, command); + const flags: c.UINT = if (item.is_current) c.MF_BYCOMMAND | c.MF_CHECKED else c.MF_BYCOMMAND | c.MF_UNCHECKED; + _ = c.CheckMenuItem(menu, @intCast(command), flags); + } + separator(menu); + append(menu, "New Workspace...", @intFromEnum(Command.workspace_new)); + appendEnabled(menu, "Manage Workspaces...", @intFromEnum(Command.workspace_manage), workspaces.len > 1); + return menu; +} + +pub fn showWorkspaceFooterMenu( + hwnd: c.HWND, + workspaces: []const WorkspaceItem, + anchor: c.POINT, +) ?usize { + const menu = createWorkspaceFooterMenu(workspaces) orelse return null; + defer _ = c.DestroyMenu(menu); + const selected = c.TrackPopupMenu( + menu, + c.TPM_RETURNCMD | c.TPM_NONOTIFY | c.TPM_RIGHTBUTTON | c.TPM_BOTTOMALIGN, + anchor.x, + anchor.y, + 0, + hwnd, + null, + ); + return if (selected > 0) @intCast(selected) else null; +} + test "workspace cycle capability counts an outside current without window queries" { const current = WorkspaceItem{ .name = "Default", .is_current = true }; const other = WorkspaceItem{ .name = "Default", .is_current = false }; @@ -3084,6 +3117,33 @@ test "workspace menu checks the exact command and retains target labels and enab try std.testing.expectError(error.TestUnexpectedResult, expectDisabledWorkspaceCommand(menu, .workspace_rename)); } +test "workspace footer popup retains target labels and owned actions" { + const items = [_]WorkspaceItem{ + .{ .name = "Default", .is_current = false }, + .{ .name = "Fixture Workspace", .is_current = true }, + }; + const menu = createWorkspaceFooterMenu(&items) orelse return error.CreateWorkspaceFooterMenuFailed; + defer _ = c.DestroyMenu(menu); + try std.testing.expectEqual(@as(i32, 5), c.GetMenuItemCount(menu)); + for (items, 0..) |item, index| { + const command: c.UINT = @intCast(workspace_command_base + index); + const state = c.GetMenuState(menu, command, c.MF_BYCOMMAND); + try std.testing.expect(state != std.math.maxInt(c.UINT)); + try std.testing.expectEqual(item.is_current, state & c.MF_CHECKED != 0); + var label: [128]u16 = undefined; + const length = c.GetMenuStringW(menu, command, &label, label.len, c.MF_BYCOMMAND); + const actual = try std.unicode.utf16LeToUtf8Alloc(std.testing.allocator, label[0..@intCast(length)]); + defer std.testing.allocator.free(actual); + try std.testing.expectEqualStrings(item.name, actual); + } + try std.testing.expect(c.GetMenuState(menu, @intFromEnum(Command.workspace_new), c.MF_BYCOMMAND) & c.MF_GRAYED == 0); + try std.testing.expect(c.GetMenuState(menu, @intFromEnum(Command.workspace_manage), c.MF_BYCOMMAND) & c.MF_GRAYED == 0); + + const single = createWorkspaceFooterMenu(items[0..1]) orelse return error.CreateWorkspaceFooterMenuFailed; + defer _ = c.DestroyMenu(single); + try std.testing.expect(c.GetMenuState(single, @intFromEnum(Command.workspace_manage), c.MF_BYCOMMAND) & c.MF_GRAYED != 0); +} + // Regression test for the Update-command re-enable bug: a real background // update check completes almost instantly, but `finishUpdateCheck` only // refreshed menu state through `updateNativeChrome`, which is gated on diff --git a/graphcode-windows/src/Sidebar.zig b/graphcode-windows/src/Sidebar.zig index d702e608..ff4b79ce 100644 --- a/graphcode-windows/src/Sidebar.zig +++ b/graphcode-windows/src/Sidebar.zig @@ -430,9 +430,12 @@ const footer_status_extent: i32 = 58; const footer_error_extent: i32 = 50; const footer_update_extent: i32 = 58; const status_line_height: i32 = 20; +pub const workspace_footer_height: i32 = 36; -/// Height the sidebar footer (status line, optional update banner, optional error footer) -/// takes from the bottom of the sidebar. Scrolling content never extends into it. +/// Height the sidebar footer (status line plus the workspace row, optional update banner, +/// optional error footer) takes from the bottom of the sidebar. The existing 58 px status +/// extent already contains the 36 px workspace row and leaves a small gap above it. +/// Scrolling content never extends into it. pub fn footerReserve(has_update: bool, has_error: bool) i32 { return footer_status_extent + (if (has_error) footer_error_extent else 0) + @@ -450,8 +453,8 @@ pub const Footer = struct { }; /// The footer parts that fit while still leaving `min_content_region` of scrolling content. On a -/// short viewport the error footer collapses first, then the update banner; the status line is -/// the footer's floor. The same result drives drawing, hit testing, and UIA, so a collapsed +/// short viewport the error footer collapses first, then the update banner; the status/workspace +/// floor remains. The same result drives drawing, hit testing, and UIA, so a collapsed /// part is neither painted nor published nor clickable. pub fn effectiveFooter(viewport_bottom: i32, has_update: bool, has_error: bool) Footer { var footer = Footer{ .update = has_update, .ingress = has_error }; @@ -477,6 +480,49 @@ pub fn statusTextRect(viewport_bottom: i32, has_update: bool, has_error: bool) c return rect(18, top, Tokens.sidebar_width - 10, top + status_line_height); } +pub fn workspaceFooterRect(viewport_bottom: i32) c.RECT { + return rect(0, viewport_bottom - workspace_footer_height, Tokens.sidebar_width, viewport_bottom); +} + +pub fn workspaceFooterAt(x: i32, y: i32, viewport_bottom: i32) bool { + const bounds = workspaceFooterRect(viewport_bottom); + return x >= bounds.left and x < bounds.right and y >= bounds.top and y < bounds.bottom; +} + +pub fn drawWorkspaceFooter( + hdc: c.HDC, + viewport_bottom: i32, + workspace_name: []const u8, + allocator: std.mem.Allocator, +) void { + const bounds = workspaceFooterRect(viewport_bottom); + fill(hdc, bounds, Tokens.workspace_rail); + + const divider = c.CreatePen(c.PS_SOLID, 1, 0x00343333) orelse return; + defer _ = c.DeleteObject(divider); + const previous_pen = c.SelectObject(hdc, divider); + _ = c.MoveToEx(hdc, bounds.left, bounds.top, null); + _ = c.LineTo(hdc, bounds.right, bounds.top); + _ = c.SelectObject(hdc, previous_pen); + + drawOutlineIcon( + hdc, + .workspace, + rect(12, bounds.top + 10, 28, bounds.top + 26), + 0x008E8E93, + ); + drawTextRect( + hdc, + allocator, + workspace_name, + rect(34, bounds.top + 6, bounds.right - 30, bounds.bottom - 6), + 13, + 0x00CCCCCC, + c.DT_LEFT | c.DT_SINGLELINE | c.DT_VCENTER | c.DT_END_ELLIPSIS | c.DT_NOPREFIX, + ); + drawWorkspaceChevrons(hdc, rect(bounds.right - 24, bounds.top + 10, bounds.right - 12, bounds.top + 26), 0x006A6A70); +} + pub fn chatsLabelRect(row_top: i32) c.RECT { return rect(18, row_top - 32, Tokens.sidebar_width - 10, row_top - 32 + 18); } @@ -2850,6 +2896,43 @@ test "sidebar footer reserve keeps content, status text, banner, and error foote try std.testing.expectEqual(@as(i32, Tokens.header_height), contentViewportBottom(100, true, true)); } +test "sidebar workspace footer paints named control inside the reserved rail bottom" { + var bitmap = try TestSidebarBitmap.init(); + defer bitmap.deinit(); + fill(bitmap.hdc, rect(0, 0, Tokens.sidebar_width, 800), Tokens.workspace_rail); + + const viewport_bottom: i32 = 800; + const bounds = workspaceFooterRect(viewport_bottom); + try std.testing.expectEqual(@as(i32, viewport_bottom - workspace_footer_height), bounds.top); + try std.testing.expectEqual(@as(i32, Tokens.sidebar_width), bounds.right); + try std.testing.expect(workspaceFooterAt(bounds.left, bounds.top, viewport_bottom)); + try std.testing.expect(!workspaceFooterAt(bounds.right, bounds.top, viewport_bottom)); + try std.testing.expect(statusTextRect(viewport_bottom, false, false).bottom <= bounds.top); + for ([_]bool{ false, true }) |has_update| for ([_]bool{ false, true }) |has_error| { + const footer = effectiveFooter(viewport_bottom, has_update, has_error); + const status = statusTextRect(viewport_bottom, footer.update, footer.ingress); + try std.testing.expect(status.bottom <= bounds.top); + if (footer.update) { + try std.testing.expect(updateBannerRect(viewport_bottom, footer.ingress).bottom <= bounds.top); + } + if (footer.ingress) { + try std.testing.expect(errorFooterRect(viewport_bottom).bottom <= bounds.top); + } + }; + + drawWorkspaceFooter(bitmap.hdc, viewport_bottom, "Fixture Workspace", std.testing.allocator); + + var changed: usize = 0; + var y = bounds.top; + while (y < bounds.bottom) : (y += 1) { + var x = bounds.left; + while (x < bounds.right) : (x += 1) { + if (c.GetPixel(bitmap.hdc, x, y) != Tokens.workspace_rail) changed += 1; + } + } + try std.testing.expect(changed >= 24); +} + test "sidebar rows beneath the update banner are neither hit nor counted as visible" { var model = GraphModel.Model.init(std.testing.allocator); defer model.deinit(); @@ -3134,7 +3217,7 @@ fn measuredWidth(hdc: c.HDC, label: []const u8) !i32 { return size.cx; } -const SidebarIcon = enum { graph, local_folder, remote_folder, chat }; +const SidebarIcon = enum { graph, local_folder, remote_folder, chat, workspace }; fn drawOutlineIcon(hdc: c.HDC, icon: SidebarIcon, bounds: c.RECT, color: u32) void { const pen = c.CreatePen(c.PS_SOLID, 1, color) orelse return; @@ -3179,12 +3262,39 @@ fn drawOutlineIcon(hdc: c.HDC, icon: SidebarIcon, bounds: c.RECT, color: u32) vo _ = c.MoveToEx(hdc, bounds.left + 12, bounds.top + 13, null); _ = c.LineTo(hdc, bounds.left + 14, bounds.bottom); }, + .workspace => { + _ = c.Rectangle(hdc, bounds.left + 2, bounds.top + 7, bounds.right - 1, bounds.bottom - 1); + _ = c.MoveToEx(hdc, bounds.left + 4, bounds.top + 7, null); + _ = c.LineTo(hdc, bounds.left + 4, bounds.top + 4); + _ = c.LineTo(hdc, bounds.right - 3, bounds.top + 4); + _ = c.LineTo(hdc, bounds.right - 3, bounds.top + 7); + _ = c.MoveToEx(hdc, bounds.left + 6, bounds.top + 4, null); + _ = c.LineTo(hdc, bounds.left + 6, bounds.top + 1); + _ = c.LineTo(hdc, bounds.right - 5, bounds.top + 1); + _ = c.LineTo(hdc, bounds.right - 5, bounds.top + 4); + }, } _ = c.SelectObject(hdc, previous_brush); _ = c.SelectObject(hdc, previous_pen); _ = c.DeleteObject(pen); } +fn drawWorkspaceChevrons(hdc: c.HDC, bounds: c.RECT, color: u32) void { + const pen = c.CreatePen(c.PS_SOLID, 1, color) orelse return; + defer _ = c.DeleteObject(pen); + const previous = c.SelectObject(hdc, pen); + const x = @divTrunc(bounds.left + bounds.right, 2); + const upper_y = bounds.top + 5; + const lower_y = bounds.bottom - 5; + _ = c.MoveToEx(hdc, x - 3, upper_y + 2, null); + _ = c.LineTo(hdc, x, upper_y - 1); + _ = c.LineTo(hdc, x + 3, upper_y + 2); + _ = c.MoveToEx(hdc, x - 3, lower_y - 2, null); + _ = c.LineTo(hdc, x, lower_y + 1); + _ = c.LineTo(hdc, x + 3, lower_y - 2); + _ = c.SelectObject(hdc, previous); +} + fn drawPlusIcon(hdc: c.HDC, bounds: c.RECT, color: u32) void { const pen = c.CreatePen(c.PS_SOLID, 1, color) orelse return; const previous = c.SelectObject(hdc, pen);