forge
Explore
Log in

Don't you dare go Hollow

tty: Load libinput plugins if available

Browse files at this commit

1ab1737653d8727c63252fb569e011c0903a9aceIvan MolodetskikhParent: b5640d5
Some distros like Fedora build libinput with plugin autoloading, however
by default, the compositor needs to explicitly load them. Plus, we need
to load manually if we want to also load from
$XDG_CONFIG_HOME/libinput/plugins.

Ref. https://gitlab.gnome.org/GNOME/mutter/-/commit/c5b12fbf6313d51f3279901bb561023e56181e36
Cargo.lockmodified+1 -0
@@ -2207,6 +2207,7 @@ dependencies = [
22072207 "pango",
22082208 "pangocairo",
22092209 "pipewire",
2210+ "pkg-config",
22102211 "png",
22112212 "portable-atomic",
22122213 "profiling",
Cargo.tomlmodified+3 -0
@@ -126,6 +126,9 @@ rayon = "1.11.0"
126126 wayland-client = "0.31.11"
127127 xshell = "0.2.7"
128128
129+[build-dependencies]
130+pkg-config = "0.3.32"
131+
129132 [features]
130133 default = ["dbus", "systemd", "xdp-gnome-screencast"]
131134 # Enables D-Bus support (serve various freedesktop and GNOME interfaces, accessibility tree, power button handling).
build.rsadded+10 -0
@@ -0,0 +1,10 @@
1+fn main() {
2+ println!("cargo:rustc-check-cfg=cfg(have_libinput_plugin_system)");
3+ if pkg_config::Config::new()
4+ .atleast_version("1.30.0")
5+ .probe("libinput")
6+ .is_ok()
7+ {
8+ println!("cargo:rustc-cfg=have_libinput_plugin_system")
9+ }
10+}
src/backend/tty.rsmodified+45 -0
@@ -434,6 +434,7 @@ impl Tty {
434434 .unwrap();
435435
436436 let mut libinput = Libinput::new_with_udev(LibinputSessionInterface::from(session.clone()));
437+ unsafe { init_libinput_plugin_system(&libinput) };
437438 {
438439 let _span = tracy_client::span!("Libinput::udev_assign_seat");
439440 libinput.udev_assign_seat(&seat_name)
@@ -3334,6 +3335,50 @@ fn make_output_name(
33343335 }
33353336 }
33363337
3338+/// Initializes the libinput plugin system.
3339+///
3340+/// # Safety
3341+///
3342+/// This function must be called before libinput iterates through the devices, i.e. before
3343+/// libinput_udev_assign_seat() or the first call to libinput_path_add_device().
3344+unsafe fn init_libinput_plugin_system(libinput: &Libinput) {
3345+ #[cfg(have_libinput_plugin_system)]
3346+ unsafe {
3347+ use std::ffi::{c_char, c_int, CString};
3348+ use std::os::unix::ffi::OsStringExt;
3349+
3350+ use directories::BaseDirs;
3351+ use input::ffi::libinput;
3352+ use input::AsRaw as _;
3353+
3354+ extern "C" {
3355+ fn libinput_plugin_system_append_path(libinput: *const libinput, path: *const c_char);
3356+ fn libinput_plugin_system_append_default_paths(libinput: *const libinput);
3357+ fn libinput_plugin_system_load_plugins(
3358+ libinput: *const libinput,
3359+ flags: c_int,
3360+ ) -> c_int;
3361+ }
3362+ const LIBINPUT_PLUGIN_SYSTEM_FLAG_NONE: c_int = 0;
3363+ let libinput = libinput.as_raw();
3364+
3365+ // Also load plugins from $XDG_CONFIG_HOME/libinput/plugins.
3366+ if let Some(dirs) = BaseDirs::new() {
3367+ let mut plugins_dir = dirs.config_dir().to_path_buf();
3368+ plugins_dir.push("libinput");
3369+ plugins_dir.push("plugins");
3370+ if let Ok(plugins_dir) = CString::new(plugins_dir.into_os_string().into_vec()) {
3371+ libinput_plugin_system_append_path(libinput, plugins_dir.as_ptr());
3372+ }
3373+ }
3374+
3375+ libinput_plugin_system_append_default_paths(libinput);
3376+ libinput_plugin_system_load_plugins(libinput, LIBINPUT_PLUGIN_SYSTEM_FLAG_NONE);
3377+ }
3378+ #[cfg(not(have_libinput_plugin_system))]
3379+ let _ = libinput;
3380+}
3381+
33373382 #[cfg(test)]
33383383 mod tests {
33393384 use insta::assert_debug_snapshot;