tty: Load libinput plugins if available
Browse files at this commit1ab1737653d8727c63252fb569e011c0903a9aceParent: b5640d54 changed files +59 -0
- Cargo.lock +1 -0
- Cargo.toml +3 -0
- build.rs +10 -0
- src/backend/tty.rs +45 -0
Cargo.lockmodified+1 -0
| @@ -2207,6 +2207,7 @@ dependencies = [ | ||
| 2207 | 2207 | "pango", |
| 2208 | 2208 | "pangocairo", |
| 2209 | 2209 | "pipewire", |
| 2210 | + "pkg-config", | |
| 2210 | 2211 | "png", |
| 2211 | 2212 | "portable-atomic", |
| 2212 | 2213 | "profiling", |
Cargo.tomlmodified+3 -0
| @@ -126,6 +126,9 @@ rayon = "1.11.0" | ||
| 126 | 126 | wayland-client = "0.31.11" |
| 127 | 127 | xshell = "0.2.7" |
| 128 | 128 | |
| 129 | +[build-dependencies] | |
| 130 | +pkg-config = "0.3.32" | |
| 131 | + | |
| 129 | 132 | [features] |
| 130 | 133 | default = ["dbus", "systemd", "xdp-gnome-screencast"] |
| 131 | 134 | # 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 { | ||
| 434 | 434 | .unwrap(); |
| 435 | 435 | |
| 436 | 436 | let mut libinput = Libinput::new_with_udev(LibinputSessionInterface::from(session.clone())); |
| 437 | + unsafe { init_libinput_plugin_system(&libinput) }; | |
| 437 | 438 | { |
| 438 | 439 | let _span = tracy_client::span!("Libinput::udev_assign_seat"); |
| 439 | 440 | libinput.udev_assign_seat(&seat_name) |
| @@ -3334,6 +3335,50 @@ fn make_output_name( | ||
| 3334 | 3335 | } |
| 3335 | 3336 | } |
| 3336 | 3337 | |
| 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 | + | |
| 3337 | 3382 | #[cfg(test)] |
| 3338 | 3383 | mod tests { |
| 3339 | 3384 | use insta::assert_debug_snapshot; |