From eb01a4e73fe438620947c0d565cafae35aaf07bd Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 27 Oct 2025 11:54:25 +1000 Subject: [PATCH] plugins: add meson option to autoload plugins Add an option to enable autoloading plugins from the default paths. This makes testing and adoption for new users easier as they can (if necessary) rebuild libinput with that option enabled instead of having to wait for the compositor stack to update. Autoloading will only use the default paths (/etc and /usr/lib) and will only happen if the client does not modify those paths since that implies the client wants to load plugins themselves. A client that adds a plugin path but doesn't load the plugins is considered buggy anyway. Part-of: --- meson.build | 6 +++++ meson_options.txt | 4 +++ src/libinput-plugin-system.h | 4 +-- src/libinput-plugin.c | 50 +++++++++++++++++++++++++++++++----- src/path-seat.c | 3 +-- src/udev-seat.c | 3 +-- 6 files changed, 57 insertions(+), 13 deletions(-) diff --git a/meson.build b/meson.build index 39244f80..535776bc 100644 --- a/meson.build +++ b/meson.build @@ -180,8 +180,14 @@ if have_plugins config_h.set('HAVE_PLUGINS', 1) endif +autoload_plugins = get_option('autoload-plugins') +if autoload_plugins + config_h.set('AUTOLOAD_PLUGINS', 1) +endif + summary({ 'Plugins enabled' : have_plugins, + 'Autoload plugins' : autoload_plugins, 'Lua Plugin support' : have_lua, }, section : 'Plugins', diff --git a/meson_options.txt b/meson_options.txt index a3ffb3e1..de0b1c41 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -42,6 +42,10 @@ option('internal-event-debugging', type: 'boolean', value: false, description: 'Enable additional internal event debug tracing. This will print key values to the logs and thus must never be enabled in a release build') +option('autoload-plugins', + type: 'boolean', + value: false, + description: 'Always load plugins from default plugin paths (only if the caller does not do so)') option('lua-plugins', type: 'feature', value: 'auto', diff --git a/src/libinput-plugin-system.h b/src/libinput-plugin-system.h index 5dafa8c7..c3d7de6d 100644 --- a/src/libinput-plugin-system.h +++ b/src/libinput-plugin-system.h @@ -42,6 +42,7 @@ struct libinput_plugin_system { char **directories; /* NULL once loaded == true */ bool loaded; + bool autoload; struct list plugins; struct list removed_plugins; @@ -53,8 +54,7 @@ void libinput_plugin_system_init(struct libinput_plugin_system *system); void -libinput_plugin_system_load_internal_plugins(struct libinput *libinput, - struct libinput_plugin_system *system); +libinput_plugin_system_autoload(struct libinput *libinput); void libinput_plugin_system_destroy(struct libinput_plugin_system *system); diff --git a/src/libinput-plugin.c b/src/libinput-plugin.c index bee11732..a6c6a9ab 100644 --- a/src/libinput-plugin.c +++ b/src/libinput-plugin.c @@ -98,6 +98,10 @@ plugin_log_msg(struct libinput_plugin *plugin, log_msg(plugin->libinput, priority, "%s%s", prefix, message); } +static void +libinput_plugin_system_load_internal_plugins(struct libinput *libinput, + struct libinput_plugin_system *system); + struct libinput_plugin * libinput_plugin_new(struct libinput *libinput, const char *name, @@ -346,6 +350,17 @@ libinput_plugin_notify_device_removed(struct libinput_plugin *plugin, plugin->interface->device_removed(plugin, device); } +static void +plugin_system_append_path(struct libinput_plugin_system *plugin_system, + const char *path) +{ + if (strv_find(plugin_system->directories, path, NULL)) + return; + + plugin_system->directories = + strv_append_strdup(plugin_system->directories, path); +} + LIBINPUT_EXPORT void libinput_plugin_system_append_path(struct libinput *libinput, const char *path) { @@ -354,11 +369,9 @@ libinput_plugin_system_append_path(struct libinput *libinput, const char *path) return; } - if (strv_find(libinput->plugin_system.directories, path, NULL)) - return; + libinput->plugin_system.autoload = false; - libinput->plugin_system.directories = - strv_append_strdup(libinput->plugin_system.directories, path); + plugin_system_append_path(&libinput->plugin_system, path); } LIBINPUT_EXPORT void @@ -369,8 +382,26 @@ libinput_plugin_system_append_default_paths(struct libinput *libinput) return; } - libinput_plugin_system_append_path(libinput, LIBINPUT_PLUGIN_ETCDIR); - libinput_plugin_system_append_path(libinput, LIBINPUT_PLUGIN_LIBDIR); + libinput->plugin_system.autoload = false; + + plugin_system_append_path(&libinput->plugin_system, LIBINPUT_PLUGIN_ETCDIR); + plugin_system_append_path(&libinput->plugin_system, LIBINPUT_PLUGIN_LIBDIR); +} + +void +libinput_plugin_system_autoload(struct libinput *libinput) +{ + if (libinput->plugin_system.loaded) + return; + + if (libinput->plugin_system.autoload) { + libinput_plugin_system_append_default_paths(libinput); + libinput_plugin_system_load_plugins(libinput, + LIBINPUT_PLUGIN_SYSTEM_FLAG_NONE); + } else { + libinput_plugin_system_load_internal_plugins(libinput, + &libinput->plugin_system); + } } LIBINPUT_EXPORT int @@ -453,11 +484,16 @@ void libinput_plugin_system_init(struct libinput_plugin_system *system) { system->loaded = false; +#ifdef AUTOLOAD_PLUGINS + system->autoload = true; +#else + system->autoload = false; +#endif list_init(&system->plugins); list_init(&system->removed_plugins); } -void +static void libinput_plugin_system_load_internal_plugins(struct libinput *libinput, struct libinput_plugin_system *system) { diff --git a/src/path-seat.c b/src/path-seat.c index bd304f6c..d76bea0a 100644 --- a/src/path-seat.c +++ b/src/path-seat.c @@ -383,8 +383,7 @@ libinput_path_add_device(struct libinput *libinput, const char *path) return NULL; } - libinput_plugin_system_load_internal_plugins(libinput, - &libinput->plugin_system); + libinput_plugin_system_autoload(libinput); /* We cannot do this during path_create_context because the log * handler isn't set up there but we really want to log to the right diff --git a/src/udev-seat.c b/src/udev-seat.c index b0f1a218..dfaeb6e5 100644 --- a/src/udev-seat.c +++ b/src/udev-seat.c @@ -416,8 +416,7 @@ libinput_udev_assign_seat(struct libinput *libinput, const char *seat_id) if (input->seat_id != NULL) return -1; - libinput_plugin_system_load_internal_plugins(libinput, - &libinput->plugin_system); + libinput_plugin_system_autoload(libinput); /* We cannot do this during udev_create_context because the log * handler isn't set up there but we really want to log to the right