I need to access data about GPU and screen resolution in C, not using system_profiler, because it takes too long(.3s-.5s system_profiler SPDisplaysDataType), and needs greping and cutting, which is not that fast either.

Caching would be answer, but very short-sighted as someone can use different monitors etc.

Unfortunately system_profiler is closed source.

EDIT: I used CGDisplayPixelsWide and CGDisplayPixelsHigh to get resolution. During compilation i had to compile with -framework Cocoa -framework IOKit. Only minus that it gets system resolution rather than screen resolution. So function looks like this.

static char *get_resolution()
{
        int screen_width = CGDisplayPixelsWide(CGMainDisplayID());
        int screen_height = CGDisplayPixelsHigh(CGMainDisplayID());
        ...
}
有帮助吗?

解决方案

displayplacer allows to read and write display settings and is open source. I'm not sure about GPU details though.

The API used seems to be defined in IOKit/graphics/IOGraphicsLib.h.

其他提示

I'm not certain of specific APIs, but looking at the source code of an open source application that works with display resolutions or GPUs may be beneficial. Two examples I can think of are RDM and gSwitch (RDM hasn't been updated for a while but there are up-to-date forks available).

许可以下: CC-BY-SA归因
不隶属于 apple.stackexchange
scroll top