From d3cb9da3aa10c7b6c7d9eaf1058a85998f4f98f7 Mon Sep 17 00:00:00 2001 From: bluepython508 <16466646+bluepython508@users.noreply.github.com> Date: Wed, 19 Mar 2025 16:14:21 +0000 Subject: [PATCH] Initial Commit: sufficient wayland work to lock screen on solid black and unlock --- .envrc | 1 + .gitignore | 2 + Cargo.lock | 628 +++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 15 ++ flake.lock | 138 +++++++++++ flake.nix | 31 +++ src/main.rs | 317 +++++++++++++++++++++++++ toolchain.toml | 4 + 8 files changed, 1136 insertions(+) create mode 100644 .envrc create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 src/main.rs create mode 100644 toolchain.toml diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d0160f2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/target +/.direnv/ diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..0e0e516 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,628 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "backtrace" +version = "0.3.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "bitflags" +version = "2.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c8214115b7bf84099f1309324e63141d4c5d7cc26862f97a0a857dbefe165bd" + +[[package]] +name = "cc" +version = "1.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be714c154be609ec7f5dad223a33bf1482fff90472de28f7362806e6d4832b8c" +dependencies = [ + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "color-eyre" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55146f5e46f237f7423d74111267d4597b59b0dad0ffaf7303bce9945d843ad5" +dependencies = [ + "backtrace", + "color-spantrace", + "eyre", + "indenter", + "once_cell", + "owo-colors", + "tracing-error", +] + +[[package]] +name = "color-spantrace" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd6be1b2a7e382e2b98b43b2adcca6bb0e465af0bdd38123873ae61eb17a72c2" +dependencies = [ + "once_cell", + "owo-colors", + "tracing-core", + "tracing-error", +] + +[[package]] +name = "cursor-icon" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96a6ac251f4a2aca6b3f91340350eab87ae57c3f127ffeb585e92bd336717991" + +[[package]] +name = "dbus" +version = "0.9.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bb21987b9fb1613058ba3843121dd18b163b254d8a6e797e144cbac14d96d1b" +dependencies = [ + "libc", + "libdbus-sys", + "winapi", +] + +[[package]] +name = "downcast-rs" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75b325c5dbd37f80359721ad39aca5a29fb04c89279657cffdda8736d0c0b9d2" + +[[package]] +name = "errno" +version = "0.3.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33d852cb9b869c2a9b3df2f71a3074817f01e1844f839a144f5fcef059a4eb5d" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] +name = "eyre" +version = "0.6.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cd915d99f24784cdc19fd37ef22b97e3ff0ae756c7e492e9fbfe897d61e2aec" +dependencies = [ + "indenter", + "once_cell", +] + +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + +[[package]] +name = "indenter" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683" + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + +[[package]] +name = "libc" +version = "0.2.171" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c19937216e9d3aa9956d9bb8dfc0b0c8beb6058fc4f7a4dc4d850edf86a237d6" + +[[package]] +name = "libdbus-sys" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06085512b750d640299b79be4bad3d2fa90a9c00b1fd9e1b46364f66f0485c72" +dependencies = [ + "pkg-config", +] + +[[package]] +name = "linux-raw-sys" +version = "0.4.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d26c52dbd32dccf2d10cac7725f8eae5296885fb5703b261f7d0a0739ec807ab" + +[[package]] +name = "log" +version = "0.4.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30bde2b3dc3671ae49d8e2e9f044c7c005836e7a023ee57cffa25ab82764bb9e" + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "memmap2" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd3f7eed9d3848f8b98834af67102b720745c4ec028fcd0aa0239277e7de374f" +dependencies = [ + "libc", +] + +[[package]] +name = "miniz_oxide" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" +dependencies = [ + "adler", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.21.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d75b0bedcc4fe52caa0e03d9f1151a323e4aa5e2d78ba3580400cd3c9e2bc4bc" + +[[package]] +name = "oneshot" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4ce411919553d3f9fa53a0880544cda985a112117a0444d5ff1e870a893d6ea" + +[[package]] +name = "owo-colors" +version = "3.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f" + +[[package]] +name = "pin-project-lite" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" + +[[package]] +name = "pkg-config" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" + +[[package]] +name = "proc-macro2" +version = "1.0.94" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a31971752e70b8b2686d7e46ec17fb38dad4051d94024c88df49b667caea9c84" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quick-xml" +version = "0.37.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "165859e9e55f79d67b96c5d96f4e88b6f2695a1972849c15a6a3f5c59fc2c003" +dependencies = [ + "memchr", +] + +[[package]] +name = "quote" +version = "1.0.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "riverigilo" +version = "0.1.0" +dependencies = [ + "color-eyre", + "dbus", + "eyre", + "oneshot", + "smithay-client-toolkit", + "wayland-client", + "wayland-protocols", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "rustix" +version = "0.38.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fdb5bc1ae2baa591800df16c9ca78619bf65c0488b41b96ccec5d11220d8c154" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys", +] + +[[package]] +name = "sharded-slab" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "smallvec" +version = "1.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fcf8323ef1faaee30a44a340193b1ac6814fd9b7b4e88e9d4519a3e4abe1cfd" + +[[package]] +name = "smithay-client-toolkit" +version = "0.19.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3457dea1f0eb631b4034d61d4d8c32074caa6cd1ab2d59f2327bd8461e2c0016" +dependencies = [ + "bitflags", + "cursor-icon", + "libc", + "log", + "memmap2", + "rustix", + "thiserror", + "wayland-backend", + "wayland-client", + "wayland-csd-frame", + "wayland-cursor", + "wayland-protocols", + "wayland-protocols-wlr", + "wayland-scanner", + "xkeysym", +] + +[[package]] +name = "syn" +version = "2.0.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b09a44accad81e1ba1cd74a32461ba89dee89095ba17b32f5d03683b1b1fc2a0" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "thiserror" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "thread_local" +version = "1.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b9ef9bad013ada3808854ceac7b46812a6465ba368859a37e2100283d2d719c" +dependencies = [ + "cfg-if", + "once_cell", +] + +[[package]] +name = "tracing" +version = "0.1.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0" +dependencies = [ + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e672c95779cf947c5311f83787af4fa8fffd12fb27e4993211a84bdfd9610f9c" +dependencies = [ + "once_cell", + "valuable", +] + +[[package]] +name = "tracing-error" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b1581020d7a273442f5b45074a6a57d5757ad0a47dac0e9f0bd57b81936f3db" +dependencies = [ + "tracing", + "tracing-subscriber", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8189decb5ac0fa7bc8b96b7cb9b2701d60d48805aca84a238004d665fcc4008" +dependencies = [ + "sharded-slab", + "thread_local", + "tracing-core", +] + +[[package]] +name = "unicode-ident" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" + +[[package]] +name = "valuable" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65" + +[[package]] +name = "wayland-backend" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7208998eaa3870dad37ec8836979581506e0c5c64c20c9e79e9d2a10d6f47bf" +dependencies = [ + "cc", + "downcast-rs", + "rustix", + "smallvec", + "wayland-sys", +] + +[[package]] +name = "wayland-client" +version = "0.31.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2120de3d33638aaef5b9f4472bff75f07c56379cf76ea320bd3a3d65ecaf73f" +dependencies = [ + "bitflags", + "rustix", + "wayland-backend", + "wayland-scanner", +] + +[[package]] +name = "wayland-csd-frame" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "625c5029dbd43d25e6aa9615e88b829a5cad13b2819c4ae129fdbb7c31ab4c7e" +dependencies = [ + "bitflags", + "cursor-icon", + "wayland-backend", +] + +[[package]] +name = "wayland-cursor" +version = "0.31.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a93029cbb6650748881a00e4922b076092a6a08c11e7fbdb923f064b23968c5d" +dependencies = [ + "rustix", + "wayland-client", + "xcursor", +] + +[[package]] +name = "wayland-protocols" +version = "0.32.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0781cf46869b37e36928f7b432273c0995aa8aed9552c556fb18754420541efc" +dependencies = [ + "bitflags", + "wayland-backend", + "wayland-client", + "wayland-scanner", +] + +[[package]] +name = "wayland-protocols-wlr" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "248a02e6f595aad796561fa82d25601bd2c8c3b145b1c7453fc8f94c1a58f8b2" +dependencies = [ + "bitflags", + "wayland-backend", + "wayland-client", + "wayland-protocols", + "wayland-scanner", +] + +[[package]] +name = "wayland-scanner" +version = "0.31.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "896fdafd5d28145fce7958917d69f2fd44469b1d4e861cb5961bcbeebc6d1484" +dependencies = [ + "proc-macro2", + "quick-xml", + "quote", +] + +[[package]] +name = "wayland-sys" +version = "0.31.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbcebb399c77d5aa9fa5db874806ee7b4eba4e73650948e8f93963f128896615" +dependencies = [ + "pkg-config", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "xcursor" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ef33da6b1660b4ddbfb3aef0ade110c8b8a781a3b6382fa5f2b5b040fd55f61" + +[[package]] +name = "xkeysym" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9cc00251562a284751c9973bace760d86c0276c471b4be569fe6b068ee97a56" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..4922ca1 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "riverigilo" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +color-eyre = "0.6.3" +dbus = "0.9.7" +eyre = "0.6.12" +oneshot = "0.1.11" +smithay-client-toolkit = { version = "0.19.2", default-features = false } +wayland-client = "0.31.8" +wayland-protocols = { version = "0.32.6", features = ["client", "staging"] } diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..26c23c6 --- /dev/null +++ b/flake.lock @@ -0,0 +1,138 @@ +{ + "nodes": { + "crane": { + "inputs": { + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1714864355, + "narHash": "sha256-uXNW6bapWFfkYIkK1EagydSrFMqycOYEDSq75GmUpjk=", + "owner": "ipetkov", + "repo": "crane", + "rev": "442a7a6152f49b907e73206dc8e1f46a61e8e873", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "repo": "crane", + "type": "github" + } + }, + "crane-flake-parts": { + "inputs": { + "crane": "crane", + "rust-overlay": [ + "rust-overlay" + ] + }, + "locked": { + "lastModified": 1739030108, + "narHash": "sha256-kwFvwlI5dSl6TFQb54oJLP+qllPGKh2wAZun+gKnFOE=", + "owner": "bluepython508", + "repo": "crane-flake-parts", + "rev": "1e60976aa3cc1d474a62d8a8b63c7849ffdc9016", + "type": "github" + }, + "original": { + "owner": "bluepython508", + "repo": "crane-flake-parts", + "type": "github" + } + }, + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1741352980, + "narHash": "sha256-+u2UunDA4Cl5Fci3m7S643HzKmIDAe+fiXrLqYsR2fs=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "f4330d22f1c5d2ba72d3d22df5597d123fdb60a9", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1714656196, + "narHash": "sha256-kjQkA98lMcsom6Gbhw8SYzmwrSo+2nruiTcTZp5jK7o=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "94035b482d181af0a0f8f77823a790b256b7c3cc", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-lib": { + "locked": { + "lastModified": 1740877520, + "narHash": "sha256-oiwv/ZK/2FhGxrCkQkB83i7GnWXPPLzoqFHpDD3uYpk=", + "owner": "nix-community", + "repo": "nixpkgs.lib", + "rev": "147dee35aab2193b174e4c0868bd80ead5ce755c", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixpkgs.lib", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1742288794, + "narHash": "sha256-Txwa5uO+qpQXrNG4eumPSD+hHzzYi/CdaM80M9XRLCo=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "b6eaf97c6960d97350c584de1b6dcff03c9daf42", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "crane-flake-parts": "crane-flake-parts", + "flake-parts": "flake-parts", + "nixpkgs": "nixpkgs_2", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1742351546, + "narHash": "sha256-GPubFcOXyi8TVm1xpltHYPcfGr+iO+if2u/EtzFVnHQ=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "b0a7450168c62a46f87d204280e6d9d1c0292671", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..2126aac --- /dev/null +++ b/flake.nix @@ -0,0 +1,31 @@ +{ + description = "Description for the project"; + + inputs = { + flake-parts.url = "github:hercules-ci/flake-parts"; + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + rust-overlay = { + url = "github:oxalica/rust-overlay"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + crane-flake-parts = { + url = "github:bluepython508/crane-flake-parts"; + inputs.rust-overlay.follows = "rust-overlay"; + }; + }; + + outputs = inputs@{ flake-parts, crane-flake-parts, ... }: + flake-parts.lib.mkFlake { inherit inputs; } { + imports = [ + crane-flake-parts.flakeModules.default + ]; + systems = [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin" ]; + crane.source = ./.; + perSystem = { pkgs, lib, ... }: { + crane.craneArgs = { + nativeBuildInputs = [pkgs.pkg-config]; + buildInputs = with pkgs; [ dbus ]; + }; + }; + }; +} diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..6b1d2f7 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,317 @@ +#![allow(unused_variables, dead_code)] + +use std::{collections::HashMap, time::{Duration, Instant}}; + +use eyre::Result; +use smithay_client_toolkit::{delegate_shm, shm::{slot::SlotPool, Shm, ShmHandler}}; +use wayland_client::{ + backend::ObjectId, + globals::{registry_queue_init, GlobalList, GlobalListContents}, + protocol::{wl_callback, wl_compositor, wl_output, wl_registry, wl_shm::Format, wl_surface}, + Connection, Dispatch, Proxy, QueueHandle, +}; +use wayland_protocols::ext::session_lock::v1::client::{ + ext_session_lock_manager_v1, ext_session_lock_surface_v1, ext_session_lock_v1, +}; + +struct LockState { + locked: bool, + sender: Option>, + lock: ext_session_lock_v1::ExtSessionLockV1, + surfaces: HashMap< + ObjectId, + ( + ext_session_lock_surface_v1::ExtSessionLockSurfaceV1, + wl_surface::WlSurface, + ), + >, +} + +impl LockState { + fn add_output( + &mut self, + queue: &QueueHandle, + compositor: &wl_compositor::WlCompositor, + output: &wl_output::WlOutput, + ) { + let surface = compositor.create_surface(queue, ()); + let lock_surface = self.lock.get_lock_surface(&surface, output, queue, surface.clone()); + self.surfaces.insert(output.id(), (lock_surface, surface)); + } + + fn remove_output(&mut self, output: &wl_output::WlOutput) { + if let Some((lock_surface, surface)) = self.surfaces.remove(&output.id()) { + lock_surface.destroy(); + surface.destroy(); + } + } + + fn locked(&mut self) { + self.locked = true; + let Some(sender) = self.sender.take() else { return }; + let _ = sender.send(true); + } + fn finished(&mut self) { + for (lock_surface, surface) in self.surfaces.values() { + lock_surface.destroy(); + surface.destroy(); + } + + let Some(sender) = self.sender.take() else { return }; + let _ = sender.send(false); + } +} + +struct State { + exit: bool, + lock_manager: ext_session_lock_manager_v1::ExtSessionLockManagerV1, + compositor: wl_compositor::WlCompositor, + shm: Shm, + pool: SlotPool, + outputs: Vec, + + lock: Option, +} + +impl State { + fn new(queue: &QueueHandle, globals: GlobalList) -> Result { + let shm = Shm::bind(&globals, queue)?; + Ok(Self { + exit: false, + lock_manager: globals.bind(queue, 1..=1, ())?, + compositor: globals.bind(queue, 6..=6, ())?, + + outputs: globals.contents().with_list(|lst| { + let registry = globals.registry(); + lst.iter() + .filter(|global| global.interface == wl_output::WlOutput::interface().name) + .map(|global| registry.bind(global.name, 4, queue, global.name)) + .collect() + }), + lock: None, + pool: SlotPool::new(4096, &shm)?, + shm, + }) + } + + fn lock(&mut self, queue: &QueueHandle) -> Result> { + let (sender, receiver) = oneshot::channel(); + let lock = self.lock_manager.lock(queue, ()); + + let mut lock = LockState { + lock, + surfaces: Default::default(), + locked: false, + sender: Some(sender), + }; + + for output in &self.outputs { + lock.add_output(queue, &self.compositor, output); + } + + self.lock = Some(lock); + Ok(receiver) + } + + fn unlock(&mut self) -> Result<()> { + let Some(lock) = &mut self.lock else { return Ok(()) }; + eprintln!("Unlocking"); + lock.lock.unlock_and_destroy(); + lock.finished(); + self.lock = None; + Ok(()) + } +} + +impl Dispatch for State { + fn event( + state: &mut Self, + proxy: &wl_registry::WlRegistry, + event: ::Event, + data: &GlobalListContents, + conn: &Connection, + qhandle: &wayland_client::QueueHandle, + ) { + match event { + wl_registry::Event::Global { + name, + interface, + version, + } => { + if interface == wl_output::WlOutput::interface().name { + let output = proxy.bind(name, 4, qhandle, name); + if let Some(lock) = &mut state.lock { + lock.add_output(qhandle, &state.compositor, &output); + } + state.outputs.push(output); + } + } + wl_registry::Event::GlobalRemove { name } => state.outputs.retain_mut(|output| { + if output.data::().unwrap() == &name { + if let Some(lock) = &mut state.lock { + lock.remove_output(output); + } + output.release(); + true + } else { + false + } + }), + _ => unreachable!(), + } + } +} + +impl Dispatch for State { + fn event( + _state: &mut Self, + _proxy: &ext_session_lock_manager_v1::ExtSessionLockManagerV1, + _event: ::Event, + _data: &(), + _conn: &Connection, + _qhandle: &QueueHandle, + ) { + unreachable!() + } +} + +impl Dispatch for State { + fn event( + state: &mut Self, + proxy: &wl_compositor::WlCompositor, + event: ::Event, + data: &(), + conn: &Connection, + qhandle: &QueueHandle, + ) { + unreachable!() + } +} + +impl Dispatch for State { + fn event( + _state: &mut Self, + _proxy: &wl_output::WlOutput, + _event: ::Event, + _data: &u32, + _conn: &Connection, + _qhandle: &QueueHandle, + ) { + } +} + +impl Dispatch for State { + fn event( + state: &mut Self, + proxy: &ext_session_lock_v1::ExtSessionLockV1, + event: ::Event, + data: &(), + conn: &Connection, + qhandle: &QueueHandle, + ) { + match event { + ext_session_lock_v1::Event::Locked => { + if let Some(lock) = &mut state.lock { + lock.locked(); + } + } + ext_session_lock_v1::Event::Finished => { + if let Some(lock) = &mut state.lock { + if lock.locked { + // Should this really use _unlock_? + // The protocol demands it, but it seems wrong + proxy.unlock_and_destroy(); + } else { + proxy.destroy(); + } + lock.finished(); + } + state.lock = None; + } + _ => unreachable!(), + }; + } +} + +impl Dispatch for State { + fn event( + state: &mut Self, + proxy: &ext_session_lock_surface_v1::ExtSessionLockSurfaceV1, + event: ::Event, + data: &wl_surface::WlSurface, + conn: &Connection, + qhandle: &QueueHandle, + ) { + match event { + ext_session_lock_surface_v1::Event::Configure { serial, width, height } => { + let (buffer, slice) = state.pool.create_buffer(width as i32, height as i32, width as i32 * 4, Format::Xrgb8888).unwrap(); + slice.fill(0); + data.attach(Some(buffer.wl_buffer()), 0, 0); + proxy.ack_configure(serial); + data.commit(); + }, + _ => unreachable!(), + } + } +} + +impl Dispatch for State { + fn event( + state: &mut Self, + proxy: &wl_surface::WlSurface, + event: ::Event, + data: &(), + conn: &Connection, + qhandle: &QueueHandle, + ) { + } +} + +delegate_shm!(State); +impl ShmHandler for State { + fn shm_state(&mut self) -> &mut Shm { + &mut self.shm + } +} + +impl Dispatch for State { + fn event( + state: &mut Self, + proxy: &wl_callback::WlCallback, + event: ::Event, + data: &(), + conn: &Connection, + qhandle: &QueueHandle, + ) { + conn.display().sync(qhandle, ()); + } +} + +fn main() -> Result<()> { + color_eyre::install()?; + let wl_sock = Connection::connect_to_env()?; + let (globals, mut event_queue) = registry_queue_init::(&wl_sock)?; + + let mut state = State::new(&event_queue.handle(), globals)?; + + let recv = state.lock(&event_queue.handle())?; + let mut locked = None; + + wl_sock.display().sync(&event_queue.handle(), ()); + + while !state.exit { + eprintln!("Tick"); + event_queue.blocking_dispatch(&mut state)?; + if let Ok(v) = recv.try_recv() { + eprintln!("Locked"); + if !v { break; } + locked = Some(Instant::now()); + } + if locked.is_some_and(|l| l.elapsed() > Duration::from_secs(10)) { + state.unlock()?; + locked = None; + } + } + + Ok(()) +} diff --git a/toolchain.toml b/toolchain.toml new file mode 100644 index 0000000..488b115 --- /dev/null +++ b/toolchain.toml @@ -0,0 +1,4 @@ +[toolchain] +channel = "stable" +components = [ "rustfmt", "rust-analyzer", "rust-src", "clippy" ] +profile = "default" \ No newline at end of file