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.
This commit is contained in:
parent
bec580f3c5
commit
ca1e4a255a
4 changed files with 14 additions and 22 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
28
src/udev.cpp
28
src/udev.cpp
|
@ -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);
|
||||
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 *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()
|
||||
|
|
Loading…
Reference in a new issue