mirror of
https://github.com/moonlight-stream/moonlight-qt.git
synced 2026-04-20 23:20:10 +00:00
Add workaround for broken Qt EGLFS card selection logic
This commit is contained in:
46
app/wm.cpp
46
app/wm.cpp
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user