From 1502fa9ab1f470877b466a4bb56dc32524696644 Mon Sep 17 00:00:00 2001 From: Xiao YaoBing Date: Tue, 18 Jul 2023 08:44:09 +0000 Subject: [PATCH] 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(); } }` --- src/utils/udev.cpp | 15 +++++++++++++++ src/utils/udev.h | 1 + 2 files changed, 16 insertions(+) diff --git a/src/utils/udev.cpp b/src/utils/udev.cpp index fe00cef029..ae032d83dc 100644 --- a/src/utils/udev.cpp +++ b/src/utils/udev.cpp @@ -126,6 +126,15 @@ std::vector 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")) { diff --git a/src/utils/udev.h b/src/utils/udev.h index 83586763dd..bb3c7bb9ff 100644 --- a/src/utils/udev.h +++ b/src/utils/udev.h @@ -38,6 +38,7 @@ public: QMap properties() const; bool isBootVga() const; QString seat() const; + bool isHotpluggable() const; operator udev_device *() const {