├── .gitignore ├── Cargo.lock ├── Cargo.toml ├── LICENSE ├── README.md └── src └── main.rs /.gitignore: -------------------------------------------------------------------------------- 1 | debug/ 2 | target/ 3 | aur/ 4 | -------------------------------------------------------------------------------- /Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 4 4 | 5 | [[package]] 6 | name = "addr2line" 7 | version = "0.24.2" 8 | source = "registry+https://github.com/rust-lang/crates.io-index" 9 | checksum = "dfbe277e56a376000877090da837660b4427aad530e3028d44e0bffe4f89a1c1" 10 | dependencies = [ 11 | "gimli", 12 | ] 13 | 14 | [[package]] 15 | name = "adler2" 16 | version = "2.0.0" 17 | source = "registry+https://github.com/rust-lang/crates.io-index" 18 | checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" 19 | 20 | [[package]] 21 | name = "anstream" 22 | version = "0.6.18" 23 | source = "registry+https://github.com/rust-lang/crates.io-index" 24 | checksum = "8acc5369981196006228e28809f761875c0327210a891e941f4c683b3a99529b" 25 | dependencies = [ 26 | "anstyle", 27 | "anstyle-parse", 28 | "anstyle-query", 29 | "anstyle-wincon", 30 | "colorchoice", 31 | "is_terminal_polyfill", 32 | "utf8parse", 33 | ] 34 | 35 | [[package]] 36 | name = "anstyle" 37 | version = "1.0.10" 38 | source = "registry+https://github.com/rust-lang/crates.io-index" 39 | checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9" 40 | 41 | [[package]] 42 | name = "anstyle-parse" 43 | version = "0.2.6" 44 | source = "registry+https://github.com/rust-lang/crates.io-index" 45 | checksum = "3b2d16507662817a6a20a9ea92df6652ee4f94f914589377d69f3b21bc5798a9" 46 | dependencies = [ 47 | "utf8parse", 48 | ] 49 | 50 | [[package]] 51 | name = "anstyle-query" 52 | version = "1.1.2" 53 | source = "registry+https://github.com/rust-lang/crates.io-index" 54 | checksum = "79947af37f4177cfead1110013d678905c37501914fba0efea834c3fe9a8d60c" 55 | dependencies = [ 56 | "windows-sys 0.59.0", 57 | ] 58 | 59 | [[package]] 60 | name = "anstyle-wincon" 61 | version = "3.0.6" 62 | source = "registry+https://github.com/rust-lang/crates.io-index" 63 | checksum = "2109dbce0e72be3ec00bed26e6a7479ca384ad226efdd66db8fa2e3a38c83125" 64 | dependencies = [ 65 | "anstyle", 66 | "windows-sys 0.59.0", 67 | ] 68 | 69 | [[package]] 70 | name = "autocfg" 71 | version = "1.4.0" 72 | source = "registry+https://github.com/rust-lang/crates.io-index" 73 | checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" 74 | 75 | [[package]] 76 | name = "backtrace" 77 | version = "0.3.74" 78 | source = "registry+https://github.com/rust-lang/crates.io-index" 79 | checksum = "8d82cb332cdfaed17ae235a638438ac4d4839913cc2af585c3c6746e8f8bee1a" 80 | dependencies = [ 81 | "addr2line", 82 | "cfg-if", 83 | "libc", 84 | "miniz_oxide", 85 | "object", 86 | "rustc-demangle", 87 | "windows-targets", 88 | ] 89 | 90 | [[package]] 91 | name = "bitflags" 92 | version = "2.6.0" 93 | source = "registry+https://github.com/rust-lang/crates.io-index" 94 | checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" 95 | 96 | [[package]] 97 | name = "bytes" 98 | version = "1.9.0" 99 | source = "registry+https://github.com/rust-lang/crates.io-index" 100 | checksum = "325918d6fe32f23b19878fe4b34794ae41fc19ddbe53b10571a4874d44ffd39b" 101 | 102 | [[package]] 103 | name = "cc" 104 | version = "1.2.4" 105 | source = "registry+https://github.com/rust-lang/crates.io-index" 106 | checksum = "9157bbaa6b165880c27a4293a474c91cdcf265cc68cc829bf10be0964a391caf" 107 | dependencies = [ 108 | "shlex", 109 | ] 110 | 111 | [[package]] 112 | name = "cfg-if" 113 | version = "1.0.0" 114 | source = "registry+https://github.com/rust-lang/crates.io-index" 115 | checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" 116 | 117 | [[package]] 118 | name = "clap" 119 | version = "4.5.39" 120 | source = "registry+https://github.com/rust-lang/crates.io-index" 121 | checksum = "fd60e63e9be68e5fb56422e397cf9baddded06dae1d2e523401542383bc72a9f" 122 | dependencies = [ 123 | "clap_builder", 124 | "clap_derive", 125 | ] 126 | 127 | [[package]] 128 | name = "clap_builder" 129 | version = "4.5.39" 130 | source = "registry+https://github.com/rust-lang/crates.io-index" 131 | checksum = "89cc6392a1f72bbeb820d71f32108f61fdaf18bc526e1d23954168a67759ef51" 132 | dependencies = [ 133 | "anstream", 134 | "anstyle", 135 | "clap_lex", 136 | "strsim", 137 | ] 138 | 139 | [[package]] 140 | name = "clap_derive" 141 | version = "4.5.32" 142 | source = "registry+https://github.com/rust-lang/crates.io-index" 143 | checksum = "09176aae279615badda0765c0c0b3f6ed53f4709118af73cf4655d85d1530cd7" 144 | dependencies = [ 145 | "heck", 146 | "proc-macro2", 147 | "quote", 148 | "syn", 149 | ] 150 | 151 | [[package]] 152 | name = "clap_lex" 153 | version = "0.7.4" 154 | source = "registry+https://github.com/rust-lang/crates.io-index" 155 | checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6" 156 | 157 | [[package]] 158 | name = "clapboard" 159 | version = "1.0.4" 160 | dependencies = [ 161 | "clap", 162 | "indexmap", 163 | "tokio", 164 | "toml", 165 | "wayland-clipboard-listener", 166 | "wl-clipboard-rs", 167 | "xdg", 168 | ] 169 | 170 | [[package]] 171 | name = "colorchoice" 172 | version = "1.0.3" 173 | source = "registry+https://github.com/rust-lang/crates.io-index" 174 | checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990" 175 | 176 | [[package]] 177 | name = "downcast-rs" 178 | version = "1.2.1" 179 | source = "registry+https://github.com/rust-lang/crates.io-index" 180 | checksum = "75b325c5dbd37f80359721ad39aca5a29fb04c89279657cffdda8736d0c0b9d2" 181 | 182 | [[package]] 183 | name = "equivalent" 184 | version = "1.0.1" 185 | source = "registry+https://github.com/rust-lang/crates.io-index" 186 | checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" 187 | 188 | [[package]] 189 | name = "errno" 190 | version = "0.3.10" 191 | source = "registry+https://github.com/rust-lang/crates.io-index" 192 | checksum = "33d852cb9b869c2a9b3df2f71a3074817f01e1844f839a144f5fcef059a4eb5d" 193 | dependencies = [ 194 | "libc", 195 | "windows-sys 0.59.0", 196 | ] 197 | 198 | [[package]] 199 | name = "fastrand" 200 | version = "2.3.0" 201 | source = "registry+https://github.com/rust-lang/crates.io-index" 202 | checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" 203 | 204 | [[package]] 205 | name = "fixedbitset" 206 | version = "0.4.2" 207 | source = "registry+https://github.com/rust-lang/crates.io-index" 208 | checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" 209 | 210 | [[package]] 211 | name = "fnv" 212 | version = "1.0.7" 213 | source = "registry+https://github.com/rust-lang/crates.io-index" 214 | checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" 215 | 216 | [[package]] 217 | name = "getrandom" 218 | version = "0.3.3" 219 | source = "registry+https://github.com/rust-lang/crates.io-index" 220 | checksum = "26145e563e54f2cadc477553f1ec5ee650b00862f0a58bcd12cbdc5f0ea2d2f4" 221 | dependencies = [ 222 | "cfg-if", 223 | "libc", 224 | "r-efi", 225 | "wasi 0.14.2+wasi-0.2.4", 226 | ] 227 | 228 | [[package]] 229 | name = "gimli" 230 | version = "0.31.1" 231 | source = "registry+https://github.com/rust-lang/crates.io-index" 232 | checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" 233 | 234 | [[package]] 235 | name = "hashbrown" 236 | version = "0.15.2" 237 | source = "registry+https://github.com/rust-lang/crates.io-index" 238 | checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" 239 | 240 | [[package]] 241 | name = "heck" 242 | version = "0.5.0" 243 | source = "registry+https://github.com/rust-lang/crates.io-index" 244 | checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" 245 | 246 | [[package]] 247 | name = "indexmap" 248 | version = "2.9.0" 249 | source = "registry+https://github.com/rust-lang/crates.io-index" 250 | checksum = "cea70ddb795996207ad57735b50c5982d8844f38ba9ee5f1aedcfb708a2aa11e" 251 | dependencies = [ 252 | "equivalent", 253 | "hashbrown", 254 | ] 255 | 256 | [[package]] 257 | name = "is_terminal_polyfill" 258 | version = "1.70.1" 259 | source = "registry+https://github.com/rust-lang/crates.io-index" 260 | checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" 261 | 262 | [[package]] 263 | name = "libc" 264 | version = "0.2.172" 265 | source = "registry+https://github.com/rust-lang/crates.io-index" 266 | checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa" 267 | 268 | [[package]] 269 | name = "linux-raw-sys" 270 | version = "0.4.14" 271 | source = "registry+https://github.com/rust-lang/crates.io-index" 272 | checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" 273 | 274 | [[package]] 275 | name = "linux-raw-sys" 276 | version = "0.9.4" 277 | source = "registry+https://github.com/rust-lang/crates.io-index" 278 | checksum = "cd945864f07fe9f5371a27ad7b52a172b4b499999f1d97574c9fa68373937e12" 279 | 280 | [[package]] 281 | name = "lock_api" 282 | version = "0.4.12" 283 | source = "registry+https://github.com/rust-lang/crates.io-index" 284 | checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" 285 | dependencies = [ 286 | "autocfg", 287 | "scopeguard", 288 | ] 289 | 290 | [[package]] 291 | name = "log" 292 | version = "0.4.27" 293 | source = "registry+https://github.com/rust-lang/crates.io-index" 294 | checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" 295 | 296 | [[package]] 297 | name = "memchr" 298 | version = "2.7.4" 299 | source = "registry+https://github.com/rust-lang/crates.io-index" 300 | checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" 301 | 302 | [[package]] 303 | name = "minimal-lexical" 304 | version = "0.2.1" 305 | source = "registry+https://github.com/rust-lang/crates.io-index" 306 | checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" 307 | 308 | [[package]] 309 | name = "miniz_oxide" 310 | version = "0.8.2" 311 | source = "registry+https://github.com/rust-lang/crates.io-index" 312 | checksum = "4ffbe83022cedc1d264172192511ae958937694cd57ce297164951b8b3568394" 313 | dependencies = [ 314 | "adler2", 315 | ] 316 | 317 | [[package]] 318 | name = "mio" 319 | version = "1.0.3" 320 | source = "registry+https://github.com/rust-lang/crates.io-index" 321 | checksum = "2886843bf800fba2e3377cff24abf6379b4c4d5c6681eaf9ea5b0d15090450bd" 322 | dependencies = [ 323 | "libc", 324 | "wasi 0.11.0+wasi-snapshot-preview1", 325 | "windows-sys 0.52.0", 326 | ] 327 | 328 | [[package]] 329 | name = "nom" 330 | version = "7.1.3" 331 | source = "registry+https://github.com/rust-lang/crates.io-index" 332 | checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" 333 | dependencies = [ 334 | "memchr", 335 | "minimal-lexical", 336 | ] 337 | 338 | [[package]] 339 | name = "object" 340 | version = "0.36.7" 341 | source = "registry+https://github.com/rust-lang/crates.io-index" 342 | checksum = "62948e14d923ea95ea2c7c86c71013138b66525b86bdc08d2dcc262bdb497b87" 343 | dependencies = [ 344 | "memchr", 345 | ] 346 | 347 | [[package]] 348 | name = "once_cell" 349 | version = "1.20.2" 350 | source = "registry+https://github.com/rust-lang/crates.io-index" 351 | checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" 352 | 353 | [[package]] 354 | name = "os_pipe" 355 | version = "1.2.1" 356 | source = "registry+https://github.com/rust-lang/crates.io-index" 357 | checksum = "5ffd2b0a5634335b135d5728d84c5e0fd726954b87111f7506a61c502280d982" 358 | dependencies = [ 359 | "libc", 360 | "windows-sys 0.59.0", 361 | ] 362 | 363 | [[package]] 364 | name = "parking_lot" 365 | version = "0.12.3" 366 | source = "registry+https://github.com/rust-lang/crates.io-index" 367 | checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" 368 | dependencies = [ 369 | "lock_api", 370 | "parking_lot_core", 371 | ] 372 | 373 | [[package]] 374 | name = "parking_lot_core" 375 | version = "0.9.10" 376 | source = "registry+https://github.com/rust-lang/crates.io-index" 377 | checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" 378 | dependencies = [ 379 | "cfg-if", 380 | "libc", 381 | "redox_syscall", 382 | "smallvec", 383 | "windows-targets", 384 | ] 385 | 386 | [[package]] 387 | name = "petgraph" 388 | version = "0.6.5" 389 | source = "registry+https://github.com/rust-lang/crates.io-index" 390 | checksum = "b4c5cc86750666a3ed20bdaf5ca2a0344f9c67674cae0515bec2da16fbaa47db" 391 | dependencies = [ 392 | "fixedbitset", 393 | "indexmap", 394 | ] 395 | 396 | [[package]] 397 | name = "pin-project-lite" 398 | version = "0.2.16" 399 | source = "registry+https://github.com/rust-lang/crates.io-index" 400 | checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" 401 | 402 | [[package]] 403 | name = "pkg-config" 404 | version = "0.3.31" 405 | source = "registry+https://github.com/rust-lang/crates.io-index" 406 | checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" 407 | 408 | [[package]] 409 | name = "proc-macro2" 410 | version = "1.0.92" 411 | source = "registry+https://github.com/rust-lang/crates.io-index" 412 | checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0" 413 | dependencies = [ 414 | "unicode-ident", 415 | ] 416 | 417 | [[package]] 418 | name = "quick-xml" 419 | version = "0.37.5" 420 | source = "registry+https://github.com/rust-lang/crates.io-index" 421 | checksum = "331e97a1af0bf59823e6eadffe373d7b27f485be8748f71471c662c1f269b7fb" 422 | dependencies = [ 423 | "memchr", 424 | ] 425 | 426 | [[package]] 427 | name = "quote" 428 | version = "1.0.37" 429 | source = "registry+https://github.com/rust-lang/crates.io-index" 430 | checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" 431 | dependencies = [ 432 | "proc-macro2", 433 | ] 434 | 435 | [[package]] 436 | name = "r-efi" 437 | version = "5.2.0" 438 | source = "registry+https://github.com/rust-lang/crates.io-index" 439 | checksum = "74765f6d916ee2faa39bc8e68e4f3ed8949b48cccdac59983d287a7cb71ce9c5" 440 | 441 | [[package]] 442 | name = "redox_syscall" 443 | version = "0.5.8" 444 | source = "registry+https://github.com/rust-lang/crates.io-index" 445 | checksum = "03a862b389f93e68874fbf580b9de08dd02facb9a788ebadaf4a3fd33cf58834" 446 | dependencies = [ 447 | "bitflags", 448 | ] 449 | 450 | [[package]] 451 | name = "rustc-demangle" 452 | version = "0.1.24" 453 | source = "registry+https://github.com/rust-lang/crates.io-index" 454 | checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" 455 | 456 | [[package]] 457 | name = "rustix" 458 | version = "0.38.44" 459 | source = "registry+https://github.com/rust-lang/crates.io-index" 460 | checksum = "fdb5bc1ae2baa591800df16c9ca78619bf65c0488b41b96ccec5d11220d8c154" 461 | dependencies = [ 462 | "bitflags", 463 | "errno", 464 | "libc", 465 | "linux-raw-sys 0.4.14", 466 | "windows-sys 0.59.0", 467 | ] 468 | 469 | [[package]] 470 | name = "rustix" 471 | version = "1.0.7" 472 | source = "registry+https://github.com/rust-lang/crates.io-index" 473 | checksum = "c71e83d6afe7ff64890ec6b71d6a69bb8a610ab78ce364b3352876bb4c801266" 474 | dependencies = [ 475 | "bitflags", 476 | "errno", 477 | "libc", 478 | "linux-raw-sys 0.9.4", 479 | "windows-sys 0.59.0", 480 | ] 481 | 482 | [[package]] 483 | name = "scopeguard" 484 | version = "1.2.0" 485 | source = "registry+https://github.com/rust-lang/crates.io-index" 486 | checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" 487 | 488 | [[package]] 489 | name = "serde" 490 | version = "1.0.152" 491 | source = "registry+https://github.com/rust-lang/crates.io-index" 492 | checksum = "bb7d1f0d3021d347a83e556fc4683dea2ea09d87bccdf88ff5c12545d89d5efb" 493 | 494 | [[package]] 495 | name = "serde_spanned" 496 | version = "0.6.8" 497 | source = "registry+https://github.com/rust-lang/crates.io-index" 498 | checksum = "87607cb1398ed59d48732e575a4c28a7a8ebf2454b964fe3f224f2afc07909e1" 499 | dependencies = [ 500 | "serde", 501 | ] 502 | 503 | [[package]] 504 | name = "shlex" 505 | version = "1.3.0" 506 | source = "registry+https://github.com/rust-lang/crates.io-index" 507 | checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" 508 | 509 | [[package]] 510 | name = "signal-hook-registry" 511 | version = "1.4.2" 512 | source = "registry+https://github.com/rust-lang/crates.io-index" 513 | checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" 514 | dependencies = [ 515 | "libc", 516 | ] 517 | 518 | [[package]] 519 | name = "smallvec" 520 | version = "1.13.2" 521 | source = "registry+https://github.com/rust-lang/crates.io-index" 522 | checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" 523 | 524 | [[package]] 525 | name = "socket2" 526 | version = "0.5.8" 527 | source = "registry+https://github.com/rust-lang/crates.io-index" 528 | checksum = "c970269d99b64e60ec3bd6ad27270092a5394c4e309314b18ae3fe575695fbe8" 529 | dependencies = [ 530 | "libc", 531 | "windows-sys 0.52.0", 532 | ] 533 | 534 | [[package]] 535 | name = "strsim" 536 | version = "0.11.1" 537 | source = "registry+https://github.com/rust-lang/crates.io-index" 538 | checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" 539 | 540 | [[package]] 541 | name = "syn" 542 | version = "2.0.90" 543 | source = "registry+https://github.com/rust-lang/crates.io-index" 544 | checksum = "919d3b74a5dd0ccd15aeb8f93e7006bd9e14c295087c9896a110f490752bcf31" 545 | dependencies = [ 546 | "proc-macro2", 547 | "quote", 548 | "unicode-ident", 549 | ] 550 | 551 | [[package]] 552 | name = "tempfile" 553 | version = "3.20.0" 554 | source = "registry+https://github.com/rust-lang/crates.io-index" 555 | checksum = "e8a64e3985349f2441a1a9ef0b853f869006c3855f2cda6862a94d26ebb9d6a1" 556 | dependencies = [ 557 | "fastrand", 558 | "getrandom", 559 | "once_cell", 560 | "rustix 1.0.7", 561 | "windows-sys 0.59.0", 562 | ] 563 | 564 | [[package]] 565 | name = "thiserror" 566 | version = "1.0.69" 567 | source = "registry+https://github.com/rust-lang/crates.io-index" 568 | checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" 569 | dependencies = [ 570 | "thiserror-impl 1.0.69", 571 | ] 572 | 573 | [[package]] 574 | name = "thiserror" 575 | version = "2.0.12" 576 | source = "registry+https://github.com/rust-lang/crates.io-index" 577 | checksum = "567b8a2dae586314f7be2a752ec7474332959c6460e02bde30d702a66d488708" 578 | dependencies = [ 579 | "thiserror-impl 2.0.12", 580 | ] 581 | 582 | [[package]] 583 | name = "thiserror-impl" 584 | version = "1.0.69" 585 | source = "registry+https://github.com/rust-lang/crates.io-index" 586 | checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" 587 | dependencies = [ 588 | "proc-macro2", 589 | "quote", 590 | "syn", 591 | ] 592 | 593 | [[package]] 594 | name = "thiserror-impl" 595 | version = "2.0.12" 596 | source = "registry+https://github.com/rust-lang/crates.io-index" 597 | checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d" 598 | dependencies = [ 599 | "proc-macro2", 600 | "quote", 601 | "syn", 602 | ] 603 | 604 | [[package]] 605 | name = "tokio" 606 | version = "1.45.1" 607 | source = "registry+https://github.com/rust-lang/crates.io-index" 608 | checksum = "75ef51a33ef1da925cea3e4eb122833cb377c61439ca401b770f54902b806779" 609 | dependencies = [ 610 | "backtrace", 611 | "bytes", 612 | "libc", 613 | "mio", 614 | "parking_lot", 615 | "pin-project-lite", 616 | "signal-hook-registry", 617 | "socket2", 618 | "tokio-macros", 619 | "windows-sys 0.52.0", 620 | ] 621 | 622 | [[package]] 623 | name = "tokio-macros" 624 | version = "2.5.0" 625 | source = "registry+https://github.com/rust-lang/crates.io-index" 626 | checksum = "6e06d43f1345a3bcd39f6a56dbb7dcab2ba47e68e8ac134855e7e2bdbaf8cab8" 627 | dependencies = [ 628 | "proc-macro2", 629 | "quote", 630 | "syn", 631 | ] 632 | 633 | [[package]] 634 | name = "toml" 635 | version = "0.8.22" 636 | source = "registry+https://github.com/rust-lang/crates.io-index" 637 | checksum = "05ae329d1f08c4d17a59bed7ff5b5a769d062e64a62d34a3261b219e62cd5aae" 638 | dependencies = [ 639 | "serde", 640 | "serde_spanned", 641 | "toml_datetime", 642 | "toml_edit", 643 | ] 644 | 645 | [[package]] 646 | name = "toml_datetime" 647 | version = "0.6.9" 648 | source = "registry+https://github.com/rust-lang/crates.io-index" 649 | checksum = "3da5db5a963e24bc68be8b17b6fa82814bb22ee8660f192bb182771d498f09a3" 650 | dependencies = [ 651 | "serde", 652 | ] 653 | 654 | [[package]] 655 | name = "toml_edit" 656 | version = "0.22.26" 657 | source = "registry+https://github.com/rust-lang/crates.io-index" 658 | checksum = "310068873db2c5b3e7659d2cc35d21855dbafa50d1ce336397c666e3cb08137e" 659 | dependencies = [ 660 | "indexmap", 661 | "serde", 662 | "serde_spanned", 663 | "toml_datetime", 664 | "toml_write", 665 | "winnow", 666 | ] 667 | 668 | [[package]] 669 | name = "toml_write" 670 | version = "0.1.1" 671 | source = "registry+https://github.com/rust-lang/crates.io-index" 672 | checksum = "bfb942dfe1d8e29a7ee7fcbde5bd2b9a25fb89aa70caea2eba3bee836ff41076" 673 | 674 | [[package]] 675 | name = "tree_magic_mini" 676 | version = "3.1.6" 677 | source = "registry+https://github.com/rust-lang/crates.io-index" 678 | checksum = "aac5e8971f245c3389a5a76e648bfc80803ae066a1243a75db0064d7c1129d63" 679 | dependencies = [ 680 | "fnv", 681 | "memchr", 682 | "nom", 683 | "once_cell", 684 | "petgraph", 685 | ] 686 | 687 | [[package]] 688 | name = "unicode-ident" 689 | version = "1.0.6" 690 | source = "registry+https://github.com/rust-lang/crates.io-index" 691 | checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" 692 | 693 | [[package]] 694 | name = "utf8parse" 695 | version = "0.2.2" 696 | source = "registry+https://github.com/rust-lang/crates.io-index" 697 | checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" 698 | 699 | [[package]] 700 | name = "wasi" 701 | version = "0.11.0+wasi-snapshot-preview1" 702 | source = "registry+https://github.com/rust-lang/crates.io-index" 703 | checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" 704 | 705 | [[package]] 706 | name = "wasi" 707 | version = "0.14.2+wasi-0.2.4" 708 | source = "registry+https://github.com/rust-lang/crates.io-index" 709 | checksum = "9683f9a5a998d873c0d21fcbe3c083009670149a8fab228644b8bd36b2c48cb3" 710 | dependencies = [ 711 | "wit-bindgen-rt", 712 | ] 713 | 714 | [[package]] 715 | name = "wayland-backend" 716 | version = "0.3.10" 717 | source = "registry+https://github.com/rust-lang/crates.io-index" 718 | checksum = "fe770181423e5fc79d3e2a7f4410b7799d5aab1de4372853de3c6aa13ca24121" 719 | dependencies = [ 720 | "cc", 721 | "downcast-rs", 722 | "rustix 0.38.44", 723 | "smallvec", 724 | "wayland-sys", 725 | ] 726 | 727 | [[package]] 728 | name = "wayland-client" 729 | version = "0.31.10" 730 | source = "registry+https://github.com/rust-lang/crates.io-index" 731 | checksum = "978fa7c67b0847dbd6a9f350ca2569174974cd4082737054dbb7fbb79d7d9a61" 732 | dependencies = [ 733 | "bitflags", 734 | "rustix 0.38.44", 735 | "wayland-backend", 736 | "wayland-scanner", 737 | ] 738 | 739 | [[package]] 740 | name = "wayland-clipboard-listener" 741 | version = "0.2.6" 742 | source = "registry+https://github.com/rust-lang/crates.io-index" 743 | checksum = "7b213d78fe3fcc17c39f80cdc8cc0015e3a31d4f781af1c52df442bc4c394d2f" 744 | dependencies = [ 745 | "os_pipe", 746 | "thiserror 1.0.69", 747 | "wayland-client", 748 | "wayland-protocols", 749 | "wayland-protocols-wlr", 750 | ] 751 | 752 | [[package]] 753 | name = "wayland-protocols" 754 | version = "0.32.8" 755 | source = "registry+https://github.com/rust-lang/crates.io-index" 756 | checksum = "779075454e1e9a521794fed15886323ea0feda3f8b0fc1390f5398141310422a" 757 | dependencies = [ 758 | "bitflags", 759 | "wayland-backend", 760 | "wayland-client", 761 | "wayland-scanner", 762 | ] 763 | 764 | [[package]] 765 | name = "wayland-protocols-wlr" 766 | version = "0.3.8" 767 | source = "registry+https://github.com/rust-lang/crates.io-index" 768 | checksum = "1cb6cdc73399c0e06504c437fe3cf886f25568dd5454473d565085b36d6a8bbf" 769 | dependencies = [ 770 | "bitflags", 771 | "wayland-backend", 772 | "wayland-client", 773 | "wayland-protocols", 774 | "wayland-scanner", 775 | ] 776 | 777 | [[package]] 778 | name = "wayland-scanner" 779 | version = "0.31.6" 780 | source = "registry+https://github.com/rust-lang/crates.io-index" 781 | checksum = "896fdafd5d28145fce7958917d69f2fd44469b1d4e861cb5961bcbeebc6d1484" 782 | dependencies = [ 783 | "proc-macro2", 784 | "quick-xml", 785 | "quote", 786 | ] 787 | 788 | [[package]] 789 | name = "wayland-sys" 790 | version = "0.31.6" 791 | source = "registry+https://github.com/rust-lang/crates.io-index" 792 | checksum = "dbcebb399c77d5aa9fa5db874806ee7b4eba4e73650948e8f93963f128896615" 793 | dependencies = [ 794 | "pkg-config", 795 | ] 796 | 797 | [[package]] 798 | name = "windows-sys" 799 | version = "0.52.0" 800 | source = "registry+https://github.com/rust-lang/crates.io-index" 801 | checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" 802 | dependencies = [ 803 | "windows-targets", 804 | ] 805 | 806 | [[package]] 807 | name = "windows-sys" 808 | version = "0.59.0" 809 | source = "registry+https://github.com/rust-lang/crates.io-index" 810 | checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" 811 | dependencies = [ 812 | "windows-targets", 813 | ] 814 | 815 | [[package]] 816 | name = "windows-targets" 817 | version = "0.52.6" 818 | source = "registry+https://github.com/rust-lang/crates.io-index" 819 | checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" 820 | dependencies = [ 821 | "windows_aarch64_gnullvm", 822 | "windows_aarch64_msvc", 823 | "windows_i686_gnu", 824 | "windows_i686_gnullvm", 825 | "windows_i686_msvc", 826 | "windows_x86_64_gnu", 827 | "windows_x86_64_gnullvm", 828 | "windows_x86_64_msvc", 829 | ] 830 | 831 | [[package]] 832 | name = "windows_aarch64_gnullvm" 833 | version = "0.52.6" 834 | source = "registry+https://github.com/rust-lang/crates.io-index" 835 | checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" 836 | 837 | [[package]] 838 | name = "windows_aarch64_msvc" 839 | version = "0.52.6" 840 | source = "registry+https://github.com/rust-lang/crates.io-index" 841 | checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" 842 | 843 | [[package]] 844 | name = "windows_i686_gnu" 845 | version = "0.52.6" 846 | source = "registry+https://github.com/rust-lang/crates.io-index" 847 | checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" 848 | 849 | [[package]] 850 | name = "windows_i686_gnullvm" 851 | version = "0.52.6" 852 | source = "registry+https://github.com/rust-lang/crates.io-index" 853 | checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" 854 | 855 | [[package]] 856 | name = "windows_i686_msvc" 857 | version = "0.52.6" 858 | source = "registry+https://github.com/rust-lang/crates.io-index" 859 | checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" 860 | 861 | [[package]] 862 | name = "windows_x86_64_gnu" 863 | version = "0.52.6" 864 | source = "registry+https://github.com/rust-lang/crates.io-index" 865 | checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" 866 | 867 | [[package]] 868 | name = "windows_x86_64_gnullvm" 869 | version = "0.52.6" 870 | source = "registry+https://github.com/rust-lang/crates.io-index" 871 | checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" 872 | 873 | [[package]] 874 | name = "windows_x86_64_msvc" 875 | version = "0.52.6" 876 | source = "registry+https://github.com/rust-lang/crates.io-index" 877 | checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" 878 | 879 | [[package]] 880 | name = "winnow" 881 | version = "0.7.10" 882 | source = "registry+https://github.com/rust-lang/crates.io-index" 883 | checksum = "c06928c8748d81b05c9be96aad92e1b6ff01833332f281e8cfca3be4b35fc9ec" 884 | dependencies = [ 885 | "memchr", 886 | ] 887 | 888 | [[package]] 889 | name = "wit-bindgen-rt" 890 | version = "0.39.0" 891 | source = "registry+https://github.com/rust-lang/crates.io-index" 892 | checksum = "6f42320e61fe2cfd34354ecb597f86f413484a798ba44a8ca1165c58d42da6c1" 893 | dependencies = [ 894 | "bitflags", 895 | ] 896 | 897 | [[package]] 898 | name = "wl-clipboard-rs" 899 | version = "0.9.2" 900 | source = "registry+https://github.com/rust-lang/crates.io-index" 901 | checksum = "8e5ff8d0e60065f549fafd9d6cb626203ea64a798186c80d8e7df4f8af56baeb" 902 | dependencies = [ 903 | "libc", 904 | "log", 905 | "os_pipe", 906 | "rustix 0.38.44", 907 | "tempfile", 908 | "thiserror 2.0.12", 909 | "tree_magic_mini", 910 | "wayland-backend", 911 | "wayland-client", 912 | "wayland-protocols", 913 | "wayland-protocols-wlr", 914 | ] 915 | 916 | [[package]] 917 | name = "xdg" 918 | version = "2.5.2" 919 | source = "registry+https://github.com/rust-lang/crates.io-index" 920 | checksum = "213b7324336b53d2414b2db8537e56544d981803139155afa84f76eeebb7a546" 921 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "clapboard" 3 | version = "1.0.4" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | xdg = "2.5.2" 10 | toml = "0.8.22" 11 | wl-clipboard-rs = "0.9.2" 12 | wayland-clipboard-listener = "0.2.6" 13 | clap = { version = "4.5.39", features = ["derive"] } 14 | tokio = { version = "1.45.1", features = ["full"] } 15 | indexmap = { version = "2.9.0", features = ["std"] } 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright 2022 Yoav Moshe 4 | 5 | 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: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | 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. 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Clapboard - clipboard manager that makes you clap 👏 2 | 3 | > [!NOTE] 4 | > Clapboard 1.0.0 is a complete rewrite of Clapboard 0.1.1. It works differently and needs to be run differently - see the Usage section. 5 | 6 | Clapboard is a simple clipboard manager for Wayland, built in Rust. It saves a history of your clipboard content, and lets you paste things you've copied earlier. It also lets you configure "favorite" pastes for strings you need often. For example, you can set favorites with your address, phone number, email address etc - and they'll all become just a few clicks away. It supports all mime-types and it is agnostic regarding to your choice of menu system (e.g. dmenu, tofi, wofi, rofl etc). You can even easily share your clipboard history across devices. 7 | 8 | [video.webm](https://user-images.githubusercontent.com/55081/211161880-63bb628c-e43d-4e46-9e77-85b5cabb8318.webm) 9 | 10 | ## Requirements 11 | 12 | - [tofi](https://github.com/philj56/tofi) or any other dmenu-like program ([wofi](https://hg.sr.ht/~scoopta/wofi), [rofi](https://github.com/lbonn/rofi), [dmenu](https://github.com/nyyManni/dmenu-wayland)) 13 | 14 | ## Installation 15 | 16 | ### From source 17 | 18 | - `git clone` the repository 19 | - Run `cargo build --release` 20 | - copy the `clapboard` executable to your PATH 21 | 22 | ### Arch Linux 23 | 24 | Clapboard is available on AUR as [clapboard-git](https://aur.archlinux.org/packages/clapboard-git). 25 | 26 | ## Usage 27 | 28 | - `clapboard --record` to record both [PRIMARY and CLIPBOARD](https://wiki.archlinux.org/title/Clipboard) 29 | - `clapboard` to open the menu 30 | 31 | If you're using Sway, just add this to your `~/.config/sway/config`: 32 | 33 | ``` 34 | exec clapboard --record 35 | ``` 36 | 37 | - Optionally, bind some key to run `clapboard`. I'm binding the Favorites key in Sway like this: 38 | ``` 39 | bindsym XF86Favorites exec clapboard 40 | ``` 41 | 42 | To share the clipboard content between devices, use a tool like [Syncthing](https://syncthing.net/) to sync the Clapboard cache folder (usually at `~/.cache/clapboard`). 43 | 44 | ## Configuration 45 | 46 | Below is the default Clapboard configuration. If you want to change it, create a similar file at `~/.config/clapboard/config.toml` 47 | 48 | ```toml 49 | launcher = [ "tofi", "--fuzzy-match=true", "--prompt-text=clap: " ] 50 | history_size = 50 51 | 52 | [favorites] 53 | # You can add your favorite clipboard pastes here like this: 54 | # "some key" = "some value" 55 | ``` 56 | 57 | ## Fun fact 58 | 59 | Clapboard was originally built in Python and later converted to Rust with the help of ChatGPT. 60 | -------------------------------------------------------------------------------- /src/main.rs: -------------------------------------------------------------------------------- 1 | use clap::Parser; 2 | use indexmap::IndexMap; 3 | use std::path::Path; 4 | use std::path::PathBuf; 5 | use std::{ 6 | fs, 7 | io::{self, Read, Write}, 8 | process::{Command, Stdio}, 9 | }; 10 | use std::{ 11 | fs::File, 12 | io::copy, 13 | time::{SystemTime, UNIX_EPOCH}, 14 | }; 15 | use tokio::task; 16 | use toml::Value; 17 | use wayland_clipboard_listener::WlClipboardPasteStream; 18 | use wayland_clipboard_listener::WlListenType; 19 | use wl_clipboard_rs::copy::{MimeSource, MimeType, Options, Source}; 20 | use wl_clipboard_rs::paste::{get_contents, ClipboardType, Seat}; 21 | use xdg::BaseDirectories; 22 | 23 | /// Clapboard, a clipboard manager for Wayland 24 | #[derive(Parser, Debug)] 25 | #[command(version, about, long_about = None)] 26 | struct Args { 27 | /// Record mode, choose between "primary", "clipboard", or the default "both" 28 | #[arg(short, long, num_args(0..=1), default_missing_value = "both")] 29 | record: Option, 30 | } 31 | 32 | #[tokio::main] 33 | async fn main() { 34 | let args = Args::parse(); 35 | 36 | let xdg_dirs = BaseDirectories::with_prefix("clapboard").unwrap(); 37 | let config_path = xdg_dirs 38 | .place_config_file("config.toml") 39 | .expect("cannot create configuration directory"); 40 | 41 | let toml_string = fs::read_to_string(config_path).unwrap_or(String::from("")); 42 | let value: Value = toml::from_str(&toml_string).unwrap(); 43 | 44 | let default_launcher = vec!["tofi", "--fuzzy-match=true", "--prompt-text=clapboard: "]; 45 | 46 | let default_launcher_values: Vec = default_launcher 47 | .iter() 48 | .map(|x| Value::String(x.to_string())) 49 | .collect(); 50 | let default_launcher_value = Value::Array(default_launcher_values); 51 | let launcher = value 52 | .get("launcher") 53 | .unwrap_or_else(|| &default_launcher_value) 54 | .as_array(); 55 | 56 | let history_size = value 57 | .get("history_size") 58 | .and_then(|v| v.as_integer()) 59 | .unwrap_or(50) as usize; 60 | 61 | let default_favorites_value = Value::Table(toml::value::Table::new()); 62 | let favorites = value 63 | .get("favorites") 64 | .unwrap_or_else(|| &default_favorites_value) 65 | .as_table() 66 | .unwrap(); 67 | 68 | let cache_dir = xdg_dirs.get_cache_home(); 69 | 70 | match args.record { 71 | Some(record) => { 72 | println!("Clapboard recording {record}..."); 73 | let listeners = match record.as_str() { 74 | "primary" => vec!["primary"], 75 | "clipboard" => vec!["clipboard"], 76 | "both" => vec!["primary", "clipboard"], 77 | _ => vec![], 78 | }; 79 | 80 | // Spawn tasks for each listener 81 | let tasks: Vec<_> = listeners 82 | .iter() 83 | .map(|&paste_type| { 84 | task::spawn(listen_to_clipboard( 85 | paste_type, 86 | cache_dir.clone(), 87 | history_size, 88 | )) 89 | }) 90 | .collect(); 91 | 92 | // Await each task individually 93 | for task in tasks { 94 | let _ = task.await; 95 | } 96 | } 97 | None => { 98 | let mut data: IndexMap = IndexMap::new(); 99 | 100 | let mut entries: Vec<_> = fs::read_dir(&cache_dir) 101 | .unwrap() // Handle the Result from read_dir 102 | .flatten() // Flatten the Result> to just DirEntry 103 | .collect(); // Collect into a vector of DirEntry 104 | 105 | // Sort entries by file name (ascending order) 106 | entries.sort_by(|a, b| b.file_name().cmp(&a.file_name())); 107 | 108 | // Iterate over sorted entries 109 | for entry in entries { 110 | if entry.path().is_dir() { 111 | let timestamp = entry.file_name().into_string().unwrap_or_default(); 112 | let text_files = 113 | vec!["UTF8_STRING", "TEXT", "text.plain", "text.html", "STRING"]; 114 | let mut found_file = false; 115 | let mut content = String::new(); 116 | for file_name in text_files { 117 | let textual_representation = entry.path().join(file_name); 118 | 119 | if textual_representation.exists() { 120 | let mut file = File::open(&textual_representation).unwrap(); 121 | if file.read_to_string(&mut content).is_ok() { 122 | found_file = true; 123 | break; 124 | } 125 | } 126 | } 127 | if found_file { 128 | data.insert( 129 | content 130 | .trim() 131 | .to_string() 132 | .replace("\n", " ") 133 | .chars() 134 | .take(50) // Avoid long text 135 | .collect(), 136 | timestamp.to_string(), 137 | ); 138 | } else { 139 | // If no file was found, proceed with the else logic 140 | println!("No textfile found for: {}", timestamp.to_string()); 141 | data.entry(timestamp.to_string()) 142 | .or_insert_with(|| timestamp.to_string()); 143 | } 144 | } 145 | } 146 | for (key, value) in favorites { 147 | data.entry(key.parse().unwrap()) 148 | .or_insert_with(|| value.as_str().unwrap().to_string()); 149 | } 150 | 151 | let input = data.keys().cloned().collect::>().join("\n"); 152 | let command_name = launcher.unwrap()[0].as_str().unwrap(); 153 | let mut command = Command::new(command_name); 154 | for arg in &launcher.unwrap()[1..] { 155 | command.arg(arg.as_str().unwrap()); 156 | } 157 | 158 | let output = command 159 | .stdin(Stdio::piped()) 160 | .stdout(Stdio::piped()) 161 | .spawn() 162 | .and_then(|mut child| { 163 | child.stdin.as_mut().unwrap().write_all(input.as_bytes())?; 164 | child.wait_with_output() 165 | }) 166 | .unwrap_or_else(|_| panic!("Cannot start your launcher, please confirm you have {} installed or configure another one", command_name)); 167 | 168 | let mut result = String::from_utf8_lossy(&output.stdout).into_owned(); 169 | result.pop(); // Remove trailing new line 170 | if result.len() > 0 { 171 | let mut opts = Options::new(); 172 | opts.foreground(true); // We need to keep the process alive for pasting to work 173 | if favorites.contains_key(&result) { 174 | opts.copy( 175 | Source::Bytes( 176 | data.get(&result) 177 | .unwrap() 178 | .to_string() 179 | .into_bytes() 180 | .into_boxed_slice(), 181 | ), 182 | MimeType::Autodetect, 183 | ) 184 | .expect("Failed to copy to clipboard"); 185 | } else { 186 | let prefix = data.get(&result).unwrap().as_str(); 187 | let sources: Vec = 188 | fs::read_dir(format!("{}{}", cache_dir.to_str().unwrap(), prefix)) 189 | .unwrap() 190 | .flatten() 191 | .filter_map(|entry| { 192 | let path = entry.path(); 193 | let mime_type = path 194 | .file_name()? 195 | .to_string_lossy() 196 | .to_string() 197 | .replacen(".", "/", 1); 198 | fs::read(&path).ok().map(|contents| MimeSource { 199 | source: Source::Bytes(contents.into()), 200 | mime_type: MimeType::Specific(mime_type), 201 | }) 202 | }) 203 | .collect(); 204 | 205 | if !sources.is_empty() { 206 | opts.copy_multi(sources) 207 | .expect("Failed to copy to clipboard"); 208 | } 209 | } 210 | } 211 | } 212 | } 213 | } 214 | 215 | async fn listen_to_clipboard(paste_type: &str, cache_dir: PathBuf, history_size: usize) { 216 | let mut stream = WlClipboardPasteStream::init(match paste_type { 217 | "primary" => WlListenType::ListenOnSelect, 218 | _ => WlListenType::ListenOnCopy, 219 | }) 220 | .unwrap(); 221 | 222 | for context in stream.paste_stream().flatten().flatten() { 223 | let timestamp = SystemTime::now() 224 | .duration_since(UNIX_EPOCH) 225 | .unwrap() 226 | .as_millis(); 227 | for mime in context.mime_types { 228 | match get_contents( 229 | match paste_type { 230 | "primary" => ClipboardType::Primary, 231 | _ => ClipboardType::Regular, 232 | }, 233 | Seat::Unspecified, 234 | wl_clipboard_rs::paste::MimeType::Specific(&mime), 235 | ) { 236 | Ok((mut reader, _)) => { 237 | let path = format!("{}{}", cache_dir.to_str().unwrap(), timestamp); 238 | fs::create_dir_all(Path::new(&path)).unwrap(); 239 | let file_path = format!("{}/{}", &path, mime.replace("/", ".")); 240 | match File::create(&file_path) { 241 | Ok(mut file) => { 242 | if let Err(e) = copy(&mut reader, &mut file) { 243 | eprintln!("Failed to copy content to {}: {}", file_path, e); 244 | } 245 | } 246 | Err(e) => { 247 | eprintln!("Failed to create file {}: {}", file_path, e); 248 | } 249 | } 250 | } 251 | Err(err) => eprintln!("Clipboard {paste_type:?} error: {}", err), 252 | } 253 | } 254 | clean_history(&cache_dir, history_size).unwrap(); 255 | } 256 | } 257 | 258 | fn clean_history(directory: &Path, max: usize) -> io::Result<()> { 259 | let mut entries: Vec<_> = fs::read_dir(directory)? 260 | .filter_map(|entry| entry.ok()) // Ignore any errors in reading entries 261 | .collect(); 262 | 263 | entries.sort_by(|a, b| b.file_name().cmp(&a.file_name())); 264 | 265 | for (index, entry) in entries.into_iter().enumerate() { 266 | if index > max { 267 | let path = entry.path(); 268 | if path.is_dir() 269 | && !path 270 | .file_name() 271 | .unwrap_or_default() 272 | .to_string_lossy() 273 | .starts_with('.') 274 | { 275 | fs::remove_dir_all(&path)?; 276 | } 277 | } 278 | } 279 | Ok(()) 280 | } 281 | --------------------------------------------------------------------------------