mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2025-02-20 11:43:27 +08:00
Brightness (macOS): code refactor
This commit is contained in:
parent
7598e57704
commit
3acbe84570
@ -1,6 +1,7 @@
|
||||
#include "brightness.h"
|
||||
#include "detection/displayserver/displayserver.h"
|
||||
#include "util/apple/cf_helpers.h"
|
||||
#include "util/edidHelper.h"
|
||||
|
||||
#include <CoreGraphics/CoreGraphics.h>
|
||||
|
||||
@ -34,26 +35,6 @@ static const char* detectWithDisplayServices(const FFDisplayServerResult* displa
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void getNameFromEdid(uint8_t edid[128], FFstrbuf* name)
|
||||
{
|
||||
// https://github.com/jinksong/read_edid/blob/master/parse-edid/parse-edid.c
|
||||
for (uint32_t i = 0x36; i < 0x7E; i += 0x12)
|
||||
{ // read through descriptor blocks...
|
||||
if (edid[i] == 0x00)
|
||||
{ // not a timing descriptor
|
||||
if (edid[i+3] == 0xfc)
|
||||
{ // Model Name tag
|
||||
for (uint32_t j = 0; j < 13; j++)
|
||||
{
|
||||
if (edid[i + 5 + j] == 0x0a)
|
||||
return;
|
||||
ffStrbufAppendC(name, (char) edid[i + 5 + j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// https://github.com/waydabber/m1ddc
|
||||
// Works for Apple Silicon and USB-C adapter connection ( but not HTMI )
|
||||
static const char* detectWithDdcci(FFlist* result)
|
||||
@ -120,7 +101,7 @@ static const char* detectWithDdcci(FFlist* result)
|
||||
|
||||
uint8_t edid[128] = {};
|
||||
if (IOAVServiceReadI2C(service, 0x50, 0x00, edid, sizeof(edid)) == KERN_SUCCESS)
|
||||
getNameFromEdid(edid, &brightness->name);
|
||||
ffEdidGetName(edid, &brightness->name);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,28 @@
|
||||
#include "edidHelper.h"
|
||||
|
||||
void ffEdidGetNativeResolution(uint8_t edid[128], uint32_t* width, uint32_t* height)
|
||||
void ffEdidGetPhycialDisplay(uint8_t edid[128], uint32_t* width, uint32_t* height)
|
||||
{
|
||||
const int dtd = 54;
|
||||
*width = (((uint32_t) edid[dtd + 4] >> 4) << 8) | edid[dtd + 2];
|
||||
*height = (((uint32_t) edid[dtd + 7] >> 4) << 8) | edid[dtd + 5];
|
||||
}
|
||||
|
||||
void ffEdidGetName(uint8_t edid[128], FFstrbuf* name)
|
||||
{
|
||||
// https://github.com/jinksong/read_edid/blob/master/parse-edid/parse-edid.c
|
||||
for (uint32_t i = 0x36; i < 0x7E; i += 0x12)
|
||||
{ // read through descriptor blocks...
|
||||
if (edid[i] == 0x00)
|
||||
{ // not a timing descriptor
|
||||
if (edid[i+3] == 0xfc)
|
||||
{ // Model Name tag
|
||||
for (uint32_t j = 0; j < 13; j++)
|
||||
{
|
||||
if (edid[i + 5 + j] == 0x0a)
|
||||
return;
|
||||
ffStrbufAppendC(name, (char) edid[i + 5 + j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,9 @@
|
||||
#define FF_INCLUDED_EDID_HELPER_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "util/FFstrbuf.h"
|
||||
|
||||
void ffEdidGetNativeResolution(uint8_t edid[128], uint32_t* width, uint32_t* height);
|
||||
void ffEdidGetPhycialDisplay(uint8_t edid[128], uint32_t* width, uint32_t* height);
|
||||
void ffEdidGetName(uint8_t edid[128], FFstrbuf* name);
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user