Add workaround for broken Qt EGLFS card selection logic

This commit is contained in:
Cameron Gutman
2024-04-06 14:35:34 -05:00
parent f8c5d3c0ce
commit 011feab6ce
3 changed files with 67 additions and 1 deletions

View File

@@ -1,4 +1,5 @@
#include <QtGlobal>
#include <QDir>
#include "utils.h"
@@ -12,6 +13,11 @@
#include <wayland-client.h>
#endif
#ifdef HAVE_DRM
#include <xf86drm.h>
#include <xf86drmMode.h>
#endif
#define VALUE_SET 0x01
#define VALUE_TRUE 0x02
@@ -96,3 +102,43 @@ bool WMUtils::isRunningDesktopEnvironment()
return isRunningWindowManager();
#endif
}
QString WMUtils::getDrmCardOverride()
{
#ifdef HAVE_DRM
QDir dir("/dev/dri");
QStringList cardList = dir.entryList(QStringList("card*"), QDir::Files | QDir::System);
if (cardList.length() == 0) {
return QString();
}
bool needsOverride = false;
for (const QString& card : cardList) {
QFile cardFd(dir.filePath(card));
if (!cardFd.open(QFile::ReadOnly)) {
continue;
}
auto resources = drmModeGetResources(cardFd.handle());
if (resources == nullptr) {
// If we find a card that doesn't have a display before a card that
// has one, we'll need to override Qt's EGLFS config because they
// don't properly handle cards without displays.
needsOverride = true;
}
else {
// We found a card with a display
drmModeFreeResources(resources);
if (needsOverride) {
// Override the default card with this one
return dir.filePath(card);
}
else {
return QString();
}
}
}
#endif
return QString();
}