diff --git a/Cargo.lock b/Cargo.lock index 108ea3e..1f796b6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11,6 +11,15 @@ dependencies = [ "memchr", ] +[[package]] +name = "ansi_term" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" +dependencies = [ + "winapi", +] + [[package]] name = "anyhow" version = "1.0.57" @@ -232,6 +241,29 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +[[package]] +name = "bindgen" +version = "0.56.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2da379dbebc0b76ef63ca68d8fc6e71c0f13e59432e0987e508c1820e6ab5239" +dependencies = [ + "bitflags", + "cexpr", + "clang-sys", + "clap 2.34.0", + "env_logger 0.8.4", + "lazy_static", + "lazycell", + "log", + "peeking_take_while", + "proc-macro2", + "quote", + "regex", + "rustc-hash", + "shlex", + "which", +] + [[package]] name = "bitflags" version = "1.3.2" @@ -259,12 +291,14 @@ dependencies = [ "anyhow", "bscreensaver-command", "bscreensaver-util", - "clap", + "clap 3.1.18", "libc", "log", "nix", + "x11", "xcb", "xcb-xembed", + "xkb", ] [[package]] @@ -272,7 +306,7 @@ name = "bscreensaver-command" version = "0.1.0" dependencies = [ "bscreensaver-util", - "clap", + "clap 3.1.18", "nix", "xcb", ] @@ -343,8 +377,8 @@ name = "bscreensaver-util" version = "0.1.0" dependencies = [ "anyhow", - "clap", - "env_logger", + "clap 3.1.18", + "env_logger 0.9.0", "humantime", "lazy_static", "libc", @@ -403,6 +437,15 @@ version = "1.0.73" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11" +[[package]] +name = "cexpr" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4aedb84272dbe89af497cf81375129abda4fc0a9e7c5d317498c15cc30c0d27" +dependencies = [ + "nom", +] + [[package]] name = "cfg-expr" version = "0.10.2" @@ -432,18 +475,44 @@ dependencies = [ ] [[package]] -name = "clap" -version = "3.1.14" +name = "clang-sys" +version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "535434c063ced786eb04aaf529308092c5ab60889e8fe24275d15de07b01fa97" +checksum = "4cc00842eed744b858222c4c9faf7243aafc6d33f92f96935263ef4d8a41ce21" +dependencies = [ + "glob", + "libc", + "libloading", +] + +[[package]] +name = "clap" +version = "2.34.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" +dependencies = [ + "ansi_term", + "atty", + "bitflags", + "strsim 0.8.0", + "textwrap 0.11.0", + "unicode-width", + "vec_map", +] + +[[package]] +name = "clap" +version = "3.1.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2dbdf4bdacb33466e854ce889eee8dfd5729abf7ccd7664d0a2d60cd384440b" dependencies = [ "atty", "bitflags", "clap_lex", "indexmap", - "strsim", + "strsim 0.10.0", "termcolor", - "textwrap", + "textwrap 0.15.0", ] [[package]] @@ -542,6 +611,19 @@ dependencies = [ "syn", ] +[[package]] +name = "env_logger" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a19187fea3ac7e84da7dacf48de0c45d63c6a76f9490dae389aead16c243fce3" +dependencies = [ + "atty", + "humantime", + "log", + "regex", + "termcolor", +] + [[package]] name = "env_logger" version = "0.9.0" @@ -873,6 +955,12 @@ dependencies = [ "system-deps", ] +[[package]] +name = "glob" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" + [[package]] name = "gloo-timers" version = "0.2.4" @@ -1028,10 +1116,26 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] -name = "libc" -version = "0.2.125" +name = "lazycell" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5916d2ae698f6de9bfb891ad7a8d65c09d232dc58cc4ac433c7da3b2fd84bc2b" +checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" + +[[package]] +name = "libc" +version = "0.2.126" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" + +[[package]] +name = "libloading" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "efbc0f03f9a775e9f6aed295c6a1ba2253c5757a9e03d55c6caa46a681abcddd" +dependencies = [ + "cfg-if", + "winapi", +] [[package]] name = "lock_api" @@ -1045,9 +1149,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.16" +version = "0.4.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6389c490849ff5bc16be905ae24bc913a9c8892e19b2341dbc175e14c341c2b8" +checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" dependencies = [ "cfg-if", "value-bag", @@ -1092,6 +1196,16 @@ dependencies = [ "memoffset", ] +[[package]] +name = "nom" +version = "5.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffb4262d26ed83a1c0a33a38fe2bb15797329c85770da05e6b828ddb782627af" +dependencies = [ + "memchr", + "version_check", +] + [[package]] name = "num-integer" version = "0.1.45" @@ -1139,9 +1253,9 @@ dependencies = [ [[package]] name = "os_str_bytes" -version = "6.0.0" +version = "6.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e22443d1643a904602595ba1cd8f7d896afe56d26712531c5ff73a15b2fbf64" +checksum = "029d8d0b2f198229de29dca79676f2738ff952edf3fde542eb8bf94d8c21b435" [[package]] name = "pam" @@ -1219,6 +1333,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "peeking_take_while" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" + [[package]] name = "pest" version = "2.1.3" @@ -1301,11 +1421,11 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.37" +version = "1.0.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec757218438d5fda206afc041538b2f6d889286160d649a86a24d37e1235afd1" +checksum = "c54b25569025b7fc9651de43004ae593a75ad88543b17178aa5e1b9c4f15f56f" dependencies = [ - "unicode-xid", + "unicode-ident", ] [[package]] @@ -1439,6 +1559,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + [[package]] name = "rustc_version" version = "0.3.3" @@ -1524,6 +1650,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24188a676b6ae68c3b2cb3a01be17fbf7240ce009799bb56d5b1409051e78fde" +[[package]] +name = "shlex" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fdf1b9db47230893d76faad238fd6097fd6d6a9245cd7a4d90dbd639536bbd2" + [[package]] name = "slab" version = "0.4.6" @@ -1552,6 +1684,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" +[[package]] +name = "strsim" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" + [[package]] name = "strsim" version = "0.10.0" @@ -1560,13 +1698,13 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "syn" -version = "1.0.92" +version = "1.0.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ff7c592601f11445996a06f8ad0c27f094a58857c2f89e97974ab9235b92c52" +checksum = "fbaf6116ab8924f39d52792136fb74fd60a80194cf1b1c6ffa6453eef1c3f942" dependencies = [ "proc-macro2", "quote", - "unicode-xid", + "unicode-ident", ] [[package]] @@ -1601,6 +1739,15 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "textwrap" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" +dependencies = [ + "unicode-width", +] + [[package]] name = "textwrap" version = "0.15.0" @@ -1663,10 +1810,16 @@ dependencies = [ ] [[package]] -name = "unicode-xid" -version = "0.2.2" +name = "unicode-ident" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" +checksum = "d22af068fba1eb5edcb4aea19d382b2a3deb4c8f9d475c589b6ada9e0fd493ee" + +[[package]] +name = "unicode-width" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" [[package]] name = "users" @@ -1679,14 +1832,20 @@ dependencies = [ [[package]] name = "value-bag" -version = "1.0.0-alpha.8" +version = "1.0.0-alpha.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79923f7731dc61ebfba3633098bf3ac533bbd35ccd8c57e7088d9a5eebe0263f" +checksum = "2209b78d1249f7e6f3293657c9779fe31ced465df091bbd433a1cf88e916ec55" dependencies = [ "ctor", "version_check", ] +[[package]] +name = "vec_map" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" + [[package]] name = "version-compare" version = "0.1.0" @@ -1796,6 +1955,15 @@ dependencies = [ "cc", ] +[[package]] +name = "which" +version = "3.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d011071ae14a2f6671d0b74080ae0cd8ebf3a6f8c9589a2cd45f23126fe29724" +dependencies = [ + "libc", +] + [[package]] name = "winapi" version = "0.3.9" @@ -1865,6 +2033,27 @@ dependencies = [ "dirs", ] +[[package]] +name = "xkb" +version = "0.2.1" +source = "git+https://github.com/kelnos/rust-xkb?branch=xcb-1.x#c24c9ec0cdc362aed7bc17686953846a2ab1e41d" +dependencies = [ + "bitflags", + "libc", + "xcb", + "xkbcommon-sys", +] + +[[package]] +name = "xkbcommon-sys" +version = "0.7.5" +source = "git+https://github.com/kelnos/rust-xkbcommon-sys?branch=release-0.7.x#8579153d01ef87096abf0ef02608e5dde8e96a0c" +dependencies = [ + "bindgen", + "libc", + "pkg-config", +] + [[package]] name = "zbus" version = "2.2.0" @@ -1929,9 +2118,9 @@ dependencies = [ [[package]] name = "zvariant" -version = "3.2.0" +version = "3.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e18ba99d71e03af262953f476071607da0c44e225236cf9b5b9f7f11f1d0b6b0" +checksum = "cbd1abd8bc2c855412b9c8af9fc11c0d695c73c732ad5a1a1be10f3fd4bf19b2" dependencies = [ "byteorder", "enumflags2", @@ -1943,9 +2132,9 @@ dependencies = [ [[package]] name = "zvariant_derive" -version = "3.2.0" +version = "3.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9042892ebdca35261951a83d17bcbfd4d3d528cb3bde828498a9b306b50d05c0" +checksum = "abebd57382dfacf3e7bbdd7b7c3d162d6ed0687a78f046263ddef4ddabc275ae" dependencies = [ "proc-macro-crate", "proc-macro2", diff --git a/Cargo.toml b/Cargo.toml index 284f69d..d3785bb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,3 +10,11 @@ members = [ "systemd", "xcb-xembed", ] + +[patch.crates-io] +# git source needed until extension event error resolution fix is released +xcb = { git = "https://github.com/rust-x-bindings/rust-xcb", rev = "d09b5f91bc07d56673f1bc0d6c7ecd72b5ff7b3e" } +# xkb package depends on xcb 0.9 +xkb = { git = "https://github.com/kelnos/rust-xkb", branch = "xcb-1.x" } +# Build error in v0.7.5 when x11 feature enabled +ffi = { package = "xkbcommon-sys", git = "https://github.com/kelnos/rust-xkbcommon-sys", branch = "release-0.7.x" } diff --git a/async-xcb/Cargo.toml b/async-xcb/Cargo.toml index ff7281a..fd4dbf4 100644 --- a/async-xcb/Cargo.toml +++ b/async-xcb/Cargo.toml @@ -9,5 +9,4 @@ async-std = { version = "1.11", features = ["attributes"] } futures = "0.3" futures-lite = "1.12" nix = "0.23" -# git source needed until extension event error resolution fix is released -xcb = { git = "https://github.com/rust-x-bindings/rust-xcb", rev = "d09b5f91bc07d56673f1bc0d6c7ecd72b5ff7b3e" } +xcb = "1" diff --git a/command/Cargo.toml b/command/Cargo.toml index 6587e63..11c9cb1 100644 --- a/command/Cargo.toml +++ b/command/Cargo.toml @@ -7,4 +7,4 @@ edition = "2021" bscreensaver-util = { path = "../util" } clap = "3" nix = "0.23" -xcb = { git = "https://github.com/rust-x-bindings/rust-xcb", rev = "d09b5f91bc07d56673f1bc0d6c7ecd72b5ff7b3e" } +xcb = "1" diff --git a/dbus-service/Cargo.toml b/dbus-service/Cargo.toml index 60680b1..8a0d183 100644 --- a/dbus-service/Cargo.toml +++ b/dbus-service/Cargo.toml @@ -11,6 +11,5 @@ bscreensaver-command = { path = "../command" } bscreensaver-util = { path = "../util" } futures = "0.3" log = "0.4" -# git source needed until extension event error resolution fix is released -xcb = { git = "https://github.com/rust-x-bindings/rust-xcb", rev = "d09b5f91bc07d56673f1bc0d6c7ecd72b5ff7b3e" } +xcb = "1" zbus = "2" diff --git a/debian/control b/debian/control index a1e1999..ef8918f 100644 --- a/debian/control +++ b/debian/control @@ -9,6 +9,7 @@ Build-Depends: libxcb-randr0-dev, libxcb-xfixes0-dev, libxcb1-dev, + libxkbcommon-x11-dev, libgtk-3-dev, libpam0g-dev, cargo (>= 0.57), diff --git a/locker/Cargo.toml b/locker/Cargo.toml index 7983f0e..5e2ead0 100644 --- a/locker/Cargo.toml +++ b/locker/Cargo.toml @@ -20,6 +20,7 @@ bscreensaver-util = { path = "../util" } libc = "0.2" log = "0.4" nix = "0.23" -# git source needed until extension event error resolution fix is released -xcb = { git = "https://github.com/rust-x-bindings/rust-xcb", rev = "d09b5f91bc07d56673f1bc0d6c7ecd72b5ff7b3e", features = ["randr", "xfixes", "xinput"] } +x11 = "2.19" +xcb = { version = "1", features = ["randr", "xkb", "xfixes", "xinput"] } xcb-xembed = { path = "../xcb-xembed" } +xkb = { version = "0.2", features = ["x11"] } diff --git a/locker/src/main.rs b/locker/src/main.rs index 58e1146..3481f97 100644 --- a/locker/src/main.rs +++ b/locker/src/main.rs @@ -112,7 +112,7 @@ fn main() -> anyhow::Result<()> { let (conn, screen_num) = xcb::Connection::connect_with_extensions( None, - &[xcb::Extension::RandR, xcb::Extension::XFixes, xcb::Extension::Input], + &[xcb::Extension::RandR, xcb::Extension::XFixes, xcb::Extension::Input, xcb::Extension::Xkb], &[] )?; let setup = conn.get_setup(); @@ -121,6 +121,8 @@ fn main() -> anyhow::Result<()> { init_xfixes(&conn)?; init_xinput(&conn)?; init_randr(&conn)?; + xkb::x11::setup(&conn, xkb::x11::MIN_MAJOR_XKB_VERSION, xkb::x11::MIN_MINOR_XKB_VERSION, xkb::x11::NO_FLAGS) + .map_err(|_| anyhow::anyhow!("Failed to initialize XKB extension"))?; create_command_window(&conn, &screen)?; let command_atoms = CommandAtoms { @@ -740,6 +742,20 @@ fn start_unlock_dialog<'a>(conn: &'a xcb::Connection, state: &State<'a>, trigger show_cursor(conn, state); + let trigger_event = match trigger_event { + Some(xcb::Event::X(x::Event::KeyPress(ev))) => match keysym_for_keypress(conn, &ev) { + Err(err) => { + warn!("Failed to get keysym for key press event: {}", err); + Some(xcb::Event::X(x::Event::KeyPress(ev))) + }, + Ok(Some(keysym)) if keysym == xkb::key::KP_Enter || keysym == xkb::key::ISO_Enter || keysym == xkb::key::Return || keysym == xkb::key::Escape => + // don't forward an or to the dialog, as that will make it activate/close immediately + None, + _ => Some(xcb::Event::X(x::Event::KeyPress(ev))), + }, + te => te, + }; + let mut child = Command::new(format!("{}/{}", env!("HELPER_DIR"), state.config.dialog_backend.binary_name())) .stdout(Stdio::piped()) .spawn()?; @@ -1012,3 +1028,14 @@ fn kill_child_processes(state: &mut State) -> anyhow::Result<()> { Ok(()) } + +fn keysym_for_keypress(conn: &xcb::Connection, ev: &x::KeyPressEvent) -> anyhow::Result> { + let ctx = xkb::Context::new(xkb::context::Flags::NO_FLAGS); + let device = xkb::x11::device(conn) + .map_err(|_| anyhow::anyhow!("Failed to get xkb device"))?; + let keymap = xkb::x11::keymap(conn, device, &ctx, xkb::keymap::compile::Flags::NO_FLAGS) + .map_err(|_| anyhow::anyhow!("Failed to get xkb keymap"))?; + let state = xkb::x11::state(conn, device, &keymap) + .map_err(|_| anyhow::anyhow!("Failed to get xkb state"))?; + Ok(state.key(ev.detail()).sym()) +} diff --git a/systemd/Cargo.toml b/systemd/Cargo.toml index 4b84257..d7b687c 100644 --- a/systemd/Cargo.toml +++ b/systemd/Cargo.toml @@ -12,7 +12,6 @@ bscreensaver-util = { path = "../util" } futures = "0.3" log = "0.4" nix = "0.23" -# git source needed until extension event error resolution fix is released -xcb = { git = "https://github.com/rust-x-bindings/rust-xcb", rev = "d09b5f91bc07d56673f1bc0d6c7ecd72b5ff7b3e" } +xcb = "1" zbus = "2.2" logind-zbus = "3" diff --git a/util/Cargo.toml b/util/Cargo.toml index dfc89ef..e90fc3a 100644 --- a/util/Cargo.toml +++ b/util/Cargo.toml @@ -14,6 +14,6 @@ lazy_static = "1" libc = "0.2" shell-words = "1" toml = "0.5" -xcb = { git = "https://github.com/rust-x-bindings/rust-xcb", rev = "d09b5f91bc07d56673f1bc0d6c7ecd72b5ff7b3e", features = ["randr", "screensaver", "xfixes"] } +xcb = "1" xdg = "2" zbus = "2" diff --git a/xcb-xembed/Cargo.toml b/xcb-xembed/Cargo.toml index fc47ffc..54cfd24 100644 --- a/xcb-xembed/Cargo.toml +++ b/xcb-xembed/Cargo.toml @@ -15,4 +15,4 @@ categories = ["gui"] [dependencies] bitflags = "1" log = "0.4" -xcb = { git = "https://github.com/rust-x-bindings/rust-xcb", rev = "d09b5f91bc07d56673f1bc0d6c7ecd72b5ff7b3e", features = ["randr", "screensaver", "xfixes"] } +xcb = { version = "1", features = ["xfixes"] }