Skip to content

fix: improve display disable/enable reliability on macOS 12.x#3

Open
RollingVeck wants to merge 3 commits into
Attiv:mainfrom
RollingVeck:main
Open

fix: improve display disable/enable reliability on macOS 12.x#3
RollingVeck wants to merge 3 commits into
Attiv:mainfrom
RollingVeck:main

Conversation

@RollingVeck

@RollingVeck RollingVeck commented Jul 3, 2026

Copy link
Copy Markdown

概述

修复了 macOS 12.x 以上版本中 ClamOpen 禁用/启用内置屏的可靠性问题。原始实现在 WindowServer 崩溃、竞态条件和显示恢复方面存在不稳定。

改动内容

  • 两阶段镜像后禁用:先镜像到外接屏再禁用内置屏,使用 forceConfiguration 确保 WindowServer 完整迁移窗口,防止崩溃
  • 重试机制 + forceConfiguration:disableBuiltin() 和 enableBuiltin() 均加入 3-5 次重试循环,适配不同 macOS 版本和硬件
  • 扩展私有 API 支持:CGSGetDisplayList(查找被禁用的显示器)、CGDisplayRestoreDisplayConfiguration(兜底恢复)
  • ClamOpen ↔ ClamRestore 协作:通过分布式通知协调,ClamRestore 先尝试通知 ClamOpen 恢复,失败后再自行恢复
  • build_app.sh 绕过 SPM:改用 swiftc 直接编译,解决 CommandLineTools 损坏导致 SPM 不可用的问题
  • enableLock 防竞态:防止快速启用/禁用切换时的状态错乱

涉及文件

  • Sources/ClamOpen/AppDelegate.swift
  • Sources/ClamOpen/DisplayController.swift
  • Sources/ClamRestore/main.swift
  • build_app.sh

- Two-phase mirror-then-disable approach prevents WindowServer crashes
- Retry logic with forceConfiguration for both disable and enable
- CGSGetDisplayList / CGDisplayRestoreDisplayConfiguration for recovery
- Coordinate ClamOpen and ClamRestore via distributed notifications
- Work around broken SPM by using swiftc directly in build_app.sh
- enableLock prevents race conditions during state transitions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant