Skip to content

Commit

Permalink
Display (Linux): don't report disabled displays when using DRM
Browse files Browse the repository at this point in the history
Ref: #634
  • Loading branch information
CarterLi committed Nov 28, 2023
1 parent 5db3c90 commit 0c522bd
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/detection/displayserver/linux/displayserver_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ static void parseDRM(FFDisplayServerResult* result)
{
const char* drmDirPath = "/sys/class/drm/";

DIR* dirp = opendir(drmDirPath);
FF_AUTO_CLOSE_DIR DIR* dirp = opendir(drmDirPath);
if(dirp == NULL)
return;

Expand All @@ -25,18 +25,30 @@ static void parseDRM(FFDisplayServerResult* result)
continue;

ffStrbufAppendS(&drmDir, entry->d_name);
uint32_t drmDirWithDnameLength = drmDir.length;

ffStrbufAppendS(&drmDir, "/enabled");
char enabled = 'd'; // disabled
ffReadFileData(drmDir.chars, sizeof(enabled), &enabled);
if (enabled != 'e') // enabled
{
ffStrbufSubstrBefore(&drmDir, drmDirLength);
continue;
}

ffStrbufSubstrBefore(&drmDir, drmDirWithDnameLength);
ffStrbufAppendS(&drmDir, "/modes");

FILE* modeFile = fopen(drmDir.chars, "r");
if(modeFile == NULL)
char modes[32];
if (ffReadFileData(drmDir.chars, sizeof(modes), modes) < 3)
{
ffStrbufSubstrBefore(&drmDir, drmDirLength);
continue;
}

uint32_t width = 0, height = 0;

int scanned = fscanf(modeFile, "%ux%u", &width, &height);
int scanned = sscanf(modes, "%ux%u", &width, &height);
if(scanned == 2 && width > 0 && height > 0)
{
ffStrbufSubstrBefore(&drmDir, drmDirLength);
Expand Down Expand Up @@ -71,11 +83,8 @@ static void parseDRM(FFDisplayServerResult* result)
);
}

fclose(modeFile);
ffStrbufSubstrBefore(&drmDir, drmDirLength);
}

closedir(dirp);
}

void ffConnectDisplayServerImpl(FFDisplayServerResult* ds)
Expand Down

0 comments on commit 0c522bd

Please sign in to comment.