Commit 48356537 authored by Kai Uwe Broulik's avatar Kai Uwe Broulik 🍇

[Mouse KCM] Check libinput Atom availability before using them

Otherwise the KCM aborts on XWayland.

CHANGELOG: Fixed mouse settings module crashing on Wayland

BUG: 389978
FIXED-IN: 5.12.1

Differential Revision: https://phabricator.kde.org/D10359
parent 51a92737
......@@ -187,39 +187,41 @@ void X11MouseBackend::load()
bool flatAvailable = false;
bool adaptiveEnabled = false;
bool flatEnabled = false;
XI2ForallPointerDevices(m_dpy, [&] (XIDeviceInfo *info) {
int deviceid = info->deviceid;
Status status;
Atom type_return;
int format_return;
unsigned long num_items_return;
unsigned long bytes_after_return;
unsigned char *_data = nullptr;
//data returned is an 2 byte boolean
status = XIGetProperty(m_dpy, deviceid, m_libinputAccelProfileAvailableAtom, 0, 2,
False, XA_INTEGER, &type_return, &format_return,
&num_items_return, &bytes_after_return, &_data);
QScopedArrayPointer<unsigned char, ScopedXDeleter> data(_data);
_data = nullptr;
if (status != Success || type_return != XA_INTEGER || !data || format_return != 8 || num_items_return != 2) {
return;
}
adaptiveAvailable = adaptiveAvailable || data[0];
flatAvailable = flatAvailable || data[1];
//data returned is an 2 byte boolean
status = XIGetProperty(m_dpy, deviceid, m_libinputAccelProfileEnabledAtom, 0, 2,
False, XA_INTEGER, &type_return, &format_return,
&num_items_return, &bytes_after_return, &_data);
data.reset(_data);
_data = nullptr;
if (status != Success || type_return != XA_INTEGER || !data || format_return != 8 || num_items_return != 2) {
return;
}
adaptiveEnabled = adaptiveEnabled || data[0];
flatEnabled = flatEnabled || data[1];
});
if (m_libinputAccelProfileAvailableAtom != None && m_libinputAccelProfileEnabledAtom != None) {
XI2ForallPointerDevices(m_dpy, [&] (XIDeviceInfo *info) {
int deviceid = info->deviceid;
Status status;
Atom type_return;
int format_return;
unsigned long num_items_return;
unsigned long bytes_after_return;
unsigned char *_data = nullptr;
//data returned is an 2 byte boolean
status = XIGetProperty(m_dpy, deviceid, m_libinputAccelProfileAvailableAtom, 0, 2,
False, XA_INTEGER, &type_return, &format_return,
&num_items_return, &bytes_after_return, &_data);
QScopedArrayPointer<unsigned char, ScopedXDeleter> data(_data);
_data = nullptr;
if (status != Success || type_return != XA_INTEGER || !data || format_return != 8 || num_items_return != 2) {
return;
}
adaptiveAvailable = adaptiveAvailable || data[0];
flatAvailable = flatAvailable || data[1];
//data returned is an 2 byte boolean
status = XIGetProperty(m_dpy, deviceid, m_libinputAccelProfileEnabledAtom, 0, 2,
False, XA_INTEGER, &type_return, &format_return,
&num_items_return, &bytes_after_return, &_data);
data.reset(_data);
_data = nullptr;
if (status != Success || type_return != XA_INTEGER || !data || format_return != 8 || num_items_return != 2) {
return;
}
adaptiveEnabled = adaptiveEnabled || data[0];
flatEnabled = flatEnabled || data[1];
});
}
if (adaptiveAvailable) {
m_supportedAccelerationProfiles << PROFILE_ADAPTIVE;
......@@ -444,6 +446,11 @@ bool X11MouseBackend::libinputApplyReverseScroll(int deviceid, bool reverse)
void X11MouseBackend::libinputApplyAccelerationProfile(int deviceid, QString profile)
{
// Check atom availability first.
if (m_libinputAccelProfileAvailableAtom == None || m_libinputAccelProfileEnabledAtom == None) {
return;
}
unsigned char profileData[2];
if (profile == PROFILE_NONE) {
profileData[0] = profileData[1] = 0;
......
Markdown is supported
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