문제

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