Run Windows games on Apple Silicon — free, open source, with an open compatibility database that tells you what actually works.
Swift apple-silicond3dmetaldxmtdxvkfexgame-porting-toolkitgamingmac-gamingmacosmetalmoltenvksteamswiftuivkd3d-protonwhisky-alternativewindows-gameswinewine-wrapper
import AppKit
import HighballKit
import SwiftUI
import UniformTypeIdentifiers
// MARK: - Design tokens
enum HB {
static let amber = Color(red: 0.86, green: 0.62, blue: 0.28)
static let amberDeep = Color(red: 0.63, green: 0.40, blue: 0.11)
static let ground = Color(red: 0.086, green: 0.070, blue: 0.048)
static let card = Color.white.opacity(0.055)
static let cardStroke = Color.white.opacity(0.08)
static let good = Color(red: 0.45, green: 0.78, blue: 0.60)
static let warn = amber
static let bad = Color(red: 0.88, green: 0.48, blue: 0.48)
static func eyebrow(_ text: String) -> some View {
Text(text.uppercased())
.font(.system(size: 11, weight: .semibold))
.kerning(1.4)
.foregroundStyle(.secondary)
}
}
// MARK: - Bottle screen
struct BottleView: View {
@Environment(AppState.self) private var state
@Environment(\.dismiss) private var dismiss
let bottle: Bottle
// epic-games is deliberately absent: its installer cannot pass its permission audit
// under Wine (issue #14) — the Epic path is "Connect Epic account" (Legendary) below,
// and showing an "Install Epic Games" tile above it contradicted that.
static let launcherMeta: [(id: String, symbol: String, short: String)] = [
("steam", "gamecontroller.fill", "Steam"),
("battle-net", "shield.fill", "Battle.net"), ("gog-galaxy", "g.circle.fill", "GOG Galaxy"),
("ea-app", "e.square.fill", "EA app"), ("ubisoft-connect", "u.circle.fill", "Ubisoft"),
("rockstar", "r.circle.fill", "Rockstar"),
]
@Binding var navigationPath: NavigationPath
@State private var editingPin: Pin?
private var engine: InstalledEngine? { state.engine(for: bottle) }
/// Pins that aren't one of the known launchers (dropped .exe files, custom programs).
/// The filter itself lives in the Kit so the unified library shares one definition.
private var customPins: [Pin] {
bottle.settings.pins.filter { !LibraryIndex.isLauncherPin($0) }
}
var body: some View {
ScrollView {
VStack(alignment: .leading, spacing: 34) {
HStack(spacing: 12) {
Button { dismiss() } label: {
Label(L("Back"), systemImage: "chevron.left")
}
Button {
navigationPath.append(EnvironmentSettingsDestination(name: bottle.name))
} label: { Label(L("Environment settings"), systemImage: "slider.horizontal.3") }
.buttonStyle(.bordered)
.help(L("Renderer, synchronization, Windows version…"))
Menu {
Button(L("Show the Windows drive")) { NSWorkspace.shared.open(bottle.driveC) }
Button(L("Uninstall Windows programs…")) { state.openUninstaller(in: bottle) }
Button(L("Test controllers…")) { state.openControllerTest(in: bottle) }
Button(L("Stop all processes")) { state.killBottle(bottle) }
} label: { Label(L("More"), systemImage: "ellipsis.circle") }
Spacer()
if state.busy { ProgressView().controlSize(.small) }
}
launchersSection
if !customPins.isEmpty { programsSection }
HStack(spacing: 6) {
Button { state.chooseProgramToRun(in: bottle.name) } label: {
Label(L("Run a Windows program…"), systemImage: "folder")
}.buttonStyle(.link)
Text(L("— or drop any .exe or .msi on this window")).font(.caption).foregroundStyle(.secondary)
}
}
.padding(.horizontal, 28)
.padding(.top, 18)
.padding(.bottom, 40)
.frame(maxWidth: .infinity, alignment: .leading)
}
.background(BottleBackdrop())
.navigationTitle(bottle.name)
.navigationSubtitle(engine?.displayName ?? "")
.navigationBarBackButtonHidden()
.toolbar {
ToolbarItem(placement: .confirmationAction) {
if navigationPath.count == 1 {
Button(L("Done")) { dismiss() }.keyboardShortcut(.defaultAction)
}
}
}
.background { if navigationPath.count == 1 { PageCancelShortcut { dismiss() } } }
.sheet(item: $editingPin) { p in PinSettingsSheet(pin: p, bottle: bottle) }
.onDrop(of: [.fileURL], isTargeted: nil) { providers in
guard let provider = providers.first else { return false }
_ = provider.loadObject(ofClass: URL.self) { url, _ in
guard let url else { return }
if ["exe", "msi", "bat"].contains(url.pathExtension.lowercased()) {
Task { @MainActor in state.pendingRunBottle = bottle.name; state.pendingRun = url }
} else if AppState.isDiscImage(url) {
Task { @MainActor in state.openDiscImage(url, in: bottle.name) }
} else {
// Silently ignoring a drop reads as "nothing happened" (Reddit report) — say why.
Task { @MainActor in
state.errorMessage = String(format: L("'%@' isn't a Windows program. You can drop .exe, .msi or .bat files here."), url.lastPathComponent)
}
}
}
return true
}
}
// MARK: Launchers
private var launchersSection: some View {
VStack(alignment: .leading, spacing: 12) {
HB.eyebrow(L("Launchers"))
LazyVGrid(columns: [GridItem(.adaptive(minimum: 108, maximum: 140), spacing: 12)], spacing: 12) {
// GOG Galaxy's blocked client gives way to Connect GOG, as in Add games, unless
// this environment already has it.
ForEach(Self.launcherMeta.filter { $0.id != "gog-galaxy" || bottle.settings.recipes.contains($0.id) }, id: \.id) { meta in
if let recipe = AppState.recipe(meta.id) {
let installed = bottle.settings.recipes.contains(meta.id)
let pin = bottle.settings.pins.first { $0.name.lowercased().hasPrefix(meta.short.lowercased().prefix(5)) }
LauncherTile(title: meta.short, symbol: meta.symbol, installed: installed, busy: state.busy,
blockedReason: recipe.blocked?.reason, flakyReason: recipe.flaky?.reason) {
if installed, let pin { state.launch(pin: pin, in: bottle) }
else { state.applyRecipe(meta.id, to: bottle) }
}
.contextMenu {
if MacAppStub.existing(for: meta.short) != nil {
Button(L("Remove the Mac app")) { state.removeMacApp(title: meta.short) }
} else {
Button(L("Make a Mac app…")) { state.makeMacApp(forLauncher: meta.id, short: meta.short) }
}
if installed, let pin {
Button(L("Open")) { state.launch(pin: pin, in: bottle) }
Button(L("Program settings…")) { editingPin = pin }
Button(L("Remove from list"), role: .destructive) { state.removePin(pin, from: bottle) }
}
}
}
}
}
Text(L("Kernel anti-cheat titles (Valorant, Fortnite, Destiny 2…) can’t work through Wine — check the compatibility database before big downloads."))
.font(.system(size: 11)).foregroundStyle(.tertiary)
.padding(.top, 2)
}
}
// MARK: Custom programs
private var programsSection: some View {
VStack(alignment: .leading, spacing: 12) {
HB.eyebrow(L("Programs"))
VStack(spacing: 1) {
ForEach(customPins) { pin in
HStack {
Image(systemName: "app.dashed").foregroundStyle(.secondary)
Text(pin.name)
if let r = pin.renderer { RendererBadge(renderer: r) }
Spacer()
Button(L("Run")) { state.launch(pin: pin, in: bottle) }
.buttonStyle(.bordered).controlSize(.small)
.disabled(state.busy)
}
.padding(.horizontal, 14).padding(.vertical, 9)
.background(HB.card)
.help(pin.path)
.contextMenu {
Button(L("Program settings…")) { editingPin = pin }
Menu(L("Renderer override")) {
Button(L("Environment default")) { state.setPinRenderer(nil, pin: pin, in: bottle) }
ForEach(Renderer.allCases, id: \.self) { r in
Button(r.rawValue.uppercased()) { state.setPinRenderer(r, pin: pin, in: bottle) }
}
}
Divider()
Button(L("Remove from list"), role: .destructive) { state.removePin(pin, from: bottle) }
}
}
}
.clipShape(RoundedRectangle(cornerRadius: 10))
.overlay(RoundedRectangle(cornerRadius: 10).stroke(HB.cardStroke))
}
}
}
/// Subtle warm wash so the surface reads as Highball's, not a system window.
struct BottleBackdrop: View {
var body: some View {
ZStack {
HB.ground
RadialGradient(colors: [HB.amber.opacity(0.09), .clear],
center: .topLeading, startRadius: 0, endRadius: 720)
RadialGradient(colors: [HB.amberDeep.opacity(0.06), .clear],
center: .bottomTrailing, startRadius: 0, endRadius: 900)
}
.ignoresSafeArea()
}
}
// MARK: - Tiles
struct LauncherTile: View {
let title: String
let symbol: String
let installed: Bool
let busy: Bool
var blockedReason: String? = nil
var flakyReason: String? = nil
let action: () -> Void
@State private var hovering = false
@State private var showingReason = false
private var blocked: Bool { blockedReason != nil && !installed }
private var flaky: Bool { flakyReason != nil && !installed && !blocked }
var body: some View {
// A blocked tile still takes the click and answers with its reason: macOS shows no tooltip
// on a disabled control, so the hover text alone left "Blocked" unexplained (highball#571).
Button(action: { if blocked { showingReason = true } else { action() } }) {
VStack(spacing: 8) {
ZStack(alignment: .bottomTrailing) {
ZStack {
Circle()
.fill(installed
? AnyShapeStyle(LinearGradient(colors: [HB.amber, HB.amberDeep], startPoint: .top, endPoint: .bottom))
: AnyShapeStyle(HB.card))
.frame(width: 44, height: 44)
Image(systemName: symbol)
.font(.system(size: 18, weight: .semibold))
.foregroundStyle(installed ? Color(red: 0.14, green: 0.09, blue: 0.02) : .secondary)
}
if !installed {
ZStack {
Circle().fill(HB.ground).frame(width: 17, height: 17)
Image(systemName: "plus.circle.fill")
.font(.system(size: 15))
.foregroundStyle(HB.amber)
}
.offset(x: 3, y: 3)
}
}
Text(title).font(.system(size: 11.5, weight: .medium)).lineLimit(1)
Text(installed ? L("Open") : (blocked ? L("Blocked") : (flaky ? L("Flaky") : L("Install"))))
.font(.system(size: 9.5).monospaced())
.foregroundStyle(installed ? AnyShapeStyle(HB.good)
: (blocked ? AnyShapeStyle(HB.bad.opacity(0.85))
: (flaky ? AnyShapeStyle(HB.amber) : AnyShapeStyle(.tertiary))))
}
.frame(maxWidth: .infinity)
.padding(.vertical, 12)
.background(RoundedRectangle(cornerRadius: 11).fill(hovering && !blocked ? Color.white.opacity(0.09) : HB.card))
.overlay(RoundedRectangle(cornerRadius: 11).stroke(hovering && !blocked ? HB.amber.opacity(0.4) : HB.cardStroke))
.opacity(blocked ? 0.55 : 1)
}
.buttonStyle(.plain)
.disabled(busy)
.help(blockedReason.map { L("Blocked on the current engine: ") + $0 }
?? flakyReason.map { L("Known issues: ") + $0 } ?? "")
.popover(isPresented: $showingReason, arrowEdge: .bottom) {
Text(L("Blocked on the current engine: ") + (blockedReason ?? ""))
.font(.callout)
.fixedSize(horizontal: false, vertical: true)
.frame(width: 320, alignment: .leading)
.padding(14)
}
.animation(.easeOut(duration: 0.12), value: hovering)
.onHover { hovering = $0 }
}
}
struct RendererBadge: View {
let renderer: Renderer
var body: some View {
Text(renderer.rawValue.uppercased())
.font(.caption2.monospaced())
.padding(.horizontal, 5).padding(.vertical, 1)
.overlay(RoundedRectangle(cornerRadius: 3).stroke(.secondary.opacity(0.6)))
}
}
// MARK: - Environment settings page
private enum EnvironmentSettingsSection: CaseIterable {
case graphics, display, compatibility, components, advanced
var title: String {
switch self {
case .graphics: L("Graphics")
case .display: L("Display")
case .compatibility: L("Compatibility")
case .components: L("Windows components")
case .advanced: L("Advanced")
}
}
}
struct EnvironmentSettingsPage: View {
@Environment(AppState.self) private var state
@Environment(\.dismiss) private var dismiss
let bottle: Bottle
// Settings' TabView owns the window toolbar; its generated navigation arrow does not pop.
var showsInlineBack = false
@State private var selectedSection: EnvironmentSettingsSection = .graphics
@AppStorage(EngineStore.showOlderRevisionsKey) private var showOlderRevisions = false
@State private var confirmDelete = false
@State private var showFrameGenInfo = false
/// small ⓘ next to a frame-generation control; the detail lives in the popover,
/// so "How frame generation works" stays about frame generation in general
private func infoIcon(_ text: String) -> some View {
InfoButton(text: L(text))
}
/// Live slider value while dragging; nil means "read the saved dpiScale". Applied on release
/// only, so dragging doesn't fire a wine registry write on every step.
@State private var dpiDraft: Double? = nil
private var currentDpi: Int { (state.bottles.first { $0.name == bottle.name } ?? bottle).settings.dpiScale }
private var liveBottle: Bottle { state.bottles.first { $0.name == bottle.name } ?? bottle }
private var currentRenderer: Renderer { liveBottle.settings.renderer }
private var engine: InstalledEngine? { state.engine(for: liveBottle) }
private var d3dmetalAvailable: Bool { engine?.rendererDir("d3dmetal") != nil }
private var dlssAvailable: Bool { engine.map { liveBottle.supportsDLSS(engine: $0) } ?? false }
private var vkd3dAvailable: Bool { engine?.rendererDir("vkd3d") != nil }
private var d3dmetalPossible: Bool {
guard let engine else { return false }
return FileManager.default.fileExists(atPath: engine.frameworksDir.appending(path: "renderer/d3dmetal/wine").path)
}
var body: some View {
VStack(spacing: 0) {
HStack(spacing: 10) {
if showsInlineBack {
Button { dismiss() } label: {
Label(L("Back"), systemImage: "chevron.left")
}
}
VStack(alignment: .leading, spacing: 4) {
Text(bottle.name).font(.title2.bold())
// "Wine 10.0", as the engine prompts say it: the full build name and revision are
// under Advanced, and at full length they crowded the title.
Text(engine.map { GamePageCopy.shortEngineName($0.manifest) } ?? "")
.font(.caption).foregroundStyle(.secondary).lineLimit(1)
}
Spacer()
Text(L("Changes save automatically")).font(.caption).foregroundStyle(.secondary)
// In the Settings window the page already has Back, which does the same thing.
if !showsInlineBack {
Button(L("Done")) { dismiss() }.keyboardShortcut(.defaultAction)
}
}
.padding(.horizontal, 20).padding(.top, 16)
ScrollView(.horizontal, showsIndicators: false) {
HStack(spacing: 6) {
ForEach(EnvironmentSettingsSection.allCases, id: \.self) { section in
FilterChip(label: section.title, on: selectedSection == section) { selectedSection = section }
.accessibilityAddTraits(selectedSection == section ? .isSelected : [])
}
}
.padding(.horizontal, 20).padding(.vertical, 14)
}
Divider()
Form {
if selectedSection == .graphics {
Section(L("Graphics")) {
// Not the generic binding: picking a renderer here is an explicit choice,
// which recipes must never clobber afterwards (#29).
Picker(L("Renderer"), selection: Binding(
get: { (state.bottles.first { $0.name == bottle.name } ?? bottle).settings.renderer },
set: { newValue in
var copy = state.bottles.first { $0.name == bottle.name } ?? bottle
copy.settings.renderer = newValue
copy.settings.rendererExplicit = true
if let engine, !copy.supportsDLSS(engine: engine, renderer: newValue) {
copy.settings.dlssEnabled = false
}
Task { @MainActor in state.update(copy) }
})) {
Text(L("DXMT — D3D10/11 → Metal (default)")).tag(Renderer.dxmt)
// Shown when selectable, and when it is the setting even though this
// engine cannot run it: a picker that hides the current value reads as
// empty, and the row below says what happens instead (#61).
if d3dmetalAvailable || currentRenderer == .d3dmetal { Text(L("D3DMetal — D3D11/12, Apple")).tag(Renderer.d3dmetal) }
Text(L("DXVK — D3D9/10/11 → Vulkan")).tag(Renderer.dxvk)
if vkd3dAvailable || currentRenderer == .vkd3d { Text(L("vkd3d-proton — D3D12 → Vulkan (experimental)")).tag(Renderer.vkd3d) }
Text(L("WineD3D — slow fallback")).tag(Renderer.wined3d)
}
Toggle(L("Enable DLSS (MetalFX)"), isOn: Binding(
get: { dlssAvailable && liveBottle.settings.dlssEnabled },
set: { enabled in
var copy = liveBottle
copy.settings.dlssEnabled = dlssAvailable && enabled
Task { @MainActor in state.update(copy) }
}))
.disabled(!dlssAvailable)
Text(L("Lets games that support DLSS use the MetalFX translation in DXMT or D3DMetal. Turn DLSS on in the game's own graphics settings too. Stop and relaunch the environment after changing this."))
.font(.caption).foregroundStyle(.secondary)
if !d3dmetalAvailable, currentRenderer == .d3dmetal, let engine, let why = Renderer.d3dmetal.unavailableReason(in: engine) {
Text(String(format: L("Programs here start with %@ until this is resolved: %@"), GamePageCopy.plainName(Renderer.fallback(for: .d3dmetal, in: engine)), why))
.font(.caption).foregroundStyle(.secondary)
}
if !d3dmetalAvailable && d3dmetalPossible {
HStack {
Text(L("D3DMetal (needed for DirectX 12) requires accepting Apple’s Game Porting Toolkit license."))
.font(.caption).foregroundStyle(.secondary)
Button(L("Review license…")) {
Task { @MainActor in
state.licenseEngine = engine
state.loadGPTKLicense()
state.showGPTKLicense = true
}
}.controlSize(.small)
}
}
// only engines that ship the shim get the control
if let engine, let shim = state.lsfgShimDirs[engine.id] {
Picker(L("Frame generation (Lossless Scaling, beta)"), selection: Binding(
get: { liveBottle.settings.frameGen },
set: { newValue in
let turnedOn = liveBottle.settings.frameGen <= 1 && newValue > 1
var copy = state.bottles.first { $0.name == bottle.name } ?? bottle
copy.settings.frameGen = newValue
Task { @MainActor in state.update(copy) }
if turnedOn { showFrameGenInfo = true }
})) {
Text(L("Off")).tag(1)
Text("2×").tag(2)
Text("3×").tag(3)
Text("4×").tag(4)
}
HStack(spacing: 6) {
Button(L("How frame generation works")) { showFrameGenInfo = true }
.buttonStyle(.link).controlSize(.small)
infoIcon("How many frames are shown for each frame the game renders. 2× puts one generated frame between every pair of real frames, 4× puts three. Higher multipliers need more GPU headroom and only pay off on a display fast enough to show them.")
}
if liveBottle.settings.frameGen > 1 {
HStack(spacing: 6) {
Toggle(L("Adaptive pacing"), isOn: binding(\.frameGenAdaptive))
infoIcon("Measures the game's own frame rate and inserts only as many frames as it takes to fill the display, up to the multiplier: a 45 fps game gets one extra frame every other frame, and a game already at the refresh rate is left alone.")
}
HStack(spacing: 6) {
Toggle(L("Performance mode"), isOn: binding(\.frameGenPerformance))
infoIcon("Uses Lossless Scaling's cheaper shader set: noticeably less GPU time per generated frame, with slightly softer interpolation around fast motion.")
}
HStack(spacing: 6) {
Toggle(L("Force vsync"), isOn: binding(\.frameGenForceVsync))
if liveBottle.settings.frameGenForceVsync {
infoIcon("Paces generated frames to the display. Turn it off to let the game present at its own rate instead.")
} else {
InfoButton(text: L("The game presents at its own rate. Frames beyond the display's refresh rate are discarded and the image can tear, so this only helps above 60 Hz."), warning: true)
}
}
HStack(spacing: 6) {
Picker(L("Motion estimation resolution"), selection: binding(\.frameGenFlowScale)) {
Text("100%").tag(100)
Text("75%").tag(75)
Text("50%").tag(50)
}
infoIcon("Resolution used to estimate motion, as a percentage of the frame. Lower is cheaper and can help a GPU-bound game, at the cost of accuracy around small or fast-moving detail.")
}
}
switch liveBottle.frameGenStatus(shim: shim) {
case .unavailable(let why):
Text(String(format: L("Frame generation stays off: %@"), L(why)))
.font(.caption).foregroundStyle(.secondary)
case .active:
Text(L("After changing this, stop the environment and relaunch so a Steam game picks it up."))
.font(.caption).foregroundStyle(.secondary)
case .off:
EmptyView()
}
// The shader DLL is a plain file, so a copy of Lossless Scaling in another Wine
// setup (CrossOver, a second account) serves as well as one installed here. A
// picker beats typing LSFGM_DLL_PATH by hand (discussion #196).
if liveBottle.settings.frameGen > 1 {
HStack(spacing: 8) {
Button(L("Use a Lossless Scaling DLL from elsewhere…")) { chooseFrameGenDLL() }
.controlSize(.small)
if let override = liveBottle.settings.environment["LSFGM_DLL_PATH"], !override.isEmpty {
Text(override).font(.caption).foregroundStyle(.secondary)
.lineLimit(1).truncationMode(.middle)
Button(L("Clear")) { setFrameGenDLL(nil) }.buttonStyle(.link).controlSize(.small)
}
}
}
}
Toggle(L("Metal performance HUD"), isOn: binding(\.metalHUD))
Toggle(L("DXVK async shader compilation (experimental — can skip draws while a shader compiles)"), isOn: binding(\.dxvkAsync))
}
}
if selectedSection == .display {
Section(L("Display")) {
Picker(L("Frame rate cap"), selection: binding(\.fpsCap)) {
Text(L("Uncapped")).tag(0)
Text("30 fps").tag(30)
Text("60 fps").tag(60)
Text("120 fps").tag(120)
}
VStack(alignment: .leading, spacing: 4) {
HStack {
Text(L("Display scaling"))
Spacer()
Text("\(Int(((dpiDraft ?? Double(currentDpi)) / 96 * 100).rounded()))%")
.foregroundStyle(.secondary).monospacedDigit()
}
Slider(
value: Binding(get: { dpiDraft ?? Double(currentDpi) }, set: { dpiDraft = $0 }),
in: 96...240, step: 24,
onEditingChanged: { editing in
if !editing, let v = dpiDraft {
state.setDpi(Int(v.rounded()), in: state.bottles.first { $0.name == bottle.name } ?? bottle)
dpiDraft = nil
}
})
}
Text(L("Scales the Windows desktop and UI, 100% to 250%. Launchers and desktop apps follow it; many full-screen games set their own resolution and won't. Above 100% uses native Retina pixels, so heavy games may run slower."))
.font(.caption).foregroundStyle(.secondary)
// Above 100% Retina pixels are always on, so the choice only exists at 100%.
if Int((dpiDraft ?? Double(currentDpi)).rounded()) <= 96 {
Toggle(L("Retina resolution at 100%"), isOn: Binding(
get: { liveBottle.settings.retinaAt100 },
set: { state.setDpi(currentDpi, retinaAt100: $0, in: liveBottle) }))
Text(L("For a game whose own interface grows with the scaling. Games get the display's full pixel count with nothing scaled up, while Windows apps like Steam draw at half size."))
.font(.caption).foregroundStyle(.secondary)
}
}
}
if selectedSection == .compatibility {
Section(L("Compatibility")) {
Picker(L("Synchronization"), selection: binding(\.sync)) {
Text(L("msync — fastest for most games")).tag(SyncMode.msync)
Text(L("None — required for Steam/CEF launchers")).tag(SyncMode.none)
Text("esync").tag(SyncMode.esync)
}
Picker(L("Windows version"), selection: binding(\.windowsVersion)) {
ForEach(WindowsVersion.allCases, id: \.self) { Text($0.rawValue).tag($0) }
}
// Rosetta's switch; an arm64 engine runs x86 code through FEX and has none.
if engine?.manifest.requiresRosetta ?? true {
Toggle(L("Advertise AVX to games (Rosetta)"), isOn: binding(\.advertiseAVX))
}
Toggle(L("Use ⌘C / ⌘V inside Windows apps"), isOn: binding(\.commandIsControl))
Text(L("Maps the Command keys to Ctrl, so Mac copy and paste work in Steam and games. Option becomes Alt so Alt-based bindings keep working. Off = Wine's default, where Command acts as Alt."))
.font(.caption).foregroundStyle(.secondary)
Text(L("Games run with the environment’s sync (msync is fastest). Opening the Steam window restarts Windows processes with sync off — its interface needs it."))
.font(.caption).foregroundStyle(.secondary)
Toggle(L("Keep game files inside this environment"), isOn: Binding(
get: { (state.bottles.first { $0.name == bottle.name } ?? bottle).settings.keepFilesInside },
set: { on in state.setKeepFilesInside(on, for: bottle) }))
Text(L("On, the Windows Documents folder lives inside this environment, so games that save there (FromSoftware, Bandai Namco, the Sims and others) no longer write into your Mac's Documents. Files already in your Mac's Documents stay there and the game starts fresh here. Off again keeps the environment's folder as “Documents (environment)”. Saves kept inside go with the environment when you delete it."))
.font(.caption).foregroundStyle(.secondary)
}
}
if selectedSection == .advanced {
Section(L("Advanced")) {
let offered = state.offeredEngines(for: state.bottles.first { $0.name == bottle.name } ?? bottle)
if offered.count > 1 {
Picker(L("Engine"), selection: Binding(
get: { (state.bottles.first { $0.name == bottle.name } ?? bottle).settings.engineID },
set: { newID in
let current = state.bottles.first { $0.name == bottle.name } ?? bottle
guard newID != current.settings.engineID else { return }
dismiss() // show the switch confirmation from the main window
state.engineTransition = AppState.EngineTransition(bottleName: current.name, targetID: newID)
})) {
ForEach(offered, id: \.id) { e in
Text(verbatim: e.missing ? "\(e.label) (\(L("missing")))" : e.installed ? e.label : "\(e.label) (\(L("download")))").tag(e.id)
}
}
.disabled(state.busy)
Toggle(L("Show older engine revisions"), isOn: $showOlderRevisions)
Text(L("Environments never change engine on their own. Switching re-runs the Windows setup when the Wine build differs; switching back is the same step. An engine marked download is fetched first."))
.font(.caption).foregroundStyle(.secondary)
}
TextField(L("DLL overrides"), text: binding(\.dllOverrides), prompt: Text(verbatim: "version=n,b;winmm=n,b"))
.font(.body.monospaced())
Text(L("Extra Wine DLL overrides for this environment, semicolon separated. Mods like Cyber Engine Tweaks need version=n,b."))
.font(.caption).foregroundStyle(.secondary)
let ignoredDlls = WineRunner.dllOverridesIgnored(binding(\.dllOverrides).wrappedValue)
if !ignoredDlls.isEmpty {
Text(L("Ignored, not name=n,b: ") + ignoredDlls.joined(separator: ", ")).font(.caption).foregroundStyle(HB.amber)
}
EnvEditor(bottle: bottle)
Text(L("Environment variables, one KEY=VALUE per line. Applied to everything launched in this environment."))
.font(.caption).foregroundStyle(.secondary)
}
Section {
Button(L("Delete environment…"), role: .destructive) { confirmDelete = true }
}
}
if selectedSection == .components {
let tweaks = AppState.tweakRecipes()
if !tweaks.isEmpty {
Section(L("Windows components")) {
ForEach(tweaks, id: \.id) { r in
HStack {
Text(r.title)
Spacer()
let live = state.bottles.first { $0.name == bottle.name } ?? bottle
if state.isApplying(r, in: live) {
// A component reads as installed once every step has run, not when its files first appear.
HStack(spacing: 6) {
ProgressView().controlSize(.small)
Text(L("Installing…")).foregroundStyle(.secondary)
}
} else if live.settings.recipes.contains(r.id) || state.tweakIsInstalled(r, in: live) {
Label(L("Installed"), systemImage: "checkmark.circle.fill").foregroundStyle(.green).labelStyle(.titleAndIcon)
if r.isRemovable {
Button(L("Remove")) { state.removeTweak(r, from: live) }.controlSize(.small).disabled(state.busy)
}
} else {
Button(L("Install")) { state.applyRecipe(r.id, to: live) }
.controlSize(.small).disabled(state.busy)
}
}
}
Text(L("Windows runtimes some games need. Install them when a game complains about a missing runtime or refuses to start."))
.font(.caption).foregroundStyle(.secondary)
}
}
}
}
.formStyle(.grouped)
}
.navigationTitle(L("Environment settings"))
.navigationBarBackButtonHidden(showsInlineBack)
.background { PageCancelShortcut { dismiss() } }
.deleteEnvironmentDialog(bottle.name, isPresented: $confirmDelete) { dismiss() }
.alert(L("About frame generation"), isPresented: $showFrameGenInfo) {
Button(L("Got it"), role: .cancel) {}
} message: {
Text(L("Lossless Scaling inserts interpolated frames between the game's real frames to make motion look smoother.\n\nBy default the generated frames are paced to your display, so it never presents more than your screen's refresh rate. It therefore helps most when a game runs BELOW your refresh rate, for example a demanding game locked at 30 fps smoothed up to 60. On the built-in 60 Hz display a game already running above 60 is capped to 60 and feels worse, not better. It pays off on an external high-refresh monitor (120 Hz or more), where a 60 fps game becomes 120.\n\nIt also adds a little input lag, because a real frame is held back to interpolate.\n\nIt works with every graphics mode: DXVK and vkd3d-proton through Vulkan, DXMT and D3DMetal through Metal, and WineD3D on its own renderer, OpenGL or Vulkan.\n\nAfter changing any of these settings, stop the environment and relaunch so a Steam game picks up the new one.\n\nThis is a beta feature: some games may show artifacts, stutter or not start with it on. Turn it off if a game misbehaves.\n\nClick the ⓘ beside each setting to see what that one does."))
}
}
/// Picks lsfg-vk.dll wherever it lives and records it as the environment's LSFGM_DLL_PATH,
/// the same variable the environment editor accepts by hand.
private func chooseFrameGenDLL() {
let panel = NSOpenPanel()
panel.canChooseDirectories = false
panel.allowsMultipleSelection = false
if let dll = UTType(filenameExtension: "dll") { panel.allowedContentTypes = [dll] }
panel.message = L("Choose lsfg-vk.dll from a Lossless Scaling install on its lsfg-vk beta branch")
guard panel.runModal() == .OK, let url = panel.url else { return }
setFrameGenDLL(url.path)
}
private func setFrameGenDLL(_ path: String?) {
var copy = state.bottles.first { $0.name == bottle.name } ?? bottle
if let path { copy.settings.environment["LSFGM_DLL_PATH"] = path }
else { copy.settings.environment.removeValue(forKey: "LSFGM_DLL_PATH") }
Task { @MainActor in state.update(copy) }
}
private func binding<T>(_ keyPath: WritableKeyPath<BottleSettings, T>) -> Binding<T> {
Binding(
get: { (state.bottles.first { $0.name == bottle.name } ?? bottle).settings[keyPath: keyPath] },
set: { newValue in
var copy = state.bottles.first { $0.name == bottle.name } ?? bottle
copy.settings[keyPath: keyPath] = newValue
Task { @MainActor in state.update(copy) }
})
}
}
/// The question before an environment goes: keep a copy of its saves first (the default), or
/// delete everything as before. The size of the copy is measured off the main actor while the
/// question is up.
private struct DeleteEnvironmentDialog: ViewModifier {
@Environment(AppState.self) private var state
let name: String?
@Binding var isPresented: Bool
let onDelete: () -> Void
@State private var savesSize: String?
func body(content: Content) -> some View {
content
.confirmationDialog(String(format: L("Delete the %@ environment?"), name ?? ""),
isPresented: $isPresented, titleVisibility: .visible) {
Button(L("Keep saves")) { delete(keepSaves: true) }.keyboardShortcut(.defaultAction)
Button(L("Delete everything"), role: .destructive) { delete(keepSaves: false) }
Button(L("Cancel"), role: .cancel) {}
} message: {
Text(savesSize.map { String(format: L("Its Windows drive and everything installed in it are removed. Keep saves first puts a copy of its saves folders (%@) in Highball's save-backups folder."), $0) }
?? L("Its Windows drive and everything installed in it are removed. Keep saves first puts a copy of its saves folders in Highball's save-backups folder."))
}
.task(id: isPresented ? name : nil) {
savesSize = nil
guard isPresented, let name else { return }
let environment = state.paths.bottle(name)
let bytes = await Task.detached { EnvironmentSaves.bytes(environment: environment) }.value
savesSize = ByteCountFormatter.string(fromByteCount: bytes, countStyle: .file)
}
}
private func delete(keepSaves: Bool) {
guard let name else { return }
onDelete()
state.deleteBottle(name, keepSaves: keepSaves)
}
}
extension View {
func deleteEnvironmentDialog(_ name: String?, isPresented: Binding<Bool>, onDelete: @escaping () -> Void = {}) -> some View {
modifier(DeleteEnvironmentDialog(name: name, isPresented: isPresented, onDelete: onDelete))
}
}
// MARK: - Onboarding & license sheet
struct OnboardingView: View {
@Environment(AppState.self) private var state
var body: some View {
ZStack {
BottleBackdrop()
VStack(spacing: 18) {
if let url = Bundle.main.url(forResource: "AppIcon", withExtension: "png"), let img = NSImage(contentsOf: url) {
Image(nsImage: img).resizable().frame(width: 104, height: 104)
.shadow(color: HB.amber.opacity(0.35), radius: 18, y: 6)
} else {
Image(systemName: "wineglass.fill").font(.system(size: 52)).foregroundStyle(.tint)
}
Text("Highball").font(.system(size: 36, weight: .heavy, design: .rounded))
Text(L("Play Windows games on your Mac."))
.font(.title3).foregroundStyle(.secondary)
Button {
state.getStarted()
} label: {
Text(state.busy ? L("Setting up…") : L("Get started")).frame(minWidth: 190)
}
.buttonStyle(.borderedProminent).controlSize(.large).tint(HB.amber)
.disabled(state.busy)
.padding(.top, 6)
Text(state.setupInstallsRosetta
? L("Nothing to choose. Highball installs Rosetta for you, then the download takes a few minutes.")
: L("Nothing to choose. The download takes a few minutes on most connections."))
.font(.callout).foregroundStyle(.secondary).multilineTextAlignment(.center).frame(maxWidth: 440)
Spacer().frame(height: 30)
Text(L("Highball downloads a Wine engine from public upstream releases. Nothing is hosted by us."))
.font(.caption).foregroundStyle(.tertiary)
Text(L("Wine LGPL · DXMT MIT · DXVK Zlib · engine builds by Gcenx and Sikarugir"))
.font(.caption2).foregroundStyle(.tertiary)
}
.padding(40)
}
}
}
struct GPTKLicenseSheet: View {
@Environment(AppState.self) private var state
@Environment(\.dismiss) private var dismiss
var body: some View {
VStack(alignment: .leading, spacing: 10) {
Text("Apple Game Porting Toolkit — Software License Agreement").font(.headline)
ScrollView {
Text(state.gptkLicenseText)
.font(.system(size: 11))
.frame(maxWidth: .infinity, alignment: .leading)
.textSelection(.enabled)
}
.frame(width: 640, height: 380)
.background(.quaternary.opacity(0.4))
HStack {
Text(L("Non-commercial use only · no modification · Apple hardware only"))
.font(.caption).foregroundStyle(.secondary)
Spacer()
Button(L("Close")) { dismiss() }
if let engine = state.licenseEngine ?? state.defaultEngine ?? state.engines.first, engine.rendererDir("d3dmetal") == nil {
Button(L("Accept & enable D3DMetal")) {
state.acceptGPTK(engine: engine)
dismiss()
}.buttonStyle(.borderedProminent)
}
}
}
.padding(16)
}
}
struct EpicSignInSheet: View {
@Environment(AppState.self) private var state
@Environment(\.dismiss) private var dismiss
@State private var code = ""
var body: some View {
VStack(alignment: .leading, spacing: 14) {
Text(L("Connect your Epic account")).font(.title2.bold())
Text(L("1. Open Epic's sign-in page and log in.\n2. The page ends by showing an authorizationCode.\n3. Paste that code here."))
.font(.callout).foregroundStyle(.secondary)
Button(L("Open Epic sign-in page")) { NSWorkspace.shared.open(EpicStore.loginURL) }
TextField(L("authorizationCode"), text: $code).textFieldStyle(.roundedBorder).frame(width: 340)
Text(L("Your password never touches Highball. The code is single use and connects through Legendary, the open source Epic client the Heroic launcher uses."))
.font(.caption).foregroundStyle(.secondary).frame(maxWidth: 360, alignment: .leading)
HStack {
Spacer()
Button(L("Cancel")) { dismiss() }
Button(L("Connect")) {
dismiss()
state.epicSignIn(code: code.trimmingCharacters(in: .whitespacesAndNewlines))
}
.keyboardShortcut(.defaultAction)
.disabled(code.trimmingCharacters(in: .whitespaces).count < 8)
}
}
.padding(24)
}
}
/// GOG sign-in, written for someone who has never copied a link: GOG's own page in the browser,
/// which ends on an almost empty embed.gog.com page whose link carries a one-time code. Each step
/// says what to click and what the player will see. Pasting the link connects at once; the sheet
/// stays open while it does, and says what went wrong in place, so a bad paste or an expired
/// link is fixed without hunting for the button again.
struct GOGSignInSheet: View {
@Environment(AppState.self) private var state
@Environment(\.dismiss) private var dismiss
@State private var pasted = ""
@State private var connecting = false
@State private var problem: String?
var body: some View {
let reading = GOGStore.readSignIn(pasted)
VStack(alignment: .leading, spacing: 16) {
VStack(alignment: .leading, spacing: 4) {
Text(state.gogSignedIn ? L("Your GOG account") : L("Connect your GOG account")).font(.title2.bold())
Text(state.gogSignedIn
? L("To use a different GOG account, follow the steps again and sign in with it. You sign in on GOG's own website, so Highball never sees your password.")
: L("It takes about a minute. You sign in on GOG's own website, so Highball never sees your password."))
.font(.callout).foregroundStyle(.secondary).fixedSize(horizontal: false, vertical: true)
}
if state.gogSignedIn {
Label(state.gogAccountName.map { String(format: L("Connected as %@"), $0) } ?? L("GOG account connected"),
systemImage: "checkmark.circle.fill").foregroundStyle(HB.good)
}
step(1, L("Sign in to GOG in your browser.")) {
Button(L("Open GOG sign-in")) { NSWorkspace.shared.open(GOGStore.loginURL) }
}
step(2, L("After you sign in, GOG shows an almost empty page. That is normal: it means it worked."))
step(3, L("Copy that page's link: click the address bar at the top of your browser, then press ⌘C."))
step(4, L("Come back here and paste it.")) {
HStack(spacing: 8) {
PasteButton(payloadType: String.self) { strings in
Task { @MainActor in
pasted = strings.first ?? ""
if GOGStore.authorizationCode(from: pasted) != nil { connect() }
}
}
TextField(L("or paste the link here"), text: $pasted).textFieldStyle(.roundedBorder).frame(width: 240)
.onSubmit { if case .code = reading { connect() } }
}
.disabled(connecting)
}
Group {
if connecting {
HStack(spacing: 8) {
ProgressView().controlSize(.small)
Text(L("Connecting to GOG…"))
}
} else if let problem {
Label(problem, systemImage: "exclamationmark.triangle.fill").foregroundStyle(HB.amber)
} else if let hint = Self.hint(for: reading) {
Label(hint.text, systemImage: hint.ok ? "checkmark.circle.fill" : "exclamationmark.triangle.fill")
.foregroundStyle(hint.ok ? HB.good : HB.amber)
}
}
.font(.callout).frame(maxWidth: 420, alignment: .leading).fixedSize(horizontal: false, vertical: true)
Text(L("Highball connects through gogdl, the open source tool the Heroic launcher uses. You can disconnect at any time."))
.font(.caption).foregroundStyle(.secondary).frame(maxWidth: 420, alignment: .leading)
.fixedSize(horizontal: false, vertical: true)
HStack {
if state.gogSignedIn {
Button(L("Disconnect GOG"), role: .destructive) { dismiss(); state.gogSignOut() }
}
Spacer()
Button(L("Cancel")) { dismiss() }.keyboardShortcut(.cancelAction)
Button(L("Connect")) { connect() }
.keyboardShortcut(.defaultAction)
.disabled(connecting || GOGStore.authorizationCode(from: pasted) == nil)
}
}
.padding(24)
.frame(width: 480)
// A new paste replaces the last problem; the field emptied after a failure keeps it shown.
.onChange(of: pasted) { _, new in if !new.isEmpty { problem = nil } }
}
/// One numbered instruction, with the control it needs (if any) under its text.
private func step(_ number: Int, _ text: String, @ViewBuilder control: () -> some View = { EmptyView() }) -> some View {
HStack(alignment: .firstTextBaseline, spacing: 10) {
Text("\(number)").font(.callout.weight(.semibold).monospacedDigit())
.frame(width: 20, height: 20).background(Circle().fill(.quaternary))
VStack(alignment: .leading, spacing: 8) {
Text(text).fixedSize(horizontal: false, vertical: true)
control()
}
}
}
private func connect() {
guard !connecting, let code = GOGStore.authorizationCode(from: pasted) else { return }
connecting = true
problem = nil
Task {
do {
try await state.gogConnect(code: code)
dismiss()
} catch {
connecting = false
problem = L(AppState.message(for: error)) // the kit's sign-in messages have French entries
pasted = ""
}
}
}
/// What the sheet says about the pasted text; nothing while it is empty.
static func hint(for reading: GOGStore.PastedSignIn) -> (text: String, ok: Bool)? {
switch reading {
case .empty: nil
case .code: (L("That is the right link. Click Connect."), true)
case .signInPage: (L("That is the link of the sign-in page. Sign in on that page first, then copy the link of the almost empty page you land on."), false)
case .noCode: (L("That is a GOG page, but not the right one. Copy the link of the almost empty page GOG shows right after you sign in."), false)
case .notGOG: (L("That does not look like a link from GOG. Copy the link of the almost empty page GOG shows after you sign in."), false)
}
}
}
/// Per-program settings: launch arguments, environment, renderer override in one place.
struct PinSettingsSheet: View {
@Environment(AppState.self) private var state
@Environment(\.dismiss) private var dismiss
let bottle: Bottle
@State private var pin: Pin
@State private var argsText: String
@State private var envText: String
init(pin: Pin, bottle: Bottle) {
self.bottle = bottle
_pin = State(initialValue: pin)
_argsText = State(initialValue: ArgumentLine.join(pin.arguments))
_envText = State(initialValue: pin.environment.sorted { $0.key < $1.key }
.map { "\($0.key)=\($0.value)" }.joined(separator: "\n"))
}
var body: some View {
VStack(alignment: .leading, spacing: 14) {
Text(pin.name).font(.title2.bold())
Text(pin.path).font(.caption.monospaced()).foregroundStyle(.secondary)
.lineLimit(1).truncationMode(.middle)
VStack(alignment: .leading, spacing: 6) {
Text(L("Launch arguments")).font(.callout.weight(.medium))
TextField(L("-dx11 -skiplauncher \"an argument with spaces\""), text: $argsText)
.textFieldStyle(.roundedBorder).font(.body.monospaced())
Text(L("Passed to the program on every launch. Quote arguments that contain spaces."))
.font(.caption).foregroundStyle(.secondary)
}
VStack(alignment: .leading, spacing: 6) {
Text(L("Environment")).font(.callout.weight(.medium))
TextEditor(text: $envText)
.font(.body.monospaced()).frame(height: 64)
.overlay(RoundedRectangle(cornerRadius: 6).stroke(.quaternary))
Text(L("One KEY=VALUE per line, applied only to this program."))
.font(.caption).foregroundStyle(.secondary)
let lookalikes = EnvText.dllOverrideLookalikes(in: EnvText.parse(envText).environment)
if !lookalikes.isEmpty {
Text(DllOverrideHint.text(for: lookalikes)).font(.caption).foregroundStyle(HB.amber)
.fixedSize(horizontal: false, vertical: true)
}
}
Picker(L("Renderer"), selection: $pin.renderer) {
Text(L("Environment default")).tag(Renderer?.none)
ForEach(Renderer.allCases, id: \.self) { r in
Text(r.rawValue.uppercased()).tag(Renderer?.some(r))
}
}
.pickerStyle(.menu)
// The registry is the state for this one, so it applies as soon as it is toggled,
// not on Save: the same value a database fix writes.
VStack(alignment: .leading, spacing: 4) {
Toggle(L("Emulate display mode changes"), isOn: Binding(
get: { state.displayModeEmulation(in: bottle, executable: pin.executableURL(driveC: bottle.driveC)) },
set: { state.setDisplayModeEmulation($0, in: bottle, executable: pin.executableURL(driveC: bottle.driveC)) }))
.toggleStyle(.checkbox)
Text(L("For a game that opens small, off-centre, or refuses its fullscreen mode. The Mac cannot switch its display for it, so Wine pretends and scales the picture instead. A fix from the database may have set this already."))
.font(.caption).foregroundStyle(.secondary).fixedSize(horizontal: false, vertical: true)
}
HStack {
Spacer()
Button(L("Cancel")) { dismiss() }
Button(L("Save")) {
pin.arguments = ArgumentLine.split(argsText)
pin.environment = EnvText.parse(envText).environment
state.updatePin(pin, in: bottle)
dismiss()
}
.keyboardShortcut(.defaultAction)
}
}
.padding(24)
.frame(width: 460)
}
}
/// Bottle environment editor: one KEY=VALUE per line, saved on every keystroke batch.
struct EnvEditor: View {
@Environment(AppState.self) private var state
let bottle: Bottle
@State private var text: String = ""
@State private var ignored: [String] = []
@State private var lookalikes: [(key: String, value: String)] = []
@State private var loaded = false
var body: some View {
VStack(alignment: .leading, spacing: 4) {
TextEditor(text: $text)
.font(.body.monospaced())
.frame(height: 72)
.overlay(RoundedRectangle(cornerRadius: 6).stroke(.quaternary))
if !ignored.isEmpty {
Text(L("Ignored, not KEY=VALUE: ") + ignored.joined(separator: ", ")).font(.caption).foregroundStyle(HB.amber)
}
// A DLL override typed here as a variable never reaches Wine (highball#202, #203).
if !lookalikes.isEmpty {
Text(DllOverrideHint.text(for: lookalikes)).font(.caption).foregroundStyle(HB.amber)
.fixedSize(horizontal: false, vertical: true)
Button(L("Move to DLL overrides")) {
var copy = state.bottles.first { $0.name == bottle.name } ?? bottle
copy.settings.adoptDllOverrideLookalikes()
state.update(copy)
text = EnvText.text(for: copy.settings.environment)
}
.controlSize(.small)
}
}
.onAppear {
guard !loaded else { return }
loaded = true
let live = (state.bottles.first { $0.name == bottle.name } ?? bottle).settings.environment
text = EnvText.text(for: live)
lookalikes = EnvText.dllOverrideLookalikes(in: live)
}
.onChange(of: text) { _, newValue in
let parsed = EnvText.parse(newValue)
ignored = parsed.ignored
lookalikes = EnvText.dllOverrideLookalikes(in: parsed.environment)
var copy = state.bottles.first { $0.name == bottle.name } ?? bottle
guard copy.settings.environment != parsed.environment else { return }
copy.settings.environment = parsed.environment
state.update(copy)
}
}
}
/// The one sentence both variable editors show under a DLL override typed as a variable.
enum DllOverrideHint {
static func text(for entries: [(key: String, value: String)]) -> String {
let names = entries.map { "\($0.key)=\($0.value)" }.joined(separator: ", ")
return names + " " + (entries.count == 1
? L("looks like a DLL override. Wine reads those only from the DLL overrides field, so as a variable it does nothing.")
: L("look like DLL overrides. Wine reads those only from the DLL overrides field, so as variables they do nothing."))
}
}
/// A small ⓘ (or ⚠) that explains one setting. Click opens a popover; hovering still shows
/// the same text as a tooltip, so it works either way.
private struct InfoButton: View {
let text: String
var warning = false
@State private var showing = false
var body: some View {
Button { showing.toggle() } label: {
Image(systemName: warning ? "exclamationmark.triangle.fill" : "info.circle")
.foregroundStyle(warning ? Color.orange : Color.secondary)
.contentShape(Rectangle())
}
.buttonStyle(.plain)
.help(text)
.accessibilityLabel(warning ? L("Warning") : L("What this setting does"))
.popover(isPresented: $showing, arrowEdge: .bottom) {
Text(text)
.font(.callout)
.fixedSize(horizontal: false, vertical: true)
.frame(width: 320, alignment: .leading)
.padding(14)
}
}
}