From eca06ecb02a6ecae3fd15209a2f3b70bed211bcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Fri, 5 Feb 2016 12:50:49 +0100 Subject: [PATCH] [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. --- libinput/context.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/libinput/context.cpp b/libinput/context.cpp index 1e2e3f99c4..a5fd7ccb84 100644 --- a/libinput/context.cpp +++ b/libinput/context.cpp @@ -19,6 +19,7 @@ along with this program. If not, see . *********************************************************************/ #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()