From a1e37280a7a4e0c3990e6b5038879fd5f6c9d5fd Mon Sep 17 00:00:00 2001 From: Avery Felts Date: Fri, 20 Nov 2026 08:26:18 -0700 Subject: [PATCH] feat(settings): Glass Transparency for Liquid Glass A slider under Settings' Liquid Glass switch, 0 to 100 % in tens (#807). Higher thins the veil over the desktop and the tint of panels and controls, and past the middle makes panels and controls clear glass with a lighter blur, so the game's art shows through the library's panels. Deep glass (settings and menus) keeps enough tint for its text, and GPUI's washes over the glass thin with it. A change retints the glass in place: dragging the slider rebuilds nothing. 0 % is the look before; it is saved as glassTransparency with the other display choices. --- app-gpui/backend-route-inventory.json | 246 +++++++++++++------------- app-gpui/glass/MSGlass.swift | 56 +++++- app-gpui/src/liquid_glass.rs | 23 ++- app-gpui/src/settings_preview.rs | 67 +++++++ app-gpui/src/ui.rs | 30 +++- app-gpui/src/ui_live.rs | 5 + 6 files changed, 292 insertions(+), 135 deletions(-) diff --git a/app-gpui/backend-route-inventory.json b/app-gpui/backend-route-inventory.json index 9ff2ec2a..2e383d03 100644 --- a/app-gpui/backend-route-inventory.json +++ b/app-gpui/backend-route-inventory.json @@ -42,7 +42,7 @@ "literal_references": [ { "file": "app-gpui/src/ui_live.rs", - "line": 1311, + "line": 1316, "kind": "literal-candidate" } ], @@ -187,7 +187,7 @@ "literal_references": [ { "file": "app-gpui/src/settings_preview.rs", - "line": 1296, + "line": 1300, "kind": "literal-candidate" }, { @@ -209,12 +209,12 @@ "literal_references": [ { "file": "app-gpui/src/settings_preview.rs", - "line": 201, + "line": 205, "kind": "literal-candidate" }, { "file": "app-gpui/src/settings_preview.rs", - "line": 594, + "line": 598, "kind": "literal-candidate" } ], @@ -241,27 +241,27 @@ }, { "file": "app-gpui/src/settings_preview.rs", - "line": 564, + "line": 568, "kind": "literal-candidate" }, { "file": "app-gpui/src/settings_preview.rs", - "line": 1088, + "line": 1092, "kind": "literal-candidate" }, { "file": "app-gpui/src/settings_preview.rs", - "line": 1122, + "line": 1126, "kind": "literal-candidate" }, { "file": "app-gpui/src/settings_preview.rs", - "line": 1159, + "line": 1163, "kind": "literal-candidate" }, { "file": "app-gpui/src/settings_preview.rs", - "line": 1193, + "line": 1197, "kind": "literal-candidate" }, { @@ -276,42 +276,42 @@ }, { "file": "app-gpui/src/ui_live.rs", - "line": 2019, + "line": 2024, "kind": "literal-candidate" }, { "file": "app-gpui/src/ui_live.rs", - "line": 2289, + "line": 2294, "kind": "literal-candidate" }, { "file": "app-gpui/src/ui_live.rs", - "line": 2315, + "line": 2320, "kind": "literal-candidate" }, { "file": "app-gpui/src/ui_live.rs", - "line": 2406, + "line": 2411, "kind": "literal-candidate" }, { "file": "app-gpui/src/ui_live.rs", - "line": 2440, + "line": 2445, "kind": "literal-candidate" }, { "file": "app-gpui/src/ui_live.rs", - "line": 2477, + "line": 2482, "kind": "literal-candidate" }, { "file": "app-gpui/src/ui_live.rs", - "line": 2503, + "line": 2508, "kind": "literal-candidate" }, { "file": "app-gpui/src/ui_live.rs", - "line": 2622, + "line": 2627, "kind": "literal-candidate" } ], @@ -338,27 +338,27 @@ }, { "file": "app-gpui/src/settings_preview.rs", - "line": 564, + "line": 568, "kind": "literal-candidate" }, { "file": "app-gpui/src/settings_preview.rs", - "line": 1088, + "line": 1092, "kind": "literal-candidate" }, { "file": "app-gpui/src/settings_preview.rs", - "line": 1122, + "line": 1126, "kind": "literal-candidate" }, { "file": "app-gpui/src/settings_preview.rs", - "line": 1159, + "line": 1163, "kind": "literal-candidate" }, { "file": "app-gpui/src/settings_preview.rs", - "line": 1193, + "line": 1197, "kind": "literal-candidate" }, { @@ -373,42 +373,42 @@ }, { "file": "app-gpui/src/ui_live.rs", - "line": 2019, + "line": 2024, "kind": "literal-candidate" }, { "file": "app-gpui/src/ui_live.rs", - "line": 2289, + "line": 2294, "kind": "literal-candidate" }, { "file": "app-gpui/src/ui_live.rs", - "line": 2315, + "line": 2320, "kind": "literal-candidate" }, { "file": "app-gpui/src/ui_live.rs", - "line": 2406, + "line": 2411, "kind": "literal-candidate" }, { "file": "app-gpui/src/ui_live.rs", - "line": 2440, + "line": 2445, "kind": "literal-candidate" }, { "file": "app-gpui/src/ui_live.rs", - "line": 2477, + "line": 2482, "kind": "literal-candidate" }, { "file": "app-gpui/src/ui_live.rs", - "line": 2503, + "line": 2508, "kind": "literal-candidate" }, { "file": "app-gpui/src/ui_live.rs", - "line": 2622, + "line": 2627, "kind": "literal-candidate" } ], @@ -557,12 +557,12 @@ "literal_references": [ { "file": "app-gpui/src/ui_live.rs", - "line": 2063, + "line": 2068, "kind": "literal-candidate" }, { "file": "app-gpui/src/ui_live.rs", - "line": 2384, + "line": 2389, "kind": "literal-candidate" } ], @@ -579,12 +579,12 @@ "literal_references": [ { "file": "app-gpui/src/ui_live.rs", - "line": 2063, + "line": 2068, "kind": "literal-candidate" }, { "file": "app-gpui/src/ui_live.rs", - "line": 2384, + "line": 2389, "kind": "literal-candidate" } ], @@ -621,7 +621,7 @@ }, { "file": "app-gpui/src/ui_live.rs", - "line": 2190, + "line": 2195, "kind": "literal-candidate" } ], @@ -658,7 +658,7 @@ }, { "file": "app-gpui/src/ui_live.rs", - "line": 2190, + "line": 2195, "kind": "literal-candidate" } ], @@ -750,12 +750,12 @@ "literal_references": [ { "file": "app-gpui/src/ui_live.rs", - "line": 1081, + "line": 1086, "kind": "literal-candidate" }, { "file": "app-gpui/src/ui_live.rs", - "line": 1830, + "line": 1835, "kind": "literal-candidate" } ], @@ -901,7 +901,7 @@ "literal_references": [ { "file": "app-gpui/src/ui_live.rs", - "line": 1079, + "line": 1084, "kind": "literal-candidate" } ], @@ -967,7 +967,7 @@ }, { "file": "app-gpui/src/ui_live.rs", - "line": 997, + "line": 1002, "kind": "literal-candidate" } ], @@ -1001,7 +1001,7 @@ "literal_references": [ { "file": "app-gpui/src/ui_live.rs", - "line": 1101, + "line": 1106, "kind": "literal-candidate" } ], @@ -1029,7 +1029,7 @@ "literal_references": [ { "file": "app-gpui/src/ui_live.rs", - "line": 2652, + "line": 2657, "kind": "literal-candidate" } ], @@ -1590,12 +1590,12 @@ }, { "file": "app-gpui/src/ui_live.rs", - "line": 1095, + "line": 1100, "kind": "literal-candidate" }, { "file": "app-gpui/src/ui_live.rs", - "line": 1870, + "line": 1875, "kind": "literal-candidate" } ], @@ -1771,7 +1771,7 @@ }, { "file": "app-gpui/src/ui_live.rs", - "line": 2077, + "line": 2082, "kind": "literal-candidate" } ], @@ -1798,7 +1798,7 @@ }, { "file": "app-gpui/src/ui_live.rs", - "line": 2263, + "line": 2268, "kind": "literal-candidate" } ], @@ -1825,12 +1825,12 @@ }, { "file": "app-gpui/src/ui_live.rs", - "line": 2522, + "line": 2527, "kind": "literal-candidate" }, { "file": "app-gpui/src/ui_live.rs", - "line": 2553, + "line": 2558, "kind": "literal-candidate" } ], @@ -1852,7 +1852,7 @@ }, { "file": "app-gpui/src/ui_live.rs", - "line": 2696, + "line": 2701, "kind": "literal-candidate" } ], @@ -1938,7 +1938,7 @@ "literal_references": [ { "file": "app-gpui/src/ui_live.rs", - "line": 2835, + "line": 2840, "kind": "literal-candidate" } ], @@ -1966,7 +1966,7 @@ "literal_references": [ { "file": "app-gpui/src/ui_live.rs", - "line": 2889, + "line": 2894, "kind": "literal-candidate" } ], @@ -1994,12 +1994,12 @@ "literal_references": [ { "file": "app-gpui/src/settings_preview.rs", - "line": 1034, + "line": 1038, "kind": "literal-candidate" }, { "file": "app-gpui/src/settings_preview.rs", - "line": 1390, + "line": 1394, "kind": "literal-candidate" } ], @@ -2044,7 +2044,7 @@ "literal_references": [ { "file": "app-gpui/src/ui_live.rs", - "line": 1310, + "line": 1315, "kind": "literal-candidate" } ], @@ -2150,7 +2150,7 @@ "literal_references": [ { "file": "app-gpui/src/settings_preview.rs", - "line": 612, + "line": 616, "kind": "literal-candidate" }, { @@ -2189,7 +2189,7 @@ "literal_references": [ { "file": "app-gpui/src/settings_preview.rs", - "line": 646, + "line": 650, "kind": "literal-candidate" } ], @@ -2223,7 +2223,7 @@ "literal_references": [ { "file": "app-gpui/src/ui_live.rs", - "line": 1328, + "line": 1333, "kind": "literal-candidate" } ], @@ -2270,12 +2270,12 @@ "literal_references": [ { "file": "app-gpui/src/settings_preview.rs", - "line": 760, + "line": 764, "kind": "literal-candidate" }, { "file": "app-gpui/src/ui_live.rs", - "line": 3729, + "line": 3734, "kind": "literal-candidate" } ], @@ -2302,7 +2302,7 @@ }, { "file": "app-gpui/src/ui_live.rs", - "line": 3406, + "line": 3411, "kind": "literal-candidate" } ], @@ -2335,7 +2335,7 @@ }, { "file": "app-gpui/src/ui_live.rs", - "line": 3447, + "line": 3452, "kind": "literal-candidate" } ], @@ -2395,12 +2395,12 @@ }, { "file": "app-gpui/src/settings_preview.rs", - "line": 777, + "line": 781, "kind": "literal-candidate" }, { "file": "app-gpui/src/ui_live.rs", - "line": 3791, + "line": 3796, "kind": "literal-candidate" } ], @@ -2422,12 +2422,12 @@ }, { "file": "app-gpui/src/ui_live.rs", - "line": 661, + "line": 666, "kind": "literal-candidate" }, { "file": "app-gpui/src/ui_live.rs", - "line": 792, + "line": 797, "kind": "literal-candidate" } ], @@ -2736,7 +2736,7 @@ "literal_references": [ { "file": "app-gpui/src/ui_live.rs", - "line": 1102, + "line": 1107, "kind": "literal-candidate" } ], @@ -2780,17 +2780,17 @@ }, { "file": "app-gpui/src/settings_preview.rs", - "line": 546, + "line": 550, "kind": "literal-candidate" }, { "file": "app-gpui/src/settings_preview.rs", - "line": 734, + "line": 738, "kind": "literal-candidate" }, { "file": "app-gpui/src/ui_live.rs", - "line": 3852, + "line": 3857, "kind": "literal-candidate" } ], @@ -2812,17 +2812,17 @@ }, { "file": "app-gpui/src/settings_preview.rs", - "line": 546, + "line": 550, "kind": "literal-candidate" }, { "file": "app-gpui/src/settings_preview.rs", - "line": 734, + "line": 738, "kind": "literal-candidate" }, { "file": "app-gpui/src/ui_live.rs", - "line": 3852, + "line": 3857, "kind": "literal-candidate" } ], @@ -3086,7 +3086,7 @@ "literal_references": [ { "file": "app-gpui/src/ui_live.rs", - "line": 1103, + "line": 1108, "kind": "literal-candidate" } ], @@ -3323,12 +3323,12 @@ "literal_references": [ { "file": "app-gpui/src/settings_preview.rs", - "line": 1384, + "line": 1388, "kind": "literal-candidate" }, { "file": "app-gpui/src/ui_live.rs", - "line": 1078, + "line": 1083, "kind": "literal-candidate" } ], @@ -3394,27 +3394,27 @@ }, { "file": "app-gpui/src/ui_live.rs", - "line": 737, + "line": 742, "kind": "literal-candidate" }, { "file": "app-gpui/src/ui_live.rs", - "line": 752, + "line": 757, "kind": "literal-candidate" }, { "file": "app-gpui/src/ui_live.rs", - "line": 935, + "line": 940, "kind": "literal-candidate" }, { "file": "app-gpui/src/ui_live.rs", - "line": 3980, + "line": 3985, "kind": "literal-candidate" }, { "file": "app-gpui/src/ui_live.rs", - "line": 4960, + "line": 4965, "kind": "literal-candidate" }, { @@ -3436,7 +3436,7 @@ "literal_references": [ { "file": "app-gpui/src/ui_live.rs", - "line": 779, + "line": 784, "kind": "literal-candidate" } ], @@ -3502,7 +3502,7 @@ }, { "file": "app-gpui/src/ui_live.rs", - "line": 3776, + "line": 3781, "kind": "literal-candidate" } ], @@ -3524,7 +3524,7 @@ }, { "file": "app-gpui/src/ui_live.rs", - "line": 3586, + "line": 3591, "kind": "literal-candidate" } ], @@ -3585,12 +3585,12 @@ }, { "file": "app-gpui/src/settings_preview.rs", - "line": 820, + "line": 824, "kind": "literal-candidate" }, { "file": "app-gpui/src/settings_preview.rs", - "line": 871, + "line": 875, "kind": "literal-candidate" }, { @@ -3600,7 +3600,7 @@ }, { "file": "app-gpui/src/ui_live.rs", - "line": 3160, + "line": 3165, "kind": "literal-candidate" } ], @@ -3675,7 +3675,7 @@ "literal_references": [ { "file": "app-gpui/src/ui_live.rs", - "line": 1300, + "line": 1305, "kind": "literal-candidate" } ], @@ -3692,7 +3692,7 @@ "literal_references": [ { "file": "app-gpui/src/settings_preview.rs", - "line": 894, + "line": 898, "kind": "literal-candidate" } ], @@ -3709,7 +3709,7 @@ "literal_references": [ { "file": "app-gpui/src/settings_preview.rs", - "line": 959, + "line": 963, "kind": "literal-candidate" } ], @@ -3758,7 +3758,7 @@ "literal_references": [ { "file": "app-gpui/src/settings_preview.rs", - "line": 925, + "line": 929, "kind": "literal-candidate" } ], @@ -3791,12 +3791,12 @@ }, { "file": "app-gpui/src/settings_preview.rs", - "line": 685, + "line": 689, "kind": "literal-candidate" }, { "file": "app-gpui/src/ui_live.rs", - "line": 3809, + "line": 3814, "kind": "literal-candidate" } ], @@ -3840,12 +3840,12 @@ "literal_references": [ { "file": "app-gpui/src/ui_live.rs", - "line": 1120, + "line": 1125, "kind": "literal-candidate" }, { "file": "app-gpui/src/ui_live.rs", - "line": 3549, + "line": 3554, "kind": "literal-candidate" } ], @@ -3862,17 +3862,17 @@ "literal_references": [ { "file": "app-gpui/src/settings_preview.rs", - "line": 805, + "line": 809, "kind": "literal-candidate" }, { "file": "app-gpui/src/settings_preview.rs", - "line": 845, + "line": 849, "kind": "literal-candidate" }, { "file": "app-gpui/src/settings_preview.rs", - "line": 975, + "line": 979, "kind": "literal-candidate" }, { @@ -3882,22 +3882,22 @@ }, { "file": "app-gpui/src/ui_live.rs", - "line": 3195, + "line": 3200, "kind": "literal-candidate" }, { "file": "app-gpui/src/ui_live.rs", - "line": 3692, + "line": 3697, "kind": "literal-candidate" }, { "file": "app-gpui/src/ui_live.rs", - "line": 4151, + "line": 4156, "kind": "literal-candidate" }, { "file": "app-gpui/src/ui_live.rs", - "line": 4536, + "line": 4541, "kind": "literal-candidate" } ], @@ -3914,7 +3914,7 @@ "literal_references": [ { "file": "app-gpui/src/ui_live.rs", - "line": 3661, + "line": 3666, "kind": "literal-candidate" } ], @@ -3953,7 +3953,7 @@ "literal_references": [ { "file": "app-gpui/src/ui_live.rs", - "line": 1260, + "line": 1265, "kind": "literal-candidate" } ], @@ -4137,7 +4137,7 @@ }, { "file": "app-gpui/src/ui_live.rs", - "line": 4692, + "line": 4697, "kind": "literal-candidate" } ], @@ -4164,7 +4164,7 @@ }, { "file": "app-gpui/src/ui_live.rs", - "line": 4720, + "line": 4725, "kind": "literal-candidate" } ], @@ -4191,7 +4191,7 @@ }, { "file": "app-gpui/src/ui_live.rs", - "line": 4787, + "line": 4792, "kind": "literal-candidate" } ], @@ -4213,7 +4213,7 @@ }, { "file": "app-gpui/src/ui_live.rs", - "line": 4617, + "line": 4622, "kind": "literal-candidate" } ], @@ -4240,7 +4240,7 @@ }, { "file": "app-gpui/src/ui_live.rs", - "line": 4760, + "line": 4765, "kind": "literal-candidate" } ], @@ -4267,7 +4267,7 @@ }, { "file": "app-gpui/src/ui_live.rs", - "line": 4813, + "line": 4818, "kind": "literal-candidate" } ], @@ -4284,7 +4284,7 @@ "literal_references": [ { "file": "app-gpui/src/ui_live.rs", - "line": 3256, + "line": 3261, "kind": "literal-candidate" } ], @@ -4323,7 +4323,7 @@ "literal_references": [ { "file": "app-gpui/src/ui_live.rs", - "line": 1309, + "line": 1314, "kind": "literal-candidate" } ], @@ -4374,7 +4374,7 @@ "literal_references": [ { "file": "app-gpui/src/ui_live.rs", - "line": 1138, + "line": 1143, "kind": "literal-candidate" } ], @@ -4391,7 +4391,7 @@ "literal_references": [ { "file": "app-gpui/src/ui_live.rs", - "line": 3230, + "line": 3235, "kind": "literal-candidate" } ], @@ -4408,17 +4408,17 @@ "literal_references": [ { "file": "app-gpui/src/settings_preview.rs", - "line": 1331, + "line": 1335, "kind": "literal-candidate" }, { "file": "app-gpui/src/ui_live.rs", - "line": 3902, + "line": 3907, "kind": "literal-candidate" }, { "file": "app-gpui/src/ui_live.rs", - "line": 3980, + "line": 3985, "kind": "literal-candidate" } ], @@ -4435,7 +4435,7 @@ "literal_references": [ { "file": "app-gpui/src/ui_live.rs", - "line": 4544, + "line": 4549, "kind": "literal-candidate" } ], @@ -4463,12 +4463,12 @@ "literal_references": [ { "file": "app-gpui/src/ui_live.rs", - "line": 4973, + "line": 4978, "kind": "literal-candidate" }, { "file": "app-gpui/src/ui_live.rs", - "line": 4981, + "line": 4986, "kind": "literal-candidate" } ], @@ -4485,7 +4485,7 @@ "literal_references": [ { "file": "app-gpui/src/ui_live.rs", - "line": 4490, + "line": 4495, "kind": "literal-candidate" } ], @@ -4513,7 +4513,7 @@ "literal_references": [ { "file": "app-gpui/src/ui_live.rs", - "line": 4445, + "line": 4450, "kind": "literal-candidate" } ], @@ -4530,7 +4530,7 @@ "literal_references": [ { "file": "app-gpui/src/ui_live.rs", - "line": 4295, + "line": 4300, "kind": "literal-candidate" } ], @@ -4547,7 +4547,7 @@ "literal_references": [ { "file": "app-gpui/src/ui_live.rs", - "line": 4261, + "line": 4266, "kind": "literal-candidate" } ], diff --git a/app-gpui/glass/MSGlass.swift b/app-gpui/glass/MSGlass.swift index 296f961f..6fe00765 100644 --- a/app-gpui/glass/MSGlass.swift +++ b/app-gpui/glass/MSGlass.swift @@ -53,6 +53,11 @@ private final class Host { let veil = FlippedView() var heroPath: String? var regions: [UInt64: NSView] = [:] + /// each region's kind, so a new transparency retints it in place + var kinds: [UInt64: Kind] = [:] + /// Settings' Glass Transparency, 0 (tinted) to 1 (clear): thins the veil and the panels' tint, and clears the + /// panels' blur, so the art and the desktop show through them + var clarity: CGFloat = 0 /// the electric rim and glow of a selected surface, over its glass var glows: [UInt64: NSView] = [:] var painted = Set() @@ -81,10 +86,42 @@ private final class Host { for view in regions.values { view.removeFromSuperview() } for view in glows.values { view.removeFromSuperview() } regions.removeAll() + kinds.removeAll() glows.removeAll() placed.removeAll() } + /// The veil's alpha: what evens the desktop toward the theme, thinned as the glass is made clearer. + func veilAlpha() -> CGFloat { + (dark ? 0.52 : 0.40) * (1 - 0.85 * clarity) + } + + /// A new transparency: the veil and every surface follow in place (a drag of the slider rebuilds nothing). + func setClarity(_ value: CGFloat) { + let value = min(max(value, 0), 1) + guard value != clarity else { return } + clarity = value + veil.layer?.backgroundColor = color(page, alpha: veilAlpha()).cgColor + if #available(macOS 26.0, *) { + for (id, view) in regions { + guard let glass = view as? NSGlassEffectView, let kind = kinds[id] else { continue } + glass.tintColor = tint(for: kind) + glass.style = style(for: kind) + } + } + } + + /// Panels go from regular glass to clear, lightly blurred glass past the middle of the transparency; the + /// selected card is always clear, and deep glass (settings) stays regular so its text reads. + @available(macOS 26.0, *) + func style(for kind: Kind) -> NSGlassEffectView.Style { + switch kind { + case .selected: return .clear + case .panel, .control: return clarity >= 0.5 ? .clear : .regular + default: return .regular + } + } + init(gpuiView: NSView) { self.gpuiView = gpuiView container.wantsLayer = true @@ -124,7 +161,7 @@ private final class Host { container.addSubview(base, positioned: .below, relativeTo: veil) windowGlass = base veil.frame = container.bounds - veil.layer?.backgroundColor = color(page, alpha: dark ? 0.52 : 0.40).cgColor + veil.layer?.backgroundColor = color(page, alpha: veilAlpha()).cgColor } } @@ -135,7 +172,7 @@ private final class Host { func makeGlass(kind: Kind, radius: CGFloat, tint: NSColor?) -> NSView { if #available(macOS 26.0, *) { let glass = NSGlassEffectView() - glass.style = kind == .selected ? .clear : .regular + glass.style = style(for: kind) glass.cornerRadius = radius glass.tintColor = tint return glass @@ -151,13 +188,16 @@ private final class Host { } /// Each kind its own strength, so surfaces contrast: panels the quietest, then controls, then the primary action. + /// Glass Transparency thins the panels' and controls' tint (to a quarter at 100 %) and the deep glass's a little + /// (its text must still read); the primary action and the selected card keep theirs. func tint(for kind: Kind) -> NSColor? { + let thin = 1 - 0.75 * clarity switch kind { - case .panel: return color(accent, alpha: dark ? 0.14 : 0.24, towardWhite: 0.25) - case .control: return color(accent, alpha: dark ? 0.42 : 0.50, towardWhite: 0.20) + case .panel: return color(accent, alpha: (dark ? 0.14 : 0.24) * thin, towardWhite: 0.25) + case .control: return color(accent, alpha: (dark ? 0.42 : 0.50) * thin, towardWhite: 0.20) case .primary: return NSColor(white: 1.0, alpha: 0.80) case .selected: return color(glowColor, alpha: 0.50) - case .sheet: return color(page, alpha: dark ? 0.62 : 0.55) + case .sheet: return color(page, alpha: (dark ? 0.62 : 0.55) * (1 - 0.3 * clarity)) } } @@ -202,6 +242,7 @@ private final class Host { } else { view = makeGlass(kind: kind, radius: radius, tint: tint(for: kind)) regions[id] = view + kinds[id] = kind if kind == .sheet { sheets.insert(ObjectIdentifier(view)) container.addSubview(view) @@ -264,6 +305,7 @@ private final class Host { sheets.remove(ObjectIdentifier(view)) placed[ObjectIdentifier(view)] = nil regions[id] = nil + kinds[id] = nil if let glow = glows.removeValue(forKey: id) { placed[ObjectIdentifier(glow)] = nil glow.removeFromSuperview() @@ -289,11 +331,13 @@ private final class Host { @_cdecl("ms_glass_begin") public func ms_glass_begin( - _ view: UnsafeMutableRawPointer, _ dark: Bool, _ page: UInt32, _ accent: UInt32, _ glow: UInt32 + _ view: UnsafeMutableRawPointer, _ dark: Bool, _ page: UInt32, _ accent: UInt32, _ glow: UInt32, + _ clarity: Double ) { MainActor.assumeIsolated { guard let host = host(view) else { return } host.retheme(dark: dark, page: page, accent: accent, glow: glow) + host.setClarity(CGFloat(clarity)) host.begin() } } diff --git a/app-gpui/src/liquid_glass.rs b/app-gpui/src/liquid_glass.rs index d5fbc03f..4c08c75e 100644 --- a/app-gpui/src/liquid_glass.rs +++ b/app-gpui/src/liquid_glass.rs @@ -22,7 +22,14 @@ pub enum Glass { #[cfg(target_os = "macos")] unsafe extern "C" { - fn ms_glass_begin(view: *mut core::ffi::c_void, dark: bool, page: u32, accent: u32, glow: u32); + fn ms_glass_begin( + view: *mut core::ffi::c_void, + dark: bool, + page: u32, + accent: u32, + glow: u32, + clarity: f64, + ); fn ms_glass_region( view: *mut core::ffi::c_void, id: u64, @@ -74,7 +81,8 @@ fn region_id(id: &impl Hash) -> u64 { /// The start of a frame's glass: paint it before anything that marks a surface. /// `page` and `accent` are the theme's (0xRRGGBB): they tint the glass. `glow` is what a selected surface glows. -pub fn begin(dark: bool, page: u32, accent: u32, glow: u32) -> impl IntoElement { +/// `clarity`, 0.0 to 1.0, is Settings' Glass Transparency: the higher, the less the panels are tinted and blurred. +pub fn begin(dark: bool, page: u32, accent: u32, glow: u32, clarity: f32) -> impl IntoElement { canvas( |_, _, _| (), move |_, (), window, _| { @@ -82,7 +90,16 @@ pub fn begin(dark: bool, page: u32, accent: u32, glow: u32) -> impl IntoElement COVERED.set(false); if let Some(view) = gpui_view(window) { // SAFETY: view is the window's live GPUI NSView, on the main thread. - unsafe { ms_glass_begin(view, dark, page, accent, glow) } + unsafe { + ms_glass_begin( + view, + dark, + page, + accent, + glow, + f64::from(clarity.clamp(0.0, 1.0)), + ) + } } }, ) diff --git a/app-gpui/src/settings_preview.rs b/app-gpui/src/settings_preview.rs index cc177387..ea6f6cdb 100644 --- a/app-gpui/src/settings_preview.rs +++ b/app-gpui/src/settings_preview.rs @@ -37,6 +37,8 @@ const LANGUAGES: [(&str, &str); 20] = [ #[derive(Clone, Debug)] pub enum SettingsPreviewEvent { LiquidGlass(bool), + /// Liquid Glass's transparency, 0–100 %: how much of the art and desktop shows through its panels (#807). + GlassTransparency(u8), Close, ReopenSetup, LanguageChanged(&'static str), @@ -85,6 +87,8 @@ pub struct AppState { /// Liquid Glass, and whether this Mac has it (macOS 26 and later) pub liquid_glass: bool, pub liquid_glass_available: bool, + /// Liquid Glass's transparency, 0–100 % in steps of 10: 0 is the default, tinted look. + pub glass_transparency: u8, pub library_grid: bool, pub window_size: WindowSize, } @@ -2242,6 +2246,68 @@ impl Render for SettingsPreview { ) .opacity(if app.liquid_glass_available { 1.0 } else { 0.45 }), ); + // Under Liquid Glass: how clear its panels are, from tinted (0 %) to clear (100 %), as macOS's own + // Liquid Glass setting goes from Tinted to Clear. A click or a drag along the track sets it, in tens. + let transparency_row = (app.liquid_glass && app.liquid_glass_available).then(|| { + let value = app.glass_transparency.min(100); + let mut track = div() + .id("glass-transparency") + .flex() + .items_center() + .w(px(170.)) + .h(px(24.)) + .gap(px(2.)) + .cursor_pointer(); + for step in 0..=10u8 { + let percent = step * 10; + let set = move |s: &mut Self, cx: &mut Context| { + if s.app.glass_transparency != percent { + s.app.glass_transparency = percent; + cx.emit(SettingsPreviewEvent::GlassTransparency(percent)); + cx.notify(); + } + }; + track = track.child( + div() + .id(("glass-transparency-step", step as usize)) + .flex_1() + .h_full() + .flex() + .items_center() + .on_mouse_down( + gpui::MouseButton::Left, + cx.listener(move |s, _, _, cx| set(s, cx)), + ) + .on_mouse_move(cx.listener(move |s, event: &gpui::MouseMoveEvent, _, cx| { + if event.pressed_button == Some(gpui::MouseButton::Left) { + set(s, cx) + } + })) + .child( + div() + .w_full() + .h(px(if percent == value { 14. } else { 6. })) + .rounded(px(999.)) + .bg(rgba(if percent <= value { + (p.accent << 8) | 0xff + } else { + p.control_border + })), + ), + ); + } + self.row( + "Glass Transparency", + "How much of the game's art and your desktop shows through Liquid Glass's panels, such as the \ + library's: 0 % is the tinted look, higher is clearer, with a lighter blur.", + div() + .flex() + .items_center() + .gap(px(10.)) + .child(track) + .child(div().w(px(38.)).child(self.text_control(format!("{value}%")))), + ) + }); let library_layout = self.row( self.tr("ui.settings.libraryLayout"), self.tr("ui.settingsDesc.libraryLayout"), @@ -2599,6 +2665,7 @@ impl Render for SettingsPreview { .child(window_size) .child(perf) .child(glass_row) + .children(transparency_row) .child(retina.border_b_0()), false, ), diff --git a/app-gpui/src/ui.rs b/app-gpui/src/ui.rs index e16baad9..c0f4d801 100644 --- a/app-gpui/src/ui.rs +++ b/app-gpui/src/ui.rs @@ -752,6 +752,8 @@ pub struct MetalSharpApp { dock_slots: usize, /// Liquid Glass, Settings > General (macOS 26 and later; off in Low Performance Mode) liquid_glass: bool, + /// Liquid Glass's transparency, 0–100 % (Settings > Library & Display): 0 is the tinted look. + glass_transparency: u8, /// The window background last set (blurred for Liquid Glass) window_glass: Option, /// The right edge of the header's launcher button, as last painted: the glass sidebar ends there @@ -832,6 +834,7 @@ impl MetalSharpApp { low_performance: false, dock_slots: DOCK_VISIBLE_CARDS, liquid_glass: true, + glass_transparency: 0, window_glass: None, launcher_edge: Default::default(), library_grid: false, @@ -1495,6 +1498,7 @@ impl Render for MetalSharpApp { } else { self.theme.accent() }, + self.glass_clarity(), ) })) .child(body) @@ -1665,6 +1669,17 @@ impl MetalSharpApp { self.liquid_glass && !self.low_performance && game_settings_impl::macos_major() >= 26 } + /// Liquid Glass's transparency as 0.0 (tinted) to 1.0 (clear). + fn glass_clarity(&self) -> f32 { + f32::from(self.glass_transparency.min(100)) / 100.0 + } + + /// `alpha` (0–255) of a wash GPUI paints over Liquid Glass, thinned as the glass is made clearer: at 100 % it + /// keeps 40 %, so text over it still reads. + fn glass_wash(&self, alpha: u32) -> u32 { + (alpha as f32 * (1.0 - 0.6 * self.glass_clarity())).round() as u32 + } + /// The theme's palette, with Liquid Glass when it is on. fn palette(&self) -> crate::page_palette::PagePalette { crate::page_palette::PagePalette { @@ -1676,7 +1691,7 @@ impl MetalSharpApp { /// A dropdown's fill: the theme's menu color, or under Liquid Glass a veil of it over the menu's own glass. fn menu_fill(&self) -> gpui::Rgba { if self.glass() { - rgba((self.theme.menu_bg() << 8) | 0x8c) + rgba((self.theme.menu_bg() << 8) | self.glass_wash(0x8c).max(0x60)) } else { rgba((self.theme.menu_bg() << 8) | 0xff) } @@ -1704,7 +1719,10 @@ impl MetalSharpApp { fn chrome(&self) -> (gpui::Rgba, gpui::Rgba) { if self.glass() { // the glass itself is AppKit's, under GPUI: here a wash of the theme's accent over it, and its rim - (rgba((self.theme.accent() << 8) | 0x30), rgba(0xffffff4d)) + ( + rgba((self.theme.accent() << 8) | self.glass_wash(0x30)), + rgba(0xffffff4d), + ) } else { (rgba(0x0c0f10b8), rgba(0xe7eaec4d)) } @@ -2903,7 +2921,7 @@ impl MetalSharpApp { .border_t_1() .border_color(rim) .bg(fill) - .bg(rgba((theme.accent() << 8) | 0x1a)) + .bg(rgba((theme.accent() << 8) | self.glass_wash(0x1a))) .child(crate::liquid_glass::mark( "library-footer", crate::liquid_glass::Glass::Panel, @@ -4656,6 +4674,11 @@ impl MetalSharpApp { this.save_ui_state(cx); cx.notify(); } + E::GlassTransparency(value) => { + this.glass_transparency = (*value).min(100); + this.save_ui_state(cx); + cx.notify(); + } E::LibraryLayout(grid) => { this.library_grid = *grid; // The library behind Settings switches now too. @@ -4715,6 +4738,7 @@ impl MetalSharpApp { low_performance: self.low_performance, liquid_glass: self.liquid_glass, liquid_glass_available: game_settings_impl::macos_major() >= 26, + glass_transparency: self.glass_transparency, library_grid: self.library_grid, window_size: self.window_size, } diff --git a/app-gpui/src/ui_live.rs b/app-gpui/src/ui_live.rs index f1720f25..450a84ee 100644 --- a/app-gpui/src/ui_live.rs +++ b/app-gpui/src/ui_live.rs @@ -552,6 +552,10 @@ impl MetalSharpApp { .get("liquidGlass") .and_then(Value::as_bool) .unwrap_or(true); + self.glass_transparency = value + .get("glassTransparency") + .and_then(Value::as_u64) + .map_or(0, |percent| percent.min(100) as u8); self.library_grid = value.get("libraryLayout").and_then(Value::as_str) == Some("grid"); self.window_size = value .get("windowSize") @@ -609,6 +613,7 @@ impl MetalSharpApp { "developerMode": self.developer_mode, "lowPerformanceMode": self.low_performance, "liquidGlass": self.liquid_glass, + "glassTransparency": self.glass_transparency, "libraryLayout": if self.library_grid { "grid" } else { "steamDeck" }, "windowSize": self.window_size, "libraryPage": self.page.storage_id(),