Use a templated approach for InputRedirection::processFilters

Summary:
An improvement from the introduction of InputEventSpy. Instead of
specifying a std::function as argument, we let the compiler decide what
is the best argument.

Reviewers: #kwin, #plasma, mart

Reviewed By: mart

Subscribers: plasma-devel, kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D3877
This commit is contained in:
Martin Gräßlin 2017-01-02 20:08:01 +01:00
parent a8db967505
commit 4db535db07
2 changed files with 10 additions and 6 deletions

View file

@ -1882,11 +1882,6 @@ bool InputRedirection::isBreakingPointerConstraints() const
return m_pointerConstraintsFilter ? m_pointerConstraintsFilter->isActive() : false;
}
void InputRedirection::processFilters(std::function<bool(InputEventFilter*)> function)
{
std::any_of(m_filters.constBegin(), m_filters.constEnd(), function);
}
InputDeviceHandler::InputDeviceHandler(InputRedirection *input)
: QObject(input)
, m_input(input)

11
input.h
View file

@ -173,10 +173,19 @@ public:
* The method @p function is invoked on each input filter. Processing is stopped if
* a filter returns @c true for @p function.
*
* The UnaryPredicate is defined like the UnaryPredicate of std::any_of.
* The signature of the function should be equivalent to the following:
* @code
* bool function(const InputEventFilter *spy);
* @endcode
*
* The intended usage is to std::bind the method to invoke on the filter with all arguments
* bind.
**/
void processFilters(std::function<bool(InputEventFilter*)> function);
template <class UnaryPredicate>
void processFilters(UnaryPredicate function) {
std::any_of(m_filters.constBegin(), m_filters.constEnd(), function);
}
/**
* Sends an event through all input event spies.