[libinput] Use macro for the standard boolean config setters

Less code duplication
This commit is contained in:
Martin Gräßlin 2016-08-11 15:41:06 +02:00
parent e18e2eb57c
commit 00f3f990d6

View file

@ -174,31 +174,24 @@ void Device::setPointerAcceleration(qreal acceleration)
} }
} }
void Device::setEnabled(bool enabled) #define CONFIG(method, condition, function, enum, variable) \
{ void Device::method(bool set) \
if (!m_supportsDisableEvents) { { \
return; if (condition) { \
} return; \
if (libinput_device_config_send_events_set_mode(m_device, enabled ? LIBINPUT_CONFIG_SEND_EVENTS_ENABLED : LIBINPUT_CONFIG_SEND_EVENTS_DISABLED) == LIBINPUT_CONFIG_STATUS_SUCCESS) { } \
if (m_enabled != enabled) { if (libinput_device_config_##function(m_device, set ? LIBINPUT_CONFIG_##enum##_ENABLED : LIBINPUT_CONFIG_##enum##_DISABLED) == LIBINPUT_CONFIG_STATUS_SUCCESS) { \
m_enabled = enabled; if (m_##variable != set) { \
emit enabledChanged(); m_##variable = set; \
} emit variable##Changed(); \
} }\
} \
} }
void Device::setTapToClick(bool set) CONFIG(setEnabled, !m_supportsDisableEvents, send_events_set_mode, SEND_EVENTS, enabled)
{ CONFIG(setTapToClick, m_tapFingerCount == 0, tap_set_enabled, TAP, tapToClick)
if (m_tapFingerCount == 0) {
return; #undef CONFIG
}
if (libinput_device_config_tap_set_enabled(m_device, set ? LIBINPUT_CONFIG_TAP_ENABLED : LIBINPUT_CONFIG_TAP_DISABLED) == LIBINPUT_CONFIG_STATUS_SUCCESS) {
if (m_tapToClick != set) {
m_tapToClick = set;
emit tapToClickChanged();
}
}
}
} }
} }