Question

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());
        ...
}
Was it helpful?

Solution

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.

OTHER TIPS

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).

Licensed under: CC-BY-SA with attribution
Not affiliated with apple.stackexchange
scroll top