From ca1e4a255a3f72d31b0f002d2bcd296ffceb939a Mon Sep 17 00:00:00 2001 From: Aleix Pol Date: Mon, 12 Apr 2021 20:09:10 +0200 Subject: [PATCH] udev: never construct UdevDevices with a null device It allows to trust the device we have as it's referenced. We were already checking for pointer validity when getting them so it still makes sense. --- src/input.cpp | 2 +- src/udev.cpp | 30 ++++++++++-------------------- src/udev.h | 2 +- src/xkb.cpp | 2 ++ 4 files changed, 14 insertions(+), 22 deletions(-) diff --git a/src/input.cpp b/src/input.cpp index ef70d0e981..6d34839032 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -268,7 +268,7 @@ public: if (event->type() == QEvent::KeyPress && !event->isAutoRepeat()) { if (event->nativeVirtualKey() == XKB_KEY_Terminate_Server) { qCWarning(KWIN_CORE) << "Request to terminate server"; - QMetaObject::invokeMethod(qApp, "quit", Qt::QueuedConnection); + QMetaObject::invokeMethod(QCoreApplication::instance(), &QCoreApplication::quit, Qt::QueuedConnection); return true; } } diff --git a/src/udev.cpp b/src/udev.cpp index ec5ea70585..d5d6d406a0 100644 --- a/src/udev.cpp +++ b/src/udev.cpp @@ -10,9 +10,11 @@ #include "main.h" #include "platform.h" #include "session.h" +#include "utils.h" // Qt #include #include +#include // system #include #include @@ -199,7 +201,12 @@ std::vector Udev::listFramebuffers() UdevDevice::Ptr Udev::deviceFromSyspath(const char *syspath) { - return UdevDevice::Ptr(new UdevDevice(udev_device_new_from_syspath(m_udev, syspath))); + auto dev = udev_device_new_from_syspath(m_udev, syspath); + if (!dev) { + qCWarning(KWIN_CORE) << "failed to retrieve device for" << syspath << strerror(errno); + return {}; + } + return UdevDevice::Ptr(new UdevDevice(dev)); } UdevMonitor *Udev::monitor() @@ -215,54 +222,37 @@ UdevMonitor *Udev::monitor() UdevDevice::UdevDevice(udev_device *device) : m_device(device) { + Q_ASSERT(device); } UdevDevice::~UdevDevice() { - if (m_device) { - udev_device_unref(m_device); - } + udev_device_unref(m_device); } udev_device *UdevDevice::getParentWithSubsystemDevType(const char *subsystem, const char *devtype) const { - if (!m_device) { - return nullptr; - } return udev_device_get_parent_with_subsystem_devtype(m_device, subsystem, devtype); } const char *UdevDevice::devNode() { - if (!m_device) { - return nullptr; - } return udev_device_get_devnode(m_device); } int UdevDevice::sysNum() const { - if (!m_device) { - return 0; - } return QByteArray(udev_device_get_sysnum(m_device)).toInt(); } const char *UdevDevice::property(const char *key) { - if (!m_device) { - return nullptr; - } return udev_device_get_property_value(m_device, key); } QMap UdevDevice::properties() const { QMap r; - if (!m_device) { - return r; - } - auto it = udev_device_get_properties_list_entry(m_device); auto current = it; udev_list_entry_foreach (current, it) { diff --git a/src/udev.h b/src/udev.h index 7cbbe57f19..105ae0fc19 100644 --- a/src/udev.h +++ b/src/udev.h @@ -45,7 +45,7 @@ public: typedef std::unique_ptr Ptr; private: - udev_device *m_device; + udev_device *const m_device; }; class KWIN_EXPORT UdevMonitor diff --git a/src/xkb.cpp b/src/xkb.cpp index ef8006f39a..a65d9617a6 100644 --- a/src/xkb.cpp +++ b/src/xkb.cpp @@ -378,6 +378,8 @@ void Xkb::updateModifiers() m_modifierState.depressed = xkb_state_serialize_mods(m_state, xkb_state_component(XKB_STATE_MODS_DEPRESSED)); m_modifierState.latched = xkb_state_serialize_mods(m_state, xkb_state_component(XKB_STATE_MODS_LATCHED)); m_modifierState.locked = xkb_state_serialize_mods(m_state, xkb_state_component(XKB_STATE_MODS_LOCKED)); + + qDebug() << "xxxxxxx modifiers!!!!!!" << m_modifiers; } void Xkb::forwardModifiers()