From bfceb1bc580656aceb14e4b0f880bfcb3e4bc368 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Fri, 4 Apr 2014 15:51:22 +1000 Subject: eventcomm: Hook up the libevdev log handler This is a bit problematic: libevdev only has one global log handler. So if we have another driver use libevdev, we'll either overwrite that handler or get overwritten, whichever comes first. So we need to re-set the handler every time we get an event to make sure we log through our handler. Likewise, if we ever drop the device, we need to unset the log handler back to NULL because we may unload the module and our handler may disappear. Use the lowest logging priority, let the server filter based on the verbosity level instead. Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede --- src/eventcomm.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/eventcomm.c b/src/eventcomm.c index 0cbbbd0..5871374 100644 --- a/src/eventcomm.c +++ b/src/eventcomm.c @@ -87,12 +87,46 @@ struct eventcomm_proto_data { enum libevdev_read_flag read_flag; }; +static void +libevdev_log_func(enum libevdev_log_priority priority, + void *data, + const char *file, int line, const char *func, + const char *format, va_list args) +_X_ATTRIBUTE_PRINTF(6, 0); + +static void +libevdev_log_func(enum libevdev_log_priority priority, + void *data, + const char *file, int line, const char *func, + const char *format, va_list args) +{ + int verbosity; + + switch(priority) { + case LIBEVDEV_LOG_ERROR: verbosity = 0; break; + case LIBEVDEV_LOG_INFO: verbosity = 4; break; + case LIBEVDEV_LOG_DEBUG: verbosity = 10; break; + } + + LogVMessageVerbSigSafe(X_NOTICE, verbosity, format, args); +} + +static void +set_libevdev_log_handler(void) +{ + /* be quiet, gcc *handwave* */ + libevdev_set_log_function((libevdev_log_func_t)libevdev_log_func, NULL); + libevdev_set_log_priority(LIBEVDEV_LOG_DEBUG); +} + struct eventcomm_proto_data * EventProtoDataAlloc(int fd) { struct eventcomm_proto_data *proto_data; int rc; + set_libevdev_log_handler(); + proto_data = calloc(1, sizeof(struct eventcomm_proto_data)); if (!proto_data) return NULL; @@ -181,6 +215,8 @@ EventDeviceOnHook(InputInfoPtr pInfo, SynapticsParameters * para) struct eventcomm_proto_data *proto_data = (struct eventcomm_proto_data *) priv->proto_data; + set_libevdev_log_handler(); + if (libevdev_get_fd(proto_data->evdev) != -1) { struct input_event ev; @@ -224,6 +260,8 @@ EventDeviceOffHook(InputInfoPtr pInfo) UninitializeTouch(pInfo); libevdev_grab(proto_data->evdev, LIBEVDEV_UNGRAB); + libevdev_set_log_function(NULL, NULL); + libevdev_set_log_priority(LIBEVDEV_LOG_INFO); /* reset to default */ return Success; } @@ -625,6 +663,8 @@ EventReadHwState(InputInfoPtr pInfo, struct eventcomm_proto_data *proto_data = priv->proto_data; Bool sync_cumulative = FALSE; + set_libevdev_log_handler(); + SynapticsResetTouchHwState(hw, FALSE); /* Reset cumulative values if buttons were not previously pressed, -- cgit v1.2.3