Skip to content

Commit 51108ea

Browse files
committed
system: Redo ProMotion check logic to use ioreg
This should also work in recoveryOS. Also handle clamshell mode properly. Signed-off-by: Hector Martin <[email protected]>
1 parent abc3eb7 commit 51108ea

2 files changed

Lines changed: 41 additions & 16 deletions

File tree

src/main.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,12 @@ def main(self):
848848
split_ver(self.sysinfo.sfr_ver) >= split_ver(BUGGY_SFR_MIN)):
849849

850850
hz = self.sysinfo.get_refresh_rate()
851+
if hz is None:
852+
p_error("Could not check ProMotion display status")
853+
print("This probably means your laptop lid is closed. Please open it and try again.")
854+
print("(You're going to have to use the power button soon anyway!)")
855+
print()
856+
sys.exit(1)
851857

852858
if split_ver(self.sysinfo.sros_ver) < split_ver(BUGGY_SFR_MIN):
853859
p_error("Mismatched System Firmware / System Recovery detected!")
@@ -862,10 +868,10 @@ def main(self):
862868
p_plain( f" {col(BLUE, BRIGHT)}https://github.com/AsahiLinux/docs/wiki/macOS-Sonoma-Boot-Failures{col()}")
863869
print()
864870

865-
p_info(f" Current refresh rate: {col()}{hz}")
871+
p_info(f" Current refresh rate: {col()}{hz} Hz")
866872
print()
867873

868-
if hz != "120.00Hz":
874+
if hz != 120.0:
869875
p_error(f"{col(BLINK)}CRITICAL ERROR: {col(NBLINK)}Your display refresh rate is set to")
870876
p_error("something other than 120Hz / ProMotion mode.")
871877
print()
@@ -896,9 +902,9 @@ def main(self):
896902
p_warning( "buggy and will NOT correctly boot older versions of macOS, nor Asahi Linux,")
897903
p_warning( "if the display is configured for a refresh rate other than ProMotion (120Hz).")
898904
print()
899-
p_info(f" Current refresh rate: {col()}{hz}")
905+
p_info(f" Current refresh rate: {col()}{hz} Hz")
900906
print()
901-
if hz != "120.00Hz":
907+
if hz != 120.0:
902908
p_error("Your display is not set to ProMotion mode (120 Hz). Please change your")
903909
p_error("display refresh rate to ProMotion mode in System Settings and try again.")
904910
print()

src/system.py

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ def fetch(self):
1313

1414
self.ioreg = plistlib.loads(result.stdout)
1515

16+
result = subprocess.run(["ioreg", "-alp", "IOService"],
17+
stdout=subprocess.PIPE, check=True)
18+
self.ioservice = plistlib.loads(result.stdout)
19+
1620
for dt in self.ioreg["IORegistryEntryChildren"]:
1721
if dt.get("IOObjectClass", None) == "IOPlatformExpertDevice":
1822
break
@@ -172,18 +176,33 @@ def get_int(self, val):
172176
return struct.unpack("<I", val)[0]
173177

174178
def get_refresh_rate(self):
175-
j = subprocess.run(["system_profiler", "SPDisplaysDataType", "-json"],
176-
stdout=subprocess.PIPE, check=True).stdout
179+
machine = self.ioservice["IORegistryEntryChildren"][0]
180+
for i in machine["IORegistryEntryChildren"]:
181+
if i["IORegistryEntryName"] == "AppleARMPE":
182+
armpe = i
183+
break
184+
else:
185+
return None
186+
for i in armpe["IORegistryEntryChildren"]:
187+
if i["IORegistryEntryName"] == "arm-io":
188+
armio = i
189+
break
190+
else:
191+
return None
192+
for i in armio["IORegistryEntryChildren"][0]["IORegistryEntryChildren"]:
193+
if i["IORegistryEntryName"] == "disp0":
194+
disp0 = i
195+
break
196+
else:
197+
return None
177198

178-
main_display = None
179-
for a in json.loads(j)["SPDisplaysDataType"]:
180-
for disp in a.get("spdisplays_ndrvs", []):
181-
if disp["_name"] != "Color LCD":
182-
continue
183-
assert main_display is None
184-
main_display = disp
199+
props = disp0["IORegistryEntryChildren"][0]
200+
201+
if "TimingElements" not in props:
202+
return None
185203

186-
if main_display is None:
187-
return "(Unknown or off)"
204+
te = {i["ID"]:i for i in props["TimingElements"]}
205+
te_id = props["DPTimingModeId"]
206+
refresh = te[te_id]["VerticalAttributes"]["SyncRate"] / 65536.0
188207

189-
return main_display["_spdisplays_resolution"].split()[-1]
208+
return refresh

0 commit comments

Comments
 (0)