diff --git a/Cargo.lock b/Cargo.lock index dd538f0..5f412d5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1329,6 +1329,7 @@ dependencies = [ "tokio", "tracing", "tracing-subscriber", + "udev", "url", "xkb-data", ] diff --git a/cosmic-settings/Cargo.toml b/cosmic-settings/Cargo.toml index 41bbde6..8e1893d 100644 --- a/cosmic-settings/Cargo.toml +++ b/cosmic-settings/Cargo.toml @@ -47,6 +47,7 @@ clap = { version = "4.4.18", features = ["derive"] } itoa = "1.0.10" futures = { package = "futures-lite", version = "2.2.0" } xkb-data = "0.1.0" +udev = "0.8.0" [dependencies.i18n-embed] version = "0.14.1" diff --git a/cosmic-settings/src/pages/input/mod.rs b/cosmic-settings/src/pages/input/mod.rs index b67d3b3..b5a02a6 100644 --- a/cosmic-settings/src/pages/input/mod.rs +++ b/cosmic-settings/src/pages/input/mod.rs @@ -1,4 +1,5 @@ use crate::app; +use clap::builder::OsStr; use cosmic::{ cosmic_config::{self, ConfigGet, ConfigSet}, iced::{self, wayland::actions::window::SctkWindowSettings, window}, @@ -205,8 +206,31 @@ impl page::Page for Page { impl page::AutoBind for Page { fn sub_pages(page: page::Insert) -> page::Insert { - page.sub_page::() - .sub_page::() - .sub_page::() + let insert = page.sub_page::().sub_page::(); + + if system_has_touchpad() { + insert.sub_page::() + } else { + insert + } } } + +/// Uses `udev` to check if a touchpad device exists on the system. +fn system_has_touchpad() -> bool { + let Ok(mut enumerator) = udev::Enumerator::new() else { + return false; + }; + + let _res = enumerator.match_subsystem("input"); + + let Ok(mut devices) = enumerator.scan_devices() else { + return false; + }; + + devices.any(|device| { + device + .property_value("ID_INPUT_TOUCHPAD") + .map_or(false, |value| value == "1") + }) +}