commit 3eedfa1eb53d95d7c0cd416c3d3245c7ca173465 Author: Gergő Sályi Date: Fri Apr 7 17:25:48 2023 +0200 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..512a606 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,1389 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "aho-corasick" +version = "0.7.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac" +dependencies = [ + "memchr", +] + +[[package]] +name = "anstream" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "342258dd14006105c2b75ab1bd7543a03bdf0cfc94383303ac212a04939dff6f" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-wincon", + "concolor-override", + "concolor-query", + "is-terminal", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23ea9e81bd02e310c216d080f6223c179012256e5151c41db88d12c88a1684d2" + +[[package]] +name = "anstyle-parse" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7d1bb534e9efed14f3e5f44e7dd1a4f709384023a4165199a4241e18dff0116" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-wincon" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3127af6145b149f3287bb9a0d10ad9c5692dba8c53ad48285e5bec4063834fa" +dependencies = [ + "anstyle", + "windows-sys 0.45.0", +] + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "bit_field" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc827186963e592360843fb5ba4b973e145841266c1357f7180c43526f2e5b61" + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "bumpalo" +version = "3.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d261e256854913907f67ed06efbc3338dfe6179796deefc1ff763fc1aee5535" + +[[package]] +name = "bytemuck" +version = "1.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17febce684fd15d89027105661fec94afb475cb995fbc59d2865198446ba2eea" + +[[package]] +name = "byteorder" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" + +[[package]] +name = "calloop" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a59225be45a478d772ce015d9743e49e92798ece9e34eda9a6aa2a6a7f40192" +dependencies = [ + "log", + "nix 0.25.1", + "slotmap", + "thiserror", + "vec_map", +] + +[[package]] +name = "cc" +version = "1.0.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "clap" +version = "4.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "046ae530c528f252094e4a77886ee1374437744b2bff1497aa898bbddbbb29b3" +dependencies = [ + "clap_builder", + "clap_derive", + "once_cell", +] + +[[package]] +name = "clap_builder" +version = "4.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "223163f58c9a40c3b0a43e1c4b50a9ce09f007ea2cb1ec258a687945b4b7929f" +dependencies = [ + "anstream", + "anstyle", + "bitflags", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9644cd56d6b87dbe899ef8b053e331c0637664e9e21a33dfcdc36093f5c5c4" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn 2.0.13", +] + +[[package]] +name = "clap_lex" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a2dd5a6fe8c6e3502f568a6353e5273bbb15193ad9a89e457b9970798efbea1" + +[[package]] +name = "color_quant" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" + +[[package]] +name = "concolor-override" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a855d4a1978dc52fb0536a04d384c2c0c1aa273597f08b77c8c4d3b2eec6037f" + +[[package]] +name = "concolor-query" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88d11d52c3d7ca2e6d0040212be9e4dbbcd78b6447f535b6b561f449427944cf" +dependencies = [ + "windows-sys 0.45.0", +] + +[[package]] +name = "crc32fast" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "crossbeam-channel" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf2b3e8478797446514c91ef04bafcb59faba183e621ad488df88983cc14128c" +dependencies = [ + "cfg-if", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-deque" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce6fd6f855243022dcecf8702fef0c297d4338e226845fe067f6341ad9fa0cef" +dependencies = [ + "cfg-if", + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46bd5f3f85273295a9d14aedfb86f6aadbff6d8f5295c4a9edb08e819dcf5695" +dependencies = [ + "autocfg", + "cfg-if", + "crossbeam-utils", + "memoffset 0.8.0", + "scopeguard", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c063cd8cc95f5c377ed0d4b49a4b21f632396ff690e8470c29b3359b346984b" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "crunchy" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" + +[[package]] +name = "dlib" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac1b7517328c04c2aa68422fc60a41b92208182142ed04a25879c26c8f878794" +dependencies = [ + "libloading", +] + +[[package]] +name = "downcast-rs" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650" + +[[package]] +name = "either" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" + +[[package]] +name = "env_logger" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85cdab6a89accf66733ad5a1693a4dcced6aeff64602b634530dd73c1f3ee9f0" +dependencies = [ + "humantime", + "is-terminal", + "log", + "regex", + "termcolor", +] + +[[package]] +name = "errno" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50d6a0976c999d473fe89ad888d5a284e55366d9dc9038b1ba2aa15128c4afa0" +dependencies = [ + "errno-dragonfly", + "libc", + "windows-sys 0.45.0", +] + +[[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 = "exr" +version = "1.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bdd2162b720141a91a054640662d3edce3d50a944a50ffca5313cd951abb35b4" +dependencies = [ + "bit_field", + "flume", + "half", + "lebe", + "miniz_oxide", + "rayon-core", + "smallvec", + "zune-inflate", +] + +[[package]] +name = "flate2" +version = "1.0.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8a2db397cb1c8772f31494cb8917e48cd1e64f0fa7efac59fbd741a0a8ce841" +dependencies = [ + "crc32fast", + "miniz_oxide", +] + +[[package]] +name = "flume" +version = "0.10.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1657b4441c3403d9f7b3409e47575237dac27b1b5726df654a6ecbf92f0f7577" +dependencies = [ + "futures-core", + "futures-sink", + "nanorand", + "pin-project", + "spin", +] + +[[package]] +name = "futures-core" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c" + +[[package]] +name = "futures-sink" +version = "0.3.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f43be4fe21a13b9781a69afa4985b0f6ee0e1afab2c6f454a8cf30e2b2237b6e" + +[[package]] +name = "getrandom" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c85e1d9ab2eadba7e5040d4e09cbd6d072b76a557ad64e797c2cb9d4da21d7e4" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "wasi", + "wasm-bindgen", +] + +[[package]] +name = "gif" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80792593675e051cf94a4b111980da2ba60d4a83e43e0048c5693baab3977045" +dependencies = [ + "color_quant", + "weezl", +] + +[[package]] +name = "half" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02b4af3693f1b705df946e9fe5631932443781d0aabb423b62fcd4d73f6d2fd0" +dependencies = [ + "crunchy", +] + +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + +[[package]] +name = "hermit-abi" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" +dependencies = [ + "libc", +] + +[[package]] +name = "hermit-abi" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" + +[[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + +[[package]] +name = "image" +version = "0.24.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "527909aa81e20ac3a44803521443a765550f09b5130c2c2fa1ea59c2f8f50a3a" +dependencies = [ + "bytemuck", + "byteorder", + "color_quant", + "exr", + "gif", + "jpeg-decoder", + "num-rational", + "num-traits", + "png", + "qoi", + "tiff", +] + +[[package]] +name = "io-lifetimes" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c66c74d2ae7e79a5a8f7ac924adbe38ee42a859c6539ad869eb51f0b52dc220" +dependencies = [ + "hermit-abi 0.3.1", + "libc", + "windows-sys 0.48.0", +] + +[[package]] +name = "is-terminal" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adcf93614601c8129ddf72e2d5633df827ba6551541c6d8c59520a371475be1f" +dependencies = [ + "hermit-abi 0.3.1", + "io-lifetimes", + "rustix", + "windows-sys 0.48.0", +] + +[[package]] +name = "itoa" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6" + +[[package]] +name = "jpeg-decoder" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc0000e42512c92e31c2252315bda326620a4e034105e900c98ec492fa077b3e" +dependencies = [ + "rayon", +] + +[[package]] +name = "js-sys" +version = "0.3.61" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "445dde2150c55e483f3d8416706b97ec8e8237c307e5b7b4b8dd15e6af2a0730" +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 = "lebe" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03087c2bad5e1034e8cace5926dec053fb3790248370865f5117a7d0213354c8" + +[[package]] +name = "libc" +version = "0.2.141" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3304a64d199bb964be99741b7a14d26972741915b3649639149b2479bb46f4b5" + +[[package]] +name = "libloading" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f" +dependencies = [ + "cfg-if", + "winapi", +] + +[[package]] +name = "linux-raw-sys" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d59d8c75012853d2e872fb56bc8a2e53718e2cafe1a4c823143141c6d90c322f" + +[[package]] +name = "lock_api" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "memchr" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" + +[[package]] +name = "memmap2" +version = "0.5.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83faa42c0a078c393f6b29d5db232d8be22776a891f8f56e5284faee4a20b327" +dependencies = [ + "libc", +] + +[[package]] +name = "memoffset" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce" +dependencies = [ + "autocfg", +] + +[[package]] +name = "memoffset" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5de893c32cde5f383baa4c04c5d6dbdd735cfd4a794b0debdb2bb1b421da5ff4" +dependencies = [ + "autocfg", +] + +[[package]] +name = "memoffset" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d61c719bcfbcf5d62b3a09efa6088de8c54bc0bfcd3ea7ae39fcc186108b8de1" +dependencies = [ + "autocfg", +] + +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + +[[package]] +name = "miniz_oxide" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b275950c28b37e794e8c55d88aeb5e139d0ce23fdbbeda68f8d7174abdf9e8fa" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b9d9a46eff5b4ff64b45a9e316a6d1e0bc719ef429cbec4dc630684212bfdf9" +dependencies = [ + "libc", + "log", + "wasi", + "windows-sys 0.45.0", +] + +[[package]] +name = "multibg-sway" +version = "0.1.0" +dependencies = [ + "clap", + "env_logger", + "image", + "log", + "mio", + "smithay-client-toolkit", + "swayipc", +] + +[[package]] +name = "nanorand" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a51313c5820b0b02bd422f4b44776fbf47961755c74ce64afc73bfad10226c3" +dependencies = [ + "getrandom", +] + +[[package]] +name = "nix" +version = "0.25.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f346ff70e7dbfd675fe90590b92d59ef2de15a8779ae305ebcbfd3f0caf59be4" +dependencies = [ + "autocfg", + "bitflags", + "cfg-if", + "libc", + "memoffset 0.6.5", +] + +[[package]] +name = "nix" +version = "0.26.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfdda3d196821d6af13126e40375cdf7da646a96114af134d5f417a9a1dc8e1a" +dependencies = [ + "bitflags", + "cfg-if", + "libc", + "memoffset 0.7.1", + "static_assertions", +] + +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + +[[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-rational" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0638a1c9d0a3c0914158145bc76cff373a75a627e6ecbfb71cbe6f453a5a19b0" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +dependencies = [ + "autocfg", +] + +[[package]] +name = "num_cpus" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b" +dependencies = [ + "hermit-abi 0.2.6", + "libc", +] + +[[package]] +name = "once_cell" +version = "1.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" + +[[package]] +name = "pin-project" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad29a609b6bcd67fee905812e544992d216af9d755757c05ed2d0e15a74c6ecc" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "069bdb1e05adc7a8990dce9cc75370895fbe4e3d58b9b73bf1aee56359344a55" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "pkg-config" +version = "0.3.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160" + +[[package]] +name = "png" +version = "0.17.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d708eaf860a19b19ce538740d2b4bdeeb8337fa53f7738455e706623ad5c638" +dependencies = [ + "bitflags", + "crc32fast", + "flate2", + "miniz_oxide", +] + +[[package]] +name = "proc-macro2" +version = "1.0.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b63bdb0cd06f1f4dedf69b254734f9b45af66e4a031e42a7480257d9898b435" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "qoi" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f6d64c71eb498fe9eae14ce4ec935c555749aef511cca85b5568910d6e48001" +dependencies = [ + "bytemuck", +] + +[[package]] +name = "quick-xml" +version = "0.23.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11bafc859c6815fbaffbbbf4229ecb767ac913fecb27f9ad4343662e9ef099ea" +dependencies = [ + "memchr", +] + +[[package]] +name = "quote" +version = "1.0.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rayon" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d2df5196e37bcc87abebc0053e20787d73847bb33134a69841207dd0a47f03b" +dependencies = [ + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b8f95bd6966f5c87776639160a66bd8ab9895d9d4ab01ddba9fc60661aebe8d" +dependencies = [ + "crossbeam-channel", + "crossbeam-deque", + "crossbeam-utils", + "num_cpus", +] + +[[package]] +name = "regex" +version = "1.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b1f693b24f6ac912f4893ef08244d70b6067480d2f1a46e950c9691e6749d1d" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.6.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" + +[[package]] +name = "rustix" +version = "0.37.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1aef160324be24d31a62147fae491c14d2204a3865c7ca8c3b0d7f7bcb3ea635" +dependencies = [ + "bitflags", + "errno", + "io-lifetimes", + "libc", + "linux-raw-sys", + "windows-sys 0.48.0", +] + +[[package]] +name = "ryu" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041" + +[[package]] +name = "scoped-tls" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" + +[[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + +[[package]] +name = "serde" +version = "1.0.159" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c04e8343c3daeec41f58990b9d77068df31209f2af111e059e9fe9646693065" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.159" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c614d17805b093df4b147b51339e7e44bf05ef59fba1e45d83500bcfb4d8585" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.13", +] + +[[package]] +name = "serde_json" +version = "1.0.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d721eca97ac802aa7777b701877c8004d950fc142651367300d21c1cc0194744" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "simd-adler32" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "238abfbb77c1915110ad968465608b68e869e0772622c9656714e73e5a1a522f" + +[[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.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" + +[[package]] +name = "smithay-client-toolkit" +version = "0.17.0" +source = "git+https://github.com/Smithay/client-toolkit.git?rev=389a4f21872a99a3ba346cc3dabd55c4079ec191#389a4f21872a99a3ba346cc3dabd55c4079ec191" +dependencies = [ + "bitflags", + "calloop", + "dlib", + "lazy_static", + "log", + "memmap2", + "nix 0.26.2", + "pkg-config", + "thiserror", + "wayland-backend", + "wayland-client", + "wayland-cursor", + "wayland-protocols", + "wayland-protocols-wlr", + "wayland-scanner", + "xkbcommon", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" +dependencies = [ + "lock_api", +] + +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + +[[package]] +name = "swayipc" +version = "3.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab1dcff328b223d85d7ca767b2e4aadbc13dad550d36b4c6b929b9ad4d26ee9a" +dependencies = [ + "serde", + "serde_json", + "swayipc-types", +] + +[[package]] +name = "swayipc-types" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44b43b4059d825ccc04adf9726f944d0e3aa20938f4cff3b5c6b53198afcd6b3" +dependencies = [ + "serde", + "serde_json", + "thiserror", +] + +[[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.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c9da457c5285ac1f936ebd076af6dac17a61cfe7826f2076b4d015cf47bc8ec" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "termcolor" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "thiserror" +version = "1.0.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "978c9a314bd8dc99be594bc3c175faaa9794be04a5a5e153caba6915336cebac" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.13", +] + +[[package]] +name = "tiff" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7449334f9ff2baf290d55d73983a7d6fa15e01198faef72af07e2a8db851e471" +dependencies = [ + "flate2", + "jpeg-decoder", + "weezl", +] + +[[package]] +name = "unicode-ident" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4" + +[[package]] +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + +[[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 = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.84" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31f8dcbc21f30d9b8f2ea926ecb58f6b91192c17e9d33594b3df58b2007ca53b" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.84" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95ce90fd5bcc06af55a641a86428ee4229e44e07033963a2290a8e241607ccb9" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn 1.0.109", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.84" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c21f77c0bedc37fd5dc21f897894a5ca01e7bb159884559461862ae90c0b4c5" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.84" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.84" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0046fef7e28c3804e5e38bfa31ea2a0f73905319b677e57ebe37e49358989b5d" + +[[package]] +name = "wayland-backend" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79ebd48bfc1178c9190c7ff80cc822b3335ffc83141e9aa723168f377257623e" +dependencies = [ + "cc", + "downcast-rs", + "io-lifetimes", + "nix 0.26.2", + "scoped-tls", + "smallvec", + "wayland-sys", +] + +[[package]] +name = "wayland-client" +version = "0.30.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85bde68449abab1a808e5227b6e295f4ae3680911eb7711b4a2cb90141edb780" +dependencies = [ + "bitflags", + "calloop", + "nix 0.26.2", + "wayland-backend", + "wayland-scanner", +] + +[[package]] +name = "wayland-cursor" +version = "0.30.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d0c3a0d5b4b688b07b0442362d3ed6bf04724fcc16cd69ab6285b90dbc487aa" +dependencies = [ + "nix 0.26.2", + "wayland-client", + "xcursor", +] + +[[package]] +name = "wayland-protocols" +version = "0.30.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fefbeb8a360abe67ab7c2efe1d297a1a50ee011f5460791bc18870c26bb84e2" +dependencies = [ + "bitflags", + "wayland-backend", + "wayland-client", + "wayland-scanner", +] + +[[package]] +name = "wayland-protocols-wlr" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fce991093320e4a6a525876e6b629ab24da25f9baef0c2e0080ad173ec89588a" +dependencies = [ + "bitflags", + "wayland-backend", + "wayland-client", + "wayland-protocols", + "wayland-scanner", +] + +[[package]] +name = "wayland-scanner" +version = "0.30.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4834c14b3edf1d9986c83ca79b1e7e3afbe9874c7c144702f6467063259ce45d" +dependencies = [ + "proc-macro2", + "quick-xml", + "quote", +] + +[[package]] +name = "wayland-sys" +version = "0.30.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96b2a02ac608e07132978689a6f9bf4214949c85998c247abadd4f4129b1aa06" +dependencies = [ + "dlib", + "log", + "pkg-config", +] + +[[package]] +name = "weezl" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9193164d4de03a926d909d3bc7c30543cecb35400c02114792c2cae20d5e2dbb" + +[[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-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +dependencies = [ + "winapi", +] + +[[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.45.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" +dependencies = [ + "windows-targets 0.42.2", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.0", +] + +[[package]] +name = "windows-targets" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" +dependencies = [ + "windows_aarch64_gnullvm 0.42.2", + "windows_aarch64_msvc 0.42.2", + "windows_i686_gnu 0.42.2", + "windows_i686_msvc 0.42.2", + "windows_x86_64_gnu 0.42.2", + "windows_x86_64_gnullvm 0.42.2", + "windows_x86_64_msvc 0.42.2", +] + +[[package]] +name = "windows-targets" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b1eb6f0cd7c80c79759c929114ef071b87354ce476d9d94271031c0497adfd5" +dependencies = [ + "windows_aarch64_gnullvm 0.48.0", + "windows_aarch64_msvc 0.48.0", + "windows_i686_gnu 0.48.0", + "windows_i686_msvc 0.48.0", + "windows_x86_64_gnu 0.48.0", + "windows_x86_64_gnullvm 0.48.0", + "windows_x86_64_msvc 0.48.0", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" + +[[package]] +name = "windows_i686_gnu" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" + +[[package]] +name = "windows_i686_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" + +[[package]] +name = "xcursor" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "463705a63313cd4301184381c5e8042f0a7e9b4bb63653f216311d4ae74690b7" +dependencies = [ + "nom", +] + +[[package]] +name = "xkbcommon" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbee136714379ab22da0280207fdb7f47e0bb940adea97731b65598b8c7a92e" +dependencies = [ + "libc", + "memmap2", +] + +[[package]] +name = "zune-inflate" +version = "0.2.53" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "440a08fd59c6442e4b846ea9b10386c38307eae728b216e1ab2c305d1c9daaf8" +dependencies = [ + "simd-adler32", +] diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..c8be8d8 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "multibg-sway" +version = "0.1.0" +authors = ["Gergő Sályi "] +edition = "2021" +description = "Set a different wallpaper for the background of each Sway workspace" +license = "MIT OR Apache-2.0" +keywords = ["wallpaper", "background", "desktop", "wayland", "sway"] +categories = ["command-line-utilities", "multimedia::images"] + +[dependencies] +clap = { version = "4.2.1", features = ["derive"] } +env_logger = "0.10.0" +image = "0.24.6" +log = "0.4.17" +mio = { version = "0.8.6", features = ["os-ext", "os-poll"] } +swayipc = "3.0.1" + +[dependencies.smithay-client-toolkit] +git = "https://github.com/Smithay/client-toolkit.git" +rev = "389a4f21872a99a3ba346cc3dabd55c4079ec191" # master branch as of 2023-04-07 diff --git a/LICENSE-APACHE b/LICENSE-APACHE new file mode 100644 index 0000000..d085c25 --- /dev/null +++ b/LICENSE-APACHE @@ -0,0 +1,177 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + diff --git a/LICENSE-MIT b/LICENSE-MIT new file mode 100644 index 0000000..cba603f --- /dev/null +++ b/LICENSE-MIT @@ -0,0 +1,19 @@ +Copyright 2023 Gergő Sályi + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the “Software”), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..6ee0f03 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +# multibg-sway + +Set a different wallpaper for the background of each Sway workspace + diff --git a/src/cli.rs b/src/cli.rs new file mode 100644 index 0000000..9dc3e01 --- /dev/null +++ b/src/cli.rs @@ -0,0 +1,8 @@ +use clap::Parser; + +#[derive(Parser)] +#[command(author, version, about, long_about = None)] +pub struct Cli { + /// directory with: wallpaper_dir/output/workspace_name.{jpg|png|...} + pub wallpaper_dir: String, +} diff --git a/src/image.rs b/src/image.rs new file mode 100644 index 0000000..1793ad8 --- /dev/null +++ b/src/image.rs @@ -0,0 +1,147 @@ +use std::{ + fs::read_dir, + path::Path +}; + +use log::error; +use image::{ImageBuffer, Rgb, ImageError}; +use smithay_client_toolkit::shm::slot::{Buffer, SlotPool}; +use smithay_client_toolkit::reexports::client::protocol::wl_shm; + +use crate::wayland::WorkspaceBackground; + +pub fn workspace_bgs_from_output_image_dir( + dir_path: impl AsRef, + slot_pool: &mut SlotPool, + format: wl_shm::Format, +) + -> Result, String> +{ + let mut buffers = Vec::new(); + + let dir = read_dir(&dir_path) + .map_err(|e| format!("Failed to open directory: {}", e))?; + + for entry_result in dir { + + let entry = match entry_result { + Ok(entry) => entry, + Err(e) => { + error!( + "Skipping a directory entry in '{:?}' due to an error: {}", + dir_path.as_ref(), e + ); + continue; + } + }; + + // Resolve symlinks + let path = match entry.path().canonicalize() { + Ok(file_type) => file_type, + Err(e) => { + error!( + "Skipping '{:?}' in '{:?}' due to an error: {}", + entry.path(), dir_path.as_ref(), e + ); + continue; + } + }; + + // Skip dirs + if path.is_dir() { continue } + + // Use the file stem as the name of the workspace for this wallpaper + let workspace_name = path.file_stem().unwrap() + .to_string_lossy().into_owned(); + + let raw_image = match image::io::Reader::open(&path) + .map_err(ImageError::IoError) + .and_then(|r| r.with_guessed_format() + .map_err(ImageError::IoError) + ) + .and_then(|r| r.decode()) + { + Ok(raw_image) => raw_image, + Err(e) => { + error!( + "Failed to open image '{:?}': {}", + path, e + ); + continue; + } + }; + + let image = raw_image + // It is possible to adjust the contrast and brightness here + // .adjust_contrast(-25.0) + // .brighten(-60) + .into_rgb8(); + + let buffer = match format { + wl_shm::Format::Xrgb8888 => + buffer_xrgb8888_from_image(image, slot_pool), + wl_shm::Format::Bgr888 => + buffer_bgr888_from_image(image, slot_pool), + _ => unreachable!() + }; + + buffers.push(WorkspaceBackground { workspace_name, buffer }); + } + + if buffers.is_empty() { + Err("Found 0 suitable images in the directory".to_string()) + } + else { + Ok(buffers) + } +} + +fn buffer_xrgb8888_from_image( + image: ImageBuffer, Vec>, + slot_pool: &mut SlotPool, +) + -> Buffer +{ + let (buffer, canvas) = slot_pool + .create_buffer( + image.width() as i32, + image.height() as i32, + image.width() as i32 * 4, + wl_shm::Format::Xrgb8888 + ) + .unwrap(); + + let canvas_len = image.len() / 3 * 4; + + let image_pixels = image.pixels(); + let canvas_pixels = canvas[..canvas_len].chunks_exact_mut(4); + + for (image_pixel, canvas_pixel) in image_pixels.zip(canvas_pixels) { + canvas_pixel[0] = image_pixel.0[2]; + canvas_pixel[1] = image_pixel.0[1]; + canvas_pixel[2] = image_pixel.0[0]; + } + + buffer +} + +fn buffer_bgr888_from_image( + image: ImageBuffer, Vec>, + slot_pool: &mut SlotPool, +) + -> Buffer +{ + let (buffer, canvas) = slot_pool + .create_buffer( + image.width() as i32, + image.height() as i32, + image.width() as i32 * 3, + wl_shm::Format::Bgr888 + ) + .unwrap(); + + canvas[..image.len()].copy_from_slice(&image); + + buffer +} + diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..65cac47 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,182 @@ +mod cli; +mod image; +mod sway; +mod wayland; + +use std::{ + io, + os::fd::AsRawFd, + path::Path, + sync::{ + Arc, + mpsc::{channel, Receiver}, + } +}; + +use clap::Parser; +use log::error; +use mio::{ + Events, Interest, Poll, Token, Waker, + unix::SourceFd, +}; +use smithay_client_toolkit::{ + compositor::CompositorState, + output::OutputState, + registry::RegistryState, + shell::wlr_layer::LayerShell, + shm::{Shm, slot::SlotPool}, +}; +use smithay_client_toolkit::reexports::client::{ + Connection, EventQueue, + backend::{ReadEventsGuard, WaylandError}, + globals::registry_queue_init, +}; + +use crate::{ + cli::Cli, + sway::{SwayConnectionTask, WorkspaceVisible}, + wayland::State, +}; + +fn main() +{ + #[cfg(debug_assertions)] + env_logger::Builder::from_env( + env_logger::Env::default().default_filter_or( + "warn,multibg_sway=trace" + ) + ).init(); + + #[cfg(not(debug_assertions))] + env_logger::Builder::from_env( + env_logger::Env::default().default_filter_or("warn") + ).init(); + + let cli = Cli::parse(); + let wallpaper_dir = Path::new(&cli.wallpaper_dir).canonicalize().unwrap(); + + // ******************************** + // Initialize wayland client + // ******************************** + + let conn = Connection::connect_to_env().unwrap(); + let (globals, mut event_queue) = registry_queue_init(&conn).unwrap(); + let qh = event_queue.handle(); + + let compositor_state = CompositorState::bind(&globals, &qh).unwrap(); + let layer_shell = LayerShell::bind(&globals, &qh).unwrap(); + let shm = Shm::bind(&globals, &qh).unwrap(); + + // Initialize slot pool with a minimum size (0 is not allowed) + // it will be automatically resized later + let shm_slot_pool = SlotPool::new(1, &shm).unwrap(); + + // Sync tools for sway ipc tasks + let mut poll = Poll::new().unwrap(); + let waker = Arc::new(Waker::new(poll.registry(), SWAY).unwrap()); + let (tx, rx) = channel(); + + let mut state = State { + compositor_state, + registry_state: RegistryState::new(&globals), + output_state: OutputState::new(&globals, &qh), + shm, + shm_slot_pool, + layer_shell, + wallpaper_dir, + pixel_format: None, + background_layers: Vec::new(), + sway_connection_task: SwayConnectionTask::new( + tx.clone(), Arc::clone(&waker) + ), + }; + + event_queue.roundtrip(&mut state).unwrap(); + + // ******************************** + // Main event loop + // ******************************** + + let mut events = Events::with_capacity(16); + + const WAYLAND: Token = Token(0); + let read_guard = event_queue.prepare_read().unwrap(); + let wayland_socket_fd = read_guard.connection_fd().as_raw_fd(); + poll.registry().register( + &mut SourceFd(&wayland_socket_fd), + WAYLAND, + Interest::READABLE + ).unwrap(); + drop(read_guard); + + const SWAY: Token = Token(1); + SwayConnectionTask::new(tx, waker).spawn_subscribe_event_loop(); + + loop { + event_queue.flush().unwrap(); + event_queue.dispatch_pending(&mut state).unwrap(); + let mut read_guard_option = Some(event_queue.prepare_read().unwrap()); + + poll.poll(&mut events, None).unwrap(); + + for event in events.iter() { + match event.token() { + WAYLAND => handle_wayland_event( + &mut state, + &mut read_guard_option, + &mut event_queue + ), + SWAY => handle_sway_event(&mut state, &rx), + _ => unreachable!() + } + } + } +} + +fn handle_wayland_event( + state: &mut State, + read_guard_option: &mut Option, + event_queue: &mut EventQueue, +) { + if let Some(read_guard) = read_guard_option.take() { + if let Err(e) = read_guard.read() { + // WouldBlock is normal here because of epoll false wakeups + if let WaylandError::Io(ref io_err) = e { + if io_err.kind() == io::ErrorKind::WouldBlock { + return; + } + } + panic!("Failed to read Wayland events: {}", e) + } + + if let Err(e) = event_queue.dispatch_pending(state) { + panic!("Failed to dispatch pending Wayland events: {}", e); + } + } +} + +fn handle_sway_event( + state: &mut State, + rx: &Receiver, +) { + while let Ok(workspace) = rx.try_recv() + { + // Find the background layer that of the output where the workspace is + if let Some(affected_bg_layer) = state.background_layers.iter_mut() + .find(|bg_layer| bg_layer.output_name == workspace.output) + { + affected_bg_layer.draw_workspace_bg(&workspace.workspace_name); + } + else { + error!( + "Workspace '{}' is on an unknown output '{}', known outputs were: {}", + workspace.workspace_name, + workspace.output, + state.background_layers.iter() + .map(|bg_layer| bg_layer.output_name.as_str()) + .collect::>().join(", ") + ); + continue; + }; + } +} diff --git a/src/sway.rs b/src/sway.rs new file mode 100644 index 0000000..b3bf903 --- /dev/null +++ b/src/sway.rs @@ -0,0 +1,119 @@ +use std::{ + sync::{Arc, mpsc::Sender}, + thread::spawn, +}; + +use mio::Waker; +use swayipc::{Connection, Event, EventType, WorkspaceChange}; + +#[derive(Debug)] +pub struct WorkspaceVisible { + pub output: String, + pub workspace_name: String +} + +pub struct SwayConnectionTask { + sway_conn: Connection, + tx: Sender, + waker: Arc, +} +impl SwayConnectionTask +{ + pub fn new(tx: Sender, waker: Arc) -> Self { + SwayConnectionTask { + sway_conn: Connection::new() + .expect("Failed to connect to sway socket"), + tx, + waker + } + } + + pub fn request_visible_workspace(&mut self, output: &str) { + if let Some(workspace) = self.sway_conn.get_workspaces().unwrap() + .into_iter() + .filter(|w| w.visible) + .find(|w| w.output == output) + { + self.tx.send(WorkspaceVisible { + output: workspace.output, + workspace_name: workspace.name, + }).unwrap(); + + self.waker.wake().unwrap(); + } + } + + pub fn request_visible_workspaces(&mut self) { + for workspace in self.sway_conn.get_workspaces().unwrap() + .into_iter().filter(|w| w.visible) + { + self.tx.send(WorkspaceVisible { + output: workspace.output, + workspace_name: workspace.name, + }).unwrap(); + } + self.waker.wake().unwrap(); + } + + pub fn spawn_subscribe_event_loop(self) { + spawn(|| self.subscribe_event_loop()); + } + + fn subscribe_event_loop(self) { + let event_stream = self.sway_conn.subscribe([EventType::Workspace]) + .unwrap(); + for event_result in event_stream { + let event = event_result.unwrap(); + let Event::Workspace(workspace_event) = event else {continue}; + if let WorkspaceChange::Focus = workspace_event.change { + let current_workspace = workspace_event.current.unwrap(); + + self.tx.send(WorkspaceVisible { + output: current_workspace.output.unwrap(), + workspace_name: current_workspace.name.unwrap(), + }).unwrap(); + + self.waker.wake().unwrap(); + } + } + } +} + +// pub fn spawn_sway_events_loop_task(tx: Sender, waker: Waker) +// { +// spawn(|| sway_events_loop_task(tx, waker)); +// } +// +// pub fn sway_events_loop_task(tx: Sender, waker: Waker) +// { +// let mut sway_conn = Connection::new() +// .expect("Failed to connect to sway socket"); +// +// // Send the initial workspaces +// for workspace in sway_conn.get_workspaces().unwrap().into_iter() { +// if workspace.visible { +// tx.send(WorkspaceVisible { +// output: workspace.output, +// workspace_name: workspace.name, +// }).unwrap(); +// } +// } +// waker.wake().unwrap(); +// +// // Event loop +// let event_stream = sway_conn.subscribe([EventType::Workspace]).unwrap(); +// for event_result in event_stream { +// let event = event_result.unwrap(); +// let Event::Workspace(workspace_event) = event else {continue}; +// if let WorkspaceChange::Focus = workspace_event.change { +// let current_workspace = workspace_event.current.unwrap(); +// +// tx.send(WorkspaceVisible { +// output: current_workspace.output.unwrap(), +// workspace_name: current_workspace.name.unwrap(), +// }).unwrap(); +// +// waker.wake().unwrap(); +// } +// } +// } diff --git a/src/wayland.rs b/src/wayland.rs new file mode 100644 index 0000000..416f64b --- /dev/null +++ b/src/wayland.rs @@ -0,0 +1,386 @@ +use std::path::PathBuf; + +use log::{debug, error}; +use smithay_client_toolkit::{ + delegate_compositor, delegate_layer, delegate_output, delegate_registry, + delegate_shm, + compositor::{CompositorHandler, CompositorState}, + output::{OutputHandler, OutputState}, + registry::{ProvidesRegistryState, RegistryState}, + registry_handlers, + shell::{ + WaylandSurface, + wlr_layer::{ + KeyboardInteractivity, Layer, LayerShell, + LayerShellHandler, LayerSurface, LayerSurfaceConfigure, + }, + }, + shm::{ + Shm, ShmHandler, + slot::{Buffer, SlotPool}, + }, +}; +use smithay_client_toolkit::reexports::client::{ + Connection, QueueHandle, + protocol::{wl_output, wl_shm, wl_surface}, +}; + +use crate::{ + image::workspace_bgs_from_output_image_dir, + sway::SwayConnectionTask, +}; + +pub struct State { + pub compositor_state: CompositorState, + pub registry_state: RegistryState, + pub output_state: OutputState, + pub shm: Shm, + pub shm_slot_pool: SlotPool, + pub layer_shell: LayerShell, + pub wallpaper_dir: PathBuf, + pub pixel_format: Option, + pub background_layers: Vec, + pub sway_connection_task: SwayConnectionTask, +} + +impl State { + fn pixel_format(&mut self) -> wl_shm::Format { + *self.pixel_format.get_or_insert_with(|| { + // Consume less gpu memory by using Bgr888 if available, + // fall back to the always supported Xrgb8888 otherwise + for format in self.shm.formats() { + if let wl_shm::Format::Bgr888 = format { + debug!("Using pixel format: {:?}", format); + return *format + } + // XXX: One may add Rgb888 and HDR support here + } + debug!("Using default pixel format: Xrgb8888"); + + wl_shm::Format::Xrgb8888 + }) + } +} + +impl CompositorHandler for State +{ + fn scale_factor_changed( + &mut self, + _conn: &Connection, + _qh: &QueueHandle, + _surface: &wl_surface::WlSurface, + _new_factor: i32, + ) { + } + + fn frame( + &mut self, + _conn: &Connection, + _qh: &QueueHandle, + _surface: &wl_surface::WlSurface, + _time: u32, + ) { + } +} + +impl LayerShellHandler for State +{ + fn closed( + &mut self, + _conn: &Connection, + _qh: &QueueHandle, + _layer: &LayerSurface + ) { + } + + fn configure( + &mut self, + _conn: &Connection, + _qh: &QueueHandle, + layer: &LayerSurface, + _configure: LayerSurfaceConfigure, + _serial: u32, + ) { + // The new layer is ready: request all the visible workspace from sway, + // it will get picked up by the main event loop and be drawn from there + let bg_layer = self.background_layers.iter_mut() + .find(|bg_layer| &bg_layer.layer == layer).unwrap(); + + if !bg_layer.configured { + bg_layer.configured = true; + self.sway_connection_task + .request_visible_workspace(&bg_layer.output_name); + + debug!( + "Background layer has been configured for output: {}", + bg_layer.output_name + ); + } + } +} + +impl OutputHandler for State { + fn output_state(&mut self) -> &mut OutputState { + &mut self.output_state + } + + fn new_output( + &mut self, + _conn: &Connection, + qh: &QueueHandle, + output: wl_output::WlOutput, + ) { + let Some(info) = self.output_state.info(&output) + else { + error!("New output has no output info, skipping"); + return; + }; + + let Some(output_name) = info.name + else { + error!("New output has no name, skipping"); + return; + }; + + let Some((width, height)) = info.modes.iter() + .find(|mode| mode.current) + .map(|mode| mode.dimensions) + else { + error!( + "New output '{}' has no current mode set, skipping", + output_name + ); + return; + }; + + debug!( + "New output, name: {}, resolution: {}x{}", + output_name, width, height + ); + + let surface = self.compositor_state.create_surface(qh); + + let layer = self.layer_shell.create_layer_surface( + qh, + surface, + Layer::Background, + layer_surface_name(&output_name), + Some(&output) + ); + + layer.set_exclusive_zone(-1); // Don't let the status bar push it around + layer.set_keyboard_interactivity(KeyboardInteractivity::None); + layer.set_size(width as u32, height as u32); + + layer.commit(); + + let pixel_format = self.pixel_format(); + + let output_wallpaper_dir = self.wallpaper_dir.join(&output_name); + + let workspace_backgrounds = match workspace_bgs_from_output_image_dir( + &output_wallpaper_dir, + &mut self.shm_slot_pool, + pixel_format + ) { + Ok(workspace_bgs) => { + debug!( + "Loaded {} wallpapers on new output for workspaces: {}", + workspace_bgs.len(), + workspace_bgs.iter() + .map(|workspace_bg| workspace_bg.workspace_name.as_str()) + .collect::>().join(", ") + ); + workspace_bgs + }, + Err(e) => { + error!( + "Failed to get wallpapers for new output '{}' form '{:?}': {}", + output_name, output_wallpaper_dir, e + ); + return; + } + }; + + self.background_layers.push(BackgroundLayer { + output_name, + width, + height, + layer, + configured: false, + workspace_backgrounds, + }); + } + + fn update_output( + &mut self, + _conn: &Connection, + _qh: &QueueHandle, + _output: wl_output::WlOutput, + ) { + // This will only be needed if we implement scaling the wallpapers + // to the output resolution + // + // let Some(info) = self.output_state.info(&output) + // else { + // error!("Updated output has no output info, skipping"); + // return; + // }; + // + // let Some(name) = info.name + // else { + // error!("Updated output has no name, skipping"); + // return; + // }; + // + // let Some((width, height)) = info.modes.iter() + // .find(|mode| mode.current) + // .map(|mode| mode.dimensions) + // else { + // error!( + // "Updated output '{}' has no current mode set, skipping", + // name + // ); + // return; + // }; + // + // if let Some(bg_layer) = self.background_layers.iter() + // .find(|bg_layers| bg_layers.output_name == name) + // { + // if bg_layer.width == width && bg_layer.height == height { + // // if a known output has its resolution unchanged + // // then ignore this event + // return; + // } + // } + // + // // renew the output otherwise + // self.output_destroyed(conn, qh, output.clone()); + // self.new_output(conn, qh, output) + } + + fn output_destroyed( + &mut self, + _conn: &Connection, + _qh: &QueueHandle, + output: wl_output::WlOutput, + ) { + let Some(info) = self.output_state.info(&output) + else { + error!("Destroyed output has no output info, skipping"); + return; + }; + + let Some(name) = info.name + else { + error!("Destroyed output has no name, skipping"); + return; + }; + + if let Some(bg_layer_index) = self.background_layers.iter() + .position(|bg_layers| bg_layers.output_name == name) + { + self.background_layers.swap_remove(bg_layer_index); + + // Workspaces on the destroyed output may have been moved anywhere + // so reset the wallpaper on all the visible workspaces + self.sway_connection_task.request_visible_workspaces(); + + debug!("Destroyed output: {}", name); + } + else { + error!( + "Ignoring destroyed output with unknown name '{}', known outputs were: {}", + name, + self.background_layers.iter() + .map(|bg_layer| bg_layer.output_name.as_str()) + .collect::>().join(", ") + ); + } + } +} + +impl ProvidesRegistryState for State { + fn registry(&mut self) -> &mut RegistryState { + &mut self.registry_state + } + registry_handlers![OutputState]; +} + +impl ShmHandler for State { + fn shm_state(&mut self) -> &mut Shm { + &mut self.shm + } +} + +delegate_compositor!(State); +delegate_layer!(State); +delegate_output!(State); +delegate_registry!(State); +delegate_shm!(State); + +pub struct BackgroundLayer { + pub output_name: String, + pub width: i32, + pub height: i32, + pub layer: LayerSurface, + pub configured: bool, + pub workspace_backgrounds: Vec, +} +impl BackgroundLayer +{ + pub fn draw_workspace_bg(&mut self, workspace_name: &str) + { + if !self.configured { + error!( +"Cannot draw wallpaper image on the not yet configured layer for output: {}", + self.output_name + ); + return; + } + + let Some(workspace_bg) = self.workspace_backgrounds.iter() + .find(|workspace_bg| workspace_bg.workspace_name == workspace_name) + else { + error!( +"There is no wallpaper image on output '{}' for workspace '{}', only for: {}", + self.output_name, + workspace_name, + self.workspace_backgrounds.iter() + .map(|workspace_bg| workspace_bg.workspace_name.as_str()) + .collect::>().join(", ") + ); + return; + }; + + // Attach and commit to new workspace background + if let Err(e) = workspace_bg.buffer.attach_to(self.layer.wl_surface()) { + error!( + "Error attaching buffer of workspace '{}' on output '{}': {:#?}", + workspace_name, + self.output_name, + e + ); + return; + } + + // Damage the entire surface + self.layer.wl_surface().damage_buffer(0, 0, self.width, self.height); + + self.layer.commit(); + + debug!( + "Setting wallpaper on output '{}' for workspace: {}", + self.output_name, workspace_name + ); + } +} + +pub struct WorkspaceBackground { + pub workspace_name: String, + pub buffer: Buffer, +} + +fn layer_surface_name(output_name: &str) -> Option { + Some([env!("CARGO_PKG_NAME"), "_wallpaper_", output_name].concat()) +}