Skip to content

Run Windows games on Apple Silicon — free, open source, with an open compatibility database that tells you what actually works.

Emulate display mode changes covers modes the Mac does not list: turning it on for a game also turns it on for explorer.exe, which builds the environment's mode list when it starts, so Wine's virtual modes are in the list the game validates against. Dark Omen on the M4 (640x480x16, r21): the game's value alone, the change returned -2; with explorer.exe's too, it went through and the window opened scaled. The value is removed with the last program, and the environment's idle background processes are stopped so the next start rebuilds the list (highball#128, #244, #103, #120)

Gauthier Piarrettee385afb0d8e5
diff --git a/Sources/HighballApp/AppState.swift b/Sources/HighballApp/AppState.swift
index c0c4b06..9b9d56e 100644
--- a/Sources/HighballApp/AppState.swift
+++ b/Sources/HighballApp/AppState.swift
@@ -1624,7 +1624,14 @@ final class AppState {
let runner = WineRunner(paths: paths, engine: engine, bottle: bottle)
do {
try await DisplayModeEmulation.set(on, in: runner, executable: exe)
- appendLog("\(exe.lastPathComponent): emulated display mode changes \(on ? "on" : "off") in \(bottle.name); the next launch uses it.")
+ // Wine builds the list of display modes when the environment starts, so the
+ // emulated ones appear only after a restart. Nothing is stopped under a game.
+ if !sessionRuns(in: bottle) {
+ Task.detached { try? runner.kill() }
+ appendLog("\(exe.lastPathComponent): emulated display mode changes \(on ? "on" : "off") in \(bottle.name); stopped the environment's background processes so its next start lists the modes.")
+ } else {
+ appendLog("\(exe.lastPathComponent): emulated display mode changes \(on ? "on" : "off") in \(bottle.name); applies once the game running there has quit and the environment restarts.")
+ }
} catch {
displayModeWritten[key] = nil
fail(error, bottle: bottle)
diff --git a/Sources/HighballKit/DisplayModeEmulation.swift b/Sources/HighballKit/DisplayModeEmulation.swift
index aeec108..1eaa79f 100644
--- a/Sources/HighballKit/DisplayModeEmulation.swift
+++ b/Sources/HighballKit/DisplayModeEmulation.swift
@@ -50,14 +50,53 @@ public enum DisplayModeEmulation {
return raw.lowercased() == "\"y\""
}
- /// Turns it on or off for `exe` through the bottle's Wine. Programs read the registry when
- /// they start, so a running Steam client needs no restart for the next launch to see it.
+ /// The program that builds the environment's list of display modes when it starts. Wine adds
+ /// its virtual modes (640x480 and the other sizes a game may ask for) to that shared list only
+ /// when the process building it emulates mode changes itself; a game with the setting alone
+ /// validates its request against the Mac's real modes and gets "bad mode" for any the display
+ /// does not list. Measured on an M4 with Warhammer: Dark Omen (640x480x16, engine r21,
+ /// 2026-10-06): the game's own value alone, NtUserChangeDisplaySettings returned -2; with
+ /// explorer.exe's too, the change went through and the window opened scaled to the screen.
+ /// Prince of Persia: The Two Thrones (highball#128), Project IGI (#244) and Dead Rising 3 (#103)
+ /// failed at the same refused change.
+ public static let listBuilder = "explorer.exe"
+
+ /// Whether any program other than `except` has it on, read from the registry text: the list
+ /// builder's value stays while one does.
+ public static func othersOn(userReg: String, except executableName: String) -> Bool {
+ var current: String?
+ for line in userReg.split(separator: "\n", omittingEmptySubsequences: false) {
+ if line.hasPrefix("[") {
+ // Keys are case-insensitive; reg.exe keeps whatever case it was given.
+ let key = line.dropFirst().prefix { $0 != "]" }.replacingOccurrences(of: "\\\\", with: "\\").lowercased()
+ let prefix = "software\\wine\\appdefaults\\", suffix = "\\x11 driver"
+ if key.hasPrefix(prefix), key.hasSuffix(suffix) {
+ current = String(key.dropFirst(prefix.count).dropLast(suffix.count))
+ } else { current = nil }
+ } else if let program = current, program.lowercased() != executableName.lowercased(),
+ program.lowercased() != listBuilder, line.lowercased().hasPrefix("\"\(valueName.lowercased())\"=\"y\"") {
+ return true
+ }
+ }
+ return false
+ }
+
+ /// Turns it on or off for `exe` through the bottle's Wine, and keeps the list builder's value
+ /// in step: on with the first program, off with the last. Programs read the registry when they
+ /// start, and the list is rebuilt when the environment starts, so a change applies from the
+ /// environment's next start.
public static func set(_ on: Bool, in runner: WineRunner, executable exe: URL) async throws {
let key = key(forExecutable: exe)
+ let builder = Self.key(forExecutable: URL(fileURLWithPath: listBuilder))
if on {
try await runner.regAdd(key: key, name: valueName, type: "REG_SZ", data: "y")
+ try await runner.regAdd(key: builder, name: valueName, type: "REG_SZ", data: "y")
} else {
try await runner.regDelete(key: key, name: valueName)
+ let reg = (try? String(contentsOf: runner.bottle.url.appending(path: "user.reg"), encoding: .utf8)) ?? ""
+ if !othersOn(userReg: reg, except: exe.lastPathComponent) {
+ try? await runner.regDelete(key: builder, name: valueName)
+ }
}
}
}
diff --git a/Tests/HighballKitTests/DisplayModeEmulationTests.swift b/Tests/HighballKitTests/DisplayModeEmulationTests.swift
index 841d048..aec6a94 100644
--- a/Tests/HighballKitTests/DisplayModeEmulationTests.swift
+++ b/Tests/HighballKitTests/DisplayModeEmulationTests.swift
@@ -74,4 +74,34 @@ final class UnswitchedDisplayModeTests: XCTestCase {
"""
XCTAssertFalse(DisplayModeEmulation.looksUnswitched(inLog: ordinary))
}
+
+ // The list builder (explorer.exe) keeps the value while any other program has it on, so
+ // turning one game off does not take the low-resolution modes away from another.
+ func testTheListBuilderStaysOnWhileAnotherProgramHasIt() {
+ let reg = """
+ [Software\\Wine\\AppDefaults\\DarkOmen.exe\\X11 Driver] 1759750000
+ "EmulateModeset"="y"
+
+ [Software\\Wine\\AppDefaults\\explorer.exe\\X11 Driver] 1759750000
+ "EmulateModeset"="y"
+
+ [Software\\Wine\\AppDefaults\\FNAF.exe\\X11 Driver] 1759750000
+ "EmulateModeset"="y"
+ """
+ XCTAssertTrue(DisplayModeEmulation.othersOn(userReg: reg, except: "DarkOmen.exe"), "FNAF still has it")
+ XCTAssertTrue(DisplayModeEmulation.othersOn(userReg: reg, except: "fnaf.exe"), "Dark Omen still has it, names in any case")
+ let alone = """
+ [software\\wine\\appdefaults\\POP3.EXE\\X11 Driver] 1759750000
+ "EmulateModeset"="y"
+
+ [Software\\Wine\\AppDefaults\\explorer.exe\\X11 Driver] 1759750000
+ "EmulateModeset"="y"
+
+ [Software\\Wine\\AppDefaults\\Other.exe\\Direct3D] 1759750000
+ "EmulateModeset"="y"
+ """
+ XCTAssertFalse(DisplayModeEmulation.othersOn(userReg: alone, except: "POP3.EXE"),
+ "the builder itself and a value under another driver key do not count")
+ XCTAssertTrue(DisplayModeEmulation.othersOn(userReg: alone, except: "Unrelated.exe"), "a key written in lower case still counts")
+ }
}