prevent the primaryGpu is a usb device in multi-gpu scenes

if usb device is the primaryGpu, the device unplug kwin_wayland exit

`   } else if (device->action() == QStringLiteral("remove")) {
            DrmGpu *gpu = findGpu(device->devNum());
            if (gpu) {
                if (primaryGpu() == gpu) {
                    qCCritical(KWIN_DRM) << "Primary gpu has been removed! Quitting...";
                    QCoreApplication::exit(1);
                    return;
                } else {
                    gpu->setRemoved();
                    updateOutputs();
                }
           }`
This commit is contained in:
Xiao YaoBing 2023-07-18 08:44:09 +00:00 committed by Xaver Hugl
parent 6df5b0297d
commit 1502fa9ab1
2 changed files with 16 additions and 0 deletions

View file

@ -126,6 +126,15 @@ std::vector<UdevDevice::Ptr> Udev::listGPUs()
enumerate.scan();
auto vect = enumerate.find();
std::sort(vect.begin(), vect.end(), [](const UdevDevice::Ptr &device1, const UdevDevice::Ptr &device2) {
// prevent usb devices from becoming the primaryGpu
if (device1->isHotpluggable()) {
return false;
}
if (device2->isHotpluggable()) {
return true;
}
// if set as boot GPU, prefer 1
if (device1->isBootVga()) {
return true;
@ -231,6 +240,12 @@ QString UdevDevice::action() const
return QString::fromLocal8Bit(udev_device_get_action(m_device));
}
bool UdevDevice::isHotpluggable() const
{
QString devPath = QString::fromUtf8(udev_device_get_devpath(m_device));
return devPath.toLower().contains("usb");
}
UdevMonitor::UdevMonitor(Udev *udev)
: m_monitor(udev_monitor_new_from_netlink(*udev, "udev"))
{

View file

@ -38,6 +38,7 @@ public:
QMap<QByteArray, QByteArray> properties() const;
bool isBootVga() const;
QString seat() const;
bool isHotpluggable() const;
operator udev_device *() const
{