diff options
author | Joe Wilm <joe@jwilm.com> | 2016-10-08 18:42:33 -0700 |
---|---|---|
committer | Joe Wilm <joe@jwilm.com> | 2016-10-08 18:42:33 -0700 |
commit | 9d491f9f676536634040fea8294dc672f3466e26 (patch) | |
tree | 81d4ddc867c570a9004c3d878647feb69e0e2d91 | |
parent | 7e69a070aaf92eff3bea1878bd77821b5ae60ede (diff) | |
download | alacritty-9d491f9f676536634040fea8294dc672f3466e26.tar.gz alacritty-9d491f9f676536634040fea8294dc672f3466e26.zip |
Start implementing copypasta, a clipboard library
Currently it only supports x11 via the xclip program, and that only
supports reading the clipboard contents.
-rw-r--r-- | Cargo.lock | 87 | ||||
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | copypasta/Cargo.lock | 4 | ||||
-rw-r--r-- | copypasta/Cargo.toml | 9 | ||||
-rw-r--r-- | copypasta/LICENSE-APACHE | 201 | ||||
-rw-r--r-- | copypasta/src/lib.rs | 46 | ||||
-rw-r--r-- | copypasta/src/macos.rs | 19 | ||||
-rw-r--r-- | copypasta/src/x11.rs | 98 | ||||
-rw-r--r-- | src/input.rs | 6 | ||||
-rw-r--r-- | src/main.rs | 2 |
10 files changed, 387 insertions, 87 deletions
@@ -4,7 +4,7 @@ version = "0.1.0" dependencies = [ "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "cgmath 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "clipboard 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "copypasta 0.0.1", "errno 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "font 0.1.0", "gl_generator 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -50,11 +50,6 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] -name = "block" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] name = "byteorder" version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -89,29 +84,6 @@ dependencies = [ ] [[package]] -name = "clipboard" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "clipboard-win 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "objc 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "objc-foundation 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "objc_id 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "x11 2.8.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "clipboard-win" -version = "1.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "user32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "windows-error 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] name = "cmake" version = "0.1.17" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -131,6 +103,10 @@ dependencies = [ ] [[package]] +name = "copypasta" +version = "0.0.1" + +[[package]] name = "core-foundation" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -626,24 +602,6 @@ dependencies = [ ] [[package]] -name = "objc-foundation" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "block 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "objc 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "objc_id 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "objc_id" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "objc 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] name = "osmesa-sys" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -869,15 +827,6 @@ dependencies = [ ] [[package]] -name = "user32-sys" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] name = "utf8parse" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -967,15 +916,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] -name = "windows-error" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] name = "ws2_32-sys" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -985,15 +925,6 @@ dependencies = [ ] [[package]] -name = "x11" -version = "2.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "libc 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)", - "pkg-config 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] name = "x11-dl" version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1023,14 +954,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum bitflags 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8dead7461c1127cf637931a1e50934eb6eee8bff2f74433ac7909e9afcee04a3" "checksum bitflags 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "72cd7314bd4ee024071241147222c706e80385a1605ac7d4cd2fcc339da2ae46" "checksum bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d" -"checksum block 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" "checksum byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0fc10e8cc6b2580fda3f36eb6dc5316657f812a3df879a44a66fc9f0fdbc4855" "checksum bytes 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c129aff112dcc562970abb69e2508b40850dd24c274761bb50fb8a0067ba6c27" "checksum cfg-if 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "de1e760d7b6535af4241fca8bd8adf68e2e7edacc6b29f5d399050c5e48cf88c" "checksum cgl 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "8bdd78cca65a739cb5475dbf6b6bbb49373e327f4a6f2b499c0f98632df38c10" "checksum cgmath 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "75e93b3eb66e74ffb946a69ff54c6026c1399960241c843f249ea0127b96b9f6" -"checksum clipboard 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "811169a9ffda99ed1841a6db3c48cffbab9a9101376f77fee3c14a7581ab933d" -"checksum clipboard-win 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "238830bd83336a8620cbc1d6edf6b9222f45a2c52d02c164348fb6b466277b21" "checksum cmake 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)" = "dfcf5bcece56ef953b8ea042509e9dcbdfe97820b7e20d86beb53df30ed94978" "checksum cocoa 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3afe4613f57a171039a98db1773f5840b5743cf85aaf03afb65ddfade4f4a9db" "checksum core-foundation 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "20a6d0448d3a99d977ae4a2aa5a98d886a923e863e81ad9ff814645b6feb3bbd" @@ -1084,8 +1012,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum num-rational 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)" = "54ff603b8334a72fbb27fe66948aac0abaaa40231b3cecd189e76162f6f38aaf" "checksum num-traits 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)" = "8359ea48994f253fa958b5b90b013728b06f54872e5a58bce39540fcdd0f2527" "checksum objc 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7c9311aa5acd7bee14476afa0f0557f564e9d0d61218a8b833d9b1f871fa5fba" -"checksum objc-foundation 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1add1b659e36c9607c7aab864a76c7a4c2760cd0cd2e120f3fb8b952c7e22bf9" -"checksum objc_id 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e4730aa1c64d722db45f7ccc4113a3e2c465d018de6db4d3e7dfe031e8c8a297" "checksum osmesa-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "88cfece6e95d2e717e0872a7f53a8684712ad13822a7979bc760b9c77ec0013b" "checksum parking_lot 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "aa2a676a66f54ed4c84f55261814eb357e530eb2b703cd21466beee4bcf30238" "checksum parking_lot_core 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "06f24c980718110494e9cfb7db7438895c3f54505101bb6170329d5e43a53f64" @@ -1115,7 +1041,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum tempfile 2.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "9270837a93bad1b1dac18fe67e786b3c960513af86231f6f4f57fddd594ff0c8" "checksum time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)" = "3c7ec6d62a20df54e07ab3b78b9a3932972f4b7981de295563686849eb3989af" "checksum user32-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6717129de5ac253f5642fc78a51d0c7de6f9f53d617fc94e9bae7f6e71cf5504" -"checksum user32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4ef4711d107b21b410a3a974b1204d9accc8b10dad75d8324b5d755de1617d47" "checksum utf8parse 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a15ea87f3194a3a454c78d79082b4f5e85f6956ddb6cb86bbfbe4892aa3c0323" "checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" "checksum vte 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "182acba7edb46d25ab5ddfc9f390b8c6cc1dcec7a4efc2798f0a8918f07d8c8a" @@ -1127,9 +1052,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum wayland-window 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "309b69d3a863c9c21422d889fb7d98cf02f8a2ca054960a49243ce5b67ad884c" "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" "checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" -"checksum windows-error 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "dfa34b3180ad6b4fe63cbc4fb773da4a83c5b3db8db15789051a4785f2b43e58" "checksum ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" -"checksum x11 2.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bfc828b6baf54ccdde44e0b5f16e035ab9c54f60a0f0c218fb5ddbc6ab38a2a9" "checksum x11-dl 2.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6acc29bdc98d7565e18dc71b3e933aa94a195d0c2f4ec84f675679d9744b0d6b" "checksum xml-rs 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "65e74b96bd3179209dc70a980da6df843dff09e46eee103a0376c0949257e3ef" "checksum yaml-rust 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ebfe12f475ad59be6178ebf004d51e682022496535994f8d23fd7ed31084598c" @@ -19,7 +19,7 @@ serde_yaml = "0.4" serde_macros = "0.8" vte = "0.1.2" mio = "0.6" -clipboard = "0.1.2" +copypasta = { path = "./copypasta" } [build-dependencies] gl_generator = "0.5" diff --git a/copypasta/Cargo.lock b/copypasta/Cargo.lock new file mode 100644 index 00000000..53d49794 --- /dev/null +++ b/copypasta/Cargo.lock @@ -0,0 +1,4 @@ +[root] +name = "copypasta" +version = "0.0.1" + diff --git a/copypasta/Cargo.toml b/copypasta/Cargo.toml new file mode 100644 index 00000000..1f07645a --- /dev/null +++ b/copypasta/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "copypasta" +version = "0.0.1" +authors = ["Joe Wilm <joe@jwilm.com>"] +license = "Apache-2.0" +description = "Forthcoming clipboard library" +keywords = ["clipboard", "copy", "paste"] + +[dependencies] diff --git a/copypasta/LICENSE-APACHE b/copypasta/LICENSE-APACHE new file mode 100644 index 00000000..d79db12e --- /dev/null +++ b/copypasta/LICENSE-APACHE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + +Copyright 2016 Joe Wilm, The Alacritty Project Contributors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/copypasta/src/lib.rs b/copypasta/src/lib.rs new file mode 100644 index 00000000..722142aa --- /dev/null +++ b/copypasta/src/lib.rs @@ -0,0 +1,46 @@ +//! A cross-platform clipboard library + +/// Types that can get the system clipboard contents +pub trait Load : Sized { + /// Errors encountered when working with a clipboard. Each implementation is + /// allowed to define its own error type, but it must conform to std error. + type Err: ::std::error::Error + Send + Sync + 'static; + + /// Create a clipboard + fn new() -> Result<Self, Self::Err>; + + /// Get the primary clipboard contents. + fn load_primary(&self) -> Result<String, Self::Err>; + + /// Get the clipboard selection contents. + /// + /// On most platforms, this doesn't mean anything. A default implementation + /// is provided which uses the primary clipboard. + #[inline] + fn load_selection(&self) -> Result<String, Self::Err> { + self.load_primary() + } +} + +/// Types that can set the system clipboard contents +/// +/// Note that some platforms require the clipboard context to stay active in +/// order to load the contents from other applications. +pub trait Store : Load { + /// Sets the primary clipboard contents + fn store_primary(&mut self, contents: String) -> Result<(), Self::Err>; + + /// Sets the secondary clipboard contents + fn store_selection(&mut self, contents: String) -> Result<(), Self::Err>; +} + +#[cfg(target_os = "linux")] +mod x11; +#[cfg(target_os = "linux")] +pub use x11::{Clipboard, Error}; + +#[cfg(target_os = "macos")] +mod macos; +#[cfg(target_os = "macos")] +pub use macos::{Clipboard, Error}; + diff --git a/copypasta/src/macos.rs b/copypasta/src/macos.rs new file mode 100644 index 00000000..5ef7630e --- /dev/null +++ b/copypasta/src/macos.rs @@ -0,0 +1,19 @@ +//! Clipboard access on macOS +//! +//! Implemented according to https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/PasteboardGuide106/Articles/pbReading.html#//apple_ref/doc/uid/TP40008123-SW1 +//! +//! FIXME implement this :) + +struct Clipboard; + +impl Load for Clipboard { + type Err = (); + + fn new() -> Result<Self, Error> { + Ok(Clipboard) + } + + fn load_primary(&self) -> Result<String, Self::Err> { + Ok(String::new()) + } +} diff --git a/copypasta/src/x11.rs b/copypasta/src/x11.rs new file mode 100644 index 00000000..45fa4825 --- /dev/null +++ b/copypasta/src/x11.rs @@ -0,0 +1,98 @@ +//! X11 Clipboard implementation +//! +//! Note that the x11 implementation is really crap right now - we just depend +//! on xclip being on the user's path. If x11 pasting doesn't work, it's +//! probably because xclip is unavailable. There's currently no non-GPL x11 +//! clipboard library for Rust. Until then, we have this hack. +//! +//! FIXME: Implement actual X11 clipboard API using the ICCCM reference +//! https://tronche.com/gui/x/icccm/ +use std::io; +use std::process::{Output, Command}; +use std::string::FromUtf8Error; + +use super::Load; + +/// The x11 clipboard +pub struct Clipboard; + +#[derive(Debug)] +pub enum Error { + Io(io::Error), + Xclip(String), + Utf8(FromUtf8Error), +} + +impl ::std::error::Error for Error { + fn cause(&self) -> Option<&::std::error::Error> { + match *self { + Error::Io(ref err) => Some(err), + Error::Utf8(ref err) => Some(err), + _ => None, + } + } + + fn description(&self) -> &str { + match *self { + Error::Io(..) => "error calling xclip", + Error::Xclip(..) => "error reported by xclip", + Error::Utf8(..) => "clipboard contents not utf8", + } + } +} + +impl ::std::fmt::Display for Error { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + match *self { + Error::Io(ref err) => write!(f, "error calling xclip: {}", err), + Error::Xclip(ref s) => write!(f, "error from xclip: {}", s), + Error::Utf8(ref err) => write!(f, "error parsing xclip output: {}", err), + } + } +} + +impl From<io::Error> for Error { + fn from(val: io::Error) -> Error { + Error::Io(val) + } +} + +impl From<FromUtf8Error> for Error { + fn from(val: FromUtf8Error) -> Error { + Error::Utf8(val) + } +} + +impl Load for Clipboard { + type Err = Error; + + fn new() -> Result<Self, Error> { + Ok(Clipboard) + } + + fn load_primary(&self) -> Result<String, Self::Err> { + let output = try!(Command::new("xclip") + .args(&["-o", "-selection", "clipboard"]) + .output()); + + Clipboard::process_xclip_output(output) + } + + fn load_selection(&self) -> Result<String, Self::Err> { + let output = try!(Command::new("xclip") + .args(&["-o"]) + .output()); + + Clipboard::process_xclip_output(output) + } +} + +impl Clipboard { + fn process_xclip_output(output: Output) -> Result<String, Error> { + if output.status.success() { + Ok(try!(String::from_utf8(output.stdout))) + } else { + Ok(try!(String::from_utf8(output.stderr))) + } + } +} diff --git a/src/input.rs b/src/input.rs index d0cbc600..f1022814 100644 --- a/src/input.rs +++ b/src/input.rs @@ -25,7 +25,7 @@ //! TODO handling xmodmap would be good use std::borrow::Cow; -use clipboard::ClipboardContext; +use copypasta::{Clipboard, Load}; use glutin::{ElementState, VirtualKeyCode, MouseButton}; use glutin::{Mods, mods}; @@ -349,8 +349,8 @@ impl Processor { Action::Esc(s) => notifier.notify(s.as_bytes()), Action::Paste => { println!("paste request"); - let clip = ClipboardContext::new().expect("get clipboard"); - clip.get_contents() + let clip = Clipboard::new().expect("get clipboard"); + clip.load_selection() .map(|contents| { println!("got contents"); notifier.notify(contents.into_bytes()) diff --git a/src/main.rs b/src/main.rs index 3316c70c..acf47302 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,7 +24,7 @@ #![feature(core_intrinsics)] extern crate cgmath; -extern crate clipboard; +extern crate copypasta; extern crate errno; extern crate font; extern crate glutin; |