Attention! Translated article might be found on my English blog.

2015年1月23日金曜日

NSApplicationDidChangeScreenParametersNotificationで外部ディスプレイの追加/削除を検知する

探し方が悪かったせいか古い記事になりますが、Notification when displays are detected? | Cocoabuilderによると、NSApplicationDidChangeScreenParametersNotificationを監視すれば良いようです。
その際、NSNotificationCenterは[[NSWorkspace sharedWorkspace] notificationCenter]ではなく、[NSNotificationCenter defaultCenter]を使う必要があるようです。

実際にNSApplicationDidChangeScreenParametersNotificationを監視し、通知ハンドラで[NSScreen screens]をチェックしたところ、意図通り外部ディスプレイを接続/切断した時はスクリーン数が増加/現象していることを確認できました。