[
  {
    "path": ".builds/freebsd.yml",
    "content": "image: freebsd/latest\n\npackages:\n  - lang/python3\n  - lang/gcc\n  - x11/libxcb\n  - x11/libxkbcommon\n\nsources:\n  - https://github.com/alacritty/copypasta\n\nenvironment:\n  PATH: /home/build/.cargo/bin:/bin:/usr/bin:/usr/local/bin\n  RUSTFLAGS: -L /usr/local/lib\n\ntasks:\n  - rustup: |\n      curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain stable --profile minimal\n  - test: |\n      cd copypasta\n      cargo test\n  - clippy: |\n      cd copypasta\n      rustup component add clippy\n      cargo clippy --all-targets\n  - oldstable: |\n      cd copypasta\n      rustup toolchain install --profile minimal 1.71.0\n      cargo +1.71.0 test\n"
  },
  {
    "path": ".builds/linux.yml",
    "content": "image: archlinux\n\npackages:\n  - libxcb\n  - libxkbcommon\n\nsources:\n  - https://github.com/alacritty/copypasta\n\nenvironment:\n  PATH: /home/build/.cargo/bin:/usr/bin/\n\ntasks:\n  - rustup: |\n      curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain stable --profile minimal\n  - test: |\n      cd copypasta\n      cargo test\n  - rustfmt: |\n      cd copypasta\n      rustup toolchain install nightly -c rustfmt\n      cargo +nightly fmt -- --check\n  - clippy: |\n      cd copypasta\n      rustup component add clippy\n      cargo clippy --all-targets\n  - oldstable: |\n      cd copypasta\n      rustup toolchain install --profile minimal 1.71.0\n      cargo +1.71.0 test\n"
  },
  {
    "path": ".github/workflows/ci.yml",
    "content": "name: CI\n\non: [push, pull_request]\n\nenv:\n  CARGO_TERM_COLOR: always\n\njobs:\n  build:\n    strategy:\n      matrix:\n        os: [windows-latest, macos-latest]\n\n    runs-on: ${{ matrix.os }}\n\n    steps:\n      - uses: actions/checkout@v2\n      - name: Stable\n        run: cargo test\n      - name: Clippy\n        run: |\n          rustup component add clippy\n          cargo clippy --all-targets\n      - name: Oldstable\n        run: |\n          rustup default 1.71.0\n          cargo clean\n          cargo test\n"
  },
  {
    "path": ".gitignore",
    "content": "/target\nCargo.lock\n"
  },
  {
    "path": "CHANGELOG.md",
    "content": "# Changelog\n\nAll notable changes to this project will be documented in this file.\n\nThe format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),\nand this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).\n\n## 0.10.2\n\n### Packaging\n\n- Minimum Rust version was bumped to `1.71.0`\n- Switched from `objc` to `objc2`\n- New default `wayland-dlopen` feature, to control `libwayland` linking\n\n## 0.10.1\n\n### Packaging\n\n- Minimum rust version was bumped to `1.66.0`\n- `x11_clipboard` was bumped to `0.9.1`\n\n## 0.10.0\n\n### Changed\n\n- Use `String` in `ClipboardProvider::set_contents` for trait to be *object-safe*\n\n## 0.9.0\n\n- Bump minimum supported Rust version to `1.65.0`\n- Change `ClipboardProvider::set_contents` parameter type to `AsRef<str>`\n- Prefer file's path over text on macOS\n\n## 0.8.2\n\n### Packaging\n\n- Minimum rust version was bumped to `1.60.0`\n\n### Fixed\n\n- `x11_clipboard` was bumped to `0.7.0` droping `quick-xml` from the deps tree\n\n\n## 0.8.1 \n\n### Fixed\n\n- Crash on use-after-free on macOS\n\n## 0.8.0\n\n### Packaging\n\n- Minimum rust version was bumped to `1.57.0`\n\n### Fixed\n\n- Memory leak on macOS\n\n## 0.7.1\n\n### Changed\n\n- Updated `smithay-clipboard` to 0.6.0\n\n## 0.7.0\n\n### Packaging\n\n- Minimum rust version was bumped to `1.41.0`\n\n### Removed\n\n- Ability to create a Wayland clipboard from Display type directly using `create_clipboard`\n\n## 0.6.3\n\n### Added\n\n- Features `x11` and `wayland` for picking the linux backends\n\n## 0.6.2\n\n### Fixed\n\n- Compilation on iOS, using the no-op clipboard\n"
  },
  {
    "path": "Cargo.toml",
    "content": "[package]\nname = \"copypasta\"\nversion = \"0.10.2\"\nauthors = [\"Christian Duerr <contact@christianduerr.com>\"]\ndescription = \"copypasta is a cross-platform library for getting and setting the contents of the OS-level clipboard.\"\nrepository = \"https://github.com/alacritty/copypasta\"\ndocumentation = \"https://docs.rs/copypasta\"\nreadme = \"README.md\"\nlicense = \"MIT / Apache-2.0\"\nkeywords = [\"clipboard\"]\nexclude = [\"/.travis.yml\"]\nedition = \"2021\"\nrust-version = \"1.71.0\"\n\n[features]\ndefault = [\"x11\", \"wayland\", \"wayland-dlopen\"]\nx11 = [\"x11-clipboard\"]\nwayland = [\"smithay-clipboard\"]\nwayland-dlopen = [\"smithay-clipboard/dlopen\"]\n\n[target.'cfg(windows)'.dependencies]\nclipboard-win = { version = \"5.4.0\", features = [\"std\"]}\n\n[target.'cfg(target_os = \"macos\")'.dependencies]\nobjc2 = \"0.6.1\"\nobjc2-foundation = { version = \"0.3.1\", default-features = false, features = [\n    \"std\",\n    \"NSArray\",\n    \"NSString\",\n    \"NSURL\",\n] }\nobjc2-app-kit = { version = \"0.3.1\", default-features = false, features = [\n    \"std\",\n    \"NSPasteboard\",\n] }\n\n[target.'cfg(all(unix, not(any(target_os=\"macos\", target_os=\"android\", target_os=\"ios\", target_os=\"emscripten\"))))'.dependencies]\nx11-clipboard = { version = \"0.9.1\", optional = true }\nsmithay-clipboard = { version = \"0.7.0\", default-features = false, optional = true }\n"
  },
  {
    "path": "LICENSE.apache2",
    "content": "Apache License\n                           Version 2.0, January 2004\n                        http://www.apache.org/licenses/\n\n   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n\n   1. Definitions.\n\n      \"License\" shall mean the terms and conditions for use, reproduction,\n      and distribution as defined by Sections 1 through 9 of this document.\n\n      \"Licensor\" shall mean the copyright owner or entity authorized by\n      the copyright owner that is granting the License.\n\n      \"Legal Entity\" shall mean the union of the acting entity and all\n      other entities that control, are controlled by, or are under common\n      control with that entity. For the purposes of this definition,\n      \"control\" means (i) the power, direct or indirect, to cause the\n      direction or management of such entity, whether by contract or\n      otherwise, or (ii) ownership of fifty percent (50%) or more of the\n      outstanding shares, or (iii) beneficial ownership of such entity.\n\n      \"You\" (or \"Your\") shall mean an individual or Legal Entity\n      exercising permissions granted by this License.\n\n      \"Source\" form shall mean the preferred form for making modifications,\n      including but not limited to software source code, documentation\n      source, and configuration files.\n\n      \"Object\" form shall mean any form resulting from mechanical\n      transformation or translation of a Source form, including but\n      not limited to compiled object code, generated documentation,\n      and conversions to other media types.\n\n      \"Work\" shall mean the work of authorship, whether in Source or\n      Object form, made available under the License, as indicated by a\n      copyright notice that is included in or attached to the work\n      (an example is provided in the Appendix below).\n\n      \"Derivative Works\" shall mean any work, whether in Source or Object\n      form, that is based on (or derived from) the Work and for which the\n      editorial revisions, annotations, elaborations, or other modifications\n      represent, as a whole, an original work of authorship. For the purposes\n      of this License, Derivative Works shall not include works that remain\n      separable from, or merely link (or bind by name) to the interfaces of,\n      the Work and Derivative Works thereof.\n\n      \"Contribution\" shall mean any work of authorship, including\n      the original version of the Work and any modifications or additions\n      to that Work or Derivative Works thereof, that is intentionally\n      submitted to Licensor for inclusion in the Work by the copyright owner\n      or by an individual or Legal Entity authorized to submit on behalf of\n      the copyright owner. For the purposes of this definition, \"submitted\"\n      means any form of electronic, verbal, or written communication sent\n      to the Licensor or its representatives, including but not limited to\n      communication on electronic mailing lists, source code control systems,\n      and issue tracking systems that are managed by, or on behalf of, the\n      Licensor for the purpose of discussing and improving the Work, but\n      excluding communication that is conspicuously marked or otherwise\n      designated in writing by the copyright owner as \"Not a Contribution.\"\n\n      \"Contributor\" shall mean Licensor and any individual or Legal Entity\n      on behalf of whom a Contribution has been received by Licensor and\n      subsequently incorporated within the Work.\n\n   2. Grant of Copyright License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      copyright license to reproduce, prepare Derivative Works of,\n      publicly display, publicly perform, sublicense, and distribute the\n      Work and such Derivative Works in Source or Object form.\n\n   3. Grant of Patent License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      (except as stated in this section) patent license to make, have made,\n      use, offer to sell, sell, import, and otherwise transfer the Work,\n      where such license applies only to those patent claims licensable\n      by such Contributor that are necessarily infringed by their\n      Contribution(s) alone or by combination of their Contribution(s)\n      with the Work to which such Contribution(s) was submitted. If You\n      institute patent litigation against any entity (including a\n      cross-claim or counterclaim in a lawsuit) alleging that the Work\n      or a Contribution incorporated within the Work constitutes direct\n      or contributory patent infringement, then any patent licenses\n      granted to You under this License for that Work shall terminate\n      as of the date such litigation is filed.\n\n   4. Redistribution. You may reproduce and distribute copies of the\n      Work or Derivative Works thereof in any medium, with or without\n      modifications, and in Source or Object form, provided that You\n      meet the following conditions:\n\n      (a) You must give any other recipients of the Work or\n          Derivative Works a copy of this License; and\n\n      (b) You must cause any modified files to carry prominent notices\n          stating that You changed the files; and\n\n      (c) You must retain, in the Source form of any Derivative Works\n          that You distribute, all copyright, patent, trademark, and\n          attribution notices from the Source form of the Work,\n          excluding those notices that do not pertain to any part of\n          the Derivative Works; and\n\n      (d) If the Work includes a \"NOTICE\" text file as part of its\n          distribution, then any Derivative Works that You distribute must\n          include a readable copy of the attribution notices contained\n          within such NOTICE file, excluding those notices that do not\n          pertain to any part of the Derivative Works, in at least one\n          of the following places: within a NOTICE text file distributed\n          as part of the Derivative Works; within the Source form or\n          documentation, if provided along with the Derivative Works; or,\n          within a display generated by the Derivative Works, if and\n          wherever such third-party notices normally appear. The contents\n          of the NOTICE file are for informational purposes only and\n          do not modify the License. You may add Your own attribution\n          notices within Derivative Works that You distribute, alongside\n          or as an addendum to the NOTICE text from the Work, provided\n          that such additional attribution notices cannot be construed\n          as modifying the License.\n\n      You may add Your own copyright statement to Your modifications and\n      may provide additional or different license terms and conditions\n      for use, reproduction, or distribution of Your modifications, or\n      for any such Derivative Works as a whole, provided Your use,\n      reproduction, and distribution of the Work otherwise complies with\n      the conditions stated in this License.\n\n   5. Submission of Contributions. Unless You explicitly state otherwise,\n      any Contribution intentionally submitted for inclusion in the Work\n      by You to the Licensor shall be under the terms and conditions of\n      this License, without any additional terms or conditions.\n      Notwithstanding the above, nothing herein shall supersede or modify\n      the terms of any separate license agreement you may have executed\n      with Licensor regarding such Contributions.\n\n   6. Trademarks. This License does not grant permission to use the trade\n      names, trademarks, service marks, or product names of the Licensor,\n      except as required for reasonable and customary use in describing the\n      origin of the Work and reproducing the content of the NOTICE file.\n\n   7. Disclaimer of Warranty. Unless required by applicable law or\n      agreed to in writing, Licensor provides the Work (and each\n      Contributor provides its Contributions) on an \"AS IS\" BASIS,\n      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n      implied, including, without limitation, any warranties or conditions\n      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\n      PARTICULAR PURPOSE. You are solely responsible for determining the\n      appropriateness of using or redistributing the Work and assume any\n      risks associated with Your exercise of permissions under this License.\n\n   8. Limitation of Liability. In no event and under no legal theory,\n      whether in tort (including negligence), contract, or otherwise,\n      unless required by applicable law (such as deliberate and grossly\n      negligent acts) or agreed to in writing, shall any Contributor be\n      liable to You for damages, including any direct, indirect, special,\n      incidental, or consequential damages of any character arising as a\n      result of this License or out of the use or inability to use the\n      Work (including but not limited to damages for loss of goodwill,\n      work stoppage, computer failure or malfunction, or any and all\n      other commercial damages or losses), even if such Contributor\n      has been advised of the possibility of such damages.\n\n   9. Accepting Warranty or Additional Liability. While redistributing\n      the Work or Derivative Works thereof, You may choose to offer,\n      and charge a fee for, acceptance of support, warranty, indemnity,\n      or other liability obligations and/or rights consistent with this\n      License. However, in accepting such obligations, You may act only\n      on Your own behalf and on Your sole responsibility, not on behalf\n      of any other Contributor, and only if You agree to indemnify,\n      defend, and hold each Contributor harmless for any liability\n      incurred by, or claims asserted against, such Contributor by reason\n      of your accepting any such warranty or additional liability.\n\n   END OF TERMS AND CONDITIONS\n\n   APPENDIX: How to apply the Apache License to your work.\n\n      To apply the Apache License to your work, attach the following\n      boilerplate notice, with the fields enclosed by brackets \"{}\"\n      replaced with your own identifying information. (Don't include\n      the brackets!)  The text should be enclosed in the appropriate\n      comment syntax for the file format. We also recommend that a\n      file or class name and description of purpose be included on the\n      same \"printed page\" as the copyright notice for easier\n      identification within third-party archives.\n\n   Copyright {yyyy} {name of copyright owner}\n\n   Licensed under the Apache License, Version 2.0 (the \"License\");\n   you may not use this file except in compliance with the License.\n   You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n   Unless required by applicable law or agreed to in writing, software\n   distributed under the License is distributed on an \"AS IS\" BASIS,\n   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n   See the License for the specific language governing permissions and\n   limitations under the License."
  },
  {
    "path": "LICENSE.mit",
    "content": "Copyright (c) 2017 Avraham Weinstock\n\nPermission is hereby granted, free of charge, to any\nperson obtaining a copy of this software and associated\ndocumentation files (the \"Software\"), to deal in the\nSoftware without restriction, including without\nlimitation the rights to use, copy, modify, merge,\npublish, distribute, sublicense, and/or sell copies of\nthe Software, and to permit persons to whom the Software\nis furnished to do so, subject to the following\nconditions:\n\nThe above copyright notice and this permission notice\nshall be included in all copies or substantial portions\nof the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF\nANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED\nTO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A\nPARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT\nSHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\nCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\nOF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR\nIN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\nDEALINGS IN THE SOFTWARE.\n"
  },
  {
    "path": "README.md",
    "content": "# copypasta\n\ncopypasta is a [rust-clipboard](https://github.com/aweinstock314/rust-clipboard) fork, adding support for the Wayland clipboard.\n\nrust-clipboard is a cross-platform library for getting and setting the contents of the OS-level clipboard.  \n\n## Example\n\n```rust\nextern crate copypasta;\n\nuse copypasta::{ClipboardContext, ClipboardProvider};\n\nfn main() {\n    let mut ctx = ClipboardContext::new().unwrap();\n\n    let msg = \"Hello, world!\";\n    ctx.set_contents(msg.to_owned()).unwrap();\n\n    let content = ctx.get_contents().unwrap();\n\n    println!(\"{}\", content);\n}\n```\n\n## API\n\nThe `ClipboardProvider` trait has the following functions:\n\n```rust\nfn get_contents(&mut self) -> Result<String, Box<Error>>;\nfn set_contents(&mut self, String) -> Result<(), Box<Error>>;\n```\n\n`ClipboardContext` is a type alias for one of {`WindowsClipboardContext`, `OSXClipboardContext`, `X11ClipboardContext`, `NopClipboardContext`}, all of which implement `ClipboardProvider`. Which concrete type is chosen for `ClipboardContext` depends on the OS (via conditional compilation).\n\n## License\n\n`rust-clipboard` is dual-licensed under MIT and Apache2.\n"
  },
  {
    "path": "examples/hello_world.rs",
    "content": "use copypasta::{ClipboardContext, ClipboardProvider};\n\nfn main() {\n    let mut ctx = ClipboardContext::new().unwrap();\n\n    let msg = \"Hello, world!\";\n    ctx.set_contents(msg.to_owned()).unwrap();\n\n    let content = ctx.get_contents().unwrap();\n\n    println!(\"{}\", content);\n}\n"
  },
  {
    "path": "examples/primary_selection.rs",
    "content": "#[cfg(target_os = \"linux\")]\nuse copypasta::x11_clipboard::{Primary, X11ClipboardContext};\n#[cfg(target_os = \"linux\")]\nuse copypasta::ClipboardProvider;\n\n#[cfg(target_os = \"linux\")]\nfn main() {\n    let mut ctx = X11ClipboardContext::<Primary>::new().unwrap();\n\n    let the_string = \"Hello, world!\";\n\n    ctx.set_contents(the_string.to_owned()).unwrap();\n}\n\n#[cfg(not(target_os = \"linux\"))]\nfn main() {\n    println!(\"Primary selection is only available under linux!\");\n}\n"
  },
  {
    "path": "rustfmt.toml",
    "content": "format_code_in_doc_comments = true\nmatch_block_trailing_comma = true\ncondense_wildcard_suffixes = true\nuse_field_init_shorthand = true\noverflow_delimited_expr = true\nuse_small_heuristics = \"Max\"\nnormalize_comments = true\nreorder_impl_items = true\nuse_try_shorthand = true\nnewline_style = \"Unix\"\nformat_strings = true\nwrap_comments = true\ncomment_width = 100\n"
  },
  {
    "path": "src/common.rs",
    "content": "// Copyright 2016 Avraham Weinstock\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nuse std::error::Error;\n\npub type Result<T> = std::result::Result<T, Box<dyn Error + Send + Sync + 'static>>;\n\n// TODO: come up with some platform-agnostic API for richer types\n/// Trait for clipboard access\npub trait ClipboardProvider: Send {\n    /// Method to get the clipboard contents as a String\n    fn get_contents(&mut self) -> Result<String>;\n    /// Method to set the clipboard contents as a String\n    fn set_contents(&mut self, _: String) -> Result<()>;\n}\n"
  },
  {
    "path": "src/lib.rs",
    "content": "// Copyright 2016 Avraham Weinstock\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n#![deny(clippy::all, clippy::if_not_else, clippy::enum_glob_use)]\n\nmod common;\npub use crate::common::ClipboardProvider;\n\n#[cfg(all(\n    unix,\n    not(any(\n        target_os = \"macos\",\n        target_os = \"android\",\n        target_os = \"ios\",\n        target_os = \"emscripten\"\n    ))\n))]\n#[cfg(feature = \"wayland\")]\npub mod wayland_clipboard;\n#[cfg(all(\n    unix,\n    not(any(\n        target_os = \"macos\",\n        target_os = \"android\",\n        target_os = \"ios\",\n        target_os = \"emscripten\"\n    ))\n))]\n#[cfg(feature = \"x11\")]\npub mod x11_clipboard;\n\n#[cfg(windows)]\npub mod windows_clipboard;\n\n#[cfg(target_os = \"macos\")]\npub mod osx_clipboard;\n\npub mod nop_clipboard;\n\n#[cfg(all(\n    unix,\n    not(any(\n        target_os = \"macos\",\n        target_os = \"android\",\n        target_os = \"ios\",\n        target_os = \"emscripten\"\n    ))\n))]\n#[cfg(feature = \"x11\")]\npub type ClipboardContext = x11_clipboard::X11ClipboardContext;\n#[cfg(windows)]\npub type ClipboardContext = windows_clipboard::WindowsClipboardContext;\n#[cfg(target_os = \"macos\")]\npub type ClipboardContext = osx_clipboard::OSXClipboardContext;\n#[cfg(target_os = \"android\")]\npub type ClipboardContext = nop_clipboard::NopClipboardContext; // TODO: implement AndroidClipboardContext\n#[cfg(target_os = \"ios\")]\npub type ClipboardContext = nop_clipboard::NopClipboardContext; // TODO: implement IOSClipboardContext\n#[cfg(not(any(\n    unix,\n    windows,\n    target_os = \"macos\",\n    target_os = \"android\",\n    target_os = \"ios\",\n    target_os = \"emscripten\"\n)))]\npub type ClipboardContext = nop_clipboard::NopClipboardContext;\n"
  },
  {
    "path": "src/nop_clipboard.rs",
    "content": "// Copyright 2016 Avraham Weinstock\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nuse crate::common::{ClipboardProvider, Result};\n\npub struct NopClipboardContext;\n\nimpl NopClipboardContext {\n    pub fn new() -> Result<NopClipboardContext> {\n        Ok(NopClipboardContext)\n    }\n}\n\nimpl ClipboardProvider for NopClipboardContext {\n    fn get_contents(&mut self) -> Result<String> {\n        println!(\n            \"Attempting to get the contents of the clipboard, which hasn't yet been implemented \\\n             on this platform.\"\n        );\n        Ok(\"\".to_string())\n    }\n\n    fn set_contents(&mut self, _: String) -> Result<()> {\n        println!(\n            \"Attempting to set the contents of the clipboard, which hasn't yet been implemented \\\n             on this platform.\"\n        );\n        Ok(())\n    }\n}\n"
  },
  {
    "path": "src/osx_clipboard.rs",
    "content": "// Copyright 2016 Avraham Weinstock\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nuse std::panic::RefUnwindSafe;\nuse std::panic::UnwindSafe;\n\nuse objc2::rc::{autoreleasepool, Retained};\nuse objc2::runtime::ProtocolObject;\nuse objc2::{msg_send, ClassType};\nuse objc2_app_kit::{NSPasteboard, NSPasteboardTypeFileURL, NSPasteboardTypeString};\nuse objc2_foundation::{NSArray, NSString, NSURL};\n\nuse crate::common::*;\n\npub struct OSXClipboardContext {\n    pasteboard: Retained<NSPasteboard>,\n}\n\nunsafe impl Send for OSXClipboardContext {}\nunsafe impl Sync for OSXClipboardContext {}\nimpl UnwindSafe for OSXClipboardContext {}\nimpl RefUnwindSafe for OSXClipboardContext {}\n\nimpl OSXClipboardContext {\n    pub fn new() -> Result<OSXClipboardContext> {\n        // Use `msg_send_id!` instead of `NSPasteboard::generalPasteboard()`\n        // in the off case that it will return NULL (even though it's\n        // documented not to).\n        let pasteboard: Option<Retained<NSPasteboard>> =\n            unsafe { msg_send![NSPasteboard::class(), generalPasteboard] };\n        let pasteboard = pasteboard.ok_or(\"NSPasteboard#generalPasteboard returned null\")?;\n        Ok(OSXClipboardContext { pasteboard })\n    }\n}\n\nimpl ClipboardProvider for OSXClipboardContext {\n    fn get_contents(&mut self) -> Result<String> {\n        autoreleasepool(|_| {\n            let types = unsafe { self.pasteboard.types() }.unwrap();\n            let has_file = unsafe { types.containsObject(NSPasteboardTypeFileURL) };\n            let has_str = unsafe { types.containsObject(NSPasteboardTypeString) };\n\n            if !has_str {\n                return Err(\"NSPasteboard#types doesn't contain NSPasteboardTypeString\".into());\n            }\n\n            let text = if has_file {\n                let file_url_string =\n                    unsafe { self.pasteboard.stringForType(NSPasteboardTypeFileURL) }\n                        .ok_or(\"NSPasteboard#stringForType returned null\")?;\n\n                let file_url = unsafe { NSURL::URLWithString(&file_url_string) }\n                    .ok_or(\"NSURL#URLWithString returned null\")?;\n                unsafe { file_url.path() }.ok_or(\"NSURL#path returned null\")?\n            } else {\n                unsafe { self.pasteboard.stringForType(NSPasteboardTypeString) }\n                    .ok_or(\"NSPasteboard#stringForType returned null\")?\n            };\n\n            Ok(text.to_string())\n        })\n    }\n\n    fn set_contents(&mut self, data: String) -> Result<()> {\n        let string_array = NSArray::from_retained_slice(&[ProtocolObject::from_retained(\n            NSString::from_str(&data),\n        )]);\n        unsafe { self.pasteboard.clearContents() };\n        let success = unsafe { self.pasteboard.writeObjects(&string_array) };\n        if success {\n            Ok(())\n        } else {\n            Err(\"NSPasteboard#writeObjects: returned false\".into())\n        }\n    }\n}\n"
  },
  {
    "path": "src/wayland_clipboard.rs",
    "content": "// Copyright 2017 Avraham Weinstock\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nuse std::ffi::c_void;\nuse std::sync::{Arc, Mutex};\n\nuse smithay_clipboard::Clipboard as WaylandClipboard;\n\nuse crate::common::{ClipboardProvider, Result};\n\npub struct Clipboard {\n    context: Arc<Mutex<WaylandClipboard>>,\n}\n\npub struct Primary {\n    context: Arc<Mutex<WaylandClipboard>>,\n}\n\n/// Create new clipboard from a raw display pointer.\n///\n/// # Safety\n///\n/// Since the type of the display is a raw pointer, it's the responsibility of the callee to make\n/// sure that the passed pointer is a valid Wayland display.\npub unsafe fn create_clipboards_from_external(display: *mut c_void) -> (Primary, Clipboard) {\n    let context = Arc::new(Mutex::new(WaylandClipboard::new(display)));\n\n    (Primary { context: context.clone() }, Clipboard { context })\n}\n\nimpl ClipboardProvider for Clipboard {\n    fn get_contents(&mut self) -> Result<String> {\n        Ok(self.context.lock().unwrap().load()?)\n    }\n\n    fn set_contents(&mut self, data: String) -> Result<()> {\n        self.context.lock().unwrap().store(data);\n\n        Ok(())\n    }\n}\n\nimpl ClipboardProvider for Primary {\n    fn get_contents(&mut self) -> Result<String> {\n        Ok(self.context.lock().unwrap().load_primary()?)\n    }\n\n    fn set_contents(&mut self, data: String) -> Result<()> {\n        self.context.lock().unwrap().store_primary(data);\n\n        Ok(())\n    }\n}\n"
  },
  {
    "path": "src/windows_clipboard.rs",
    "content": "// Copyright 2016 Avraham Weinstock\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nuse clipboard_win::{get_clipboard_string, set_clipboard_string};\n\nuse crate::common::{ClipboardProvider, Result};\n\npub struct WindowsClipboardContext;\n\nimpl WindowsClipboardContext {\n    pub fn new() -> Result<Self> {\n        Ok(WindowsClipboardContext)\n    }\n}\n\nimpl ClipboardProvider for WindowsClipboardContext {\n    fn get_contents(&mut self) -> Result<String> {\n        Ok(get_clipboard_string()?)\n    }\n\n    fn set_contents(&mut self, data: String) -> Result<()> {\n        Ok(set_clipboard_string(&data)?)\n    }\n}\n"
  },
  {
    "path": "src/x11_clipboard.rs",
    "content": "// Copyright 2017 Avraham Weinstock\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nuse std::marker::PhantomData;\nuse std::time::Duration;\n\nuse x11_clipboard::Atom;\nuse x11_clipboard::{Atoms, Clipboard as X11Clipboard};\n\nuse crate::common::*;\n\npub trait Selection: Send {\n    fn atom(atoms: &Atoms) -> Atom;\n}\n\npub struct Primary;\n\nimpl Selection for Primary {\n    fn atom(atoms: &Atoms) -> Atom {\n        atoms.primary\n    }\n}\n\npub struct Clipboard;\n\nimpl Selection for Clipboard {\n    fn atom(atoms: &Atoms) -> Atom {\n        atoms.clipboard\n    }\n}\n\npub struct X11ClipboardContext<S = Clipboard>(X11Clipboard, PhantomData<S>)\nwhere\n    S: Selection;\n\nimpl<S> X11ClipboardContext<S>\nwhere\n    S: Selection,\n{\n    pub fn new() -> Result<X11ClipboardContext<S>> {\n        Ok(X11ClipboardContext(X11Clipboard::new()?, PhantomData))\n    }\n}\n\nimpl<S> ClipboardProvider for X11ClipboardContext<S>\nwhere\n    S: Selection,\n{\n    fn get_contents(&mut self) -> Result<String> {\n        Ok(String::from_utf8(self.0.load(\n            S::atom(&self.0.getter.atoms),\n            self.0.getter.atoms.utf8_string,\n            self.0.getter.atoms.property,\n            Duration::from_secs(3),\n        )?)?)\n    }\n\n    fn set_contents(&mut self, data: String) -> Result<()> {\n        Ok(self.0.store(S::atom(&self.0.setter.atoms), self.0.setter.atoms.utf8_string, data)?)\n    }\n}\n"
  }
]