pax_global_header00006660000000000000000000000064144727160300014516gustar00rootroot0000000000000052 comment=3eb912c274042cd5deed6b478b39908a12f37498 wl-clipboard-2.2.1/000077500000000000000000000000001447271603000140775ustar00rootroot00000000000000wl-clipboard-2.2.1/.editorconfig000066400000000000000000000002641447271603000165560ustar00rootroot00000000000000root = true [*] indent_style = space indent_size = 4 end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [**.{c,h}] max_line_length = 80 wl-clipboard-2.2.1/.gitignore000066400000000000000000000000071447271603000160640ustar00rootroot00000000000000build/ wl-clipboard-2.2.1/BUILDING.md000066400000000000000000000033441447271603000156220ustar00rootroot00000000000000# Building wl-clipboard is a simple Meson project, so building it is just: ```bash # Clone: $ git clone https://github.com/bugaevc/wl-clipboard.git $ cd wl-clipboard # Build: $ meson setup build $ cd build $ ninja # Install $ sudo meson install ``` wl-clipboard supports Linux and BSD systems, and is also known to work on Mac OS X and GNU Hurd. The only mandatory dependency is the `wayland-client` library (try package named `wayland-devel` or `libwayland-dev`). Optional (but highly recommended) dependencies for building: * `wayland-scanner` * `wayland-protocols` (version 1.12 or later) If these are found during configuration, wl-clipboard gets built with additional protocols support, which enables features such as primary selection support and `--watch` mode. If they are not found, Meson can optionally build them on the spot as subprojects. Note that many compositors have dropped support for the `wl_shell` interface, which means wl-clipboard will not work under them unless built with both `wayland-scanner` and `wayland-protocols`. For this reason, you have to explicitly opt into allowing building without these dependencies by specifying `-D protocols=auto` (or `-D protocols=disabled`) when configuring with Meson. Optional dependencies for running: * `xdg-mime` for content type inference in `wl-copy` (try package named `xdg-utils`) * `/etc/mime.types` file for type inference in `wl-paste` (try package named `mime-support` or `mailcap`) If you're packaging wl-clipboard for a distribution, please consider making packages providing `xdg-mime` and `/etc/mime.types` *weak* dependencies of the package providing wl-clipboard, meaning ones that get installed along with wl-clipboard by default, but are not strictly required by it. wl-clipboard-2.2.1/COPYING000066400000000000000000001045141447271603000151370ustar00rootroot00000000000000 GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . wl-clipboard-2.2.1/README.md000066400000000000000000000025051447271603000153600ustar00rootroot00000000000000# wl-clipboard: Wayland clipboard utilities This project implements two command-line Wayland clipboard utilities, `wl-copy` and `wl-paste`, that let you easily copy data between the clipboard and Unix pipes, sockets, files and so on. ```bash # Copy a simple text message: $ wl-copy Hello world! # Copy the list of files in ~/Downloads: $ ls ~/Downloads | wl-copy # Copy an image: $ wl-copy < ~/Pictures/photo.png # Copy the previous command: $ wl-copy "!!" # Paste to a file: $ wl-paste > clipboard.txt # Sort clipboard contents: $ wl-paste | sort | wl-copy # Upload clipboard contents to a pastebin on each change: $ wl-paste --watch nc paste.example.org 5555 ``` Please see the wl-clipboard(1) man page for more details. # Installing wl-clipboard is likely available in your favorite Linux or BSD distro. For building from source, see [BUILDING.md](BUILDING.md). # License wl-clipboard is free software, available under the GNU General Public License version 3 or later. # Related projects * [wl-clipboard-x11](https://github.com/brunelli/wl-clipboard-x11): A wrapper to use wl-clipboard as a drop-in replacement to X11 clipboard tools. * [wl-clipboard-rs](https://github.com/YaLTeR/wl-clipboard-rs): A Rust crate (library) for working with the Wayland clipboard which includes a reimplementation of `wl-copy` and `wl-paste`. wl-clipboard-2.2.1/completions/000077500000000000000000000000001447271603000164335ustar00rootroot00000000000000wl-clipboard-2.2.1/completions/bash/000077500000000000000000000000001447271603000173505ustar00rootroot00000000000000wl-clipboard-2.2.1/completions/bash/meson.build000066400000000000000000000003201447271603000215050ustar00rootroot00000000000000bash_completion_dir = join_paths(get_option('datadir'), 'bash-completion', 'completions') install_data('wl-copy', install_dir: bash_completion_dir) install_data('wl-paste', install_dir: bash_completion_dir) wl-clipboard-2.2.1/completions/bash/wl-copy000066400000000000000000000032101447271603000206610ustar00rootroot00000000000000# wl-copy(1) completion _wl_clipboard_list_seats() { weston-info 2>/dev/null | sed -n '/wl_seat/{n;s/\s*name: //;p}' } _wl_clipboard_complete_types() { local cur prev types cur="${COMP_WORDS[COMP_CWORD]}" prev="${COMP_WORDS[COMP_CWORD-1]}" types="$1" if [ "${cur:0:1}" = \' -o "${cur:0:1}" = \" ]; then COMPREPLY=($(compgen -W "$types" -- "$cur")) else COMPREPLY=($(compgen -W "$types" -- "$cur" | sed 's/;/\\;/g')) fi } _wl_copy_completion() { compopt +o default local cur prev opts types seats cur="${COMP_WORDS[COMP_CWORD]}" prev="${COMP_WORDS[COMP_CWORD-1]}" case "$cur" in "<"*) compopt -o default COMPREPLY=() return ;; esac case "$prev" in "<"*) compopt -o default COMPREPLY=() ;; -t | -[a-z]*t | --type) types="$(sed -e 's/#.*$//' -e '/^$/d' -e 's/^\(\S\+\).*/\1/' /etc/mime.types 2>/dev/null)" _wl_clipboard_complete_types "$types" ;; -s | -[a-z]*s | --seat) seats="$(_wl_clipboard_list_seats)" COMPREPLY=($(compgen -W "$seats" -- "$cur")) ;; *) opts="-o --paste-once " opts+="-f --foreground " opts+="-c --clear " opts+="-p --primary " opts+="-n --trim-newline " opts+="-t --type " opts+="-s --seat " opts+="-v --version " opts+="-h --help " COMPREPLY=($(compgen -W "$opts" -- "$cur")) ;; esac } complete -o default -F _wl_copy_completion wl-copy wl-clipboard-2.2.1/completions/bash/wl-paste000066400000000000000000000047671447271603000210450ustar00rootroot00000000000000# wl-paste(1) completion _wl_clipboard_list_seats() { weston-info 2>/dev/null | sed -n '/wl_seat/{n;s/\s*name: //;p}' } _wl_clipboard_complete_types() { local cur prev types cur="${COMP_WORDS[COMP_CWORD]}" prev="${COMP_WORDS[COMP_CWORD-1]}" types="$1" if [ "${cur:0:1}" = \' -o "${cur:0:1}" = \" ]; then COMPREPLY=($(compgen -W "$types" -- "$cur")) else COMPREPLY=($(compgen -W "$types" -- "$cur" | sed 's/;/\\;/g')) fi } _wl_clipboard_complete_paste_types() { local i cur primary seat cmd types for (( i = 0; i < "${#COMP_WORDS[@]}"; ++i )); do cur="${COMP_WORDS[i]}" case "$cur" in -p* | -[a-z]*p* | --primary) primary="yes" ;; esac case "$cur" in -s | -[a-z]*s | --seat) seat="${COMP_WORDS[i+1]}" ;; -s* | -[a-z]s*) seat=$(echo "$cur" | sed 's/-[^s]*s//') ;; esac done cmd="${COMP_WORDS[0]}" if [ -n "$primary" ]; then cmd="$cmd -p" fi if [ -n "$seat" ]; then cmd="$cmd -s $seat" fi cmd="$cmd -l" types="$($cmd 2>/dev/null)" _wl_clipboard_complete_types "$types" } _wl_paste_completion() { compopt +o default local cur prev opts types seats offset for (( offset=1; offset < COMP_CWORD; offset++ )); do cur="${COMP_WORDS[offset]}" if [ "$cur" = "-w" -o "$cur" = "--watch" ]; then _command_offset $(($offset+1)) return fi done cur="${COMP_WORDS[COMP_CWORD]}" prev="${COMP_WORDS[COMP_CWORD-1]}" case "$cur" in ">"*) compopt -o default COMPREPLY=() return ;; esac case "$prev" in ">"*) compopt -o default COMPREPLY=() ;; -t | -[a-z]*t | --type) _wl_clipboard_complete_paste_types ;; -s | -[a-z]*s | --seat) seats="$(_wl_clipboard_list_seats)" COMPREPLY=($(compgen -W "$seats" -- "$cur")) ;; *) opts="-n --no-newline " opts+="-l --list-types " opts+="-p --primary " opts+="-w --watch " opts+="-t --type " opts+="-s --seat " opts+="-v --version " opts+="-h --help " COMPREPLY=($(compgen -W "$opts" -- "$cur")) ;; esac } complete -o default -F _wl_paste_completion wl-paste wl-clipboard-2.2.1/completions/fish/000077500000000000000000000000001447271603000173645ustar00rootroot00000000000000wl-clipboard-2.2.1/completions/fish/meson.build000066400000000000000000000017361447271603000215350ustar00rootroot00000000000000fish_completion_dir = get_option('fishcompletiondir') fish = dependency('fish', required : false) if fish_completion_dir == '' and fish.found() if meson.version().version_compare('>= 0.58') fish_completion_dir = fish.get_variable('completionsdir') else fish_completion_dir = fish.get_pkgconfig_variable('completionsdir') endif elif fish_completion_dir == '' # Fish does not look in /usr/local/, which is the default prefix, # so we cannot use get_option("datadir"). Instead, they recommend # custom completions to be installed into /usr/share/fish/vendor_completions.d, # so we use that. Note that this is a fallback in case you neither # have fish installed, nor have specified a path explicitly fish_completion_dir = '/usr/share/fish/vendor_completions.d' endif if fish_completion_dir != 'no' install_data('wl-copy.fish', install_dir: fish_completion_dir) install_data('wl-paste.fish', install_dir: fish_completion_dir) endif wl-clipboard-2.2.1/completions/fish/wl-copy.fish000066400000000000000000000017711447271603000216370ustar00rootroot00000000000000function __wayland_seats --description 'Print all wayland seats' if type -q weston-info weston-info 2>/dev/null | sed -n '/wl_seat/{n;s/\s*name: //;p}' else if type -q loginctl loginctl --no-legend --no-pager list-seats 2>/dev/null else # Fallback seat echo "seat0" end end complete -c wl-copy -x complete -c wl-copy -s h -l help -d 'Display a help message' complete -c wl-copy -s v -l version -d 'Display version info' complete -c wl-copy -s o -l paste-once -d 'Only serve one paste request and then exit' complete -c wl-copy -s c -l clear -d 'Instead of copying anything, clear the clipboard' complete -c wl-copy -s p -l primary -d 'Use the "primary" clipboard' complete -c wl-copy -s n -l trim-newline -d 'Do not copy the trailing newline character' complete -c wl-copy -s t -l type -x -d 'Override the inferred MIME type for the content' -a "(__fish_print_xdg_mimetypes)" complete -c wl-copy -s s -l seat -x -d 'Pick the seat to work with' -a "(__wayland_seats)" wl-clipboard-2.2.1/completions/fish/wl-paste.fish000066400000000000000000000043431447271603000217770ustar00rootroot00000000000000function __wayland_seats --description 'Print all wayland seats' if type -q weston-info weston-info 2>/dev/null | sed -n '/wl_seat/{n;s/\s*name: //;p}' else if type -q loginctl loginctl --no-legend --no-pager list-seats 2>/dev/null else # Fallback seat echo "seat0" end end function __wl_paste_types --description 'Print types with context' set -l type (commandline -o) for i in (seq (count $type)) if [ "$type[$i]" = '--primary' ]; or [ "$type[$i]" = '-p' ] set clip "primary" else if [ "$type[$i]" = '--seat' ]; or [ "$type[$i]" = '-s' ] set seat $type[(math $i + 1)] end end # Note fish does not handle passing unset variables # to commands well, thus setting clip to "--primary" and passing # that to wl-paste wont work, so if statements are used instead if test -n "$seat"; and test -n "$clip" wl-paste 2>/dev/null --seat "$seat" -p -l else if test -n "$seat" wl-paste 2>/dev/null --seat "$seat" -l else if test -n "$clip" wl-paste 2>/dev/null -p -l else wl-paste 2>/dev/null -l end end complete -c wl-paste -f complete -c wl-paste -f -n '__fish_contains_opt -s w watch' -a "(__fish_complete_subcommand -- -s --seat -t --type)" complete -c wl-paste -n '__fish_not_contain_opt -s w watch' -s h -l help -d 'Display a help message' complete -c wl-paste -n '__fish_not_contain_opt -s w watch' -s v -l version -d 'Display version info' complete -c wl-paste -n '__fish_not_contain_opt -s w watch' -s n -l no-newline -d 'Do not append a newline character' complete -c wl-paste -n '__fish_not_contain_opt -s w watch' -s l -l list-types -d 'Instead of pasting, list the offered types' complete -c wl-paste -n '__fish_not_contain_opt -s w watch' -s p -l primary -d 'Use the "primary" clipboard' complete -c wl-paste -n '__fish_not_contain_opt -s w watch' -s w -l watch -d 'Run a command each time the selection changes' complete -c wl-paste -n '__fish_not_contain_opt -s w watch' -s t -l type -x -d 'Override the inferred MIME type for the content' -a "(__wl_paste_types)" complete -c wl-paste -n '__fish_not_contain_opt -s w watch' -s s -l seat -x -d 'Pick the seat to work with' -a "(__wayland_seats)" wl-clipboard-2.2.1/completions/meson.build000066400000000000000000000000541447271603000205740ustar00rootroot00000000000000subdir('bash') subdir('zsh') subdir('fish') wl-clipboard-2.2.1/completions/zsh/000077500000000000000000000000001447271603000172375ustar00rootroot00000000000000wl-clipboard-2.2.1/completions/zsh/_wl-copy000066400000000000000000000026231447271603000207160ustar00rootroot00000000000000#compdef wl-copy __xdg_mimetypes() { local expl SEARCH=${XDG_DATA_HOME:-$HOME/.local/share} SEARCH+=:${XDG_DATA_DIRS:-/usr/share:/usr/local/share} local -a _all_mimetypes for dir in ${(s.:.)SEARCH}; do [[ -f "${dir}/mime/types" ]] && _all_mimetypes+=(${(f)"$(<"${dir}/mime/types")"}) done _wanted mimetypes expl 'mimetypes' _multi_parts / _all_mimetypes } __all_seats() { local -a seats if (( $+commands[weston-info] && $+commands[sed] )); then seats=( ${(@f)"$(weston-info 2>/dev/null | sed -n '/wl_seat/{n;s/\s*name: //;p}')"} ) elif (( $+commands[loginctl] )); then seats=( ${(@f)"$(loginctl --no-legend --no-pager list-seats 2>/dev/null)"} ) fi if [[ -z $seats ]]; then # seat0 is always a vaild seat and covers most cases, so its a good fallback. compadd "$@" - seat0 else compadd "$@" -a seats fi } _arguments -S -s \ {-o,--paste-once}'[Only serve one paste request and then exit]' \ {-f,--foreground}'[Stay in the foreground instead of forking]' \ {-c,--clear}'[Instead of copying anything, clear the clipboard]' \ {-p,--primary}'[Use the "primary" clipboard]' \ {-n,--trim-newline}'[Do not copy the trailing newline character]' \ {-t+,--type=}'[Override the inferred MIME type for the content]:mimetype:__xdg_mimetypes' \ {-s+,--seat=}'[Pick the seat to work with]:seat:__all_seats' \ {-v,--version}'[Display version info]' \ {-h,--help}'[Display a help message]' \ '*::text' wl-clipboard-2.2.1/completions/zsh/_wl-paste000066400000000000000000000023341447271603000210570ustar00rootroot00000000000000#compdef wl-paste local expl typeset -A opt_args _wl-paste_types() { local -a types args args=( ${(kv)opt_args[(I)-p|--primary]} ${(kv)opt_args[(I)-s|--seat]} ) types=( ${(@f)"$(wl-paste $args -l 2>/dev/null)"} ) local expl _wanted types expl 'type' compadd "$@" -a types } __all_seats() { local -a seats if (( $+commands[weston-info] && $+commands[sed] )); then seats=( ${(@f)"$(weston-info 2>/dev/null | sed -n '/wl_seat/{n;s/\s*name: //;p}')"} ) elif (( $+commands[loginctl] )); then seats=( ${(@f)"$(loginctl --no-legend --no-pager list-seats 2>/dev/null)"} ) fi if [[ -z $seats ]]; then # seat0 covers most cases, so its a good fallback. compadd "$@" - seat0 else compadd "$@" -a seats fi } _arguments -S -s \ {-n,--no-newline}'[Do not append a newline character]' \ {-l,--list-types}'[Instead of pasting, list the offered types]' \ {-p,--primary}'[Use the "primary" clipboard]' \ {-w,--watch}'[Run a command wach time the selection changes]:*::command:_normal' \ {-t+,--type=}'[Override the inferred MIME type for the content]:mimetype:_wl-paste_types' \ {-s+,--seat=}'[Pick the seat to work with]:seat:__all_seats' \ {-v,--version}'[Display version info]' \ {-h,--help}'[Display a help message]' wl-clipboard-2.2.1/completions/zsh/meson.build000066400000000000000000000005141447271603000214010ustar00rootroot00000000000000zsh_completion_dir = get_option('zshcompletiondir') if zsh_completion_dir == '' zsh_completion_dir = join_paths(get_option('datadir'), 'zsh', 'site-functions') endif if zsh_completion_dir != 'no' install_data('_wl-copy', install_dir: zsh_completion_dir) install_data('_wl-paste', install_dir: zsh_completion_dir) endif wl-clipboard-2.2.1/data/000077500000000000000000000000001447271603000150105ustar00rootroot00000000000000wl-clipboard-2.2.1/data/meson.build000066400000000000000000000001201447271603000171430ustar00rootroot00000000000000install_man('wl-copy.1') install_man('wl-paste.1') install_man('wl-clipboard.1')wl-clipboard-2.2.1/data/wl-clipboard.1000066400000000000000000000247441447271603000174640ustar00rootroot00000000000000.TH WL-CLIPBOARD 1 2023-04-22 wl-clipboard .SH NAME wl-clipboard \- Wayland copy and paste command line utilities .SH SYNOPSIS .B wl-copy [\fB\-\-primary\fR] [\fB\-\-type \fImime/type\fR] [\fItext\fR...] .PP .B wl-paste [\fB\-\-primary\fR] [\fB\-\-type \fImime/type\fR] .PP Only the most useful options are listed here; see below for the full list. .SH DESCRIPTION \fBwl-copy\fR copies the given \fItext\fR to the Wayland clipboard. If no \fItext\fR is given, \fBwl-copy\fR copies data from its standard input. .PP \fBwl-paste\fR pastes data from the Wayland clipboard to its standard output. .PP Although \fBwl-copy\fR and \fBwl-paste\fR are particularly optimized for plain text and other textual content formats, they fully support content of arbitrary MIME types. \fBwl-copy\fR automatically infers the type of the copied content by running \fBxdg-mime\fR(1) on it. \fBwl-paste\fR tries its best to pick a type to paste based on the list of offered MIME types and the extension of the file it's pasting into. If you're not satisfied with the type they pick or don't want to rely on this implicit type inference, you can explicitly specify the type to use with the \fB\-\-type\fR option. .SH OPTIONS To parse options, wl-clipboard uses the .BR getopt (3) library routines, whose features depend on the C library in use. In particular, it may be possible to specify \fB\-\-\fR as an argument on its own to prevent any further arguments from getting parsed as options (which lets you copy text containing words that start with the \fB-\fR sign), and to shorten long options to their unambiguous prefixes. .TP \fB\-p\fR, \fB\-\-primary Use the "primary" clipboard instead of the regular clipboard. .TP \fB\-o\fR, \fB\-\-paste-once\fR (for \fBwl-copy\fR) Only serve one paste request and then exit. Unless a clipboard manager specifically designed to prevent this is in use, this has the effect of clearing the clipboard after the first paste, which is useful for copying sensitive data such as passwords. Note that this may break pasting into some clients that expect to be able to paste multiple times, in particular pasting into XWayland windows is known to break when this option is used. .TP \fB\-f\fR, \fB\-\-foreground\fR (for \fBwl-copy\fR) By default, \fBwl-copy\fR forks and serves data requests in the background; this option overrides that behavior, causing \fBwl-copy\fR to run in the foreground. .TP \fB\-c\fR, \fB\-\-clear\fR (for \fBwl-copy\fR) Instead of copying anything, clear the clipboard so that nothing is copied. .TP \fB\-n\fR, \fB\-\-trim-newline\fR (for \fBwl-copy\fR) Do not copy the trailing newline character if it is present in the input file. .TP \fB\-n\fR, \fB\-\-no-newline\fR (for \fBwl-paste\fR) Do not append a newline character after the pasted clipboard content. This option is automatically enabled for non-text content types and when using the \fB\-\-watch\fR mode. .TP \fB\-t\fI mime/type\fR, \fB\-\-type\fI mime/type Override the automatically selected MIME type. For \fBwl-copy\fR this option controls which type \fBwl-copy\fR will offer the content as. For \fBwl-paste\fR it controls which of the offered types \fBwl-paste\fR will request the content in. In addition to specific MIME types such as \fIimage/png\fR, \fBwl-paste\fR also accepts generic type names such as \fItext\fR and \fIimage\fR which make it automatically pick some offered MIME type that matches the given generic name. .TP \fB\-s\fI seat-name\fR, \fB\-\-seat\fI seat-name Specify which seat \fBwl-copy\fR and \fBwl-paste\fR should work with. Wayland natively supports multi-seat configurations where each seat gets its own mouse pointer, keyboard focus, and among other things its own separate clipboard. The name of the default seat is likely \fIdefault\fR or \fIseat0\fR, and additional seat names normally come from the .BR udev (7) property \fBENV{WL_SEAT}\fR. You can view the list of the currently available seats as advertised by the compositor using the .BR weston-info (1) tool. If you don't specify the seat name explicitly, \fBwl-copy\fR and \fBwl-paste\fR will pick a seat arbitrarily. If you are using a single-seat system, there is little reason to use this option. .TP \fB\-l\fR, \fB\-\-list-types\fR (for \fBwl-paste\fR) Instead of pasting the selection, output the list of MIME types it is offered in. .TP \fB\-w\fI command\fR..., \fB\-\-watch \fIcommand\fR... (for \fBwl-paste\fR) Instead of pasting once and exiting, continuously watch the clipboard for changes, and run the specified \fIcommand\fR each time a new selection appears. The spawned process can read the clipboard contents from its standard input. \fBwl-paste\fR also sets the \fBCLIPBOARD_STATE\fR variable in the environment of the spawned processes (see below). .IP This mode requires a compositor that supports the wlroots data-control protocol. .TP \fB\-v\fR, \fB\-\-version Display the version of wl-clipboard and some short info about its license. .TP \fB\-h\fR, \fB\-\-help Display a short help message listing the available options. .SH ENVIRONMENT .TP .B WAYLAND_DISPLAY Specifies what Wayland server \fBwl-copy\fR and \fBwl-paste\fR should connect to. This is the same environment variable that you pass to other Wayland clients, such as graphical applications, that connect to this Wayland server. It is normally set up automatically by the graphical session and the Wayland compositor. See .BR wl_display_connect (3) for more details. .TP .B WAYLAND_DEBUG When set to \fB1\fR, causes the \fBwayland-client\fR(7) library to log every interaction \fBwl-copy\fR and \fBwl-paste\fR make with the Wayland compositor to stderr. .TP .B CLIPBOARD_STATE Set by \fBwl-paste\fR for the spawned command in \fB\-\-watch\fR mode. Currently the following possible values are \fIdefined\fR: .RS .TP CLIPBOARD_STATE=\fBdata Indicates that the clipboard contains data that the spawned command can read from its standard input. This is the most common case. .TP CLIPBOARD_STATE=\fBnil Indicates that the clipboard is empty. In this case the spawned command's standard input will be attached to \fI/dev/null\fR. Note that this is subtly different from the clipboard containing zero-sized data (which can be achieved, for instance, by running \fBwl-copy < /dev/null\fR). .TP CLIPBOARD_STATE=\fBclear Indicates that the clipboard is empty because of an explicit clear request, such as after running \fBwl-copy --clear\fR. As for \fBnil\fR, the command's standard input will be attached to \fI/dev/null\fR. .TP CLIPBOARD_STATE=\fBsensitive Indicates that the clipboard contains sensitive data such as a password or a key. It is probably best to avoid visibly displaying or persistently saving clipboard contents. .RE .IP Any client programs implementing the \fBCLIPBOARD_STATE\fR protocol are encouraged to implement proper support for all the values listed above, as well as to fall back to some sensible behavior if \fBCLIPBOARD_STATE\fR is unset or set to some unrecognized value (this is to leave the design space open for future extensions). However, the currently existing Wayland clipboard protocols don't let wl-clipboard identify the cases where \fBclear\fR and \fBsensitive\fR values should be set, so currently wl-clipboard only ever sets \fBCLIPBOARD_STATE\fR to \fBdata\fR or \fBnil\fR. .IP The \fBCLIPBOARD_STATE\fR protocol was intentionally designed to not be specific to either wl-clipboard or Wayland; in fact, other clipboard tools are encouraged to implement the same protocol. Currently, the SerenityOS .BR paste (1) utility is known to implement the same \fBCLIPBOARD_STATE\fR protocol. .SH FILES .TP .I /etc/mime.types If present, read by \fBwl-paste\fR to infer the MIME type to paste in based on the file name extension of its standard output. .SH BUGS Unless the Wayland compositor implements the wlroots data-control protocol, wl-clipboard has to resort to using a hack to access the clipboard: it will briefly pop up a tiny transparent surface (window). On some desktop environments (in particular when using tiling window managers), this can cause visual issues such as brief flashing. In some cases the Wayland compositor doesn't give focus to the popup surface, which prevents wl-clipboard from accessing the clipboard and manifests as a hang. .PP There is currently no way to copy data in multiple MIME types, such as multiple image formats, at the same time. .br See .nh . .hy .PP wl-clipboard is not always able to detect that a MIME type is textual, which may break pasting into clients that expect textual formats, not \fIapplication/something\fR. The workaround, same as for all format inference issues, is to specify the desired MIME type explicitly, such as \fBwl-copy \-\-type\fI text/plain\fR. .PP \fBwl-copy \-\-clear\fR and \fBwl-copy \-\-paste-once\fR don't always interact well with clipboard managers that are overeager to preserve clipboard contents. .PP Applications written using the GTK 3 toolkit copy text with \(dq\er\en\(dq (also known as CR LF) line endings, which takes most other software by surprise. wl-cipboard does nothing to rectify this. The recommended workaround is piping \fBwl-paste\fR output through .BR dos2unix (1) when pasting from a GTK 3 application. .br See .nh . .hy .PP When trying to paste content copied with \fBwl-copy\fR, \fBwl-copy\fR does not check whether the requested MIME type is among those it has offered, and always provides the same data in response. .SH EXAMPLES .TP Copy a simple text message: $ .BI wl-copy " Hello world!" .TP Copy a message starting with dashes: .BI "wl-copy -- " --long .TP Copy the list of files in \fI~/Downloads\fR: $ .IB "ls ~/Downloads" " | wl-copy" .TP Copy an image: $ .BI "wl-copy < " ~/Pictures/photo.png .TP Copy the previous command: $ .B wl-copy \(dq!!\(dq .TP Paste to a file, without appending a newline: $ .BI "wl-paste \-n > " clipboard.txt .TP Sort clipboard contents: $ .B wl-paste | sort | wl-copy .TP Upload clipboard contents to a pastebin on each change: $ .BI "wl-paste --watch nc " "paste.example.org 5555 .SH AUTHOR Written by Sergey Bugaev. .SH REPORTING BUGS Report wl-clipboard bugs to .br Please make sure to mention which Wayland compositor you are using, and attach \fBWAYLAND_DEBUG=1\fR debugging logs of wl-clipboard. .SH COPYRIGHT Copyright \(co 2018-2023 Sergey Bugaev. License GPLv3+: GNU GPL version 3 or later . .br This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. .SH SEE ALSO .BR xclip (1), .BR xsel (1), .BR wl-clipboard-x11 (1) wl-clipboard-2.2.1/data/wl-copy.1000066400000000000000000000000271447271603000164630ustar00rootroot00000000000000.so man1/wl-clipboard.1wl-clipboard-2.2.1/data/wl-paste.1000066400000000000000000000000271447271603000166250ustar00rootroot00000000000000.so man1/wl-clipboard.1wl-clipboard-2.2.1/meson.build000066400000000000000000000003151447271603000162400ustar00rootroot00000000000000project('wl-clipboard', 'c', version: '2.2.1', license: 'GPL-3.0-or-later', meson_version: '>= 0.47.0', default_options: 'c_std=gnu99' ) subdir('src') subdir('data') subdir('completions') wl-clipboard-2.2.1/meson_options.txt000066400000000000000000000005171447271603000175370ustar00rootroot00000000000000option('protocols', type: 'feature', value: 'enabled') option('zshcompletiondir', type: 'string', value: '', description: 'Directory for zsh completions. Set "no" to disable.' ) option('fishcompletiondir', type: 'string', value: '', description: 'Directory for fish completions. Set "no" to disable.' ) wl-clipboard-2.2.1/src/000077500000000000000000000000001447271603000146665ustar00rootroot00000000000000wl-clipboard-2.2.1/src/includes/000077500000000000000000000000001447271603000164745ustar00rootroot00000000000000wl-clipboard-2.2.1/src/includes/selection-protocols.h000066400000000000000000000021611447271603000226540ustar00rootroot00000000000000/* wl-clipboard * * Copyright © 2018-2023 Sergey Bugaev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef INCLUDES_SELECTION_PROTOCOLS_H #define INCLUDES_SELECTION_PROTOCOLS_H #include "config.h" #include #ifdef HAVE_WP_PRIMARY_SELECTION # include "wp-primary-selection.h" #endif #ifdef HAVE_GTK_PRIMARY_SELECTION # include "gtk-primary-selection.h" #endif #ifdef HAVE_WLR_DATA_CONTROL # include "wlr-data-control.h" #endif #endif /* INCLUDES_SELECTION_PROTOCOLS_H */ wl-clipboard-2.2.1/src/includes/shell-protocols.h000066400000000000000000000021271447271603000220000ustar00rootroot00000000000000/* wl-clipboard * * Copyright © 2018-2023 Sergey Bugaev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef INCLUDES_SHELL_PROTOCOLS_H #define INCLUDES_SHELL_PROTOCOLS_H #include "config.h" #include #ifdef HAVE_XDG_SHELL # include "xdg-shell.h" #endif #ifdef HAVE_GTK_SHELL # include "gtk-shell.h" #endif /* Not strictly speaking a shell */ #ifdef HAVE_XDG_ACTIVATION # include "xdg-activation.h" #endif #endif /* INCLUDES_SHELL_PROTOCOLS_H */ wl-clipboard-2.2.1/src/meson.build000066400000000000000000000031261447271603000170320ustar00rootroot00000000000000wayland = dependency( 'wayland-client', default_options: ['tests=false', 'documentation=false', 'dtd_validation=false'] ) cc = meson.get_compiler('c') have_memfd = cc.has_header_symbol('sys/syscall.h', 'SYS_memfd_create') have_shm_anon = cc.has_header_symbol('sys/mman.h', 'SHM_ANON') conf_data = configuration_data() conf_data.set('HAVE_MEMFD', have_memfd) conf_data.set('HAVE_SHM_ANON', have_shm_anon) subdir('protocol') configure_file(output: 'config.h', configuration: conf_data) lib = static_library( 'wl-clipboard', protocol_headers, 'includes/shell-protocols.h', 'includes/selection-protocols.h', 'util/string.h', 'util/string.c', 'util/files.h', 'util/files.c', 'util/misc.h', 'util/misc.c', 'types/source.h', 'types/source.c', 'types/offer.h', 'types/offer.c', 'types/device.h', 'types/device.c', 'types/device-manager.h', 'types/device-manager.c', 'types/keyboard.h', 'types/keyboard.c', 'types/seat.h', 'types/seat.c', 'types/shell.h', 'types/shell.c', 'types/shell-surface.h', 'types/shell-surface.c', 'types/popup-surface.h', 'types/popup-surface.c', 'types/registry.h', 'types/registry.c', 'types/copy-action.h', 'types/copy-action.c', dependencies: wayland, link_with: protocol_deps ) executable( 'wl-copy', 'wl-copy.c', protocol_headers, dependencies: wayland, link_with: lib, install: true ) executable( 'wl-paste', 'wl-paste.c', protocol_headers, dependencies: wayland, link_with: lib, install: true ) wl-clipboard-2.2.1/src/protocol/000077500000000000000000000000001447271603000165275ustar00rootroot00000000000000wl-clipboard-2.2.1/src/protocol/gtk-primary-selection.xml000066400000000000000000000237111447271603000235060ustar00rootroot00000000000000 Copyright © 2015, 2016 Red Hat Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice (including the next paragraph) shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. This protocol provides the ability to have a primary selection device to match that of the X server. This primary selection is a shortcut to the common clipboard selection, where text just needs to be selected in order to allow copying it elsewhere. The de facto way to perform this action is the middle mouse button, although it is not limited to this one. Clients wishing to honor primary selection should create a primary selection source and set it as the selection through wp_primary_selection_device.set_selection whenever the text selection changes. In order to minimize calls in pointer-driven text selection, it should happen only once after the operation finished. Similarly, a NULL source should be set when text is unselected. wp_primary_selection_offer objects are first announced through the wp_primary_selection_device.data_offer event. Immediately after this event, the primary data offer will emit wp_primary_selection_offer.offer events to let know of the mime types being offered. When the primary selection changes, the client with the keyboard focus will receive wp_primary_selection_device.selection events. Only the client with the keyboard focus will receive such events with a non-NULL wp_primary_selection_offer. Across keyboard focus changes, previously focused clients will receive wp_primary_selection_device.events with a NULL wp_primary_selection_offer. In order to request the primary selection data, the client must pass a recent serial pertaining to the press event that is triggering the operation, if the compositor deems the serial valid and recent, the wp_primary_selection_source.send event will happen in the other end to let the transfer begin. The client owning the primary selection should write the requested data, and close the file descriptor immediately. If the primary selection owner client disappeared during the transfer, the client reading the data will receive a wp_primary_selection_device.selection event with a NULL wp_primary_selection_offer, the client should take this as a hint to finish the reads related to the no longer existing offer. The primary selection owner should be checking for errors during writes, merely cancelling the ongoing transfer if any happened. The primary selection device manager is a singleton global object that provides access to the primary selection. It allows to create wp_primary_selection_source objects, as well as retrieving the per-seat wp_primary_selection_device objects. Create a new primary selection source. Create a new data device for a given seat. Destroy the primary selection device manager. Replaces the current selection. The previous owner of the primary selection will receive a wp_primary_selection_source.cancelled event. To unset the selection, set the source to NULL. Introduces a new wp_primary_selection_offer object that may be used to receive the current primary selection. Immediately following this event, the new wp_primary_selection_offer object will send wp_primary_selection_offer.offer events to describe the offered mime types. The wp_primary_selection_device.selection event is sent to notify the client of a new primary selection. This event is sent after the wp_primary_selection.data_offer event introducing this object, and after the offer has announced its mimetypes through wp_primary_selection_offer.offer. The data_offer is valid until a new offer or NULL is received or until the client loses keyboard focus. The client must destroy the previous selection data_offer, if any, upon receiving this event. Destroy the primary selection device. A wp_primary_selection_offer represents an offer to transfer the contents of the primary selection clipboard to the client. Similar to wl_data_offer, the offer also describes the mime types that the source will transferthat the data can be converted to and provides the mechanisms for transferring the data directly to the client. To transfer the contents of the primary selection clipboard, the client issues this request and indicates the mime type that it wants to receive. The transfer happens through the passed file descriptor (typically created with the pipe system call). The source client writes the data in the mime type representation requested and then closes the file descriptor. The receiving client reads from the read end of the pipe until EOF and closes its end, at which point the transfer is complete. Destroy the primary selection offer. Sent immediately after creating announcing the wp_primary_selection_offer through wp_primary_selection_device.data_offer. One event is sent per offered mime type. The source side of a wp_primary_selection_offer, it provides a way to describe the offered data and respond to requests to transfer the requested contents of the primary selection clipboard. This request adds a mime type to the set of mime types advertised to targets. Can be called several times to offer multiple types. Destroy the primary selection source. Request for the current primary selection contents from the client. Send the specified mime type over the passed file descriptor, then close it. This primary selection source is no longer valid. The client should clean up and destroy this primary selection source. wl-clipboard-2.2.1/src/protocol/gtk-shell.xml000066400000000000000000000064171447271603000211530ustar00rootroot00000000000000 gtk_shell is a protocol extension providing additional features for clients implementing it. wl-clipboard-2.2.1/src/protocol/meson.build000066400000000000000000000067621447271603000207040ustar00rootroot00000000000000protocols_opt = get_option('protocols') wayland_scanner = find_program('wayland-scanner', required: protocols_opt, native: true) wayland_protocols = dependency( 'wayland-protocols', version: '>= 1.12', required: protocols_opt, default_options: ['tests=false'] ) if wayland_scanner.found() have_xdg_shell = wayland_protocols.found() have_wp_primary_selection = wayland_protocols.found() and wayland_protocols.version().version_compare('>= 1.17') have_xdg_activation = wayland_protocols.found() and wayland_protocols.version().version_compare('>= 1.21') # these are bundled have_gtk_primary_selection = true have_wlr_data_control = true have_gtk_shell = true if wayland.version().version_compare('>= 1.15') scanner_code_command = 'private-code' else scanner_code_command = 'code' endif else have_xdg_shell = false have_wp_primary_selection = false have_xdg_activation = false have_gtk_primary_selection = false have_wlr_data_control = false have_gtk_shell = false endif conf_data.set('PROJECT_VERSION', '"@0@"'.format(meson.project_version())) conf_data.set('HAVE_XDG_SHELL', have_xdg_shell) conf_data.set('HAVE_WP_PRIMARY_SELECTION', have_wp_primary_selection) conf_data.set('HAVE_GTK_PRIMARY_SELECTION', have_gtk_primary_selection) conf_data.set('HAVE_WLR_DATA_CONTROL', have_wlr_data_control) conf_data.set('HAVE_XDG_ACTIVATION', have_xdg_activation) conf_data.set('HAVE_GTK_SHELL', have_gtk_shell) if wayland_protocols.found() if meson.version().version_compare('>= 0.58') protocols_path = wayland_protocols.get_variable('pkgdatadir') else protocols_path = wayland_protocols.get_pkgconfig_variable('pkgdatadir') endif endif protocols = [] if not have_xdg_shell warning('Building without xdg-shell support, wl-clipboard will be unable to work on some compositors') else xdg_shell_xml = join_paths(protocols_path, 'stable', 'xdg-shell', 'xdg-shell.xml') protocols += [['xdg-shell', xdg_shell_xml]] endif if have_wp_primary_selection wp_primary_selection_xml = join_paths(protocols_path, 'unstable', 'primary-selection', 'primary-selection-unstable-v1.xml') protocols += [['wp-primary-selection', wp_primary_selection_xml]] endif if not have_gtk_primary_selection warning('Building without primary selection support') else gtk_primary_selection_xml = 'gtk-primary-selection.xml' protocols += [['gtk-primary-selection', gtk_primary_selection_xml]] endif if have_wlr_data_control wlr_data_control_xml = 'wlr-data-control-unstable-v1.xml' protocols += [['wlr-data-control', wlr_data_control_xml]] endif if have_xdg_activation xdg_activation_xml = join_paths(protocols_path, 'staging', 'xdg-activation', 'xdg-activation-v1.xml') protocols += [['xdg-activation', xdg_activation_xml]] endif if have_gtk_shell gtk_shell_xml = 'gtk-shell.xml' protocols += [['gtk-shell', gtk_shell_xml]] endif protocol_deps = [] protocol_headers = [] foreach protocol : protocols name = protocol[0] xml = protocol[1] header = custom_target(name + ' client header', input: xml, output: name + '.h', command: [wayland_scanner, 'client-header', '@INPUT@', '@OUTPUT@'] ) impl = custom_target(name + ' code', input: xml, output: name + '.c', command: [wayland_scanner, scanner_code_command, '@INPUT@', '@OUTPUT@'] ) protocol_headers += header lib = static_library(name, impl, header, dependencies: wayland) protocol_deps += lib endforeach wl-clipboard-2.2.1/src/protocol/wlr-data-control-unstable-v1.xml000066400000000000000000000274161447271603000246130ustar00rootroot00000000000000 Copyright © 2018 Simon Ser Copyright © 2019 Ivan Molodetskikh Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted without fee, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation, and that the name of the copyright holders not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. The copyright holders make no representations about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty. THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. This protocol allows a privileged client to control data devices. In particular, the client will be able to manage the current selection and take the role of a clipboard manager. Warning! The protocol described in this file is experimental and backward incompatible changes may be made. Backward compatible changes may be added together with the corresponding interface version bump. Backward incompatible changes are done by bumping the version number in the protocol and interface names and resetting the interface version. Once the protocol is to be declared stable, the 'z' prefix and the version number in the protocol and interface names are removed and the interface version number is reset. This interface is a manager that allows creating per-seat data device controls. Create a new data source. Create a data device that can be used to manage a seat's selection. All objects created by the manager will still remain valid, until their appropriate destroy request has been called. This interface allows a client to manage a seat's selection. When the seat is destroyed, this object becomes inert. This request asks the compositor to set the selection to the data from the source on behalf of the client. The given source may not be used in any further set_selection or set_primary_selection requests. Attempting to use a previously used source is a protocol error. To unset the selection, set the source to NULL. Destroys the data device object. The data_offer event introduces a new wlr_data_control_offer object, which will subsequently be used in either the wlr_data_control_device.selection event (for the regular clipboard selections) or the wlr_data_control_device.primary_selection event (for the primary clipboard selections). Immediately following the wlr_data_control_device.data_offer event, the new data_offer object will send out wlr_data_control_offer.offer events to describe the MIME types it offers. The selection event is sent out to notify the client of a new wlr_data_control_offer for the selection for this device. The wlr_data_control_device.data_offer and the wlr_data_control_offer.offer events are sent out immediately before this event to introduce the data offer object. The selection event is sent to a client when a new selection is set. The wlr_data_control_offer is valid until a new wlr_data_control_offer or NULL is received. The client must destroy the previous selection wlr_data_control_offer, if any, upon receiving this event. The first selection event is sent upon binding the wlr_data_control_device object. This data control object is no longer valid and should be destroyed by the client. The primary_selection event is sent out to notify the client of a new wlr_data_control_offer for the primary selection for this device. The wlr_data_control_device.data_offer and the wlr_data_control_offer.offer events are sent out immediately before this event to introduce the data offer object. The primary_selection event is sent to a client when a new primary selection is set. The wlr_data_control_offer is valid until a new wlr_data_control_offer or NULL is received. The client must destroy the previous primary selection wlr_data_control_offer, if any, upon receiving this event. If the compositor supports primary selection, the first primary_selection event is sent upon binding the wlr_data_control_device object. This request asks the compositor to set the primary selection to the data from the source on behalf of the client. The given source may not be used in any further set_selection or set_primary_selection requests. Attempting to use a previously used source is a protocol error. To unset the primary selection, set the source to NULL. The compositor will ignore this request if it does not support primary selection. The wlr_data_control_source object is the source side of a wlr_data_control_offer. It is created by the source client in a data transfer and provides a way to describe the offered data and a way to respond to requests to transfer the data. This request adds a MIME type to the set of MIME types advertised to targets. Can be called several times to offer multiple types. Calling this after wlr_data_control_device.set_selection is a protocol error. Destroys the data source object. Request for data from the client. Send the data as the specified MIME type over the passed file descriptor, then close it. This data source is no longer valid. The data source has been replaced by another data source. The client should clean up and destroy this data source. A wlr_data_control_offer represents a piece of data offered for transfer by another client (the source client). The offer describes the different MIME types that the data can be converted to and provides the mechanism for transferring the data directly from the source client. To transfer the offered data, the client issues this request and indicates the MIME type it wants to receive. The transfer happens through the passed file descriptor (typically created with the pipe system call). The source client writes the data in the MIME type representation requested and then closes the file descriptor. The receiving client reads from the read end of the pipe until EOF and then closes its end, at which point the transfer is complete. This request may happen multiple times for different MIME types. Destroys the data offer object. Sent immediately after creating the wlr_data_control_offer object. One event per offered MIME type. wl-clipboard-2.2.1/src/types/000077500000000000000000000000001447271603000160325ustar00rootroot00000000000000wl-clipboard-2.2.1/src/types/copy-action.c000066400000000000000000000125761447271603000204360ustar00rootroot00000000000000/* wl-clipboard * * Copyright © 2018-2023 Sergey Bugaev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "types/copy-action.h" #include "types/device.h" #include "types/source.h" #include "types/popup-surface.h" #include "util/misc.h" #include #include #include #include #include #include #include #include static void do_set_selection(struct copy_action *self, uint32_t serial) { /* Set the selection and make sure it reaches * the display before we do anything else, * such as destroying the surface or exiting. * Make sure to unset the callback to prevent * reentrancy issues. */ if (self->popup_surface != NULL) { self->popup_surface->on_focus = NULL; self->popup_surface->data = NULL; } device_set_selection(self->device, self->source, serial, self->primary); wl_display_roundtrip(self->device->wl_display); /* Now, if we have used a popup surface, destroy it */ if (self->popup_surface != NULL) { popup_surface_destroy(self->popup_surface); self->popup_surface = NULL; } /* And invoke the callback */ if (self->did_set_selection_callback != NULL) { self->did_set_selection_callback(self); } } static void on_focus( struct popup_surface *popup_surface, uint32_t serial ) { struct copy_action *self = (struct copy_action *) popup_surface->data; do_set_selection(self, serial); } static void do_send(struct source *source, const char *mime_type, int fd) { struct copy_action *self = source->data; /* Unset O_NONBLOCK */ fcntl(fd, F_SETFL, 0); if (self->fd_to_copy_from != -1) { /* Copy the file to the given file descriptor * by spawning an appropriate cat process. */ pid_t pid = fork(); if (pid < 0) { perror("fork"); close(fd); return; } if (pid == 0) { dup2(self->fd_to_copy_from, STDIN_FILENO); close(self->fd_to_copy_from); dup2(fd, STDOUT_FILENO); close(fd); signal(SIGHUP, SIG_DFL); signal(SIGPIPE, SIG_DFL); execlp("cat", "cat", NULL); perror("exec cat"); exit(1); } close(fd); /* Wait for the cat process to exit. This effectively * means waiting for the other side to read the whole * file. In theory, a malicious client could perform a * denial-of-serivice attack against us. Perhaps we * should switch to an asynchronous child waiting scheme * instead. */ waitpid(pid, NULL, 0); /* Seek back to the beginning of the file */ off_t rc = lseek(self->fd_to_copy_from, 0, SEEK_SET); if (rc < 0) { perror("lseek"); } } else { /* We'll perform the copy ourselves */ FILE *f = fdopen(fd, "w"); if (f == NULL) { perror("fdopen"); close(fd); return; } if (self->data_to_copy.ptr != NULL) { /* Just copy the given chunk of data */ fwrite(self->data_to_copy.ptr, 1, self->data_to_copy.len, f); } else if (self->argv_to_copy != NULL) { /* Copy an argv-style string array, * inserting spaces between items. */ int is_first = 1; for (argv_t word = self->argv_to_copy; *word != NULL; word++) { if (!is_first) { fwrite(" ", 1, 1, f); } is_first = 0; fwrite(*word, 1, strlen(*word), f); } } else { bail("Unreachable: nothing to copy"); } fclose(f); } if (self->pasted_callback != NULL) { self->pasted_callback(self); } } static void forward_cancel(struct source *source) { struct copy_action *self = source->data; if (self->cancelled_callback != NULL) { self->cancelled_callback(self); } } void copy_action_init(struct copy_action *self) { if (self->source != NULL) { self->source->send_callback = do_send; self->source->cancelled_callback = forward_cancel; self->source->data = self; } /* See if we can just set the selection directly */ if (!self->device->needs_popup_surface) { /* If we can, it doesn't actually require * a serial, so passing zero will do. */ do_set_selection(self, 0); } else { /* If we cannot, schedule to do it later, * when our popup surface gains keyboard focus. */ self->popup_surface->on_focus = on_focus; self->popup_surface->data = self; popup_surface_init(self->popup_surface); } } wl-clipboard-2.2.1/src/types/copy-action.h000066400000000000000000000031711447271603000204320ustar00rootroot00000000000000/* wl-clipboard * * Copyright © 2018-2023 Sergey Bugaev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef TYPES_COPY_ACTION_H #define TYPES_COPY_ACTION_H #include "util/string.h" #include struct device; struct source; struct popup_surface; struct copy_action { /* These fields are initialized by the creator */ struct device *device; struct source *source; struct popup_surface *popup_surface; int primary; void (*did_set_selection_callback)(struct copy_action *self); void (*pasted_callback)(struct copy_action *self); void (*cancelled_callback)(struct copy_action *self); /* Exactly one of these fields must be non-null if the source * is non-null, otherwise all these fields must be null. * The null value for fd_to_copy_from is -1. */ int fd_to_copy_from; argv_t argv_to_copy; struct { const char *ptr; size_t len; } data_to_copy; }; void copy_action_init(struct copy_action *self); #endif /* TYPES_COPY_ACTION_H */ wl-clipboard-2.2.1/src/types/device-manager.c000066400000000000000000000073351447271603000210550ustar00rootroot00000000000000/* wl-clipboard * * Copyright © 2018-2023 Sergey Bugaev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "types/device-manager.h" #include "types/device.h" #include "types/source.h" #include "types/seat.h" #include "includes/selection-protocols.h" #include struct source *device_manager_create_source(struct device_manager *self) { return self->do_create_source(self); } struct device *device_manager_get_device( struct device_manager *self, struct seat *seat ) { return self->do_get_device(self, seat); } /* Macros to reduce implementation boilerplate */ #define CREATE_SOURCE(type, source_type, method_name) \ static struct source *device_manager_ ## type ## _do_create_source( \ struct device_manager *self \ ) { \ struct type *proxy = (struct type *) self->proxy; \ struct source *source = calloc(1, sizeof(struct source)); \ source->proxy = (struct wl_proxy *) type ## _ ## method_name(proxy); \ source_init_ ## source_type(source); \ return source; \ } #define GET_DEVICE(type, device_type, method_name) \ static struct device *device_manager_ ## type ## _do_get_device( \ struct device_manager *self, \ struct seat *seat_wrapper \ ) { \ struct type *proxy = (struct type *) self->proxy; \ struct wl_seat *seat = (struct wl_seat *) seat_wrapper->proxy; \ struct device *device = calloc(1, sizeof(struct device)); \ device->proxy = (struct wl_proxy *) type ## _ ## method_name(proxy, seat); \ device->wl_display = self->wl_display; \ device_init_ ## device_type(device); \ return device; \ } #define INIT(type) \ void device_manager_init_ ## type(struct device_manager *self) { \ self->do_create_source = device_manager_ ## type ## _do_create_source; \ self->do_get_device = device_manager_ ## type ## _do_get_device; \ } /* Core Wayland implementation */ CREATE_SOURCE(wl_data_device_manager, wl_data_source, create_data_source) GET_DEVICE(wl_data_device_manager, wl_data_device, get_data_device) INIT(wl_data_device_manager) /* gtk-primary-selection implementation */ #ifdef HAVE_GTK_PRIMARY_SELECTION CREATE_SOURCE( gtk_primary_selection_device_manager, gtk_primary_selection_source, create_source ) GET_DEVICE( gtk_primary_selection_device_manager, gtk_primary_selection_device, get_device ) INIT(gtk_primary_selection_device_manager) #endif /* HAVE_GTK_PRIMARY_SELECTION */ /* wp-primary-selection implementation */ #ifdef HAVE_WP_PRIMARY_SELECTION CREATE_SOURCE( zwp_primary_selection_device_manager_v1, zwp_primary_selection_source_v1, create_source ) GET_DEVICE( zwp_primary_selection_device_manager_v1, zwp_primary_selection_device_v1, get_device ) INIT(zwp_primary_selection_device_manager_v1) #endif /* HAVE_WP_PRIMARY_SELECTION */ /* wlr-data-control implementation */ #ifdef HAVE_WLR_DATA_CONTROL CREATE_SOURCE( zwlr_data_control_manager_v1, zwlr_data_control_source_v1, create_data_source ) GET_DEVICE( zwlr_data_control_manager_v1, zwlr_data_control_device_v1, get_data_device ) INIT(zwlr_data_control_manager_v1) #endif /* HAVE_WLR_DATA_CONTROL */ wl-clipboard-2.2.1/src/types/device-manager.h000066400000000000000000000037371447271603000210640ustar00rootroot00000000000000/* wl-clipboard * * Copyright © 2018-2023 Sergey Bugaev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef TYPES_DEVICE_MANAGER_H #define TYPES_DEVICE_MANAGER_H #include "includes/selection-protocols.h" #include struct seat; struct device; struct source; struct device_manager { /* These fields are initialized by the creator */ struct wl_proxy *proxy; struct wl_display *wl_display; /* These fields are initialized by the implementation */ struct source *(*do_create_source)(struct device_manager *self); struct device *(*do_get_device)( struct device_manager *self, struct seat *seat ); }; struct source *device_manager_create_source(struct device_manager *self); struct device *device_manager_get_device( struct device_manager *self, struct seat *seat ); /* Initializers */ void device_manager_init_wl_data_device_manager(struct device_manager *self); #ifdef HAVE_GTK_PRIMARY_SELECTION void device_manager_init_gtk_primary_selection_device_manager( struct device_manager *self ); #endif #ifdef HAVE_WP_PRIMARY_SELECTION void device_manager_init_zwp_primary_selection_device_manager_v1( struct device_manager *self ); #endif #ifdef HAVE_WLR_DATA_CONTROL void device_manager_init_zwlr_data_control_manager_v1( struct device_manager *self ); #endif #endif /* TYPES_DEVICE_MANAGER_H */ wl-clipboard-2.2.1/src/types/device.c000066400000000000000000000166711447271603000174500ustar00rootroot00000000000000/* wl-clipboard * * Copyright © 2018-2023 Sergey Bugaev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "config.h" #include "types/device.h" #include "types/offer.h" #include "types/source.h" #include "includes/selection-protocols.h" #include #include int device_supports_selection(struct device *self, int primary) { return self->supports_selection(self, primary); } void device_set_selection( struct device *self, struct source *source, uint32_t serial, int primary ) { self->do_set_selection(self, source, serial, primary); } /* Macros to reduce implementation boilerplate */ #define SUPPORTS_SELECTION(type, expr) \ static int device_supports_selection_on_ ## type( \ struct device *self, \ int primary \ ) { \ return expr; \ } #define SET_SELECTION_IMPL(type, source_type, impl) \ static void device_set_selection_on_ ## type( \ struct device *self, \ struct source *source_wrapper, \ uint32_t serial, \ int primary \ ) { \ struct type *device = (struct type *) self->proxy; \ struct source_type *source = NULL; \ if (source_wrapper != NULL) { \ source = (struct source_type *) source_wrapper->proxy; \ } \ impl \ } #define DATA_OFFER_HANDLER(type, offer_type) \ static void type ## _data_offer_handler( \ void *data, \ struct type *device, \ struct offer_type *offer_proxy \ ) { \ struct device *self = data; \ struct offer *offer = calloc(1, sizeof(struct offer)); \ offer->proxy = (struct wl_proxy *) offer_proxy; \ offer_init_ ## offer_type(offer); \ if (self->new_offer_callback) { \ self->new_offer_callback(offer); \ } \ } #define SELECTION_HANDLER(type, offer_type, selection_event, primary) \ static void type ## _ ## selection_event ## _handler( \ void *data, \ struct type *device, \ struct offer_type *offer_proxy \ ) { \ struct device *self = data; \ struct offer *offer = NULL; \ if (offer_proxy != NULL) { \ offer = wl_proxy_get_user_data((struct wl_proxy *) offer_proxy); \ } \ if (self->selection_callback) { \ self->selection_callback(offer, primary); \ } \ } #define INIT(type, needs_surface) \ void device_init_ ## type(struct device *self) { \ struct type *device = (struct type *) self->proxy; \ type ## _add_listener(device, &type ## _listener, self); \ self->supports_selection = device_supports_selection_on_ ## type; \ self->needs_popup_surface = needs_surface; \ self->do_set_selection = device_set_selection_on_ ## type; \ } /* Core Wayland implementation */ SUPPORTS_SELECTION(wl_data_device, !primary) SET_SELECTION_IMPL(wl_data_device, wl_data_source, { wl_data_device_set_selection(device, source, serial); }) DATA_OFFER_HANDLER(wl_data_device, wl_data_offer) SELECTION_HANDLER(wl_data_device, wl_data_offer, selection, 0) static const struct wl_data_device_listener wl_data_device_listener = { .data_offer = wl_data_device_data_offer_handler, .selection = wl_data_device_selection_handler }; INIT(wl_data_device, 1) /* gtk-primary-selection implementation */ #ifdef HAVE_GTK_PRIMARY_SELECTION SUPPORTS_SELECTION(gtk_primary_selection_device, primary) SET_SELECTION_IMPL(gtk_primary_selection_device, gtk_primary_selection_source, { gtk_primary_selection_device_set_selection(device, source, serial); }) DATA_OFFER_HANDLER(gtk_primary_selection_device, gtk_primary_selection_offer) SELECTION_HANDLER( gtk_primary_selection_device, gtk_primary_selection_offer, selection, 1 ) static const struct gtk_primary_selection_device_listener gtk_primary_selection_device_listener = { .data_offer = gtk_primary_selection_device_data_offer_handler, .selection = gtk_primary_selection_device_selection_handler }; INIT(gtk_primary_selection_device, 1) #endif /* HAVE_GTK_PRIMARY_SELECTION */ /* wp-primary-selection implementation */ #ifdef HAVE_WP_PRIMARY_SELECTION SUPPORTS_SELECTION(zwp_primary_selection_device_v1, primary) SET_SELECTION_IMPL( zwp_primary_selection_device_v1, zwp_primary_selection_source_v1, { zwp_primary_selection_device_v1_set_selection(device, source, serial); } ) DATA_OFFER_HANDLER( zwp_primary_selection_device_v1, zwp_primary_selection_offer_v1 ) SELECTION_HANDLER( zwp_primary_selection_device_v1, zwp_primary_selection_offer_v1, selection, 1 ) static const struct zwp_primary_selection_device_v1_listener zwp_primary_selection_device_v1_listener = { .data_offer = zwp_primary_selection_device_v1_data_offer_handler, .selection = zwp_primary_selection_device_v1_selection_handler }; INIT(zwp_primary_selection_device_v1, 1) #endif /* HAVE_WP_PRIMARY_SELECTION */ /* wlr-data-control implementation */ #ifdef HAVE_WLR_DATA_CONTROL enum TriState { Unknown, Yes, No }; /* Whether wlr-data-control supports primary selection */ static enum TriState device_wlr_supports_primary_selection = Unknown; static int device_get_wlr_supports_selection(struct device *self, int primary) { if (!primary) { return 1; } if (device_wlr_supports_primary_selection == Yes) { return 1; } else if (device_wlr_supports_primary_selection == No) { return 0; } wl_display_roundtrip(self->wl_display); if (device_wlr_supports_primary_selection == Yes) { return 1; } else { device_wlr_supports_primary_selection = No; return 0; } } SUPPORTS_SELECTION( zwlr_data_control_device_v1, device_get_wlr_supports_selection(self, primary) ) SET_SELECTION_IMPL(zwlr_data_control_device_v1, zwlr_data_control_source_v1, { if (!primary) { zwlr_data_control_device_v1_set_selection(device, source); } else { zwlr_data_control_device_v1_set_primary_selection(device, source); } }) DATA_OFFER_HANDLER(zwlr_data_control_device_v1, zwlr_data_control_offer_v1) SELECTION_HANDLER( zwlr_data_control_device_v1, zwlr_data_control_offer_v1, selection, 0 ) static void zwlr_data_control_device_v1_primary_selection_handler( void *data, struct zwlr_data_control_device_v1 *device, struct zwlr_data_control_offer_v1 *offer_proxy ) { device_wlr_supports_primary_selection = Yes; struct device *self = data; struct offer *offer = NULL; if (offer_proxy != NULL) { offer = wl_proxy_get_user_data((struct wl_proxy *) offer_proxy); } if (self->selection_callback != NULL) { self->selection_callback(offer, 1); } } static const struct zwlr_data_control_device_v1_listener zwlr_data_control_device_v1_listener = { .data_offer = zwlr_data_control_device_v1_data_offer_handler, .selection = zwlr_data_control_device_v1_selection_handler, .primary_selection = zwlr_data_control_device_v1_primary_selection_handler }; INIT(zwlr_data_control_device_v1, 0) #endif /* HAVE_WLR_DATA_CONTROL */ wl-clipboard-2.2.1/src/types/device.h000066400000000000000000000040141447271603000174410ustar00rootroot00000000000000/* wl-clipboard * * Copyright © 2018-2023 Sergey Bugaev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef TYPES_DEVICE_H #define TYPES_DEVICE_H #include "includes/selection-protocols.h" #include struct offer; struct source; struct device { /* These fields are initialized by the creator */ void (*new_offer_callback)(struct offer *offer); void (*selection_callback)(struct offer *offer, int primary); void *data; struct wl_proxy *proxy; struct wl_display *wl_display; /* These fields are initialized by the implementation */ int (*supports_selection)(struct device *self, int primary); int needs_popup_surface; void (*do_set_selection)( struct device *self, struct source *source, uint32_t serial, int primary ); }; int device_supports_selection(struct device *self, int primary); void device_set_selection( struct device *self, struct source *source, uint32_t serial, int primary ); /* Initializers */ void device_init_wl_data_device(struct device *self); #ifdef HAVE_GTK_PRIMARY_SELECTION void device_init_gtk_primary_selection_device(struct device *self); #endif #ifdef HAVE_WP_PRIMARY_SELECTION void device_init_zwp_primary_selection_device_v1(struct device *self); #endif #ifdef HAVE_WLR_DATA_CONTROL void device_init_zwlr_data_control_device_v1(struct device *self); #endif #endif /* TYPES_DEVICE_H */ wl-clipboard-2.2.1/src/types/keyboard.c000066400000000000000000000042111447271603000177740ustar00rootroot00000000000000/* wl-clipboard * * Copyright © 2018-2023 Sergey Bugaev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "types/keyboard.h" #include static void wl_keyboard_keymap_handler( void *data, struct wl_keyboard *keyboard, uint32_t format, int fd, uint32_t size ) { close(fd); } static void wl_keyboard_enter_handler( void *data, struct wl_keyboard *keyboard, uint32_t serial, struct wl_surface *surface, struct wl_array *keys ) { struct keyboard *self = (struct keyboard *) data; if (self->on_focus != NULL) { self->on_focus(self, serial); } } static void wl_keyboard_leave_handler( void *data, struct wl_keyboard *keyboard, uint32_t serial, struct wl_surface *surface ) {} static void wl_keyboard_key_handler( void *data, struct wl_keyboard *keyboard, uint32_t serial, uint32_t time, uint32_t key, uint32_t state ) {} static void wl_keyboard_modifiers_handler( void *data, struct wl_keyboard *keyboard, uint32_t serial, uint32_t mods_depressed, uint32_t mods_latched, uint32_t mods_locked, uint32_t group ) {} static const struct wl_keyboard_listener wl_keyboard_listener = { .keymap = wl_keyboard_keymap_handler, .enter = wl_keyboard_enter_handler, .leave = wl_keyboard_leave_handler, .key = wl_keyboard_key_handler, .modifiers = wl_keyboard_modifiers_handler, }; void keyboard_init(struct keyboard *self) { wl_keyboard_add_listener(self->proxy, &wl_keyboard_listener, self); } wl-clipboard-2.2.1/src/types/keyboard.h000066400000000000000000000021041447271603000200000ustar00rootroot00000000000000/* wl-clipboard * * Copyright © 2018-2023 Sergey Bugaev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef TYPES_KEYBOARD_H #define TYPES_KEYBOARD_H #include #include struct keyboard { /* These fields are initialized by the creator */ struct wl_keyboard *proxy; void (*on_focus)(struct keyboard *self, uint32_t serial); void *data; }; void keyboard_init(struct keyboard *self); #endif /* TYPES_KEYBOARD_H */ wl-clipboard-2.2.1/src/types/offer.c000066400000000000000000000054571447271603000173120ustar00rootroot00000000000000/* wl-clipboard * * Copyright © 2018-2023 Sergey Bugaev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "types/offer.h" #include "includes/selection-protocols.h" #include #include #include void offer_receive(struct offer *self, const char *mime_type, int fd) { self->do_receive(self->proxy, mime_type, fd); } void offer_destroy(struct offer *self) { self->do_destroy(self->proxy); wl_array_release(&self->offered_mime_types); free(self); } /* Macros to reduce implementation boilerplate */ #define OFFER_HANDLER(type) \ static void type ## _offer_handler( \ void *data, \ struct type *proxy, \ const char *mime_type \ ) { \ struct offer *self = data; \ char *ptr = wl_array_add( \ &self->offered_mime_types, \ strlen(mime_type) + 1 \ ); \ strcpy(ptr, mime_type); \ } #define LISTENER(type) \ static const struct type ## _listener type ## _listener = { \ .offer = type ## _offer_handler \ }; #define INIT(type) \ void offer_init_ ## type(struct offer *self) { \ self->do_receive = \ (void (*)(struct wl_proxy *, const char *, int)) type ## _receive; \ self->do_destroy = (void (*)(struct wl_proxy *)) type ## _destroy; \ wl_array_init(&self->offered_mime_types); \ struct type *proxy = (struct type *) self->proxy; \ type ## _add_listener(proxy, &type ## _listener, self); \ } /* Core Wayland implementation */ OFFER_HANDLER(wl_data_offer) LISTENER(wl_data_offer) INIT(wl_data_offer) /* gtk-primary-selection implementation */ #ifdef HAVE_GTK_PRIMARY_SELECTION OFFER_HANDLER(gtk_primary_selection_offer) LISTENER(gtk_primary_selection_offer) INIT(gtk_primary_selection_offer) #endif /* HAVE_GTK_PRIMARY_SELECTION */ /* wp-primary-selection implementation */ #ifdef HAVE_WP_PRIMARY_SELECTION OFFER_HANDLER(zwp_primary_selection_offer_v1) LISTENER(zwp_primary_selection_offer_v1) INIT(zwp_primary_selection_offer_v1) #endif /* HAVE_WP_PRIMARY_SELECTION */ /* wlr-data-control implementation */ #ifdef HAVE_WLR_DATA_CONTROL OFFER_HANDLER(zwlr_data_control_offer_v1) LISTENER(zwlr_data_control_offer_v1) INIT(zwlr_data_control_offer_v1) #endif /* HAVE_WLR_DATA_CONTROL */ wl-clipboard-2.2.1/src/types/offer.h000066400000000000000000000037471447271603000173170ustar00rootroot00000000000000/* wl-clipboard * * Copyright © 2018-2023 Sergey Bugaev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef TYPES_OFFER_H #define TYPES_OFFER_H #include "includes/selection-protocols.h" #include #include struct offer { /* This field is initialized by the creator */ struct wl_proxy *proxy; /* These fields are initialized by the implementation */ void (*do_receive)(struct wl_proxy *proxy, const char *mime_type, int fd); void (*do_destroy)(struct wl_proxy *proxy); struct wl_array offered_mime_types; }; #define offer_for_each_mime_type(offer, mime_type) \ for ( \ const char *mime_type = offer->offered_mime_types.data; \ mime_type != (const char *) offer->offered_mime_types.data + \ offer->offered_mime_types.size; \ mime_type += strlen(mime_type) + 1 \ ) void offer_receive(struct offer *self, const char *mime_type, int fd); void offer_destroy(struct offer *self); /* Initializers */ void offer_init_wl_data_offer(struct offer *self); #ifdef HAVE_GTK_PRIMARY_SELECTION void offer_init_gtk_primary_selection_offer(struct offer *self); #endif #ifdef HAVE_WP_PRIMARY_SELECTION void offer_init_zwp_primary_selection_offer_v1(struct offer *self); #endif #ifdef HAVE_WLR_DATA_CONTROL void offer_init_zwlr_data_control_offer_v1(struct offer *self); #endif #endif /* TYPES_OFFER_H */ wl-clipboard-2.2.1/src/types/popup-surface.c000066400000000000000000000132261447271603000207730ustar00rootroot00000000000000/* wl-clipboard * * Copyright © 2018-2023 Sergey Bugaev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "types/popup-surface.h" #include "types/registry.h" #include "types/seat.h" #include "types/keyboard.h" #include "types/shell.h" #include "types/shell-surface.h" #include "util/files.h" #include "util/misc.h" #include #include #include static void forward_on_focus( struct keyboard *keyboard, uint32_t serial ) { struct popup_surface *self = (struct popup_surface *) keyboard->data; if (self->on_focus != NULL) { self->on_focus(self, serial); } } void popup_surface_init(struct popup_surface *self) { self->shell = registry_find_shell(self->registry); if (self->shell == NULL) { complain_about_missing_shell(); } self->keyboard = seat_get_keyboard(self->seat); if (self->keyboard == NULL) { bail("This seat has no keyboard"); } self->keyboard->on_focus = forward_on_focus; self->keyboard->data = self; /* Make sure that we get the keyboard * object before we create the surface, * so that we get the enter event. */ wl_display_dispatch(self->registry->wl_display); struct wl_compositor *wl_compositor = self->registry->wl_compositor; if (wl_compositor == NULL) { complain_about_missing_global("wl_compositor"); } self->wl_surface = wl_compositor_create_surface(wl_compositor); self->shell_surface = shell_create_shell_surface( self->shell, self->wl_surface ); #ifdef HAVE_GTK_SHELL if (self->registry->gtk_shell1 != NULL) { self->gtk_surface = gtk_shell1_get_gtk_surface( self->registry->gtk_shell1, self->wl_surface ); } #endif /* Signal that the surface is ready to be configured */ wl_surface_commit(self->wl_surface); wl_display_roundtrip(self->registry->wl_display); if (self->wl_surface == NULL) { /* It's possible that we were given focus * (without ever commiting a buffer) during * the above roundtrip, in which case we have * already fired the callback and have likely * already destroyed the surface. No need to * do anything further in that case. */ free(self); return; } /* Remember that after this point, we should * free() self when it gets destroyed. */ self->should_free_self = 1; int width = 1; int height = 1; int stride = width * 4; int size = stride * height; /* Open an anonymous file and write some zero bytes to it */ int fd = create_anonymous_file(); int rc = ftruncate(fd, size); if (rc < 0) { perror("ftruncate"); } /* Create a shared memory pool */ struct wl_shm *wl_shm = self->registry->wl_shm; if (wl_shm == NULL) { complain_about_missing_global("wl_shm"); } struct wl_shm_pool *wl_shm_pool = wl_shm_create_pool(wl_shm, fd, size); /* Allocate the buffer in that pool */ struct wl_buffer *wl_buffer = wl_shm_pool_create_buffer( wl_shm_pool, 0, width, height, stride, WL_SHM_FORMAT_ARGB8888 ); /* We're using ARGB, so zero bytes mean * a fully transparent pixel, which happens * to be exactly what we want. */ wl_surface_attach(self->wl_surface, wl_buffer, 0, 0); wl_surface_damage(self->wl_surface, 0, 0, width, height); /* Ask the compositor nicely to give us focus */ #ifdef HAVE_GTK_SHELL if (self->gtk_surface != NULL) { gtk_surface1_present(self->gtk_surface, 0); } #endif #ifdef HAVE_XDG_ACTIVATION if (self->registry->xdg_activation_v1 != NULL) { /* See if someone was kind enough to leave * some tokens for us in the environment. */ const char *token = getenv("XDG_ACTIVATION_TOKEN"); if (token == NULL) { token = getenv("DESKTOP_STARTUP_ID"); } if (token != NULL) { xdg_activation_v1_activate( self->registry->xdg_activation_v1, token, self->wl_surface ); } } #endif wl_surface_commit(self->wl_surface); } void popup_surface_destroy(struct popup_surface *self) { /* We cannot destroy the keyboard * because it acts as a listener, * and there's no way to reset that. * So just unreference ourselves. */ self->keyboard->on_focus = NULL; self->keyboard->data = NULL; shell_surface_destroy(self->shell_surface); #ifdef HAVE_GTK_SHELL if (self->gtk_surface != NULL) { if ( gtk_surface1_get_version(self->gtk_surface) >= GTK_SURFACE1_RELEASE_SINCE_VERSION ) { gtk_surface1_release(self->gtk_surface); } else { gtk_surface1_destroy(self->gtk_surface); } } #endif wl_surface_destroy(self->wl_surface); /* Let popup_surface_init() know we're already done */ self->wl_surface = NULL; free(self->shell); if (self->should_free_self) { free(self); } } wl-clipboard-2.2.1/src/types/popup-surface.h000066400000000000000000000030751447271603000210010ustar00rootroot00000000000000/* wl-clipboard * * Copyright © 2018-2023 Sergey Bugaev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef TYPES_POPUP_SURFACE_H #define TYPES_POPUP_SURFACE_H #include "includes/shell-protocols.h" #include struct registry; struct shell; struct shell_surface; struct seat; struct keyboard; struct popup_surface { /* These fields are initialized by the creator */ struct registry *registry; struct seat *seat; void (*on_focus)(struct popup_surface *self, uint32_t serial); void *data; /* These fields are initialized by the implementation */ struct shell *shell; struct shell_surface *shell_surface; struct wl_surface *wl_surface; struct keyboard *keyboard; int should_free_self; #ifdef HAVE_GTK_SHELL struct gtk_surface1 *gtk_surface; #endif }; void popup_surface_init(struct popup_surface *self); void popup_surface_destroy(struct popup_surface *self); #endif /* TYPES_POPUP_SURFACE_H */ wl-clipboard-2.2.1/src/types/registry.c000066400000000000000000000134371447271603000200560ustar00rootroot00000000000000/* wl-clipboard * * Copyright © 2018-2023 Sergey Bugaev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "types/registry.h" #include "types/seat.h" #include "types/shell.h" #include "types/device-manager.h" #include "includes/shell-protocols.h" #include "includes/selection-protocols.h" #include "util/misc.h" #include #include #define BIND(interface_name, known_version) \ if (strcmp(interface, #interface_name) == 0) { \ if (version >= (known_version)) { \ self->interface_name = wl_registry_bind( \ wl_registry, \ name, \ &interface_name ## _interface, \ known_version \ ); \ } \ } static void wl_registry_global_handler( void *data, struct wl_registry *wl_registry, uint32_t name, const char *interface, uint32_t version ) { struct registry *self = (struct registry *) data; BIND(wl_compositor, 2) BIND(wl_shm, 1) #ifdef HAVE_XDG_ACTIVATION BIND(xdg_activation_v1, 1) #endif /* Shells */ BIND(wl_shell, 1) #ifdef HAVE_XDG_SHELL BIND(xdg_wm_base, 1) #endif #ifdef HAVE_GTK_SHELL BIND(gtk_shell1, 4) #endif /* Device managers */ BIND(wl_data_device_manager, 1) #ifdef HAVE_GTK_PRIMARY_SELECTION BIND(gtk_primary_selection_device_manager, 1) #endif #ifdef HAVE_WP_PRIMARY_SELECTION BIND(zwp_primary_selection_device_manager_v1, 1) #endif #ifdef HAVE_WLR_DATA_CONTROL BIND(zwlr_data_control_manager_v1, version > 2 ? 2 : version) #endif if (strcmp(interface, "wl_seat") == 0 && version >= 2) { struct seat *seat = calloc(1, sizeof(struct seat)); seat->proxy = wl_registry_bind( wl_registry, name, &wl_seat_interface, 2 ); seat_init(seat); struct seat **ptr = wl_array_add(&self->seats, sizeof(struct seat *)); *ptr = seat; } } static void wl_registry_global_remove_handler( void *data, struct wl_registry *wl_registry, uint32_t name ) {} static const struct wl_registry_listener wl_registry_listener = { .global = wl_registry_global_handler, .global_remove = wl_registry_global_remove_handler }; void registry_init(struct registry *self) { self->proxy = wl_display_get_registry(self->wl_display); wl_registry_add_listener(self->proxy, &wl_registry_listener, self); } struct shell *registry_find_shell(struct registry *self) { struct shell *shell = calloc(1, sizeof(struct shell)); if (self->wl_shell != NULL) { shell->proxy = (struct wl_proxy *) self->wl_shell; shell_init_wl_shell(shell); return shell; } #ifdef HAVE_XDG_SHELL if (self->xdg_wm_base != NULL) { shell->proxy = (struct wl_proxy *) self->xdg_wm_base; shell_init_xdg_shell(shell); return shell; } #endif free(shell); return NULL; } #define TRY(type) \ if (self->type != NULL) { \ device_manager->proxy = (struct wl_proxy *) self->type; \ device_manager_init_ ## type(device_manager); \ return device_manager; \ } struct device_manager *registry_find_device_manager( struct registry *self, int primary ) { struct device_manager *device_manager = calloc(1, sizeof(struct device_manager)); device_manager->wl_display = self->wl_display; /* For regular selection, we just look at the two supported * protocols. We prefer wlr-data-control, as it doesn't require * us to use the popup surface hack. */ if (!primary) { #ifdef HAVE_WLR_DATA_CONTROL TRY(zwlr_data_control_manager_v1) #endif TRY(wl_data_device_manager) free(device_manager); return NULL; } /* For primary selection, it's a bit more complicated. We also * prefer wlr-data-control, but we don't know in advance whether * the compositor supports primary selection, as unlike with * other protocols here, the mere presence of wlr-data-control * does not imply primary selection support. However, we assume * that if a compositor supports primary selection at all, then * if it supports wlr-data-control v2 it also supports primary * selection over wlr-data-control; which is only reasonable. */ #ifdef HAVE_WLR_DATA_CONTROL if (self->zwlr_data_control_manager_v1 != NULL) { struct wl_proxy *proxy = (struct wl_proxy *) self->zwlr_data_control_manager_v1; if (wl_proxy_get_version(proxy) >= 2) { device_manager->proxy = proxy; device_manager_init_zwlr_data_control_manager_v1(device_manager); return device_manager; } } #endif #ifdef HAVE_WP_PRIMARY_SELECTION TRY(zwp_primary_selection_device_manager_v1) #endif #ifdef HAVE_GTK_PRIMARY_SELECTION TRY(gtk_primary_selection_device_manager) #endif free(device_manager); return NULL; } struct seat *registry_find_seat( struct registry *self, const char *name ) { /* Ensure we get all the seat info */ wl_display_roundtrip(self->wl_display); struct seat **ptr; wl_array_for_each(ptr, &self->seats) { struct seat *seat = *ptr; if (name == NULL || strcmp(seat->name, name) == 0) { return seat; } } return NULL; } wl-clipboard-2.2.1/src/types/registry.h000066400000000000000000000044001447271603000200510ustar00rootroot00000000000000/* wl-clipboard * * Copyright © 2018-2023 Sergey Bugaev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef TYPES_REGISTRY_H #define TYPES_REGISTRY_H #include "includes/shell-protocols.h" #include "includes/selection-protocols.h" #include struct shell; struct device_manager; struct seat; struct registry { /* This field is initialized by the creator */ struct wl_display *wl_display; /* These fields are initialized by the implementation */ struct wl_registry *proxy; struct wl_array seats; struct wl_compositor *wl_compositor; struct wl_shm *wl_shm; #ifdef HAVE_XDG_ACTIVATION struct xdg_activation_v1 *xdg_activation_v1; #endif /* Shells */ struct wl_shell *wl_shell; #ifdef HAVE_XDG_SHELL struct xdg_wm_base *xdg_wm_base; #endif #ifdef HAVE_GTK_SHELL struct gtk_shell1 *gtk_shell1; #endif /* Device managers */ struct wl_data_device_manager *wl_data_device_manager; #ifdef HAVE_GTK_PRIMARY_SELECTION struct gtk_primary_selection_device_manager *gtk_primary_selection_device_manager; #endif #ifdef HAVE_WP_PRIMARY_SELECTION struct zwp_primary_selection_device_manager_v1 *zwp_primary_selection_device_manager_v1; #endif #ifdef HAVE_WLR_DATA_CONTROL struct zwlr_data_control_manager_v1 *zwlr_data_control_manager_v1; #endif }; void registry_init(struct registry *self); struct shell *registry_find_shell(struct registry *self); struct device_manager *registry_find_device_manager( struct registry *self, int primary ); struct seat *registry_find_seat( struct registry *self, const char *name ); #endif /* TYPES_REGISTRY_H */ wl-clipboard-2.2.1/src/types/seat.c000066400000000000000000000034251447271603000171360ustar00rootroot00000000000000/* wl-clipboard * * Copyright © 2018-2023 Sergey Bugaev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "types/seat.h" #include "types/keyboard.h" #include #include #include static void wl_seat_capabilities_handler( void *data, struct wl_seat *seat, uint32_t capabilities ) { struct seat *self = (struct seat *) data; self->capabilities = capabilities; } static void wl_seat_name_handler( void *data, struct wl_seat *seat, const char *name ) { struct seat *self = (struct seat *) data; self->name = strdup(name); } static const struct wl_seat_listener wl_seat_listener = { .capabilities = wl_seat_capabilities_handler, .name = wl_seat_name_handler }; void seat_init(struct seat *self) { wl_seat_add_listener(self->proxy, &wl_seat_listener, self); } struct keyboard *seat_get_keyboard(struct seat *self) { if ((self->capabilities & WL_SEAT_CAPABILITY_KEYBOARD) == 0) { return NULL; } struct keyboard *keyboard = calloc(1, sizeof(struct keyboard)); keyboard->proxy = wl_seat_get_keyboard(self->proxy); keyboard_init(keyboard); return keyboard; } wl-clipboard-2.2.1/src/types/seat.h000066400000000000000000000021561447271603000171430ustar00rootroot00000000000000/* wl-clipboard * * Copyright © 2018-2023 Sergey Bugaev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef TYPES_SEAT_H #define TYPES_SEAT_H #include struct keyboard; struct seat { /* This field is initialized by the creator */ struct wl_seat *proxy; /* These fields are initialized by the implementation */ char *name; uint32_t capabilities; }; void seat_init(struct seat *self); struct keyboard *seat_get_keyboard(struct seat *self); #endif /* TYPES_SEAT_H */ wl-clipboard-2.2.1/src/types/shell-surface.c000066400000000000000000000073031447271603000207360ustar00rootroot00000000000000/* wl-clipboard * * Copyright © 2018-2023 Sergey Bugaev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "types/shell-surface.h" #include "includes/shell-protocols.h" #include #include void shell_surface_destroy(struct shell_surface *self) { self->do_destroy(self); free(self); } /* Core Wayland implementation */ static void wl_shell_surface_ping( void *data, struct wl_shell_surface *wl_shell_surface, uint32_t serial ) { wl_shell_surface_pong(wl_shell_surface, serial); } static void wl_shell_surface_configure( void *data, struct wl_shell_surface *wl_shell_surface, uint32_t edges, int32_t width, int32_t height ) {} static void wl_shell_surface_popup_done( void *data, struct wl_shell_surface *wl_shell_surface ) {} static const struct wl_shell_surface_listener wl_shell_surface_listener = { .ping = wl_shell_surface_ping, .configure = wl_shell_surface_configure, .popup_done = wl_shell_surface_popup_done }; static void destroy_wl_shell_surface(struct shell_surface *self) { struct wl_shell_surface *proxy = (struct wl_shell_surface *) self->proxy; wl_shell_surface_destroy(proxy); } void shell_surface_init_wl_shell_surface(struct shell_surface *self) { struct wl_shell_surface *proxy = (struct wl_shell_surface *) self->proxy; wl_shell_surface_add_listener(proxy, &wl_shell_surface_listener, self); wl_shell_surface_set_toplevel(proxy); wl_shell_surface_set_title(proxy, "wl-clipboard"); self->do_destroy = destroy_wl_shell_surface; } /* xdg-shell implementation */ #ifdef HAVE_XDG_SHELL static void xdg_toplevel_configure_handler( void *data, struct xdg_toplevel *xdg_toplevel, int32_t width, int32_t height, struct wl_array *states ) {} static void xdg_toplevel_close_handler( void *data, struct xdg_toplevel *xdg_toplevel ) {} static const struct xdg_toplevel_listener xdg_toplevel_listener = { .configure = xdg_toplevel_configure_handler, .close = xdg_toplevel_close_handler }; static void xdg_surface_configure_handler( void *data, struct xdg_surface *xdg_surface, uint32_t serial ) { xdg_surface_ack_configure(xdg_surface, serial); } static const struct xdg_surface_listener xdg_surface_listener = { .configure = xdg_surface_configure_handler }; static void destroy_xdg_surface(struct shell_surface *self) { struct xdg_toplevel *toplevel = (struct xdg_toplevel *) self->proxy2; struct xdg_surface *proxy = (struct xdg_surface *) self->proxy; xdg_toplevel_destroy(toplevel); xdg_surface_destroy(proxy); } void shell_surface_init_xdg_surface(struct shell_surface *self) { struct xdg_surface *proxy = (struct xdg_surface *) self->proxy; xdg_surface_add_listener(proxy, &xdg_surface_listener, self); struct xdg_toplevel *toplevel = xdg_surface_get_toplevel(proxy); self->proxy2 = (struct wl_proxy *) toplevel; xdg_toplevel_add_listener(toplevel, &xdg_toplevel_listener, self); xdg_toplevel_set_title(toplevel, "wl-clipboard"); self->do_destroy = destroy_xdg_surface; } #endif /* HAVE_XDG_SHELL */ wl-clipboard-2.2.1/src/types/shell-surface.h000066400000000000000000000025211447271603000207400ustar00rootroot00000000000000/* wl-clipboard * * Copyright © 2018-2023 Sergey Bugaev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef TYPES_SHELL_SURFACE_H #define TYPES_SHELL_SURFACE_H #include "includes/shell-protocols.h" struct shell_surface { /* This field is initialized by the creator */ struct wl_proxy *proxy; /* These fields are initialized by the implementation */ struct wl_proxy *proxy2; void (*do_destroy)(struct shell_surface *self); }; void shell_surface_destroy(struct shell_surface *self); /* Initializers */ void shell_surface_init_wl_shell_surface(struct shell_surface *self); #ifdef HAVE_XDG_SHELL void shell_surface_init_xdg_surface(struct shell_surface *self); #endif #endif /* TYPES_SHELL_SURFACE_H */ wl-clipboard-2.2.1/src/types/shell.c000066400000000000000000000054031447271603000173070ustar00rootroot00000000000000/* wl-clipboard * * Copyright © 2018-2023 Sergey Bugaev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "types/shell-surface.h" #include "types/shell.h" #include "includes/shell-protocols.h" #include struct shell_surface *shell_create_shell_surface( struct shell *self, struct wl_surface *surface ) { return self->do_create_shell_surface(self, surface); } /* Core Wayland implementation */ static struct shell_surface *wl_shell_create_shell_surface( struct shell *self, struct wl_surface *surface ) { struct wl_shell *shell = (struct wl_shell *) self->proxy; struct wl_shell_surface *wl_shell_surface = wl_shell_get_shell_surface(shell, surface); struct shell_surface *shell_surface = calloc(1, sizeof(struct shell_surface)); shell_surface->proxy = (struct wl_proxy *) wl_shell_surface; shell_surface_init_wl_shell_surface(shell_surface); return shell_surface; } void shell_init_wl_shell(struct shell *self) { self->do_create_shell_surface = wl_shell_create_shell_surface; } /* xdg-shell implementation */ #ifdef HAVE_XDG_SHELL static struct shell_surface *xdg_shell_create_shell_surfacce( struct shell *self, struct wl_surface *surface ) { struct xdg_wm_base *wm_base = (struct xdg_wm_base *) self->proxy; struct shell_surface *shell_surface = calloc(1, sizeof(struct shell_surface)); struct xdg_surface *xdg_surface = xdg_wm_base_get_xdg_surface(wm_base, surface); shell_surface->proxy = (struct wl_proxy *) xdg_surface; shell_surface_init_xdg_surface(shell_surface); return shell_surface; } static void xdg_wm_base_ping_handler( void *data, struct xdg_wm_base *wm_base, uint32_t serial ) { xdg_wm_base_pong(wm_base, serial); } static const struct xdg_wm_base_listener xdg_wm_base_listener = { .ping = xdg_wm_base_ping_handler }; void shell_init_xdg_shell(struct shell *self) { struct xdg_wm_base *wm_base = (struct xdg_wm_base *) self->proxy; xdg_wm_base_add_listener(wm_base, &xdg_wm_base_listener, self); self->do_create_shell_surface = xdg_shell_create_shell_surfacce; } #endif /* HAVE_XDG_SHELL */ wl-clipboard-2.2.1/src/types/shell.h000066400000000000000000000026271447271603000173210ustar00rootroot00000000000000/* wl-clipboard * * Copyright © 2018-2023 Sergey Bugaev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef TYPES_SHELL_H #define TYPES_SHELL_H #include "includes/shell-protocols.h" #include struct shell_surface; struct shell { /* This field is initialized by the creator */ struct wl_proxy *proxy; /* This field is initialized by the implementation */ struct shell_surface *(*do_create_shell_surface)( struct shell *self, struct wl_surface *surface ); }; struct shell_surface *shell_create_shell_surface( struct shell *self, struct wl_surface *surface ); /* Initializers */ void shell_init_wl_shell(struct shell *self); #ifdef HAVE_XDG_SHELL void shell_init_xdg_shell(struct shell *self); #endif #endif /* TYPES_SHELL_H */ wl-clipboard-2.2.1/src/types/source.c000066400000000000000000000065031447271603000175020ustar00rootroot00000000000000/* wl-clipboard * * Copyright © 2018-2023 Sergey Bugaev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "config.h" #include "includes/selection-protocols.h" #include "types/source.h" #include "util/string.h" #include void source_offer(struct source *self, char *mime_type) { self->do_offer(self->proxy, mime_type); } /* Macros to reduce implementation boilerplate */ #define SEND_HANDLER(type) \ static void type ## _send_handler( \ void *data, \ struct type *proxy, \ const char *mime_type, \ int fd \ ) { \ struct source *self = data; \ if (self->send_callback != NULL) { \ self->send_callback(self, mime_type, fd); \ } else { \ close(fd); \ } \ } #define CANCELLED_HANDLER(type) \ static void type ## _cancelled_handler( \ void *data, \ struct type *proxy \ ) { \ struct source *self = data; \ if (self->cancelled_callback != NULL) { \ self->cancelled_callback(self); \ } \ } #define LISTENER(type) \ static const struct type ## _listener type ## _listener = { \ .send = type ## _send_handler, \ .cancelled = type ## _cancelled_handler \ }; #define INIT(type) \ void source_init_ ## type(struct source *self) { \ self->do_offer = \ (void (*)(struct wl_proxy *, const char *)) type ## _offer; \ struct type *proxy = (struct type *) self->proxy; \ type ## _add_listener(proxy, &type ## _listener, self); \ } /* Core Wayland implementation */ static void wl_data_source_target_handler ( void *data, struct wl_data_source *wl_data_source, const char *mime_type ) {} SEND_HANDLER(wl_data_source) CANCELLED_HANDLER(wl_data_source) static const struct wl_data_source_listener wl_data_source_listener = { .target = wl_data_source_target_handler, .send = wl_data_source_send_handler, .cancelled = wl_data_source_cancelled_handler }; INIT(wl_data_source) /* gtk-primary-selection implementation */ #ifdef HAVE_GTK_PRIMARY_SELECTION SEND_HANDLER(gtk_primary_selection_source) CANCELLED_HANDLER(gtk_primary_selection_source) LISTENER(gtk_primary_selection_source) INIT(gtk_primary_selection_source) #endif /* HAVE_GTK_PRIMARY_SELECTION */ /* wp-primary-selection implementation */ #ifdef HAVE_WP_PRIMARY_SELECTION SEND_HANDLER(zwp_primary_selection_source_v1) CANCELLED_HANDLER(zwp_primary_selection_source_v1) LISTENER(zwp_primary_selection_source_v1) INIT(zwp_primary_selection_source_v1) #endif /* HAVE_WP_PRIMARY_SELECTION */ /* wlr-data-control implementation */ #ifdef HAVE_WLR_DATA_CONTROL SEND_HANDLER(zwlr_data_control_source_v1) CANCELLED_HANDLER(zwlr_data_control_source_v1) LISTENER(zwlr_data_control_source_v1) INIT(zwlr_data_control_source_v1) #endif /* HAVE_WLR_DATA_CONTROL */ wl-clipboard-2.2.1/src/types/source.h000066400000000000000000000032321447271603000175030ustar00rootroot00000000000000/* wl-clipboard * * Copyright © 2018-2023 Sergey Bugaev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef TYPES_SOURCE_H #define TYPES_SOURCE_H #include "includes/selection-protocols.h" struct source { /* These fields are initialized by the creator */ void (*send_callback)(struct source *self, const char *mime_type, int fd); void (*cancelled_callback)(struct source *self); void *data; struct wl_proxy *proxy; /* This field is initialized by the implementation */ void (*do_offer)(struct wl_proxy *proxy, const char *mime_type); }; void source_offer(struct source *self, char *mime_type); /* Initializers */ void source_init_wl_data_source(struct source *self); #ifdef HAVE_GTK_PRIMARY_SELECTION void source_init_gtk_primary_selection_source(struct source *self); #endif #ifdef HAVE_WP_PRIMARY_SELECTION void source_init_zwp_primary_selection_source_v1(struct source *self); #endif #ifdef HAVE_WLR_DATA_CONTROL void source_init_zwlr_data_control_source_v1(struct source *self); #endif #endif /* TYPES_SOURCE_H */ wl-clipboard-2.2.1/src/util/000077500000000000000000000000001447271603000156435ustar00rootroot00000000000000wl-clipboard-2.2.1/src/util/files.c000066400000000000000000000171421447271603000171160ustar00rootroot00000000000000/* wl-clipboard * * Copyright © 2018-2023 Sergey Bugaev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "util/files.h" #include "util/string.h" #include "util/misc.h" #include "config.h" #include #include #include #include #include #include #include // open #include // open #include // exit #include // basename #include #include #include #ifdef HAVE_MEMFD # include // syscall, SYS_memfd_create #endif #ifdef HAVE_SHM_ANON # include // shm_open, SHM_ANON #endif #include // wl_display_get_fd void complain_about_closed_stdio(struct wl_display *wl_display) { const char *message = "wl-clipboard has been launched with a closed" " standard file descriptor. This is a bug in the software that" " has launched wl-clipboard. Aborting."; /* See if we can write to stderr */ if (wl_display_get_fd(wl_display) < STDERR_FILENO) { int rc = fcntl(STDERR_FILENO, F_GETFL); if (rc > 0) { rc &= O_ACCMODE; if (rc == O_WRONLY || rc == O_RDWR) { /* Yes, we can! */ fprintf(stderr, "%s\n", message); fflush(stderr); abort(); } } } /* Maybe there is a tty we could write to? */ FILE *tty = fopen("/dev/tty", "w"); if (tty != NULL) { fprintf(tty, "%s\n", message); fflush(stderr); abort(); } /* As a last resort, try syslog */ openlog("wl-clipboard", LOG_CONS | LOG_PID, LOG_USER); syslog(LOG_ERR, "%s", message); closelog(); abort(); } int create_anonymous_file() { int res; #ifdef HAVE_MEMFD res = syscall(SYS_memfd_create, "buffer", 0); if (res >= 0) { return res; } #endif #ifdef HAVE_SHM_ANON res = shm_open(SHM_ANON, O_RDWR | O_CREAT, 0600); if (res >= 0) { return res; } #endif (void) res; return fileno(tmpfile()); } void trim_trailing_newline(const char *file_path) { int fd = open(file_path, O_RDWR); if (fd < 0) { perror("open file for trimming"); return; } int seek_res = lseek(fd, -1, SEEK_END); if (seek_res < 0 && errno == EINVAL) { /* It was an empty file */ goto out; } else if (seek_res < 0) { perror("lseek"); goto out; } /* If the seek was successful, seek_res is the * new file size after trimming the newline. */ char last_char; int read_res = read(fd, &last_char, 1); if (read_res != 1) { perror("read"); goto out; } if (last_char != '\n') { goto out; } int rc = ftruncate(fd, seek_res); if (rc < 0) { perror("ftruncate"); } out: close(fd); } char *path_for_fd(int fd) { char fdpath[64]; snprintf(fdpath, sizeof(fdpath), "/dev/fd/%d", fd); return realpath(fdpath, NULL); } char *infer_mime_type_from_contents(const char *file_path) { /* Spawn xdg-mime query filetype */ int pipefd[2]; int rc = pipe(pipefd); if (rc < 0) { perror("pipe"); return NULL; } pid_t pid = fork(); if (pid < 0) { perror("fork"); close(pipefd[0]); close(pipefd[1]); return NULL; } if (pid == 0) { dup2(pipefd[1], STDOUT_FILENO); close(pipefd[0]); close(pipefd[1]); int devnull = open("/dev/null", O_RDONLY); if (devnull >= 0) { dup2(devnull, STDIN_FILENO); close(devnull); } else { /* If we cannot open /dev/null, just close stdin */ close(STDIN_FILENO); } signal(SIGHUP, SIG_DFL); signal(SIGPIPE, SIG_DFL); execlp("xdg-mime", "xdg-mime", "query", "filetype", file_path, NULL); exit(1); } close(pipefd[1]); int wstatus; waitpid(pid, &wstatus, 0); /* See if that worked */ if (!WIFEXITED(wstatus) || WEXITSTATUS(wstatus) != 0) { close(pipefd[0]); return NULL; } /* Read the result */ char *res = malloc(256); size_t len = read(pipefd[0], res, 256); /* Trim the newline */ len--; res[len] = 0; close(pipefd[0]); if (str_has_prefix(res, "inode/")) { free(res); return NULL; } return res; } char *infer_mime_type_from_name(const char *file_path) { const char *actual_ext = get_file_extension(file_path); if (actual_ext == NULL) { return NULL; } FILE *f = fopen("/etc/mime.types", "r"); if (f == NULL) { f = fopen("/usr/local/etc/mime.types", "r"); } if (f == NULL) { return NULL; } for (char line[200]; fgets(line, sizeof(line), f) != NULL;) { /* Skip comments and black lines */ if (line[0] == '#' || line[0] == '\n') { continue; } /* Each line consists of a mime type and a list of extensions */ char mime_type[200]; int consumed; if (sscanf(line, "%199s%n", mime_type, &consumed) != 1) { /* A malformed line, perhaps? */ continue; } char *lineptr = line + consumed; for (char ext[200]; sscanf(lineptr, "%199s%n", ext, &consumed) == 1;) { if (strcmp(ext, actual_ext) == 0) { fclose(f); return strdup(mime_type); } lineptr += consumed; } } fclose(f); return NULL; } /* Returns the name of a new file */ char *dump_stdin_into_a_temp_file() { /* Create a temp directory to host out file */ char dirpath[] = "/tmp/wl-copy-buffer-XXXXXX"; if (mkdtemp(dirpath) != dirpath) { perror("mkdtemp"); exit(1); } /* Pick a name for the file we'll be * creating inside that directory. We * try to preserve the origial name for * the mime type inference to work. */ char *original_path = path_for_fd(STDIN_FILENO); char *name = original_path != NULL ? basename(original_path) : "stdin"; /* Construct the path */ char *res_path = malloc(strlen(dirpath) + 1 + strlen(name) + 1); memcpy(res_path, dirpath, sizeof(dirpath)); res_path[sizeof(dirpath) - 1] = '/'; strcpy(res_path + sizeof(dirpath), name); /* Spawn cat to perform the copy */ pid_t pid = fork(); if (pid < 0) { perror("fork"); exit(1); } if (pid == 0) { int fd = creat(res_path, S_IRUSR | S_IWUSR); if (fd < 0) { perror("creat"); exit(1); } dup2(fd, STDOUT_FILENO); close(fd); signal(SIGHUP, SIG_DFL); signal(SIGPIPE, SIG_DFL); execlp("cat", "cat", NULL); perror("exec cat"); exit(1); } int wstatus; waitpid(pid, &wstatus, 0); if (original_path != NULL) { free(original_path); } if (!WIFEXITED(wstatus) || WEXITSTATUS(wstatus) != 0) { bail("Failed to copy the file"); } return res_path; } wl-clipboard-2.2.1/src/util/files.h000066400000000000000000000024351447271603000171220ustar00rootroot00000000000000/* wl-clipboard * * Copyright © 2018-2023 Sergey Bugaev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef UTIL_FILES_H #define UTIL_FILES_H struct wl_display; void complain_about_closed_stdio(struct wl_display *wl_display); int create_anonymous_file(void); void trim_trailing_newline(const char *file_path); /* These functions return owned strings, so make sure * to free() their return values when done with them. */ char *path_for_fd(int fd); char *infer_mime_type_from_contents(const char *file_path); char *infer_mime_type_from_name(const char *file_path); /* Returns the name of a new file */ char *dump_stdin_into_a_temp_file(void); #endif /* UTIL_FILES_H */ wl-clipboard-2.2.1/src/util/misc.c000066400000000000000000000077431447271603000167550ustar00rootroot00000000000000/* wl-clipboard * * Copyright © 2018-2023 Sergey Bugaev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "config.h" #include "util/misc.h" #include #include #include #include void print_version_info() { printf( "wl-clipboard " PROJECT_VERSION "\n" "Copyright (C) 2018-2023 Sergey Bugaev\n" "License GPLv3+: GNU GPL version 3 or later" " .\n" "This is free software: you are free to change and redistribute it.\n" "There is NO WARRANTY, to the extent permitted by law.\n" ); } void complain_about_selection_support(int primary) { if (!primary) { /* We always expect to find at least wl_data_device_manager */ complain_about_missing_global("wl_data_device_manager"); } #if !defined(HAVE_WP_PRIMARY_SELECTION) && !defined(HAVE_GTK_PRIMARY_SELECTION) bail("wl-clipboard was built without primary selection support"); #endif bail("The compositor does not seem to support primary selection"); } void complain_about_watch_mode_support() { #ifdef HAVE_WLR_DATA_CONTROL bail( "Watch mode requires a compositor that supports" " the wlroots data-control protocol" ); #else bail( "wl-clipboard was built without support for" " the wlroots data-control protocol" ); #endif } void complain_about_wayland_connection() { int saved_errno = errno; fprintf(stderr, "Failed to connect to a Wayland server"); if (saved_errno != 0) { fprintf(stderr, ": %s", strerror(saved_errno)); } fputc('\n', stderr); const char *display = getenv("WAYLAND_DISPLAY"); const char *runtime_dir = getenv("XDG_RUNTIME_DIR"); if (display != NULL) { fprintf(stderr, "Note: WAYLAND_DISPLAY is set to %s\n", display); } else { fprintf( stderr, "Note: WAYLAND_DISPLAY is unset" " (falling back to wayland-0)\n" ); display = "wayland-0"; } if (runtime_dir != NULL) { fprintf(stderr, "Note: XDG_RUNTIME_DIR is set to %s\n", runtime_dir); } else { fprintf(stderr, "Note: XDG_RUNTIME_DIR is unset\n"); } if (display[0] != '/' && runtime_dir != NULL) { fprintf( stderr, "Please check whether %s/%s socket exists and is accessible.\n", runtime_dir, display ); } exit(1); } void complain_about_missing_seat(const char *seat_name) { if (seat_name != NULL) { fprintf(stderr, "No such seat: %s\n", seat_name); } else { complain_about_missing_global("seat"); } exit(1); } void complain_about_missing_global(const char *global) { fprintf( stderr, "The compositor does not seem to implement %s," " which is required for wl-clipboard to work\n", global ); exit(1); } void complain_about_missing_shell() { #ifndef HAVE_XDG_SHELL fprintf( stderr, "wl-clipboard was built without xdg-shell support, and the compositor" " does not seem to support any other Wayland shell.\nPlease rebuild" " wl-clipboard with xdg-shell support.\n" ); exit(1); #endif fprintf( stderr, "The compositor does not seem to implement a Wayland shell," " which is required for wl-clipboard to work\n" ); exit(1); } wl-clipboard-2.2.1/src/util/misc.h000066400000000000000000000023421447271603000167500ustar00rootroot00000000000000/* wl-clipboard * * Copyright © 2018-2023 Sergey Bugaev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef UTIL_MISC_H #define UTIL_MISC_H #include #include #define bail(message) do { fprintf(stderr, message "\n"); exit(1); } while (0) void print_version_info(void); void complain_about_selection_support(int primary); void complain_about_watch_mode_support(void); void complain_about_wayland_connection(void); void complain_about_missing_seat(const char *seat_name); void complain_about_missing_global(const char *global); void complain_about_missing_shell(void); #endif /* UTIL_MISC_H */ wl-clipboard-2.2.1/src/util/string.c000066400000000000000000000052411447271603000173170ustar00rootroot00000000000000/* wl-clipboard * * Copyright © 2018-2023 Sergey Bugaev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "util/string.h" #include #include int mime_type_is_text(const char *mime_type) { /* A heuristic to detect plain text mime types */ /* Types that explicitly declare they're textual */ int basic = str_has_prefix(mime_type, "text/") || strcmp(mime_type, "TEXT") == 0 || strcmp(mime_type, "STRING") == 0 || strcmp(mime_type, "UTF8_STRING") == 0; /* Common script and markup types */ int common = strstr(mime_type, "json") != NULL || str_has_suffix(mime_type, "script") || str_has_suffix(mime_type, "xml") || str_has_suffix(mime_type, "yaml") || str_has_suffix(mime_type, "csv") || str_has_suffix(mime_type, "ini"); /* Special-case PGP and SSH keys. * A public SSH key is typically stored * in a file that has a name similar to * id_rsa.pub, which xdg-mime misidentifies * as being a Publisher file. Note that it * handles private keys, which do not have * a .pub extension, correctly. */ int special = strstr(mime_type, "application/vnd.ms-publisher") != NULL || str_has_suffix(mime_type, "pgp-keys"); return basic || common || special; } int str_has_prefix(const char *string, const char *prefix) { size_t prefix_length = strlen(prefix); return strncmp(string, prefix, prefix_length) == 0; } int str_has_suffix(const char *string, const char *suffix) { size_t string_length = strlen(string); size_t suffix_length = strlen(suffix); if (string_length < suffix_length) { return 0; } size_t offset = string_length - suffix_length; return strcmp(string + offset, suffix) == 0; } const char *get_file_extension(const char *file_path) { const char *name = strrchr(file_path, '/'); if (name == NULL) { name = file_path; } const char *ext = strrchr(name, '.'); if (ext == NULL) { return NULL; } return ext + 1; } wl-clipboard-2.2.1/src/util/string.h000066400000000000000000000021701447271603000173220ustar00rootroot00000000000000/* wl-clipboard * * Copyright © 2018-2023 Sergey Bugaev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef UTIL_STRING_H #define UTIL_STRING_H #define text_plain "text/plain" #define text_plain_utf8 "text/plain;charset=utf-8" typedef char * const *argv_t; int mime_type_is_text(const char *mime_type); int str_has_prefix(const char *string, const char *prefix); int str_has_suffix(const char *string, const char *suffix); const char *get_file_extension(const char *file_path); #endif /* UTIL_STRING_H */ wl-clipboard-2.2.1/src/wl-copy.c000066400000000000000000000240661447271603000164340ustar00rootroot00000000000000/* wl-clipboard * * Copyright © 2018-2023 Sergey Bugaev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "types/copy-action.h" #include "types/source.h" #include "types/device.h" #include "types/device-manager.h" #include "types/registry.h" #include "types/popup-surface.h" #include "types/offer.h" #include "util/files.h" #include "util/string.h" #include "util/misc.h" #include #include #include #include // open #include #include #include static struct { int stay_in_foreground; int clear; char *mime_type; int trim_newline; int paste_once; int primary; const char *seat_name; } options; static void did_set_selection_callback(struct copy_action *copy_action) { if (options.clear) { exit(0); } if (!options.stay_in_foreground) { /* Move to background. * We fork our process and leave the * child running in the background, * while exiting in the parent. We also * replace stdin/stdout with /dev/null * so the stdout file descriptor isn't * kept alive, and chdir to the root, to * prevent blocking file systems from * being unmounted. */ int devnull = open("/dev/null", O_RDWR); if (devnull >= 0) { dup2(devnull, STDOUT_FILENO); dup2(devnull, STDIN_FILENO); close(devnull); } else { /* If we cannot open /dev/null, * just close stdin/stdout. */ close(STDIN_FILENO); close(STDOUT_FILENO); } if (chdir("/") < 0) { perror("chdir /"); } signal(SIGHUP, SIG_IGN); pid_t pid = fork(); if (pid < 0) { perror("fork"); /* Proceed without forking */ } if (pid > 0) { exit(0); } } } static void cancelled_callback(struct copy_action *copy_action) { exit(0); } static void pasted_callback(struct copy_action *copy_action) { if (options.paste_once) { exit(0); } } static void selection_callback(struct offer *offer, int primary) { /* We're not interested */ if (offer != NULL) { offer_destroy(offer); } } static void print_usage(FILE *f, const char *argv0) { fprintf( f, "Usage:\n" "\t%s [options] text to copy\n" "\t%s [options] < file-to-copy\n\n" "Copy content to the Wayland clipboard.\n\n" "Options:\n" "\t-o, --paste-once\tOnly serve one paste request and then exit.\n" "\t-f, --foreground\tStay in the foreground instead of forking.\n" "\t-c, --clear\t\tInstead of copying, clear the clipboard.\n" "\t-p, --primary\t\tUse the \"primary\" clipboard.\n" "\t-n, --trim-newline\tDo not copy the trailing newline character.\n" "\t-t, --type mime/type\t" "Override the inferred MIME type for the content.\n" "\t-s, --seat seat-name\t" "Pick the seat to work with.\n" "\t-v, --version\t\tDisplay version info.\n" "\t-h, --help\t\tDisplay this message.\n" "Mandatory arguments to long options are mandatory" " for short options too.\n\n" "See wl-clipboard(1) for more details.\n", argv0, argv0 ); } static void parse_options(int argc, argv_t argv) { if (argc < 1) { bail("Empty argv"); } static struct option long_options[] = { {"version", no_argument, 0, 'v'}, {"help", no_argument, 0, 'h'}, {"primary", no_argument, 0, 'p'}, {"trim-newline", no_argument, 0, 'n'}, {"paste-once", no_argument, 0, 'o'}, {"foreground", no_argument, 0, 'f'}, {"clear", no_argument, 0, 'c'}, {"type", required_argument, 0, 't'}, {"seat", required_argument, 0, 's'}, {0, 0, 0, 0} }; while (1) { int option_index; const char *opts = "vhpnofct:s:"; int c = getopt_long(argc, argv, opts, long_options, &option_index); if (c == -1) { break; } if (c == 0) { c = long_options[option_index].val; } switch (c) { case 'v': print_version_info(); exit(0); case 'h': print_usage(stdout, argv[0]); exit(0); case 'p': options.primary = 1; break; case 'n': options.trim_newline = 1; break; case 'o': options.paste_once = 1; break; case 'f': options.stay_in_foreground = 1; break; case 'c': options.clear = 1; break; case 't': options.mime_type = strdup(optarg); break; case 's': options.seat_name = strdup(optarg); break; default: /* getopt has already printed an error message */ print_usage(stderr, argv[0]); exit(1); } } } int main(int argc, argv_t argv) { parse_options(argc, argv); /* Ignore SIGPIPE. * We don't really output anything * to our stdout, yet we don't want * to get killed when writing clipboard * contents to a closed pipe. */ signal(SIGPIPE, SIG_IGN); struct wl_display *wl_display = wl_display_connect(NULL); if (wl_display == NULL) { complain_about_wayland_connection(); } if (wl_display_get_fd(wl_display) <= STDERR_FILENO) { complain_about_closed_stdio(wl_display); } struct registry *registry = calloc(1, sizeof(struct registry)); registry->wl_display = wl_display; registry_init(registry); /* Wait for the initial set of globals to appear */ wl_display_roundtrip(wl_display); struct seat *seat = registry_find_seat(registry, options.seat_name); if (seat == NULL) { complain_about_missing_seat(options.seat_name); } /* Create the device */ struct device_manager *device_manager = registry_find_device_manager(registry, options.primary); if (device_manager == NULL) { complain_about_selection_support(options.primary); } struct device *device = device_manager_get_device(device_manager, seat); device->selection_callback = selection_callback; if (!device_supports_selection(device, options.primary)) { complain_about_selection_support(options.primary); } /* Create and initialize the copy action */ struct copy_action *copy_action = calloc(1, sizeof(struct copy_action)); copy_action->fd_to_copy_from = -1; copy_action->device = device; copy_action->primary = options.primary; if (!options.clear) { if (optind < argc) { /* Copy our command-line arguments */ copy_action->argv_to_copy = &argv[optind]; } else { /* Copy data from our stdin. * It's important that we only do this * after going through the initial stages * that are likely to result in errors, * so that we don't forget to clean up * the temp file. */ char *temp_file = dump_stdin_into_a_temp_file(); if (options.trim_newline) { trim_trailing_newline(temp_file); } if (options.mime_type == NULL) { options.mime_type = infer_mime_type_from_contents(temp_file); } copy_action->fd_to_copy_from = open( temp_file, O_RDONLY | O_CLOEXEC ); if (copy_action->fd_to_copy_from < 0) { perror("Failed to open temp file"); return 1; } /* Now, remove the temp file and its * containing directory. We still keep * access to the file through our open * file descriptor. */ int rc = unlink(temp_file); if (rc < 0) { perror("Failed to unlink temp file"); } rc = rmdir(dirname(temp_file)); if (rc < 0) { perror("Failed to remove temp file directory"); } free(temp_file); } /* Create the source */ copy_action->source = device_manager_create_source(device_manager); if (options.mime_type != NULL) { source_offer(copy_action->source, options.mime_type); } if (options.mime_type == NULL || mime_type_is_text(options.mime_type)) { /* Offer a few generic plain text formats */ source_offer(copy_action->source, text_plain); source_offer(copy_action->source, text_plain_utf8); source_offer(copy_action->source, "TEXT"); source_offer(copy_action->source, "STRING"); source_offer(copy_action->source, "UTF8_STRING"); } free(options.mime_type); options.mime_type = NULL; } if (device->needs_popup_surface) { copy_action->popup_surface = calloc(1, sizeof(struct popup_surface)); copy_action->popup_surface->registry = registry; copy_action->popup_surface->seat = seat; } copy_action->did_set_selection_callback = did_set_selection_callback; copy_action->pasted_callback = pasted_callback; copy_action->cancelled_callback = cancelled_callback; copy_action_init(copy_action); while (wl_display_dispatch(wl_display) >= 0); perror("wl_display_dispatch"); return 1; } wl-clipboard-2.2.1/src/wl-paste.c000066400000000000000000000362271447271603000166000ustar00rootroot00000000000000/* wl-clipboard * * Copyright © 2018-2023 Sergey Bugaev * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "types/offer.h" #include "types/device.h" #include "types/device-manager.h" #include "types/registry.h" #include "types/popup-surface.h" #include "util/files.h" #include "util/string.h" #include "util/misc.h" #include #include #include #include #include #include #include #include #include #include static struct { char *explicit_type; char *inferred_type; int no_newline; int list_types; int primary; int watch; argv_t watch_command; const char *seat_name; } options; struct types { int explicit_available; int inferred_available; int plain_text_utf8_available; int plain_text_available; const char *having_explicit_as_prefix; const char *any_text; const char *any; }; static struct wl_display *wl_display = NULL; static struct popup_surface *popup_surface = NULL; static int offer_received = 0; static struct types classify_offer_types(struct offer *offer) { struct types types = { 0 }; offer_for_each_mime_type(offer, mime_type) { if ( options.explicit_type != NULL && strcmp(mime_type, options.explicit_type) == 0 ) { types.explicit_available = 1; } if ( options.inferred_type != NULL && strcmp(mime_type, options.inferred_type) == 0 ) { types.inferred_available = 1; } if (strcmp(mime_type, text_plain_utf8) == 0) { types.plain_text_utf8_available = 1; } if (strcmp(mime_type, text_plain) == 0) { types.plain_text_available = 1; } if ( types.any_text == NULL && mime_type_is_text(mime_type) ) { types.any_text = mime_type; } if (types.any == NULL) { types.any = mime_type; } if ( options.explicit_type != NULL && types.having_explicit_as_prefix == NULL && str_has_prefix(mime_type, options.explicit_type) ) { types.having_explicit_as_prefix = mime_type; } } return types; } #define try_explicit \ if (types.explicit_available) \ return options.explicit_type #define try_inferred \ if (types.inferred_available) \ return options.inferred_type #define try_text_plain_utf8 \ if (types.plain_text_utf8_available) \ return text_plain_utf8 #define try_text_plain \ if (types.plain_text_available) \ return text_plain #define try_prefixed \ if (types.having_explicit_as_prefix != NULL) \ return types.having_explicit_as_prefix #define try_any_text \ if (types.any_text != NULL) \ return types.any_text #define try_any \ if (types.any != NULL) \ return types.any static const char *mime_type_to_request(struct types types) { if (options.explicit_type != NULL) { if (strcmp(options.explicit_type, "text") == 0) { try_text_plain_utf8; try_text_plain; try_any_text; } else if (strchr(options.explicit_type, '/') != NULL) { try_explicit; } else if (isupper(options.explicit_type[0])) { try_explicit; } else { try_explicit; try_prefixed; } } else { /* No mime type requested explicitly, * so try to guess. */ if (options.inferred_type == NULL) { try_text_plain_utf8; try_text_plain; try_any_text; try_any; } else if (mime_type_is_text(options.inferred_type)) { try_inferred; try_text_plain_utf8; try_text_plain; try_any_text; } else { try_inferred; } } return NULL; } #undef try_explicit #undef try_inferred #undef try_text_plain_utf8 #undef try_text_plain #undef try_prefixed #undef try_any_text #undef try_any static int run_paste_command(int stdin_fd, const char *clipboard_state) { /* Spawn a cat to perform the copy. * If watch mode is active, we spawn * a custom command instead. */ pid_t pid = fork(); if (pid < 0) { perror("fork"); close(stdin_fd); return 0; } if (pid == 0) { dup2(stdin_fd, STDIN_FILENO); close(stdin_fd); if (options.watch) { if (clipboard_state != NULL) { setenv("CLIPBOARD_STATE", clipboard_state, 1); } execvp(options.watch_command[0], options.watch_command); fprintf( stderr, "Failed to spawn %s: %s", options.watch_command[0], strerror(errno) ); } else { execlp("cat", "cat", NULL); perror("exec cat"); } exit(1); } close(stdin_fd); waitpid(pid, NULL, 0); return 1; } static void complain_no_suitable_type() { fprintf(stderr, "Clipboard content is not available as "); if (options.explicit_type != NULL) { fprintf(stderr, "requested type \"%s\"\n", options.explicit_type); } else { assert(options.inferred_type); fprintf( stderr, "inferred output type \"%s\"\n", options.inferred_type ); } fprintf(stderr, "Use \"wl-paste --list-types\" to view available types."); if (options.explicit_type == NULL) { fprintf(stderr, " Use \"--type\" to explicitly specify a type."); } fputc('\n', stderr); exit(1); } static void selection_callback(struct offer *offer, int primary) { /* Ignore all but the first non-NULL offer. * This could happen due to reentrancy, though * we try to prevent it in other ways. */ if (offer_received && !options.watch) { return; } /* Ignore events we're not interested in */ if (primary != options.primary) { if (offer != NULL) { offer_destroy(offer); }; return; } if (offer == NULL) { if (!options.watch) { bail("Nothing is copied"); } int devnull = open("/dev/null", O_RDONLY | O_CLOEXEC); if (devnull < 0) { perror("open /dev/null"); return; } run_paste_command(devnull, "nil"); return; } offer_received = 1; if (options.list_types) { offer_for_each_mime_type(offer, mime_type) { printf("%s\n", mime_type); } exit(0); } struct types types = classify_offer_types(offer); const char *mime_type = mime_type_to_request(types); if (mime_type == NULL) { if (options.watch) { offer_destroy(offer); return; } complain_no_suitable_type(); } /* Never append a newline character to binary content */ if (!mime_type_is_text(mime_type)) { options.no_newline = 1; } /* Create a pipe which we'll * use to receive the data. */ int pipefd[2]; int rc = pipe(pipefd); if (rc < 0) { perror("pipe"); offer_destroy(offer); if (options.watch) { return; } exit(1); } offer_receive(offer, mime_type, pipefd[1]); if (popup_surface != NULL) { popup_surface_destroy(popup_surface); popup_surface = NULL; } /* Make sure the receive request reaches * the compositor before we block on reading. * We call flush() instead of dispatch() to * prevent reentrancy. */ wl_display_flush(wl_display); close(pipefd[1]); rc = run_paste_command(pipefd[0], "data"); if (!rc) { if (options.watch) { /* Try to cope without exiting completely */ offer_destroy(offer); return; } exit(1); } if (!options.no_newline && !options.watch) { rc = write(STDOUT_FILENO, "\n", 1); if (rc != 1) { perror("write"); } } offer_destroy(offer); if (!options.watch) { free(options.explicit_type); free(options.inferred_type); exit(0); } } static void print_usage(FILE *f, const char *argv0) { fprintf( f, "Usage:\n" "\t%s [options]\n" "Paste content from the Wayland clipboard.\n\n" "Options:\n" "\t-n, --no-newline\tDo not append a newline character.\n" "\t-l, --list-types\tInstead of pasting, list the offered types.\n" "\t-p, --primary\t\tUse the \"primary\" clipboard.\n" "\t-w, --watch command\t" "Run a command each time the selection changes.\n" "\t-t, --type mime/type\t" "Override the inferred MIME type for the content.\n" "\t-s, --seat seat-name\t" "Pick the seat to work with.\n" "\t-v, --version\t\tDisplay version info.\n" "\t-h, --help\t\tDisplay this message.\n" "Mandatory arguments to long options are mandatory" " for short options too.\n\n" "See wl-clipboard(1) for more details.\n", argv0 ); } static void parse_options(int argc, argv_t argv) { if (argc < 1) { bail("Empty argv"); } static struct option long_options[] = { {"version", no_argument, 0, 'v'}, {"help", no_argument, 0, 'h'}, {"primary", no_argument, 0, 'p'}, {"no-newline", no_argument, 0, 'n'}, {"list-types", no_argument, 0, 'l'}, {"watch", required_argument, 0, 'w'}, {"type", required_argument, 0, 't'}, {"seat", required_argument, 0, 's'}, {0, 0, 0, 0} }; while (1) { int option_index; const char *opts = "vhpnlw:t:s:"; int c = getopt_long(argc, argv, opts, long_options, &option_index); if (c == -1) { break; } if (c == 0) { c = long_options[option_index].val; } switch (c) { case 'v': print_version_info(); exit(0); case 'h': print_usage(stdout, argv[0]); exit(0); case 'p': options.primary = 1; break; case 'n': options.no_newline = 1; break; case 'l': options.list_types = 1; break; case 'w': options.watch = 1; /* We tell getopt that --watch requires an argument, * but it's more nuanced than that. We actually take * that argument and everything that follows it as a * subcommand to spawn. When we get here, getopt sets * the optind variable to point to the *next* option * to be processed, after both the current option and * its argument, if any. So if we're invoked like this: * $ wl-paste --primary --watch foo bar baz * then optind will point to bar, as it considers foo * to be the argument that --watch requires. However, * if we get invoked like this: * $ wl-paste --watch=foo bar baz * or like this: * $ wl-paste -wfoo bar baz * then getopt will not consider it an error, and optind * will also point to bar. We do consider that an error, * so detect this case and print an error message. */ options.watch_command = (argv_t) &argv[optind - 1]; if (options.watch_command[0][0] == '-') { fprintf( stderr, "Expected a subcommand instead of an argument" " after --watch\n" ); print_usage(stderr, argv[0]); exit(1); } /* We're going to forward the rest of our * arguments to the command we spawn, so stop * trying to process further options. */ return; case 't': options.explicit_type = strdup(optarg); break; case 's': options.seat_name = strdup(optarg); break; default: /* getopt has already printed an error message */ print_usage(stderr, argv[0]); exit(1); } } if (optind != argc) { fprintf(stderr, "Unexpected argument: %s\n", argv[optind]); print_usage(stderr, argv[0]); exit(1); } } int main(int argc, argv_t argv) { parse_options(argc, argv); char *path = path_for_fd(STDOUT_FILENO); if (path != NULL && options.explicit_type == NULL) { options.inferred_type = infer_mime_type_from_name(path); } free(path); wl_display = wl_display_connect(NULL); if (wl_display == NULL) { complain_about_wayland_connection(); } if (wl_display_get_fd(wl_display) <= STDERR_FILENO) { complain_about_closed_stdio(wl_display); } struct registry *registry = calloc(1, sizeof(struct registry)); registry->wl_display = wl_display; registry_init(registry); /* Wait for the initial set of globals to appear */ wl_display_roundtrip(wl_display); struct seat *seat = registry_find_seat(registry, options.seat_name); if (seat == NULL) { complain_about_missing_seat(options.seat_name); } /* Create the device */ struct device_manager *device_manager = registry_find_device_manager(registry, options.primary); if (device_manager == NULL) { complain_about_selection_support(options.primary); } struct device *device = device_manager_get_device(device_manager, seat); /* Set up the callback before checking whether the device * actually supports the kind of selection we need, because * checking for the support might roundtrip. */ device->selection_callback = selection_callback; if (!device_supports_selection(device, options.primary)) { complain_about_selection_support(options.primary); } if (device->needs_popup_surface) { if (options.watch) { complain_about_watch_mode_support(); } /* If we cannot get the selection directly, pop up * a surface. When it gets focus, we'll immediately * get the selection events, se we don't need to do * anything special on the surface getting focus. */ popup_surface = calloc(1, sizeof(struct popup_surface)); popup_surface->registry = registry; popup_surface->seat = seat; popup_surface_init(popup_surface); } while (wl_display_dispatch(wl_display) >= 0); perror("wl_display_dispatch"); return 1; } wl-clipboard-2.2.1/subprojects/000077500000000000000000000000001447271603000164425ustar00rootroot00000000000000wl-clipboard-2.2.1/subprojects/expat.wrap000066400000000000000000000011311447271603000204520ustar00rootroot00000000000000[wrap-file] directory = expat-2.5.0 source_url = https://github.com/libexpat/libexpat/releases/download/R_2_5_0/expat-2.5.0.tar.xz source_filename = expat-2.5.0.tar.bz2 source_hash = ef2420f0232c087801abf705e89ae65f6257df6b7931d37846a193ef2e8cdcbe patch_filename = expat_2.5.0-3_patch.zip patch_url = https://wrapdb.mesonbuild.com/v2/expat_2.5.0-3/get_patch patch_hash = e30c8c32f79fd4563a86a5c9cfe419568c35b775077c2d1428170081129406b4 source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/expat_2.5.0-3/expat-2.5.0.tar.bz2 wrapdb_version = 2.5.0-3 [provide] expat = expat_dep wl-clipboard-2.2.1/subprojects/libffi.wrap000066400000000000000000000007611447271603000205740ustar00rootroot00000000000000[wrap-file] directory = libffi-3.4.4 source_url = https://github.com/libffi/libffi/releases/download/v3.4.4/libffi-3.4.4.tar.gz source_filename = libffi-3.4.4.tar.gz source_hash = d66c56ad259a82cf2a9dfc408b32bf5da52371500b84745f7fb8b645712df676 patch_filename = libffi_3.4.4-2_patch.zip patch_url = https://wrapdb.mesonbuild.com/v2/libffi_3.4.4-2/get_patch patch_hash = 77da71839584dfc33d998b6461fff1ebc90a6f9c0a8c2f490335aafe370a115b wrapdb_version = 3.4.4-2 [provide] dependency_names = libffi wl-clipboard-2.2.1/subprojects/wayland-protocols.wrap000066400000000000000000000004631447271603000230210ustar00rootroot00000000000000[wrap-file] directory = wayland-protocols-1.24 source_url = https://wayland.freedesktop.org/releases/wayland-protocols-1.24.tar.xz source_filename = wayland-protocols-1.24.tar.xz source_hash = bff0d8cffeeceb35159d6f4aa6bab18c807b80642c9d50f66cba52ecf7338bc2 [provide] wayland-protocols = wayland_protocols wl-clipboard-2.2.1/subprojects/wayland.wrap000066400000000000000000000006061447271603000207760ustar00rootroot00000000000000[wrap-file] directory = wayland-1.22.0 source_url = https://gitlab.freedesktop.org/wayland/wayland/-/releases/1.22.0/downloads/wayland-1.22.0.tar.xz source_filename = wayland-1.22.0.tar.xz source_hash = 1540af1ea698a471c2d8e9d288332c7e0fd360c8f1d12936ebb7e7cbc2425842 [provide] dependency_names = wayland-client, wayland-server, wayland-cursor, wayland-egl program_names = wayland-scanner