How to resolve CGDirectDisplayID changing issues on newer multi-GPU Apple laptops in Core Foundation/IO Kit?

后端 未结 3 1373
再見小時候
再見小時候 2021-02-04 10:14

In Mac OS X, every display gets a unique CGDirectDisplayID number assigned to it. You can use CGGetActiveDisplayList() or [NSScreen screens]

3条回答
  •  灰色年华
    2021-02-04 10:52

    While I'm no pro, I believe the answer is to allow Apple to notify you when the user changes displays. The info inf the callback contains flags for adding and removing CGDirectDisplayIDs.

    The user shouldn't be adding or removing graphics cards during operation, so I would play with making list at startup, and whenever you get the "remove" flag set the next "add" operation to replace that ID in the list.

    I'd try just printing the information you get back each time CGDisplayRegisterReconfigurationCallback calls your function. See if you get one with a DeviceUID with a 'remove' flag, and then a subsequent call another with an 'add' flag. Checking those id's against CGGetActiveDisplayList would also aid in understanding what's going on.

    That's my best bet, hope it helps!

提交回复
热议问题