diff --git a/.gitignore b/.gitignore index ea8c4bf..7099b4e 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,5 @@ +.* +!.gitignore + +*.log /target diff --git a/Cargo.lock b/Cargo.lock index 2eda30a..145a1d7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,12 +2,69 @@ # It is not intended for manual editing. version = 3 +[[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 = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + +[[package]] +name = "anyhow" +version = "1.0.75" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" + +[[package]] +name = "arc-swap" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bddcadddf5e9015d310179a59bb28c4d4b9920ad0f11e8e14dbadf654890c9a6" + [[package]] name = "autocfg" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +[[package]] +name = "backtrace" +version = "0.3.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + [[package]] name = "bitflags" version = "1.3.2" @@ -15,10 +72,61 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] -name = "cc" -version = "1.0.79" +name = "bitflags" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" +checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635" + +[[package]] +name = "bumpalo" +version = "3.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3e2c3daef883ecc1b5d58c15adae93470a91d425f3532ba1695849656af3fc1" + +[[package]] +name = "cairo" +version = "0.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93611bc95d77e5486187a8c148f9d9317b2cdb759694676670a087e636dc8658" +dependencies = [ + "libc", + "num", +] + +[[package]] +name = "calloop" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52e0d00eb1ea24371a97d2da6201c6747a633dc6dc1988ef503403b4c59504a8" +dependencies = [ + "bitflags 1.3.2", + "log", + "nix 0.25.1", + "slotmap", + "thiserror", + "vec_map", +] + +[[package]] +name = "calloop-wayland-source" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6550ab8b7814ac2188969b1ff1b2d8c8a54108aa72663c94e842f9d60e2361a7" +dependencies = [ + "calloop", + "rustix", + "wayland-backend", + "wayland-client", +] + +[[package]] +name = "cc" +version = "1.0.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" +dependencies = [ + "libc", +] [[package]] name = "cfg-if" @@ -26,6 +134,70 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "chrono" +version = "0.4.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "defd4e7873dbddba6c7c91e199c7fcb946abc4a6a4ac3195400bcfb01b5de877" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "js-sys", + "num-traits", + "wasm-bindgen", + "windows-targets", +] + +[[package]] +name = "color-eyre" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a667583cca8c4f8436db8de46ea8233c42a7d9ae424a82d338f2e4675229204" +dependencies = [ + "backtrace", + "color-spantrace", + "eyre", + "indenter", + "once_cell", + "owo-colors", + "tracing-error", +] + +[[package]] +name = "color-spantrace" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ba75b3d9449ecdccb27ecbc479fdc0b87fa2dd43d2f8298f9bf0e59aacc8dce" +dependencies = [ + "once_cell", + "owo-colors", + "tracing-core", + "tracing-error", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" + +[[package]] +name = "derivative" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "destructure_traitobject" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c877555693c14d2f84191cfd3ad8582790fc52b5e2274b40b59cf5f5cea25c7" + [[package]] name = "dlib" version = "0.5.2" @@ -42,10 +214,116 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650" [[package]] -name = "hermit-abi" -version = "0.3.1" +name = "errno" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" +checksum = "136526188508e25c6fef639d7927dfb3e0e3084488bf202267829cf7fc23dbdd" +dependencies = [ + "errno-dragonfly", + "libc", + "windows-sys", +] + +[[package]] +name = "errno-dragonfly" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" +dependencies = [ + "cc", + "libc", +] + +[[package]] +name = "eyre" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c2b6b5a29c02cdc822728b7d7b8ae1bab3e3b05d44522770ddd49722eeac7eb" +dependencies = [ + "indenter", + "once_cell", +] + +[[package]] +name = "fastrand" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6999dc1837253364c2ebb0704ba97994bd874e8f195d665c50b7548f6ea92764" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "fuchsia-cprng" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" + +[[package]] +name = "gimli" +version = "0.28.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0" + +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" + +[[package]] +name = "hermit-abi" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "443144c8cdadd93ebf52ddb4056d257f5b52c04d3c804e657d19eb73fc33668b" + +[[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + +[[package]] +name = "iana-time-zone" +version = "0.1.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fad5b825842d2b38bd206f3e81d6957625fd7f0a361e345c30e01a0ae2dd613" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + +[[package]] +name = "indenter" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683" + +[[package]] +name = "indexmap" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" +dependencies = [ + "autocfg", + "hashbrown", +] [[package]] name = "io-lifetimes" @@ -59,10 +337,31 @@ dependencies = [ ] [[package]] -name = "libc" -version = "0.2.146" +name = "itoa" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f92be4933c13fd498862a9e02a3055f8a8d9c039ce33db97306fd5a6caa7f29b" +checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" + +[[package]] +name = "js-sys" +version = "0.3.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5f195fe497f702db0f318b07fdd68edb16955aed830df8363d837542f8f935a" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "libc" +version = "0.2.147" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" [[package]] name = "libloading" @@ -75,16 +374,82 @@ dependencies = [ ] [[package]] -name = "log" -version = "0.4.19" +name = "linked-hash-map" +version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b06a4cde4c0f271a446782e3eff8de789548ce57dbc8eca9292c27f4a42004b4" +checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" + +[[package]] +name = "linux-raw-sys" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a9bad9f94746442c783ca431b22403b519cd7fbeed0533fdd6328b2f2212128" + +[[package]] +name = "lock_api" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1cc9717a20b1bb222f333e6a92fd32f7d8a18ddc5a3191a11af45dcbf4dcd16" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" +dependencies = [ + "serde", +] + +[[package]] +name = "log-mdc" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a94d21414c1f4a51209ad204c1776a3d0765002c76c6abcb602a6f09f1e881c7" + +[[package]] +name = "log4rs" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d36ca1786d9e79b8193a68d480a0907b612f109537115c6ff655a3a1967533fd" +dependencies = [ + "anyhow", + "arc-swap", + "chrono", + "derivative", + "fnv", + "humantime", + "libc", + "log", + "log-mdc", + "parking_lot", + "serde", + "serde-value", + "serde_json", + "serde_yaml", + "thiserror", + "thread-id", + "typemap-ors", + "winapi", +] [[package]] name = "memchr" -version = "2.5.0" +version = "2.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" +checksum = "8f232d6ef707e1956a43342693d2a31e72989554d58299d7a88738cc95b0d35c" + +[[package]] +name = "memoffset" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce" +dependencies = [ + "autocfg", +] [[package]] name = "memoffset" @@ -96,18 +461,176 @@ dependencies = [ ] [[package]] -name = "nix" -version = "0.26.2" +name = "miniz_oxide" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfdda3d196821d6af13126e40375cdf7da646a96114af134d5f417a9a1dc8e1a" +checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7" dependencies = [ - "bitflags", + "adler", +] + +[[package]] +name = "nix" +version = "0.25.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f346ff70e7dbfd675fe90590b92d59ef2de15a8779ae305ebcbfd3f0caf59be4" +dependencies = [ + "autocfg", + "bitflags 1.3.2", "cfg-if", "libc", - "memoffset", - "static_assertions", + "memoffset 0.6.5", ] +[[package]] +name = "nix" +version = "0.26.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "598beaf3cc6fdd9a5dfb1630c2800c7acd31df7aaf0f565796fba2b53ca1af1b" +dependencies = [ + "bitflags 1.3.2", + "cfg-if", + "libc", + "memoffset 0.7.1", +] + +[[package]] +name = "num" +version = "0.1.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4703ad64153382334aa8db57c637364c322d3372e097840c72000dabdcf6156e" +dependencies = [ + "num-bigint", + "num-complex", + "num-integer", + "num-iter", + "num-rational", + "num-traits", +] + +[[package]] +name = "num-bigint" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e63899ad0da84ce718c14936262a41cee2c79c981fc0a0e7c7beb47d5a07e8c1" +dependencies = [ + "num-integer", + "num-traits", + "rand", + "rustc-serialize", +] + +[[package]] +name = "num-complex" +version = "0.1.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b288631d7878aaf59442cffd36910ea604ecd7745c36054328595114001c9656" +dependencies = [ + "num-traits", + "rustc-serialize", +] + +[[package]] +name = "num-integer" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" +dependencies = [ + "autocfg", + "num-traits", +] + +[[package]] +name = "num-iter" +version = "0.1.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d03e6c028c5dc5cac6e2dec0efda81fc887605bb3d884578bb6d6bf7514e252" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-rational" +version = "0.1.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee314c74bd753fc86b4780aa9475da469155f3848473a261d2d18e35245a784e" +dependencies = [ + "num-bigint", + "num-integer", + "num-traits", + "rustc-serialize", +] + +[[package]] +name = "num-traits" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f30b0abd723be7e2ffca1272140fac1a2f084c77ec3e123c192b66af1ee9e6c2" +dependencies = [ + "autocfg", +] + +[[package]] +name = "object" +version = "0.32.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9cf5f9dd3933bd50a9e1f149ec995f39ae2c496d31fd772c1fd45ebc27e902b0" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" + +[[package]] +name = "ordered-float" +version = "2.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7940cf2ca942593318d07fcf2596cdca60a85c9e7fab408a5e21a4f9dcd40d87" +dependencies = [ + "num-traits", +] + +[[package]] +name = "owo-colors" +version = "3.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f" + +[[package]] +name = "parking_lot" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93f00c865fe7cabf650081affecd3871070f26767e7b2070a3ffae14c654b447" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall 0.3.5", + "smallvec", + "windows-targets", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" + [[package]] name = "pkg-config" version = "0.3.27" @@ -116,9 +639,9 @@ checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" [[package]] name = "proc-macro2" -version = "1.0.60" +version = "1.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dec2b086b7a862cf4de201096214fa870344cf922b2b30c167badb3af3195406" +checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" dependencies = [ "unicode-ident", ] @@ -134,13 +657,99 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.28" +version = "1.0.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b9ab9c7eadfd8df19006f1cf1a4aed13540ed5cbc047010ece5826e10825488" +checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" dependencies = [ "proc-macro2", ] +[[package]] +name = "rand" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293" +dependencies = [ + "fuchsia-cprng", + "libc", + "rand_core 0.3.1", + "rdrand", + "winapi", +] + +[[package]] +name = "rand_core" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" +dependencies = [ + "rand_core 0.4.2", +] + +[[package]] +name = "rand_core" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" + +[[package]] +name = "rdrand" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" +dependencies = [ + "rand_core 0.3.1", +] + +[[package]] +name = "redox_syscall" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" +dependencies = [ + "bitflags 1.3.2", +] + +[[package]] +name = "redox_syscall" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" +dependencies = [ + "bitflags 1.3.2", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" + +[[package]] +name = "rustc-serialize" +version = "0.3.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda" + +[[package]] +name = "rustix" +version = "0.38.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7db8590df6dfcd144d22afd1b83b36c21a18d7cbc1dc4bb5295a8712e9eb662" +dependencies = [ + "bitflags 2.4.0", + "errno", + "libc", + "linux-raw-sys", + "windows-sys", +] + +[[package]] +name = "ryu" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" + [[package]] name = "scoped-tls" version = "1.0.1" @@ -148,29 +757,316 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" [[package]] -name = "smallvec" -version = "1.10.0" +name = "scopeguard" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] -name = "static_assertions" -version = "1.1.0" +name = "serde" +version = "1.0.188" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" +checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde-value" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3a1a3341211875ef120e117ea7fd5228530ae7e7036a779fdc9117be6b3282c" +dependencies = [ + "ordered-float", + "serde", +] + +[[package]] +name = "serde_derive" +version = "1.0.188" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.32", +] + +[[package]] +name = "serde_json" +version = "1.0.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2cc66a619ed80bf7a0f6b17dd063a84b88f6dea1813737cf469aef1d081142c2" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "serde_yaml" +version = "0.8.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "578a7433b776b56a35785ed5ce9a7e777ac0598aac5a6dd1b4b18a307c7fc71b" +dependencies = [ + "indexmap", + "ryu", + "serde", + "yaml-rust", +] + +[[package]] +name = "sharded-slab" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "900fba806f70c630b0a382d0d825e17a0f19fcd059a2ade1ff237bcddf446b31" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "slotmap" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1e08e261d0e8f5c43123b7adf3e4ca1690d655377ac93a03b2c9d3e98de1342" +dependencies = [ + "version_check", +] + +[[package]] +name = "smallvec" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9" + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "239814284fd6f1a4ffe4ca893952cdd93c224b6a1571c9a9eadd670295c0c9e2" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tempfile" +version = "3.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb94d2f3cc536af71caac6b6fcebf65860b347e7ce0cc9ebe8f70d3e521054ef" +dependencies = [ + "cfg-if", + "fastrand", + "redox_syscall 0.3.5", + "rustix", + "windows-sys", +] + +[[package]] +name = "thiserror" +version = "1.0.48" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d6d7a740b8a666a7e828dd00da9c0dc290dff53154ea77ac109281de90589b7" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.48" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49922ecae66cc8a249b77e68d1d0623c1b2c514f0060c27cdc68bd62a1219d35" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.32", +] + +[[package]] +name = "thread-id" +version = "4.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79474f573561cdc4871a0de34a51c92f7f5a56039113fbb5b9c9f96bdb756669" +dependencies = [ + "libc", + "redox_syscall 0.2.16", + "winapi", +] + +[[package]] +name = "thread_local" +version = "1.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152" +dependencies = [ + "cfg-if", + "once_cell", +] + +[[package]] +name = "tracing" +version = "0.1.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" +dependencies = [ + "cfg-if", + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0955b8137a1df6f1a2e9a37d8a6656291ff0297c1a97c24e0d8425fe2312f79a" +dependencies = [ + "once_cell", + "valuable", +] + +[[package]] +name = "tracing-error" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d686ec1c0f384b1277f097b2f279a2ecc11afe8c133c1aabf036a27cb4cd206e" +dependencies = [ + "tracing", + "tracing-subscriber", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30a651bc37f915e81f087d86e62a18eec5f79550c7faff886f7090b4ea757c77" +dependencies = [ + "sharded-slab", + "thread_local", + "tracing-core", +] + +[[package]] +name = "typemap-ors" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a68c24b707f02dd18f1e4ccceb9d49f2058c2fb86384ef9972592904d7a28867" +dependencies = [ + "unsafe-any-ors", +] [[package]] name = "udon" version = "0.1.0" dependencies = [ + "cairo", + "calloop", + "calloop-wayland-source", + "color-eyre", + "log", + "log4rs", + "tempfile", "wayland-client", + "wayland-protocols", ] [[package]] name = "unicode-ident" -version = "1.0.9" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b15811caf2415fb889178633e7724bad2509101cde276048e013b9def5e51fa0" +checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" + +[[package]] +name = "unsafe-any-ors" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0a303d30665362d9680d7d91d78b23f5f899504d4f08b3c4cf08d055d87c0ad" +dependencies = [ + "destructure_traitobject", +] + +[[package]] +name = "valuable" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" + +[[package]] +name = "vec_map" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "wasm-bindgen" +version = "0.2.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7706a72ab36d8cb1f80ffbf0e071533974a60d0a308d01a5d0375bf60499a342" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ef2b6d3c510e9625e5fe6f509ab07d66a760f0885d858736483c32ed7809abd" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn 2.0.32", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dee495e55982a3bd48105a7b947fd2a9b4a8ae3010041b9e0faab3f9cd028f1d" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.32", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1" [[package]] name = "wayland-backend" @@ -181,7 +1077,7 @@ dependencies = [ "cc", "downcast-rs", "io-lifetimes", - "nix", + "nix 0.26.4", "scoped-tls", "smallvec", "wayland-sys", @@ -193,12 +1089,24 @@ version = "0.30.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "489c9654770f674fc7e266b3c579f4053d7551df0ceb392f153adb1f9ed06ac8" dependencies = [ - "bitflags", - "nix", + "bitflags 1.3.2", + "nix 0.26.4", "wayland-backend", "wayland-scanner", ] +[[package]] +name = "wayland-protocols" +version = "0.30.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b28101e5ca94f70461a6c2d610f76d85ad223d042dd76585ab23d3422dd9b4d" +dependencies = [ + "bitflags 1.3.2", + "wayland-backend", + "wayland-client", + "wayland-scanner", +] + [[package]] name = "wayland-scanner" version = "0.30.1" @@ -221,6 +1129,37 @@ 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" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f" +dependencies = [ + "windows-targets", +] + [[package]] name = "windows-sys" version = "0.48.0" @@ -232,9 +1171,9 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b1eb6f0cd7c80c79759c929114ef071b87354ce476d9d94271031c0497adfd5" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" dependencies = [ "windows_aarch64_gnullvm", "windows_aarch64_msvc", @@ -247,42 +1186,51 @@ dependencies = [ [[package]] name = "windows_aarch64_gnullvm" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" [[package]] name = "windows_aarch64_msvc" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" [[package]] name = "windows_i686_gnu" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" [[package]] name = "windows_i686_msvc" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" [[package]] name = "windows_x86_64_gnu" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" [[package]] name = "windows_x86_64_gnullvm" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" [[package]] name = "windows_x86_64_msvc" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "yaml-rust" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85" +dependencies = [ + "linked-hash-map", +] diff --git a/Cargo.toml b/Cargo.toml index 493623c..84cc945 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,6 +2,21 @@ name = "udon" version = "0.1.0" edition = "2021" +description = "A kanban-lockscreen" [dependencies] -wayland-client = "0.30.2" +# Logs and error reporting +log = "0.4.20" +log4rs = "1.2.0" +color-eyre = "0.6.2" + +# Surface drawing +cairo = "0.0.4" + +# the version here must match the one used by wayland-client +calloop = "0.10.0" +calloop-wayland-source = "0.1.0" +tempfile = "3.7.0" +wayland-client = { version = "0.30.2" } +# staging needed for ext session lock +wayland-protocols = { version = "0.30.1", features = ["staging", "client"] } diff --git a/README.md b/README.md index 1b5968a..484ff0c 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,9 @@ # Udon A Wayland lockscreen supporting rotating display of informations + +## Acknowledgements + +The following code repositories were consulted to make Udon possible +- [wpaperd](https://github.com/danyspin97/wpaperd) + diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..a14d586 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1,5 @@ +edition = "2021" +brace_style = "AlwaysNextLine" +hard_tabs = true +tab_spaces = 3 +imports_granularity = "Crate" diff --git a/src/main.rs b/src/main.rs index b24d04b..96ef733 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,81 +1,69 @@ -use wayland_client::{protocol::wl_registry, Connection, Dispatch, QueueHandle}; -// This struct represents the state of our app. This simple app does not -// need any state, by this type still supports the `Dispatch` implementations. -struct AppData; +mod state; -// Implement `Dispatch for out state. This provides the logic -// to be able to process events for the wl_registry interface. -// -// The second type parameter is the user-data of our implementation. It is a -// mechanism that allows you to associate a value to each particular Wayland -// object, and allow different dispatching logic depending on the type of the -// associated value. -// -// In this example, we just use () as we don't have any value to associate. See -// the `Dispatch` documentation for more details about this. -impl Dispatch for AppData +use crate::state::State; + +use calloop_wayland_source::WaylandSource; +use color_eyre::eyre::{self, Context}; +use wayland_client::{globals as WG, Connection}; + +fn setup() -> eyre::Result<()> { - fn event( - _state: &mut Self, - _: &wl_registry::WlRegistry, - event: wl_registry::Event, - _: &(), - _: &Connection, - _: &QueueHandle, - ) - { - // When receiving events from the wl_registry, we are only interested in the - // `global` event, which signals a new available global. - // When receiving this event, we just print its characteristics in this example. - if let wl_registry::Event::Global { - name, - interface, - version, - } = event - { - println!("[{}] {} (v{})", name, interface, version); + use log4rs::{append, config, encode::pattern::PatternEncoder}; + let stdout = append::console::ConsoleAppender::builder() + .encoder(Box::new(PatternEncoder::new( + "{d(%Y-%m-%d %H:%M:%S)} | {h({l}):5.5} | [{T}] {f}:{L} — {m}{n}", + ))) + .build(); + + let file = append::file::FileAppender::builder() + .encoder(Box::new(PatternEncoder::new("{d} - {m}{n}"))) + .build("requests.log")?; + + let config = config::Config::builder() + .appender(config::Appender::builder().build("stdout", Box::new(stdout))) + .appender(config::Appender::builder().build("file", Box::new(file))) + .build( + config::Root::builder() + .appender("stdout") + .build(log::LevelFilter::Trace), + )?; + + let _handle = log4rs::init_config(config)?; + Ok(()) +} + +fn main() -> eyre::Result<()> +{ + // Initialise on I/O modules + color_eyre::install()?; + setup().wrap_err("Could not initialize logging")?; + + // Create WL connection and get the display + let connection = Connection::connect_to_env()?; + let display = connection.display(); + let (globals, event_queue) = WG::registry_queue_init::(&connection)?; + let q_handle = event_queue.handle(); + + let registry = display.get_registry(&q_handle, ()); + + let mut state = State::new(globals.contents().clone_list(), ®istry, &q_handle)?; + + // Main calloop event loop + let mut event_loop = calloop::EventLoop::::try_new()?; + + WaylandSource::new(event_queue)?.insert(event_loop.handle())?; + + log::trace!("Main loop starting"); + + state.lock(&q_handle); + + while let Ok(_) = event_loop.dispatch(None, &mut state) { + if state.stop { + break; } } -} - -// The main function of our program -fn main() -{ - // Create a Wayland connection by connecting to the server through the - // environment-provided configuration. - let conn = Connection::connect_to_env().unwrap(); - - // Retrieve the WlDisplay Wayland object from the connection. This object is - // the starting point of any Wayland program, from which all other objects will - // be created. - let display = conn.display(); - - // Create an event queue for our event processing - let mut event_queue = conn.new_event_queue(); - // An get its handle to associated new objects to it - let qh = event_queue.handle(); - - // Create a wl_registry object by sending the wl_display.get_registry request - // This method takes two arguments: a handle to the queue the newly created - // wl_registry will be assigned to, and the user-data that should be associated - // with this registry (here it is () as we don't need user-data). - let _registry = display.get_registry(&qh, ()); - - // At this point everything is ready, and we just need to wait to receive the events - // from the wl_registry, our callback will print the advertized globals. - println!("Advertized globals:"); - - // To actually receive the events, we invoke the `sync_roundtrip` method. This method - // is special and you will generally only invoke it during the setup of your program: - // it will block until the server has received and processed all the messages you've - // sent up to now. - // - // In our case, that means it'll block until the server has received our - // wl_display.get_registry request, and as a reaction has sent us a batch of - // wl_registry.global events. - // - // `sync_roundtrip` will then empty the internal buffer of the queue it has been invoked - // on, and thus invoke our `Dispatch` implementation that prints the list of advertized - // globals. - event_queue.roundtrip(&mut AppData).unwrap(); + + log::trace!("Teardown"); + + Ok(()) } diff --git a/src/state.rs b/src/state.rs new file mode 100644 index 0000000..440cc1d --- /dev/null +++ b/src/state.rs @@ -0,0 +1,448 @@ +use color_eyre::eyre::{self, eyre}; +use wayland_client::{globals as WG, protocol as WP, Connection, Dispatch, QueueHandle, WEnum}; +use wayland_protocols::ext::session_lock::v1::client as WpSl; + +pub struct State +{ + pub stop: bool, + + // wayland globals + pub compositor: WP::wl_compositor::WlCompositor, + pub subcompositor: WP::wl_subcompositor::WlSubcompositor, + pub shm: WP::wl_shm::WlShm, + pub seat: WP::wl_seat::WlSeat, + pub output: WP::wl_output::WlOutput, + pub ext_session_lock_manager: WpSl::ext_session_lock_manager_v1::ExtSessionLockManagerV1, + + // wayland objects + pub surface: Option, + pub ext_session_lock: Option, + pub ext_session_lock_surface: Option, + buffer: Option, + //cairo_surface: Option, +} + +impl State +{ + pub fn new( + globals: Vec, + registry: &WP::wl_registry::WlRegistry, + q_handle: &wayland_client::QueueHandle, + ) -> eyre::Result + { + let globals: std::collections::BTreeMap<_, _> = globals + .into_iter() + .map(|global| (global.interface, global.name)) + .collect(); + + let compositor_name = globals + .get("wl_compositor") + .ok_or_else(|| eyre!("compositor global not found"))?; + let subcompositor_name = globals + .get("wl_subcompositor") + .ok_or_else(|| eyre!("subcompositor global not found"))?; + let shm_name = globals + .get("wl_shm") + .ok_or_else(|| eyre!("shm global not found"))?; + let seat_name = globals + .get("wl_seat") + .ok_or_else(|| eyre!("seat global not found"))?; + let output_name = globals + .get("wl_output") + .ok_or_else(|| eyre!("output global not found"))?; + let eslm_name = globals + .get("ext_session_lock_manager_v1") + .ok_or_else(|| eyre!("session lock global not found"))?; + + Ok(State { + stop: false, + + compositor: registry.bind(*compositor_name, 4, q_handle, ()), + subcompositor: registry.bind(*subcompositor_name, 1, q_handle, ()), + shm: registry.bind(*shm_name, 1, q_handle, ()), + seat: registry.bind(*seat_name, 4, q_handle, ()), + output: registry.bind(*output_name, 4, q_handle, ()), + ext_session_lock_manager: registry.bind(*eslm_name, 1, q_handle, ()), + + surface: None, + ext_session_lock: None, + ext_session_lock_surface: None, + buffer: None, + }) + } + + pub fn lock(&mut self, q_handle: &wayland_client::QueueHandle) + { + self.ext_session_lock = Some(self.ext_session_lock_manager.lock(&q_handle, ())); + /* + let surface = self.compositor.create_surface(&q_handle, ()); + self.ext_session_lock_surface = + Some(registry.get_lock_surface(&surface, &self.output, &q_handle, ())); + self.surface = Some(surface); + */ + } + + pub fn unlock(&mut self) + { + match &self.ext_session_lock { + Some(lock) => { + lock.unlock_and_destroy(); + self.stop = true; + } + None => log::warn!("Attempting to unlock lock that does not exist"), + } + } +} + +// This hook is required to read globals +impl Dispatch for State +{ + fn event( + _state: &mut Self, + _proxy: &WP::wl_registry::WlRegistry, + _event: WP::wl_registry::Event, + _data: &WG::GlobalListContents, + _conn: &Connection, + _q_handle: &QueueHandle, + ) + { + } +} +impl Dispatch for State +{ + fn event( + _state: &mut Self, + _proxy: &WP::wl_registry::WlRegistry, + _event: WP::wl_registry::Event, + _data: &(), + _conn: &Connection, + _q_handle: &QueueHandle, + ) + { + } +} + +/* +impl Dispatch for State +{ + fn event( + state: &mut Self, + proxy: &WP::wl_registry::WlRegistry, + event: WP::wl_registry::Event, + _data: &(), + _conn: &Connection, + q_handle: &QueueHandle, + ) + { + if let WP::wl_registry::Event::Global { + name, + interface, + version, + } = event + { + match interface.as_str() { + "wl_compositor" => { + let v = 4; // Version override + state.compositor = Some(proxy.bind(name, v, q_handle, ())); + log::trace!("Compositor [{}] {} (v{})", name, interface, version); + } + "wl_subcompositor" => { + let v = 1; // Version override + state.subcompositor = Some(proxy.bind(name, v, q_handle, ())); + log::trace!("Subcompositor [{}] {} (v{})", name, interface, version); + } + "wl_shm" => { + let v = 1; // Version override + state.shm = Some(proxy.bind(name, v, q_handle, ())); + log::trace!("Shared Memory [{}] {} (v{})", name, interface, version); + } + "wl_seat" => { + let v = 4; // Version override + state.seat = Some(proxy.bind(name, v, q_handle, ())); + log::trace!("Seat [{}] {} (v{})", name, interface, version); + } + "wl_output" => { + let v = 4; // Version override + state.output = Some(proxy.bind(name, v, q_handle, ())); + log::trace!("Output [{}] {} (v{})", name, interface, version); + } + "ext_session_lock_manager_v1" => { + let v = 1; + state.ext_session_lock_manager = Some(proxy.bind(name, v, q_handle, ())); + log::trace!( + "Ext Session Lock Manager [{}] {} (v{})", + name, interface, version + ); + } + _ => log::trace!("Other Global [{}] {} (v{})", name, interface, version), + } + } + } +} +*/ + +impl Dispatch for State +{ + fn event( + _state: &mut Self, + _proxy: &WP::wl_compositor::WlCompositor, + _event: WP::wl_compositor::Event, + _data: &(), + _conn: &Connection, + _q_handle: &QueueHandle, + ) + { + log::trace!("Event from compositor!") + } +} +impl Dispatch for State +{ + fn event( + _state: &mut Self, + _proxy: &WP::wl_subcompositor::WlSubcompositor, + _event: WP::wl_subcompositor::Event, + _data: &(), + _conn: &Connection, + _q_handle: &QueueHandle, + ) + { + log::trace!("Event from subcompositor!") + } +} +impl Dispatch for State +{ + fn event( + _state: &mut Self, + _proxy: &WP::wl_shm::WlShm, + _event: WP::wl_shm::Event, + _data: &(), + _conn: &Connection, + _q_handle: &QueueHandle, + ) + { + log::trace!("Event from shm!") + } +} +impl Dispatch for State +{ + fn event( + _state: &mut Self, + _proxy: &WP::wl_output::WlOutput, + _event: WP::wl_output::Event, + _data: &(), + _conn: &Connection, + _q_handle: &QueueHandle, + ) + { + log::trace!("Event from output!") + } +} +impl Dispatch for State +{ + fn event( + _state: &mut Self, + _proxy: &WpSl::ext_session_lock_manager_v1::ExtSessionLockManagerV1, + _event: WpSl::ext_session_lock_manager_v1::Event, + _data: &(), + _conn: &Connection, + _q_handle: &QueueHandle, + ) + { + unreachable!("Session lock manager should not emit any event"); + //state.lock(&q_handle); + } +} + +impl Dispatch for State +{ + fn event( + _state: &mut Self, + _proxy: &WP::wl_surface::WlSurface, + _event: WP::wl_surface::Event, + _data: &(), + _conn: &Connection, + _q_handle: &QueueHandle, + ) + { + log::trace!("Event from surface!") + } +} +impl Dispatch for State +{ + fn event( + state: &mut Self, + proxy: &WpSl::ext_session_lock_v1::ExtSessionLockV1, + event: WpSl::ext_session_lock_v1::Event, + _data: &(), + _conn: &Connection, + q_handle: &QueueHandle, + ) + { + match event { + WpSl::ext_session_lock_v1::Event::Locked => { + if state.stop { + return; + } + let surface = state.compositor.create_surface(&q_handle, ()); + state.ext_session_lock_surface = + Some(proxy.get_lock_surface(&surface, &state.output, &q_handle, ())); + state.surface = Some(surface); + log::info!("Locked."); + } + WpSl::ext_session_lock_v1::Event::Finished => { + state.ext_session_lock_surface = None; + log::trace!("Could not lock surface!"); + } + _ => log::trace!("Unknown event"), + } + } +} + +fn draw(tmp: &mut std::fs::File, (buf_x, buf_y): (u32, u32)) +{ + use std::{cmp::min, io::Write}; + let mut buf = std::io::BufWriter::new(tmp); + for y in 0..buf_y { + for x in 0..buf_x { + let a = 0xFF; + let r = min(((buf_x - x) * 0xFF) / buf_x, ((buf_y - y) * 0xFF) / buf_y); + let g = min((x * 0xFF) / buf_x, ((buf_y - y) * 0xFF) / buf_y); + let b = min(((buf_x - x) * 0xFF) / buf_x, (y * 0xFF) / buf_y); + + let color = (a << 24) + (r << 16) + (g << 8) + b; + buf.write_all(&color.to_ne_bytes()).unwrap(); + } + } + buf.flush().unwrap(); +} + +impl Dispatch for State +{ + fn event( + state: &mut Self, + proxy: &WpSl::ext_session_lock_surface_v1::ExtSessionLockSurfaceV1, + event: WpSl::ext_session_lock_surface_v1::Event, + _data: &(), + _conn: &Connection, + q_handle: &QueueHandle, + ) + { + match event { + WpSl::ext_session_lock_surface_v1::Event::Configure { + serial, + width, + height, + } => { + use std::os::unix::prelude::AsRawFd; + log::info!( + "Lock surface configuration event: ({}), {} {}", + serial, + width, + height + ); + // Ack should go before any buffer commitment. + proxy.ack_configure(serial); + + let mut file = tempfile::tempfile().unwrap(); + draw(&mut file, (width, height)); + let pool = + state + .shm + .create_pool(file.as_raw_fd(), (width * height * 4) as i32, q_handle, ()); + let buffer = pool.create_buffer( + 0, + width as i32, + height as i32, + (width * 4) as i32, + WP::wl_shm::Format::Argb8888, + q_handle, + (), + ); + + let surface = state.surface.as_ref().unwrap(); + surface.attach(Some(&buffer), 0, 0); + surface.commit(); + + state.buffer = Some(buffer); + } + _ => log::trace!("Unknown event"), + } + } +} + +impl Dispatch for State +{ + fn event( + state: &mut Self, + proxy: &WP::wl_seat::WlSeat, + event: WP::wl_seat::Event, + _data: &(), + _conn: &Connection, + q_handle: &QueueHandle, + ) + { + log::trace!("Event from seat!"); + if let WP::wl_seat::Event::Capabilities { + capabilities: WEnum::Value(capabilities), + } = event + { + if capabilities.contains(WP::wl_seat::Capability::Keyboard) { + proxy.get_keyboard(q_handle, ()); + } else { + log::error!("Seat capability does not contain keyboard"); + state.stop = true; + } + } + } +} +impl Dispatch for State +{ + fn event( + state: &mut Self, + _proxy: &WP::wl_keyboard::WlKeyboard, + event: WP::wl_keyboard::Event, + _data: &(), + _conn: &Connection, + _q_handle: &QueueHandle, + ) + { + if let WP::wl_keyboard::Event::Key { key, .. } = event { + if key == 1 { + // ESC key + log::trace!("Event from keyboard! Unlocking."); + state.stop = true; + state.unlock(); + } + } + } +} + +impl Dispatch for State +{ + fn event( + _state: &mut Self, + _proxy: &WP::wl_shm_pool::WlShmPool, + _event: WP::wl_shm_pool::Event, + _data: &(), + _conn: &Connection, + _q_handle: &QueueHandle, + ) + { + log::trace!("Event from shm pool!") + } +} + +impl Dispatch for State +{ + fn event( + _state: &mut Self, + _proxy: &WP::wl_buffer::WlBuffer, + _event: WP::wl_buffer::Event, + _data: &(), + _conn: &Connection, + _q_handle: &QueueHandle, + ) + { + log::trace!("Event from shm pool!") + } +}