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 {