From b7c414558d4d9520b3d935be9e6ad3c7f045639e Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 24 Jun 2015 15:07:53 +1000 Subject: [PATCH] tools: pass a context around as userdata We need the options during open_restricted(), so instead of the caller just passing in a custom userdata, let them wrap it into a tools_context. Signed-off-by: Peter Hutterer --- tools/event-debug.c | 10 +++++----- tools/event-gui.c | 22 +++++++++++++--------- tools/libinput-list-devices.c | 6 +++--- tools/shared.c | 14 +++++++++----- tools/shared.h | 12 ++++++++---- 5 files changed, 38 insertions(+), 26 deletions(-) diff --git a/tools/event-debug.c b/tools/event-debug.c index 77133851..7f6c54ab 100644 --- a/tools/event-debug.c +++ b/tools/event-debug.c @@ -42,7 +42,7 @@ uint32_t start_time; static const uint32_t screen_width = 100; static const uint32_t screen_height = 100; -struct tools_options options; +struct tools_context context; static unsigned int stop = 0; static void @@ -298,7 +298,7 @@ handle_and_print_events(struct libinput *li) case LIBINPUT_EVENT_DEVICE_REMOVED: print_device_notify(ev); tools_device_apply_config(libinput_event_get_device(ev), - &options); + &context.options); break; case LIBINPUT_EVENT_KEYBOARD_KEY: print_key_event(ev); @@ -380,12 +380,12 @@ main(int argc, char **argv) struct libinput *li; struct timespec tp; - tools_init_options(&options); + tools_init_context(&context); - if (tools_parse_args(argc, argv, &options)) + if (tools_parse_args(argc, argv, &context)) return 1; - li = tools_open_backend(&options, NULL); + li = tools_open_backend(&context); if (!li) return 1; diff --git a/tools/event-gui.c b/tools/event-gui.c index 7af2a303..5736e979 100644 --- a/tools/event-gui.c +++ b/tools/event-gui.c @@ -44,7 +44,7 @@ #define clip(val_, min_, max_) min((max_), max((min_), (val_))) -struct tools_options options; +struct tools_context context; struct touch { int active; @@ -264,6 +264,7 @@ change_ptraccel(struct window *w, double amount) static void handle_event_device_notify(struct libinput_event *ev) { + struct tools_context *context; struct libinput_device *dev = libinput_event_get_device(ev); struct libinput *li; struct window *w; @@ -280,11 +281,12 @@ handle_event_device_notify(struct libinput_event *ev) libinput_device_get_name(dev), type); - tools_device_apply_config(libinput_event_get_device(ev), - &options); - li = libinput_event_get_context(ev); - w = libinput_get_user_data(li); + context = libinput_get_user_data(li); + w = context->user_data; + + tools_device_apply_config(libinput_event_get_device(ev), + &context->options); if (libinput_event_get_type(ev) == LIBINPUT_EVENT_DEVICE_ADDED) { for (i = 0; i < ARRAY_LENGTH(w->devices); i++) { @@ -430,7 +432,8 @@ static gboolean handle_event_libinput(GIOChannel *source, GIOCondition condition, gpointer data) { struct libinput *li = data; - struct window *w = libinput_get_user_data(li); + struct tools_context *context = libinput_get_user_data(li); + struct window *w = context->user_data; struct libinput_event *ev; libinput_dispatch(li); @@ -498,16 +501,17 @@ main(int argc, char *argv[]) gtk_init(&argc, &argv); - tools_init_options(&options); + tools_init_context(&context); - if (tools_parse_args(argc, argv, &options) != 0) + if (tools_parse_args(argc, argv, &context) != 0) return 1; udev = udev_new(); if (!udev) error("Failed to initialize udev\n"); - li = tools_open_backend(&options, &w); + context.user_data = &w; + li = tools_open_backend(&context); if (!li) return 1; diff --git a/tools/libinput-list-devices.c b/tools/libinput-list-devices.c index e66aa3c9..6d162e2f 100644 --- a/tools/libinput-list-devices.c +++ b/tools/libinput-list-devices.c @@ -268,7 +268,7 @@ int main(int argc, char **argv) { struct libinput *li; - struct tools_options options; + struct tools_context context; struct libinput_event *ev; if (argc > 1) { @@ -284,9 +284,9 @@ main(int argc, char **argv) } } - tools_init_options(&options); + tools_init_context(&context); - li = tools_open_backend(&options, NULL); + li = tools_open_backend(&context); if (!li) return 1; diff --git a/tools/shared.c b/tools/shared.c index 7b032080..0bb03b1b 100644 --- a/tools/shared.c +++ b/tools/shared.c @@ -101,8 +101,12 @@ tools_usage() } void -tools_init_options(struct tools_options *options) +tools_init_context(struct tools_context *context) { + struct tools_options *options = &context->options; + + context->user_data = NULL; + memset(options, 0, sizeof(*options)); options->tapping = -1; options->drag_lock = -1; @@ -367,15 +371,15 @@ static const struct libinput_interface interface = { }; struct libinput * -tools_open_backend(struct tools_options *options, - void *userdata) +tools_open_backend(struct tools_context *context) { struct libinput *li = NULL; + struct tools_options *options = &context->options; if (options->backend == BACKEND_UDEV) { - li = open_udev(&interface, userdata, options->seat, options->verbose); + li = open_udev(&interface, context, options->seat, options->verbose); } else if (options->backend == BACKEND_DEVICE) { - li = open_device(&interface, userdata, options->device, options->verbose); + li = open_device(&interface, context, options->device, options->verbose); } else abort(); diff --git a/tools/shared.h b/tools/shared.h index dad33a16..442d7cd3 100644 --- a/tools/shared.h +++ b/tools/shared.h @@ -48,10 +48,14 @@ struct tools_options { double speed; }; -void tools_init_options(struct tools_options *options); -int tools_parse_args(int argc, char **argv, struct tools_options *options); -struct libinput* tools_open_backend(struct tools_options *options, - void *userdata); +struct tools_context { + struct tools_options options; + void *user_data; +}; + +void tools_init_context(struct tools_context *context); +int tools_parse_args(int argc, char **argv, struct tools_context *context); +struct libinput* tools_open_backend(struct tools_context *context); void tools_device_apply_config(struct libinput_device *device, struct tools_options *options); void tools_usage();