enum button_event event,
uint64_t time)
{
+ struct libinput *libinput = tp->device->base.seat->libinput;
enum button_state current = t->button.state;
switch(t->button.state) {
}
if (current != t->button.state)
- log_debug("button state: from %s, event %s to %s\n",
+ log_debug(libinput,
+ "button state: from %s, event %s to %s\n",
button_state_to_str(current),
button_event_to_str(event),
button_state_to_str(t->button.state));
const struct input_event *e,
uint64_t time)
{
+ struct libinput *libinput = tp->device->base.seat->libinput;
uint32_t mask = 1 << (e->code - BTN_LEFT);
/* Ignore other buttons on clickpads */
if (tp->buttons.is_clickpad && e->code != BTN_LEFT) {
- log_bug_kernel("received %s button event on a clickpad\n",
+ log_bug_kernel(libinput,
+ "received %s button event on a clickpad\n",
libevdev_event_code_get_name(EV_KEY, e->code));
return 0;
}
tp_init_buttons(struct tp_dispatch *tp,
struct evdev_device *device)
{
+ struct libinput *libinput = tp->device->base.seat->libinput;
struct tp_touch *t;
int width, height;
double diagonal;
if (libevdev_has_event_code(device->evdev, EV_KEY, BTN_MIDDLE) ||
libevdev_has_event_code(device->evdev, EV_KEY, BTN_RIGHT)) {
if (tp->buttons.is_clickpad)
- log_bug_kernel("clickpad advertising right button\n");
+ log_bug_kernel(libinput,
+ "clickpad advertising right button\n");
} else {
if (!tp->buttons.is_clickpad)
- log_bug_kernel("non clickpad without right button?\n");
+ log_bug_kernel(libinput,
+ "non clickpad without right button?\n");
}
absinfo_x = device->abs.absinfo_x;
static void
tp_tap_idle_handle_event(struct tp_dispatch *tp, enum tap_event event, uint64_t time)
{
+ struct libinput *libinput = tp->device->base.seat->libinput;
switch (event) {
case TAP_EVENT_TOUCH:
break;
case TAP_EVENT_RELEASE:
case TAP_EVENT_MOTION:
- log_bug_libinput("invalid event, no fingers are down\n");
+ log_bug_libinput(libinput,
+ "invalid event, no fingers are down\n");
break;
case TAP_EVENT_TIMEOUT:
break;
static void
tp_tap_tapped_handle_event(struct tp_dispatch *tp, enum tap_event event, uint64_t time)
{
+ struct libinput *libinput = tp->device->base.seat->libinput;
switch (event) {
case TAP_EVENT_MOTION:
case TAP_EVENT_RELEASE:
- log_bug_libinput("invalid event when fingers are up\n");
+ log_bug_libinput(libinput,
+ "invalid event when fingers are up\n");
break;
case TAP_EVENT_TOUCH:
tp->tap.state = TAP_STATE_DRAGGING_OR_DOUBLETAP;
static void
tp_tap_handle_event(struct tp_dispatch *tp, enum tap_event event, uint64_t time)
{
+ struct libinput *libinput = tp->device->base.seat->libinput;
enum tp_tap_state current;
+
if (!tp->tap.enabled)
return;
if (tp->tap.state == TAP_STATE_IDLE || tp->tap.state == TAP_STATE_DEAD)
tp_tap_clear_timer(tp);
- log_debug("tap state: %s → %s → %s\n",
+ log_debug(libinput,
+ "tap state: %s → %s → %s\n",
tap_state_to_str(current),
tap_event_to_str(event),
tap_state_to_str(tp->tap.state));
static void
evdev_flush_pending_event(struct evdev_device *device, uint64_t time)
{
+ struct libinput *libinput = device->base.seat->libinput;
struct motion_params motion;
int32_t cx, cy;
double x, y;
break;
if (device->mt.slots[slot].seat_slot != -1) {
- log_bug_kernel("%s: Driver sent multiple touch down for the "
+ log_bug_kernel(libinput,
+ "%s: Driver sent multiple touch down for the "
"same slot", device->devnode);
break;
}
break;
if (device->abs.seat_slot != -1) {
- log_bug_kernel("%s: Driver sent multiple touch down for the "
+ log_bug_kernel(libinput,
+ "%s: Driver sent multiple touch down for the "
"same slot", device->devnode);
break;
}
static int
evdev_configure_device(struct evdev_device *device)
{
+ struct libinput *libinput = device->base.seat->libinput;
struct libevdev *evdev = device->evdev;
const struct input_absinfo *absinfo;
struct input_absinfo fixed;
!libevdev_has_event_code(evdev, EV_KEY, BTN_TOOL_PEN) &&
(has_abs || has_mt)) {
device->dispatch = evdev_mt_touchpad_create(device);
- log_info("input device '%s', %s is a touchpad\n",
+ log_info(libinput,
+ "input device '%s', %s is a touchpad\n",
device->devname, device->devnode);
}
for (i = KEY_ESC; i < KEY_MAX; i++) {
device->seat_caps |= EVDEV_DEVICE_POINTER;
- log_info("input device '%s', %s is a pointer caps =%s%s%s\n",
+ log_info(libinput,
+ "input device '%s', %s is a pointer caps =%s%s%s\n",
device->devname, device->devnode,
has_abs ? " absolute-motion" : "",
has_rel ? " relative-motion": "",
}
if (has_keyboard) {
device->seat_caps |= EVDEV_DEVICE_KEYBOARD;
- log_info("input device '%s', %s is a keyboard\n",
+ log_info(libinput,
+ "input device '%s', %s is a keyboard\n",
device->devname, device->devnode);
}
if (has_touch && !has_button) {
device->seat_caps |= EVDEV_DEVICE_TOUCH;
- log_info("input device '%s', %s is a touch device\n",
+ log_info(libinput,
+ "input device '%s', %s is a touch device\n",
device->devname, device->devnode);
}
* read. mtdev_get() also expects this. */
fd = open_restricted(libinput, devnode, O_RDWR | O_NONBLOCK);
if (fd < 0) {
- log_info("opening input device '%s' failed (%s).\n",
+ log_info(libinput,
+ "opening input device '%s' failed (%s).\n",
devnode, strerror(-fd));
return NULL;
}
const struct libinput_interface *interface;
const struct libinput_interface_backend *interface_backend;
+
+ libinput_log_handler log_handler;
+ enum libinput_log_priority log_priority;
void *user_data;
};
typedef void (*libinput_source_dispatch_t)(void *data);
-#define log_debug(...) log_msg(LIBINPUT_LOG_PRIORITY_DEBUG, __VA_ARGS__)
-#define log_info(...) log_msg(LIBINPUT_LOG_PRIORITY_INFO, __VA_ARGS__)
-#define log_error(...) log_msg(LIBINPUT_LOG_PRIORITY_ERROR, __VA_ARGS__)
-#define log_bug_kernel(...) log_msg(LIBINPUT_LOG_PRIORITY_ERROR, "kernel bug: " __VA_ARGS__)
-#define log_bug_libinput(...) log_msg(LIBINPUT_LOG_PRIORITY_ERROR, "libinput bug: " __VA_ARGS__);
-#define log_bug_client(...) log_msg(LIBINPUT_LOG_PRIORITY_ERROR, "client bug: " __VA_ARGS__);
+#define log_debug(li_, ...) log_msg((li_), LIBINPUT_LOG_PRIORITY_DEBUG, __VA_ARGS__)
+#define log_info(li_, ...) log_msg((li_), LIBINPUT_LOG_PRIORITY_INFO, __VA_ARGS__)
+#define log_error(li_, ...) log_msg((li_), LIBINPUT_LOG_PRIORITY_ERROR, __VA_ARGS__)
+#define log_bug_kernel(li_, ...) log_msg((li_), LIBINPUT_LOG_PRIORITY_ERROR, "kernel bug: " __VA_ARGS__)
+#define log_bug_libinput(li_, ...) log_msg((li_), LIBINPUT_LOG_PRIORITY_ERROR, "libinput bug: " __VA_ARGS__);
+#define log_bug_client(li_, ...) log_msg((li_), LIBINPUT_LOG_PRIORITY_ERROR, "client bug: " __VA_ARGS__);
void
-log_msg(enum libinput_log_priority priority, const char *format, ...);
+log_msg(struct libinput *libinput,
+ enum libinput_log_priority priority,
+ const char *format, ...);
+
void
-log_msg_va(enum libinput_log_priority priority,
+log_msg_va(struct libinput *libinput,
+ enum libinput_log_priority priority,
const char *format,
va_list args);
};
static void
-libinput_default_log_func(enum libinput_log_priority priority,
- void *data,
+libinput_default_log_func(struct libinput *libinput,
+ enum libinput_log_priority priority,
const char *format, va_list args)
{
const char *prefix;
vfprintf(stderr, format, args);
}
-struct log_data {
- enum libinput_log_priority priority;
- libinput_log_handler handler;
- void *user_data;
-};
-
-static struct log_data log_data = {
- .priority = LIBINPUT_LOG_PRIORITY_ERROR,
- .handler = libinput_default_log_func,
- .user_data = NULL,
-};
-
void
-log_msg_va(enum libinput_log_priority priority,
+log_msg_va(struct libinput *libinput,
+ enum libinput_log_priority priority,
const char *format,
va_list args)
{
- if (log_data.handler && log_data.priority <= priority)
- log_data.handler(priority, log_data.user_data, format, args);
+ if (libinput->log_handler &&
+ libinput->log_priority <= priority)
+ libinput->log_handler(libinput, priority, format, args);
}
void
-log_msg(enum libinput_log_priority priority, const char *format, ...)
+log_msg(struct libinput *libinput,
+ enum libinput_log_priority priority,
+ const char *format, ...)
{
va_list args;
va_start(args, format);
- log_msg_va(priority, format, args);
+ log_msg_va(libinput, priority, format, args);
va_end(args);
}
LIBINPUT_EXPORT void
-libinput_log_set_priority(enum libinput_log_priority priority)
+libinput_log_set_priority(struct libinput *libinput,
+ enum libinput_log_priority priority)
{
- log_data.priority = priority;
+ libinput->log_priority = priority;
}
LIBINPUT_EXPORT enum libinput_log_priority
-libinput_log_get_priority(void)
+libinput_log_get_priority(const struct libinput *libinput)
{
- return log_data.priority;
+ return libinput->log_priority;
}
LIBINPUT_EXPORT void
-libinput_log_set_handler(libinput_log_handler log_handler,
- void *user_data)
+libinput_log_set_handler(struct libinput *libinput,
+ libinput_log_handler log_handler)
{
- log_data.handler = log_handler;
- log_data.user_data = user_data;
+ libinput->log_handler = log_handler;
}
static void
return -1;
}
+ libinput->log_handler = libinput_default_log_func;
+ libinput->log_priority = LIBINPUT_LOG_PRIORITY_ERROR;
libinput->interface = interface;
libinput->interface_backend = interface_backend;
libinput->user_data = user_data;
*
* The default log priority is LIBINPUT_LOG_PRIORITY_ERROR.
*
+ * @param libinput A previously initialized libinput context
* @param priority The minimum priority of log messages to print.
*
* @see libinput_log_set_handler
* @see libinput_log_get_priority
*/
void
-libinput_log_set_priority(enum libinput_log_priority priority);
+libinput_log_set_priority(struct libinput *libinput,
+ enum libinput_log_priority priority);
/**
* @ingroup base
*
* The default log priority is LIBINPUT_LOG_PRIORITY_ERROR.
*
+ * @param libinput A previously initialized libinput context
* @return The minimum priority of log messages to print.
*
* @see libinput_log_set_handler
* @see libinput_log_set_priority
*/
enum libinput_log_priority
-libinput_log_get_priority(void);
+libinput_log_get_priority(const struct libinput *libinput);
/**
* @ingroup base
*
* Log handler type for custom logging.
*
+ * @param libinput The libinput context
* @param priority The priority of the current message
- * @param user_data Caller-specific data pointer as previously passed into
- * libinput_log_set_handler()
* @param format Message format in printf-style
* @param args Message arguments
*
* @see libinput_set_log_priority
* @see libinput_log_set_handler
*/
-typedef void (*libinput_log_handler)(enum libinput_log_priority priority,
- void *user_data,
+typedef void (*libinput_log_handler)(struct libinput *libinput,
+ enum libinput_log_priority priority,
const char *format, va_list args)
LIBINPUT_ATTRIBUTE_PRINTF(3, 0);
*
* The default log handler prints to stderr.
*
+ * @param libinput A previously initialized libinput context
* @param log_handler The log handler for library messages.
* @param user_data Caller-specific data pointer, passed into the log
* handler.
* @see libinput_log_set_handler
*/
void
-libinput_log_set_handler(libinput_log_handler log_handler,
- void *user_data);
+libinput_log_set_handler(struct libinput *libinput,
+ libinput_log_handler log_handler);
/**
* @defgroup seat Initialization and manipulation of seats
if (path_get_udev_properties(devnode, &sysname,
&seat_name, &seat_logical_name) == -1) {
- log_info("failed to obtain sysname for device '%s'.\n", devnode);
+ log_info(&input->base,
+ "failed to obtain sysname for device '%s'.\n",
+ devnode);
return NULL;
}
} else {
seat = path_seat_create(input, seat_name, seat_logical_name);
if (!seat) {
- log_info("failed to create seat for device '%s'.\n", devnode);
+ log_info(&input->base,
+ "failed to create seat for device '%s'.\n",
+ devnode);
goto out;
}
}
if (device == EVDEV_UNHANDLED_DEVICE) {
device = NULL;
- log_info("not using input device '%s'.\n", devnode);
+ log_info(&input->base,
+ "not using input device '%s'.\n",
+ devnode);
goto out;
} else if (device == NULL) {
- log_info("failed to create input device '%s'.\n", devnode);
+ log_info(&input->base,
+ "failed to create input device '%s'.\n",
+ devnode);
goto out;
}
struct libinput_device *device;
if (libinput->interface_backend != &interface_backend) {
- log_bug_client("Mismatching backends.\n");
+ log_bug_client(libinput, "Mismatching backends.\n");
return NULL;
}
struct path_device *dev;
if (libinput->interface_backend != &interface_backend) {
- log_bug_client("Mismatching backends.\n");
+ log_bug_client(libinput, "Mismatching backends.\n");
return;
}
r = timerfd_settime(libinput->timer.fd, TFD_TIMER_ABSTIME, &its, NULL);
if (r)
- log_error("timerfd_settime error: %s\n", strerror(errno));
+ log_error(libinput, "timerfd_settime error: %s\n", strerror(errno));
}
void
r = clock_gettime(CLOCK_MONOTONIC, &ts);
if (r) {
- log_error("clock_gettime error: %s\n", strerror(errno));
+ log_error(libinput, "clock_gettime error: %s\n", strerror(errno));
return;
}
libinput_seat_unref(&seat->base);
if (device == EVDEV_UNHANDLED_DEVICE) {
- log_info("not using input device '%s'.\n", devnode);
+ log_info(&input->base, "not using input device '%s'.\n", devnode);
return 0;
} else if (device == NULL) {
- log_info("failed to create input device '%s'.\n", devnode);
+ log_info(&input->base, "failed to create input device '%s'.\n", devnode);
return 0;
}
&device->abs.calibration[4],
&device->abs.calibration[5]) == 6) {
device->abs.apply_calibration = 1;
- log_info("Applying calibration: %f %f %f %f %f %f\n",
+ log_info(&input->base,
+ "Applying calibration: %f %f %f %f %f %f\n",
device->abs.calibration[0],
device->abs.calibration[1],
device->abs.calibration[2],
list_for_each_safe(device, next,
&seat->base.devices_list, base.link) {
if (!strcmp(device->devnode, devnode)) {
- log_info("input device %s, %s removed\n",
+ log_info(&input->base,
+ "input device %s, %s removed\n",
device->devname, device->devnode);
evdev_device_remove(device);
break;
input->udev_monitor = udev_monitor_new_from_netlink(udev, "udev");
if (!input->udev_monitor) {
- log_info("udev: failed to create the udev monitor\n");
+ log_info(libinput,
+ "udev: failed to create the udev monitor\n");
return -1;
}
"input", NULL);
if (udev_monitor_enable_receiving(input->udev_monitor)) {
- log_info("udev: failed to bind the udev monitor\n");
+ log_info(libinput, "udev: failed to bind the udev monitor\n");
udev_monitor_unref(input->udev_monitor);
input->udev_monitor = NULL;
return -1;
return -1;
if (libinput->interface_backend != &interface_backend) {
- log_bug_client("Mismatching backends.\n");
+ log_bug_client(libinput, "Mismatching backends.\n");
return -1;
}
#include "libinput-util.h"
static int in_debugger = -1;
+static int verbose = 0;
struct test {
struct list node;
}
static void
-litest_log_handler(enum libinput_log_priority pri,
- void *user_data,
+litest_log_handler(struct libinput *libinput,
+ enum libinput_log_priority pri,
const char *format,
va_list args)
{
litest_list_tests(&all_tests);
return 0;
case 'v':
- libinput_log_set_priority(LIBINPUT_LOG_PRIORITY_DEBUG);
- libinput_log_set_handler(litest_log_handler, NULL);
+ verbose = 1;
break;
default:
fprintf(stderr, "usage: %s [--list]\n", argv[0]);
struct libinput *libinput =
libinput_path_create_context(&interface, NULL);
ck_assert_notnull(libinput);
+
+ libinput_log_set_handler(libinput, litest_log_handler);
+ if (verbose)
+ libinput_log_set_priority(libinput, LIBINPUT_LOG_PRIORITY_DEBUG);
+
return libinput;
}
#include "litest.h"
static int log_handler_called;
-static void *log_handler_userdata;
+static struct libinput *log_handler_context;
static int open_restricted(const char *path, int flags, void *data)
{
};
static void
-simple_log_handler(enum libinput_log_priority priority,
- void *userdata,
+simple_log_handler(struct libinput *libinput,
+ enum libinput_log_priority priority,
const char *format,
va_list args)
{
log_handler_called++;
- ck_assert(userdata == log_handler_userdata);
+ if (log_handler_context)
+ ck_assert(libinput == log_handler_context);
ck_assert(format != NULL);
}
START_TEST(log_default_priority)
{
enum libinput_log_priority pri;
-
- pri = libinput_log_get_priority();
-
- ck_assert_int_eq(pri, LIBINPUT_LOG_PRIORITY_ERROR);
-}
-END_TEST
-
-START_TEST(log_handler_invoked)
-{
struct libinput *li;
- enum libinput_log_priority pri = libinput_log_get_priority();
-
- libinput_log_set_priority(LIBINPUT_LOG_PRIORITY_DEBUG);
- libinput_log_set_handler(simple_log_handler, NULL);
- log_handler_userdata = NULL;
li = libinput_path_create_context(&simple_interface, NULL);
- libinput_path_add_device(li, "/tmp");
+ pri = libinput_log_get_priority(li);
- ck_assert_int_gt(log_handler_called, 0);
- log_handler_called = 0;
+ ck_assert_int_eq(pri, LIBINPUT_LOG_PRIORITY_ERROR);
libinput_destroy(li);
- libinput_log_set_priority(pri);
}
END_TEST
-START_TEST(log_userdata_NULL)
+START_TEST(log_handler_invoked)
{
struct libinput *li;
- enum libinput_log_priority pri = libinput_log_get_priority();
-
- libinput_log_set_priority(LIBINPUT_LOG_PRIORITY_DEBUG);
- libinput_log_set_handler(simple_log_handler, NULL);
- log_handler_userdata = NULL;
li = libinput_path_create_context(&simple_interface, NULL);
- libinput_path_add_device(li, "/tmp");
- ck_assert_int_gt(log_handler_called, 0);
- log_handler_called = 0;
-
- libinput_destroy(li);
-
- libinput_log_set_priority(pri);
-}
-END_TEST
-
-START_TEST(log_userdata)
-{
- struct libinput *li;
- enum libinput_log_priority pri = libinput_log_get_priority();
-
- libinput_log_set_priority(LIBINPUT_LOG_PRIORITY_DEBUG);
- libinput_log_set_handler(simple_log_handler, &li);
- log_handler_userdata = &li;
+ libinput_log_set_priority(li, LIBINPUT_LOG_PRIORITY_DEBUG);
+ libinput_log_set_handler(li, simple_log_handler);
+ log_handler_context = li;
- li = libinput_path_create_context(&simple_interface, NULL);
libinput_path_add_device(li, "/tmp");
ck_assert_int_gt(log_handler_called, 0);
log_handler_called = 0;
libinput_destroy(li);
- libinput_log_set_priority(pri);
+
+ log_handler_context = NULL;
}
END_TEST
START_TEST(log_handler_NULL)
{
struct libinput *li;
- enum libinput_log_priority pri = libinput_log_get_priority();
-
- libinput_log_set_priority(LIBINPUT_LOG_PRIORITY_DEBUG);
- libinput_log_set_handler(NULL, NULL);
- log_handler_userdata = NULL;
li = libinput_path_create_context(&simple_interface, NULL);
+ libinput_log_set_priority(li, LIBINPUT_LOG_PRIORITY_DEBUG);
+ libinput_log_set_handler(li, NULL);
+
libinput_path_add_device(li, "/tmp");
ck_assert_int_eq(log_handler_called, 0);
log_handler_called = 0;
- libinput_log_set_handler(simple_log_handler, NULL);
libinput_destroy(li);
- libinput_log_set_priority(pri);
}
END_TEST
START_TEST(log_priority)
{
struct libinput *li;
- enum libinput_log_priority pri = libinput_log_get_priority();
-
- libinput_log_set_priority(LIBINPUT_LOG_PRIORITY_ERROR);
- libinput_log_set_handler(simple_log_handler, NULL);
- log_handler_userdata = NULL;
li = libinput_path_create_context(&simple_interface, NULL);
+ libinput_log_set_priority(li, LIBINPUT_LOG_PRIORITY_ERROR);
+ libinput_log_set_handler(li, simple_log_handler);
+ log_handler_context = li;
+
libinput_path_add_device(li, "/tmp");
ck_assert_int_eq(log_handler_called, 0);
- libinput_log_set_priority(LIBINPUT_LOG_PRIORITY_INFO);
+ libinput_log_set_priority(li, LIBINPUT_LOG_PRIORITY_INFO);
libinput_path_add_device(li, "/tmp");
ck_assert_int_gt(log_handler_called, 0);
log_handler_called = 0;
libinput_destroy(li);
- libinput_log_set_priority(pri);
+ log_handler_context = NULL;
}
END_TEST
litest_add_no_device("log:defaults", log_default_priority);
litest_add_no_device("log:logging", log_handler_invoked);
litest_add_no_device("log:logging", log_handler_NULL);
- litest_add_no_device("log:logging", log_userdata);
- litest_add_no_device("log:logging", log_userdata_NULL);
litest_add_no_device("log:logging", log_priority);
return litest_run(argc, argv);
.close_restricted = close_restricted,
};
+static void
+log_handler(struct libinput *li,
+ enum libinput_log_priority priority,
+ const char *format,
+ va_list args)
+{
+ vprintf(format, args);
+}
+
static int
open_udev(struct libinput **li)
{
return 1;
}
+ if (verbose) {
+ libinput_log_set_handler(*li, log_handler);
+ libinput_log_set_priority(*li, LIBINPUT_LOG_PRIORITY_DEBUG);
+ }
+
if (libinput_udev_assign_seat(*li, seat)) {
fprintf(stderr, "Failed to set seat\n");
libinput_destroy(*li);
return 1;
}
+ if (verbose) {
+ libinput_log_set_handler(*li, log_handler);
+ libinput_log_set_priority(*li, LIBINPUT_LOG_PRIORITY_DEBUG);
+ }
+
device = libinput_path_add_device(*li, path);
if (!device) {
fprintf(stderr, "Failed to initialized device %s\n", path);
close(fds[1].fd);
}
-static void
-log_handler(enum libinput_log_priority priority,
- void *user_data,
- const char *format,
- va_list args)
-{
- vprintf(format, args);
-}
-
int
main(int argc, char **argv)
{
if (parse_args(argc, argv))
return 1;
- if (verbose) {
- libinput_log_set_handler(log_handler, NULL);
- libinput_log_set_priority(LIBINPUT_LOG_PRIORITY_DEBUG);
- }
-
if (mode == MODE_UDEV) {
if (open_udev(&li))
return 1;