Commit ca1e4a25 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧 Committed by Aleix Pol Gonzalez
Browse files

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.
parent bec580f3
......@@ -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;
}
}
......
......@@ -10,9 +10,11 @@
#include "main.h"
#include "platform.h"
#include "session.h"
#include "utils.h"
// Qt
#include <QByteArray>
#include <QScopedPointer>
#include <QDebug>
// system
#include <libudev.h>
#include <functional>
......@@ -199,7 +201,12 @@ std::vector<UdevDevice::Ptr> 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);
Please register or sign in to reply
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<QByteArray, QByteArray> UdevDevice::properties() const
{
QMap<QByteArray, QByteArray> 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) {
......
......@@ -45,7 +45,7 @@ public:
typedef std::unique_ptr<UdevDevice> Ptr;
private:
udev_device *m_device;
udev_device *const m_device;
};
class KWIN_EXPORT UdevMonitor
......
......@@ -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()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment