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: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1347>
This commit is contained in:
Peter Hutterer 2025-10-27 11:54:25 +10:00 committed by Marge Bot
parent f27fbdfa53
commit eb01a4e73f
6 changed files with 57 additions and 13 deletions

View file

@ -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',

View file

@ -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',

View file

@ -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);

View file

@ -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)
{

View file

@ -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

View file

@ -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