commit 322f3f5bbe0aa4b623eedd96abb50610c91d8e7d Author: reidlab Date: Thu Jan 16 18:31:05 2025 -0800 init diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..263e3ee --- /dev/null +++ b/.editorconfig @@ -0,0 +1,11 @@ +root = true + +[*] +end_of_line = lf +indent_style = space +indent_size = 4 +insert_final_newline = true +trim_trailing_whitespace = true + +[*.nix] +indent_size = 2 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d787b70 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/target +/result diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..83f9a48 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,882 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + +[[package]] +name = "anyhow" +version = "1.0.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34ac096ce696dc2fcabef30516bb13c0a68a11d30131d3df6f04711467681b04" + +[[package]] +name = "autocfg" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" + +[[package]] +name = "bitflags" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1be3f42a67d6d345ecd59f675f3f012d6974981560836e938c22b424b85ce1be" + +[[package]] +name = "bytemuck" +version = "1.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef657dfab802224e671f5818e9a4935f9b1957ed18e58292690cc39e7a4092a3" +dependencies = [ + "bytemuck_derive", +] + +[[package]] +name = "bytemuck_derive" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fa76293b4f7bb636ab88fd78228235b5248b4d05cc589aed610f954af5d7c7a" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "byteorder-lite" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f1fe948ff07f4bd06c30984e69f5b4899c516a3ef74f34df92a2df2ab535495" + +[[package]] +name = "calloop" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b99da2f8558ca23c71f4fd15dc57c906239752dd27ff3c00a1d56b685b7cbfec" +dependencies = [ + "bitflags", + "log", + "polling", + "rustix", + "slab", + "thiserror", +] + +[[package]] +name = "calloop-wayland-source" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95a66a987056935f7efce4ab5668920b5d0dac4a7c99991a67395f13702ddd20" +dependencies = [ + "calloop", + "rustix", + "wayland-backend", + "wayland-client", +] + +[[package]] +name = "cc" +version = "1.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8293772165d9345bdaaa39b45b2109591e63fe5e6fbc23c6ff930a048aa310b" +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_quant" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" + +[[package]] +name = "concurrent-queue" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ca0197aee26d1ae37445ee532fefce43251d24cc7c166799f4d46817f1d3973" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" + +[[package]] +name = "cursor-icon" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96a6ac251f4a2aca6b3f91340350eab87ae57c3f127ffeb585e92bd336717991" + +[[package]] +name = "dlib" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "330c60081dcc4c72131f8eb70510f1ac07223e5d4163db481a04a0befcffa412" +dependencies = [ + "libloading", +] + +[[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 = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "gif" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fb2d69b19215e18bb912fa30f7ce15846e301408695e44e0ef719f1da9e19f2" +dependencies = [ + "color_quant", + "weezl", +] + +[[package]] +name = "hermit-abi" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbf6a919d6cf397374f7dfeeea91d974c7c0a7221d0d0f4f20d859d329e53fcc" + +[[package]] +name = "image" +version = "0.25.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd6f44aed642f18953a158afeb30206f4d50da59fbc66ecb53c66488de73563b" +dependencies = [ + "bytemuck", + "byteorder-lite", + "color_quant", + "gif", + "num-traits", +] + +[[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.169" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a" + +[[package]] +name = "libloading" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34" +dependencies = [ + "cfg-if", + "windows-targets", +] + +[[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.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04cbf5b083de1c7e0222a7a51dbfdba1cbe1c6ab0b15e29fff3f6c077fd9cd9f" + +[[package]] +name = "matchers" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" +dependencies = [ + "regex-automata 0.1.10", +] + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "memmap2" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43a5a03cefb0d953ec0be133036f14e109412fa594edc2f77227249db66cc3ed" +dependencies = [ + "libc", +] + +[[package]] +name = "memmap2" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd3f7eed9d3848f8b98834af67102b720745c4ec028fcd0aa0239277e7de374f" +dependencies = [ + "libc", +] + +[[package]] +name = "nu-ansi-term" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" +dependencies = [ + "overload", + "winapi", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "once_cell" +version = "1.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" + +[[package]] +name = "oneko-rs" +version = "0.1.0" +dependencies = [ + "anyhow", + "image", + "rand", + "smithay-client-toolkit", + "tracing", + "tracing-subscriber", +] + +[[package]] +name = "overload" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" + +[[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.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" + +[[package]] +name = "polling" +version = "3.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a604568c3202727d1507653cb121dbd627a58684eb09a820fd746bee38b4442f" +dependencies = [ + "cfg-if", + "concurrent-queue", + "hermit-abi", + "pin-project-lite", + "rustix", + "tracing", + "windows-sys", +] + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "proc-macro2" +version = "1.0.93" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60946a68e5f9d28b0dc1c21bb8a97ee7d018a8b322fa57838ba31cc878e22d99" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quick-xml" +version = "0.36.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7649a7b4df05aed9ea7ec6f628c67c9953a43869b8bc50929569b2999d443fe" +dependencies = [ + "memchr", +] + +[[package]] +name = "quote" +version = "1.0.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "regex" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata 0.4.9", + "regex-syntax 0.8.5", +] + +[[package]] +name = "regex-automata" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" +dependencies = [ + "regex-syntax 0.6.29", +] + +[[package]] +name = "regex-automata" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax 0.8.5", +] + +[[package]] +name = "regex-syntax" +version = "0.6.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" + +[[package]] +name = "regex-syntax" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" + +[[package]] +name = "rustix" +version = "0.38.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a78891ee6bf2340288408954ac787aa063d8e8817e9f53abb37c695c6d834ef6" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys", +] + +[[package]] +name = "scoped-tls" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" + +[[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 = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "smithay-client-toolkit" +version = "0.19.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3457dea1f0eb631b4034d61d4d8c32074caa6cd1ab2d59f2327bd8461e2c0016" +dependencies = [ + "bitflags", + "bytemuck", + "calloop", + "calloop-wayland-source", + "cursor-icon", + "libc", + "log", + "memmap2 0.9.5", + "pkg-config", + "rustix", + "thiserror", + "wayland-backend", + "wayland-client", + "wayland-csd-frame", + "wayland-cursor", + "wayland-protocols", + "wayland-protocols-wlr", + "wayland-scanner", + "xkbcommon", + "xkeysym", +] + +[[package]] +name = "syn" +version = "2.0.96" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5d0adab1ae378d7f53bdebc67a39f1f151407ef230f0ce2883572f5d8985c80" +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-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "395ae124c09f9e6918a2310af6038fba074bcf474ac352496d5910dd59a2226d" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[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-log" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" +dependencies = [ + "log", + "once_cell", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8189decb5ac0fa7bc8b96b7cb9b2701d60d48805aca84a238004d665fcc4008" +dependencies = [ + "matchers", + "nu-ansi-term", + "once_cell", + "regex", + "sharded-slab", + "smallvec", + "thread_local", + "tracing", + "tracing-core", + "tracing-log", +] + +[[package]] +name = "unicode-ident" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83" + +[[package]] +name = "valuable" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wayland-backend" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "056535ced7a150d45159d3a8dc30f91a2e2d588ca0b23f70e56033622b8016f6" +dependencies = [ + "cc", + "downcast-rs", + "rustix", + "scoped-tls", + "smallvec", + "wayland-sys", +] + +[[package]] +name = "wayland-client" +version = "0.31.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b66249d3fc69f76fd74c82cc319300faa554e9d865dab1f7cd66cc20db10b280" +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.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32b08bc3aafdb0035e7fe0fdf17ba0c09c268732707dca4ae098f60cb28c9e4c" +dependencies = [ + "rustix", + "wayland-client", + "xcursor", +] + +[[package]] +name = "wayland-protocols" +version = "0.32.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cd0ade57c4e6e9a8952741325c30bf82f4246885dca8bf561898b86d0c1f58e" +dependencies = [ + "bitflags", + "wayland-backend", + "wayland-client", + "wayland-scanner", +] + +[[package]] +name = "wayland-protocols-wlr" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "782e12f6cd923c3c316130d56205ebab53f55d6666b7faddfad36cecaeeb4022" +dependencies = [ + "bitflags", + "wayland-backend", + "wayland-client", + "wayland-protocols", + "wayland-scanner", +] + +[[package]] +name = "wayland-scanner" +version = "0.31.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "597f2001b2e5fc1121e3d5b9791d3e78f05ba6bfa4641053846248e3a13661c3" +dependencies = [ + "proc-macro2", + "quick-xml", + "quote", +] + +[[package]] +name = "wayland-sys" +version = "0.31.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "efa8ac0d8e8ed3e3b5c9fc92c7881406a268e11555abe36493efabe649a29e09" +dependencies = [ + "dlib", + "log", + "pkg-config", +] + +[[package]] +name = "weezl" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53a85b86a771b1c87058196170769dd264f66c0782acf1ae6cc51bfd64b39082" + +[[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 = "xkbcommon" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13867d259930edc7091a6c41b4ce6eee464328c6ff9659b7e4c668ca20d4c91e" +dependencies = [ + "libc", + "memmap2 0.8.0", + "xkeysym", +] + +[[package]] +name = "xkeysym" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9cc00251562a284751c9973bace760d86c0276c471b4be569fe6b068ee97a56" +dependencies = [ + "bytemuck", +] + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..47db496 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "oneko-rs" +description = "oneko.js, but in rust" +authors = [ "reidlab " ] +version = "0.1.0" +edition = "2024" + +[dependencies] +anyhow = "1.0.95" +image = { version = "0.25.5", default-features = false, features = ["gif"] } +rand = "0.8.5" +smithay-client-toolkit = "0.19.2" +tracing = "0.1.41" +tracing-subscriber = { version = "0.3.19", features = ["env-filter"] } diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..f288702 --- /dev/null +++ b/LICENSE @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/README.md b/README.md new file mode 100644 index 0000000..c9c4bb4 --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +# oneko-rs + +cat follow mouse real! based on [oneko.js](github.com/adryd325/oneko.js/) + +## limitations + +due to the way wayland functions, your mouse clicks and scrolls will Be Eaten while oneko is running, this is a limitation (security feature: ex. an input grabbing layer (which is what this is!) could feed all inputs to a bad actor) of the wayland protocol—if you want to be able to use your mouse freely, you will have to kill the process + +## screenshots + +![screenshot](./docs/screenshot.png) diff --git a/assets/oneko.gif b/assets/oneko.gif new file mode 100644 index 0000000..a009c2c Binary files /dev/null and b/assets/oneko.gif differ diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..cac1cf9 --- /dev/null +++ b/flake.lock @@ -0,0 +1,96 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1736798957, + "narHash": "sha256-qwpCtZhSsSNQtK4xYGzMiyEDhkNzOCz/Vfu4oL2ETsQ=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "9abb87b552b7f55ac8916b6fc9e5cb486656a2f3", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1736320768, + "narHash": "sha256-nIYdTAiKIGnFNugbomgBJR+Xv5F1ZQU+HfaBqJKroC0=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "4bc9c909d9ac828a039f288cf872d16d38185db8", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1736735482, + "narHash": "sha256-QOA4jCDyyUM9Y2Vba+HSZ/5LdtCMGaTE/7NkkUzBr50=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "cf960a1938ee91200fe0d2f7b2582fde2429d562", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..573b85d --- /dev/null +++ b/flake.nix @@ -0,0 +1,59 @@ +{ + description = "oneko"; + + inputs = { + flake-utils.url = "github:numtide/flake-utils"; + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + rust-overlay.url = "github:oxalica/rust-overlay"; + }; + + outputs = { self, nixpkgs, flake-utils, rust-overlay, }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { + inherit system; + overlays = [rust-overlay.overlays.default]; + }; + package = (builtins.fromTOML (builtins.readFile ./Cargo.toml)).package; + toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; + rustPlatform = pkgs.makeRustPlatform { + cargo = toolchain; + rustc = toolchain; + }; + in { + packages = flake-utils.lib.flattenTree rec { + default = oneko; + oneko = rustPlatform.buildRustPackage { + pname = package.name; + inherit (package) version; + + # uncomment this and let the build fail, then get the current hash + # very scuffed but endorsed! + #cargoHash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="; + cargoHash = "sha256-aBvcI4iAlIGi60+tN/fes6/2MeNFwj21W7rV3pV88EY="; + + nativeBuildInputs = with pkgs; [ pkg-config ]; + + buildInputs = with pkgs; [ libxkbcommon ]; + + src = ./.; + + meta.mainProgram = package.name; + }; + }; + + devShells.default = pkgs.mkShell { + nativeBuildInputs = with pkgs; [ pkg-config ]; + + buildInputs = with pkgs; [ libxkbcommon ]; + + packages = with pkgs; [ + toolchain + rust-analyzer-unwrapped + ]; + + RUST_SRC_PATH = "${toolchain}/lib/rustlib/src/rust/library"; + }; + } + ); +} diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..fc0b1fe --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,4 @@ +[toolchain] +channel = "nightly" +components = [ "rust-src" ] +profile = "minimal" diff --git a/src/assets.rs b/src/assets.rs new file mode 100644 index 0000000..aef34d1 --- /dev/null +++ b/src/assets.rs @@ -0,0 +1,55 @@ +use image::{ + DynamicImage, + GenericImageView, + RgbaImage, + SubImage +}; + +/// a frame in a spritesheet +/// x, y are the coordinates of the frame in the spritesheet, 1 per frame +#[derive(Clone, Copy)] +pub struct Frame(pub u32, pub u32); + +pub struct Animation { + pub frames: &'static [Frame], + pub ticks_per_frame: u32 +} + +pub struct Spritesheet { + image: RgbaImage, + sprite_size: (u32, u32) +} + +// this reminded me of the plist spritesheet format from RobTop's Geometry Dash +// oh RobTop how i miss you +impl Spritesheet { + pub fn new(image: DynamicImage, sprite_size: (u32, u32)) -> Self { + Spritesheet { + image: image.into(), + sprite_size: sprite_size + } + } + + pub fn get_frame( + &self, + frame: Frame + ) -> SubImage<&RgbaImage> { + let Frame(x, y) = frame; + let (width, height) = self.sprite_size; + let (x, y) = (x * width, y * height); + + return self.image.view(x, y, width, height) + } + + pub fn get_animation( + &self, + animation: Animation, + animation_tick: u32 + ) -> SubImage<&RgbaImage> { + self.get_frame(animation.frames[animation_tick as usize % animation.frames.len()]) + } + + pub fn get_size(&self) -> (u32, u32) { + self.sprite_size + } +} diff --git a/src/layer/compositor.rs b/src/layer/compositor.rs new file mode 100644 index 0000000..5b43636 --- /dev/null +++ b/src/layer/compositor.rs @@ -0,0 +1,56 @@ +use super::Layer; +use smithay_client_toolkit::{ + compositor::CompositorHandler, + reexports::client::{ + Connection, + protocol::{wl_output, wl_surface}, + QueueHandle, + } +}; +use tracing::trace; + +impl CompositorHandler for Layer { + fn scale_factor_changed( + &mut self, + _conn: &Connection, + _qh: &QueueHandle, + _surface: &wl_surface::WlSurface, + _new_factor: i32, + ) { } + + fn transform_changed( + &mut self, + _conn: &Connection, + _qh: &QueueHandle, + _surface: &wl_surface::WlSurface, + _new_transform: wl_output::Transform, + ) { } + + fn frame( + &mut self, + _conn: &Connection, + _qh: &QueueHandle, + _surface: &wl_surface::WlSurface, + _time: u32, + ) { + trace!("frame requested"); + + self.paint(); + } + + fn surface_enter( + &mut self, + _conn: &Connection, + _qh: &QueueHandle, + _surface: &wl_surface::WlSurface, + _output: &wl_output::WlOutput, + ) { } + + fn surface_leave( + &mut self, + _conn: &Connection, + _qh: &QueueHandle, + _surface: &wl_surface::WlSurface, + _output: &wl_output::WlOutput, + ) { } +} diff --git a/src/layer/layer_shell.rs b/src/layer/layer_shell.rs new file mode 100644 index 0000000..c4670cb --- /dev/null +++ b/src/layer/layer_shell.rs @@ -0,0 +1,48 @@ +use super::Layer; +use smithay_client_toolkit::{ + reexports::client::{ + Connection, + QueueHandle + }, + shell::wlr_layer::{ + KeyboardInteractivity, + LayerShellHandler, + LayerSurface, + LayerSurfaceConfigure + } +}; + +impl LayerShellHandler for Layer { + fn closed( + &mut self, + _conn: &Connection, + _qh: &QueueHandle, + _layer: &LayerSurface, + ) { + self.exit = true; + } + + fn configure( + &mut self, + _conn: &Connection, + _qh: &QueueHandle, + layer: &LayerSurface, + configure: LayerSurfaceConfigure, + _serial: u32, + ) { + let (w, h) = configure.new_size; + + tracing::info!("configuring new size: {:?}", (w, h)); + + self.width = w; + self.height = h; + + layer.set_keyboard_interactivity(KeyboardInteractivity::None); + + if !self.configured_surface { + self.configured_surface = true; + + self.paint(); + } + } +} diff --git a/src/layer/mod.rs b/src/layer/mod.rs new file mode 100644 index 0000000..f238c3a --- /dev/null +++ b/src/layer/mod.rs @@ -0,0 +1,233 @@ +mod compositor; +mod layer_shell; +mod output; +mod pointer; +mod registry; +mod seat; +mod shm; + +use crate::oneko::Oneko; +use anyhow::{Result, Context}; +use smithay_client_toolkit::{ + compositor::CompositorState, + delegate_compositor, delegate_layer, delegate_output, delegate_pointer, delegate_registry, delegate_seat, delegate_shm, + output::OutputState, + reexports::{ + calloop::EventLoop, + calloop_wayland_source::WaylandSource, + client::{ + Connection, + globals::registry_queue_init, + protocol::{ + wl_pointer::WlPointer, + wl_shm::Format, + wl_surface::WlSurface, + }, + QueueHandle + } + }, + registry::RegistryState, + seat::SeatState, + shell::{ + wlr_layer::{ + Anchor, + Layer as LayerDepth, + LayerShell, + LayerSurface + }, + WaylandSurface + }, + shm::{ + slot::{ + Buffer, + SlotPool + }, + Shm + } +}; +use tracing::trace; + +pub struct Layer { + oneko: Oneko, + + registry_state: RegistryState, + seat_state: SeatState, + output_state: OutputState, + + buffer: Option, + pool: SlotPool, + shm: Shm, + layer_surface: LayerSurface, + surface: WlSurface, + configured_surface: bool, + width: u32, + height: u32, + + pointer: Option, + pointer_position: Option<(f64, f64)>, + + // used to capture the event loop outside of the struct + // bad idea(?) see `src/layer/compositor.rs` and `src/layer/layer_shell.rs` qh not being used for `request_draw` + // maybe it's fine, but for now: TODO + qh: QueueHandle, + exit: bool, + + error: Option +} + +impl Layer { + pub fn new() -> Result<(Self, EventLoop<'static, Self>)> { + let connection = Connection::connect_to_env()?; + + let (globals, event_queue) = registry_queue_init(&connection)?; + let qh = event_queue.handle(); + let event_loop: EventLoop = EventLoop::try_new() + .context("failed to initialize the event loop")?; + + let wayland_source = WaylandSource::new(connection.clone(), event_queue); + wayland_source + .insert(event_loop.handle()) + .context("failed to insert wayland into the event loop")?; + + let mut oneko = Oneko::new(); + oneko + .insert(event_loop.handle()) + // TODO: use ? instead of expect + // not possible right now because of thread safety yada yada + .expect("failed to insert oneko into the event loop"); + + let shm = Shm::bind(&globals, &qh) + .context("wl_shm is not available")?; + let layer_shell = LayerShell::bind(&globals, &qh) + .context("zwlr_layer_shell_v1 is not available")?; + let compositor = CompositorState::bind(&globals, &qh) + .context("wl_compositor is not available")?; + + let pool = SlotPool::new( + // 4 bytes per pixel, later resized + // we can just set it to the absolute minimum + 4 as usize, + &shm + ) + .context("failed to create a new slot pool")?; + + let surface = compositor.create_surface(&qh); + let layer_surface = layer_shell.create_layer_surface(&qh, surface.clone(), LayerDepth::Overlay, Some("oneko"), None); + + layer_surface.set_size(0, 0); + layer_surface.set_anchor(Anchor::all()); + layer_surface.set_margin(0, 0, 0, 0); + layer_surface.set_exclusive_zone(-1); + layer_surface.commit(); + + Ok((Self { + oneko: oneko, + + registry_state: RegistryState::new(&globals), + seat_state: SeatState::new(&globals, &qh), + output_state: OutputState::new(&globals, &qh), + + buffer: None, + pool: pool, + shm: shm, + layer_surface: layer_surface, + surface: surface, + configured_surface: false, + // these can be set to 0 + // set by the configure event + width: 0, + height: 0, + + pointer: None, + pointer_position: None, + + qh: qh, + exit: false, + + error: None + }, event_loop)) + } + + fn paint(&mut self) { + trace!("repainting surface fully"); + + let width = self.width; + let height = self.height; + let stride = width * 4; + + self.pool + .resize((stride * height * 4) as usize) + .expect("failed to resize the pool"); + + const FORMAT: Format = Format::Argb8888; + let mut buffer = self.buffer.take().unwrap_or_else(|| { + self.pool + .create_buffer(width as i32, height as i32, stride as i32, FORMAT) + .expect("failed to create a buffer") + .0 + }); + + let canvas = match self.pool.canvas(&buffer) { + Some(canvas) => canvas, + None => { + // this is a rare case + // if compositor hasn't released the buffer yet, double buffer it + let (second_buffer, canvas) = self.pool + .create_buffer(width as i32, height as i32, stride as i32, FORMAT) + .expect("failed to create a buffer"); + buffer = second_buffer; + canvas + } + }; + + self.oneko.render( + canvas, + (width, height) + ); + + // buffer damaging is not needed + // this is done in update + + buffer + .attach_to(&self.surface) + .expect("failed to attach the buffer to the surface"); + + self.layer_surface.commit(); + } + + // this repaints the surface by calling a frame event + // this is seen by the compositor, which then our loop calls the draw function! + pub fn request_repaint(&mut self) { + trace!("requesting repaint"); + + let qh = &self.qh; + + self.surface.frame(&qh, self.surface.clone()); + self.layer_surface.commit(); + } + + pub fn update(&mut self) -> bool { + self.oneko.update( + // return to center if pointer is not set + self.pointer_position.unwrap_or((self.width as f64 / 2.0, self.height as f64 / 2.0)), + (self.width, self.height), + &self.surface + ) + } + + pub fn asked_exit(&mut self) -> bool { + self.exit + } + + pub fn take_error(&mut self) -> Option { + self.error.take() + } +} + +delegate_compositor!(Layer); +delegate_output!(Layer); +delegate_shm!(Layer); +delegate_seat!(Layer); +delegate_layer!(Layer); +delegate_registry!(Layer); +delegate_pointer!(Layer); diff --git a/src/layer/output.rs b/src/layer/output.rs new file mode 100644 index 0000000..0f07d10 --- /dev/null +++ b/src/layer/output.rs @@ -0,0 +1,36 @@ +use super::Layer; +use smithay_client_toolkit::{ + output::{OutputHandler, OutputState}, + reexports::client::{ + Connection, + protocol::wl_output, + QueueHandle, + } +}; + +impl OutputHandler for Layer { + fn output_state(&mut self) -> &mut OutputState { + &mut self.output_state + } + + fn new_output( + &mut self, + _conn: &Connection, + _qh: &QueueHandle, + _output: wl_output::WlOutput, + ) { } + + fn update_output( + &mut self, + _conn: &Connection, + _qh: &QueueHandle, + _output: wl_output::WlOutput, + ) { } + + fn output_destroyed( + &mut self, + _conn: &Connection, + _qh: &QueueHandle, + _output: wl_output::WlOutput, + ) { } +} diff --git a/src/layer/pointer.rs b/src/layer/pointer.rs new file mode 100644 index 0000000..0ff14bf --- /dev/null +++ b/src/layer/pointer.rs @@ -0,0 +1,31 @@ +use super::Layer; +use smithay_client_toolkit::{ + reexports::client::{ + Connection, + protocol::wl_pointer::WlPointer, + QueueHandle, + }, + seat::pointer::{PointerEvent, PointerHandler}, + shell::WaylandSurface +}; +use tracing::trace; + +impl PointerHandler for Layer { + fn pointer_frame( + &mut self, + _conn: &Connection, + _qh: &QueueHandle, + _pointer: &WlPointer, + events: &[PointerEvent], + ) { + for event in events { + if event.surface != *self.layer_surface.wl_surface() { + continue; + } + + self.pointer_position = Some(event.position); + + trace!("pointer event: {:?}", event); + } + } +} diff --git a/src/layer/registry.rs b/src/layer/registry.rs new file mode 100644 index 0000000..e3b35d7 --- /dev/null +++ b/src/layer/registry.rs @@ -0,0 +1,15 @@ +use super::Layer; +use smithay_client_toolkit::{ + output::OutputState, + registry::{ProvidesRegistryState, RegistryState}, + registry_handlers, + seat::SeatState, +}; + +impl ProvidesRegistryState for Layer { + fn registry(&mut self) -> &mut RegistryState { + &mut self.registry_state + } + + registry_handlers![OutputState, SeatState]; +} diff --git a/src/layer/seat.rs b/src/layer/seat.rs new file mode 100644 index 0000000..13651b2 --- /dev/null +++ b/src/layer/seat.rs @@ -0,0 +1,44 @@ +use super::Layer; +use smithay_client_toolkit::{ + reexports::client::{ + Connection, + protocol::wl_seat::WlSeat, + QueueHandle, + }, + seat::{Capability, SeatHandler, SeatState} +}; + +impl SeatHandler for Layer { + fn seat_state(&mut self) -> &mut SeatState { + &mut self.seat_state + } + + fn new_capability( + &mut self, + _conn: &Connection, + qh: &QueueHandle, + seat: WlSeat, + capability: Capability, + ) { + match capability { + Capability::Pointer if self.pointer.is_none() => { + if let Ok(pointer) = self.seat_state.get_pointer(qh, &seat) { + self.pointer = Some(pointer); + } + } + _ => { } + } + } + + fn remove_capability( + &mut self, + _conn: &Connection, + _qh: &QueueHandle, + _seat: WlSeat, + _capability: Capability, + ) { } + + fn new_seat(&mut self, _conn: &Connection, _qh: &QueueHandle, _seat: WlSeat) { } + + fn remove_seat(&mut self, _conn: &Connection, _qh: &QueueHandle, _seat: WlSeat) { } +} diff --git a/src/layer/shm.rs b/src/layer/shm.rs new file mode 100644 index 0000000..4abb6cc --- /dev/null +++ b/src/layer/shm.rs @@ -0,0 +1,8 @@ +use super::Layer; +use smithay_client_toolkit::shm::{Shm, ShmHandler}; + +impl ShmHandler for Layer { + fn shm_state(&mut self) -> &mut Shm { + &mut self.shm + } +} diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..9df0ca2 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,40 @@ +#![feature(mixed_integer_ops_unsigned_sub)] + +mod assets; +mod layer; +mod oneko; + +use crate::layer::Layer; +use anyhow::{Result, Context}; +use tracing::{Level, info}; +use tracing_subscriber::EnvFilter; + +fn main() -> Result<()> { + let env_filter = EnvFilter::builder() + .with_default_directive((if cfg!(debug_assertions) { Level::DEBUG } else { Level::INFO }).into()) + .from_env_lossy(); + tracing_subscriber::fmt() + .with_env_filter(env_filter) + .init(); + + info!("{} by {}, {}", + env!("CARGO_PKG_NAME"), + env!("CARGO_PKG_AUTHORS"), + env!("CARGO_PKG_DESCRIPTION") + ); + + let (mut layer, mut event_loop) = Layer::new() + .context("failed to create layer")?; + + info!("layer created, starting event loop"); + + while !layer.asked_exit() { + event_loop.dispatch(None, &mut layer)?; + if let Some(err) = layer.take_error() { + return Err(err); + } + } + // event_loop.run(None, &mut layer, |_| {})?; + + Ok(()) +} diff --git a/src/oneko.rs b/src/oneko.rs new file mode 100644 index 0000000..86518a5 --- /dev/null +++ b/src/oneko.rs @@ -0,0 +1,395 @@ +use crate::assets::{Animation, Frame, Spritesheet}; +use crate::layer::Layer; +use image::{ + GenericImageView, + RgbaImage, + SubImage, +}; +use smithay_client_toolkit::reexports::calloop::{ + timer::{TimeoutAction, Timer}, + InsertError, + LoopHandle, + RegistrationToken +}; +use rand::prelude::*; +use smithay_client_toolkit::reexports::client::protocol::wl_surface::WlSurface; +use std::time::Duration; +use tracing::{debug, trace}; + +// default values taken from oneko.js, simple oneko implementation in JS +// https://github.com/adryd325/oneko.js/ +pub const UPDATE_INTERVAL: Duration = Duration::from_millis(100); +pub const FOLLOW_DISTANCE: f64 = 48.0; +pub const SPEED: f64 = 10.0; + +pub const SPRITESHEET_IMAGE: &[u8] = include_bytes!("../assets/oneko.gif"); +pub const SPRITE_WIDTH: u32 = 32; +pub const SPRITE_HEIGHT: u32 = 32; + +pub struct Oneko { + animation_state: AnimationState, + animation_ticks: u32, + position: (u32, u32), + spritesheet: Spritesheet +} + +impl Oneko { + pub fn new() -> Self { + let spritesheet_image = image::load_from_memory(SPRITESHEET_IMAGE) + .expect("failed to load spritesheet"); + + Oneko { + animation_state: AnimationState::Idle(AnimationStateIdle::Idle), + animation_ticks: 0, + // TODO: place in the center / random position + // this is okay for now, not out of range of any *real* resolution + position: (64, 64), + spritesheet: Spritesheet::new(spritesheet_image, (SPRITE_WIDTH, SPRITE_HEIGHT)) + } + } + + // insert in to a loop + // similar to `calloop_wayland_source::WaylandSource` `insert` method + pub fn insert( + &mut self, + loop_handle: LoopHandle<'static, Layer> + ) -> Result> { + loop_handle + .insert_source(Timer::from_duration(UPDATE_INTERVAL), move |_event, _metadata, layer| { + let changed = layer.update(); + if changed { + trace!("animation/frame has changed, requesting repaint"); + + layer.request_repaint(); + }; + + return TimeoutAction::ToDuration(UPDATE_INTERVAL) + }) + } + + /// returns true if the frame has changed + /// will damage the buffer as necessary + pub fn update( + &mut self, + pointer_position: (f64, f64), + resolution: (u32, u32), + surface: &WlSurface + ) -> bool { + let mut rng = rand::thread_rng(); + + let (resolution_x, resolution_y) = resolution; + let (cat_x, cat_y) = self.position; + let (cat_width, cat_height) = self.spritesheet.get_size(); + let (pointer_x, pointer_y) = pointer_position; + + let distance = + ((cat_x as f64 - pointer_x).abs().powi(2) + + (cat_y as f64 - pointer_y).abs().powi(2)).sqrt(); + + let moving = distance > FOLLOW_DISTANCE; + + let next_movement_animation = AnimationState::Moving(AnimationStateMoving::from_vec( + (pointer_x - cat_x as f64, + pointer_y - cat_y as f64) + )); + let (_, mut next_scratch_animation, touching_wall) = [ + ((0, -1), AnimationStateScratch::ScratchWallN), + ((1, 0), AnimationStateScratch::ScratchWallE), + ((0, 1), AnimationStateScratch::ScratchWallS), + ((-1, 0), AnimationStateScratch::ScratchWallW) + ] + .into_iter() + .map(|((x, y), anim)| { + let pointer_dist = + (pointer_x - cat_width as f64 / 2.0) * x as f64 + + (pointer_y - cat_height as f64 / 2.0) * y as f64; + let touching = match (x, y) { + (0, -1) => cat_y <= 0, + (1, 0) => cat_x >= resolution_x - cat_width, + (0, 1) => cat_y >= resolution_y - cat_height, + (-1, 0) => cat_x <= 0, + // safety: each tuple is a valid pair of x, y from the array, we cover all cases + _ => unreachable!() + }; + (pointer_dist, anim, touching) + }) + .max_by(|(a, _, _), (b, _, _)| a.partial_cmp(b).unwrap_or(std::cmp::Ordering::Equal)) + .unwrap(); + + if !touching_wall { + next_scratch_animation = AnimationStateScratch::ScratchSelf; + } + + let next_animation_state = match self.animation_state { + AnimationState::Moving(_) if !moving => AnimationState::Idle(AnimationStateIdle::Idle), + AnimationState::Moving(_) if moving => next_movement_animation, + AnimationState::Idle(_) if moving => AnimationState::Alert, + // about every 20 seconds (assuming interval is 100ms) + AnimationState::Idle(AnimationStateIdle::Idle) if self.animation_ticks > 10 && rng.gen_bool(1.0 / 200.0) => AnimationState::Idle( + [ + AnimationStateIdle::Scratch(next_scratch_animation), + AnimationStateIdle::Tired + ] + .choose(&mut rng) + .unwrap() + .clone() + ), + AnimationState::Idle(AnimationStateIdle::Scratch(_)) if self.animation_ticks > 9 => AnimationState::Idle(AnimationStateIdle::Idle), + AnimationState::Idle(AnimationStateIdle::Tired) if self.animation_ticks > 7 => AnimationState::Idle(AnimationStateIdle::Sleeping), + AnimationState::Idle(AnimationStateIdle::Sleeping) if self.animation_ticks > 192 => AnimationState::Idle(AnimationStateIdle::Idle), + AnimationState::Alert if self.animation_ticks > 6 => next_movement_animation, + _ => self.animation_state + }; + + let (delta_x, delta_y) = match next_animation_state { + AnimationState::Moving(_) => ( + ((pointer_x - cat_x as f64) / distance * SPEED) as i32, + ((pointer_y - cat_y as f64) / distance * SPEED) as i32 + ), + _ => (0, 0) + }; + + self.position = ( + cat_x.saturating_add_signed(delta_x).clamp(cat_width / 2, resolution_x - cat_width / 2), + cat_y.saturating_add_signed(delta_y).clamp(cat_height / 2, resolution_y - cat_height / 2) + ); + let (cat_x_new, cat_y_new) = self.position; + + if next_animation_state != self.animation_state { + debug!("animation state has changed: {:?}", next_animation_state); + + self.animation_state = next_animation_state; + self.animation_ticks = 0; + } else { + self.animation_ticks += 1; + } + + let animation = get_animation(self.animation_state); + + if (animation.frames.len() > 1 && self.animation_ticks % animation.ticks_per_frame == 0) + || (animation.frames.len() == 1 && self.animation_ticks == 0) + { + trace!("animation frame has changed"); + + // damage the buffer, only in changed frames + // i'm proud of this. i tested it on a compositor that cares very much about damage regions (niri) and it works perfectly + let (cat_width_half, cat_height_half) = (cat_width / 2, cat_height / 2); + let (x, y) = ( + (cat_x_new - cat_width_half).min(cat_x - cat_width_half), + (cat_y_new - cat_height_half).min(cat_y - cat_height_half) + ); + let (width, height) = ( + (cat_x_new + cat_width_half).max(cat_x + cat_width_half) - x, + (cat_y_new + cat_height_half).max(cat_y + cat_height_half) - y + ); + trace!("damaging buffer: x: {}, y: {}, width: {}, height: {}", x, y, width, height); + surface.damage_buffer( + x as i32, + y as i32, + width as i32, + height as i32 + ); + + return true; + } else { + return false; + } + } + + pub fn get_frame(&self) -> SubImage<&RgbaImage> { + let animation = get_animation(self.animation_state); + return self.spritesheet.get_animation(animation, self.animation_ticks); + } + + // TODO (this could go in other spots too): scaling! + // fractional? or just integer scaling? who knows + /// handles EXCLUSIVELY the rendering of the oneko, not the damage region + pub fn render( + &mut self, + canvas: &mut [u8], + resolution: (u32, u32) + ) { + let (position_x, position_y) = self.position; + let (resolution_x, resolution_y) = resolution; + let frame = self.get_frame(); + let (frame_width, frame_height) = frame.dimensions(); + + // fill with transparent color (little-endian ARGB) + canvas.fill(0); + + for frame_pixel_x in 0..frame_width { + for frame_pixel_y in 0..frame_height { + let destination_x = position_x + frame_pixel_x - frame_width / 2; + let destination_y = position_y + frame_pixel_y - frame_height / 2; + + if destination_x >= resolution_x || destination_y >= resolution_y { + continue; + } + + // raw RGBA bytes + let mut frame_pixel = frame.get_pixel(frame_pixel_x, frame_pixel_y).0; + let destination_index = ((destination_y * resolution_x + destination_x) * 4) as usize; + + // RGBA -> BGRA (little-endian ARGB) + frame_pixel.swap(0, 2); + + // skip transparent pixels + // i'm honestly not even sure why i need to do this--maia_oneko.gif has a transparent background, but the "fully transparent" pixels are still colored a transparent blue? + if frame_pixel[3] == 0 { + continue; + } + + canvas[destination_index..destination_index + 4].copy_from_slice(&frame_pixel); + } + } + } +} + +#[derive(Debug, Clone, Copy, PartialEq)] +enum AnimationState { + Idle(AnimationStateIdle), + Alert, + Moving(AnimationStateMoving) +} + +#[derive(Debug, Clone, Copy, PartialEq)] +enum AnimationStateIdle { + Idle, + Scratch(AnimationStateScratch), + Tired, + Sleeping +} + +#[derive(Debug, Clone, Copy, PartialEq)] +enum AnimationStateScratch { + ScratchSelf, + ScratchWallN, + ScratchWallS, + ScratchWallE, + ScratchWallW +} + +#[derive(Debug, Clone, Copy, PartialEq)] +enum AnimationStateMoving { + N, + NE, + E, + SE, + S, + SW, + W, + NW +} + +impl AnimationStateMoving { + fn from_vec((x, y): (f64, f64)) -> Self { + enum AxisDirection { + Negative, + Positive, + Zero + } + + let distance = (x * x + y * y).sqrt(); + + let x_direction = match x / distance { + ..-0.5 => AxisDirection::Negative, + 0.5.. => AxisDirection::Positive, + // NaN is possible, catch all + _ => AxisDirection::Zero, + }; + + let y_direction = match y / distance { + ..-0.5 => AxisDirection::Negative, + 0.5.. => AxisDirection::Positive, + // NaN is possible, catch all + _ => AxisDirection::Zero, + }; + + match (x_direction, y_direction) { + (AxisDirection::Zero, AxisDirection::Negative) => AnimationStateMoving::N, + (AxisDirection::Positive, AxisDirection::Negative) => AnimationStateMoving::NE, + (AxisDirection::Positive, AxisDirection::Zero) => AnimationStateMoving::E, + (AxisDirection::Positive, AxisDirection::Positive) => AnimationStateMoving::SE, + (AxisDirection::Zero, AxisDirection::Positive) => AnimationStateMoving::S, + (AxisDirection::Negative, AxisDirection::Positive) => AnimationStateMoving::SW, + (AxisDirection::Negative, AxisDirection::Zero) => AnimationStateMoving::W, + (AxisDirection::Negative, AxisDirection::Negative) => AnimationStateMoving::NW, + // this is possible to be evaluated (NaN, NaN), but it won't actually be used (distance is not greater than `FOLLOW_DISTANCE`) + // just insert a bogus value so we don't panic + (AxisDirection::Zero, AxisDirection::Zero) => AnimationStateMoving::N + } + } +} + +fn get_animation(state: AnimationState) -> Animation { + match state { + AnimationState::Idle(AnimationStateIdle::Idle) => Animation { + frames: &[Frame(3, 3)], + ticks_per_frame: 1 + }, + AnimationState::Idle(AnimationStateIdle::Scratch(AnimationStateScratch::ScratchSelf)) => Animation { + ticks_per_frame: 1, + frames: &[Frame(5, 0), Frame(6, 0), Frame(7, 0)], + }, + AnimationState::Idle(AnimationStateIdle::Scratch(AnimationStateScratch::ScratchWallN)) => Animation { + ticks_per_frame: 1, + frames: &[Frame(0, 0), Frame(0, 1)], + }, + AnimationState::Idle(AnimationStateIdle::Scratch(AnimationStateScratch::ScratchWallS)) => Animation { + ticks_per_frame: 1, + frames: &[Frame(7, 1), Frame(6, 2)], + }, + AnimationState::Idle(AnimationStateIdle::Scratch(AnimationStateScratch::ScratchWallE)) => Animation { + ticks_per_frame: 1, + frames: &[Frame(2, 2), Frame(2, 3)], + }, + AnimationState::Idle(AnimationStateIdle::Scratch(AnimationStateScratch::ScratchWallW)) => Animation { + ticks_per_frame: 1, + frames: &[Frame(4, 0), Frame(4, 1)], + }, + AnimationState::Idle(AnimationStateIdle::Tired) => Animation { + ticks_per_frame: 1, + frames: &[Frame(3, 2)], + }, + AnimationState::Idle(AnimationStateIdle::Sleeping) => Animation { + ticks_per_frame: 4, + frames: &[Frame(2, 0), Frame(2, 1)], + }, + AnimationState::Alert => Animation { + ticks_per_frame: 1, + frames: &[Frame(7, 3)], + }, + AnimationState::Moving(AnimationStateMoving::N) => Animation { + ticks_per_frame: 1, + frames: &[Frame(1, 2), Frame(1, 3)], + }, + AnimationState::Moving(AnimationStateMoving::NE) => Animation { + ticks_per_frame: 1, + frames: &[Frame(0, 2), Frame(0, 3)], + }, + AnimationState::Moving(AnimationStateMoving::E) => Animation { + ticks_per_frame: 1, + frames: &[Frame(3, 0), Frame(3, 1)], + }, + AnimationState::Moving(AnimationStateMoving::SE) => Animation { + ticks_per_frame: 1, + frames: &[Frame(5, 1), Frame(5, 2)], + }, + AnimationState::Moving(AnimationStateMoving::S) => Animation { + ticks_per_frame: 1, + frames: &[Frame(6, 3), Frame(7, 2)], + }, + AnimationState::Moving(AnimationStateMoving::SW) => Animation { + ticks_per_frame: 1, + frames: &[Frame(5, 3), Frame(6, 1)], + }, + AnimationState::Moving(AnimationStateMoving::W) => Animation { + ticks_per_frame: 1, + frames: &[Frame(4, 2), Frame(4, 3)], + }, + AnimationState::Moving(AnimationStateMoving::NW) => Animation { + ticks_per_frame: 1, + frames: &[Frame(1, 0), Frame(1, 1)], + } + } +}