Added Wayland clipboard support. (#666)

* Fixed MPRIS OpenUri function not respecting ncspot's shuffle setting.

* Added support for Wayland clipboard.

* Formatted code properly using cargo fmt.

* Added is_wayland() function to check if using Wayland.

* Added wayland_clipboard feature flag.
It can be used to enable Wayland clipboard support.
Changed is_wayland() function to check wayland related environment
variables at runtime and not compile time.
This commit is contained in:
Bettehem
2021-12-09 12:55:44 +02:00
committed by GitHub
parent beec2867f0
commit 3324094974
3 changed files with 647 additions and 41 deletions

492
Cargo.lock generated
View File

@@ -2,6 +2,21 @@
# It is not intended for manual editing.
version = 3
[[package]]
name = "addr2line"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9ecd88a8c8378ca913a680cd98f0f13ac67383d35993f86c90a70e3f137816b"
dependencies = [
"gimli",
]
[[package]]
name = "adler"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
[[package]]
name = "aes"
version = "0.6.0"
@@ -62,7 +77,7 @@ version = "0.7.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f"
dependencies = [
"memchr",
"memchr 2.4.1",
]
[[package]]
@@ -146,12 +161,12 @@ dependencies = [
[[package]]
name = "atty"
version = "0.2.14"
version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
checksum = "9a7d5b8723950951411ee34d271d99dddcc2035a16ab25310ea2c8cfd4369652"
dependencies = [
"hermit-abi",
"libc",
"termion",
"winapi",
]
@@ -161,6 +176,21 @@ version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
[[package]]
name = "backtrace"
version = "0.3.63"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "321629d8ba6513061f26707241fa9bc89524ff1cd7a915a97ef0c62c666ce1b6"
dependencies = [
"addr2line",
"cc",
"cfg-if 1.0.0",
"libc",
"miniz_oxide",
"object",
"rustc-demangle",
]
[[package]]
name = "base-x"
version = "0.2.8"
@@ -182,7 +212,7 @@ dependencies = [
"bitflags",
"cexpr",
"clang-sys",
"lazy_static",
"lazy_static 1.4.0",
"lazycell",
"peeking_take_while",
"proc-macro2",
@@ -269,7 +299,7 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f4aedb84272dbe89af497cf81375129abda4fc0a9e7c5d317498c15cc30c0d27"
dependencies = [
"nom",
"nom 5.1.2",
]
[[package]]
@@ -335,6 +365,7 @@ dependencies = [
"atty",
"bitflags",
"strsim 0.8.0",
"term_size",
"textwrap",
"unicode-width",
"vec_map",
@@ -362,6 +393,15 @@ dependencies = [
"winapi",
]
[[package]]
name = "cloudabi"
version = "0.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f"
dependencies = [
"bitflags",
]
[[package]]
name = "combine"
version = "4.6.2"
@@ -369,7 +409,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b2b2f5d0ee456f3928812dfc8c6d9a1d592b98678f6d56db9b0cd2b7bc6c8db5"
dependencies = [
"bytes",
"memchr",
"memchr 2.4.1",
]
[[package]]
@@ -393,6 +433,12 @@ version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc"
[[package]]
name = "convert_case"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e"
[[package]]
name = "cookie"
version = "0.15.1"
@@ -467,14 +513,14 @@ dependencies = [
"coreaudio-rs",
"jni",
"js-sys",
"lazy_static",
"lazy_static 1.4.0",
"libc",
"mach",
"ndk 0.3.0",
"ndk-glue 0.3.0",
"nix 0.20.0",
"oboe",
"parking_lot",
"parking_lot 0.11.2",
"stdweb 0.1.3",
"thiserror",
"web-sys",
@@ -507,7 +553,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d82cfc11ce7f2c3faef78d8a684447b40d503d9681acebed6cb728d45940c4db"
dependencies = [
"cfg-if 1.0.0",
"lazy_static",
"lazy_static 1.4.0",
]
[[package]]
@@ -539,7 +585,7 @@ dependencies = [
"cfg-if 1.0.0",
"crossbeam-channel",
"cursive_core",
"lazy_static",
"lazy_static 1.4.0",
"libc",
"log",
"maplit",
@@ -562,7 +608,7 @@ dependencies = [
"chrono",
"crossbeam-channel",
"enum-map",
"lazy_static",
"lazy_static 1.4.0",
"libc",
"log",
"num",
@@ -640,6 +686,30 @@ dependencies = [
"syn",
]
[[package]]
name = "derive-new"
version = "0.5.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3418329ca0ad70234b9735dc4ceed10af4df60eff9c8e7b06cb5e520d92c3535"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "derive_more"
version = "0.99.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321"
dependencies = [
"convert_case",
"proc-macro2",
"quote",
"rustc_version 0.4.0",
"syn",
]
[[package]]
name = "digest"
version = "0.9.0"
@@ -687,6 +757,12 @@ version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0"
[[package]]
name = "downcast-rs"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650"
[[package]]
name = "encoding_rs"
version = "0.8.29"
@@ -738,6 +814,37 @@ dependencies = [
"syn",
]
[[package]]
name = "exitfailure"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2ff5bd832af37f366c6c194d813a11cd90ac484f124f079294f28e357ae40515"
dependencies = [
"failure",
]
[[package]]
name = "failure"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d32e9bd16cc02eae7db7ef620b392808b89f6a5e16bb3497d159c6b92a0f4f86"
dependencies = [
"backtrace",
"failure_derive",
]
[[package]]
name = "failure_derive"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa4da3c766cd7a0db8242e326e9e4e081edd567072893ed320008189715366a4"
dependencies = [
"proc-macro2",
"quote",
"syn",
"synstructure",
]
[[package]]
name = "fastrand"
version = "1.5.0"
@@ -756,6 +863,12 @@ dependencies = [
"log",
]
[[package]]
name = "fixedbitset"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37ab347416e802de484e4d03c7316c48f1ecb56574dfd4a46a80f173ce1de04d"
[[package]]
name = "fnv"
version = "1.0.7"
@@ -850,7 +963,7 @@ dependencies = [
"fastrand",
"futures-core",
"futures-io",
"memchr",
"memchr 2.4.1",
"parking",
"pin-project-lite",
"waker-fn",
@@ -892,7 +1005,7 @@ dependencies = [
"futures-macro",
"futures-sink",
"futures-task",
"memchr",
"memchr 2.4.1",
"pin-project-lite",
"pin-utils",
"slab",
@@ -930,6 +1043,12 @@ dependencies = [
"wasi 0.10.0+wasi-snapshot-preview1",
]
[[package]]
name = "gimli"
version = "0.26.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78cc372d058dcf6d5ecd98510e7fbc9e5aec4d21de70f65fea8fecebcd881bd4"
[[package]]
name = "glob"
version = "0.3.0"
@@ -1201,6 +1320,12 @@ dependencies = [
"wasm-bindgen",
]
[[package]]
name = "lazy_static"
version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "76f033c7ad61445c5b347c7382dd1237847eb1bce590fe50365dcb33d546be73"
[[package]]
name = "lazy_static"
version = "1.4.0"
@@ -1414,6 +1539,15 @@ dependencies = [
"protobuf-codegen-pure",
]
[[package]]
name = "lock_api"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4da24a77a3d8a6d4862d95f72e6fdb9c09a643ecdb402d754004a557f2bec75"
dependencies = [
"scopeguard",
]
[[package]]
name = "lock_api"
version = "0.4.5"
@@ -1485,6 +1619,15 @@ dependencies = [
"syn",
]
[[package]]
name = "memchr"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "148fab2e51b4f1cfc66da2a7c32981d1d3c083a803978268bb11fe4b86925e7a"
dependencies = [
"libc",
]
[[package]]
name = "memchr"
version = "2.4.1"
@@ -1497,6 +1640,26 @@ version = "0.3.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d"
[[package]]
name = "mime_guess"
version = "2.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2684d4c2e97d99848d30b324b00c8fcc7e5c897b7cbb5819b09e7c90e8baf212"
dependencies = [
"mime",
"unicase",
]
[[package]]
name = "miniz_oxide"
version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a92518e98c078586bc6c934028adcca4c92a53d6a958196de835170a01d84e4b"
dependencies = [
"adler",
"autocfg",
]
[[package]]
name = "mio"
version = "0.7.14"
@@ -1525,7 +1688,7 @@ version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "48ba9f7719b5a0f42f338907614285fb5fd70e53858141f69898a1fb7203b24d"
dependencies = [
"lazy_static",
"lazy_static 1.4.0",
"libc",
"log",
"openssl",
@@ -1561,7 +1724,7 @@ dependencies = [
"fern",
"futures 0.3.18",
"ioctl-rs",
"lazy_static",
"lazy_static 1.4.0",
"librespot-core",
"librespot-playback",
"librespot-protocol",
@@ -1584,6 +1747,7 @@ dependencies = [
"unicode-width",
"url",
"webbrowser",
"wl-clipboard-rs",
]
[[package]]
@@ -1628,7 +1792,7 @@ version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c5caf0c24d51ac1c905c27d4eda4fa0635bbe0de596b8f79235e0b17a4d29385"
dependencies = [
"lazy_static",
"lazy_static 1.4.0",
"libc",
"log",
"ndk 0.3.0",
@@ -1642,7 +1806,7 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3e9e94628f24e7a3cb5b96a2dc5683acd9230bf11991c2a1677b87695138420"
dependencies = [
"lazy_static",
"lazy_static 1.4.0",
"libc",
"log",
"ndk 0.4.0",
@@ -1682,6 +1846,18 @@ dependencies = [
"void",
]
[[package]]
name = "nix"
version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "83450fe6a6142ddd95fb064b746083fc4ef1705fe81f64a64e1d4b39f54a1055"
dependencies = [
"bitflags",
"cc",
"cfg-if 0.1.10",
"libc",
]
[[package]]
name = "nix"
version = "0.20.0"
@@ -1694,13 +1870,22 @@ dependencies = [
"libc",
]
[[package]]
name = "nom"
version = "3.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "05aec50c70fd288702bcd93284a8444607f3292dbdf2a30de5ea5dcdbe72287b"
dependencies = [
"memchr 1.0.2",
]
[[package]]
name = "nom"
version = "5.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ffb4262d26ed83a1c0a33a38fe2bb15797329c85770da05e6b828ddb782627af"
dependencies = [
"memchr",
"memchr 2.4.1",
"version_check",
]
@@ -1881,6 +2066,15 @@ dependencies = [
"objc",
]
[[package]]
name = "object"
version = "0.27.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "67ac1d3f9a1d3616fd9a60c8d74296f22406a238b6a72f5cc1e6f314df4ffbf9"
dependencies = [
"memchr 2.4.1",
]
[[package]]
name = "oboe"
version = "0.4.4"
@@ -1958,6 +2152,16 @@ dependencies = [
"vcpkg",
]
[[package]]
name = "os_pipe"
version = "0.9.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fb233f06c2307e1f5ce2ecad9f8121cffbbee2c95428f44ea85222e460d0d213"
dependencies = [
"libc",
"winapi",
]
[[package]]
name = "owning_ref"
version = "0.4.1"
@@ -1999,6 +2203,16 @@ version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "427c3892f9e783d91cc128285287e70a59e206ca452770ece88a76f7a3eddd72"
[[package]]
name = "parking_lot"
version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3a704eb390aafdc107b0e392f56a82b668e3a71366993b5340f5833fd62505e"
dependencies = [
"lock_api 0.3.4",
"parking_lot_core 0.7.2",
]
[[package]]
name = "parking_lot"
version = "0.11.2"
@@ -2006,8 +2220,22 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99"
dependencies = [
"instant",
"lock_api",
"parking_lot_core",
"lock_api 0.4.5",
"parking_lot_core 0.8.5",
]
[[package]]
name = "parking_lot_core"
version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d58c7c768d4ba344e3e8d72518ac13e259d7c7ade24167003b8488e10b6740a3"
dependencies = [
"cfg-if 0.1.10",
"cloudabi",
"libc",
"redox_syscall 0.1.57",
"smallvec",
"winapi",
]
[[package]]
@@ -2056,6 +2284,16 @@ version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e"
[[package]]
name = "petgraph"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "467d164a6de56270bd7c4d070df81d07beace25012d5103ced4e9ff08d6afdb7"
dependencies = [
"fixedbitset",
"indexmap",
]
[[package]]
name = "pin-project-lite"
version = "0.2.7"
@@ -2152,6 +2390,30 @@ dependencies = [
"toml",
]
[[package]]
name = "proc-macro-error"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
dependencies = [
"proc-macro-error-attr",
"proc-macro2",
"quote",
"syn",
"version_check",
]
[[package]]
name = "proc-macro-error-attr"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
dependencies = [
"proc-macro2",
"quote",
"version_check",
]
[[package]]
name = "proc-macro-hack"
version = "0.5.19"
@@ -2321,7 +2583,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461"
dependencies = [
"aho-corasick",
"memchr",
"memchr 2.4.1",
"regex-syntax",
]
@@ -2357,7 +2619,7 @@ dependencies = [
"hyper-tls",
"ipnet",
"js-sys",
"lazy_static",
"lazy_static 1.4.0",
"log",
"mime",
"native-tls",
@@ -2464,6 +2726,12 @@ dependencies = [
"crossbeam-utils",
]
[[package]]
name = "rustc-demangle"
version = "0.1.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342"
[[package]]
name = "rustc-hash"
version = "1.1.0"
@@ -2533,7 +2801,7 @@ version = "0.1.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f05ba609c234e60bee0d547fe94a4c7e9da733d1c962cf6e59efa4cd9c8bc75"
dependencies = [
"lazy_static",
"lazy_static 1.4.0",
"winapi",
]
@@ -2788,6 +3056,19 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
[[package]]
name = "stderrlog"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32e5ee9b90a5452c570a0b0ac1c99ae9498db7e56e33d74366de7f2a7add7f25"
dependencies = [
"atty",
"chrono",
"log",
"termcolor",
"thread_local",
]
[[package]]
name = "stdweb"
version = "0.1.3"
@@ -2855,6 +3136,30 @@ version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6446ced80d6c486436db5c078dde11a9f73d42b57fb273121e160b84f63d894c"
[[package]]
name = "structopt"
version = "0.3.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "40b9788f4202aa75c240ecc9c15c65185e6a39ccdeb0fd5d008b98825464c87c"
dependencies = [
"clap",
"lazy_static 1.4.0",
"structopt-derive",
]
[[package]]
name = "structopt-derive"
version = "0.4.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dcb5ae327f9cc13b68763b5749770cb9e048a99bd9dfdfa58d0cf05d5f64afe0"
dependencies = [
"heck",
"proc-macro-error",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "strum"
version = "0.22.0"
@@ -2951,6 +3256,15 @@ dependencies = [
"winapi",
]
[[package]]
name = "termcolor"
version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4"
dependencies = [
"winapi-util",
]
[[package]]
name = "termion"
version = "1.5.6"
@@ -2969,6 +3283,7 @@ version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
dependencies = [
"term_size",
"unicode-width",
]
@@ -2992,6 +3307,16 @@ dependencies = [
"syn",
]
[[package]]
name = "thread_local"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1697c4b57aeeb7a536b647165a2825faddffb1d3bad386d507709bd51a90bb14"
dependencies = [
"lazy_static 0.2.11",
"unreachable",
]
[[package]]
name = "time"
version = "0.1.44"
@@ -3065,7 +3390,7 @@ dependencies = [
"autocfg",
"bytes",
"libc",
"memchr",
"memchr 2.4.1",
"mio",
"num_cpus",
"pin-project-lite",
@@ -3151,7 +3476,20 @@ version = "0.1.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f4ed65637b8390770814083d20756f87bfa2c21bf2f110babdc5438351746e4"
dependencies = [
"lazy_static",
"lazy_static 1.4.0",
]
[[package]]
name = "tree_magic"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1d99367ce3e553a84738f73bd626ccca541ef90ae757fdcdc4cbe728e6cb629"
dependencies = [
"fnv",
"lazy_static 1.4.0",
"nom 3.2.1",
"parking_lot 0.10.2",
"petgraph",
]
[[package]]
@@ -3166,6 +3504,15 @@ version = "1.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b63708a265f51345575b27fe43f9500ad611579e764c79edbc2037b1121959ec"
[[package]]
name = "unicase"
version = "2.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6"
dependencies = [
"version_check",
]
[[package]]
name = "unicode-bidi"
version = "0.3.7"
@@ -3199,6 +3546,15 @@ version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
[[package]]
name = "unreachable"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56"
dependencies = [
"void",
]
[[package]]
name = "untrusted"
version = "0.7.1"
@@ -3337,7 +3693,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a317bf8f9fba2476b4b2c85ef4c4af8ff39c3c7f0cdfeed4f82c34a880aa837b"
dependencies = [
"bumpalo",
"lazy_static",
"lazy_static 1.4.0",
"log",
"proc-macro2",
"quote",
@@ -3408,6 +3764,65 @@ dependencies = [
"syn",
]
[[package]]
name = "wayland-client"
version = "0.27.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ab702fefbcd6d6f67fb5816e3a89a3b5a42a94290abbc015311c9a30d1068ae4"
dependencies = [
"bitflags",
"downcast-rs",
"libc",
"nix 0.17.0",
"wayland-commons",
"wayland-scanner",
"wayland-sys",
]
[[package]]
name = "wayland-commons"
version = "0.27.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e972e9336ad5a9dd861b4e21ff35ad71d3e5c6b4803d65c39913612f851b95f1"
dependencies = [
"nix 0.17.0",
"once_cell",
"smallvec",
"wayland-sys",
]
[[package]]
name = "wayland-protocols"
version = "0.27.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f3d6fc54b17b98b5083bc21ae3a30e6d75cb4b01647360e4c3a04648bcf8781d"
dependencies = [
"bitflags",
"wayland-client",
"wayland-commons",
"wayland-scanner",
]
[[package]]
name = "wayland-scanner"
version = "0.27.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "030f56009d932bd9400bb472764fea8109be1b0fc482d9cd75496c943ac30328"
dependencies = [
"proc-macro2",
"quote",
"xml-rs",
]
[[package]]
name = "wayland-sys"
version = "0.27.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8bdeffbbb474477dfa2acb45ac7479e5fe8f741c64ab032c5d11b94d07edc269"
dependencies = [
"pkg-config",
]
[[package]]
name = "web-sys"
version = "0.3.55"
@@ -3559,6 +3974,29 @@ dependencies = [
"xml-rs",
]
[[package]]
name = "wl-clipboard-rs"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23d00076f424455f5988a18c7d7433fc7f919d6f4c685f663439cf7b4c65a288"
dependencies = [
"derive-new",
"derive_more",
"exitfailure",
"failure",
"libc",
"log",
"mime_guess",
"nix 0.18.0",
"os_pipe",
"stderrlog",
"structopt",
"tempfile",
"tree_magic",
"wayland-client",
"wayland-protocols",
]
[[package]]
name = "x11-clipboard"
version = "0.3.3"

View File

@@ -38,6 +38,7 @@ dbus-tree = { version = "0.9.2", optional = true }
rand = "0.8"
webbrowser = "0.5"
clipboard = { version = "0.5", optional = true }
wl-clipboard-rs = { version = "0.4", optional = true }
url = "2.2"
strum = "0.23.0"
strum_macros = "0.23.1"
@@ -57,7 +58,8 @@ default-features = false
[features]
share_clipboard = ["clipboard"]
share_selection = ["clipboard"] # Use the primary selection for sharing - linux only
wayland_clipboard = ["wl-clipboard-rs"] # Support wayland clipboard - linux only
share_selection = ["clipboard", "wl-clipboard-rs"] # Use the primary selection for sharing - linux only
alsa_backend = ["librespot-playback/alsa-backend"]
pulseaudio_backend = ["librespot-playback/pulseaudio-backend"]
rodio_backend = ["librespot-playback/rodio-backend"]

View File

@@ -1,35 +1,201 @@
#![cfg(feature = "share_clipboard")]
use std::env;
#[cfg(feature = "wayland_clipboard")]
use {
std::io::Read,
wl_clipboard_rs::{
copy,
copy::{Options, Source},
paste,
paste::{get_contents, Error, Seat},
},
};
#[cfg(feature = "share_selection")]
use clipboard::x11_clipboard::{Primary, X11ClipboardContext};
use clipboard::{x11_clipboard, x11_clipboard::X11ClipboardContext};
#[cfg(feature = "share_selection")]
use wl_clipboard_rs::utils::{is_primary_selection_supported, PrimarySelectionCheckError};
#[cfg(not(feature = "share_selection"))]
use clipboard::ClipboardContext;
use clipboard::ClipboardProvider;
fn is_wayland() -> bool {
fn session_type() -> String {
env::var("XDG_SESSION_TYPE").unwrap_or_default()
}
fn wl_display() -> String {
env::var("WAYLAND_DISPLAY").unwrap_or_default()
}
fn gdk_backend() -> String {
env::var("GDK_BACKEND").unwrap_or_default()
}
session_type().as_str() == "wayland" || !wl_display().is_empty() || gdk_backend() == "wayland"
}
#[cfg(not(feature = "share_selection"))]
pub fn read_share() -> Option<String> {
ClipboardProvider::new()
.and_then(|mut ctx: ClipboardContext| ctx.get_contents())
.ok()
if is_wayland() {
#[allow(unused_mut, unused_assignments)]
let mut string = None;
#[cfg(feature = "wayland_clipboard")]
{
//use wayland clipboard
let result = get_contents(
paste::ClipboardType::Regular,
Seat::Unspecified,
paste::MimeType::Text,
);
match result {
Ok((mut pipe, _)) => {
let mut contents = vec![];
pipe.read_to_end(&mut contents).ok();
string = Some(String::from_utf8_lossy(&contents).to_string())
}
Err(Error::NoSeats) | Err(Error::ClipboardEmpty) | Err(Error::NoMimeType) => {
//The clipboard is empty or doesn't contain text, nothing to worry about.
string = None
}
Err(err) => {
eprintln!("{}", err);
string = None
}
}
}
if let Some(s) = string {
Some(s)
} else {
None
}
} else {
//use x11 clipboard
ClipboardProvider::new()
.and_then(|mut ctx: ClipboardContext| ctx.get_contents())
.ok()
}
}
#[cfg(feature = "share_selection")]
pub fn read_share() -> Option<String> {
ClipboardProvider::new()
.and_then(|mut ctx: X11ClipboardContext<Primary>| ctx.get_contents())
.ok()
if is_wayland() {
#[allow(unused_mut, unused_assignments)]
let mut string = None;
#[cfg(feature = "wayland_clipboard")]
{
//use wayland clipboard
match is_primary_selection_supported() {
Ok(supported) => {
let result = get_contents(
paste::ClipboardType::Primary,
Seat::Unspecified,
paste::MimeType::Text,
);
match result {
Ok((mut pipe, _)) => {
let mut contents = vec![];
pipe.read_to_end(&mut contents).ok();
Some(String::from_utf8_lossy(&contents).to_string())
}
Err(Error::NoSeats)
| Err(Error::ClipboardEmpty)
| Err(Error::NoMimeType) => {
//The clipboard is empty or doesn't contain text, nothing to worry about.
None
}
Err(err) => {
eprintln!("{}", err);
None
}
}
}
Err(PrimarySelectionCheckError::NoSeats) => {
// Impossible to give a definitive result. Primary selection may or may not be
// supported.
// The required protocol (data-control version 2) is there, but there are no seats.
// Unfortunately, at least one seat is needed to check for the primary clipboard support.
None
}
Err(PrimarySelectionCheckError::MissingProtocol { .. }) => {
// The data-control protocol (required for wl-clipboard-rs operation) is not
// supported by the compositor.
None
}
Err(err) => {
eprintln!("{}", err);
None
}
}
}
if let Some(s) = string {
Some(s)
} else {
None
}
} else {
//use x11 clipboard
ClipboardProvider::new()
.and_then(|mut ctx: X11ClipboardContext<x11_clipboard::Primary>| ctx.get_contents())
.ok()
}
}
#[cfg(not(feature = "share_selection"))]
pub fn write_share(url: String) -> Option<()> {
ClipboardProvider::new()
.and_then(|mut ctx: ClipboardContext| ctx.set_contents(url))
.ok()
if is_wayland() {
#[allow(unused_mut, unused_assignments)]
let mut option = None;
#[cfg(feature = "wayland_clipboard")]
{
//use wayland clipboard
let opts = Options::new();
option = opts
.copy(
Source::Bytes(url.into_bytes().into()),
copy::MimeType::Autodetect,
)
.ok()
}
if let Some(o) = option {
Some(o)
} else {
None
}
} else {
//use x11 clipboard
ClipboardProvider::new()
.and_then(|mut ctx: ClipboardContext| ctx.set_contents(url))
.ok()
}
}
#[cfg(feature = "share_selection")]
pub fn write_share(url: String) -> Option<()> {
ClipboardProvider::new()
.and_then(|mut ctx: X11ClipboardContext<Primary>| ctx.set_contents(url))
.ok()
if is_wayland() {
#[allow(unused_mut, unused_assignments)]
let mut option = None;
#[cfg(feature = "wayland_clipboard")]
{
//use wayland clipboard
let mut opts = Options::new();
opts.clipboard(copy::ClipboardType::Primary);
option = opts
.copy(
Source::Bytes(url.into_bytes().into()),
copy::MimeType::Autodetect,
)
.ok()
}
if let Some(o) = option {
Some(o)
} else {
None
}
} else {
//use x11 clipboard
ClipboardProvider::new()
.and_then(|mut ctx: X11ClipboardContext<x11_clipboard::Primary>| ctx.set_contents(url))
.ok()
}
}