[libinput] Install a log handler

Let's get all debug events from libinput and forward them to a custom
log handler. This in turn can pass them to Qt's categorized logging.
So it's still easy to
* disable all libinput related logging
* configure the log level

Both was not possible before.
icc-effect-5.14.5
Martin Gräßlin 2016-02-05 12:50:49 +01:00
parent 66c77bcd31
commit eca06ecb02
1 changed files with 24 additions and 0 deletions

View File

@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#include "context.h"
#include "events.h"
#include "libinput_logging.h"
#include "../logind.h"
#include "../udev.h"
@ -31,10 +32,33 @@ namespace KWin
namespace LibInput
{
static void libinputLogHandler(libinput *libinput, libinput_log_priority priority, const char *format, va_list args)
{
Q_UNUSED(libinput)
char buf[1024];
if (std::vsnprintf(buf, 1023, format, args) <= 0) {
return;
}
switch (priority) {
case LIBINPUT_LOG_PRIORITY_DEBUG:
qCDebug(KWIN_LIBINPUT) << "Libinput:" << buf;
break;
case LIBINPUT_LOG_PRIORITY_INFO:
qCInfo(KWIN_LIBINPUT) << "Libinput:" << buf;
break;
case LIBINPUT_LOG_PRIORITY_ERROR:
default:
qCCritical(KWIN_LIBINPUT) << "Libinput:" << buf;
break;
}
}
Context::Context(const Udev &udev)
: m_libinput(libinput_udev_create_context(&Context::s_interface, this, udev))
, m_suspended(false)
{
libinput_log_set_priority(m_libinput, LIBINPUT_LOG_PRIORITY_DEBUG);
libinput_log_set_handler(m_libinput, &libinputLogHandler);
}
Context::~Context()