pax_global_header00006660000000000000000000000064141750402430014512gustar00rootroot0000000000000052 comment=9a74c7135a2332f5cb314c52d0361472c063d8cc core-0.8/000077500000000000000000000000001417504024300123115ustar00rootroot00000000000000core-0.8/.github/000077500000000000000000000000001417504024300136515ustar00rootroot00000000000000core-0.8/.github/workflows/000077500000000000000000000000001417504024300157065ustar00rootroot00000000000000core-0.8/.github/workflows/build.yml000066400000000000000000000012051417504024300175260ustar00rootroot00000000000000name: Build on: push: branches: [ main ] pull_request: branches: [ main ] jobs: debian: name: Debian runs-on: ubuntu-latest container: docker.io/library/debian:sid steps: - name: Checkout Source uses: actions/checkout@v2 - name: Update repository run: apt-get update -y - name: Install the basic dev packages run: apt-get install -y equivs curl git devscripts lintian build-essential automake autotools-dev cmake g++ - name: Install build dependencies run: mk-build-deps -i -t "apt-get --yes" -r - name: Build Package run: dpkg-buildpackage -b -uc -us -j$(nproc) core-0.8/.gitignore000066400000000000000000000011631417504024300143020ustar00rootroot00000000000000# C++ objects and libs *.slo *.lo *.o *.a *.la *.lai *.so *.so.* *.dll *.dylib # Qt-es object_script.*.Release object_script.*.Debug *_plugin_import.cpp /.qmake.cache /.qmake.stash *.pro.user *.pro.user.* *.qbs.user *.qbs.user.* *.moc moc_*.cpp moc_*.h qrc_*.cpp ui_*.h *.qmlc *.jsc Makefile* *build-* *.qm *.prl # Qt unit tests target_wrapper.* # QtCreator *.autosave # QtCreator Qml *.qmlproject.user *.qmlproject.user.* # QtCreator CMake CMakeLists.txt.user* # QtCreator 4.8< compilation database compile_commands.json # QtCreator local machine specific files for imported projects *creator.user* build/* .vscode/* core-0.8/CMakeLists.txt000066400000000000000000000020321417504024300150460ustar00rootroot00000000000000cmake_minimum_required(VERSION 3.5) project(core) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake;${CMAKE_CURRENT_SOURCE_DIR}/cmake") set(QT Core Gui Widgets Quick QuickControls2 DBus Xml X11Extras LinguistTools) find_package(Qt5 REQUIRED ${QT}) # find_package(FishUI REQUIRED) find_package(PkgConfig REQUIRED) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}) include(GNUInstallDirs) add_subdirectory(polkit-agent) add_subdirectory(screen-brightness) add_subdirectory(session) add_subdirectory(settings-daemon) add_subdirectory(shutdown-ui) add_subdirectory(xembed-sni-proxy) add_subdirectory(powerman) add_subdirectory(cpufreq) add_subdirectory(chotkeys) add_subdirectory(cupdatecursor) add_subdirectory(gmenuproxy) add_subdirectory(notificationd) add_subdirectory(sddm-helper) add_subdirectory(clipboard) install(FILES cutefish DESTINATION /etc/ COMPONENT Runtime) core-0.8/LICENSE000066400000000000000000001045151417504024300133240ustar00rootroot00000000000000 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 . core-0.8/README.md000066400000000000000000000031241417504024300135700ustar00rootroot00000000000000# Core System backend and start session and more. ## Compile dependencies ```shell sudo pacman -S extra-cmake-modules pkgconf qt5-base qt5-quickcontrols2 qt5-x11extras qt5-tools\ kwindowsystem polkit polkit-qt5 xorg-server-devel xf86-input-libinput xf86-input-synaptics ``` For Ubuntu: ```shell sudo apt install libpolkit-agent-1-dev libpolkit-qt5-1-dev libsm-dev libxtst-dev\ libxcb-randr0-dev libxcb-shape0-dev libxcb-xfixes0-dev libxcb-composite0-dev libxcb-damage0-dev libxcb-image0-dev libxcb-util0-dev libkf5idletime-dev ``` (Yes it's annoying that so many xcb's packages here is needed to install. Isn't there a way to install one package and these `libxcb`s all get ready?) For Debian: ```shell sudo apt install extra-cmake-modules pkg-config xserver-xorg-input-libinput-dev libx11-xcb-dev libxcb1-dev libxcb-randr0-dev\ libxcb-keysyms1-dev libxcursor-dev libxcb-xfixes0-dev libxcb-damage0-dev libxcb-composite0-dev libxcb-shm0-dev libxcb-util-dev\ libxcb-image0-dev libxcb-dpms0-dev libxcb-dri2-0-dev libxcb-dri3-dev libxcb-ewmh-dev libxcb-glx0-dev libxcb-record0-dev xserver-xorg-dev\ xserver-xorg-input-synaptics-dev libxtst-dev libsm-dev libpolkit-qt5-1-dev libpolkit-agent-1-dev libkf5windowsystem-dev libkf5globalaccel-dev\ libkf5coreaddons-dev libkf5idletime-dev libqt5x11extras5-dev qtbase5-dev qtdeclarative5-dev qtquickcontrols2-5-dev qttools5-dev qttools5-dev-tools ``` ## Runtime ## Build ```shell mkdir build cd build cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr .. make ``` ## Install ```shell sudo make install ``` ## License This project has been licensed by GPLv3. core-0.8/chotkeys/000077500000000000000000000000001417504024300141425ustar00rootroot00000000000000core-0.8/chotkeys/CMakeLists.txt000066400000000000000000000007621417504024300167070ustar00rootroot00000000000000find_package(Qt5 COMPONENTS Core Widgets DBus X11Extras REQUIRED) find_package(XCB MODULE REQUIRED COMPONENTS XCB KEYSYMS) find_package(X11) set(PROJECT_SOURCES main.cpp application.cpp hotkeys.cpp ) add_executable(chotkeys ${PROJECT_SOURCES} ) target_link_libraries(chotkeys PRIVATE Qt5::Core Qt5::Widgets Qt5::DBus Qt5::X11Extras ${XCB_LIBS} ${X11_LIBRARIES} XCB::KEYSYMS ) install(TARGETS chotkeys RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) core-0.8/chotkeys/application.cpp000066400000000000000000000037021417504024300171530ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: Reion Wong * * 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 * 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 "application.h" #include "hotkeys.h" #include Application::Application(QObject *parent) : QObject(parent) , m_hotKeys(new Hotkeys) { setupShortcuts(); connect(m_hotKeys, &Hotkeys::pressed, this, &Application::onPressed); connect(m_hotKeys, &Hotkeys::released, this, &Application::onReleased); } void Application::setupShortcuts() { m_hotKeys->registerKey(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_Delete)); m_hotKeys->registerKey(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_A)); m_hotKeys->registerKey(QKeySequence(Qt::META + Qt::Key_L)); // m_hotKeys->registerKey(QKeySequence(Qt::Key_Super_L)); } void Application::onPressed(QKeySequence keySeq) { if (keySeq.toString() == "Ctrl+Alt+Del") { QProcess::startDetached("cutefish-shutdown", QStringList()); } if (keySeq.toString() == "Meta+L") { QProcess::startDetached("cutefish-screenlocker", QStringList()); } if (keySeq.toString() == "Ctrl+Alt+A") { QProcess::startDetached("cutefish-screenshot", QStringList()); } } void Application::onReleased(QKeySequence keySeq) { if (keySeq == QKeySequence(Qt::Key_Super_L)) { QProcess::startDetached("cutefish-launcher", QStringList()); } } core-0.8/chotkeys/application.h000066400000000000000000000021441417504024300166170ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: Reion Wong * * 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 * 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 APPLICATION_H #define APPLICATION_H #include #include "hotkeys.h" class Application : public QObject { Q_OBJECT public: explicit Application(QObject *parent = nullptr); private: void setupShortcuts(); private slots: void onPressed(QKeySequence keySeq); void onReleased(QKeySequence keySeq); private: Hotkeys *m_hotKeys; }; #endif // APPLICATION_H core-0.8/chotkeys/hotkeys.cpp000066400000000000000000000200351417504024300163340ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: Reion Wong * * 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 * 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 "hotkeys.h" #include #include #include #include #include // #include // #include // XCB & X11 #include #include #include #include Hotkeys::Hotkeys(QObject *parent) : QObject(parent) { qApp->installNativeEventFilter(this); } Hotkeys::~Hotkeys() { qApp->removeNativeEventFilter(this); } bool Hotkeys::nativeEventFilter(const QByteArray &eventType, void *message, long *result) { Q_UNUSED(result); if (eventType != "xcb_generic_event_t") { return false; } xcb_generic_event_t *e = static_cast(message); if (e->response_type == XCB_KEY_PRESS) { xcb_key_press_event_t *keyEvent = static_cast(message); quint32 keycode = keyEvent->detail; quint32 mods = keyEvent->state; // & (ShiftMask | ControlMask | Mod1Mask | Mod3Mask); quint32 id = keycode | mods; // int keyQt; // KKeyServer::xcbKeyPressEventToQt(keyEvent, &keyQt); // bool found = false; // for (QKeySequence &seq : m_shortcuts.values()) { // if (seq == QKeySequence(keyQt)) { // found = true; // // emit pressed(seq); // break; // } // } // if (!found && m_shortcuts.contains(id)) { // // emit pressed(m_shortcuts[id]); // } // // Keyboard needs to be ungrabed after XGrabKey() activates the grab, // // otherwise it becomes frozen. // xcb_connection_t *c = QX11Info::connection(); // xcb_void_cookie_t cookie = xcb_ungrab_keyboard_checked(c, XCB_TIME_CURRENT_TIME); // xcb_flush(c); // // xcb_flush() only makes sure that the ungrab keyboard request has been // // sent, but is not enough to make sure that request has been fulfilled. Use // // xcb_request_check() to make sure that the request has been processed. // xcb_request_check(c, cookie); // int keyQt; // if (!KKeyServer::xcbKeyPressEventToQt(keyEvent, &keyQt)) { // qDebug() << "KKeyServer::xcbKeyPressEventToQt failed"; // return false; // } // // All that work for this hey... argh... // if (NET::timestampCompare(keyEvent->time, QX11Info::appTime()) > 0) { // QX11Info::setAppTime(keyEvent->time); // } // bool found = false; // for (QKeySequence &seq : m_shortcuts.values()) { // if (seq == QKeySequence(keyQt)) { // found = true; // emit pressed(seq); // break; // } // } if (m_shortcuts.contains(id)) { emit pressed(m_shortcuts[id]); } return true; } else if (e->response_type == XCB_KEY_RELEASE) { xcb_key_release_event_t *keyEvent = static_cast(message); quint32 keycode = keyEvent->detail; quint32 mods = keyEvent->state; // & (ShiftMask | ControlMask | Mod1Mask | Mod3Mask); quint32 id = keycode | mods; // META if (id == 197) { id = 133; } if (m_shortcuts.contains(id)) { emit released(m_shortcuts[id]); } return true; } return false; } void Hotkeys::registerKey(QKeySequence keySequence) { if (keySequence.isEmpty()) return; quint32 keycode = nativeKeycode(getKey(keySequence)); quint32 mods = nativeModifiers(getMods(keySequence)); quint32 keyId = keycode | mods; // META if (keycode == 204 && mods == 0) { keycode = 133; keyId = keycode | mods; } if (!m_shortcuts.contains(keyId)) { registerKey(keycode, mods); m_shortcuts.insert(keyId, keySequence); } } void Hotkeys::registerKey(quint32 keycode) { if (!m_shortcuts.contains(keycode)) { registerKey(keycode, 0); m_shortcuts.insert(keycode, QKeySequence(keycode | 0)); } } void Hotkeys::registerKey(quint32 key, quint32 mods) { xcb_grab_key(QX11Info::connection(), 1, QX11Info::appRootWindow(), mods, key, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC); xcb_grab_key(QX11Info::connection(), 1, QX11Info::appRootWindow(), mods | XCB_MOD_MASK_2, key, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC); } void Hotkeys::unregisterKey(quint32 key, quint32 mods) { xcb_ungrab_key(QX11Info::connection(), key, QX11Info::appRootWindow(), mods); } quint32 Hotkeys::nativeKeycode(Qt::Key k) { /* keysymdef.h */ quint32 key = 0; if (k >= Qt::Key_F1 && k <= Qt::Key_F35) { key = XK_F1 + (k - Qt::Key_F1); } else if (k >= Qt::Key_Space && k <= Qt::Key_QuoteLeft) { key = k; } else if (k >= Qt::Key_BraceLeft && k <= Qt::Key_AsciiTilde) { key = k; } else if (k >= Qt::Key_nobreakspace && k <= Qt::Key_ydiaeresis) { key = k; } else { switch (k) { case Qt::Key_Escape: key = XK_Escape; break; case Qt::Key_Tab: case Qt::Key_Backtab: key = XK_Tab; break; case Qt::Key_Backspace: key = XK_BackSpace; break; case Qt::Key_Return: case Qt::Key_Enter: key = XK_Return; break; case Qt::Key_Insert: key = XK_Insert; break; case Qt::Key_Delete: key = XK_Delete; break; case Qt::Key_Pause: key = XK_Pause; break; case Qt::Key_Print: key = XK_Print; break; case Qt::Key_SysReq: key = XK_Sys_Req; break; case Qt::Key_Clear: key = XK_Clear; break; case Qt::Key_Home: key = XK_Home; break; case Qt::Key_End: key = XK_End; break; case Qt::Key_Left: key = XK_Left; break; case Qt::Key_Up: key = XK_Up; break; case Qt::Key_Right: key = XK_Right; break; case Qt::Key_Down: key = XK_Down; break; case Qt::Key_PageUp: key = XK_Page_Up; break; case Qt::Key_PageDown: key = XK_Page_Down; break; default: key = 0; } } return XKeysymToKeycode(QX11Info::display(), key); } quint32 Hotkeys::nativeModifiers(Qt::KeyboardModifiers m) { quint32 mods = Qt::NoModifier; if (m & Qt::ShiftModifier) mods |= ShiftMask; if (m & Qt::ControlModifier) mods |= ControlMask; if (m & Qt::AltModifier) mods |= Mod1Mask; if (m & Qt::MetaModifier) mods |= Mod4Mask; return mods; } Qt::Key Hotkeys::getKey(const QKeySequence &keyseq) { if (keyseq.isEmpty()) { return Qt::Key(0); } return Qt::Key(keyseq[0] & ~Qt::KeyboardModifierMask); } Qt::KeyboardModifiers Hotkeys::getMods(const QKeySequence &keyseq) { if (keyseq.isEmpty()) { return Qt::KeyboardModifiers(); } return Qt::KeyboardModifiers(keyseq[0] & Qt::KeyboardModifierMask); } core-0.8/chotkeys/hotkeys.h000066400000000000000000000033171417504024300160050ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: Reion Wong * * 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 * 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 HOTKEYS_H #define HOTKEYS_H #include #include #include #include #include #include #include class Hotkeys : public QObject, public QAbstractNativeEventFilter { Q_OBJECT public: explicit Hotkeys(QObject *parent = nullptr); ~Hotkeys(); bool nativeEventFilter(const QByteArray &eventType, void *message, long *result) override; void registerKey(QKeySequence keySequence); void registerKey(quint32 keycode); void registerKey(quint32 key, quint32 mods); void unregisterKey(quint32 key, quint32 mods); signals: void pressed(QKeySequence keySeq); void released(QKeySequence keySeq); private: quint32 nativeKeycode(Qt::Key k); quint32 nativeModifiers(Qt::KeyboardModifiers m); Qt::Key getKey(const QKeySequence& keyseq); Qt::KeyboardModifiers getMods(const QKeySequence& keyseq); private: QHash m_shortcuts; }; #endif // HOTKEYS_H core-0.8/chotkeys/main.cpp000066400000000000000000000022311417504024300155700ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: Reion Wong * * 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 * 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 #include #include "application.h" int main(int argc, char *argv[]) { QApplication a(argc, argv); a.setQuitOnLastWindowClosed(true); // if (!QDBusConnection::sessionBus().registerService("com.cutefish.Chotkeys")) { // return -1; // } // if (!QDBusConnection::sessionBus().registerObject("/Chotkeys", &a)) { // return -1; // } Application app; return a.exec(); } core-0.8/clipboard/000077500000000000000000000000001417504024300142505ustar00rootroot00000000000000core-0.8/clipboard/CMakeLists.txt000066400000000000000000000010151417504024300170050ustar00rootroot00000000000000cmake_minimum_required(VERSION 3.14) project(cutefish-clipboard LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) find_package(Qt5 COMPONENTS Core Gui Widgets REQUIRED) add_executable(cutefish-clipboard main.cpp clipboard.cpp ) target_link_libraries(cutefish-clipboard Qt5::Core Qt5::Gui Qt5::Widgets ) install(TARGETS cutefish-clipboard DESTINATION ${CMAKE_INSTALL_BINDIR})core-0.8/clipboard/clipboard.cpp000066400000000000000000000041221417504024300167120ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: Kate Leet * * 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 * 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 "clipboard.h" #include #include #include #include #include Clipboard::Clipboard(QObject *parent) : QObject(parent) , m_qtClipboard(qApp->clipboard()) { connect(m_qtClipboard, &QClipboard::dataChanged, this, &Clipboard::onDataChanged); } void Clipboard::onDataChanged() { const QMimeData *mimeData = m_qtClipboard->mimeData(); if (mimeData->formats().isEmpty()) return; if (mimeData->hasFormat("application/x-cutefish-clipboard") && mimeData->data("application/x-cutefish-clipboard") == "1") return; QByteArray timeStamp = mimeData->data("TIMESTAMP"); QMimeData *newMimeData = new QMimeData; if (mimeData->hasImage()) { QPixmap srcPix = m_qtClipboard->pixmap(); QByteArray bArray; QBuffer buffer(&bArray); buffer.open(QIODevice::WriteOnly); srcPix.save(&buffer); newMimeData->setImageData(srcPix); newMimeData->setData("TIMESTAMP", timeStamp); } for (const QString &key : mimeData->formats()) { if (key == "image/png" || key == "application/x-qt-image") continue; newMimeData->setData(key, mimeData->data(key)); } // cutefish flag. newMimeData->setData("application/x-cutefish-clipboard", QByteArray("1")); m_qtClipboard->setMimeData(newMimeData); } core-0.8/clipboard/clipboard.h000066400000000000000000000020051417504024300163550ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: Kate Leet * * 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 * 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 CLIPBOARD_H #define CLIPBOARD_H #include #include class Clipboard : public QObject { Q_OBJECT public: explicit Clipboard(QObject *parent = nullptr); private slots: void onDataChanged(); private: QClipboard *m_qtClipboard; }; #endif // CLIPBOARD_H core-0.8/clipboard/main.cpp000066400000000000000000000015761417504024300157110ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: Kate Leet * * 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 * 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 #include "clipboard.h" int main(int argc, char *argv[]) { QApplication a(argc, argv); Clipboard clipboard; return a.exec(); } core-0.8/cmake/000077500000000000000000000000001417504024300133715ustar00rootroot00000000000000core-0.8/cmake/ECMFindModuleHelpers.cmake000066400000000000000000000323441417504024300202770ustar00rootroot00000000000000#.rst: # ECMFindModuleHelpers # -------------------- # # Helper macros for find modules: ecm_find_package_version_check(), # ecm_find_package_parse_components() and # ecm_find_package_handle_library_components(). # # :: # # ecm_find_package_version_check() # # Prints warnings if the CMake version or the project's required CMake version # is older than that required by extra-cmake-modules. # # :: # # ecm_find_package_parse_components( # RESULT_VAR # KNOWN_COMPONENTS [ [...]] # [SKIP_DEPENDENCY_HANDLING]) # # This macro will populate with a list of components found in # _FIND_COMPONENTS, after checking that all those components are in the # list of KNOWN_COMPONENTS; if there are any unknown components, it will print # an error or warning (depending on the value of _FIND_REQUIRED) and call # return(). # # The order of components in is guaranteed to match the order they # are listed in the KNOWN_COMPONENTS argument. # # If SKIP_DEPENDENCY_HANDLING is not set, for each component the variable # __component_deps will be checked for dependent components. # If is listed in _FIND_COMPONENTS, then all its (transitive) # dependencies will also be added to . # # :: # # ecm_find_package_handle_library_components( # COMPONENTS [ [...]] # [SKIP_DEPENDENCY_HANDLING]) # [SKIP_PKG_CONFIG]) # # Creates an imported library target for each component. The operation of this # macro depends on the presence of a number of CMake variables. # # The __lib variable should contain the name of this library, # and __header variable should contain the name of a header # file associated with it (whatever relative path is normally passed to # '#include'). __header_subdir variable can be used to specify # which subdirectory of the include path the headers will be found in. # ecm_find_package_components() will then search for the library # and include directory (creating appropriate cache variables) and create an # imported library target named ::. # # Additional variables can be used to provide additional information: # # If SKIP_PKG_CONFIG, the __pkg_config variable is set, and # pkg-config is found, the pkg-config module given by # __pkg_config will be searched for and used to help locate the # library and header file. It will also be used to set # __VERSION. # # Note that if version information is found via pkg-config, # __FIND_VERSION can be set to require a particular version # for each component. # # If SKIP_DEPENDENCY_HANDLING is not set, the INTERFACE_LINK_LIBRARIES property # of the imported target for will be set to contain the imported # targets for the components listed in __component_deps. # _FOUND will also be set to false if any of the compoments in # __component_deps are not found. This requires the components # in __component_deps to be listed before in the # COMPONENTS argument. # # The following variables will be set: # # ``_TARGETS`` # the imported targets # ``_LIBRARIES`` # the found libraries # ``_INCLUDE_DIRS`` # the combined required include directories for the components # ``_DEFINITIONS`` # the "other" CFLAGS provided by pkg-config, if any # ``_VERSION`` # the value of ``__VERSION`` for the first component that # has this variable set (note that components are searched for in the order # they are passed to the macro), although if it is already set, it will not # be altered # # Note that these variables are never cleared, so if # ecm_find_package_handle_library_components() is called multiple times with # different components (typically because of multiple find_package() calls) then # ``_TARGETS``, for example, will contain all the targets found in any # call (although no duplicates). # # Since pre-1.0.0. #============================================================================= # Copyright 2014 Alex Merry # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # 3. The name of the author may not be used to endorse or promote products # derived from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. include(CMakeParseArguments) macro(ecm_find_package_version_check module_name) if(CMAKE_VERSION VERSION_LESS 2.8.12) message(FATAL_ERROR "CMake 2.8.12 is required by Find${module_name}.cmake") endif() if(CMAKE_MINIMUM_REQUIRED_VERSION VERSION_LESS 2.8.12) message(AUTHOR_WARNING "Your project should require at least CMake 2.8.12 to use Find${module_name}.cmake") endif() endmacro() macro(ecm_find_package_parse_components module_name) set(ecm_fppc_options SKIP_DEPENDENCY_HANDLING) set(ecm_fppc_oneValueArgs RESULT_VAR) set(ecm_fppc_multiValueArgs KNOWN_COMPONENTS DEFAULT_COMPONENTS) cmake_parse_arguments(ECM_FPPC "${ecm_fppc_options}" "${ecm_fppc_oneValueArgs}" "${ecm_fppc_multiValueArgs}" ${ARGN}) if(ECM_FPPC_UNPARSED_ARGUMENTS) message(FATAL_ERROR "Unexpected arguments to ecm_find_package_parse_components: ${ECM_FPPC_UNPARSED_ARGUMENTS}") endif() if(NOT ECM_FPPC_RESULT_VAR) message(FATAL_ERROR "Missing RESULT_VAR argument to ecm_find_package_parse_components") endif() if(NOT ECM_FPPC_KNOWN_COMPONENTS) message(FATAL_ERROR "Missing KNOWN_COMPONENTS argument to ecm_find_package_parse_components") endif() if(NOT ECM_FPPC_DEFAULT_COMPONENTS) set(ECM_FPPC_DEFAULT_COMPONENTS ${ECM_FPPC_KNOWN_COMPONENTS}) endif() if(${module_name}_FIND_COMPONENTS) set(ecm_fppc_requestedComps ${${module_name}_FIND_COMPONENTS}) if(NOT ECM_FPPC_SKIP_DEPENDENCY_HANDLING) # Make sure deps are included foreach(ecm_fppc_comp ${ecm_fppc_requestedComps}) foreach(ecm_fppc_dep_comp ${${module_name}_${ecm_fppc_comp}_component_deps}) list(FIND ecm_fppc_requestedComps "${ecm_fppc_dep_comp}" ecm_fppc_index) if("${ecm_fppc_index}" STREQUAL "-1") if(NOT ${module_name}_FIND_QUIETLY) message(STATUS "${module_name}: ${ecm_fppc_comp} requires ${${module_name}_${ecm_fppc_comp}_component_deps}") endif() list(APPEND ecm_fppc_requestedComps "${ecm_fppc_dep_comp}") endif() endforeach() endforeach() else() message(STATUS "Skipping dependency handling for ${module_name}") endif() list(REMOVE_DUPLICATES ecm_fppc_requestedComps) # This makes sure components are listed in the same order as # KNOWN_COMPONENTS (potentially important for inter-dependencies) set(${ECM_FPPC_RESULT_VAR}) foreach(ecm_fppc_comp ${ECM_FPPC_KNOWN_COMPONENTS}) list(FIND ecm_fppc_requestedComps "${ecm_fppc_comp}" ecm_fppc_index) if(NOT "${ecm_fppc_index}" STREQUAL "-1") list(APPEND ${ECM_FPPC_RESULT_VAR} "${ecm_fppc_comp}") list(REMOVE_AT ecm_fppc_requestedComps ${ecm_fppc_index}) endif() endforeach() # if there are any left, they are unknown components if(ecm_fppc_requestedComps) set(ecm_fppc_msgType STATUS) if(${module_name}_FIND_REQUIRED) set(ecm_fppc_msgType FATAL_ERROR) endif() if(NOT ${module_name}_FIND_QUIETLY) message(${ecm_fppc_msgType} "${module_name}: requested unknown components ${ecm_fppc_requestedComps}") endif() return() endif() else() set(${ECM_FPPC_RESULT_VAR} ${ECM_FPPC_DEFAULT_COMPONENTS}) endif() endmacro() macro(ecm_find_package_handle_library_components module_name) set(ecm_fpwc_options SKIP_PKG_CONFIG SKIP_DEPENDENCY_HANDLING) set(ecm_fpwc_oneValueArgs) set(ecm_fpwc_multiValueArgs COMPONENTS) cmake_parse_arguments(ECM_FPWC "${ecm_fpwc_options}" "${ecm_fpwc_oneValueArgs}" "${ecm_fpwc_multiValueArgs}" ${ARGN}) if(ECM_FPWC_UNPARSED_ARGUMENTS) message(FATAL_ERROR "Unexpected arguments to ecm_find_package_handle_components: ${ECM_FPWC_UNPARSED_ARGUMENTS}") endif() if(NOT ECM_FPWC_COMPONENTS) message(FATAL_ERROR "Missing COMPONENTS argument to ecm_find_package_handle_components") endif() include(FindPackageHandleStandardArgs) find_package(PkgConfig) foreach(ecm_fpwc_comp ${ECM_FPWC_COMPONENTS}) set(ecm_fpwc_dep_vars) set(ecm_fpwc_dep_targets) if(NOT SKIP_DEPENDENCY_HANDLING) foreach(ecm_fpwc_dep ${${module_name}_${ecm_fpwc_comp}_component_deps}) list(APPEND ecm_fpwc_dep_vars "${module_name}_${ecm_fpwc_dep}_FOUND") list(APPEND ecm_fpwc_dep_targets "${module_name}::${ecm_fpwc_dep}") endforeach() endif() if(NOT ECM_FPWC_SKIP_PKG_CONFIG AND ${module_name}_${ecm_fpwc_comp}_pkg_config) pkg_check_modules(PKG_${module_name}_${ecm_fpwc_comp} QUIET ${${module_name}_${ecm_fpwc_comp}_pkg_config}) endif() find_path(${module_name}_${ecm_fpwc_comp}_INCLUDE_DIR NAMES ${${module_name}_${ecm_fpwc_comp}_header} HINTS ${PKG_${module_name}_${ecm_fpwc_comp}_INCLUDE_DIRS} PATH_SUFFIXES ${${module_name}_${ecm_fpwc_comp}_header_subdir} ) find_library(${module_name}_${ecm_fpwc_comp}_LIBRARY NAMES ${${module_name}_${ecm_fpwc_comp}_lib} HINTS ${PKG_${module_name}_${ecm_fpwc_comp}_LIBRARY_DIRS} ) set(${module_name}_${ecm_fpwc_comp}_VERSION "${PKG_${module_name}_${ecm_fpwc_comp}_VERSION}") if(NOT ${module_name}_VERSION) set(${module_name}_VERSION ${${module_name}_${ecm_fpwc_comp}_VERSION}) endif() find_package_handle_standard_args(${module_name}_${ecm_fpwc_comp} FOUND_VAR ${module_name}_${ecm_fpwc_comp}_FOUND REQUIRED_VARS ${module_name}_${ecm_fpwc_comp}_LIBRARY ${module_name}_${ecm_fpwc_comp}_INCLUDE_DIR ${ecm_fpwc_dep_vars} VERSION_VAR ${module_name}_${ecm_fpwc_comp}_VERSION ) mark_as_advanced( ${module_name}_${ecm_fpwc_comp}_LIBRARY ${module_name}_${ecm_fpwc_comp}_INCLUDE_DIR ) if(${module_name}_${ecm_fpwc_comp}_FOUND) list(APPEND ${module_name}_LIBRARIES "${${module_name}_${ecm_fpwc_comp}_LIBRARY}") list(APPEND ${module_name}_INCLUDE_DIRS "${${module_name}_${ecm_fpwc_comp}_INCLUDE_DIR}") set(${module_name}_DEFINITIONS ${${module_name}_DEFINITIONS} ${PKG_${module_name}_${ecm_fpwc_comp}_DEFINITIONS}) if(NOT TARGET ${module_name}::${ecm_fpwc_comp}) add_library(${module_name}::${ecm_fpwc_comp} UNKNOWN IMPORTED) set_target_properties(${module_name}::${ecm_fpwc_comp} PROPERTIES IMPORTED_LOCATION "${${module_name}_${ecm_fpwc_comp}_LIBRARY}" INTERFACE_COMPILE_OPTIONS "${PKG_${module_name}_${ecm_fpwc_comp}_DEFINITIONS}" INTERFACE_INCLUDE_DIRECTORIES "${${module_name}_${ecm_fpwc_comp}_INCLUDE_DIR}" INTERFACE_LINK_LIBRARIES "${ecm_fpwc_dep_targets}" ) endif() list(APPEND ${module_name}_TARGETS "${module_name}::${ecm_fpwc_comp}") endif() endforeach() if(${module_name}_LIBRARIES) list(REMOVE_DUPLICATES ${module_name}_LIBRARIES) endif() if(${module_name}_INCLUDE_DIRS) list(REMOVE_DUPLICATES ${module_name}_INCLUDE_DIRS) endif() if(${module_name}_DEFINITIONS) list(REMOVE_DUPLICATES ${module_name}_DEFINITIONS) endif() if(${module_name}_TARGETS) list(REMOVE_DUPLICATES ${module_name}_TARGETS) endif() endmacro() core-0.8/cmake/FindAppMenuGtkModule.cmake000066400000000000000000000022071417504024300203560ustar00rootroot00000000000000#.rst: # FindAppmenuGtkModule # ----------- # # Try to find appmenu-gtk2-module and appmenu-gtk3-module. # Once done this will define: # # ``AppMenuGtkModule_FOUND`` # System has both appmenu-gtk2-module and appmenu-gtk3-module #============================================================================= # SPDX-FileCopyrightText: 2018 Kai Uwe Broulik # # SPDX-License-Identifier: BSD-3-Clause find_library(AppMenuGtk2Module_LIBRARY libappmenu-gtk-module.so PATH_SUFFIXES gtk-2.0/modules ) find_library(AppMenuGtk3Module_LIBRARY libappmenu-gtk-module.so PATH_SUFFIXES gtk-3.0/modules ) include(FindPackageHandleStandardArgs) find_package_handle_standard_args(AppMenuGtkModule FOUND_VAR AppMenuGtkModule_FOUND REQUIRED_VARS AppMenuGtk3Module_LIBRARY AppMenuGtk2Module_LIBRARY ) mark_as_advanced(AppMenuGtk3Module_LIBRARY AppMenuGtk2Module_LIBRARY) include(FeatureSummary) set_package_properties(AppMenuGtkModule PROPERTIES URL "https://github.com/rilian-la-te/vala-panel-appmenu/tree/master/subprojects/appmenu-gtk-module" DESCRIPTION "Application Menu GTK+ Module" )core-0.8/cmake/FindX11_XCB.cmake000066400000000000000000000056031417504024300162450ustar00rootroot00000000000000# SPDX-FileCopyrightText: 2014 Alex Merry # SPDX-FileCopyrightText: 2011 Fredrik Höglund # SPDX-FileCopyrightText: 2008 Helio Chissini de Castro # SPDX-FileCopyrightText: 2007 Matthias Kretz # # SPDX-License-Identifier: BSD-3-Clause #[=======================================================================[.rst: FindX11_XCB ----------- Try to find the X11 XCB compatibility library. This will define the following variables: ``X11_XCB_FOUND`` True if (the requested version of) libX11-xcb is available ``X11_XCB_VERSION`` The version of libX11-xcb (this is not guaranteed to be set even when X11_XCB_FOUND is true) ``X11_XCB_LIBRARIES`` This can be passed to target_link_libraries() instead of the ``EGL::EGL`` target ``X11_XCB_INCLUDE_DIR`` This should be passed to target_include_directories() if the target is not used for linking ``X11_XCB_DEFINITIONS`` This should be passed to target_compile_options() if the target is not used for linking If ``X11_XCB_FOUND`` is TRUE, it will also define the following imported target: ``X11::XCB`` The X11 XCB compatibility library In general we recommend using the imported target, as it is easier to use. Bear in mind, however, that if the target is in the link interface of an exported library, it must be made available by the package config file. Since pre-1.0.0. #]=======================================================================] # use pkg-config to get the directories and then use these values # in the FIND_PATH() and FIND_LIBRARY() calls find_package(PkgConfig QUIET) pkg_check_modules(PKG_X11_XCB QUIET x11-xcb) set(X11_XCB_DEFINITIONS ${PKG_X11_XCB_CFLAGS_OTHER}) set(X11_XCB_VERSION ${PKG_X11_XCB_VERSION}) find_path(X11_XCB_INCLUDE_DIR NAMES X11/Xlib-xcb.h HINTS ${PKG_X11_XCB_INCLUDE_DIRS} ) find_library(X11_XCB_LIBRARY NAMES X11-xcb HINTS ${PKG_X11_XCB_LIBRARY_DIRS} ) include(FindPackageHandleStandardArgs) find_package_handle_standard_args(X11_XCB FOUND_VAR X11_XCB_FOUND REQUIRED_VARS X11_XCB_LIBRARY X11_XCB_INCLUDE_DIR VERSION_VAR X11_XCB_VERSION ) if(X11_XCB_FOUND AND NOT TARGET X11::XCB) add_library(X11::XCB UNKNOWN IMPORTED) set_target_properties(X11::XCB PROPERTIES IMPORTED_LOCATION "${X11_XCB_LIBRARY}" INTERFACE_COMPILE_OPTIONS "${X11_XCB_DEFINITIONS}" INTERFACE_INCLUDE_DIRECTORIES "${X11_XCB_INCLUDE_DIR}" ) endif() mark_as_advanced(X11_XCB_INCLUDE_DIR X11_XCB_LIBRARY) # compatibility variables set(X11_XCB_LIBRARIES ${X11_XCB_LIBRARY}) set(X11_XCB_INCLUDE_DIRS ${X11_XCB_INCLUDE_DIR}) set(X11_XCB_VERSION_STRING ${X11_XCB_VERSION}) include(FeatureSummary) set_package_properties(X11_XCB PROPERTIES URL "https://xorg.freedesktop.org/" DESCRIPTION "A compatibility library for code that translates Xlib API calls into XCB calls" ) core-0.8/cmake/FindXCB.cmake000066400000000000000000000124471417504024300156200ustar00rootroot00000000000000# SPDX-FileCopyrightText: 2011 Fredrik Höglund # SPDX-FileCopyrightText: 2013 Martin Gräßlin # SPDX-FileCopyrightText: 2014-2015 Alex Merry # # SPDX-License-Identifier: BSD-3-Clause #[=======================================================================[.rst: FindXCB ------- Try to find XCB. This is a component-based find module, which makes use of the COMPONENTS and OPTIONAL_COMPONENTS arguments to find_module. The following components are available:: XCB ATOM AUX COMPOSITE CURSOR DAMAGE DPMS DRI2 DRI3 EVENT EWMH GLX ICCCM IMAGE KEYSYMS PRESENT RANDR RECORD RENDER RENDERUTIL RES SCREENSAVER SHAPE SHM SYNC UTIL XEVIE XF86DRI XFIXES XINERAMA XINPUT XKB XPRINT XTEST XV XVMC If no components are specified, this module will act as though all components except XINPUT (which is considered unstable) were passed to OPTIONAL_COMPONENTS. This module will define the following variables, independently of the components searched for or found: ``XCB_FOUND`` True if (the requestion version of) xcb is available ``XCB_VERSION`` Found xcb version ``XCB_TARGETS`` A list of all targets imported by this module (note that there may be more than the components that were requested) ``XCB_LIBRARIES`` This can be passed to target_link_libraries() instead of the imported targets ``XCB_INCLUDE_DIRS`` This should be passed to target_include_directories() if the targets are not used for linking ``XCB_DEFINITIONS`` This should be passed to target_compile_options() if the targets are not used for linking For each searched-for components, ``XCB__FOUND`` will be set to true if the corresponding xcb library was found, and false otherwise. If ``XCB__FOUND`` is true, the imported target ``XCB::`` will be defined. This module will also attempt to determine ``XCB_*_VERSION`` variables for each imported target, although ``XCB_VERSION`` should normally be sufficient. In general we recommend using the imported targets, as they are easier to use and provide more control. Bear in mind, however, that if any target is in the link interface of an exported library, it must be made available by the package config file. Since pre-1.0.0. #]=======================================================================] include(${CMAKE_CURRENT_LIST_DIR}/ECMFindModuleHelpers.cmake) # Note that this list needs to be ordered such that any component # appears after its dependencies set(XCB_known_components XCB RENDER SHAPE XFIXES SHM ATOM AUX COMPOSITE CURSOR DAMAGE DPMS DRI2 DRI3 EVENT EWMH GLX ICCCM IMAGE KEYSYMS PRESENT RANDR RECORD RENDERUTIL RES SCREENSAVER SYNC UTIL XEVIE XF86DRI XINERAMA XINPUT XKB XPRINT XTEST XV XVMC ) # XINPUT is unstable; do not include it by default set(XCB_default_components ${XCB_known_components}) list(REMOVE_ITEM XCB_default_components "XINPUT") # default component info: xcb components have fairly predictable # header files, library names and pkg-config names foreach(_comp ${XCB_known_components}) string(TOLOWER "${_comp}" _lc_comp) set(XCB_${_comp}_component_deps XCB) set(XCB_${_comp}_pkg_config "xcb-${_lc_comp}") set(XCB_${_comp}_lib "xcb-${_lc_comp}") set(XCB_${_comp}_header "xcb/${_lc_comp}.h") endforeach() # exceptions set(XCB_XCB_component_deps) set(XCB_COMPOSITE_component_deps XCB XFIXES) set(XCB_DAMAGE_component_deps XCB XFIXES) set(XCB_IMAGE_component_deps XCB SHM) set(XCB_RENDERUTIL_component_deps XCB RENDER) set(XCB_XFIXES_component_deps XCB RENDER SHAPE) set(XCB_XVMC_component_deps XCB XV) set(XCB_XV_component_deps XCB SHM) set(XCB_XCB_pkg_config "xcb") set(XCB_XCB_lib "xcb") set(XCB_ATOM_header "xcb/xcb_atom.h") set(XCB_ATOM_lib "xcb-util") set(XCB_AUX_header "xcb/xcb_aux.h") set(XCB_AUX_lib "xcb-util") set(XCB_CURSOR_header "xcb/xcb_cursor.h") set(XCB_EVENT_header "xcb/xcb_event.h") set(XCB_EVENT_lib "xcb-util") set(XCB_EWMH_header "xcb/xcb_ewmh.h") set(XCB_ICCCM_header "xcb/xcb_icccm.h") set(XCB_IMAGE_header "xcb/xcb_image.h") set(XCB_KEYSYMS_header "xcb/xcb_keysyms.h") set(XCB_PIXEL_header "xcb/xcb_pixel.h") set(XCB_RENDERUTIL_header "xcb/xcb_renderutil.h") set(XCB_RENDERUTIL_lib "xcb-render-util") set(XCB_UTIL_header "xcb/xcb_util.h") ecm_find_package_parse_components(XCB RESULT_VAR XCB_components KNOWN_COMPONENTS ${XCB_known_components} DEFAULT_COMPONENTS ${XCB_default_components} ) list(FIND XCB_components "XINPUT" _XCB_XINPUT_index) if (NOT _XCB_XINPUT_index EQUAL -1) message(AUTHOR_WARNING "XINPUT from XCB was requested: this is EXPERIMENTAL and is likely to unavailable on many systems!") endif() ecm_find_package_handle_library_components(XCB COMPONENTS ${XCB_components} ) find_package_handle_standard_args(XCB FOUND_VAR XCB_FOUND REQUIRED_VARS XCB_LIBRARIES VERSION_VAR XCB_VERSION HANDLE_COMPONENTS ) include(FeatureSummary) set_package_properties(XCB PROPERTIES URL "https://xcb.freedesktop.org/" DESCRIPTION "X protocol C-language Binding" ) core-0.8/cpufreq/000077500000000000000000000000001417504024300137565ustar00rootroot00000000000000core-0.8/cpufreq/CMakeLists.txt000066400000000000000000000010601417504024300165130ustar00rootroot00000000000000project(cutefish-cpufreq) set(TARGET cutefish-cpufreq) set(SOURCES main.cpp ) add_executable(${TARGET} ${SOURCES} ${DBUS_SOURCES}) target_link_libraries(${TARGET} Qt5::Core Qt5::Quick Qt5::DBus Qt5::X11Extras ) configure_file( com.cutefish.cpufreq.pkexec.policy.in com.cutefish.cpufreq.pkexec.policy @ONLY ) install(TARGETS ${TARGET} DESTINATION ${CMAKE_INSTALL_BINDIR}) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/com.cutefish.cpufreq.pkexec.policy DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/polkit-1/actions/) core-0.8/cpufreq/com.cutefish.cpufreq.pkexec.policy.in000066400000000000000000000012211417504024300231110ustar00rootroot00000000000000 Authentication is required to Change CPU configuration battery no no yes @CMAKE_INSTALL_FULL_BINDIR@/cutefish-cpufreq core-0.8/cpufreq/main.cpp000066400000000000000000000046741417504024300154210ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: Reion Wong * * 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 * 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 #include #include #include #include int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QCommandLineParser parser; parser.setApplicationDescription(QStringLiteral("Cutefish CPU frequency tool")); parser.addHelpOption(); QCommandLineOption setOption(QStringList() << "s" << "set" << "Setting"); parser.addOption(setOption); QCommandLineOption numberOption(QStringList() << "c" << "number" << "Number"); parser.addOption(numberOption); QCommandLineOption modeOption(QStringList() << "m" << "mode" << "Mode"); parser.addOption(modeOption); parser.process(a); // cutefish-cpufreq --set -n 0 -m performance if (parser.isSet(setOption) && parser.isSet(numberOption) && parser.isSet(modeOption)) { QString modeStr = parser.positionalArguments().last(); if (modeStr != "powersave" && modeStr != "performance") { return -1; } QFile file(QString("/sys/devices/system/cpu/cpu%1/cpufreq/scaling_governor").arg(parser.positionalArguments().first())); if (!file.open(QIODevice::WriteOnly)) { return -1; } file.write(modeStr.toUtf8()); file.close(); // Set intel gpu. if (QFile("/usr/bin/intel_gpu_frequency").exists()) { QProcess process; process.setProgram("/usr/bin/intel_gpu_frequency"); if (modeStr == "powersave") { process.setArguments(QStringList() << "-d"); } else { process.setArguments(QStringList() << "-m"); } process.start(); process.waitForFinished(); } } return 0; } core-0.8/cupdatecursor/000077500000000000000000000000001417504024300151745ustar00rootroot00000000000000core-0.8/cupdatecursor/CMakeLists.txt000066400000000000000000000005151417504024300177350ustar00rootroot00000000000000find_package(Qt5 COMPONENTS Core Gui X11Extras REQUIRED) find_package(X11) add_executable(cupdatecursor main.cpp ) target_link_libraries(cupdatecursor Qt5::Core Qt5::Gui Qt5::X11Extras ${X11_LIBRARIES} X11::X11 X11::Xi X11::Xcursor ) install(TARGETS cupdatecursor DESTINATION ${CMAKE_INSTALL_BINDIR}) core-0.8/cupdatecursor/main.cpp000066400000000000000000000024611417504024300166270ustar00rootroot00000000000000#include #include #include #include #include #include #include #include inline void applyTheme(const QString &theme, int size) { Display *display = QX11Info::display(); if (!theme.isEmpty()) XcursorSetTheme(display, QFile::encodeName(theme)); if (size > 0) XcursorSetDefaultSize(display, size); Cursor handle = XcursorLibraryLoadCursor(display, "left_ptr"); XDefineCursor(display, DefaultRootWindow(display), handle); XFreeCursor(display, handle); XFlush(display); // For KWin QSettings settings(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + "/kcminputrc", QSettings::IniFormat); settings.beginGroup("Mouse"); settings.setValue("cursorTheme", theme); settings.setValue("cursorSize", size); settings.endGroup(); settings.sync(); } int main(int argc, char *argv[]) { QGuiApplication::setDesktopSettingsAware(false); QGuiApplication a(argc, argv); if (argc != 3) return 1; if (!QX11Info::isPlatformX11()) return 2; QString theme = QFile::decodeName(argv[1]); QString size = QFile::decodeName(argv[2]); applyTheme(theme, size.toInt()); return 0; } core-0.8/cutefish000066400000000000000000000000251417504024300140430ustar00rootroot00000000000000[General] Version=0.8core-0.8/debian/000077500000000000000000000000001417504024300135335ustar00rootroot00000000000000core-0.8/debian/changelog000066400000000000000000000003021417504024300154000ustar00rootroot00000000000000cutefish-core (0.8) UNRELEASED; urgency=high * Initial release (CutefishOS) -- CutefishOS Packaging Team Sat, 29 Jan 2022 03:14:11 +0800 core-0.8/debian/compat000066400000000000000000000000011417504024300147300ustar00rootroot000000000000009core-0.8/debian/control000066400000000000000000000036621417504024300151450ustar00rootroot00000000000000Source: cutefish-core Section: devel Priority: optional Maintainer: CutefishOS Build-Depends: cmake, debhelper (>= 9), extra-cmake-modules, pkg-config, xserver-xorg-input-libinput-dev, libx11-xcb-dev, libxcb1-dev, libxcb-randr0-dev, libxcb-keysyms1-dev, libxcursor-dev, libxcb-xfixes0-dev, libxcb-damage0-dev, libxcb-composite0-dev, libxcb-shm0-dev, libxcb-util-dev, libxcb-image0-dev, libxcb-dpms0-dev, libxcb-dri2-0-dev, libxcb-dri3-dev, libxcb-ewmh-dev, libxcb-glx0-dev, libxcb-record0-dev, xserver-xorg-dev, xserver-xorg-input-synaptics-dev, libxtst-dev, libsm-dev, libpolkit-qt5-1-dev, libpolkit-agent-1-dev, libkf5windowsystem-dev, libkf5globalaccel-dev, libkf5coreaddons-dev, libkf5idletime-dev, libqt5x11extras5-dev, qtbase5-dev, qtdeclarative5-dev, qtquickcontrols2-5-dev, qttools5-dev, qttools5-dev-tools Standards-Version: 4.5.0 Homepage: https://github.com/cutefishos/core Package: cutefish-core Architecture: any Depends: accountsservice, qml-module-qtquick-controls2, qml-module-qtquick2, qml-module-qtquick-layouts, qml-module-qt-labs-platform, qml-module-qt-labs-settings, qml-module-qtqml, qml-module-qtquick-window2, qml-module-qtquick-shapes, appmenu-gtk2-module, appmenu-gtk3-module, ${misc:Depends}, ${shlibs:Depends} Description: CutefishOS System Components core-0.8/debian/copyright000066400000000000000000000001761417504024300154720ustar00rootroot00000000000000Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Upstream-Name: cutefish-core Source: cutefishos.com core-0.8/debian/postinst000066400000000000000000000017561417504024300153520ustar00rootroot00000000000000#! /bin/sh # see: dh_installdeb(1) set -e # summary of how this script can be called: # * `configure' # * `abort-upgrade' # * `abort-remove' `in-favour' # # * `abort-deconfigure' `in-favour' # `removing' # # for details, see http://www.debian.org/doc/debian-policy/ or # the debian-policy package # case "$1" in configure) update-alternatives --install /usr/bin/x-session-manager \ x-session-manager /usr/bin/cutefish-session 60 ;; abort-upgrade|abort-remove|abort-deconfigure) ;; *) echo "postinst called with unknown argument \`$1'" >&2 exit 1 ;; esac # dh_installdeb will replace this with shell code automatically # generated by other debhelper scripts. #DEBHELPER# exit 0 core-0.8/debian/prerm000066400000000000000000000016611417504024300146070ustar00rootroot00000000000000#! /bin/sh # # see: dh_installdeb(1) set -e # summary of how this script can be called: # * `remove' # * `upgrade' # * `failed-upgrade' # * `remove' `in-favour' # * `deconfigure' `in-favour' # `removing' # # for details, see http://www.debian.org/doc/debian-policy/ or # the debian-policy package case "$1" in remove) update-alternatives --remove x-session-manager /usr/bin/cutefish-session ;; upgrade|deconfigure) ;; failed-upgrade) ;; *) echo "prerm called with unknown argument \`$1'" >&2 exit 1 ;; esac # dh_installdeb will replace this with shell code automatically # generated by other debhelper scripts. #DEBHELPER# exit 0 core-0.8/debian/rules000077500000000000000000000000511417504024300146070ustar00rootroot00000000000000#!/usr/bin/make -f %: dh $@ --parallel core-0.8/debian/source/000077500000000000000000000000001417504024300150335ustar00rootroot00000000000000core-0.8/debian/source/format000066400000000000000000000000141417504024300162410ustar00rootroot000000000000003.0 (quilt) core-0.8/gmenuproxy/000077500000000000000000000000001417504024300145265ustar00rootroot00000000000000core-0.8/gmenuproxy/CMakeLists.txt000066400000000000000000000023151417504024300172670ustar00rootroot00000000000000find_package(AppMenuGtkModule) find_package(KF5WindowSystem) find_package(KF5CoreAddons) set_package_properties(AppMenuGtkModule PROPERTIES TYPE RUNTIME) add_definitions(-DQT_NO_CAST_TO_ASCII -DQT_NO_CAST_FROM_ASCII -DQT_NO_CAST_FROM_BYTEARRAY) find_package(XCB REQUIRED COMPONENTS XCB ) set(GMENU_DBUSMENU_PROXY_SRCS extend/dbusmenutypes_p.cpp # extend/dbusmenushortcut_p.cpp main.cpp menuproxy.cpp window.cpp menu.cpp actions.cpp dbusmenuadaptor.cpp gdbusmenutypes_p.cpp icons.cpp utils.cpp ) # qt_add_dbus_adaptor(GMENU_DBUSMENU_PROXY_SRCS ./com.canonical.dbusmenu.xml window.h Window) add_executable(cutefish-gmenuproxy ${GMENU_DBUSMENU_PROXY_SRCS}) set_package_properties(XCB PROPERTIES TYPE REQUIRED) target_link_libraries(cutefish-gmenuproxy Qt5::Core Qt5::X11Extras Qt5::DBus Qt5::Widgets KF5::CoreAddons KF5::WindowSystem XCB::XCB ) configure_file( cutefish-gmenuproxy.service.in cutefish-gmenuproxy.service @ONLY ) install(TARGETS cutefish-gmenuproxy DESTINATION ${CMAKE_INSTALL_BINDIR}) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/cutefish-gmenuproxy.service DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/systemd/user/) core-0.8/gmenuproxy/actions.cpp000066400000000000000000000156071417504024300167030ustar00rootroot00000000000000/* SPDX-FileCopyrightText: 2018 Kai Uwe Broulik SPDX-License-Identifier: LGPL-2.1-or-later */ #include "actions.h" #include #include #include #include #include #include #include static const QString s_orgGtkActions = QStringLiteral("org.gtk.Actions"); Actions::Actions(const QString &serviceName, const QString &objectPath, QObject *parent) : QObject(parent) , m_serviceName(serviceName) , m_objectPath(objectPath) { Q_ASSERT(!serviceName.isEmpty()); Q_ASSERT(!m_objectPath.isEmpty()); if (!QDBusConnection::sessionBus().connect(serviceName, objectPath, s_orgGtkActions, QStringLiteral("Changed"), this, SLOT(onActionsChanged(QStringList, StringBoolMap, QVariantMap, GMenuActionMap)))) { qDebug() << "Failed to subscribe to action changes for" << parent << "on" << serviceName << "at" << objectPath; } } Actions::~Actions() = default; void Actions::load() { QDBusMessage msg = QDBusMessage::createMethodCall(m_serviceName, m_objectPath, s_orgGtkActions, QStringLiteral("DescribeAll")); QDBusPendingReply reply = QDBusConnection::sessionBus().asyncCall(msg); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this); connect(watcher, &QDBusPendingCallWatcher::finished, this, [this](QDBusPendingCallWatcher *watcher) { QDBusPendingReply reply = *watcher; if (reply.isError()) { qDebug() << "Failed to get actions from" << m_serviceName << "at" << m_objectPath << reply.error(); emit failedToLoad(); } else { m_actions = reply.value(); emit loaded(); } watcher->deleteLater(); }); } bool Actions::get(const QString &name, GMenuAction &action) const { auto it = m_actions.find(name); if (it == m_actions.constEnd()) { return false; } action = *it; return true; } GMenuActionMap Actions::getAll() const { return m_actions; } void Actions::trigger(const QString &name, const QVariant &target, uint timestamp) { if (!m_actions.contains(name)) { qDebug() << "Cannot invoke action" << name << "which doesn't exist"; return; } QDBusMessage msg = QDBusMessage::createMethodCall(m_serviceName, m_objectPath, s_orgGtkActions, QStringLiteral("Activate")); msg << name; QVariantList args; if (target.isValid()) { args << target; } msg << QVariant::fromValue(args); QVariantMap platformData; if (timestamp) { // From documentation: // If the startup notification id is not available, this can be just "_TIMEtime", where // time is the time stamp from the event triggering the call. // see also gtkwindow.c extract_time_from_startup_id and startup_id_is_fake platformData.insert(QStringLiteral("desktop-startup-id"), QStringLiteral("_TIME") + QString::number(timestamp)); } msg << platformData; QDBusPendingReply reply = QDBusConnection::sessionBus().asyncCall(msg); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this); connect(watcher, &QDBusPendingCallWatcher::finished, this, [this, name](QDBusPendingCallWatcher *watcher) { QDBusPendingReply reply = *watcher; if (reply.isError()) { qDebug() << "Failed to invoke action" << name << "on" << m_serviceName << "at" << m_objectPath << reply.error(); } watcher->deleteLater(); }); } bool Actions::isValid() const { return !m_actions.isEmpty(); } void Actions::onActionsChanged(const QStringList &removed, const StringBoolMap &enabledChanges, const QVariantMap &stateChanges, const GMenuActionMap &added) { // Collect the actions that we removed, altered, or added, so we can eventually signal changes for all menus that contain one of those actions QStringList dirtyActions; // TODO I bet for most of the loops below we could use a nice short std algorithm for (const QString &removedAction : removed) { if (m_actions.remove(removedAction)) { dirtyActions.append(removedAction); } } for (auto it = enabledChanges.constBegin(), end = enabledChanges.constEnd(); it != end; ++it) { const QString &actionName = it.key(); const bool enabled = it.value(); auto actionIt = m_actions.find(actionName); if (actionIt == m_actions.end()) { qDebug() << "Got enabled changed for action" << actionName << "which we don't know"; continue; } GMenuAction &action = *actionIt; if (action.enabled != enabled) { action.enabled = enabled; dirtyActions.append(actionName); } else { qDebug() << "Got enabled change for action" << actionName << "which didn't change it"; } } for (auto it = stateChanges.constBegin(), end = stateChanges.constEnd(); it != end; ++it) { const QString &actionName = it.key(); const QVariant &state = it.value(); auto actionIt = m_actions.find(actionName); if (actionIt == m_actions.end()) { qDebug() << "Got state changed for action" << actionName << "which we don't know"; continue; } GMenuAction &action = *actionIt; if (action.state.isEmpty()) { qDebug() << "Got new state for action" << actionName << "that didn't have any state before"; action.state.append(state); dirtyActions.append(actionName); } else { // Action state is a list but the state change only sends us a single variant, so just overwrite the first one QVariant &firstState = action.state.first(); if (firstState != state) { firstState = state; dirtyActions.append(actionName); } else { qDebug() << "Got state change for action" << actionName << "which didn't change it"; } } } // unite() will result in keys being present multiple times, do it manually and overwrite existing ones for (auto it = added.constBegin(), end = added.constEnd(); it != end; ++it) { const QString &actionName = it.key(); // if ((DBUSMENUPROXY).isInfoEnabled()) { // if (m_actions.contains(actionName)) { // qDebug() << "Got new action" << actionName << "that we already have, overwriting existing one"; // } // } m_actions.insert(actionName, it.value()); dirtyActions.append(actionName); } if (!dirtyActions.isEmpty()) { emit actionsChanged(dirtyActions); } } core-0.8/gmenuproxy/actions.h000066400000000000000000000020421417504024300163350ustar00rootroot00000000000000/* SPDX-FileCopyrightText: 2018 Kai Uwe Broulik SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once #include #include #include "gdbusmenutypes_p.h" class QStringList; class Actions : public QObject { Q_OBJECT public: Actions(const QString &serviceName, const QString &objectPath, QObject *parent = nullptr); ~Actions() override; void load(); bool get(const QString &name, GMenuAction &action) const; GMenuActionMap getAll() const; void trigger(const QString &name, const QVariant &target, uint timestamp = 0); bool isValid() const; // basically "has actions" Q_SIGNALS: void loaded(); void failedToLoad(); // expose error? void actionsChanged(const QStringList &dirtyActions); private slots: void onActionsChanged(const QStringList &removed, const StringBoolMap &enabledChanges, const QVariantMap &stateChanges, const GMenuActionMap &added); private: GMenuActionMap m_actions; QString m_serviceName; QString m_objectPath; }; core-0.8/gmenuproxy/com.canonical.dbusmenu.xml000066400000000000000000000041711417504024300216000ustar00rootroot00000000000000 core-0.8/gmenuproxy/cutefish-gmenuproxy.service.in000066400000000000000000000003631417504024300225440ustar00rootroot00000000000000[Unit] Description=Proxies GTK DBus menus to a Cutefish readable format PartOf=graphical-session.target [Service] ExecStart=@CMAKE_INSTALL_FULL_BINDIR@/cutefish-gmenuproxy Restart=on-failure Type=simple Slice=background.slice TimeoutSec=5sec core-0.8/gmenuproxy/dbusmenuadaptor.cpp000066400000000000000000000042631417504024300204340ustar00rootroot00000000000000/* * This file was generated by qdbusxml2cpp version 0.8 * Command line was: qdbusxml2cpp -m -a dbusmenuadaptor -i window.h -l Window /home/reion/Cutefish/core/gmenuproxy/com.canonical.dbusmenu.xml * * qdbusxml2cpp is Copyright (C) 2020 The Qt Company Ltd. * * This is an auto-generated file. * Do not edit! All changes made to it will be lost. */ #include "dbusmenuadaptor.h" #include #include #include #include #include #include #include /* * Implementation of adaptor class DbusmenuAdaptor */ DbusmenuAdaptor::DbusmenuAdaptor(Window *parent) : QDBusAbstractAdaptor(parent) { // constructor setAutoRelaySignals(true); } DbusmenuAdaptor::~DbusmenuAdaptor() { // destructor } QString DbusmenuAdaptor::status() const { // get the value of property Status return qvariant_cast< QString >(parent()->property("Status")); } uint DbusmenuAdaptor::version() const { // get the value of property Version return qvariant_cast< uint >(parent()->property("Version")); } bool DbusmenuAdaptor::AboutToShow(int id) { // handle method call com.canonical.dbusmenu.AboutToShow return parent()->AboutToShow(id); } void DbusmenuAdaptor::Event(int id, const QString &eventId, const QDBusVariant &data, uint timestamp) { // handle method call com.canonical.dbusmenu.Event parent()->Event(id, eventId, data, timestamp); } DBusMenuItemList DbusmenuAdaptor::GetGroupProperties(const QList &ids, const QStringList &propertyNames) { // handle method call com.canonical.dbusmenu.GetGroupProperties return parent()->GetGroupProperties(ids, propertyNames); } uint DbusmenuAdaptor::GetLayout(int parentId, int recursionDepth, const QStringList &propertyNames, DBusMenuLayoutItem &item) { // handle method call com.canonical.dbusmenu.GetLayout return parent()->GetLayout(parentId, recursionDepth, propertyNames, item); } QDBusVariant DbusmenuAdaptor::GetProperty(int id, const QString &property) { // handle method call com.canonical.dbusmenu.GetProperty return parent()->GetProperty(id, property); } #include "dbusmenuadaptor.moc" core-0.8/gmenuproxy/dbusmenuadaptor.h000066400000000000000000000107001417504024300200720ustar00rootroot00000000000000/* * This file was generated by qdbusxml2cpp version 0.8 * Command line was: qdbusxml2cpp -m -a dbusmenuadaptor -i window.h -l Window /home/reion/Cutefish/core/gmenuproxy/com.canonical.dbusmenu.xml * * qdbusxml2cpp is Copyright (C) 2020 The Qt Company Ltd. * * This is an auto-generated file. * This file may have been hand-edited. Look for HAND-EDIT comments * before re-generating it. */ #ifndef DBUSMENUADAPTOR_H #define DBUSMENUADAPTOR_H #include #include #include "window.h" QT_BEGIN_NAMESPACE class QByteArray; template class QList; template class QMap; class QString; class QStringList; class QVariant; QT_END_NAMESPACE /* * Adaptor class for interface com.canonical.dbusmenu */ class DbusmenuAdaptor: public QDBusAbstractAdaptor { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "com.canonical.dbusmenu") Q_CLASSINFO("D-Bus Introspection", "" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" "") public: DbusmenuAdaptor(Window *parent); virtual ~DbusmenuAdaptor(); inline Window *parent() const { return static_cast(QObject::parent()); } public: // PROPERTIES Q_PROPERTY(QString Status READ status) QString status() const; Q_PROPERTY(uint Version READ version) uint version() const; public Q_SLOTS: // METHODS bool AboutToShow(int id); Q_NOREPLY void Event(int id, const QString &eventId, const QDBusVariant &data, uint timestamp); DBusMenuItemList GetGroupProperties(const QList &ids, const QStringList &propertyNames); uint GetLayout(int parentId, int recursionDepth, const QStringList &propertyNames, DBusMenuLayoutItem &item); QDBusVariant GetProperty(int id, const QString &property); Q_SIGNALS: // SIGNALS void ItemActivationRequested(int id, uint timeStamp); void ItemsPropertiesUpdated(DBusMenuItemList in0, DBusMenuItemKeysList in1); void LayoutUpdated(uint revision, int parentId); }; #endif core-0.8/gmenuproxy/extend/000077500000000000000000000000001417504024300160155ustar00rootroot00000000000000core-0.8/gmenuproxy/extend/dbusmenushortcut_p.cpp000066400000000000000000000046061417504024300224640ustar00rootroot00000000000000/* This file is part of the dbusmenu-qt library SPDX-FileCopyrightText: 2009 Canonical SPDX-FileContributor: Aurelien Gateau SPDX-License-Identifier: LGPL-2.0-or-later */ #include "dbusmenushortcut_p.h" // Qt #include static const int QT_COLUMN = 0; static const int DM_COLUMN = 1; static void processKeyTokens(QStringList *tokens, int srcCol, int dstCol) { struct Row { const char *zero; const char *one; const char *operator[](int col) const { return col == 0 ? zero : one; } }; static const Row table[] = {{"Meta", "Super"}, {"Ctrl", "Control"}, // Special cases for compatibility with libdbusmenu-glib which uses // "plus" for "+" and "minus" for "-". // cf https://bugs.launchpad.net/libdbusmenu-qt/+bug/712565 {"+", "plus"}, {"-", "minus"}, {nullptr, nullptr}}; const Row *ptr = table; for (; ptr->zero != nullptr; ++ptr) { const char *from = (*ptr)[srcCol]; const char *to = (*ptr)[dstCol]; tokens->replaceInStrings(from, to); } } DBusMenuShortcut DBusMenuShortcut::fromKeySequence(const QKeySequence &sequence) { QString string = sequence.toString(); DBusMenuShortcut shortcut; QStringList tokens = string.split(QStringLiteral(", ")); Q_FOREACH (QString token, tokens) { // Hack: Qt::CTRL | Qt::Key_Plus is turned into the string "Ctrl++", // but we don't want the call to token.split() to consider the // second '+' as a separator so we replace it with its final value. token.replace(QLatin1String("++"), QLatin1String("+plus")); QStringList keyTokens = token.split('+'); processKeyTokens(&keyTokens, QT_COLUMN, DM_COLUMN); shortcut << keyTokens; } return shortcut; } QKeySequence DBusMenuShortcut::toKeySequence() const { QStringList tmp; Q_FOREACH (const QStringList &keyTokens_, *this) { QStringList keyTokens = keyTokens_; processKeyTokens(&keyTokens, DM_COLUMN, QT_COLUMN); tmp << keyTokens.join(QLatin1String("+")); } QString string = tmp.join(QLatin1String(", ")); return QKeySequence::fromString(string); } core-0.8/gmenuproxy/extend/dbusmenushortcut_p.h000066400000000000000000000007771417504024300221360ustar00rootroot00000000000000/* This file is part of the dbusmenu-qt library SPDX-FileCopyrightText: 2009 Canonical SPDX-FileContributor: Aurelien Gateau SPDX-License-Identifier: LGPL-2.0-or-later */ #pragma once // Qt #include #include class QKeySequence; class DBusMenuShortcut : public QList { public: QKeySequence toKeySequence() const; static DBusMenuShortcut fromKeySequence(const QKeySequence &); }; Q_DECLARE_METATYPE(DBusMenuShortcut) core-0.8/gmenuproxy/extend/dbusmenutypes_p.cpp000066400000000000000000000065321417504024300217550ustar00rootroot00000000000000/* This file is part of the dbusmenu-qt library SPDX-FileCopyrightText: 2009 Canonical SPDX-FileContributor: Aurelien Gateau SPDX-License-Identifier: LGPL-2.0-or-later */ #include "dbusmenutypes_p.h" // Local #include "dbusmenushortcut_p.h" // Qt #include #include //// DBusMenuItem QDBusArgument &operator<<(QDBusArgument &argument, const DBusMenuItem &obj) { argument.beginStructure(); argument << obj.id << obj.properties; argument.endStructure(); return argument; } const QDBusArgument &operator>>(const QDBusArgument &argument, DBusMenuItem &obj) { argument.beginStructure(); argument >> obj.id >> obj.properties; argument.endStructure(); return argument; } //// DBusMenuItemKeys QDBusArgument &operator<<(QDBusArgument &argument, const DBusMenuItemKeys &obj) { argument.beginStructure(); argument << obj.id << obj.properties; argument.endStructure(); return argument; } const QDBusArgument &operator>>(const QDBusArgument &argument, DBusMenuItemKeys &obj) { argument.beginStructure(); argument >> obj.id >> obj.properties; argument.endStructure(); return argument; } //// DBusMenuLayoutItem QDBusArgument &operator<<(QDBusArgument &argument, const DBusMenuLayoutItem &obj) { argument.beginStructure(); argument << obj.id << obj.properties; argument.beginArray(qMetaTypeId()); Q_FOREACH (const DBusMenuLayoutItem &child, obj.children) { argument << QDBusVariant(QVariant::fromValue(child)); } argument.endArray(); argument.endStructure(); return argument; } const QDBusArgument &operator>>(const QDBusArgument &argument, DBusMenuLayoutItem &obj) { argument.beginStructure(); argument >> obj.id >> obj.properties; argument.beginArray(); while (!argument.atEnd()) { QDBusVariant dbusVariant; argument >> dbusVariant; QDBusArgument childArgument = dbusVariant.variant().value(); DBusMenuLayoutItem child; childArgument >> child; obj.children.append(child); } argument.endArray(); argument.endStructure(); return argument; } //// DBusMenuShortcut QDBusArgument &operator<<(QDBusArgument &argument, const DBusMenuShortcut &obj) { argument.beginArray(qMetaTypeId()); typename QList::ConstIterator it = obj.constBegin(); typename QList::ConstIterator end = obj.constEnd(); for (; it != end; ++it) argument << *it; argument.endArray(); return argument; } const QDBusArgument &operator>>(const QDBusArgument &argument, DBusMenuShortcut &obj) { argument.beginArray(); obj.clear(); while (!argument.atEnd()) { QStringList item; argument >> item; obj.push_back(item); } argument.endArray(); return argument; } void DBusMenuTypes_register() { static bool registered = false; if (registered) { return; } qDBusRegisterMetaType(); qDBusRegisterMetaType(); qDBusRegisterMetaType(); qDBusRegisterMetaType(); qDBusRegisterMetaType(); qDBusRegisterMetaType(); qDBusRegisterMetaType(); registered = true; } core-0.8/gmenuproxy/extend/dbusmenutypes_p.h000066400000000000000000000037131417504024300214200ustar00rootroot00000000000000/* This file is part of the dbusmenu-qt library SPDX-FileCopyrightText: 2009 Canonical SPDX-FileContributor: Aurelien Gateau SPDX-License-Identifier: LGPL-2.0-or-later */ #pragma once // Qt #include #include #include class QDBusArgument; //// DBusMenuItem /** * Internal struct used to communicate on DBus */ struct DBusMenuItem { int id; QVariantMap properties; }; Q_DECLARE_METATYPE(DBusMenuItem) QDBusArgument &operator<<(QDBusArgument &argument, const DBusMenuItem &item); const QDBusArgument &operator>>(const QDBusArgument &argument, DBusMenuItem &item); typedef QList DBusMenuItemList; Q_DECLARE_METATYPE(DBusMenuItemList) //// DBusMenuItemKeys /** * Represents a list of keys for a menu item */ struct DBusMenuItemKeys { int id; QStringList properties; }; Q_DECLARE_METATYPE(DBusMenuItemKeys) QDBusArgument &operator<<(QDBusArgument &argument, const DBusMenuItemKeys &); const QDBusArgument &operator>>(const QDBusArgument &argument, DBusMenuItemKeys &); typedef QList DBusMenuItemKeysList; Q_DECLARE_METATYPE(DBusMenuItemKeysList) //// DBusMenuLayoutItem /** * Represents an item with its children. GetLayout() returns a * DBusMenuLayoutItemList. */ struct DBusMenuLayoutItem; struct DBusMenuLayoutItem { int id; QVariantMap properties; QList children; }; Q_DECLARE_METATYPE(DBusMenuLayoutItem) QDBusArgument &operator<<(QDBusArgument &argument, const DBusMenuLayoutItem &); const QDBusArgument &operator>>(const QDBusArgument &argument, DBusMenuLayoutItem &); typedef QList DBusMenuLayoutItemList; Q_DECLARE_METATYPE(DBusMenuLayoutItemList) //// DBusMenuShortcut class DBusMenuShortcut; QDBusArgument &operator<<(QDBusArgument &argument, const DBusMenuShortcut &); const QDBusArgument &operator>>(const QDBusArgument &argument, DBusMenuShortcut &); void DBusMenuTypes_register();core-0.8/gmenuproxy/gdbusmenutypes_p.cpp000066400000000000000000000062561417504024300206400ustar00rootroot00000000000000/* SPDX-FileCopyrightText: 2018 Kai Uwe Broulik SPDX-License-Identifier: LGPL-2.1-or-later */ #include "gdbusmenutypes_p.h" #include #include // GMenuItem QDBusArgument &operator<<(QDBusArgument &argument, const GMenuItem &item) { argument.beginStructure(); argument << item.id << item.section << item.items; argument.endStructure(); return argument; } const QDBusArgument &operator>>(const QDBusArgument &argument, GMenuItem &item) { argument.beginStructure(); argument >> item.id >> item.section >> item.items; argument.endStructure(); return argument; } // GMenuSection QDBusArgument &operator<<(QDBusArgument &argument, const GMenuSection &item) { argument.beginStructure(); argument << item.subscription << item.menu; argument.endStructure(); return argument; } const QDBusArgument &operator>>(const QDBusArgument &argument, GMenuSection &item) { argument.beginStructure(); argument >> item.subscription >> item.menu; argument.endStructure(); return argument; } // GMenuChange QDBusArgument &operator<<(QDBusArgument &argument, const GMenuChange &item) { argument.beginStructure(); argument << item.subscription << item.menu << item.changePosition << item.itemsToRemoveCount << item.itemsToInsert; argument.endStructure(); return argument; } const QDBusArgument &operator>>(const QDBusArgument &argument, GMenuChange &item) { argument.beginStructure(); argument >> item.subscription >> item.menu >> item.changePosition >> item.itemsToRemoveCount >> item.itemsToInsert; argument.endStructure(); return argument; } // GMenuActionProperty QDBusArgument &operator<<(QDBusArgument &argument, const GMenuAction &item) { argument.beginStructure(); argument << item.enabled << item.signature << item.state; argument.endStructure(); return argument; } const QDBusArgument &operator>>(const QDBusArgument &argument, GMenuAction &item) { argument.beginStructure(); argument >> item.enabled >> item.signature >> item.state; argument.endStructure(); return argument; } // GMenuActionsChange QDBusArgument &operator<<(QDBusArgument &argument, const GMenuActionsChange &item) { argument.beginStructure(); argument << item.removed << item.enabledChanged << item.stateChanged << item.added; argument.endStructure(); return argument; } const QDBusArgument &operator>>(const QDBusArgument &argument, GMenuActionsChange &item) { argument.beginStructure(); argument >> item.removed >> item.enabledChanged >> item.stateChanged >> item.added; argument.endStructure(); return argument; } void GDBusMenuTypes_register() { static bool registered = false; if (registered) { return; } qDBusRegisterMetaType(); qDBusRegisterMetaType(); qDBusRegisterMetaType(); qDBusRegisterMetaType(); qDBusRegisterMetaType(); qDBusRegisterMetaType(); qDBusRegisterMetaType(); qDBusRegisterMetaType(); qDBusRegisterMetaType(); registered = true; } core-0.8/gmenuproxy/gdbusmenutypes_p.h000066400000000000000000000045441417504024300203030ustar00rootroot00000000000000/* SPDX-FileCopyrightText: 2018 Kai Uwe Broulik SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once #include #include #include #include class QDBusArgument; // Various using VariantMapList = QList; Q_DECLARE_METATYPE(VariantMapList); using StringBoolMap = QMap; Q_DECLARE_METATYPE(StringBoolMap); // Menu item itself (Start method) struct GMenuItem { uint id; uint section; VariantMapList items; }; Q_DECLARE_METATYPE(GMenuItem); QDBusArgument &operator<<(QDBusArgument &argument, const GMenuItem &item); const QDBusArgument &operator>>(const QDBusArgument &argument, GMenuItem &item); using GMenuItemList = QList; Q_DECLARE_METATYPE(GMenuItemList); // Information about what section or submenu to use for a particular entry struct GMenuSection { uint subscription; uint menu; }; Q_DECLARE_METATYPE(GMenuSection); QDBusArgument &operator<<(QDBusArgument &argument, const GMenuSection &item); const QDBusArgument &operator>>(const QDBusArgument &argument, GMenuSection &item); // Changes of a menu item (Changed signal) struct GMenuChange { uint subscription; uint menu; uint changePosition; uint itemsToRemoveCount; VariantMapList itemsToInsert; }; Q_DECLARE_METATYPE(GMenuChange); QDBusArgument &operator<<(QDBusArgument &argument, const GMenuChange &item); const QDBusArgument &operator>>(const QDBusArgument &argument, GMenuChange &item); using GMenuChangeList = QList; Q_DECLARE_METATYPE(GMenuChangeList); // An application action struct GMenuAction { bool enabled; QDBusSignature signature; QVariantList state; }; Q_DECLARE_METATYPE(GMenuAction); QDBusArgument &operator<<(QDBusArgument &argument, const GMenuAction &item); const QDBusArgument &operator>>(const QDBusArgument &argument, GMenuAction &item); using GMenuActionMap = QMap; Q_DECLARE_METATYPE(GMenuActionMap); struct GMenuActionsChange { QStringList removed; QMap enabledChanged; QVariantMap stateChanged; GMenuActionMap added; }; Q_DECLARE_METATYPE(GMenuActionsChange); QDBusArgument &operator<<(QDBusArgument &argument, const GMenuActionsChange &item); const QDBusArgument &operator>>(const QDBusArgument &argument, GMenuActionsChange &item); void GDBusMenuTypes_register(); core-0.8/gmenuproxy/gmenudbusmenuproxy.desktop000066400000000000000000000027661417504024300221140ustar00rootroot00000000000000[Desktop Entry] Exec=gmenudbusmenuproxy Name=GMenuDBusMenuProxy Name[ar]=وكيل قائمة D-Bus لـ GMenu. Name[ast]=GMenuDBusMenuProxy Name[az]=GMenuDBusMenuProxy Name[ca]=GMenuDBusMenuProxy Name[ca@valencia]=GMenuDBusMenuProxy Name[da]=GMenuDBusMenuProxy Name[de]=GMenuDBusMenuProxy Name[el]=GMenuDBusMenuProxy Name[en_GB]=GMenuDBusMenuProxy Name[es]=GMenuDBusMenuProxy Name[et]=GMenuDBusMenuProxy Name[eu]=GMenuDBusMenuProxy Name[fi]=GMenuDBusMenuProxy Name[fr]=GMenuDBusMenuProxy Name[gl]=Proxy de menú por D-Bus para GMenu. Name[hi]=जीमेन्यूडीबसमेन्यूप्रॉक्सी Name[hu]=GMenuDBusMenuProxy Name[ia]=GMenuDBusMenuProxy Name[id]=GMenuDBusMenuProxy Name[it]=GMenuDBusMenuProxy Name[ko]=GMenuDBusMenuProxy Name[lt]=GMenuDBusMenuProxy Name[ml]=ജിമെനുഡിബസ്‍മെനുപ്രോക്സി Name[nl]=GMenuDBusMenuProxy Name[nn]=GMenuDBusMenuProxy Name[pa]=GMenuDBusMenuProxy Name[pl]=GMenuDBusMenuProxy Name[pt]=GMenuDBusMenuProxy Name[pt_BR]=GMenuDBusMenuProxy Name[ro]=GMenuDBusMenuProxy Name[ru]=GMenuDBusMenuProxy Name[sk]=GMenuDBusMenuProxy Name[sl]=GMenuDBusMenuProxy Name[sv]=GMenuDBusMenuProxy Name[ta]=GMenuDBusMenuProxy Name[tr]=GMenuDBusMenuProxy Name[uk]=Проксі-меню GMenu D-Bus Name[vi]=GMenuDBusMenuProxy Name[x-test]=xxGMenuDBusMenuProxyxx Name[zh_CN]=GMenuDBusMenuProxy Name[zh_TW]=GMenuDBusMenuProxy Type=Application X-KDE-StartupNotify=false NoDisplay=true OnlyShowIn=KDE; X-KDE-autostart-phase=1 X-systemd-skip=true core-0.8/gmenuproxy/icons.cpp000066400000000000000000000370001417504024300163450ustar00rootroot00000000000000/* SPDX-FileCopyrightText: 2018 Kai Uwe Broulik SPDX-License-Identifier: LGPL-2.1-or-later */ #include "icons.h" #include #include QString Icons::actionIcon(const QString &actionName) { QString icon; QString action = actionName; if (action.isEmpty()) { return icon; } static const QHash s_icons{ {QStringLiteral("new"), QStringLiteral("document-new")}, // appmenu-gtk-module "New" {QStringLiteral("image-new"), QStringLiteral("document-new")}, // Gimp "New" item {QStringLiteral("adddirect"), QStringLiteral("document-new")}, // LibreOffice "New" item {QStringLiteral("filenew"), QStringLiteral("document-new")}, // Pluma "New" item {QStringLiteral("new-window"), QStringLiteral("window-new")}, {QStringLiteral("newwindow"), QStringLiteral("window-new")}, {QStringLiteral("yelp-window-new"), QStringLiteral("window-new")}, // Gnome help {QStringLiteral("new-tab"), QStringLiteral("tab-new")}, {QStringLiteral("open"), QStringLiteral("document-open")}, {QStringLiteral("open-location"), QStringLiteral("document-open-remote")}, {QStringLiteral("openremote"), QStringLiteral("document-open-remote")}, {QStringLiteral("save"), QStringLiteral("document-save")}, {QStringLiteral("save-as"), QStringLiteral("document-save-as")}, {QStringLiteral("saveas"), QStringLiteral("document-save-as")}, {QStringLiteral("save-all"), QStringLiteral("document-save-all")}, {QStringLiteral("saveall"), QStringLiteral("document-save-all")}, {QStringLiteral("import"), QStringLiteral("document-import")}, {QStringLiteral("export"), QStringLiteral("document-export")}, {QStringLiteral("exportto"), QStringLiteral("document-export")}, // LibreOffice {QStringLiteral("exporttopdf"), QStringLiteral("viewpdf")}, // LibreOffice, the icon it uses but the name is quite random {QStringLiteral("webhtml"), QStringLiteral("text-html")}, // LibreOffice {QStringLiteral("printpreview"), QStringLiteral("document-print-preview")}, {QStringLiteral("print-preview"), QStringLiteral("document-print-preview")}, {QStringLiteral("print"), QStringLiteral("document-print")}, {QStringLiteral("print-gtk"), QStringLiteral("document-print")}, // Gimp {QStringLiteral("mail-image"), QStringLiteral("mail-message-new")}, // Gimp {QStringLiteral("sendmail"), QStringLiteral("mail-message-new")}, // LibreOffice {QStringLiteral("sendviabluetooth"), QStringLiteral("preferences-system-bluetooth")}, // LibreOffice {QStringLiteral("sendviabluetooth"), QStringLiteral("preferences-system-bluetooth")}, // LibreOffice {QStringLiteral("document-properties"), QStringLiteral("document-properties")}, {QStringLiteral("close"), QStringLiteral("document-close")}, // appmenu-gtk-module "Close" {QStringLiteral("closedoc"), QStringLiteral("document-close")}, {QStringLiteral("close-all"), QStringLiteral("document-close")}, {QStringLiteral("closeall"), QStringLiteral("document-close")}, {QStringLiteral("closewin"), QStringLiteral("window-close")}, // LibreOffice {QStringLiteral("quit"), QStringLiteral("application-exit")}, {QStringLiteral("undo"), QStringLiteral("edit-undo")}, {QStringLiteral("redo"), QStringLiteral("edit-redo")}, {QStringLiteral("revert"), QStringLiteral("document-revert")}, {QStringLiteral("cut"), QStringLiteral("edit-cut")}, {QStringLiteral("copy"), QStringLiteral("edit-copy")}, {QStringLiteral("paste"), QStringLiteral("edit-paste")}, {QStringLiteral("duplicate"), QStringLiteral("edit-duplicate")}, {QStringLiteral("preferences"), QStringLiteral("settings-configure")}, {QStringLiteral("optionstreedialog"), QStringLiteral("settings-configure")}, // LibreOffice {QStringLiteral("keyboard-shortcuts"), QStringLiteral("configure-shortcuts")}, {QStringLiteral("fullscreen"), QStringLiteral("view-fullscreen")}, {QStringLiteral("find"), QStringLiteral("edit-find")}, {QStringLiteral("searchfind"), QStringLiteral("edit-find")}, {QStringLiteral("replace"), QStringLiteral("edit-find-replace")}, {QStringLiteral("searchreplace"), QStringLiteral("edit-find-replace")}, // LibreOffice {QStringLiteral("searchdialog"), QStringLiteral("edit-find-replace")}, // LibreOffice {QStringLiteral("find-replace"), QStringLiteral("edit-find-replace")}, // Inkscape {QStringLiteral("select-all"), QStringLiteral("edit-select-all")}, {QStringLiteral("selectall"), QStringLiteral("edit-select-all")}, {QStringLiteral("select-none"), QStringLiteral("edit-select-invert")}, {QStringLiteral("select-invert"), QStringLiteral("edit-select-invert")}, {QStringLiteral("invert-selection"), QStringLiteral("edit-select-invert")}, // Inkscape {QStringLiteral("check-spelling"), QStringLiteral("tools-check-spelling")}, {QStringLiteral("set-language"), QStringLiteral("set-language")}, {QStringLiteral("increasesize"), QStringLiteral("zoom-in")}, {QStringLiteral("decreasesize"), QStringLiteral("zoom-out")}, {QStringLiteral("zoom-in"), QStringLiteral("zoom-in")}, {QStringLiteral("zoom-out"), QStringLiteral("zoom-out")}, {QStringLiteral("zoomfit"), QStringLiteral("zoom-fit-best")}, {QStringLiteral("zoom-fit-in"), QStringLiteral("zoom-fit-best")}, {QStringLiteral("show-guides"), QStringLiteral("show-guides")}, {QStringLiteral("show-grid"), QStringLiteral("show-grid")}, {QStringLiteral("rotateclockwise"), QStringLiteral("object-rotate-right")}, {QStringLiteral("rotatecounterclockwise"), QStringLiteral("object-rotate-left")}, {QStringLiteral("fliphorizontally"), QStringLiteral("object-flip-horizontal")}, {QStringLiteral("image-flip-horizontal"), QStringLiteral("object-flip-horizontal")}, {QStringLiteral("flipvertically"), QStringLiteral("object-flip-vertical")}, {QStringLiteral("image-flip-vertical"), QStringLiteral("object-flip-vertical")}, {QStringLiteral("image-scale"), QStringLiteral("transform-scale")}, {QStringLiteral("bold"), QStringLiteral("format-text-bold")}, {QStringLiteral("italic"), QStringLiteral("format-text-italic")}, {QStringLiteral("underline"), QStringLiteral("format-text-underline")}, {QStringLiteral("strikeout"), QStringLiteral("format-text-strikethrough")}, {QStringLiteral("superscript"), QStringLiteral("format-text-superscript")}, {QStringLiteral("subscript"), QStringLiteral("format-text-subscript")}, // "grow" is a bit unspecific to always set it to "grow font", so use the exact ID here {QStringLiteral(".uno:Grow"), QStringLiteral("format-font-size-more")}, // LibreOffice {QStringLiteral(".uno:Shrink"), QStringLiteral("format-font-size-less")}, // LibreOffice // also a bit unspecific? {QStringLiteral("alignleft"), QStringLiteral("format-justify-left")}, {QStringLiteral("alignhorizontalcenter"), QStringLiteral("format-justify-center")}, {QStringLiteral("alignright"), QStringLiteral("format-justify-right")}, {QStringLiteral("alignjustified"), QStringLiteral("format-justify-fill")}, {QStringLiteral("incrementindent"), QStringLiteral("format-indent-more")}, {QStringLiteral("decrementindent"), QStringLiteral("format-indent-less")}, {QStringLiteral("defaultbullet"), QStringLiteral("format-list-unordered")}, // LibreOffice {QStringLiteral("defaultnumbering"), QStringLiteral("format-list-ordered")}, // LibreOffice {QStringLiteral("sortascending"), QStringLiteral("view-sort-ascending")}, {QStringLiteral("sortdescending"), QStringLiteral("view-sort-descending")}, {QStringLiteral("autopilotmenu"), QStringLiteral("tools-wizard")}, // LibreOffice {QStringLiteral("layers-new"), QStringLiteral("layer-new")}, {QStringLiteral("layers-duplicate"), QStringLiteral("layer-duplicate")}, {QStringLiteral("layers-delete"), QStringLiteral("layer-delete")}, {QStringLiteral("layers-anchor"), QStringLiteral("anchor")}, {QStringLiteral("slideshow"), QStringLiteral("media-playback-start")}, // Gwenview uses this icon for that {QStringLiteral("playvideo"), QStringLiteral("media-playback-start")}, {QStringLiteral("addtags"), QStringLiteral("tag-new")}, {QStringLiteral("newevent"), QStringLiteral("appointment-new")}, {QStringLiteral("previous-document"), QStringLiteral("go-previous")}, {QStringLiteral("prevphoto"), QStringLiteral("go-previous")}, {QStringLiteral("next-document"), QStringLiteral("go-next")}, {QStringLiteral("nextphoto"), QStringLiteral("go-next")}, {QStringLiteral("redeye"), QStringLiteral("redeyes")}, {QStringLiteral("crop"), QStringLiteral("transform-crop")}, {QStringLiteral("move"), QStringLiteral("transform-move")}, {QStringLiteral("rotate"), QStringLiteral("transform-rotate")}, {QStringLiteral("scale"), QStringLiteral("transform-scale")}, {QStringLiteral("shear"), QStringLiteral("transform-shear")}, {QStringLiteral("flip"), QStringLiteral("object-flip-horizontal")}, {QStringLiteral("flag"), QStringLiteral("flag-red")}, // is there a "mark" or "important" icon that isn't email? {QStringLiteral("tools-measure"), QStringLiteral("measure")}, {QStringLiteral("tools-text"), QStringLiteral("draw-text")}, {QStringLiteral("tools-color-picker"), QStringLiteral("color-picker")}, {QStringLiteral("tools-paintbrush"), QStringLiteral("draw-brush")}, {QStringLiteral("tools-eraser"), QStringLiteral("draw-eraser")}, {QStringLiteral("tools-paintbrush"), QStringLiteral("draw-brush")}, {QStringLiteral("help"), QStringLiteral("help-contents")}, {QStringLiteral("helpindex"), QStringLiteral("help-contents")}, {QStringLiteral("contents"), QStringLiteral("help-contents")}, {QStringLiteral("helpcontents"), QStringLiteral("help-contents")}, {QStringLiteral("context-help"), QStringLiteral("help-whatsthis")}, {QStringLiteral("extendedhelp"), QStringLiteral("help-whatsthis")}, // LibreOffice {QStringLiteral("helpreportproblem"), QStringLiteral("tools-report-bug")}, {QStringLiteral("sendfeedback"), QStringLiteral("tools-report-bug")}, // LibreOffice {QStringLiteral("about"), QStringLiteral("help-about")}, {QStringLiteral("emptytrash"), QStringLiteral("trash-empty")}, {QStringLiteral("movetotrash"), QStringLiteral("user-trash-symbolic")}, // Gnome help {QStringLiteral("yelp-application-larger-text"), QStringLiteral("format-font-size-more")}, {QStringLiteral("yelp-application-smaller-text"), QStringLiteral("format-font-size-less")}, // LibreOffice // LibreOffice documents in its New menu {QStringLiteral("private:factory/swriter"), QStringLiteral("application-vnd.oasis.opendocument.text")}, {QStringLiteral("private:factory/scalc"), QStringLiteral("application-vnd.oasis.opendocument.spreadsheet")}, {QStringLiteral("private:factory/simpress"), QStringLiteral("application-vnd.oasis.opendocument.presentation")}, {QStringLiteral("private:factory/sdraw"), QStringLiteral("application-vnd.oasis.opendocument.graphics")}, {QStringLiteral("private:factory/swriter/web"), QStringLiteral("text-html")}, {QStringLiteral("private:factory/smath"), QStringLiteral("application-vnd.oasis.opendocument.formula")}, }; // Sometimes we get additional arguments (?slot=123) we don't care about const int questionMarkIndex = action.indexOf(QLatin1Char('?')); if (questionMarkIndex > -1) { action.truncate(questionMarkIndex); } icon = s_icons.value(action); if (icon.isEmpty()) { const int dotIndex = action.indexOf(QLatin1Char('.')); // app., win., or unity. prefix QString prefix; if (dotIndex > -1) { prefix = action.left(dotIndex); action = action.mid(dotIndex + 1); } // appmenu-gtk-module if (prefix == QLatin1String("unity")) { // Remove superfluous hyphens added by appmenu-gtk-module // First remove multiple subsequent ones static QRegularExpression subsequentHyphenRegExp(QStringLiteral("-{2,}")); action.replace(subsequentHyphenRegExp, QStringLiteral("-")); // now we can be sure we only have a single hyphen at the start or end, remove it if needed if (action.startsWith(QLatin1Char('-'))) { action.remove(0, 1); } if (action.endsWith(QLatin1Char('-'))) { action.chop(1); } // It also turns accelerators (&) into hyphens, so remove any hyphen that comes before // a lower-case letter ("mid sentence"), e.g. "P-references" static QRegularExpression strayHyphenRegExp(QStringLiteral("-(?=[a-z]+)")); action.remove(strayHyphenRegExp); } icon = s_icons.value(action); } if (icon.isEmpty()) { static const auto s_dup1Prefix = QStringLiteral("dup:1:"); // can it be dup2 also? if (action.startsWith(s_dup1Prefix)) { action = action.mid(s_dup1Prefix.length()); } static const auto s_unoPrefix = QStringLiteral(".uno:"); // LibreOffice with appmenu-gtk if (action.startsWith(s_unoPrefix)) { action = action.mid(s_unoPrefix.length()); } // LibreOffice's "Open" entry is always "OpenFromAppname" so we just chop that off if (action.startsWith(QLatin1String("OpenFrom"))) { action.truncate(4); // basically "Open" } icon = s_icons.value(action); } if (icon.isEmpty()) { static const auto s_commonPrefix = QStringLiteral("Common"); if (action.startsWith(s_commonPrefix)) { action = action.mid(s_commonPrefix.length()); } icon = s_icons.value(action); } if (icon.isEmpty()) { static const auto s_prefixes = QStringList{ // Gimp with appmenu-gtk QStringLiteral("file-"), QStringLiteral("edit-"), QStringLiteral("view-"), QStringLiteral("image-"), QStringLiteral("layers-"), QStringLiteral("colors-"), QStringLiteral("tools-"), QStringLiteral("plug-in-"), QStringLiteral("windows-"), QStringLiteral("dialogs-"), QStringLiteral("help-"), }; for (const QString &prefix : s_prefixes) { if (action.startsWith(prefix)) { action = action.mid(prefix.length()); break; } } icon = s_icons.value(action); } if (icon.isEmpty()) { action = action.toLower(); icon = s_icons.value(action); } if (icon.isEmpty()) { static const auto s_prefixes = QStringList{ // Pluma with appmenu-gtk QStringLiteral("file"), QStringLiteral("edit"), QStringLiteral("view"), QStringLiteral("help"), }; for (const QString &prefix : s_prefixes) { if (action.startsWith(prefix)) { action = action.mid(prefix.length()); break; } } icon = s_icons.value(action); } return icon; } core-0.8/gmenuproxy/icons.h000066400000000000000000000003461417504024300160150ustar00rootroot00000000000000/* SPDX-FileCopyrightText: 2018 Kai Uwe Broulik SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once #include namespace Icons { QString actionIcon(const QString &actionName); } core-0.8/gmenuproxy/main.cpp000066400000000000000000000016171417504024300161630ustar00rootroot00000000000000/* SPDX-FileCopyrightText: 2018 Kai Uwe Broulik SPDX-License-Identifier: LGPL-2.1-or-later */ #include #include #include #include "menuproxy.h" int main(int argc, char **argv) { qputenv("QT_QPA_PLATFORM", "xcb"); QGuiApplication::setDesktopSettingsAware(false); QGuiApplication app(argc, argv); if (!KWindowSystem::isPlatformX11()) { qFatal("qdbusmenuproxy is only useful XCB. Aborting"); } auto disableSessionManagement = [](QSessionManager &sm) { sm.setRestartHint(QSessionManager::RestartNever); }; QObject::connect(&app, &QGuiApplication::commitDataRequest, disableSessionManagement); QObject::connect(&app, &QGuiApplication::saveStateRequest, disableSessionManagement); app.setQuitOnLastWindowClosed(false); MenuProxy proxy; return app.exec(); } core-0.8/gmenuproxy/menu.cpp000066400000000000000000000252251417504024300162040ustar00rootroot00000000000000/* SPDX-FileCopyrightText: 2018 Kai Uwe Broulik SPDX-License-Identifier: LGPL-2.1-or-later */ #include "menu.h" #include #include #include #include #include #include #include #include "utils.h" static const QString s_orgGtkMenus = QStringLiteral("org.gtk.Menus"); Menu::Menu(const QString &serviceName, const QString &objectPath, QObject *parent) : QObject(parent) , m_serviceName(serviceName) , m_objectPath(objectPath) { Q_ASSERT(!serviceName.isEmpty()); Q_ASSERT(!m_objectPath.isEmpty()); if (!QDBusConnection::sessionBus() .connect(m_serviceName, m_objectPath, s_orgGtkMenus, QStringLiteral("Changed"), this, SLOT(onMenuChanged(GMenuChangeList)))) { qDebug() << "Failed to subscribe to menu changes for" << parent << "on" << serviceName << "at" << objectPath; } } Menu::~Menu() = default; void Menu::cleanup() { stop(m_subscriptions); } void Menu::start(uint id) { if (m_subscriptions.contains(id)) { return; } // TODO watch service disappearing? // dbus-send --print-reply --session --dest=:1.103 /org/libreoffice/window/104857641/menus/menubar org.gtk.Menus.Start array:uint32:0 QDBusMessage msg = QDBusMessage::createMethodCall(m_serviceName, m_objectPath, s_orgGtkMenus, QStringLiteral("Start")); msg.setArguments({QVariant::fromValue(QList{id})}); QDBusPendingReply reply = QDBusConnection::sessionBus().asyncCall(msg); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this); connect(watcher, &QDBusPendingCallWatcher::finished, this, [this, id](QDBusPendingCallWatcher *watcher) { QScopedPointer watcherPtr(watcher); QDBusPendingReply reply = *watcherPtr; if (reply.isError()) { qDebug() << "Failed to start subscription to" << id << "on" << m_serviceName << "at" << m_objectPath << reply.error(); emit failedToSubscribe(id); } else { const bool hadMenu = !m_menus.isEmpty(); const auto menus = reply.value(); for (const auto &menu : menus) { m_menus[menu.id].append(menus); } // LibreOffice on startup fails to give us some menus right away, we'll also subscribe in onMenuChanged() if necessary if (menus.isEmpty()) { qDebug() << "Got an empty menu for" << id << "on" << m_serviceName << "at" << m_objectPath; return; } // TODO are we subscribed to all it returns or just to the ones we requested? m_subscriptions.append(id); // do we have a menu now? let's tell everyone if (!hadMenu && !m_menus.isEmpty()) { emit menuAppeared(); } emit subscribed(id); } }); } void Menu::stop(const QList &ids) { QDBusMessage msg = QDBusMessage::createMethodCall(m_serviceName, m_objectPath, s_orgGtkMenus, QStringLiteral("End")); msg.setArguments({ QVariant::fromValue(ids) // don't let it unwrap it, hence in a variant }); QDBusPendingReply reply = QDBusConnection::sessionBus().asyncCall(msg); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this); connect(watcher, &QDBusPendingCallWatcher::finished, this, [this, ids](QDBusPendingCallWatcher *watcher) { QDBusPendingReply reply = *watcher; if (reply.isError()) { qDebug() << "Failed to stop subscription to" << ids << "on" << m_serviceName << "at" << m_objectPath << reply.error(); } else { // remove all subscriptions that we unsubscribed from // TODO is there a nicer algorithm for that? // TODO remove all m_menus also? m_subscriptions.erase( std::remove_if(m_subscriptions.begin(), m_subscriptions.end(), std::bind(&QList::contains, m_subscriptions, std::placeholders::_1)), m_subscriptions.end()); if (m_subscriptions.isEmpty()) { emit menuDisappeared(); } } watcher->deleteLater(); }); } bool Menu::hasMenu() const { return !m_menus.isEmpty(); } bool Menu::hasSubscription(uint subscription) const { return m_subscriptions.contains(subscription); } GMenuItem Menu::getSection(int id, bool *ok) const { int subscription; int section; int index; Utils::intToTreeStructure(id, subscription, section, index); return getSection(subscription, section, ok); } GMenuItem Menu::getSection(int subscription, int section, bool *ok) const { const auto menu = m_menus.value(subscription); auto it = std::find_if(menu.begin(), menu.end(), [section](const GMenuItem &item) { return item.section == section; }); if (it == menu.end()) { if (ok) { *ok = false; } return GMenuItem(); } if (ok) { *ok = true; } return *it; } QVariantMap Menu::getItem(int id) const { int subscription; int section; int index; Utils::intToTreeStructure(id, subscription, section, index); return getItem(subscription, section, index); } QVariantMap Menu::getItem(int subscription, int sectionId, int index) const { bool ok; const GMenuItem section = getSection(subscription, sectionId, &ok); if (!ok) { return QVariantMap(); } const auto items = section.items; if (items.count() < index) { qDebug() << "Cannot get action" << subscription << sectionId << index << "which is out of bounds"; return QVariantMap(); } // 0 is the menu itself, items start at 1 return items.at(index - 1); } void Menu::onMenuChanged(const GMenuChangeList &changes) { const bool hadMenu = !m_menus.isEmpty(); QVector dirtyMenus; QVector dirtyItems; for (const auto &change : changes) { auto updateSection = [&](GMenuItem §ion) { // Check if the amount of inserted items is identical to the items to be removed, // just update the existing items and signal a change for that. // LibreOffice tends to do that e.g. to update its Undo menu entry if (change.itemsToRemoveCount == change.itemsToInsert.count()) { for (int i = 0; i < change.itemsToInsert.count(); ++i) { const auto &newItem = change.itemsToInsert.at(i); section.items[change.changePosition + i] = newItem; // 0 is the menu itself, items start at 1 dirtyItems.append(Utils::treeStructureToInt(change.subscription, change.menu, change.changePosition + i + 1)); } } else { for (int i = 0; i < change.itemsToRemoveCount; ++i) { section.items.removeAt(change.changePosition); // TODO bounds check } for (int i = 0; i < change.itemsToInsert.count(); ++i) { section.items.insert(change.changePosition + i, change.itemsToInsert.at(i)); } dirtyMenus.append(Utils::treeStructureToInt(change.subscription, change.menu, 0)); } }; // shouldn't happen, it says only Start() subscribes to changes if (!m_subscriptions.contains(change.subscription)) { qDebug() << "Got menu change for menu" << change.subscription << "that we are not subscribed to, subscribing now"; // LibreOffice doesn't give us a menu right away but takes a while and then signals us a change start(change.subscription); continue; } auto &menu = m_menus[change.subscription]; bool sectionFound = false; // TODO findSectionRef for (GMenuItem §ion : menu) { if (section.section != change.menu) { continue; } qDebug() << "Updating existing section" << change.menu << "in subscription" << change.subscription; sectionFound = true; updateSection(section); break; } // Insert new section if (!sectionFound) { qDebug() << "Creating new section" << change.menu << "in subscription" << change.subscription; if (change.itemsToRemoveCount > 0) { qDebug() << "Menu change requested to remove items from a new (and as such empty) section"; } GMenuItem newSection; newSection.id = change.subscription; newSection.section = change.menu; updateSection(newSection); menu.append(newSection); } } // do we have a menu now? let's tell everyone if (!hadMenu && !m_menus.isEmpty()) { emit menuAppeared(); } else if (hadMenu && m_menus.isEmpty()) { emit menuDisappeared(); } if (!dirtyItems.isEmpty()) { emit itemsChanged(dirtyItems); } emit menusChanged(dirtyMenus); } void Menu::actionsChanged(const QStringList &dirtyActions, const QString &prefix) { auto forEachMenuItem = [this](const std::function &cb) { for (auto it = m_menus.constBegin(), end = m_menus.constEnd(); it != end; ++it) { const int subscription = it.key(); for (const auto &menu : it.value()) { const int section = menu.section; int count = 0; const auto items = menu.items; for (const auto &item : items) { ++count; // 0 is a menu, entries start at 1 if (!cb(subscription, section, count, item)) { goto loopExit; // hell yeah break; } } } } loopExit: // loop exit return; }; // now find in which menus these actions are and emit a change accordingly QVector dirtyItems; for (const QString &action : dirtyActions) { const QString prefixedAction = prefix + action; forEachMenuItem([&prefixedAction, &dirtyItems](int subscription, int section, int index, const QVariantMap &item) { const QString actionName = Utils::itemActionName(item); if (actionName == prefixedAction) { dirtyItems.append(Utils::treeStructureToInt(subscription, section, index)); return false; // break } return true; // continue }); } if (!dirtyItems.isEmpty()) { emit itemsChanged(dirtyItems); } } core-0.8/gmenuproxy/menu.h000066400000000000000000000031561417504024300156500ustar00rootroot00000000000000/* SPDX-FileCopyrightText: 2018 Kai Uwe Broulik SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once #include #include #include #include "./extend/dbusmenutypes_p.h" #include "gdbusmenutypes_p.h" class Menu : public QObject { Q_OBJECT public: Menu(const QString &serviceName, const QString &objectPath, QObject *parent = nullptr); ~Menu() override; void init(); void cleanup(); void start(uint id); void stop(const QList &ids); bool hasMenu() const; bool hasSubscription(uint subscription) const; GMenuItem getSection(int id, bool *ok = nullptr) const; GMenuItem getSection(int subscription, int sectionId, bool *ok = nullptr) const; QVariantMap getItem(int id) const; // bool ok argument? QVariantMap getItem(int subscription, int sectionId, int id) const; public slots: void actionsChanged(const QStringList &dirtyActions, const QString &prefix); Q_SIGNALS: void menuAppeared(); // emitted the first time a menu was successfully loaded void menuDisappeared(); void subscribed(uint id); void failedToSubscribe(uint id); void itemsChanged(const QVector &itemIds); void menusChanged(const QVector &menuIds); private slots: void onMenuChanged(const GMenuChangeList &changes); private: void initMenu(); void menuChanged(const GMenuChangeList &changes); // QSet? QList m_subscriptions; // keeps track of which menu trees we're subscribed to QHash m_menus; QString m_serviceName; QString m_objectPath; }; core-0.8/gmenuproxy/menuproxy.cpp000066400000000000000000000317711417504024300173110ustar00rootroot00000000000000/* SPDX-FileCopyrightText: 2018 Kai Uwe Broulik SPDX-License-Identifier: LGPL-2.1-or-later */ #include "menuproxy.h" #include #include #include #include #include #include #include #include #include #include // #include #include // #include #include #include #include #include "window.h" static const QString s_ourServiceName = QStringLiteral("org.kde.plasma.gmenu_dbusmenu_proxy"); static const QString s_dbusMenuRegistrar = QStringLiteral("com.canonical.AppMenu.Registrar"); static const QByteArray s_gtkUniqueBusName = QByteArrayLiteral("_GTK_UNIQUE_BUS_NAME"); static const QByteArray s_gtkApplicationObjectPath = QByteArrayLiteral("_GTK_APPLICATION_OBJECT_PATH"); static const QByteArray s_unityObjectPath = QByteArrayLiteral("_UNITY_OBJECT_PATH"); static const QByteArray s_gtkWindowObjectPath = QByteArrayLiteral("_GTK_WINDOW_OBJECT_PATH"); static const QByteArray s_gtkMenuBarObjectPath = QByteArrayLiteral("_GTK_MENUBAR_OBJECT_PATH"); // that's the generic app menu with Help and Options and will be used if window doesn't have a fully-blown menu bar static const QByteArray s_gtkAppMenuObjectPath = QByteArrayLiteral("_GTK_APP_MENU_OBJECT_PATH"); static const QByteArray s_kdeNetWmAppMenuServiceName = QByteArrayLiteral("_KDE_NET_WM_APPMENU_SERVICE_NAME"); static const QByteArray s_kdeNetWmAppMenuObjectPath = QByteArrayLiteral("_KDE_NET_WM_APPMENU_OBJECT_PATH"); static const QString s_gtkModules = QStringLiteral("gtk-modules"); static const QString s_appMenuGtkModule = QStringLiteral("appmenu-gtk-module"); MenuProxy::MenuProxy() : QObject() , m_xConnection(QX11Info::connection()) , m_serviceWatcher(new QDBusServiceWatcher(this)) , m_gtk2RcWatch(new KDirWatch(this)) , m_writeGtk2SettingsTimer(new QTimer(this)) { m_serviceWatcher->setConnection(QDBusConnection::sessionBus()); m_serviceWatcher->setWatchMode(QDBusServiceWatcher::WatchForUnregistration | QDBusServiceWatcher::WatchForRegistration); m_serviceWatcher->addWatchedService(s_dbusMenuRegistrar); connect(m_serviceWatcher, &QDBusServiceWatcher::serviceRegistered, this, [this](const QString &service) { Q_UNUSED(service); qDebug() << "Global menu service became available, starting"; init(); }); connect(m_serviceWatcher, &QDBusServiceWatcher::serviceUnregistered, this, [this](const QString &service) { Q_UNUSED(service); qDebug() << "Global menu service disappeared, cleaning up"; teardown(); }); // It's fine to do a blocking call here as we're a separate binary with no UI if (QDBusConnection::sessionBus().interface()->isServiceRegistered(s_dbusMenuRegistrar)) { qDebug() << "Global menu service is running, starting right away"; init(); } else { qDebug() << "No global menu service available, waiting for it to start before doing anything"; // be sure when started to restore gtk menus when there's no dbus menu around in case we crashed enableGtkSettings(false); } // kde-gtk-config just deletes and re-creates the gtkrc-2.0, watch this and add our config to it again m_writeGtk2SettingsTimer->setSingleShot(true); m_writeGtk2SettingsTimer->setInterval(1000); connect(m_writeGtk2SettingsTimer, &QTimer::timeout, this, &MenuProxy::writeGtk2Settings); auto startGtk2SettingsTimer = [this] { if (!m_writeGtk2SettingsTimer->isActive()) { m_writeGtk2SettingsTimer->start(); } }; connect(m_gtk2RcWatch, &KDirWatch::created, this, startGtk2SettingsTimer); connect(m_gtk2RcWatch, &KDirWatch::dirty, this, startGtk2SettingsTimer); m_gtk2RcWatch->addFile(gtkRc2Path()); } MenuProxy::~MenuProxy() { teardown(); } bool MenuProxy::init() { if (!QDBusConnection::sessionBus().registerService(s_ourServiceName)) { qDebug() << "Failed to register DBus service" << s_ourServiceName; return false; } enableGtkSettings(true); connect(KWindowSystem::self(), &KWindowSystem::windowAdded, this, &MenuProxy::onWindowAdded); connect(KWindowSystem::self(), &KWindowSystem::windowRemoved, this, &MenuProxy::onWindowRemoved); const auto windows = KWindowSystem::windows(); for (WId id : windows) { onWindowAdded(id); } if (m_windows.isEmpty()) { qDebug() << "Up and running but no windows with menus in sight"; } return true; } void MenuProxy::teardown() { enableGtkSettings(false); QDBusConnection::sessionBus().unregisterService(s_ourServiceName); disconnect(KWindowSystem::self(), &KWindowSystem::windowAdded, this, &MenuProxy::onWindowAdded); disconnect(KWindowSystem::self(), &KWindowSystem::windowRemoved, this, &MenuProxy::onWindowRemoved); qDeleteAll(m_windows); m_windows.clear(); } void MenuProxy::enableGtkSettings(bool enable) { m_enabled = enable; writeGtk2Settings(); writeGtk3Settings(); // TODO use gconf/dconf directly or at least signal a change somehow? } QString MenuProxy::gtkRc2Path() { return QDir::homePath() + QLatin1String("/.gtkrc-2.0"); } QString MenuProxy::gtk3SettingsIniPath() { return QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + QLatin1String("/gtk-3.0/settings.ini"); } void MenuProxy::writeGtk2Settings() { QFile rcFile(gtkRc2Path()); if (!rcFile.exists()) { // Don't create it here, that would break writing default GTK-2.0 settings on first login, // as the gtkbreeze kconf_update script only does so if it does not exist return; } qDebug() << "Writing gtkrc-2.0 to" << (m_enabled ? "enable" : "disable") << "global menu support"; if (!rcFile.open(QIODevice::ReadWrite | QIODevice::Text)) { return; } QByteArray content; QStringList gtkModules; while (!rcFile.atEnd()) { const QByteArray rawLine = rcFile.readLine(); const QString line = QString::fromUtf8(rawLine.trimmed()); if (!line.startsWith(s_gtkModules)) { // keep line as-is content += rawLine; continue; } const int equalSignIdx = line.indexOf(QLatin1Char('=')); if (equalSignIdx < 1) { continue; } #if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) gtkModules = line.mid(equalSignIdx + 1).split(QLatin1Char(':'), QString::SkipEmptyParts); #else gtkModules = line.mid(equalSignIdx + 1).split(QLatin1Char(':'), Qt::SkipEmptyParts); #endif break; } addOrRemoveAppMenuGtkModule(gtkModules); if (!gtkModules.isEmpty()) { content += QStringLiteral("%1=%2").arg(s_gtkModules, gtkModules.join(QLatin1Char(':'))).toUtf8(); } qDebug() << " gtk-modules:" << gtkModules; m_gtk2RcWatch->stopScan(); // now write the new contents of the file rcFile.resize(0); rcFile.write(content); rcFile.close(); m_gtk2RcWatch->startScan(); } void MenuProxy::writeGtk3Settings() { qDebug() << "Writing gtk-3.0/settings.ini" << (m_enabled ? "enable" : "disable") << "global menu support"; // mostly taken from kde-gtk-config QSettings cfg(gtk3SettingsIniPath(), QSettings::IniFormat); cfg.beginGroup(QStringLiteral("Settings")); QStringList gtkModules = cfg.value(QStringLiteral("gtk-modules")).toString().split(QLatin1Char(':')); addOrRemoveAppMenuGtkModule(gtkModules); if (!gtkModules.isEmpty()) { cfg.setValue(QStringLiteral("gtk-modules"), gtkModules.join(QLatin1Char(':'))); } else { cfg.remove(QStringLiteral("gtk-modules")); } qDebug() << " gtk-modules:" << gtkModules; if (m_enabled) { cfg.setValue(QStringLiteral("gtk-shell-shows-menubar"), 1); } else { cfg.remove(QStringLiteral("gtk-shell-shows-menubar")); } qDebug() << " gtk-shell-shows-menubar:" << (m_enabled ? 1 : 0); cfg.sync(); } void MenuProxy::addOrRemoveAppMenuGtkModule(QStringList &list) { if (m_enabled && !list.contains(s_appMenuGtkModule)) { list.append(s_appMenuGtkModule); } else if (!m_enabled) { list.removeAll(s_appMenuGtkModule); } } void MenuProxy::onWindowAdded(WId id) { if (m_windows.contains(id)) { return; } KWindowInfo info(id, NET::WMWindowType); NET::WindowType wType = info.windowType(NET::NormalMask | NET::DesktopMask | NET::DockMask | NET::ToolbarMask | NET::MenuMask | NET::DialogMask | NET::OverrideMask | NET::TopMenuMask | NET::UtilityMask | NET::SplashMask); // Only top level windows typically have a menu bar, dialogs, such as settings don't if (wType != NET::Normal) { qDebug() << "Ignoring window" << id << "of type" << wType; return; } const QString serviceName = QString::fromUtf8(getWindowPropertyString(id, s_gtkUniqueBusName)); if (serviceName.isEmpty()) { return; } const QString applicationObjectPath = QString::fromUtf8(getWindowPropertyString(id, s_gtkApplicationObjectPath)); const QString unityObjectPath = QString::fromUtf8(getWindowPropertyString(id, s_unityObjectPath)); const QString windowObjectPath = QString::fromUtf8(getWindowPropertyString(id, s_gtkWindowObjectPath)); const QString applicationMenuObjectPath = QString::fromUtf8(getWindowPropertyString(id, s_gtkAppMenuObjectPath)); const QString menuBarObjectPath = QString::fromUtf8(getWindowPropertyString(id, s_gtkMenuBarObjectPath)); if (applicationMenuObjectPath.isEmpty() && menuBarObjectPath.isEmpty()) { return; } Window *window = new Window(serviceName); window->setWinId(id); window->setApplicationObjectPath(applicationObjectPath); window->setUnityObjectPath(unityObjectPath); window->setWindowObjectPath(windowObjectPath); window->setApplicationMenuObjectPath(applicationMenuObjectPath); window->setMenuBarObjectPath(menuBarObjectPath); m_windows.insert(id, window); connect(window, &Window::requestWriteWindowProperties, this, [this, window] { Q_ASSERT(!window->proxyObjectPath().isEmpty()); writeWindowProperty(window->winId(), s_kdeNetWmAppMenuServiceName, s_ourServiceName.toUtf8()); writeWindowProperty(window->winId(), s_kdeNetWmAppMenuObjectPath, window->proxyObjectPath().toUtf8()); }); connect(window, &Window::requestRemoveWindowProperties, this, [this, window] { writeWindowProperty(window->winId(), s_kdeNetWmAppMenuServiceName, QByteArray()); writeWindowProperty(window->winId(), s_kdeNetWmAppMenuObjectPath, QByteArray()); }); window->init(); } void MenuProxy::onWindowRemoved(WId id) { // no need to cleanup() (which removes window properties) when the window is gone, delete right away delete m_windows.take(id); } QByteArray MenuProxy::getWindowPropertyString(WId id, const QByteArray &name) { QByteArray value; auto atom = getAtom(name); if (atom == XCB_ATOM_NONE) { return value; } // GTK properties aren't XCB_ATOM_STRING but a custom one auto utf8StringAtom = getAtom(QByteArrayLiteral("UTF8_STRING")); static const long MAX_PROP_SIZE = 10000; auto propertyCookie = xcb_get_property(m_xConnection, false, id, atom, utf8StringAtom, 0, MAX_PROP_SIZE); QScopedPointer propertyReply(xcb_get_property_reply(m_xConnection, propertyCookie, nullptr)); if (propertyReply.isNull()) { qDebug() << "XCB property reply for atom" << name << "on" << id << "was null"; return value; } if (propertyReply->type == utf8StringAtom && propertyReply->format == 8 && propertyReply->value_len > 0) { const char *data = (const char *)xcb_get_property_value(propertyReply.data()); int len = propertyReply->value_len; if (data) { value = QByteArray(data, data[len - 1] ? len : len - 1); } } return value; } void MenuProxy::writeWindowProperty(WId id, const QByteArray &name, const QByteArray &value) { auto atom = getAtom(name); if (atom == XCB_ATOM_NONE) { return; } if (value.isEmpty()) { xcb_delete_property(m_xConnection, id, atom); } else { xcb_change_property(m_xConnection, XCB_PROP_MODE_REPLACE, id, atom, XCB_ATOM_STRING, 8, value.length(), value.constData()); } } xcb_atom_t MenuProxy::getAtom(const QByteArray &name) { static QHash s_atoms; auto atom = s_atoms.value(name, XCB_ATOM_NONE); if (atom == XCB_ATOM_NONE) { const xcb_intern_atom_cookie_t atomCookie = xcb_intern_atom(m_xConnection, false, name.length(), name.constData()); QScopedPointer atomReply(xcb_intern_atom_reply(m_xConnection, atomCookie, nullptr)); if (!atomReply.isNull()) { atom = atomReply->atom; if (atom != XCB_ATOM_NONE) { s_atoms.insert(name, atom); } } } return atom; } core-0.8/gmenuproxy/menuproxy.h000066400000000000000000000023201417504024300167420ustar00rootroot00000000000000/* SPDX-FileCopyrightText: 2018 Kai Uwe Broulik SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once #include #include #include #include // for WId #include class QDBusServiceWatcher; class QTimer; class KDirWatch; class Window; class MenuProxy : public QObject { Q_OBJECT public: MenuProxy(); ~MenuProxy() override; private Q_SLOTS: void onWindowAdded(WId id); void onWindowRemoved(WId id); private: bool init(); void teardown(); static QString gtkRc2Path(); static QString gtk3SettingsIniPath(); void enableGtkSettings(bool enabled); void writeGtk2Settings(); void writeGtk3Settings(); void addOrRemoveAppMenuGtkModule(QStringList &list); xcb_connection_t *m_xConnection; QByteArray getWindowPropertyString(WId id, const QByteArray &name); void writeWindowProperty(WId id, const QByteArray &name, const QByteArray &value); xcb_atom_t getAtom(const QByteArray &name); QHash m_windows; QDBusServiceWatcher *m_serviceWatcher; KDirWatch *m_gtk2RcWatch; QTimer *m_writeGtk2SettingsTimer; bool m_enabled = false; }; core-0.8/gmenuproxy/utils.cpp000066400000000000000000000014551417504024300163770ustar00rootroot00000000000000/* SPDX-FileCopyrightText: 2018 Kai Uwe Broulik SPDX-License-Identifier: LGPL-2.1-or-later */ #include "utils.h" int Utils::treeStructureToInt(int subscription, int section, int index) { return subscription * 1000000 + section * 1000 + index; } void Utils::intToTreeStructure(int source, int &subscription, int §ion, int &index) { // TODO some better math :) or bit shifting or something index = source % 1000; section = (source / 1000) % 1000; subscription = source / 1000000; } QString Utils::itemActionName(const QVariantMap &item) { QString actionName = item.value(QStringLiteral("action")).toString(); if (actionName.isEmpty()) { actionName = item.value(QStringLiteral("submenu-action")).toString(); } return actionName; } core-0.8/gmenuproxy/utils.h000066400000000000000000000006241417504024300160410ustar00rootroot00000000000000/* SPDX-FileCopyrightText: 2018 Kai Uwe Broulik SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once #include #include namespace Utils { int treeStructureToInt(int subscription, int section, int index); void intToTreeStructure(int source, int &subscription, int §ion, int &index); QString itemActionName(const QVariantMap &item); } core-0.8/gmenuproxy/window.cpp000066400000000000000000000503741417504024300165520ustar00rootroot00000000000000/* SPDX-FileCopyrightText: 2018 Kai Uwe Broulik SPDX-License-Identifier: LGPL-2.1-or-later */ #include "window.h" #include #include #include #include #include #include #include #include #include #include "actions.h" #include "dbusmenuadaptor.h" #include "icons.h" #include "menu.h" #include "utils.h" #include "./extend/dbusmenushortcut_p.h" static const QString s_orgGtkActions = QStringLiteral("org.gtk.Actions"); static const QString s_orgGtkMenus = QStringLiteral("org.gtk.Menus"); static const QString s_applicationActionsPrefix = QStringLiteral("app."); static const QString s_unityActionsPrefix = QStringLiteral("unity."); static const QString s_windowActionsPrefix = QStringLiteral("win."); Window::Window(const QString &serviceName) : QObject() , m_serviceName(serviceName) { qDebug() << "Created menu on" << serviceName; Q_ASSERT(!serviceName.isEmpty()); GDBusMenuTypes_register(); DBusMenuTypes_register(); } Window::~Window() = default; void Window::init() { qDebug() << "Inited window with menu for" << m_winId << "on" << m_serviceName << "at app" << m_applicationObjectPath << "win" << m_windowObjectPath << "unity" << m_unityObjectPath; if (!m_applicationMenuObjectPath.isEmpty()) { m_applicationMenu = new Menu(m_serviceName, m_applicationMenuObjectPath, this); connect(m_applicationMenu, &Menu::menuAppeared, this, &Window::updateWindowProperties); connect(m_applicationMenu, &Menu::menuDisappeared, this, &Window::updateWindowProperties); connect(m_applicationMenu, &Menu::subscribed, this, &Window::onMenuSubscribed); // basically so it replies on DBus no matter what connect(m_applicationMenu, &Menu::failedToSubscribe, this, &Window::onMenuSubscribed); connect(m_applicationMenu, &Menu::itemsChanged, this, &Window::menuItemsChanged); connect(m_applicationMenu, &Menu::menusChanged, this, &Window::menuChanged); } if (!m_menuBarObjectPath.isEmpty()) { m_menuBar = new Menu(m_serviceName, m_menuBarObjectPath, this); connect(m_menuBar, &Menu::menuAppeared, this, &Window::updateWindowProperties); connect(m_menuBar, &Menu::menuDisappeared, this, &Window::updateWindowProperties); connect(m_menuBar, &Menu::subscribed, this, &Window::onMenuSubscribed); connect(m_menuBar, &Menu::failedToSubscribe, this, &Window::onMenuSubscribed); connect(m_menuBar, &Menu::itemsChanged, this, &Window::menuItemsChanged); connect(m_menuBar, &Menu::menusChanged, this, &Window::menuChanged); } if (!m_applicationObjectPath.isEmpty()) { m_applicationActions = new Actions(m_serviceName, m_applicationObjectPath, this); connect(m_applicationActions, &Actions::actionsChanged, this, [this](const QStringList &dirtyActions) { onActionsChanged(dirtyActions, s_applicationActionsPrefix); }); connect(m_applicationActions, &Actions::loaded, this, [this] { if (m_menuInited) { onActionsChanged(m_applicationActions->getAll().keys(), s_applicationActionsPrefix); } else { initMenu(); } }); m_applicationActions->load(); } if (!m_unityObjectPath.isEmpty()) { m_unityActions = new Actions(m_serviceName, m_unityObjectPath, this); connect(m_unityActions, &Actions::actionsChanged, this, [this](const QStringList &dirtyActions) { onActionsChanged(dirtyActions, s_unityActionsPrefix); }); connect(m_unityActions, &Actions::loaded, this, [this] { if (m_menuInited) { onActionsChanged(m_unityActions->getAll().keys(), s_unityActionsPrefix); } else { initMenu(); } }); m_unityActions->load(); } if (!m_windowObjectPath.isEmpty()) { m_windowActions = new Actions(m_serviceName, m_windowObjectPath, this); connect(m_windowActions, &Actions::actionsChanged, this, [this](const QStringList &dirtyActions) { onActionsChanged(dirtyActions, s_windowActionsPrefix); }); connect(m_windowActions, &Actions::loaded, this, [this] { if (m_menuInited) { onActionsChanged(m_windowActions->getAll().keys(), s_windowActionsPrefix); } else { initMenu(); } }); m_windowActions->load(); } } WId Window::winId() const { return m_winId; } void Window::setWinId(WId winId) { m_winId = winId; } QString Window::serviceName() const { return m_serviceName; } QString Window::applicationObjectPath() const { return m_applicationObjectPath; } void Window::setApplicationObjectPath(const QString &applicationObjectPath) { m_applicationObjectPath = applicationObjectPath; } QString Window::unityObjectPath() const { return m_unityObjectPath; } void Window::setUnityObjectPath(const QString &unityObjectPath) { m_unityObjectPath = unityObjectPath; } QString Window::applicationMenuObjectPath() const { return m_applicationMenuObjectPath; } void Window::setApplicationMenuObjectPath(const QString &applicationMenuObjectPath) { m_applicationMenuObjectPath = applicationMenuObjectPath; } QString Window::menuBarObjectPath() const { return m_menuBarObjectPath; } void Window::setMenuBarObjectPath(const QString &menuBarObjectPath) { m_menuBarObjectPath = menuBarObjectPath; } QString Window::windowObjectPath() const { return m_windowObjectPath; } void Window::setWindowObjectPath(const QString &windowObjectPath) { m_windowObjectPath = windowObjectPath; } QString Window::currentMenuObjectPath() const { return m_currentMenuObjectPath; } QString Window::proxyObjectPath() const { return m_proxyObjectPath; } void Window::initMenu() { if (m_menuInited) { return; } if (!registerDBusObject()) { return; } // appmenu-gtk-module always announces a menu bar on every GTK window even if there is none // so we subscribe to the menu bar as soon as it shows up so we can figure out // if we have a menu bar, an app menu, or just nothing if (m_applicationMenu) { m_applicationMenu->start(0); } if (m_menuBar) { m_menuBar->start(0); } m_menuInited = true; } void Window::menuItemsChanged(const QVector &itemIds) { if (qobject_cast(sender()) != m_currentMenu) { return; } DBusMenuItemList items; for (uint id : itemIds) { const auto newItem = m_currentMenu->getItem(id); DBusMenuItem dBusItem{// 0 is menu, items start at 1 static_cast(id), gMenuToDBusMenuProperties(newItem)}; items.append(dBusItem); } emit ItemsPropertiesUpdated(items, {}); } void Window::menuChanged(const QVector &menuIds) { if (qobject_cast(sender()) != m_currentMenu) { return; } for (uint menu : menuIds) { emit LayoutUpdated(3 /*revision*/, menu); } } void Window::onMenuSubscribed(uint id) { // When it was a delayed GetLayout request, send the reply now const auto pendingReplies = m_pendingGetLayouts.values(id); if (!pendingReplies.isEmpty()) { for (const auto &pendingReply : pendingReplies) { if (pendingReply.type() != QDBusMessage::InvalidMessage) { auto reply = pendingReply.createReply(); DBusMenuLayoutItem item; uint revision = GetLayout(Utils::treeStructureToInt(id, 0, 0), 0, {}, item); reply << revision << QVariant::fromValue(item); QDBusConnection::sessionBus().send(reply); } } m_pendingGetLayouts.remove(id); } else { emit LayoutUpdated(2 /*revision*/, id); } } bool Window::getAction(const QString &name, GMenuAction &action) const { QString lookupName; Actions *actions = getActionsForAction(name, lookupName); if (!actions) { return false; } return actions->get(lookupName, action); } void Window::triggerAction(const QString &name, const QVariant &target, uint timestamp) { QString lookupName; Actions *actions = getActionsForAction(name, lookupName); if (!actions) { return; } actions->trigger(lookupName, target, timestamp); } Actions *Window::getActionsForAction(const QString &name, QString &lookupName) const { if (name.startsWith(QLatin1String("app."))) { lookupName = name.mid(4); return m_applicationActions; } else if (name.startsWith(QLatin1String("unity."))) { lookupName = name.mid(6); return m_unityActions; } else if (name.startsWith(QLatin1String("win."))) { lookupName = name.mid(4); return m_windowActions; } return nullptr; } void Window::onActionsChanged(const QStringList &dirty, const QString &prefix) { if (m_applicationMenu) { m_applicationMenu->actionsChanged(dirty, prefix); } if (m_menuBar) { m_menuBar->actionsChanged(dirty, prefix); } } bool Window::registerDBusObject() { Q_ASSERT(m_proxyObjectPath.isEmpty()); static int menus = 0; ++menus; new DbusmenuAdaptor(this); const QString objectPath = QStringLiteral("/MenuBar/%1").arg(QString::number(menus)); qDebug() << "Registering DBus object path" << objectPath; if (!QDBusConnection::sessionBus().registerObject(objectPath, this)) { qDebug() << "Failed to register object"; return false; } m_proxyObjectPath = objectPath; return true; } void Window::updateWindowProperties() { const bool hasMenu = ((m_applicationMenu && m_applicationMenu->hasMenu()) || (m_menuBar && m_menuBar->hasMenu())); if (!hasMenu) { emit requestRemoveWindowProperties(); return; } Menu *oldMenu = m_currentMenu; Menu *newMenu = qobject_cast(sender()); // set current menu as needed if (!m_currentMenu) { m_currentMenu = newMenu; // Menu Bar takes precedence over application menu } else if (m_currentMenu == m_applicationMenu && newMenu == m_menuBar) { qDebug() << "Switching from application menu to menu bar"; m_currentMenu = newMenu; // TODO update layout } if (m_currentMenu != oldMenu) { // update entire menu now emit LayoutUpdated(4 /*revision*/, 0); } emit requestWriteWindowProperties(); } // DBus bool Window::AboutToShow(int id) { // We always request the first time GetLayout is called and keep up-to-date internally // No need to have us prepare anything here Q_UNUSED(id); return false; } void Window::Event(int id, const QString &eventId, const QDBusVariant &data, uint timestamp) { Q_UNUSED(data); if (!m_currentMenu) { return; } // GMenu dbus doesn't have any "opened" or "closed" signals, we'll only handle "clicked" if (eventId == QLatin1String("clicked")) { const QVariantMap item = m_currentMenu->getItem(id); const QString action = item.value(QStringLiteral("action")).toString(); const QVariant target = item.value(QStringLiteral("target")); if (!action.isEmpty()) { triggerAction(action, target, timestamp); } } } DBusMenuItemList Window::GetGroupProperties(const QList &ids, const QStringList &propertyNames) { Q_UNUSED(ids); Q_UNUSED(propertyNames); return DBusMenuItemList(); } uint Window::GetLayout(int parentId, int recursionDepth, const QStringList &propertyNames, DBusMenuLayoutItem &dbusItem) { Q_UNUSED(recursionDepth); // TODO Q_UNUSED(propertyNames); int subscription; int sectionId; int index; Utils::intToTreeStructure(parentId, subscription, sectionId, index); if (!m_currentMenu) { return 1; } if (!m_currentMenu->hasSubscription(subscription)) { // let's serve multiple similar requests in one go once we've processed them m_pendingGetLayouts.insertMulti(subscription, message()); setDelayedReply(true); m_currentMenu->start(subscription); return 1; } bool ok; const GMenuItem section = m_currentMenu->getSection(subscription, sectionId, &ok); if (!ok) { qDebug() << "There is no section on" << subscription << "at" << sectionId << "with" << parentId; return 1; } // If a particular entry is requested, see what it is and resolve as necessary // for example the "File" entry on root is 0,0,1 but is a menu reference to e.g. 1,0,0 // so resolve that and return the correct menu if (index > 0) { // non-zero index indicates item within a menu but the index in the list still starts at zero if (section.items.count() < index) { qDebug() << "Requested index" << index << "on" << subscription << "at" << sectionId << "with" << parentId << "is out of bounds"; return 0; } const auto &requestedItem = section.items.at(index - 1); auto it = requestedItem.constFind(QStringLiteral(":submenu")); if (it != requestedItem.constEnd()) { const GMenuSection gmenuSection = qdbus_cast(it->value()); return GetLayout(Utils::treeStructureToInt(gmenuSection.subscription, gmenuSection.menu, 0), recursionDepth, propertyNames, dbusItem); } else { // TODO return 0; } } dbusItem.id = parentId; // TODO dbusItem.properties = {{QStringLiteral("children-display"), QStringLiteral("submenu")}}; int count = 0; const auto itemsToBeAdded = section.items; for (const auto &item : itemsToBeAdded) { DBusMenuLayoutItem child{ Utils::treeStructureToInt(section.id, sectionId, ++count), gMenuToDBusMenuProperties(item), {} // children }; dbusItem.children.append(child); // Now resolve section aliases auto it = item.constFind(QStringLiteral(":section")); if (it != item.constEnd()) { // references another place, add it instead GMenuSection gmenuSection = qdbus_cast(it->value()); // remember where the item came from and give it an appropriate ID // so updates signalled by the app will map to the right place int originalSubscription = gmenuSection.subscription; int originalMenu = gmenuSection.menu; // TODO start subscription if we don't have it auto items = m_currentMenu->getSection(gmenuSection.subscription, gmenuSection.menu).items; // Check whether it's an alias to an alias // FIXME make generic/recursive if (items.count() == 1) { const auto &aliasedItem = items.constFirst(); auto findIt = aliasedItem.constFind(QStringLiteral(":section")); if (findIt != aliasedItem.constEnd()) { GMenuSection gmenuSection2 = qdbus_cast(findIt->value()); items = m_currentMenu->getSection(gmenuSection2.subscription, gmenuSection2.menu).items; originalSubscription = gmenuSection2.subscription; originalMenu = gmenuSection2.menu; } } int aliasedCount = 0; for (const auto &aliasedItem : qAsConst(items)) { DBusMenuLayoutItem aliasedChild{ Utils::treeStructureToInt(originalSubscription, originalMenu, ++aliasedCount), gMenuToDBusMenuProperties(aliasedItem), {} // children }; dbusItem.children.append(aliasedChild); } } } // revision, unused in libdbusmenuqt return 1; } QDBusVariant Window::GetProperty(int id, const QString &property) { Q_UNUSED(id); Q_UNUSED(property); QDBusVariant value; return value; } QString Window::status() const { return QStringLiteral("normal"); } uint Window::version() const { return 4; } QVariantMap Window::gMenuToDBusMenuProperties(const QVariantMap &source) const { QVariantMap result; result.insert(QStringLiteral("label"), source.value(QStringLiteral("label")).toString()); if (source.contains(QLatin1String(":section"))) { result.insert(QStringLiteral("type"), QStringLiteral("separator")); } const bool isMenu = source.contains(QLatin1String(":submenu")); if (isMenu) { result.insert(QStringLiteral("children-display"), QStringLiteral("submenu")); } QString accel = source.value(QStringLiteral("accel")).toString(); if (!accel.isEmpty()) { QStringList shortcut; // TODO use regexp or something if (accel.contains(QLatin1String("")) || accel.contains(QLatin1String(""))) { shortcut.append(QStringLiteral("Control")); accel.remove(QLatin1String("")); accel.remove(QLatin1String("")); } if (accel.contains(QLatin1String(""))) { shortcut.append(QStringLiteral("Shift")); accel.remove(QLatin1String("")); } if (accel.contains(QLatin1String(""))) { shortcut.append(QStringLiteral("Alt")); accel.remove(QLatin1String("")); } if (accel.contains(QLatin1String(""))) { shortcut.append(QStringLiteral("Super")); accel.remove(QLatin1String("")); } if (!accel.isEmpty()) { // TODO replace "+" by "plus" and "-" by "minus" shortcut.append(accel); // TODO does gmenu support multiple? DBusMenuShortcut dbusShortcut; dbusShortcut.append(shortcut); // don't let it unwrap the list we append result.insert(QStringLiteral("shortcut"), QVariant::fromValue(dbusShortcut)); } } bool enabled = true; const QString actionName = Utils::itemActionName(source); GMenuAction action; // if no action is specified this is fine but if there is an action we don't have // disable the menu entry bool actionOk = true; if (!actionName.isEmpty()) { actionOk = getAction(actionName, action); enabled = actionOk && action.enabled; } // we used to only send this if not enabled but then dbusmenuimporter does not // update the enabled state when it changes from disabled to enabled result.insert(QStringLiteral("enabled"), enabled); bool visible = true; const QString hiddenWhen = source.value(QStringLiteral("hidden-when")).toString(); if (hiddenWhen == QLatin1String("action-disabled") && (!actionOk || !enabled)) { visible = false; } else if (hiddenWhen == QLatin1String("action-missing") && !actionOk) { visible = false; // While we have Global Menu we don't have macOS menu (where Quit, Help, etc is separate) } else if (hiddenWhen == QLatin1String("macos-menubar")) { visible = true; } result.insert(QStringLiteral("visible"), visible); QString icon = source.value(QStringLiteral("icon")).toString(); if (icon.isEmpty()) { icon = source.value(QStringLiteral("verb-icon")).toString(); } icon = Icons::actionIcon(actionName); if (!icon.isEmpty()) { result.insert(QStringLiteral("icon-name"), icon); } const QVariant target = source.value(QStringLiteral("target")); if (actionOk) { const auto actionStates = action.state; if (actionStates.count() == 1) { const auto &actionState = actionStates.first(); // assume this is a checkbox if (!isMenu) { if (actionState.type() == QVariant::Bool) { result.insert(QStringLiteral("toggle-type"), QStringLiteral("checkbox")); result.insert(QStringLiteral("toggle-state"), actionState.toBool() ? 1 : 0); } else if (actionState.type() == QVariant::String) { result.insert(QStringLiteral("toggle-type"), QStringLiteral("radio")); result.insert(QStringLiteral("toggle-state"), actionState == target ? 1 : 0); } } } } return result; } core-0.8/gmenuproxy/window.h000066400000000000000000000067731417504024300162230ustar00rootroot00000000000000/* SPDX-FileCopyrightText: 2018 Kai Uwe Broulik SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once #include #include #include #include #include // for WId #include #include "./extend/dbusmenutypes_p.h" #include "gdbusmenutypes_p.h" class QDBusVariant; class Actions; class Menu; class Window : public QObject, protected QDBusContext { Q_OBJECT // DBus Q_PROPERTY(QString Status READ status) Q_PROPERTY(uint Version READ version) public: Window(const QString &serviceName); ~Window() override; void init(); WId winId() const; void setWinId(WId winId); QString serviceName() const; QString applicationObjectPath() const; void setApplicationObjectPath(const QString &applicationObjectPath); QString unityObjectPath() const; void setUnityObjectPath(const QString &unityObjectPath); QString windowObjectPath() const; void setWindowObjectPath(const QString &windowObjectPath); QString applicationMenuObjectPath() const; void setApplicationMenuObjectPath(const QString &applicationMenuObjectPath); QString menuBarObjectPath() const; void setMenuBarObjectPath(const QString &menuBarObjectPath); QString currentMenuObjectPath() const; QString proxyObjectPath() const; // DBus bool AboutToShow(int id); void Event(int id, const QString &eventId, const QDBusVariant &data, uint timestamp); DBusMenuItemList GetGroupProperties(const QList &ids, const QStringList &propertyNames); uint GetLayout(int parentId, int recursionDepth, const QStringList &propertyNames, DBusMenuLayoutItem &dbusItem); QDBusVariant GetProperty(int id, const QString &property); QString status() const; uint version() const; Q_SIGNALS: // don't want to pollute X stuff into Menu, let all of that be in MenuProxy void requestWriteWindowProperties(); void requestRemoveWindowProperties(); // DBus void ItemActivationRequested(int id, uint timestamp); void ItemsPropertiesUpdated(const DBusMenuItemList &updatedProps, const DBusMenuItemKeysList &removedProps); void LayoutUpdated(uint revision, int parent); private: void initMenu(); bool registerDBusObject(); void updateWindowProperties(); bool getAction(const QString &name, GMenuAction &action) const; void triggerAction(const QString &name, const QVariant &target, uint timestamp = 0); Actions *getActionsForAction(const QString &name, QString &lookupName) const; void menuChanged(const QVector &menuIds); void menuItemsChanged(const QVector &itemIds); void onActionsChanged(const QStringList &dirty, const QString &prefix); void onMenuSubscribed(uint id); QVariantMap gMenuToDBusMenuProperties(const QVariantMap &source) const; WId m_winId = 0; QString m_serviceName; // original GMenu service (the gtk app) QString m_applicationObjectPath; QString m_unityObjectPath; QString m_windowObjectPath; QString m_applicationMenuObjectPath; QString m_menuBarObjectPath; QString m_currentMenuObjectPath; QString m_proxyObjectPath; // our object path on this proxy app QHash m_pendingGetLayouts; Menu *m_applicationMenu = nullptr; Menu *m_menuBar = nullptr; Menu *m_currentMenu = nullptr; Actions *m_applicationActions = nullptr; Actions *m_unityActions = nullptr; Actions *m_windowActions = nullptr; bool m_menuInited = false; }; core-0.8/notificationd/000077500000000000000000000000001417504024300151435ustar00rootroot00000000000000core-0.8/notificationd/CMakeLists.txt000066400000000000000000000024201417504024300177010ustar00rootroot00000000000000set(SRCS main.cpp application.cpp datehelper.cpp screenhelper.cpp notificationsmodel.cpp notificationserver.cpp notification.cpp notificationpopup.cpp notificationwindow.cpp historymodel.cpp settings.cpp utils.cpp dbus/notificationsadaptor.cpp resources.qrc ) # for Ubuntu # qt_add_dbus_adaptor(SRCS org.freedesktop.Notifications.xml notificationserver.h NotificationServer) qt5_add_dbus_adaptor(DBUS_SOURCES com.cutefish.Notification.xml application.h Application) set_source_files_properties(${DBUS_SOURCES} PROPERTIES SKIP_AUTOGEN ON) find_package(KF5WindowSystem) add_executable(cutefish-notificationd ${SRCS} ${DBUS_SOURCES}) target_link_libraries(cutefish-notificationd Qt5::Core Qt5::DBus Qt5::Quick Qt5::Widgets KF5::WindowSystem ) install(TARGETS cutefish-notificationd DESTINATION /usr/bin COMPONENT Runtime ) file(GLOB TS_FILES translations/*.ts) qt5_create_translation(QM_FILES ${TS_FILES}) add_custom_target(notificationd_translations DEPENDS ${QM_FILES} SOURCES ${TS_FILES}) add_dependencies(cutefish-notificationd notificationd_translations) install(FILES ${QM_FILES} DESTINATION /usr/share/cutefish-notificationd/translations) core-0.8/notificationd/application.cpp000066400000000000000000000074621417504024300201630ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: Reion Wong * * 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 * 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 "application.h" #include "notificationsmodel.h" #include "screenhelper.h" #include "notificationadaptor.h" #include "historymodel.h" #include "notificationpopup.h" #include #include #include #include #include #include #include #include #include #include #include #include Application::Application(int& argc, char** argv) : QApplication(argc, argv) , m_notificationServer(NotificationServer::self()) , m_model(NotificationsModel::self()) , m_window(nullptr) , m_settings(Settings::self()) , m_instance(false) { if (QDBusConnection::sessionBus().registerService("com.cutefish.Notification")) { setOrganizationName("cutefishos"); // Translations QLocale locale; QString qmFilePath = QString("%1/%2.qm").arg("/usr/share/cutefish-notificationd/translations/").arg(locale.name()); if (QFile::exists(qmFilePath)) { QTranslator *translator = new QTranslator(this); if (translator->load(qmFilePath)) { installTranslator(translator); } else { translator->deleteLater(); } } new NotificationAdaptor(this); QDBusConnection::sessionBus().registerObject("/Notification", this); qmlRegisterType("Cutefish.Notification", 1, 0, "NotificationsModel"); qmlRegisterType("Cutefish.Notification", 1, 0, "HistoryModel"); qmlRegisterType("Cutefish.Notification", 1, 0, "ScreenHelper"); qmlRegisterType("Cutefish.Notification", 1, 0, "NotificationPopup"); m_instance = true; } } void Application::showWindow() { if (m_window) m_window->open(); } void Application::setDoNotDisturb(bool enabled) { m_settings->setDoNotDisturb(enabled); } int Application::run() { if (!parseCommandLineArgs()) return 0; QQmlApplicationEngine engine; engine.rootContext()->setContextProperty("notificationsModel", m_model); engine.rootContext()->setContextProperty("Settings", m_settings); engine.load(QUrl("qrc:/qml/main.qml")); m_window = new NotificationWindow; return QApplication::exec(); } bool Application::parseCommandLineArgs() { QCommandLineParser parser; parser.setApplicationDescription(QStringLiteral("Notification")); parser.addHelpOption(); QCommandLineOption showOption(QStringList() << "s" << "show" << "Show dialog"); parser.addOption(showOption); parser.process(arguments()); if (m_instance) { QPixmapCache::setCacheLimit(2048); } else { QDBusInterface iface("com.cutefish.Notification", "/Notification", "com.cutefish.Notification", QDBusConnection::sessionBus(), this); if (iface.isValid() && parser.isSet(showOption)) { iface.call("showWindow"); } } return m_instance; } core-0.8/notificationd/application.h000066400000000000000000000024641417504024300176250ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: Reion Wong * * 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 * 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 APPLICATION_H #define APPLICATION_H #include #include "notificationwindow.h" #include "settings.h" class NotificationServer; class NotificationsModel; class Application : public QApplication { Q_OBJECT public: explicit Application(int& argc, char** argv); void showWindow(); void setDoNotDisturb(bool enabled); int run(); bool parseCommandLineArgs(); private: NotificationServer *m_notificationServer; NotificationsModel *m_model; NotificationWindow *m_window; Settings *m_settings; bool m_instance; }; #endif // APPLICATION_H core-0.8/notificationd/com.cutefish.Notification.xml000066400000000000000000000005521417504024300227030ustar00rootroot00000000000000 core-0.8/notificationd/datehelper.cpp000066400000000000000000000015261417504024300177700ustar00rootroot00000000000000#include "datehelper.h" #include DateHelper::DateHelper(QObject *parent) : QObject(parent) { } QString DateHelper::friendlyTime(const QDateTime &time) { QDateTime now = QDateTime::currentDateTime(); qint64 minutes = qRound64(time.secsTo(now) / 60.0f); if (minutes < 1) return tr("Now"); else if (minutes == 1) return tr("1 minute ago"); else if (minutes < 60) return tr("%1 minutes ago").arg(minutes); qint64 hours = qRound64(minutes / 60.0f); if (hours == 1) return tr("1 hour ago"); else if (hours < 24) return tr("%1 hours ago").arg(hours); qint64 days = qRound64(hours / 24.0f); if (days == 1) return tr("1 day ago"); else if (days <= 10) return tr("%1 days ago").arg(days); return time.toString(Qt::DefaultLocaleShortDate); } core-0.8/notificationd/datehelper.h000066400000000000000000000004151417504024300174310ustar00rootroot00000000000000#ifndef DATEHELPER_H #define DATEHELPER_H #include class DateHelper : public QObject { Q_OBJECT public: explicit DateHelper(QObject *parent = nullptr); Q_INVOKABLE static QString friendlyTime(const QDateTime &time); }; #endif // DATEHELPER_H core-0.8/notificationd/dbus/000077500000000000000000000000001417504024300161005ustar00rootroot00000000000000core-0.8/notificationd/dbus/notificationsadaptor.cpp000066400000000000000000000036401417504024300230330ustar00rootroot00000000000000/* * This file was generated by qdbusxml2cpp version 0.8 * Command line was: qdbusxml2cpp -m -a notificationsadaptor -i notificationserver.h -l NotificationServer /home/reion/Cutefish/core/notificationd/org.freedesktop.Notifications.xml * * qdbusxml2cpp is Copyright (C) 2020 The Qt Company Ltd. * * This is an auto-generated file. * Do not edit! All changes made to it will be lost. */ #include "notificationsadaptor.h" #include #include #include #include #include #include #include /* * Implementation of adaptor class NotificationsAdaptor */ NotificationsAdaptor::NotificationsAdaptor(NotificationServer *parent) : QDBusAbstractAdaptor(parent) { // constructor setAutoRelaySignals(true); } NotificationsAdaptor::~NotificationsAdaptor() { // destructor } void NotificationsAdaptor::CloseNotification(uint id) { // handle method call org.freedesktop.Notifications.CloseNotification parent()->CloseNotification(id); } QStringList NotificationsAdaptor::GetCapabilities() { // handle method call org.freedesktop.Notifications.GetCapabilities return parent()->GetCapabilities(); } QString NotificationsAdaptor::GetServerInformation(QString &vendor, QString &version, QString &spec_version) { // handle method call org.freedesktop.Notifications.GetServerInformation return parent()->GetServerInformation(vendor, version, spec_version); } uint NotificationsAdaptor::Notify(const QString &app_name, uint replaces_id, const QString &app_icon, const QString &summary, const QString &body, const QStringList &actions, const QVariantMap &hints, int expire_timeout) { // handle method call org.freedesktop.Notifications.Notify return parent()->Notify(app_name, replaces_id, app_icon, summary, body, actions, hints, expire_timeout); } #include "notificationsadaptor.moc" core-0.8/notificationd/dbus/notificationsadaptor.h000066400000000000000000000064641417504024300225070ustar00rootroot00000000000000/* * This file was generated by qdbusxml2cpp version 0.8 * Command line was: qdbusxml2cpp -m -a notificationsadaptor -i notificationserver.h -l NotificationServer /home/reion/Cutefish/core/notificationd/org.freedesktop.Notifications.xml * * qdbusxml2cpp is Copyright (C) 2020 The Qt Company Ltd. * * This is an auto-generated file. * This file may have been hand-edited. Look for HAND-EDIT comments * before re-generating it. */ #ifndef NOTIFICATIONSADAPTOR_H #define NOTIFICATIONSADAPTOR_H #include #include #include "notificationserver.h" QT_BEGIN_NAMESPACE class QByteArray; template class QList; template class QMap; class QString; class QStringList; class QVariant; QT_END_NAMESPACE /* * Adaptor class for interface org.freedesktop.Notifications */ class NotificationsAdaptor: public QDBusAbstractAdaptor { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.freedesktop.Notifications") Q_CLASSINFO("D-Bus Introspection", "" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" "") public: NotificationsAdaptor(NotificationServer *parent); virtual ~NotificationsAdaptor(); inline NotificationServer *parent() const { return static_cast(QObject::parent()); } public: // PROPERTIES public Q_SLOTS: // METHODS void CloseNotification(uint id); QStringList GetCapabilities(); QString GetServerInformation(QString &vendor, QString &version, QString &spec_version); uint Notify(const QString &app_name, uint replaces_id, const QString &app_icon, const QString &summary, const QString &body, const QStringList &actions, const QVariantMap &hints, int expire_timeout); Q_SIGNALS: // SIGNALS void ActionInvoked(uint in0, const QString &in1); void NotificationClosed(uint in0, uint in1); }; #endif core-0.8/notificationd/historymodel.cpp000066400000000000000000000100751417504024300203740ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: Reion Wong * * 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 * 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 "historymodel.h" #include "datehelper.h" #include #include #include static HistoryModel *s_historyModel = nullptr; HistoryModel *HistoryModel::self() { if (!s_historyModel) s_historyModel = new HistoryModel; return s_historyModel; } HistoryModel::HistoryModel(QObject *parent) : QAbstractListModel(parent) { initDatas(); } QVariant HistoryModel::data(const QModelIndex &index, int role) const { const Notification ¬ification = m_notifications.at(index.row()); switch (role) { case HistoryModel::IdRole: return notification.id; case HistoryModel::SummaryRole: return notification.summary; case HistoryModel::ImageRole: return ""; case HistoryModel::CreatedRole: return DateHelper::friendlyTime(notification.created); case HistoryModel::UpdatedRole: return DateHelper::friendlyTime(notification.updated); case HistoryModel::BodyRole: return notification.body; case HistoryModel::IconNameRole: return notification.appIcon; case HistoryModel::HasDefaultActionRole: return notification.actions.contains("default"); default: break; } return QVariant(); } int HistoryModel::rowCount(const QModelIndex &parent) const { Q_UNUSED(parent); return m_notifications.size(); } QHash HistoryModel::roleNames() const { static QHash s_roles; if (s_roles.isEmpty()) { // This generates role names from the Roles enum in the form of: FooRole -> foo const QMetaEnum e = QMetaEnum::fromType(); // Qt built-in roles we use s_roles.insert(Qt::DisplayRole, QByteArrayLiteral("display")); s_roles.insert(Qt::DecorationRole, QByteArrayLiteral("decoration")); for (int i = 0; i < e.keyCount(); ++i) { const int value = e.value(i); QByteArray key(e.key(i)); key[0] = key[0] + 32; // lower case first letter key.chop(4); // strip "Role" suffix s_roles.insert(value, key); } s_roles.insert(HistoryModel::IdRole, QByteArrayLiteral("notificationId")); // id is QML-reserved } return s_roles; } void HistoryModel::add(const Notification ¬ification) { beginInsertRows(QModelIndex(), 0, 0); m_notifications.prepend(std::move(notification)); endInsertRows(); save(); } void HistoryModel::remove(int index) { if (index > m_notifications.size() && index < 0) return; beginRemoveRows(QModelIndex(), index, index); m_notifications.removeAt(index); endRemoveRows(); save(); } void HistoryModel::clearAll() { beginResetModel(); m_notifications.clear(); endResetModel(); save(); } void HistoryModel::save() { QSettings settings(QSettings::UserScope, "cutefishos", "notifications"); settings.clear(); QByteArray datas; QDataStream out(&datas, QIODevice::WriteOnly); out << m_notifications; settings.setValue("datas", datas); } void HistoryModel::initDatas() { QSettings settings(QSettings::UserScope, "cutefishos", "notifications"); QByteArray listByteArray = settings.value("datas").toByteArray(); QDataStream in(&listByteArray, QIODevice::ReadOnly); in >> m_notifications; } void HistoryModel::updateTime() { emit layoutChanged(); } core-0.8/notificationd/historymodel.h000066400000000000000000000033321417504024300200370ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: Reion Wong * * 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 * 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 HISTORYMODEL_H #define HISTORYMODEL_H #include #include "notification.h" class HistoryModel : public QAbstractListModel { Q_OBJECT public: enum Roles { IdRole = Qt::UserRole + 1, SummaryRole = Qt::DisplayRole, ImageRole = Qt::DecorationRole, CreatedRole, UpdatedRole, BodyRole, IconNameRole, HasDefaultActionRole }; Q_ENUM(Roles) static HistoryModel* self(); explicit HistoryModel(QObject *parent = nullptr); QVariant data(const QModelIndex &index, int role) const override; int rowCount(const QModelIndex &parent = QModelIndex()) const override; QHash roleNames() const override; Q_INVOKABLE void add(const Notification ¬ification); Q_INVOKABLE void remove(int index); Q_INVOKABLE void clearAll(); Q_INVOKABLE void save(); void initDatas(); void updateTime(); private: QVector m_notifications; }; #endif // HISTORYMODEL_H core-0.8/notificationd/images/000077500000000000000000000000001417504024300164105ustar00rootroot00000000000000core-0.8/notificationd/images/dark/000077500000000000000000000000001417504024300173315ustar00rootroot00000000000000core-0.8/notificationd/images/dark/clear.svg000066400000000000000000000020201417504024300211320ustar00rootroot00000000000000 image/svg+xml core-0.8/notificationd/images/dark/close.svg000066400000000000000000000015421417504024300211610ustar00rootroot00000000000000 core-0.8/notificationd/images/light/000077500000000000000000000000001417504024300175175ustar00rootroot00000000000000core-0.8/notificationd/images/light/clear.svg000066400000000000000000000020301417504024300213210ustar00rootroot00000000000000 image/svg+xml core-0.8/notificationd/images/light/close.svg000066400000000000000000000015531417504024300213510ustar00rootroot00000000000000 core-0.8/notificationd/main.cpp000066400000000000000000000020731417504024300165750ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: Reion Wong * * 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 * 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 "application.h" #include #include "notificationsmodel.h" #include "screenhelper.h" int main(int argc, char *argv[]) { // QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps, true); // QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling, true); Application a(argc, argv); return a.run(); } core-0.8/notificationd/notification.cpp000066400000000000000000000023511417504024300203360ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: Reion Wong * * 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 * 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 "notification.h" QDataStream &operator<<(QDataStream &argument, const Notification &info) { argument << info.service << info.summary << info.body << info.appName << info.appIcon << info.created << info.updated; return argument; } const QDataStream &operator>>(QDataStream &argument, Notification &info) { argument >> info.service >> info.summary; argument >> info.body >> info.appName >> info.appIcon; argument >> info.created >> info.updated; return argument; } core-0.8/notificationd/notification.h000066400000000000000000000032231417504024300200020ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: Reion Wong * * 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 * 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 NOTIFICATION_H #define NOTIFICATION_H #include #include #include class Notification { public: uint id = 0; QString service; QString summary; QString body; QString appName; QString appIcon; QStringList actions; int timeout = -1; QDateTime created; QDateTime updated; inline bool operator==(const Notification &other) const { return service == other.service && summary == other.summary && body == other.body && appName == other.appName && appIcon == other.appIcon && created == other.created && updated == other.updated; } friend QDataStream &operator<<(QDataStream &argument, const Notification &info); friend const QDataStream &operator>>(QDataStream &argument, Notification &info); }; Q_DECLARE_METATYPE(Notification) #endif // NOTIFICATION_H core-0.8/notificationd/notificationpopup.cpp000066400000000000000000000024301417504024300214200ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: Kate Leet * * 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 * 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 "notificationpopup.h" #include #include #include NotificationPopup::NotificationPopup(QQuickView *parent) : QQuickView(parent) { installEventFilter(this); setResizeMode(QQuickView::SizeRootObjectToView); setColor(Qt::transparent); } bool NotificationPopup::eventFilter(QObject *object, QEvent *event) { if (event->type() == QEvent::Show) { KWindowSystem::setState(winId(), NET::SkipTaskbar | NET::SkipPager | NET::SkipSwitcher); } return QObject::eventFilter(object, event); } core-0.8/notificationd/notificationpopup.h000066400000000000000000000020151417504024300210640ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: Kate Leet * * 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 * 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 NOTIFICATIONPOPUP_H #define NOTIFICATIONPOPUP_H #include class NotificationPopup : public QQuickView { Q_OBJECT public: explicit NotificationPopup(QQuickView *parent = nullptr); bool eventFilter(QObject *object, QEvent *event) override; }; #endif // NOTIFICATIONPOPUP_H core-0.8/notificationd/notificationserver.cpp000066400000000000000000000115751417504024300215750ustar00rootroot00000000000000/* * SPDX-FileCopyrightText: 2021 Reion Wong * SPDX-FileCopyrightText: 2018-2019 Kai Uwe Broulik * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "notificationserver.h" #include "dbus/notificationsadaptor.h" #include "utils.h" #include static NotificationServer *NOTIFICATION_SERVER_SELF = nullptr; NotificationServer *NotificationServer::self() { if (!NOTIFICATION_SERVER_SELF) NOTIFICATION_SERVER_SELF = new NotificationServer; return NOTIFICATION_SERVER_SELF; } NotificationServer::NotificationServer(QObject *parent) : QObject(parent) , m_notificationWatcher(nullptr) { new NotificationsAdaptor(this); QDBusConnectionInterface *iface = QDBusConnection::sessionBus().interface(); QDBusConnection::sessionBus().registerObject("/org/freedesktop/Notifications", this); auto registration = iface->registerService("org.freedesktop.Notifications", QDBusConnectionInterface::ReplaceExistingService, QDBusConnectionInterface::DontAllowReplacement); } uint NotificationServer::Notify(const QString &app_name, uint replaces_id, const QString &app_icon, const QString &summary, const QString &body, const QStringList &actions, const QVariantMap &hints, int timeout) { Q_UNUSED(hints); uint id = 0; const bool wasReplaced = replaces_id > 0; if (wasReplaced) { id = replaces_id; } else { if (!m_highestId) ++m_highestId; id = m_highestId; ++m_highestId; } Notification notification; notification.id = id; notification.created = QDateTime::currentDateTimeUtc(); notification.service = message().service(); notification.summary = summary; notification.body = body; notification.appName = app_name; notification.appIcon = app_icon; notification.actions = actions; notification.timeout = timeout; if (notification.appIcon.startsWith("file://")) notification.appIcon = notification.appIcon.replace("file://", ""); uint pid = 0; QDBusReply pidReply = connection().interface()->servicePid(message().service()); if (pidReply.isValid()) { pid = pidReply.value(); } if (pid > 0) { // 查找 app name if (notification.appIcon.isEmpty()) { // const QString processName = Utils::processNameFromPid(pid); // notification.appIcon = processName; } } if (m_lastNotification.appName == notification.appName && m_lastNotification.summary == notification.summary && m_lastNotification.body == notification.body && m_lastNotification.created.msecsTo(notification.created) < 1000) { return 0; } m_lastNotification = notification; if (wasReplaced) { notification.updated = QDateTime::currentDateTimeUtc(); emit notificationReplaced(replaces_id, notification); } else { emit notificationAdded(notification); } return id; } void NotificationServer::CloseNotification(uint id) { Q_UNUSED(id); } QStringList NotificationServer::GetCapabilities() const { return QStringList{ QStringLiteral("body"), QStringLiteral("body-hyperlinks"), QStringLiteral("body-markup"), QStringLiteral("body-images"), QStringLiteral("icon-static"), QStringLiteral("actions"), QStringLiteral("persistence"), QStringLiteral("inline-reply"), QStringLiteral("inhibitions") }; } QString NotificationServer::GetServerInformation(QString &vendor, QString &version, QString &specVersion) const { vendor = "CutefishOS"; version = "1.0"; specVersion = "1.2"; return "Cutefish"; } uint NotificationServer::Inhibit(const QString &desktop_entry, const QString &reason, const QVariantMap &hints) { return 0; } void NotificationServer::UnInhibit(uint cookie) { Q_UNUSED(cookie) } bool NotificationServer::inhibited() const { return false; } void NotificationServer::RegisterWatcher() { m_notificationWatcher->addWatchedService(message().service()); } void NotificationServer::UnRegisterWatcher() { m_notificationWatcher->removeWatchedService(message().service()); } void NotificationServer::InvokeAction(uint id, const QString &actionKey) { Q_EMIT ActionInvoked(id, actionKey); } void NotificationServer::closeNotification(uint id, NotificationServer::CloseReason reason) { emit notificationRemoved(id, reason); } core-0.8/notificationd/notificationserver.h000066400000000000000000000044551417504024300212410ustar00rootroot00000000000000/* * SPDX-FileCopyrightText: 2021 Reion Wong * SPDX-FileCopyrightText: 2018-2019 Kai Uwe Broulik * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef NOTIFICATIONSERVER_H #define NOTIFICATIONSERVER_H #include #include #include #include #include "notification.h" class NotificationServer : public QObject, protected QDBusContext { Q_OBJECT public: enum class CloseReason { Expired = 1, ///< The notification timed out DismissedByUser = 2, ///< The user explicitly closed or acknowledged the notification Revoked = 3, ///< The notification was revoked by the issuing app because it is no longer relevant }; Q_ENUM(CloseReason) static NotificationServer *self(); explicit NotificationServer(QObject *parent = nullptr); // DBus uint Notify(const QString &app_name, uint replaces_id, const QString &app_icon, const QString &summary, const QString &body, const QStringList &actions, const QVariantMap &hints, int timeout); void CloseNotification(uint id); QStringList GetCapabilities() const; QString GetServerInformation(QString &vendor, QString &version, QString &specVersion) const; // Inhibitions uint Inhibit(const QString &desktop_entry, const QString &reason, const QVariantMap &hints); void UnInhibit(uint cookie); bool inhibited() const; // property getter // Notifition watcher void RegisterWatcher(); void UnRegisterWatcher(); void InvokeAction(uint id, const QString &actionKey); // Self void closeNotification(uint id, CloseReason reason); Q_SIGNALS: // DBus void NotificationClosed(uint id, uint reason); void ActionInvoked(uint id, const QString &actionKey); // Self void notificationAdded(const Notification ¬ification); void notificationReplaced(uint replacedId, const Notification ¬ification); void notificationRemoved(uint id, CloseReason reason); private: uint m_highestId = -1; Notification m_lastNotification; QDBusServiceWatcher *m_notificationWatcher; }; #endif // NOTIFICATIONSERVER_H core-0.8/notificationd/notificationsmodel.cpp000066400000000000000000000174771417504024300215610ustar00rootroot00000000000000/* * SPDX-FileCopyrightText: 2021 Reion Wong * SPDX-FileCopyrightText: 2018-2019 Kai Uwe Broulik * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "notificationsmodel.h" #include "historymodel.h" #include "notification.h" #include "settings.h" #include #include static const int s_notificationsLimit = 1000; static NotificationsModel *NOTIFICATIONS_MODEL = nullptr; NotificationsModel *NotificationsModel::self() { if (!NOTIFICATIONS_MODEL) NOTIFICATIONS_MODEL = new NotificationsModel; return NOTIFICATIONS_MODEL; } NotificationsModel::NotificationsModel(QObject *parent) : QAbstractListModel(parent) { m_pendingRemovalTimer.setSingleShot(true); m_pendingRemovalTimer.setInterval(50); connect(&m_pendingRemovalTimer, &QTimer::timeout, this, [this] { QVector rowsToBeRemoved; rowsToBeRemoved.reserve(m_pendingRemovals.count()); for (uint id : qAsConst(m_pendingRemovals)) { int row = rowOfNotification(id); // oh the complexity... if (row == -1) { continue; } rowsToBeRemoved.append(row); } removeRows(rowsToBeRemoved); }); connect(NotificationServer::self(), &NotificationServer::notificationAdded, this, &NotificationsModel::onNotificationAdded); connect(NotificationServer::self(), &NotificationServer::notificationReplaced, this, &NotificationsModel::onNotificationReplaced); connect(NotificationServer::self(), &NotificationServer::notificationRemoved, this, &NotificationsModel::onNotificationRemoved); } QVariant NotificationsModel::data(const QModelIndex &index, int role) const { const Notification ¬ification = m_notifications.at(index.row()); switch (role) { case NotificationsModel::IdRole: return notification.id; case NotificationsModel::SummaryRole: return notification.summary; case NotificationsModel::ImageRole: return ""; case NotificationsModel::CreatedRole: return notification.created; case NotificationsModel::BodyRole: return notification.body; case NotificationsModel::IconNameRole: return notification.appIcon; case NotificationsModel::HasDefaultActionRole: return notification.actions.contains("default"); default: break; } return QVariant(); } bool NotificationsModel::setData(const QModelIndex &index, const QVariant &value, int role) { // Notification ¬ification = m_notifications[index.row()]; bool dirty = false; return dirty; } int NotificationsModel::rowCount(const QModelIndex &parent) const { if (parent.isValid()) return 0; return m_notifications.size(); } QHash NotificationsModel::roleNames() const { static QHash s_roles; if (s_roles.isEmpty()) { // This generates role names from the Roles enum in the form of: FooRole -> foo const QMetaEnum e = QMetaEnum::fromType(); // Qt built-in roles we use s_roles.insert(Qt::DisplayRole, QByteArrayLiteral("display")); s_roles.insert(Qt::DecorationRole, QByteArrayLiteral("decoration")); for (int i = 0; i < e.keyCount(); ++i) { const int value = e.value(i); QByteArray key(e.key(i)); key[0] = key[0] + 32; // lower case first letter key.chop(4); // strip "Role" suffix s_roles.insert(value, key); } s_roles.insert(NotificationsModel::IdRole, QByteArrayLiteral("notificationId")); // id is QML-reserved } return s_roles; } void NotificationsModel::expired(uint id) { int row = rowOfNotification(id); if (row > -1) { onNotificationRemoved(id, NotificationServer::CloseReason::Expired); } } void NotificationsModel::close(uint id) { if (rowOfNotification(id) > -1) { NotificationServer::self()->closeNotification(id, NotificationServer::CloseReason::DismissedByUser); } } void NotificationsModel::invokeDefaultAction(uint notificationId) { const int row = rowOfNotification(notificationId); if (row == -1) { return; } const Notification ¬ification = m_notifications.at(row); if (!notification.actions.contains("default")) { return; } NotificationServer::self()->InvokeAction(notificationId, "default"); } int NotificationsModel::rowOfNotification(uint id) const { auto it = std::find_if(m_notifications.constBegin(), m_notifications.constEnd(), [id](const Notification &item) { return item.id == id; }); if (it == m_notifications.constEnd()) { return -1; } return std::distance(m_notifications.constBegin(), it); } void NotificationsModel::removeRows(const QVector &rows) { if (rows.isEmpty()) { return; } QVector rowsToBeRemoved(rows); std::sort(rowsToBeRemoved.begin(), rowsToBeRemoved.end()); QVector> clearQueue; QPair clearRange{rowsToBeRemoved.first(), rowsToBeRemoved.first()}; for (int row : rowsToBeRemoved) { if (row > clearRange.second + 1) { clearQueue.append(clearRange); clearRange.first = row; } clearRange.second = row; } if (clearQueue.isEmpty() || clearQueue.last() != clearRange) { clearQueue.append(clearRange); } int rowsRemoved = 0; for (int i = clearQueue.count() - 1; i >= 0; --i) { const auto &range = clearQueue.at(i); beginRemoveRows(QModelIndex(), range.first, range.second); for (int j = range.second; j >= range.first; --j) { m_notifications.removeAt(j); ++rowsRemoved; } endRemoveRows(); } Q_ASSERT(rowsRemoved == rowsToBeRemoved.count()); m_pendingRemovals.clear(); } void NotificationsModel::onNotificationAdded(const Notification ¬ification) { // Do Not Disturb Mode: // Add directly to the historical model. if (Settings::self()->doNotDisturb()) { HistoryModel::self()->add(notification); return; } if (m_notifications.size() >= s_notificationsLimit) { const int cleanupCount = s_notificationsLimit / 2; beginRemoveRows(QModelIndex(), 0, cleanupCount - 1); for (int i = 0; i < cleanupCount; ++i) { m_notifications.removeAt(0); } endRemoveRows(); } beginInsertRows(QModelIndex(), m_notifications.size(), m_notifications.size()); m_notifications.append(std::move(notification)); endInsertRows(); } void NotificationsModel::onNotificationReplaced(uint replacedId, const Notification ¬ification) { } void NotificationsModel::onNotificationRemoved(uint removedId, NotificationServer::CloseReason reason) { const int row = rowOfNotification(removedId); if (row == -1) { return; } // When a notification expired, keep it around in the history and mark it as such if (reason == NotificationServer::CloseReason::Expired) { const QModelIndex idx = NotificationsModel::index(row, 0); Notification ¬ification = m_notifications[row]; // notification.setExpired(true); notification.actions.clear(); emit dataChanged(idx, idx); HistoryModel::self()->add(notification); // return; } // Otherwise if explicitly closed by either user or app, mark it for removal // some apps are notorious for closing a bunch of notifications at once // causing newer notifications to move up and have a dialogs created for them // just to then be discarded causing excess CPU usage if (!m_pendingRemovals.contains(removedId)) { m_pendingRemovals.append(removedId); } if (!m_pendingRemovalTimer.isActive()) { m_pendingRemovalTimer.start(); } } core-0.8/notificationd/notificationsmodel.h000066400000000000000000000034171417504024300212130ustar00rootroot00000000000000/* * SPDX-FileCopyrightText: 2021 Reion Wong * SPDX-FileCopyrightText: 2018-2019 Kai Uwe Broulik * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef NOTIFICATIONSMODEL_H #define NOTIFICATIONSMODEL_H #include #include #include #include "notificationserver.h" class Notification; class NotificationsModel : public QAbstractListModel { Q_OBJECT public: enum Roles { IdRole = Qt::UserRole + 1, SummaryRole = Qt::DisplayRole, ImageRole = Qt::DecorationRole, CreatedRole, UpdatedRole, BodyRole, IconNameRole, HasDefaultActionRole }; Q_ENUM(Roles) static NotificationsModel *self(); explicit NotificationsModel(QObject *parent = nullptr); QVariant data(const QModelIndex &index, int role) const override; bool setData(const QModelIndex &index, const QVariant &value, int role) override; int rowCount(const QModelIndex &parent = QModelIndex()) const override; QHash roleNames() const override; Q_INVOKABLE void expired(uint id); Q_INVOKABLE void close(uint id); Q_INVOKABLE void invokeDefaultAction(uint id); int rowOfNotification(uint id) const; void removeRows(const QVector &rows); private slots: void onNotificationAdded(const Notification ¬ification); void onNotificationReplaced(uint replacedId, const Notification ¬ification); void onNotificationRemoved(uint notificationId, NotificationServer::CloseReason reason); private: QVector m_notifications; QVector m_pendingRemovals; QTimer m_pendingRemovalTimer; }; #endif // NOTIFICATIONSMODEL_H core-0.8/notificationd/notificationwindow.cpp000066400000000000000000000050041417504024300215640ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: Kate Leet * * 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 * 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 "notificationwindow.h" #include "notificationsmodel.h" #include "historymodel.h" #include #include #include NotificationWindow::NotificationWindow(QQuickView *parent) : QQuickView(parent) { installEventFilter(this); setFlags(Qt::Popup); setResizeMode(QQuickView::SizeRootObjectToView); setColor(Qt::transparent); rootContext()->setContextProperty("NotificationDialog", this); rootContext()->setContextProperty("notificationsModel", NotificationsModel::self()); rootContext()->setContextProperty("historyModel", HistoryModel::self()); // KWindowEffects::slideWindow(winId(), KWindowEffects::RightEdge); setSource(QUrl("qrc:/qml/NotificationWindow.qml")); setVisible(false); } void NotificationWindow::open() { setVisible(true); setMouseGrabEnabled(true); setKeyboardGrabEnabled(true); } bool NotificationWindow::eventFilter(QObject *object, QEvent *event) { if (event->type() == QEvent::MouseButtonPress) { if (QWindow *w = qobject_cast(object)) { if (!w->geometry().contains(static_cast(event)->globalPos())) { QQuickView::setVisible(false); } } } else if (event->type() == QEvent::KeyPress) { QKeyEvent *keyEvent = static_cast(event); if (keyEvent->key() == Qt::Key_Escape) { QQuickView::setVisible(false); } } else if (event->type() == QEvent::Show) { KWindowSystem::setState(winId(), NET::SkipTaskbar | NET::SkipPager | NET::SkipSwitcher); HistoryModel::self()->updateTime(); } else if (event->type() == QEvent::Hide) { setMouseGrabEnabled(false); setKeyboardGrabEnabled(false); } return QObject::eventFilter(object, event); } core-0.8/notificationd/notificationwindow.h000066400000000000000000000020441417504024300212320ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: Kate Leet * * 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 * 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 NOTIFICATIONWINDOW_H #define NOTIFICATIONWINDOW_H #include class NotificationWindow : public QQuickView { Q_OBJECT public: explicit NotificationWindow(QQuickView *parent = nullptr); void open(); bool eventFilter(QObject *object, QEvent *event) override; }; #endif // NOTIFICATIONWINDOW_H core-0.8/notificationd/org.freedesktop.Notifications.xml000066400000000000000000000047611417504024300236060ustar00rootroot00000000000000 core-0.8/notificationd/qml/000077500000000000000000000000001417504024300157345ustar00rootroot00000000000000core-0.8/notificationd/qml/IconButton.qml000066400000000000000000000043251417504024300205370ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: Reion Wong * * 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 * 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 . */ import QtQuick 2.12 import QtQuick.Controls 2.12 import QtQuick.Layouts 1.12 import FishUI 1.0 as FishUI Item { id: control property url source property real size: 30 property string popupText signal leftButtonClicked signal rightButtonClicked MouseArea { id: mouseArea anchors.fill: parent acceptedButtons: Qt.LeftButton | Qt.RightButton hoverEnabled: control.visible ? true : false onClicked: { if (mouse.button === Qt.LeftButton) control.leftButtonClicked() else if (mouse.button === Qt.RightButton) control.rightButtonClicked() } } Rectangle { anchors.fill: parent anchors.margins: 1 // radius: parent.height * 0.2 radius: parent.height / 2 color: { if (mouseArea.containsMouse) { if (mouseArea.containsPress) return (FishUI.Theme.darkMode) ? Qt.rgba(255, 255, 255, 0.3) : Qt.rgba(0, 0, 0, 0.2) else return (FishUI.Theme.darkMode) ? Qt.rgba(255, 255, 255, 0.2) : Qt.rgba(0, 0, 0, 0.1) } return "transparent" } } Image { id: iconImage anchors.centerIn: parent width: parent.height * 0.8 height: width sourceSize.width: width sourceSize.height: height source: control.source asynchronous: true antialiasing: true smooth: false } } core-0.8/notificationd/qml/NotificationWindow.qml000066400000000000000000000254021417504024300222700ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: Reion Wong * * 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 * 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 . */ import QtQuick 2.12 import QtQml 2.12 import QtQuick.Controls 2.12 import QtQuick.Layouts 1.12 import QtQuick.Window 2.12 import QtGraphicalEffects 1.0 import FishUI 1.0 as FishUI import Cutefish.Notification 1.0 Item { id: control visible: true Rectangle { id: _background anchors.fill: parent color: FishUI.Theme.secondBackgroundColor radius: NotificationDialog.width * 0.05 opacity: 0.7 border.width: 1 / FishUI.Units.devicePixelRatio border.pixelAligned: Screen.devicePixelRatio > 1 ? false : true border.color: FishUI.Theme.darkMode ? Qt.rgba(255, 255, 255, 0.1) : Qt.rgba(0, 0, 0, 0.05) } readonly property rect screenRect: { let rect = Qt.rect(screen.screenGeometry.x + screen.availableScreenRect.x, screen.screenGeometry.y + screen.availableScreenRect.y, screen.availableScreenRect.width, screen.availableScreenRect.height) return rect } onScreenRectChanged: { NotificationDialog.width = 350 NotificationDialog.height = screenRect.height - FishUI.Units.smallSpacing * 3 NotificationDialog.x = screenRect.x + screenRect.width - NotificationDialog.width - FishUI.Units.smallSpacing * 1.5 NotificationDialog.y = screenRect.y + FishUI.Units.smallSpacing * 1.5 } ScreenHelper { id: screen } FishUI.WindowHelper { id: windowHelper } FishUI.WindowShadow { view: NotificationDialog radius: _background.radius } FishUI.WindowBlur { view: NotificationDialog geometry: Qt.rect(NotificationDialog.x, NotificationDialog.y, NotificationDialog.width, NotificationDialog.height) windowRadius: _background.radius enabled: true } NumberAnimation { id: scrollToTopAni target: _view from: 0 to: 0 property: "contentY" duration: 200 easing.type: Easing.OutSine } ColumnLayout { anchors.fill: parent anchors.topMargin: FishUI.Units.largeSpacing anchors.bottomMargin: FishUI.Units.largeSpacing spacing: FishUI.Units.largeSpacing RowLayout { Layout.leftMargin: FishUI.Units.largeSpacing Layout.rightMargin: FishUI.Units.largeSpacing Label { text: qsTr("Notification Center") Layout.fillWidth: true elide: Text.ElideRight leftPadding: FishUI.Units.smallSpacing color: FishUI.Theme.textColor font.pointSize: 15 MouseArea { anchors.fill: parent onClicked: { if (_view.contentY === 0) return scrollToTopAni.from = _view.contentY scrollToTopAni.to = 0 scrollToTopAni.restart() } } } IconButton { visible: _view.count > 0 Layout.preferredHeight: 30 Layout.preferredWidth: 30 source: FishUI.Theme.darkMode ? "qrc:/images/dark/clear.svg" : "qrc:/images/light/clear.svg" onLeftButtonClicked: historyModel.clearAll() } } Item { Layout.fillWidth: true Layout.fillHeight: true ListView { id: _view anchors.fill: parent model: historyModel spacing: FishUI.Units.largeSpacing highlightFollowsCurrentItem: true clip: true leftMargin: FishUI.Units.largeSpacing rightMargin: FishUI.Units.largeSpacing ScrollBar.vertical: ScrollBar {} Label { anchors.centerIn: parent text: qsTr("No notifications") color: FishUI.Theme.disabledTextColor font.pointSize: 15 visible: _view.count === 0 } removeDisplaced: Transition { NumberAnimation { properties: "x, y"; duration: 250 } } delegate: Item { width: ListView.view.width - ListView.view.leftMargin - ListView.view.rightMargin height: 70 Rectangle { anchors.fill: parent color: FishUI.Theme.darkMode ? "white" : "black" radius: FishUI.Theme.bigRadius opacity: FishUI.Theme.darkMode ? 0.1 : 0.03 } MouseArea { id: _itemMouseArea anchors.fill: parent hoverEnabled: true z: 999 } RowLayout { anchors.fill: parent anchors.margins: FishUI.Units.largeSpacing anchors.leftMargin: FishUI.Units.smallSpacing * 1.5 anchors.rightMargin: FishUI.Units.smallSpacing * 1.5 spacing: FishUI.Units.smallSpacing Image { id: _icon width: 48 height: width source: model.iconName ? "image://icontheme/%1".arg(model.iconName) : "" sourceSize: Qt.size(width, height) Layout.alignment: Qt.AlignVCenter antialiasing: true smooth: true visible: status === Image.Ready } Image { id: _defaultIcon width: 48 height: width source: "image://icontheme/preferences-desktop-notification" sourceSize: Qt.size(width, height) Layout.alignment: Qt.AlignVCenter antialiasing: true smooth: true visible: !_icon.visible } ColumnLayout { spacing: 0 Item { Layout.fillHeight: true } Label { text: model.summary visible: text elide: Text.ElideRight Layout.fillWidth: true rightPadding: FishUI.Units.smallSpacing } RowLayout { Label { id: bodyLabel text: model.body visible: text rightPadding: FishUI.Units.smallSpacing maximumLineCount: 2 elide: Text.ElideRight wrapMode: Text.Wrap Layout.fillWidth: true // Layout.fillHeight: true Layout.alignment: Qt.AlignVCenter } Label { text: model.created rightPadding: FishUI.Units.smallSpacing Layout.alignment: Qt.AlignRight } } Item { Layout.fillHeight: true } } } Image { anchors.top: parent.top anchors.right: parent.right anchors.topMargin: FishUI.Units.smallSpacing / 2 anchors.rightMargin: FishUI.Units.smallSpacing / 2 width: 24 height: 24 source: "qrc:/images/" + (FishUI.Theme.darkMode ? "dark" : "light") + "/close.svg" sourceSize: Qt.size(width, height) visible: _itemMouseArea.containsMouse z: 9999 Rectangle { property color hoveredColor: FishUI.Theme.darkMode ? Qt.lighter(FishUI.Theme.backgroundColor, 2) : Qt.darker(FishUI.Theme.backgroundColor, 1.2) property color pressedColor: FishUI.Theme.darkMode ? Qt.lighter(FishUI.Theme.backgroundColor, 1.5) : Qt.darker(FishUI.Theme.backgroundColor, 1.3) z: -1 anchors.fill: parent color: "transparent" radius: height / 2 } MouseArea { id: _closeBtnArea anchors.fill: parent // hoverEnabled: true onClicked: { historyModel.remove(index) } } } } } } } } core-0.8/notificationd/qml/QmlNotificationPopup.qml000066400000000000000000000127541417504024300226040ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: Reion Wong * * 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 * 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 . */ import QtQuick 2.12 import QtQuick.Controls 2.12 import QtQuick.Layouts 1.12 import QtQuick.Window 2.12 import QtGraphicalEffects 1.0 import FishUI 1.0 as FishUI import Cutefish.Notification 1.0 NotificationPopup { id: control flags: Qt.WindowDoesNotAcceptFocus | Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint width: 400 height: 70 color: "transparent" visible: false onVisibleChanged: if (visible) timer.restart() property int defaultTimeout: 7000 FishUI.WindowShadow { view: control radius: _background.radius } FishUI.WindowBlur { view: control geometry: Qt.rect(control.x, control.y, control.width, control.height) windowRadius: _background.radius enabled: true } Rectangle { id: _background anchors.fill: parent radius: height * 0.2 color: FishUI.Theme.backgroundColor opacity: 0.5 } MouseArea { id: _mouseArea z: 999 anchors.fill: parent hoverEnabled: true onEntered: timer.stop() onExited: timer.restart() onClicked: { if (model.hasDefaultAction) { notificationsModel.invokeDefaultAction(model.notificationId) } notificationsModel.close(model.notificationId) } } RowLayout { anchors.fill: parent anchors.leftMargin: FishUI.Units.smallSpacing * 1.5 anchors.rightMargin: FishUI.Units.smallSpacing anchors.topMargin: FishUI.Units.smallSpacing anchors.bottomMargin: FishUI.Units.smallSpacing spacing: FishUI.Units.largeSpacing Image { id: _icon width: 48 height: width source: model.iconName ? "image://icontheme/%1".arg(model.iconName) : "" sourceSize: Qt.size(width, height) Layout.alignment: Qt.AlignVCenter antialiasing: true smooth: true visible: status === Image.Ready } Image { id: _defaultIcon width: 48 height: width source: "image://icontheme/preferences-desktop-notification" sourceSize: Qt.size(width, height) Layout.alignment: Qt.AlignVCenter antialiasing: true smooth: true visible: !_icon.visible } ColumnLayout { spacing: 0 Item { Layout.fillHeight: true } Label { text: model.summary visible: text elide: Text.ElideRight Layout.fillWidth: true rightPadding: FishUI.Units.smallSpacing } Label { text: model.body visible: text rightPadding: FishUI.Units.smallSpacing maximumLineCount: 2 elide: Text.ElideRight wrapMode: Text.Wrap Layout.fillWidth: true // Layout.fillHeight: true Layout.alignment: Qt.AlignVCenter } Item { Layout.fillHeight: true } } } Image { anchors.top: parent.top anchors.right: parent.right anchors.topMargin: FishUI.Units.smallSpacing / 2 anchors.rightMargin: FishUI.Units.smallSpacing width: 24 height: 24 source: "qrc:/images/" + (FishUI.Theme.darkMode ? "dark" : "light") + "/close.svg" sourceSize: Qt.size(width, height) visible: _mouseArea.containsMouse || _closeBtnArea.containsMouse z: 9999 Rectangle { property color hoveredColor: FishUI.Theme.darkMode ? Qt.lighter(FishUI.Theme.backgroundColor, 2) : Qt.darker(FishUI.Theme.backgroundColor, 1.2) property color pressedColor: FishUI.Theme.darkMode ? Qt.lighter(FishUI.Theme.backgroundColor, 1.5) : Qt.darker(FishUI.Theme.backgroundColor, 1.3) z: -1 anchors.fill: parent color: "transparent" // color: _closeBtnArea.pressed ? pressedColor : _closeBtnArea.containsMouse ? hoveredColor : "transparent" radius: height / 2 } MouseArea { id: _closeBtnArea anchors.fill: parent hoverEnabled: true onEntered: timer.stop() onClicked: { notificationsModel.close(model.notificationId) } } } Timer { id: timer interval: control.defaultTimeout onTriggered: { notificationsModel.expired(model.notificationId) } } } core-0.8/notificationd/qml/main.qml000066400000000000000000000051521417504024300173760ustar00rootroot00000000000000/* SPDX-FileCopyrightText: 2021 Reion Wong SPDX-FileCopyrightText: 2019 Kai Uwe Broulik SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL */ import QtQuick 2.12 import QtQml 2.12 import QtQuick.Controls 2.12 import QtQuick.Layouts 1.12 import QtQuick.Window 2.12 import QtGraphicalEffects 1.0 import FishUI 1.0 as FishUI import Cutefish.Notification 1.0 Item { id: root width: 0 height: 0 visible: false property int popupEdgeDistance: FishUI.Units.largeSpacing property int popupSpacing: FishUI.Units.largeSpacing readonly property real popupMaximumScreenFill: 0.4 readonly property rect screenRect: { let rect = Qt.rect(screen.screenGeometry.x + screen.availableScreenRect.x, screen.screenGeometry.y + screen.availableScreenRect.y, screen.availableScreenRect.width, screen.availableScreenRect.height) return rect } onScreenRectChanged: positionPopups() property Instantiator popupInstantiator: Instantiator { model: notificationsModel delegate: QmlNotificationPopup {} onObjectAdded: { positionPopups() } onObjectRemoved: { positionPopups() } } ScreenHelper { id: screen } function positionPopups() { const screenRect = root.screenRect if (screenRect.width <= 0 || screenRect.height <= 0) { return } let y = screenRect.y y += root.popupEdgeDistance for (var i = 0; i < popupInstantiator.count; ++i) { let popup = popupInstantiator.objectAt(i) if (!popup) continue var popupEffectiveWidth = popup.width const leftMostX = screenRect.x + root.popupEdgeDistance const rightMostX = screenRect.x + screenRect.width - root.popupEdgeDistance - popupEffectiveWidth // right popup.x = rightMostX popup.y = y y += popup.height + (popup.height > 0 ? popupSpacing : 0) // Horizontal // popup.x = screenRect.x + (screenRect.width - popup.width) / 2 // don't let notifications take more than popupMaximumScreenFill of the screen var visible = true if (i > 0) { // however always show at least one popup visible = (popup.y + popup.height < screenRect.y + (screenRect.height * popupMaximumScreenFill)) } popup.visible = visible } } } core-0.8/notificationd/resources.qrc000066400000000000000000000006231417504024300176650ustar00rootroot00000000000000 qml/main.qml qml/QmlNotificationPopup.qml images/dark/close.svg images/light/close.svg qml/NotificationWindow.qml images/dark/clear.svg images/light/clear.svg qml/IconButton.qml core-0.8/notificationd/screenhelper.cpp000066400000000000000000000024251417504024300203310ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: Reion Wong * * 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 * 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 "screenhelper.h" #include #include ScreenHelper::ScreenHelper(QObject *parent) : QObject(parent) { connect(qApp->primaryScreen(), &QScreen::geometryChanged, this, &ScreenHelper::screenGeometryChanged); connect(qApp->primaryScreen(), &QScreen::availableGeometryChanged, this, &ScreenHelper::availableScreenRectChanged); } QRect ScreenHelper::screenGeometry() const { return qApp->primaryScreen()->geometry(); } QRect ScreenHelper::availableScreenRect() const { return qApp->primaryScreen()->availableGeometry(); } core-0.8/notificationd/screenhelper.h000066400000000000000000000024261417504024300177770ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: Reion Wong * * 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 * 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 SCREENHELPER_H #define SCREENHELPER_H #include #include class ScreenHelper : public QObject { Q_OBJECT Q_PROPERTY(QRect screenGeometry READ screenGeometry NOTIFY screenGeometryChanged) Q_PROPERTY(QRect availableScreenRect READ availableScreenRect NOTIFY availableScreenRectChanged) public: explicit ScreenHelper(QObject *parent = nullptr); QRect screenGeometry() const; QRect availableScreenRect() const; signals: void screenGeometryChanged(); void availableScreenRectChanged(); }; #endif // SCREENHELPER_H core-0.8/notificationd/settings.cpp000066400000000000000000000024711417504024300175130ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: Kate Leet * * 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 * 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 "settings.h" Settings *Settings::self() { static Settings s; return &s; } Settings::Settings(QObject *parent) : QObject(parent) , m_settings(QSettings::UserScope, "cutefishos", "notification") { m_doNotDisturb = m_settings.value("DoNotDisturb", false).toBool(); } bool Settings::doNotDisturb() const { return m_doNotDisturb; } void Settings::setDoNotDisturb(bool doNotDisturb) { if (m_doNotDisturb != doNotDisturb) { m_doNotDisturb = doNotDisturb; m_settings.setValue("DoNotDisturb", m_doNotDisturb); emit doNotDisturbChanged(); } } core-0.8/notificationd/settings.h000066400000000000000000000023471417504024300171620ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: Kate Leet * * 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 * 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 SETTINGS_H #define SETTINGS_H #include #include class Settings : public QObject { Q_OBJECT Q_PROPERTY(bool doNotDisturb READ doNotDisturb WRITE setDoNotDisturb NOTIFY doNotDisturbChanged) public: static Settings *self(); explicit Settings(QObject *parent = nullptr); bool doNotDisturb() const; void setDoNotDisturb(bool doNotDisturb); signals: void doNotDisturbChanged(); private: QSettings m_settings; bool m_doNotDisturb; }; #endif // SETTINGS_H core-0.8/notificationd/translations/000077500000000000000000000000001417504024300176645ustar00rootroot00000000000000core-0.8/notificationd/translations/en_US.ts000066400000000000000000000034431417504024300212510ustar00rootroot00000000000000 DateHelper Now 1 minute ago %1 minutes ago 1 hour ago %1 hours ago 1 day ago %1 days ago NotificationWindow Notification Center No notifications core-0.8/notificationd/translations/zh_CN.ts000066400000000000000000000033541417504024300212420ustar00rootroot00000000000000 DateHelper Now 现在 1 minute ago 一分钟前 %1 minutes ago %1分钟前 1 hour ago 一小时前 %1 hours ago %1小时前 1 day ago 一天前 %1 days ago %1天前 NotificationWindow Notification Center 通知中心 No notifications 无通知 core-0.8/notificationd/utils.cpp000066400000000000000000000027501417504024300170130ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: Reion Wong * * 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 * 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 "utils.h" #include Utils::Utils(QObject *parent) : QObject(parent) { } QString Utils::processNameFromPid(uint pid) { QFile file(QString("/proc/%1/cmdline").arg(pid)); QString name; if (file.open(QIODevice::ReadOnly)) { QByteArray cmd = file.readAll(); if (!cmd.isEmpty()) { // extract non-truncated name from cmdline int zeroIndex = cmd.indexOf('\0'); int processNameStart = cmd.lastIndexOf('/', zeroIndex); if (processNameStart == -1) { processNameStart = 0; } else { processNameStart++; } name = QString::fromLocal8Bit(cmd.mid(processNameStart, zeroIndex - processNameStart)); } } return name; } core-0.8/notificationd/utils.h000066400000000000000000000016741417504024300164640ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: Reion Wong * * 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 * 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 UTILS_H #define UTILS_H #include class Utils : public QObject { Q_OBJECT public: explicit Utils(QObject *parent = nullptr); static QString processNameFromPid(uint pid); }; #endif // UTILS_H core-0.8/notificationd/view.cpp000066400000000000000000000006361417504024300166260ustar00rootroot00000000000000#include "view.h" #include #include View::View(QQuickView *parent) : QQuickView(parent) { rootContext()->setContextProperty("View", this); setFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint); // setResizeMode(QQuickView::SizeViewToRootObject); setSource(QUrl("qrc:/qml/main.qml")); setScreen(qApp->primaryScreen()); setColor(Qt::transparent); } core-0.8/notificationd/view.h000066400000000000000000000002641417504024300162700ustar00rootroot00000000000000#ifndef VIEW_H #define VIEW_H #include class View : public QQuickView { Q_OBJECT public: explicit View(QQuickView *parent = nullptr); }; #endif // VIEW_H core-0.8/polkit-agent/000077500000000000000000000000001417504024300147075ustar00rootroot00000000000000core-0.8/polkit-agent/CMakeLists.txt000066400000000000000000000023171417504024300174520ustar00rootroot00000000000000find_package(PkgConfig) pkg_check_modules(POLKIT_AGENT REQUIRED polkit-agent-1) message(STATUS "polkit agent: ${POLKIT_AGENT_INCLUDE_DIRS} ${POLKIT_AGENT_LIBRARIES}") find_package(PolkitQt5-1 REQUIRED) include_directories( ${POLKIT_AGENT_INCLUDE_DIRS} "${POLKITQT-1_INCLUDE_DIR}" ) add_executable(cutefish-polkit-agent main.cpp polkitagentlistener.cpp dialog.cpp qml.qrc ) target_link_libraries(cutefish-polkit-agent Qt5::Core Qt5::Widgets Qt5::Quick Qt5::QuickControls2 # FishUI ${POLKITQT-1_CORE_LIBRARY} ${POLKITQT-1_AGENT_LIBRARY} ${POLKIT_AGENT_LDFLAGS} ) file(GLOB TS_FILES translations/*.ts) qt5_create_translation(QM_FILES ${TS_FILES}) add_custom_target(polkit-agent-translations DEPENDS ${QM_FILES} SOURCES ${TS_FILES}) add_dependencies(cutefish-polkit-agent polkit-agent-translations) install(TARGETS cutefish-polkit-agent DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT Runtime ) install(FILES cutefish-polkit-agent.desktop DESTINATION "${CMAKE_INSTALL_FULL_SYSCONFDIR}/xdg/autostart" COMPONENT Runtime ) install(FILES ${QM_FILES} DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/cutefish-polkit-agent/translations) core-0.8/polkit-agent/cutefish-polkit-agent.desktop000066400000000000000000000002001417504024300225000ustar00rootroot00000000000000[Desktop Entry] Type=Application Name=PolicyKit Handler TryExec=cutefish-polkit-agent Exec=cutefish-polkit-agent NoDisplay=true core-0.8/polkit-agent/dialog.cpp000066400000000000000000000045331417504024300166570ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: revenmartin * * 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 * 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 "dialog.h" #include #include #include #include Dialog::Dialog(const QString &action, const QString &message, const QString &cookie, const QString &identity, const QString &iconName, PolkitQt1::Agent::AsyncResult *result) : m_action(action) , m_message(message) , m_cookie(cookie) , m_identity(identity) , m_password(QString()) , m_iconName(iconName) , m_result(result) , m_view(new QQuickView) { qDebug() << "Creating ConfirmationDialog"; m_view->setFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint); m_view->rootContext()->setContextProperty("confirmation", this); m_view->rootContext()->setContextProperty("rootWindow", m_view); m_view->setResizeMode(QQuickView::SizeViewToRootObject); m_view->setClearBeforeRendering(true); m_view->setDefaultAlphaBuffer(true); m_view->setColor(Qt::transparent); m_view->setSource(QUrl(QStringLiteral("qrc:/main.qml"))); m_view->setVisible(false); } Dialog::~Dialog() { qDebug() << "Deleting ConfirmationDialog"; delete m_view; } void Dialog::setConfirmationResult(const QString &passwd) { m_password = passwd; emit accepted(); } void Dialog::rejected() { emit cancel(); } void Dialog::show() { m_view->show(); m_view->setScreen(qGuiApp->primaryScreen()); m_view->setX((m_view->screen()->geometry().width() - m_view->geometry().width()) / 2); m_view->setY((m_view->screen()->geometry().height() - m_view->geometry().height()) / 2); } void Dialog::authenticationFailure() { emit failure(); } core-0.8/polkit-agent/dialog.h000066400000000000000000000050121417504024300163150ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: revenmartin * * 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 * 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 DIALOG_H #define DIALOG_H #include #include #include #include #include class Dialog : public QObject { Q_OBJECT public: explicit Dialog(const QString &action, const QString &message, const QString &cookie, const QString &identity, const QString &iconName, PolkitQt1::Agent::AsyncResult *result); ~Dialog(); Q_INVOKABLE void setConfirmationResult(const QString &password = QString()); Q_INVOKABLE void rejected(); Q_INVOKABLE void show(); Q_INVOKABLE void authenticationFailure(); Q_PROPERTY(QString message READ message NOTIFY changed) Q_PROPERTY(QString action READ action NOTIFY changed) Q_PROPERTY(QString cookie READ cookie NOTIFY changed) Q_PROPERTY(QString identity READ identity NOTIFY changed) Q_PROPERTY(QString password READ password NOTIFY changed) Q_PROPERTY(QString iconName READ iconName NOTIFY changed) QString message() { return m_message; } QString action() { return m_action; } QString cookie() { return m_cookie; } QString identity() { return m_identity; } QString password() { return m_password; } QString iconName() { return m_iconName; } PolkitQt1::Agent::AsyncResult *result() { return m_result; } signals: // This signal is never emitted at the moment, as we don't change the // properties of this window dynamically for now void changed(); void failure(); void cancel(); void accepted(); private: QString m_action; QString m_message; QVariantMap m_details; QString m_cookie; QString m_identity; QString m_password; QString m_iconName; PolkitQt1::Agent::AsyncResult *m_result; QQuickView *m_view; }; #endif // DIALOG_H core-0.8/polkit-agent/main.cpp000066400000000000000000000033361417504024300163440ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: revenmartin * * 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 * 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 #include #include #include #include #include "polkitagentlistener.h" int main(int argc, char *argv[]) { QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QGuiApplication app(argc, argv); app.setQuitOnLastWindowClosed(false); // Translations QLocale locale; QString qmFilePath = QString("%1/%2.qm").arg("/usr/share/cutefish-polkit-agent/translations/").arg(locale.name()); if (QFile::exists(qmFilePath)) { QTranslator *translator = new QTranslator(QGuiApplication::instance()); if (translator->load(qmFilePath)) { QGuiApplication::installTranslator(translator); } else { translator->deleteLater(); } } PolKitAgentListener listener; PolkitQt1::UnixSessionSubject session(getpid()); if (!listener.registerListener(session, QStringLiteral("/com/cutefish/PolicyKit1/AuthenticationAgent"))) return -1; return app.exec(); } core-0.8/polkit-agent/main.qml000066400000000000000000000101021417504024300163400ustar00rootroot00000000000000import QtQuick 2.12 import QtQuick.Controls 2.5 import QtQuick.Layouts 1.3 import FishUI 1.0 as FishUI Item { id: root property var heightValue: mainLayout.implicitHeight + FishUI.Units.largeSpacing * 2 width: 450 height: heightValue Connections { target: confirmation function onFailure() { doneButton.enabled = true passwordInput.enabled = true } } onHeightValueChanged: { rootWindow.height = heightValue rootWindow.maximumHeight = heightValue rootWindow.minimumHeight = heightValue rootWindow.maximumWidth = root.width rootWindow.minimumWidth = root.width } Keys.enabled: true Keys.onEscapePressed: { confirmation.setConfirmationResult("") } Rectangle { id: _background anchors.fill: parent radius: FishUI.Theme.bigRadius color: FishUI.Theme.secondBackgroundColor } DragHandler { target: null acceptedDevices: PointerDevice.GenericPointer grabPermissions: TapHandler.CanTakeOverFromAnything onActiveChanged: if (active) { windowHelper.startSystemMove(rootWindow) } } FishUI.WindowHelper { id: windowHelper } FishUI.WindowShadow { view: rootWindow geometry: Qt.rect(root.x, root.y, root.width, root.height) radius: _background.radius } FontMetrics { id: fontMetrics } RowLayout { id: mainLayout anchors.fill: parent anchors.margins: FishUI.Units.largeSpacing Image { id: icon source: "qrc:/svg/emblem-warning.svg" sourceSize.width: 64 sourceSize.height: 64 smooth: true Layout.alignment: Qt.AlignTop visible: !iconImage } Image { id: iconImage source: "image://icontheme/" + confirmation.iconName sourceSize.width: 64 sourceSize.height: 64 Layout.alignment: Qt.AlignTop visible: state !== Image.Ready } Item { width: FishUI.Units.largeSpacing } ColumnLayout { id: column spacing: FishUI.Units.largeSpacing Text { text: confirmation.message font.bold: false Layout.fillWidth: true Layout.fillHeight: true maximumLineCount: 2 wrapMode: Text.Wrap elide: Text.ElideRight color: FishUI.Theme.textColor } TextField { id: userTextField text: confirmation.identity enabled: false Layout.fillWidth: true } TextField { id: passwordInput placeholderText: qsTr("Password") echoMode: TextField.Password Layout.fillWidth: true selectByMouse: true focus: true onAccepted: { if (passwordInput.text) confirmation.setConfirmationResult(passwordInput.text) } Keys.onEscapePressed: { confirmation.setConfirmationResult("") } } RowLayout { spacing: FishUI.Units.largeSpacing Button { text: qsTr("Cancel") Layout.fillWidth: true height: 50 onClicked: confirmation.rejected() } Button { id: doneButton text: qsTr("Done") Layout.fillWidth: true flat: true height: 50 onClicked: { doneButton.enabled = false passwordInput.enabled = false confirmation.setConfirmationResult(passwordInput.text) } } } } } } core-0.8/polkit-agent/polkitagentlistener.cpp000066400000000000000000000075631417504024300215150ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: revenmartin * * 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 * 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 "polkitagentlistener.h" #include "dialog.h" #include PolKitAgentListener::PolKitAgentListener(QObject *parent) : PolkitQt1::Agent::Listener(parent) , m_dialog(nullptr) , m_inProgress(false) { } void PolKitAgentListener::initiateAuthentication(const QString &actionId, const QString &message, const QString &iconName, const PolkitQt1::Details &details, const QString &cookie, const PolkitQt1::Identity::List &identities, PolkitQt1::Agent::AsyncResult *result) { Q_UNUSED(details); if (m_inProgress) { result->setCompleted(); return; } m_identities = identities; m_cookie = cookie; m_result = result; m_session.clear(); m_inProgress = true; m_dialog = new Dialog(actionId, message, cookie, identities.first().toString(), iconName, result); m_session = new PolkitQt1::Agent::Session(identities.first(), cookie, result); connect(m_dialog.data(), &Dialog::accepted, this, &PolKitAgentListener::onDialogAccepted); connect(m_dialog.data(), &Dialog::cancel, this, &PolKitAgentListener::onDialogCanceled); m_dialog.data()->show(); m_session.data()->initiate(); if (!identities.isEmpty()) { m_selectedUser = identities[0]; } m_numTries = 0; tryAgain(); } void PolKitAgentListener::request(const QString &request, bool echo) { Q_UNUSED(request); Q_UNUSED(echo); } void PolKitAgentListener::completed(bool gainedAuthorization) { m_gainedAuthorization = gainedAuthorization; finishObtainPrivilege(); } void PolKitAgentListener::tryAgain() { m_wasCancelled = false; if (m_selectedUser.isValid()) { m_session = new PolkitQt1::Agent::Session(m_selectedUser, m_cookie, m_result); connect(m_session.data(), SIGNAL(request(QString, bool)), this, SLOT(request(QString, bool))); connect(m_session.data(), SIGNAL(completed(bool)), this, SLOT(completed(bool))); m_session.data()->initiate(); } } void PolKitAgentListener::finishObtainPrivilege() { m_numTries++; if (!m_gainedAuthorization && !m_wasCancelled && !m_dialog.isNull()) { m_dialog.data()->authenticationFailure(); if (m_numTries < 3) { m_session.data()->deleteLater(); tryAgain(); return; } } if (!m_session.isNull()) { m_session.data()->result()->setCompleted(); } else { m_result->setCompleted(); } m_session.data()->deleteLater(); if (!m_dialog.isNull()) { m_dialog.data()->deleteLater(); } m_inProgress = false; } void PolKitAgentListener::onDialogAccepted() { if (!m_dialog.isNull()) { m_session.data()->setResponse(m_dialog.data()->password()); } } void PolKitAgentListener::onDialogCanceled() { m_wasCancelled = true; if (!m_session.isNull()) { m_session.data()->cancel(); } finishObtainPrivilege(); } core-0.8/polkit-agent/polkitagentlistener.h000066400000000000000000000044121417504024300211500ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: revenmartin * * 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 * 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 POLKITAGENTLISTENER_H #define POLKITAGENTLISTENER_H #include #include #include #include #include #include #include class Dialog; class PolKitAgentListener : public PolkitQt1::Agent::Listener { Q_OBJECT public: explicit PolKitAgentListener(QObject *parent = nullptr); public slots: void initiateAuthentication(const QString &actionId, const QString &message, const QString &iconName, const PolkitQt1::Details &details, const QString &cookie, const PolkitQt1::Identity::List &identities, PolkitQt1::Agent::AsyncResult *result); bool initiateAuthenticationFinish() { return true; } void cancelAuthentication() {} void request(const QString &request, bool echo); void completed(bool gainedAuthorization); private: void tryAgain(); void finishObtainPrivilege(); private slots: void onDialogAccepted(); void onDialogCanceled(); private: QPointer m_dialog; QPointer m_session; PolkitQt1::Identity::List m_identities; PolkitQt1::Agent::AsyncResult *m_result; PolkitQt1::Identity m_selectedUser; QString m_cookie; bool m_inProgress; bool m_gainedAuthorization; bool m_wasCancelled; int m_numTries; }; #endif // POLKITAGENTLISTENER_H core-0.8/polkit-agent/qml.qrc000066400000000000000000000002031417504024300162020ustar00rootroot00000000000000 main.qml svg/emblem-warning.svg core-0.8/polkit-agent/svg/000077500000000000000000000000001417504024300155065ustar00rootroot00000000000000core-0.8/polkit-agent/svg/emblem-warning.svg000066400000000000000000000044541417504024300211420ustar00rootroot00000000000000 image/svg+xml core-0.8/polkit-agent/translations/000077500000000000000000000000001417504024300174305ustar00rootroot00000000000000core-0.8/polkit-agent/translations/ar_AA.ts000066400000000000000000000012041417504024300207400ustar00rootroot00000000000000 main Password كلمة المرور Done تم Cancel إلغاﺀ core-0.8/polkit-agent/translations/be_BY.ts000066400000000000000000000012121417504024300207540ustar00rootroot00000000000000 main Password Пароль Done Гатова Cancel Скасаваць core-0.8/polkit-agent/translations/be_Latn.ts000066400000000000000000000012331417504024300213430ustar00rootroot00000000000000 main Password Done Cancel core-0.8/polkit-agent/translations/bg_BG.ts000066400000000000000000000012021417504024300207330ustar00rootroot00000000000000 main Password Парола Done Готово Cancel Отказ core-0.8/polkit-agent/translations/bs_BA.ts000066400000000000000000000011641417504024300207500ustar00rootroot00000000000000 main Password Lozinka Done U redu Cancel Otkaži core-0.8/polkit-agent/translations/cs_CZ.ts000066400000000000000000000011611417504024300210000ustar00rootroot00000000000000 main Password Heslo Done Hotovo Cancel Storno core-0.8/polkit-agent/translations/da_DK.ts000066400000000000000000000011671417504024300207470ustar00rootroot00000000000000 main Password Kodeord Done Færdig Cancel Annullér core-0.8/polkit-agent/translations/de_DE.ts000066400000000000000000000011721417504024300207410ustar00rootroot00000000000000 main Password Passwort Done Fertig Cancel Abbrechen core-0.8/polkit-agent/translations/en_US.ts000066400000000000000000000011361417504024300210120ustar00rootroot00000000000000 main Password Password Done Done Cancel Cancel core-0.8/polkit-agent/translations/eo_XX.ts000066400000000000000000000011641417504024300210240ustar00rootroot00000000000000 main Password Pasvorto Done Finita Cancel Nuligi core-0.8/polkit-agent/translations/es_ES.ts000066400000000000000000000011741417504024300210010ustar00rootroot00000000000000 main Password Contraseña Done Terminado Cancel Cancelar core-0.8/polkit-agent/translations/es_MX.ts000066400000000000000000000011731417504024300210150ustar00rootroot00000000000000 main Password Contraseña Done Listo Cancel Cancelar core-0.8/polkit-agent/translations/fa_IR.ts000066400000000000000000000012141417504024300207560ustar00rootroot00000000000000 main Password گذرواژه Done انجام شد Cancel لغو کردن core-0.8/polkit-agent/translations/fi_FI.ts000066400000000000000000000011651417504024300207570ustar00rootroot00000000000000 main Password Salasana Done Valmis Cancel Peruuta core-0.8/polkit-agent/translations/fr_FR.ts000066400000000000000000000011731417504024300210000ustar00rootroot00000000000000 main Password Mot de passe Done Terminé Cancel Annuler core-0.8/polkit-agent/translations/he_IL.ts000066400000000000000000000011741417504024300207630ustar00rootroot00000000000000 main Password סיסמא Done בוצע Cancel ביטול core-0.8/polkit-agent/translations/hi_IN.ts000066400000000000000000000012361417504024300207700ustar00rootroot00000000000000 main Password कुंजिका Done ठीक है Cancel रद्द करें core-0.8/polkit-agent/translations/hu_HU.ts000066400000000000000000000011631417504024300210110ustar00rootroot00000000000000 main Password Jelszó Done Kész Cancel Mégsem core-0.8/polkit-agent/translations/id_ID.ts000066400000000000000000000011611417504024300207470ustar00rootroot00000000000000 main Password Sandi Done Selesai Cancel Batal core-0.8/polkit-agent/translations/ie.ts000066400000000000000000000011671417504024300204020ustar00rootroot00000000000000 main Password Contrasigne Done Finit Cancel Anullar core-0.8/polkit-agent/translations/it_IT.ts000066400000000000000000000011651417504024300210130ustar00rootroot00000000000000 main Password Password Done Finito Cancel Annulla core-0.8/polkit-agent/translations/ja_JP.ts000066400000000000000000000012041417504024300207600ustar00rootroot00000000000000 main Password パスワード Done 終了 Cancel キャンセル core-0.8/polkit-agent/translations/lt_LT.ts000066400000000000000000000011751417504024300210220ustar00rootroot00000000000000 main Password Slaptažodis Done Atlikta Cancel Atsisakyti core-0.8/polkit-agent/translations/lv_LV.ts000066400000000000000000000011621417504024300210220ustar00rootroot00000000000000 main Password Parole Done Gatavs Cancel Atcelt core-0.8/polkit-agent/translations/mg.ts000066400000000000000000000011671417504024300204100ustar00rootroot00000000000000 main Password Teny miafina Done Vita Cancel Ajanona core-0.8/polkit-agent/translations/ml_IN.ts000066400000000000000000000012261417504024300207770ustar00rootroot00000000000000 main Password Done Cancel core-0.8/polkit-agent/translations/nb_NO.ts000066400000000000000000000011661417504024300207770ustar00rootroot00000000000000 main Password Passord Done Ferdig Cancel Avbryt core-0.8/polkit-agent/translations/ne_NP.ts000066400000000000000000000012211417504024300207730ustar00rootroot00000000000000 main Password गोप्य शब्द Done भयो Cancel रद्द core-0.8/polkit-agent/translations/pl_PL.ts000066400000000000000000000011361417504024300210070ustar00rootroot00000000000000 main Password Hasło Done Gotowe Cancel Anuluj core-0.8/polkit-agent/translations/pt_BR.ts000066400000000000000000000011651417504024300210110ustar00rootroot00000000000000 main Password Senha Done Feito Cancel Cancelar core-0.8/polkit-agent/translations/pt_PT.ts000066400000000000000000000011751417504024300210320ustar00rootroot00000000000000 main Password Palavra-passe Done Feito Cancel Cancelar core-0.8/polkit-agent/translations/ro_RO.ts000066400000000000000000000012261417504024300210210ustar00rootroot00000000000000 main Password Done Cancel core-0.8/polkit-agent/translations/ru_RU.ts000066400000000000000000000012101417504024300210260ustar00rootroot00000000000000 main Password Пароль Done Готово Cancel Отменить core-0.8/polkit-agent/translations/si_LK.ts000066400000000000000000000012461417504024300210040ustar00rootroot00000000000000 main Password මුරපදය Done Cancel අවලංගු කරන්න core-0.8/polkit-agent/translations/sk_SK.ts000066400000000000000000000011631417504024300210130ustar00rootroot00000000000000 main Password Heslo Done Hotovo Cancel Zrušiť core-0.8/polkit-agent/translations/so.ts000066400000000000000000000011651417504024300204240ustar00rootroot00000000000000 main Password Erey sireed Done Dhammee Cancel Xir core-0.8/polkit-agent/translations/sr_RS.ts000066400000000000000000000011661417504024300210340ustar00rootroot00000000000000 main Password Šifra Done Završeno Cancel Otkaži core-0.8/polkit-agent/translations/sv_SE.ts000066400000000000000000000011631417504024300210200ustar00rootroot00000000000000 main Password Lösenord Done Klar Cancel Avbryt core-0.8/polkit-agent/translations/sw.ts000066400000000000000000000011701417504024300204300ustar00rootroot00000000000000 main Password Neno la siri Done Maliza Cancel Ghairi core-0.8/polkit-agent/translations/ta_IN.ts000066400000000000000000000012261417504024300207730ustar00rootroot00000000000000 main Password Done Cancel core-0.8/polkit-agent/translations/tr_TR.ts000066400000000000000000000011621417504024300210320ustar00rootroot00000000000000 main Password Şifre Done Hazır Cancel İptal core-0.8/polkit-agent/translations/uk_UA.ts000066400000000000000000000012121417504024300210000ustar00rootroot00000000000000 main Password Пароль Done Готово Cancel Скасувати core-0.8/polkit-agent/translations/uz_UZ.ts000066400000000000000000000011761417504024300210610ustar00rootroot00000000000000 main Password Hahfiy so'z Done Bajarildi Cancel Bekor core-0.8/polkit-agent/translations/vi_VN.ts000066400000000000000000000012071417504024300210210ustar00rootroot00000000000000 main Password Mật khẩu Done Đã hoàn thành Cancel Đã hủy core-0.8/polkit-agent/translations/zh_CN.ts000066400000000000000000000011361417504024300210020ustar00rootroot00000000000000 main Password 密码 Done 完成 Cancel 取消 core-0.8/polkit-agent/translations/zh_HK.ts000066400000000000000000000012311417504024300210000ustar00rootroot00000000000000 main Password Done Cancel core-0.8/polkit-agent/translations/zh_TW.ts000066400000000000000000000011651417504024300210360ustar00rootroot00000000000000 main Password 密碼 Done 完成 Cancel 取消 core-0.8/powerman/000077500000000000000000000000001417504024300141415ustar00rootroot00000000000000core-0.8/powerman/CMakeLists.txt000066400000000000000000000022151417504024300167010ustar00rootroot00000000000000project(cutefish-powerman) set(TARGET cutefish-powerman) find_package(KF5IdleTime) find_package(X11) find_package(XCB REQUIRED COMPONENTS XCB DPMS ) set(XCB_LIBS XCB::XCB XCB::DPMS ) set(SOURCES main.cpp application.cpp lidwatcher.cpp action.cpp idlemanager.cpp dimdisplayaction.cpp cpu/cpuitem.cpp cpu/cpumanagement.cpp ) qt5_add_dbus_adaptor(DBUS_SOURCES cpu/com.cutefish.CPUManagement.xml cpu/cpumanagement.h CPUManagement) qt5_add_dbus_adaptor(DBUS_SOURCES com.cutefish.PowerManager.xml application.h Application) qt_add_dbus_interface(DBUS_SOURCES org.freedesktop.ScreenSaver.xml screenlocker_interface) set_source_files_properties(${DBUS_SOURCES} PROPERTIES SKIP_AUTOGEN ON) add_executable(${TARGET} ${SOURCES} ${DBUS_SOURCES}) target_link_libraries(${TARGET} Qt5::Core Qt5::Gui Qt5::Widgets Qt5::Quick Qt5::DBus Qt5::X11Extras KF5::IdleTime ${XCB_LIBS} ${X11_LIBRARIES} ) install(TARGETS ${TARGET} DESTINATION ${CMAKE_INSTALL_BINDIR}) core-0.8/powerman/action.cpp000066400000000000000000000040601417504024300161220ustar00rootroot00000000000000/*************************************************************************** * Copyright (C) 2010 by Dario Freddi * * * * 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 2 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, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * ***************************************************************************/ #include "action.h" #include "idlemanager.h" #include class Action::Private { public: Private() {} ~Private() {} QVector< int > registeredIdleTimeouts; }; Action::Action(QObject* parent) : QObject(parent) , d(new Private) { } Action::~Action() { delete d; } void Action::registerIdleTimeout(int msec) { d->registeredIdleTimeouts.append(msec); IdleManager::self()->registerActionTimeout(this, msec); } void Action::unregisterIdleTimeout() { d->registeredIdleTimeouts.clear(); IdleManager::self()->unregisterActionTimeouts(this); } bool Action::isSupported() { return true; } void Action::setTimeout(int timeout) { Q_UNUSED(timeout) } core-0.8/powerman/action.h000066400000000000000000000066031417504024300155740ustar00rootroot00000000000000/*************************************************************************** * Copyright (C) 2010 by Dario Freddi * * * * 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 2 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, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * ***************************************************************************/ #ifndef POWERDEVIL_POWERDEVILACTION_H #define POWERDEVIL_POWERDEVILACTION_H #include #include class IDleManager; class Q_DECL_EXPORT Action : public QObject { Q_OBJECT Q_DISABLE_COPY(Action) public: /** * Default constructor */ explicit Action(QObject *parent); /** * Default destructor */ ~Action() override; /** * This function is meant to find out if this action is available on this system. Actions * CAN reimplement this function if they are dependent on specific hardware/software requirements. * By default, this function will always return true. * * Should this function return false, the core will delete and ignore the action right after creation. * * @returns Whether this action is supported or not by the current system */ virtual bool isSupported(); virtual void setTimeout(int timeout); protected: /** * Registers an idle timeout for this action. Call this function and not KIdleTime directly to take advantage * of Action's automated handling of idle timeouts. Also, please reimplement onIdleTimeout instead of listening * to KIdleTime's signals to catch idle timeout events. * * @param msec The idle timeout to be registered in milliseconds. */ void registerIdleTimeout(int msec); void unregisterIdleTimeout(); public Q_SLOTS: /** * This slot is triggered whenever an idle timeout registered with registerIdleTimeout is reached. * * @param msec The idle timeout reached in milliseconds */ virtual void onIdleTimeout(int msec) = 0; /** * This slot is triggered whenever the PC wakes up from an Idle state. It is @b always called after a registered * idle timeout has been reached. */ virtual void onWakeupFromIdle() = 0; Q_SIGNALS: void actionTriggered(bool result, const QString &error = QString()); private: class Private; Private * const d; friend class IDleManager; }; #endif // POWERDEVIL_POWERDEVILACTION_H core-0.8/powerman/application.cpp000066400000000000000000000045751417504024300171630ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: Reion Wong * * 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 * 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 "application.h" #include "powermanageradaptor.h" #include #include Application::Application(QObject *parent) : QObject(parent) , m_lidWatcher(new LidWatcher) , m_cpuManagement(new CPUManagement) , m_settings("cutefishos", "power") , m_dimDisplayAction(new DimDisplayAction) { m_closeScreenTimeout = m_settings.value("CloseScreenTimeout", 600).toInt(); m_sleepWhenClosedScreen = m_settings.value("SleepWhenClosedScreen", false).toBool(); m_lockWhenClosedScreen = m_settings.value("LockWhenClosedScreen", true).toBool(); // Live if (QFile("/run/live/medium/live/filesystem.squashfs").exists()) { m_closeScreenTimeout = -1; } m_dimDisplayAction->setTimeout(m_closeScreenTimeout); m_dimDisplayAction->setSleep(m_sleepWhenClosedScreen); m_dimDisplayAction->setLock(m_lockWhenClosedScreen); QDBusConnection::sessionBus().registerService(QStringLiteral("com.cutefish.PowerManager")); QDBusConnection::sessionBus().registerObject(QStringLiteral("/PowerManager"), this); new PowerManagerAdaptor(this); } void Application::setDimDisplayTimeout(int timeout) { m_closeScreenTimeout = timeout; m_dimDisplayAction->setTimeout(timeout); m_settings.setValue("CloseScreenTimeout", timeout); } void Application::setSleepWhenClosedScreen(bool enabled) { m_sleepWhenClosedScreen = enabled; m_dimDisplayAction->setSleep(enabled); m_settings.setValue("SleepWhenClosedScreen", enabled); } void Application::setLockWhenClosedScreen(bool lock) { m_lockWhenClosedScreen = lock; m_dimDisplayAction->setLock(lock); m_settings.setValue("LockWhenClosedScreen", lock); } core-0.8/powerman/application.h000066400000000000000000000027151417504024300166220ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: Reion Wong * * 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 * 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 APPLICATION_H #define APPLICATION_H #include #include #include #include #include "lidwatcher.h" #include "idlemanager.h" #include "dimdisplayaction.h" #include "cpu/cpumanagement.h" class Application : public QObject { Q_OBJECT public: explicit Application(QObject *parent = nullptr); void setDimDisplayTimeout(int timeout); void setSleepWhenClosedScreen(bool enabled); void setLockWhenClosedScreen(bool lock); private: LidWatcher *m_lidWatcher; CPUManagement *m_cpuManagement; QSettings m_settings; int m_closeScreenTimeout; bool m_sleepWhenClosedScreen; bool m_lockWhenClosedScreen; DimDisplayAction *m_dimDisplayAction; }; #endif // APPLICATION_H core-0.8/powerman/com.cutefish.PowerManager.xml000066400000000000000000000010411417504024300216340ustar00rootroot00000000000000 core-0.8/powerman/cpu/000077500000000000000000000000001417504024300147305ustar00rootroot00000000000000core-0.8/powerman/cpu/com.cutefish.CPUManagement.xml000066400000000000000000000005561417504024300224720ustar00rootroot00000000000000 core-0.8/powerman/cpu/cpuitem.cpp000066400000000000000000000030341417504024300171020ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: Reion Wong * * 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 * 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 "cpuitem.h" #include #include CpuItem::CpuItem(const QString &name, QObject *parent) : QObject(parent) , m_name(name) { } bool CpuItem::setPolicy(const QString &value) { bool result = false; QFile file(QString("/sys/devices/system/cpu/%1/cpufreq/scaling_governor").arg(m_name)); if (file.open(QIODevice::WriteOnly)) { if (file.write(value.toLatin1()) != -1) result = true; file.close(); } qDebug() << m_name << "set policy: " << value << result; return result; } QString CpuItem::policy() { QString result; QFile file(QString("/sys/devices/system/cpu/%1/cpufreq/scaling_governor").arg(m_name)); if (file.open(QIODevice::ReadOnly)) { result = file.readAll().simplified(); file.close(); } return result; } core-0.8/powerman/cpu/cpuitem.h000066400000000000000000000020341417504024300165460ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: Reion Wong * * 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 * 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 CPUITEM_H #define CPUITEM_H #include class CpuItem : public QObject { Q_OBJECT public: explicit CpuItem(const QString &name, QObject *parent = nullptr); QString name(); bool setPolicy(const QString &value); QString policy(); private: QString m_name; }; #endif // CPUITEM_H core-0.8/powerman/cpu/cpumanagement.cpp000066400000000000000000000052771417504024300202730ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: Reion Wong * * 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 * 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 "cpumanagement.h" #include "cpumanagementadaptor.h" #include #include #include #include CPUManagement::CPUManagement(QObject *parent) : QObject(parent) , m_currentMode(PowerSave) { new CPUManagementAdaptor(this); QDBusConnection::sessionBus().registerObject(QStringLiteral("/CPUManagement"), this); // Init cpu items. QDir dir("/sys/devices/system/cpu"); QStringList dirList = dir.entryList(QDir::Dirs | QDir::NoDot | QDir::NoDotAndDotDot); for (const QString &dirName : dirList) { if (dirName.startsWith("cpu") && dirName[3].isNumber()) { m_items.append(new CpuItem(dirName)); } } // Init mode bool performance = false; for (CpuItem *item : m_items) { qDebug() << item->policy(); if (item->policy() == "performance") { performance = true; break; } } if (performance) m_currentMode = CPUManagement::Performance; } void CPUManagement::setMode(int value) { CPUManagement::Mode mode = static_cast(value); QString modeString = modeConvertToString(mode); if (modeString.isEmpty() || mode == m_currentMode) return; QProcess process; for (int i = 0; i <= m_items.count(); ++i) { process.start("pkexec", QStringList() << "cutefish-cpufreq" << "-s" << "-c" << QString::number(i) << "-m" << modeString); process.waitForFinished(-1); } m_currentMode = mode; emit modeChanged(); } int CPUManagement::mode() { return m_currentMode; } QString CPUManagement::modeConvertToString(CPUManagement::Mode mode) { QString result; switch (mode) { case CPUManagement::PowerSave: result = "powersave"; break; case CPUManagement::Performance: result = "performance"; break; default: break; } return result; } core-0.8/powerman/cpu/cpumanagement.h000066400000000000000000000024271417504024300177320ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: Reion Wong * * 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 * 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 CPUMANAGEMENT_H #define CPUMANAGEMENT_H #include #include "cpuitem.h" class CPUManagement : public QObject { Q_OBJECT Q_PROPERTY(int mode READ mode WRITE setMode NOTIFY modeChanged) public: enum Mode { PowerSave = 0, Performance, Normal, }; explicit CPUManagement(QObject *parent = nullptr); void setMode(int i); int mode(); QString modeConvertToString(Mode mode); signals: void modeChanged(); private: Mode m_currentMode; QList m_items; }; #endif // CPUMANAGEMENT_H core-0.8/powerman/dimdisplayaction.cpp000066400000000000000000000101411417504024300201770ustar00rootroot00000000000000/*************************************************************************** * Copyright (C) 2021 by Reion Wong * * Copyright (C) 2010 by Dario Freddi * * * * 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 2 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, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * ***************************************************************************/ #include "dimdisplayaction.h" #include #include #include #include #include #include #include #include DimDisplayAction::DimDisplayAction(QObject *parent) : Action(parent) , m_iface("com.cutefish.Settings", "/Brightness", "com.cutefish.Brightness", QDBusConnection::sessionBus()) { if (QX11Info::isPlatformX11()) { // Disable a default timeout, if any xcb_dpms_set_timeouts(QX11Info::connection(), 0, 0, 0); XSetScreenSaver(QX11Info::display(), 0, 0, 0, 0); } } void DimDisplayAction::onWakeupFromIdle() { if (!m_dimmed) { return; } if (m_oldScreenBrightness < 0) m_oldScreenBrightness = 1; // An active inhibition may not let us restore the brightness. // We should wait a bit screen to wake-up from sleep QTimer::singleShot(0, this, [this]() { m_iface.asyncCall("setValue", QVariant::fromValue(m_oldScreenBrightness)); }); m_dimmed = false; } void DimDisplayAction::onIdleTimeout(int msec) { int sec = msec / 1000; if (m_iface.property("brightness").toInt() == 0) return; if (sec == m_dimOnIdleTime) { m_iface.asyncCall("setValue", QVariant::fromValue(0)); // Sleep if (m_sleep) { QDBusInterface iface("com.cutefish.Session", "/Session", "com.cutefish.Session", QDBusConnection::sessionBus()); if (iface.isValid()) { iface.call("suspend"); } } if (m_lock) { QProcess::startDetached("cutefish-screenlocker", QStringList()); } } else if (sec == (m_dimOnIdleTime * 3 / 4)) { const int newBrightness = qRound(m_oldScreenBrightness / 8.0); m_iface.asyncCall("setValue", QVariant::fromValue(newBrightness)); } else if (sec == (m_dimOnIdleTime * 1 / 2)) { m_oldScreenBrightness = m_iface.property("brightness").toInt(); const int newBrightness = qRound(m_oldScreenBrightness / 2.0); m_iface.asyncCall("setValue", QVariant::fromValue(newBrightness)); } m_dimmed = true; } void DimDisplayAction::setTimeout(int timeout) { unregisterIdleTimeout(); if (timeout < 0) { m_dimOnIdleTime = timeout; return; } m_dimOnIdleTime = timeout; registerIdleTimeout(m_dimOnIdleTime * 3 / 4); registerIdleTimeout(m_dimOnIdleTime / 2); registerIdleTimeout(m_dimOnIdleTime); } void DimDisplayAction::setSleep(bool sleep) { m_sleep = sleep; } void DimDisplayAction::setLock(bool lock) { m_lock = lock; } core-0.8/powerman/dimdisplayaction.h000066400000000000000000000040461417504024300176530ustar00rootroot00000000000000/*************************************************************************** * Copyright (C) 2021 by Reion Wong * * Copyright (C) 2010 by Dario Freddi * * * * 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 2 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, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * ***************************************************************************/ #ifndef DIMDISPLAYACTION_H #define DIMDISPLAYACTION_H #include "action.h" #include class DimDisplayAction : public Action { Q_OBJECT public: explicit DimDisplayAction(QObject *parent = nullptr); void onWakeupFromIdle() override; void onIdleTimeout(int msec) override; void setTimeout(int timeout) override; void setSleep(bool sleep); void setLock(bool lock); private: QDBusInterface m_iface; int m_dimOnIdleTime = 0; int m_oldScreenBrightness = 0; bool m_dimmed = false; bool m_sleep = false; bool m_lock = false; }; #endif // DIMDISPLAYACTION_H core-0.8/powerman/idlemanager.cpp000066400000000000000000000066351417504024300171270ustar00rootroot00000000000000/*************************************************************************** * Copyright (C) 2021 by Reion Wong * * Copyright (C) 2010 by Dario Freddi * * * * 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 2 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, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * ***************************************************************************/ #include "idlemanager.h" #include IdleManager *IdleManager::self() { static IdleManager mgr; return &mgr; } IdleManager::IdleManager(QObject *parent) : QObject(parent) { connect(KIdleTime::instance(), SIGNAL(timeoutReached(int,int)), this, SLOT(onKIdleTimeoutReached(int,int))); connect(KIdleTime::instance(), &KIdleTime::resumingFromIdle, this, &IdleManager::onResumingFromIdle); } void IdleManager::registerActionTimeout(Action *action, int secs) { int identifier = KIdleTime::instance()->addIdleTimeout(secs * 1000); QList timeouts = m_registeredActionTimeouts[action]; timeouts.append(identifier); m_registeredActionTimeouts[action] = timeouts; } void IdleManager::unregisterActionTimeouts(Action *action) { // Clear all timeouts from the action const QList< int > timeoutsToClean = m_registeredActionTimeouts[action]; for (int id : timeoutsToClean) { KIdleTime::instance()->removeIdleTimeout(id); } m_registeredActionTimeouts.remove(action); } void IdleManager::onKIdleTimeoutReached(int identifier, int timeout) { for (auto i = m_registeredActionTimeouts.constBegin(), end = m_registeredActionTimeouts.constEnd(); i != end; ++i) { if (i.value().contains(identifier)) { i.key()->onIdleTimeout(timeout); // And it will need to be awaken m_pendingResumeFromIdleActions.insert(i.key()); break; } } // Catch the next resume event if some actions require it if (!m_pendingResumeFromIdleActions.isEmpty()) { KIdleTime::instance()->catchNextResumeEvent(); } } void IdleManager::onResumingFromIdle() { KIdleTime::instance()->simulateUserActivity(); // Wake up the actions in which an idle action was triggered std::for_each(m_pendingResumeFromIdleActions.cbegin(), m_pendingResumeFromIdleActions.cend(), std::mem_fn(&Action::onWakeupFromIdle)); m_pendingResumeFromIdleActions.clear(); } core-0.8/powerman/idlemanager.h000066400000000000000000000040661417504024300165700ustar00rootroot00000000000000/*************************************************************************** * Copyright (C) 2021 by Reion Wong * * Copyright (C) 2010 by Dario Freddi * * * * 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 2 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, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * ***************************************************************************/ #ifndef IDLEMANAGER_H #define IDLEMANAGER_H #include #include #include #include "action.h" class IdleManager : public QObject { Q_OBJECT public: static IdleManager *self(); explicit IdleManager(QObject *parent = nullptr); void registerActionTimeout(Action *action, int secs); void unregisterActionTimeouts(Action *action); private slots: void onKIdleTimeoutReached(int, int); void onResumingFromIdle(); private: friend class Action; QHash> m_registeredActionTimeouts; QSet m_pendingResumeFromIdleActions; }; #endif // IDLEMANAGER_H core-0.8/powerman/lidwatcher.cpp000066400000000000000000000027161417504024300170010ustar00rootroot00000000000000#include "lidwatcher.h" #include LidWatcher::LidWatcher(QObject *parent) : QObject(parent) { m_uPowerIface = new QDBusInterface("org.freedesktop.UPower", "/org/freedesktop/UPower", "org.freedesktop.UPower", QDBusConnection::systemBus(), this); m_uPowerPropertiesIface = new QDBusInterface("org.freedesktop.UPower", "/org/freedesktop/UPower", "org.freedesktop.DBus.Properties", QDBusConnection::systemBus(), this); QDBusConnection::systemBus().connect("org.freedesktop.UPower", "/org/freedesktop/UPower", "org.freedesktop.DBus.Properties", "PropertiesChanged", this, SLOT(onPropertiesChanged())); m_lidClosed = m_uPowerPropertiesIface->property("LidIsClosed").toBool(); } bool LidWatcher::existLid() const { return m_uPowerIface->property("LidIsPresent").toBool(); } bool LidWatcher::lidClosed() const { return m_lidClosed; } void LidWatcher::onPropertiesChanged() { bool isLidClosed = m_uPowerIface->property("LidIsClosed").toBool(); if (isLidClosed != m_lidClosed) { m_lidClosed = isLidClosed; emit lidClosedChanged(); } } core-0.8/powerman/lidwatcher.h000066400000000000000000000007421417504024300164430ustar00rootroot00000000000000#ifndef LIDWATCHER_H #define LIDWATCHER_H #include #include class LidWatcher : public QObject { Q_OBJECT public: explicit LidWatcher(QObject *parent = nullptr); bool existLid() const; bool lidClosed() const; signals: void lidClosedChanged(); private slots: void onPropertiesChanged(); private: QDBusInterface *m_uPowerIface; QDBusInterface *m_uPowerPropertiesIface; bool m_lidClosed; }; #endif // LIDWATCHER_H core-0.8/powerman/main.cpp000066400000000000000000000016431417504024300155750ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: Reion Wong * * 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 * 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 #include "application.h" int main(int argc, char *argv[]) { QApplication a(argc, argv); Application app; a.setQuitOnLastWindowClosed(false); return a.exec(); } core-0.8/powerman/org.freedesktop.ScreenSaver.xml000066400000000000000000000026271417504024300222120ustar00rootroot00000000000000 core-0.8/screen-brightness/000077500000000000000000000000001417504024300157365ustar00rootroot00000000000000core-0.8/screen-brightness/CMakeLists.txt000066400000000000000000000011671417504024300205030ustar00rootroot00000000000000project(cutefish-screen-brightness) set(PROJECT_NAME cutefish-screen-brightness) set(SRCS main.cpp brightnesshelper.h brightnesshelper.cpp ) add_executable(${PROJECT_NAME} ${SRCS} ) target_link_libraries(${PROJECT_NAME} Qt5::Core Qt5::Gui Qt5::Widgets ) configure_file( com.cutefish.brightness.pkexec.policy.in com.cutefish.brightness.pkexec.policy @ONLY ) install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/com.cutefish.brightness.pkexec.policy DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/polkit-1/actions/) core-0.8/screen-brightness/brightnesshelper.cpp000066400000000000000000000071401417504024300220140ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: pjx * rekols * * 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 * 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 "brightnesshelper.h" BrightnessHelper::BrightnessHelper(QObject *parent) : QObject(parent) { init(); anime.setEasingCurve(QEasingCurve::Linear); connect(&anime, &QVariantAnimation::valueChanged, this, [this](const QVariant &value){ if (QAbstractAnimation::Running == anime.state()) { writeBrightness(value.toInt()); } }); connect(&anime, &QVariantAnimation::finished, this, [this]() { qApp->quit(); }); } BrightnessHelper::~BrightnessHelper() { } void BrightnessHelper::init() { const char kSysBrightnessDir[] = "/sys/class/backlight"; const char kMaxFile[] = "max_brightness"; const char kActualFile[] = "actual_brightness"; QDir sys(kSysBrightnessDir); QStringList firmware, platform, raw; QFile file; QByteArray typeBuffer; for (const QFileInfo &device: sys.entryInfoList( QDir::Dirs | QDir::NoDotAndDotDot | QDir::Readable, QDir::Name | QDir::Reversed)) { const QString dev_path = device.filePath(); file.setFileName(dev_path + "/type"); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { continue; } typeBuffer = file.readLine().trimmed(); if (typeBuffer == "firmware") { firmware.append(dev_path); } else if(typeBuffer == "platform") { platform.append(dev_path); } else if (typeBuffer == "raw") { raw.append(dev_path); } else { qWarning() << "unsupported type in '" << file.fileName() << "' : " << QString(typeBuffer); } file.close(); } if (!firmware.isEmpty()) name = firmware.constFirst(); else if (!platform.isEmpty()) name = platform.constFirst(); else if (!raw.isEmpty()) name = raw.constFirst(); actual = readFile(QDir(name).filePath(kActualFile)).toInt(); maxValue = readFile(QDir(name).filePath(kMaxFile)).toInt(); } void BrightnessHelper::setBrightness(int value) { if (value < 0) value = 0; if (value > 100) value = 100; anime.setDuration(85); anime.setStartValue(actual); const int end = static_cast(value /100.0 * maxValue); anime.setEndValue(end); anime.start(); } void BrightnessHelper::increaseBrightness() { int value = static_cast(actual / (double)maxValue * 100); setBrightness(value + 20); } void BrightnessHelper::decreaseBrightness() { int value = static_cast(actual / (double)maxValue * 100); setBrightness(value - 20); } void BrightnessHelper::writeBrightness(int brightness) { if (brightness < 0) brightness = 0; if (brightness > maxValue) brightness = maxValue; QString dbg_s = QDir(name).filePath("brightness"); writeFile(QDir(name).filePath("brightness"), QString::number(brightness)); } core-0.8/screen-brightness/brightnesshelper.h000066400000000000000000000036601417504024300214640ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: pjx * rekols * * 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 * 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 BRIGHTNESSHELPER_H #define BRIGHTNESSHELPER_H #include #include #include #include #include #include #include inline QString readFile(const QString &fileName) { QFile file(fileName); if (file.open(QIODevice::ReadOnly)) { QString data = QString::fromUtf8(file.readAll()); file.close(); return data; } return QString(); } inline bool writeFile(const QString &fileName, const QString &data) { QFile file(fileName); if (file.open(QIODevice::WriteOnly | QIODevice::Text)) { QTextStream textStream(&file); textStream << data; textStream.flush(); file.close(); return true; } return false; } class BrightnessHelper : public QObject { Q_OBJECT public: explicit BrightnessHelper(QObject *parent = nullptr); ~BrightnessHelper(); void init(); void setBrightness(int value); void increaseBrightness(); void decreaseBrightness(); int actual; int maxValue; QString name; QVariantAnimation anime; private: void writeBrightness(int brightness); }; #endif // BRIGHTNESSHELPER_H core-0.8/screen-brightness/com.cutefish.brightness.pkexec.policy.in000066400000000000000000000012271417504024300256020ustar00rootroot00000000000000 Authentication is required to Change Brightness battery no no yes @CMAKE_INSTALL_FULL_BINDIR@/cutefish-screen-brightness core-0.8/screen-brightness/main.cpp000066400000000000000000000035531417504024300173740ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: rekols * pjx * * 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 * 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 #include "brightnesshelper.h" int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); QCommandLineParser parser; parser.addHelpOption(); parser.addVersionOption(); QCommandLineOption setOption(QStringLiteral("set"), QStringLiteral("Set screen brightness")); parser.addOption(setOption); parser.addPositionalArgument("value", "Value"); QCommandLineOption increaseOption(QStringLiteral("i"), QStringLiteral("Increase brightness")); parser.addOption(increaseOption); QCommandLineOption decreaseOption(QStringLiteral("d"), QStringLiteral("Decrease brightness")); parser.addOption(decreaseOption); parser.process(app); BrightnessHelper *brightnessHelper = new BrightnessHelper(); if (parser.isSet(setOption)) { int value = parser.positionalArguments().value(0).toInt(); brightnessHelper->setBrightness(value); } else if (parser.isSet(increaseOption)) brightnessHelper->increaseBrightness(); else if (parser.isSet(decreaseOption)) brightnessHelper->decreaseBrightness(); app.exec(); } core-0.8/sddm-helper/000077500000000000000000000000001417504024300145155ustar00rootroot00000000000000core-0.8/sddm-helper/CMakeLists.txt000066400000000000000000000010511417504024300172520ustar00rootroot00000000000000project(cutefish-sddm-helper) set(PROJECT_NAME cutefish-sddm-helper) set(SRCS main.cpp ) add_executable(${PROJECT_NAME} ${SRCS} ) target_link_libraries(${PROJECT_NAME} Qt5::Core Qt5::Gui ) configure_file( com.cutefish.sddm.helper.pkexec.policy.in com.cutefish.sddm.helper.pkexec.policy @ONLY ) install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/com.cutefish.sddm.helper.pkexec.policy DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/polkit-1/actions/) core-0.8/sddm-helper/com.cutefish.sddm.helper.pkexec.policy.in000066400000000000000000000012111417504024300244070ustar00rootroot00000000000000 Authentication is required to SDDM DPI battery no no yes @CMAKE_INSTALL_FULL_BINDIR@/cutefish-sddm-helper core-0.8/sddm-helper/main.cpp000066400000000000000000000033071417504024300161500ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: Kate Leet (kate@cutefishos.com) * * 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 * 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 #include #include #include #include int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); QCommandLineParser parser; parser.addHelpOption(); parser.addVersionOption(); QCommandLineOption dpiOption(QStringLiteral("dpi"), QStringLiteral("Set DPI")); parser.addOption(dpiOption); parser.addPositionalArgument("value", "Value"); parser.process(app); if (parser.isSet(dpiOption)) { int value = parser.positionalArguments().value(0).toInt(); int minValue = 96; if (value < minValue) value = minValue; QDir dir("/etc/sddm.conf.d"); if (!dir.exists()) { dir.mkpath("/etc/sddm.conf.d"); } QSettings settings("/etc/sddm.conf.d/dpi.conf", QSettings::IniFormat); settings.beginGroup("X11"); settings.setValue("ServerArguments", QString("-nolisten tcp -dpi %1").arg(value)); } return 0; } core-0.8/session/000077500000000000000000000000001417504024300137745ustar00rootroot00000000000000core-0.8/session/CMakeLists.txt000066400000000000000000000016101417504024300165320ustar00rootroot00000000000000project(cutefish-session) set(TARGET cutefish-session) set(SOURCES application.cpp main.cpp process.cpp processmanager.cpp networkproxymanager.cpp powermanager/power.cpp powermanager/powerproviders.cpp ) qt5_add_dbus_adaptor(DBUS_SOURCES com.cutefish.Session.xml application.h Application sessionadaptor SessionAdaptor) set_source_files_properties(${DBUS_SOURCES} PROPERTIES SKIP_AUTOGEN ON) find_package(KF5WindowSystem) add_executable(${TARGET} ${SOURCES} ${DBUS_SOURCES}) target_link_libraries(${TARGET} Qt5::Core Qt5::Gui Qt5::Widgets Qt5::Quick Qt5::DBus Qt5::X11Extras KF5::WindowSystem ) install(TARGETS ${TARGET} DESTINATION ${CMAKE_INSTALL_BINDIR}) install(FILES cutefish-xsession.desktop DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/xsessions/) core-0.8/session/application.cpp000066400000000000000000000314411417504024300170060ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: revenmartin * * 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 * 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 "application.h" #include "sessionadaptor.h" // Qt #include #include #include #include #include #include #include #include #include // STL #include std::optional getSystemdEnvironment() { QStringList list; auto msg = QDBusMessage::createMethodCall(QStringLiteral("org.freedesktop.systemd1"), QStringLiteral("/org/freedesktop/systemd1"), QStringLiteral("org.freedesktop.DBus.Properties"), QStringLiteral("Get")); msg << QStringLiteral("org.freedesktop.systemd1.Manager") << QStringLiteral("Environment"); auto reply = QDBusConnection::sessionBus().call(msg); if (reply.type() == QDBusMessage::ErrorMessage) { return std::nullopt; } // Make sure the returned type is correct. auto arguments = reply.arguments(); if (arguments.isEmpty() || arguments[0].userType() != qMetaTypeId()) { return std::nullopt; } auto variant = qdbus_cast(arguments[0]); if (variant.type() != QVariant::StringList) { return std::nullopt; } return variant.toStringList(); } bool isShellVariable(const QByteArray &name) { return name == "_" || name.startsWith("SHLVL"); } bool isSessionVariable(const QByteArray &name) { // Check is variable is specific to session. return name == "DISPLAY" || name == "XAUTHORITY" || // name == "WAYLAND_DISPLAY" || name == "WAYLAND_SOCKET" || // name.startsWith("XDG_"); } void setEnvironmentVariable(const QByteArray &name, const QByteArray &value) { if (qgetenv(name) != value) { qputenv(name, value); } } Application::Application(int &argc, char **argv) : QApplication(argc, argv) , m_processManager(new ProcessManager(this)) , m_networkProxyManager(new NetworkProxyManager) , m_wayland(false) { new SessionAdaptor(this); // connect to D-Bus and register as an object: QDBusConnection::sessionBus().registerService(QStringLiteral("com.cutefish.Session")); QDBusConnection::sessionBus().registerObject(QStringLiteral("/Session"), this); QCommandLineParser parser; parser.setApplicationDescription(QStringLiteral("Cutefish Session")); parser.addHelpOption(); QCommandLineOption waylandOption(QStringList() << "w" << "wayland" << "Wayland Mode"); parser.addOption(waylandOption); parser.process(*this); m_wayland = parser.isSet(waylandOption); createConfigDirectory(); initKWinConfig(); initLanguage(); initScreenScaleFactors(); initXResource(); initEnvironments(); if (!syncDBusEnvironment()) { // Startup error qDebug() << "Could not sync environment to dbus."; qApp->exit(1); } // We import systemd environment after we sync the dbus environment here. // Otherwise it may leads to some unwanted order of applying environment // variables (e.g. LANG and LC_*) // ref plasma importSystemdEnvrionment(); qunsetenv("XCURSOR_THEME"); qunsetenv("XCURSOR_SIZE"); qunsetenv("SESSION_MANAGER"); m_networkProxyManager->update(); QTimer::singleShot(50, this, &Application::updateUserDirs); QTimer::singleShot(100, m_processManager, &ProcessManager::start); } bool Application::wayland() const { return m_wayland; } void Application::launch(const QString &exec, const QStringList &args) { QProcess process; process.setProgram(exec); process.setProcessEnvironment(QProcessEnvironment::systemEnvironment()); process.setArguments(args); process.startDetached(); } void Application::launch(const QString &exec, const QString &workingDir, const QStringList &args) { QProcess process; process.setProgram(exec); process.setProcessEnvironment(QProcessEnvironment::systemEnvironment()); process.setWorkingDirectory(workingDir); process.setArguments(args); process.startDetached(); } void Application::initEnvironments() { // Set defaults if (qEnvironmentVariableIsEmpty("XDG_DATA_HOME")) qputenv("XDG_DATA_HOME", QDir::home().absoluteFilePath(QStringLiteral(".local/share")).toLocal8Bit()); if (qEnvironmentVariableIsEmpty("XDG_DESKTOP_DIR")) qputenv("XDG_DESKTOP_DIR", QDir::home().absoluteFilePath(QStringLiteral("/Desktop")).toLocal8Bit()); if (qEnvironmentVariableIsEmpty("XDG_CONFIG_HOME")) qputenv("XDG_CONFIG_HOME", QDir::home().absoluteFilePath(QStringLiteral(".config")).toLocal8Bit()); if (qEnvironmentVariableIsEmpty("XDG_CACHE_HOME")) qputenv("XDG_CACHE_HOME", QDir::home().absoluteFilePath(QStringLiteral(".cache")).toLocal8Bit()); if (qEnvironmentVariableIsEmpty("XDG_DATA_DIRS")) qputenv("XDG_DATA_DIRS", "/usr/local/share/:/usr/share/"); if (qEnvironmentVariableIsEmpty("XDG_CONFIG_DIRS")) qputenv("XDG_CONFIG_DIRS", "/etc/xdg"); // Environment qputenv("DESKTOP_SESSION", "Cutefish"); qputenv("XDG_CURRENT_DESKTOP", "Cutefish"); qputenv("XDG_SESSION_DESKTOP", "Cutefish"); // Qt qputenv("QT_QPA_PLATFORMTHEME", "cutefish"); qputenv("QT_PLATFORM_PLUGIN", "cutefish"); qputenv("QT_AUTO_SCREEN_SCALE_FACTOR", "0"); // IM Config // qputenv("GTK_IM_MODULE", "fcitx5"); // qputenv("QT4_IM_MODULE", "fcitx5"); // qputenv("QT_IM_MODULE", "fcitx5"); // qputenv("CLUTTER_IM_MODULE", "fcitx5"); // qputenv("XMODIFIERS", "@im=fcitx"); } void Application::initLanguage() { QSettings settings(QSettings::UserScope, "cutefishos", "language"); QString value = settings.value("language", "").toString(); // Init Language if (value.isEmpty()) { QFile file("/etc/locale.gen"); if (file.open(QIODevice::ReadOnly)) { QStringList lines = QString(file.readAll()).split('\n'); for (const QString &line : lines) { if (line.startsWith('#')) continue; if (line.trimmed().isEmpty()) continue; value = line.split(' ').first().split('.').first(); } } } if (value.isEmpty()) value = "en_US"; settings.setValue("language", value); QString str = QString("%1.UTF-8").arg(value); const auto lcValues = { "LANG", "LC_NUMERIC", "LC_TIME", "LC_MONETARY", "LC_MEASUREMENT", "LC_COLLATE", "LC_CTYPE" }; for (auto lc : lcValues) { const QString value = str; if (!value.isEmpty()) { qputenv(lc, value.toUtf8()); } } if (!value.isEmpty()) { qputenv("LANGUAGE", value.toUtf8()); } } void Application::initScreenScaleFactors() { QSettings settings(QSettings::UserScope, "cutefishos", "theme"); qreal scaleFactor = settings.value("PixelRatio", 1.0).toReal(); qputenv("QT_SCREEN_SCALE_FACTORS", QByteArray::number(scaleFactor)); // for Gtk if (qFloor(scaleFactor) > 1) { qputenv("GDK_SCALE", QByteArray::number(scaleFactor, 'g', 0)); qputenv("GDK_DPI_SCALE", QByteArray::number(1.0 / scaleFactor, 'g', 3)); } else { qputenv("GDK_SCALE", QByteArray::number(qFloor(scaleFactor), 'g', 0)); qputenv("GDK_DPI_SCALE", QByteArray::number(qFloor(scaleFactor), 'g', 0)); } } void Application::initXResource() { QSettings settings(QSettings::UserScope, "cutefishos", "theme"); qreal scaleFactor = settings.value("PixelRatio", 1.0).toReal(); int fontDpi = 96 * scaleFactor; QString cursorTheme = settings.value("CursorTheme", "default").toString(); int cursorSize = settings.value("CursorSize", 24).toInt() * scaleFactor; int xftAntialias = settings.value("XftAntialias", 1).toBool(); QString xftHintStyle = settings.value("XftHintStyle", "hintslight").toString(); const QString datas = QString("Xft.dpi: %1\n" "Xcursor.theme: %2\n" "Xcursor.size: %3\n" "Xft.antialias: %4\n" "Xft.hintstyle: %5\n" "Xft.rgba: rgb") .arg(fontDpi) .arg(cursorTheme) .arg(cursorSize) .arg(xftAntialias) .arg(xftHintStyle); QProcess p; p.start(QStringLiteral("xrdb"), {QStringLiteral("-quiet"), QStringLiteral("-merge"), QStringLiteral("-nocpp")}); p.setProcessChannelMode(QProcess::ForwardedChannels); p.write(datas.toLatin1()); p.closeWriteChannel(); p.waitForFinished(-1); // For cutefish-wine qputenv("CUTEFISH_FONT_DPI", QByteArray::number(fontDpi)); // Init cursor runSync("cupdatecursor", {cursorTheme, QString::number(cursorSize)}); // qputenv("XCURSOR_THEME", cursorTheme.toLatin1()); // qputenv("XCURSOR_SIZE", QByteArray::number(cursorSize * scaleFactor)); } void Application::initKWinConfig() { QSettings settings(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + "/kwinrc", QSettings::IniFormat); settings.beginGroup("Effect-Blur"); settings.setValue("BlurStrength", 10); settings.setValue("NoiseStrength", 0); settings.endGroup(); settings.beginGroup("Windows"); settings.setValue("FocusStealingPreventionLevel", 0); settings.setValue("HideUtilityWindowsForInactive", false); settings.setValue("BorderlessMaximizedWindows", false); settings.setValue("Placement", "Centered"); settings.endGroup(); settings.beginGroup("org.kde.kdecoration2"); settings.setValue("BorderSize", "Normal"); settings.setValue("ButtonsOnLeft", ""); settings.setValue("ButtonsOnRight", "HIAX"); settings.setValue("library", "org.cutefish.decoration"); settings.setValue("theme", ""); settings.endGroup(); } bool Application::syncDBusEnvironment() { int exitCode = 0; // At this point all environment variables are set, let's send it to the DBus session server to update the activation environment if (!QStandardPaths::findExecutable(QStringLiteral("dbus-update-activation-environment")).isEmpty()) { exitCode = runSync(QStringLiteral("dbus-update-activation-environment"), { QStringLiteral("--systemd"), QStringLiteral("--all") }); } return exitCode == 0; } // Import systemd user environment. // Systemd read ~/.config/environment.d which applies to all systemd user unit. // But it won't work if cutefishDE is not started by systemd. void Application::importSystemdEnvrionment() { auto environment = getSystemdEnvironment(); if (!environment) { return; } for (auto &envString : environment.value()) { const auto env = envString.toLocal8Bit(); const int idx = env.indexOf('='); if (Q_UNLIKELY(idx <= 0)) { continue; } const auto name = env.left(idx); if (isShellVariable(name) || isSessionVariable(name)) { continue; } setEnvironmentVariable(name, env.mid(idx + 1)); } } void Application::createConfigDirectory() { const QString configDir = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation); if (!QDir().mkpath(configDir)) qDebug() << "Could not create config directory XDG_CONFIG_HOME: " << configDir; } void Application::updateUserDirs() { // bool isCutefishOS = QFile::exists("/etc/cutefishos"); // if (!isCutefishOS) // return; // QProcess p; // p.setEnvironment(QStringList() << "LC_ALL=C"); // p.start("xdg-user-dirs-update", QStringList() << "--force"); // p.waitForFinished(-1); } int Application::runSync(const QString &program, const QStringList &args, const QStringList &env) { QProcess p; if (!env.isEmpty()) p.setEnvironment(QProcess::systemEnvironment() << env); p.setProcessChannelMode(QProcess::ForwardedChannels); p.start(program, args); p.waitForFinished(-1); if (p.exitCode()) { qWarning() << program << args << "exited with code" << p.exitCode(); } return p.exitCode(); } core-0.8/session/application.h000066400000000000000000000042461417504024300164560ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: revenmartin * * 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 * 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 APPLICATION_H #define APPLICATION_H #include #include "processmanager.h" #include "networkproxymanager.h" #include "powermanager/power.h" class Application : public QApplication { Q_OBJECT public: explicit Application(int &argc, char **argv); bool wayland() const; public slots: void logout() { m_processManager->logout(); } void reboot() { m_power.reboot(); QCoreApplication::exit(0); } void powerOff() { m_power.shutdown(); QCoreApplication::exit(0); } void suspend() { m_power.suspend(); } void startDesktopProcess() { m_processManager->startDesktopProcess(); } void updateNetworkProxy() { m_networkProxyManager->update(); } void launch(const QString &exec, const QStringList &args); void launch(const QString &exec, const QString &workingDir, const QStringList &args); private: void initEnvironments(); void initLanguage(); void initScreenScaleFactors(); void initXResource(); void initKWinConfig(); bool syncDBusEnvironment(); void importSystemdEnvrionment(); void createConfigDirectory(); void updateUserDirs(); int runSync(const QString &program, const QStringList &args, const QStringList &env = {}); private: ProcessManager *m_processManager; NetworkProxyManager *m_networkProxyManager; Power m_power; bool m_wayland; }; #endif // APPLICATION_H core-0.8/session/com.cutefish.Session.xml000066400000000000000000000024061417504024300205310ustar00rootroot00000000000000 core-0.8/session/cutefish-xsession.desktop000066400000000000000000000002071417504024300210510ustar00rootroot00000000000000[Desktop Entry] Type=Application Exec=cutefish-session TryExec=cutefish-session Name=Cutefish Desktop Keywords=session Comment=session core-0.8/session/main.cpp000066400000000000000000000022661417504024300154320ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: revenmartin * * 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 * 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 "application.h" #include int main(int argc, char *argv[]) { // putenv((char *)"SESSION_MANAGER="); // force xcb QPA plugin as session manager server is very X11 specific. qputenv("QT_QPA_PLATFORM", QByteArrayLiteral("xcb")); QQuickWindow::setDefaultAlphaBuffer(true); QCoreApplication::setAttribute(Qt::AA_DisableHighDpiScaling); Application a(argc, argv); a.setQuitOnLastWindowClosed(false); return a.exec(); } core-0.8/session/networkproxymanager.cpp000066400000000000000000000065631417504024300206400ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: Reion Wong * * 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 * 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 "networkproxymanager.h" #include #include #include #include NetworkProxyManager::NetworkProxyManager(QObject *parent) : QObject(parent) , m_settings(QSettings::UserScope, "cutefishos", "network") { } void NetworkProxyManager::update() { qunsetenv("HTTP_PROXY"); qunsetenv("HTTPS_PROXY"); qunsetenv("FTP_PROXY"); qunsetenv("ALL_PROXY"); qunsetenv("NO_PROXY"); qunsetenv("http_proxy"); qunsetenv("https_proxy"); qunsetenv("ftp_proxy"); qunsetenv("all_proxy"); qunsetenv("no_proxy"); m_settings.sync(); m_flag = m_settings.value("ProxyFlag", 0).toInt(); m_useSameProxy = m_settings.value("UseSameProxy", false).toBool(); m_scriptProxy = m_settings.value("ProxyScriptProxy", "").toString(); m_httpProxy = m_settings.value("HttpProxy", "").toString(); m_ftpProxy = m_settings.value("FtpProxy", "").toString(); m_socksProxy = m_settings.value("SocksProxy", "").toString(); m_httpProxyPort = m_settings.value("HttpProxyPort", "").toString(); m_ftpProxyPort = m_settings.value("FtpProxyPort", "").toString(); m_socksProxyPort = m_settings.value("SocksProxyPort", "").toString(); QMap dbusActivationEnv; QStringList systemdUpdates; if (m_flag == 0) { // No proxy } else if (m_flag == 1) { // Use proxy auto configuration URL } else if (m_flag == 2) { // Use manually specified proxy configuration QString httpProxy = QString("http://%1:%2/").arg(m_httpProxy).arg(m_httpProxyPort); QString ftpProxy = QString("http://%1:%2/").arg(m_ftpProxy).arg(m_ftpProxyPort); if (m_useSameProxy) { ftpProxy = httpProxy; } if (!m_httpProxy.isEmpty() && !m_httpProxyPort.isEmpty()) { qputenv("HTTP_PROXY", httpProxy.toLatin1()); qputenv("HTTPS_PROXY", httpProxy.toLatin1()); qputenv("http_proxy", httpProxy.toLatin1()); qputenv("https_proxy", httpProxy.toLatin1()); } if (!m_ftpProxy.isEmpty() && !m_ftpProxyPort.isEmpty()) { qputenv("FTP_PROXY", ftpProxy.toLatin1()); qputenv("ftp_proxy", ftpProxy.toLatin1()); } qputenv("NO_PROXY", "localhost,127.0.0.0/8,::1"); qputenv("no_proxy", "localhost,127.0.0.0/8,::1"); if (!m_socksProxy.isEmpty() && !m_socksProxyPort.isEmpty()) { // qputenv("ALL_PROXY", QString("socks://%1:%2/").arg(m_socksProxy).arg(m_socksProxyPort).toLatin1()); // qputenv("all_proxy", QString("socks://%1:%2/").arg(m_socksProxy).arg(m_socksProxyPort).toLatin1()); } } } core-0.8/session/networkproxymanager.h000066400000000000000000000024061417504024300202750ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: Reion Wong * * 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 * 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 NETWORKPROXYMANAGER_H #define NETWORKPROXYMANAGER_H #include #include class NetworkProxyManager : public QObject { Q_OBJECT public: explicit NetworkProxyManager(QObject *parent = nullptr); void update(); private: QSettings m_settings; int m_flag; bool m_useSameProxy; QString m_scriptProxy; QString m_httpProxy; QString m_ftpProxy; QString m_socksProxy; QString m_httpProxyPort; QString m_ftpProxyPort; QString m_socksProxyPort; }; #endif // NETWORKPROXYMANAGER_H core-0.8/session/powermanager/000077500000000000000000000000001417504024300164635ustar00rootroot00000000000000core-0.8/session/powermanager/power.cpp000066400000000000000000000053071417504024300203300ustar00rootroot00000000000000/* BEGIN_COMMON_COPYRIGHT_HEADER * Authors: * Alexander Sokoloff * * This program or library is free software; you can redistribute it * and/or modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * You should have received a copy of the GNU Lesser General * Public License along with this library; if not, write to the * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301 USA * * END_COMMON_COPYRIGHT_HEADER */ #include "power.h" #include "powerproviders.h" #include #include Power::Power(bool useSessionProvider, QObject * parent /*= nullptr*/) : QObject(parent) { m_providers.append(new SystemdProvider(this)); m_providers.append(new UPowerProvider(this)); m_providers.append(new ConsoleKitProvider(this)); } Power::Power(QObject * parent /*= nullptr*/) : Power(true, parent) { } Power::~Power() { } bool Power::canAction(Power::Action action) const { for(const PowerProvider* provider : qAsConst(m_providers)) if (provider->canAction(action)) return true; return false; } bool Power::doAction(Power::Action action) { for(PowerProvider* provider : qAsConst(m_providers)) { if (provider->canAction(action) && provider->doAction(action)) { return true; } } return false; } bool Power::canLogout() const { return canAction(PowerLogout); } bool Power::canHibernate() const { return canAction(PowerHibernate); } bool Power::canReboot() const { return canAction(PowerReboot); } bool Power::canShutdown() const { return canAction(PowerShutdown); } bool Power::canSuspend() const { return canAction(PowerSuspend); } bool Power::canMonitorOff() const { return canAction(PowerMonitorOff); } bool Power::canShowLeaveDialog() const { return canAction(PowerShowLeaveDialog); } bool Power::logout() { return doAction(PowerLogout); } bool Power::hibernate() { return doAction(PowerHibernate); } bool Power::reboot() { return doAction(PowerReboot); } bool Power::shutdown() { return doAction(PowerShutdown); } bool Power::suspend() { return doAction(PowerSuspend); } bool Power::monitorOff() { return doAction(PowerMonitorOff); } bool Power::showLeaveDialog() { return doAction(PowerShowLeaveDialog); } core-0.8/session/powermanager/power.h000066400000000000000000000104361417504024300177740ustar00rootroot00000000000000/* BEGIN_COMMON_COPYRIGHT_HEADER * Authors: * Alexander Sokoloff * * This program or library is free software; you can redistribute it * and/or modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * You should have received a copy of the GNU Lesser General * Public License along with this library; if not, write to the * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301 USA * * END_COMMON_COPYRIGHT_HEADER */ #ifndef POWER_H #define POWER_H #include #include class PowerProvider; /*! Power class provides an interface to control system-wide power and session management. It allows logout from the user session, hibernate, reboot, shutdown and suspend computer. This is a wrapper class. All the real work is done in the PowerWorker classes. */ class Power : public QObject { Q_OBJECT public: /// Power can perform next actions: enum Action{ PowerLogout, /// Close the current user session. PowerHibernate, /// Hibernate the comupter PowerReboot, /// Reboot the computer PowerShutdown, /// Shutdown the computer PowerSuspend, /// Suspend the computer PowerMonitorOff, /// Turn off the monitor(s) PowerShowLeaveDialog /// Show the lxqt-leave dialog }; /*! * Constructs the Power object. * \param useLxqtSessionProvider indicates if the DBus methods * provided by lxqt-session should be considered. This is useful to * avoid recursion if the lxqt-session wants to provide some of the * methods by itself with internal use of this object. */ explicit Power(bool useSessionProvider, QObject *parent = nullptr); /// Constructs a Power with using the lxqt-session provider. explicit Power(QObject *parent = nullptr); /// Destroys the object. ~Power() override; /// Returns true if the Power can perform action. bool canAction(Action action) const; //! This function is provided for convenience. It's equivalent to calling canAction(PowerLogout). bool canLogout() const; //! This function is provided for convenience. It's equivalent to calling canAction(PowerHibernate). bool canHibernate() const; //! This function is provided for convenience. It's equivalent to calling canAction(PowerReboot). bool canReboot() const; //! This function is provided for convenience. It's equivalent to calling canAction(PowerShutdown). bool canShutdown() const; //! This function is provided for convenience. It's equivalent to calling canAction(PowerSuspend). bool canSuspend() const; //! This function is provided for convenience. It's equivalent to calling canAction(PowerMonitorOff). bool canMonitorOff() const; //! This function is provided for convenience. It's equivalent to calling canAction(PowerShowLeaveDialog). bool canShowLeaveDialog() const; public Q_SLOTS: /// Performs the requested action. bool doAction(Action action); //! This function is provided for convenience. It's equivalent to calling doAction(PowerLogout). bool logout(); //! This function is provided for convenience. It's equivalent to calling doAction(PowerHibernate). bool hibernate(); //! This function is provided for convenience. It's equivalent to calling doAction(PowerReboot). bool reboot(); //! This function is provided for convenience. It's equivalent to calling doAction(PowerShutdown). bool shutdown(); //! This function is provided for convenience. It's equivalent to calling doAction(PowerSuspend). bool suspend(); //! This function is provided for convenience. It's equivalent to calling doAction(PowerMonitorOff). bool monitorOff(); //! This function is provided for convenience. It's equivalent to calling doAction(PowerShowLeaveDialog). bool showLeaveDialog(); private: QList m_providers; }; #endif core-0.8/session/powermanager/powerproviders.cpp000066400000000000000000000345171417504024300222730ustar00rootroot00000000000000/* BEGIN_COMMON_COPYRIGHT_HEADER * Authors: * Alexander Sokoloff * Petr Vanek * * This program or library is free software; you can redistribute it * and/or modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * You should have received a copy of the GNU Lesser General * Public License along with this library; if not, write to the * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301 USA * * END_COMMON_COPYRIGHT_HEADER */ #include "powerproviders.h" #include #include #include #include // for kill() #define UPOWER_SERVICE "org.freedesktop.UPower" #define UPOWER_PATH "/org/freedesktop/UPower" #define UPOWER_INTERFACE UPOWER_SERVICE #define CONSOLEKIT_SERVICE "org.freedesktop.ConsoleKit" #define CONSOLEKIT_PATH "/org/freedesktop/ConsoleKit/Manager" #define CONSOLEKIT_INTERFACE "org.freedesktop.ConsoleKit.Manager" #define SYSTEMD_SERVICE "org.freedesktop.login1" #define SYSTEMD_PATH "/org/freedesktop/login1" #define SYSTEMD_INTERFACE "org.freedesktop.login1.Manager" #define PROPERTIES_INTERFACE "org.freedesktop.DBus.Properties" /************************************************ Helper func ************************************************/ void printDBusMsg(const QDBusMessage &msg) { qWarning() << "** Dbus error **************************"; qWarning() << "Error name " << msg.errorName(); qWarning() << "Error msg " << msg.errorMessage(); qWarning() << "****************************************"; } /************************************************ Helper func ************************************************/ static bool dbusCall(const QString &service, const QString &path, const QString &interface, const QDBusConnection &connection, const QString & method, PowerProvider::DbusErrorCheck errorCheck = PowerProvider::CheckDBUS ) { QDBusInterface dbus(service, path, interface, connection); if (!dbus.isValid()) { qWarning() << "dbusCall: QDBusInterface is invalid" << service << path << interface << method; if (errorCheck == PowerProvider::CheckDBUS) { // Notification::notify( // QObject::tr("Power Manager Error"), // QObject::tr("QDBusInterface is invalid") + QStringLiteral("\n\n") + service + QStringLiteral(' ') + path + QStringLiteral(' ') + interface + QStringLiteral(' ') + method, // QStringLiteral("logo.png")); } return false; } QDBusMessage msg = dbus.call(method); if (!msg.errorName().isEmpty()) { printDBusMsg(msg); if (errorCheck == PowerProvider::CheckDBUS) { // Notification::notify( // QObject::tr("Power Manager Error (D-BUS call)"), // msg.errorName() + QStringLiteral("\n\n") + msg.errorMessage(), // QStringLiteral("logo.png")); } } // If the method no returns value, we believe that it was successful. return msg.arguments().isEmpty() || msg.arguments().constFirst().isNull() || msg.arguments().constFirst().toBool(); } /************************************************ Helper func Just like dbusCall(), except that systemd returns a string instead of a bool, and it takes an "interactivity boolean" as an argument. ************************************************/ static bool dbusCallSystemd(const QString &service, const QString &path, const QString &interface, const QDBusConnection &connection, const QString &method, bool needBoolArg, PowerProvider::DbusErrorCheck errorCheck = PowerProvider::CheckDBUS ) { QDBusInterface dbus(service, path, interface, connection); if (!dbus.isValid()) { qWarning() << "dbusCall: QDBusInterface is invalid" << service << path << interface << method; if (errorCheck == PowerProvider::CheckDBUS) { // Notification::notify( // QObject::tr("Power Manager Error"), // QObject::tr("QDBusInterface is invalid") + QStringLiteral("\n\n") + service + QStringLiteral(' ') + path + QStringLiteral(' ')+ interface + QStringLiteral(' ') + method, // QStringLiteral("logo.png")); } return false; } QDBusMessage msg = dbus.call(method, needBoolArg ? QVariant(true) : QVariant()); if (!msg.errorName().isEmpty()) { printDBusMsg(msg); if (errorCheck == PowerProvider::CheckDBUS) { // Notification::notify( // QObject::tr("Power Manager Error (D-BUS call)"), // msg.errorName() + QStringLiteral("\n\n") + msg.errorMessage(), // QStringLiteral("logo.png")); } } // If the method no returns value, we believe that it was successful. if (msg.arguments().isEmpty() || msg.arguments().constFirst().isNull()) return true; QString response = msg.arguments().constFirst().toString(); qDebug() << "systemd:" << method << "=" << response; return response == QStringLiteral("yes") || response == QStringLiteral("challenge"); } /************************************************ Helper func ************************************************/ bool dbusGetProperty(const QString &service, const QString &path, const QString &interface, const QDBusConnection &connection, const QString & property ) { QDBusInterface dbus(service, path, interface, connection); if (!dbus.isValid()) { qWarning() << "dbusGetProperty: QDBusInterface is invalid" << service << path << interface << property; // Notification::notify(QObject::tr("Power Manager"), // "logo.png", // QObject::tr("Power Manager Error"), // QObject::tr("QDBusInterface is invalid")+ "\n\n" + service +" " + path +" " + interface +" " + property); return false; } QDBusMessage msg = dbus.call(QStringLiteral("Get"), dbus.interface(), property); if (!msg.errorName().isEmpty()) { printDBusMsg(msg); // Notification::notify(QObject::tr("Power Manager"), // "logo.png", // QObject::tr("Power Manager Error (Get Property)"), // msg.errorName() + "\n\n" + msg.errorMessage()); } return !msg.arguments().isEmpty() && msg.arguments().constFirst().value().variant().toBool(); } /************************************************ PowerProvider ************************************************/ PowerProvider::PowerProvider(QObject *parent): QObject(parent) { } PowerProvider::~PowerProvider() { } /************************************************ UPowerProvider ************************************************/ UPowerProvider::UPowerProvider(QObject *parent): PowerProvider(parent) { } UPowerProvider::~UPowerProvider() { } bool UPowerProvider::canAction(Power::Action action) const { QString command; QString property; switch (action) { case Power::PowerHibernate: property = QStringLiteral("CanHibernate"); command = QStringLiteral("HibernateAllowed"); break; case Power::PowerSuspend: property = QStringLiteral("CanSuspend"); command = QStringLiteral("SuspendAllowed"); break; default: return false; } return dbusGetProperty( // Whether the system is able to hibernate. QStringLiteral(UPOWER_SERVICE), QStringLiteral(UPOWER_PATH), QStringLiteral(PROPERTIES_INTERFACE), QDBusConnection::systemBus(), property ) && dbusCall( // Check if the caller has (or can get) the PolicyKit privilege to call command. QStringLiteral(UPOWER_SERVICE), QStringLiteral(UPOWER_PATH), QStringLiteral(UPOWER_INTERFACE), QDBusConnection::systemBus(), command, // canAction should be always silent because it can freeze // g_main_context_iteration Qt event loop in QMessageBox // on panel startup if there is no DBUS running. PowerProvider::DontCheckDBUS ); } bool UPowerProvider::doAction(Power::Action action) { QString command; switch (action) { case Power::PowerHibernate: command = QStringLiteral("Hibernate"); break; case Power::PowerSuspend: command = QStringLiteral("Suspend"); break; default: return false; } return dbusCall(QStringLiteral(UPOWER_SERVICE), QStringLiteral(UPOWER_PATH), QStringLiteral(UPOWER_INTERFACE), QDBusConnection::systemBus(), command ); } /************************************************ ConsoleKitProvider ************************************************/ ConsoleKitProvider::ConsoleKitProvider(QObject *parent): PowerProvider(parent) { } ConsoleKitProvider::~ConsoleKitProvider() { } bool ConsoleKitProvider::canAction(Power::Action action) const { QString command; switch (action) { case Power::PowerReboot: command = QStringLiteral("CanReboot"); break; case Power::PowerShutdown: command = QStringLiteral("CanPowerOff"); break; case Power::PowerHibernate: command = QStringLiteral("CanHibernate"); break; case Power::PowerSuspend: command = QStringLiteral("CanSuspend"); break; default: return false; } return dbusCallSystemd(QStringLiteral(CONSOLEKIT_SERVICE), QStringLiteral(CONSOLEKIT_PATH), QStringLiteral(CONSOLEKIT_INTERFACE), QDBusConnection::systemBus(), command, false, // canAction should be always silent because it can freeze // g_main_context_iteration Qt event loop in QMessageBox // on panel startup if there is no DBUS running. PowerProvider::DontCheckDBUS ); } bool ConsoleKitProvider::doAction(Power::Action action) { QString command; switch (action) { case Power::PowerReboot: command = QStringLiteral("Reboot"); break; case Power::PowerShutdown: command = QStringLiteral("PowerOff"); break; case Power::PowerHibernate: command = QStringLiteral("Hibernate"); break; case Power::PowerSuspend: command = QStringLiteral("Suspend"); break; default: return false; } return dbusCallSystemd(QStringLiteral(CONSOLEKIT_SERVICE), QStringLiteral(CONSOLEKIT_PATH), QStringLiteral(CONSOLEKIT_INTERFACE), QDBusConnection::systemBus(), command, true); } /************************************************ SystemdProvider http://www.freedesktop.org/wiki/Software/systemd/logind ************************************************/ SystemdProvider::SystemdProvider(QObject *parent): PowerProvider(parent) { } SystemdProvider::~SystemdProvider() { } bool SystemdProvider::canAction(Power::Action action) const { QString command; switch (action) { case Power::PowerReboot: command = QStringLiteral("CanReboot"); break; case Power::PowerShutdown: command = QStringLiteral("CanPowerOff"); break; case Power::PowerSuspend: command = QStringLiteral("CanSuspend"); break; case Power::PowerHibernate: command = QStringLiteral("CanHibernate"); break; default: return false; } return dbusCallSystemd(QStringLiteral(SYSTEMD_SERVICE), QStringLiteral(SYSTEMD_PATH), QStringLiteral(SYSTEMD_INTERFACE), QDBusConnection::systemBus(), command, false, // canAction should be always silent because it can freeze // g_main_context_iteration Qt event loop in QMessageBox // on panel startup if there is no DBUS running. PowerProvider::DontCheckDBUS ); } bool SystemdProvider::doAction(Power::Action action) { QString command; switch (action) { case Power::PowerReboot: command = QStringLiteral("Reboot"); break; case Power::PowerShutdown: command = QStringLiteral("PowerOff"); break; case Power::PowerSuspend: command = QStringLiteral("Suspend"); break; case Power::PowerHibernate: command = QStringLiteral("Hibernate"); break; default: return false; } return dbusCallSystemd(QStringLiteral(SYSTEMD_SERVICE), QStringLiteral(SYSTEMD_PATH), QStringLiteral(SYSTEMD_INTERFACE), QDBusConnection::systemBus(), command, true ); } /************************************************ HalProvider ************************************************/ HalProvider::HalProvider(QObject *parent): PowerProvider(parent) { } HalProvider::~HalProvider() { } bool HalProvider::canAction(Power::Action action) const { Q_UNUSED(action) return false; } bool HalProvider::doAction(Power::Action action) { Q_UNUSED(action) return false; } core-0.8/session/powermanager/powerproviders.h000066400000000000000000000052651417504024300217360ustar00rootroot00000000000000/* BEGIN_COMMON_COPYRIGHT_HEADER * Authors: * Alexander Sokoloff * * This program or library is free software; you can redistribute it * and/or modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * You should have received a copy of the GNU Lesser General * Public License along with this library; if not, write to the * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301 USA * * END_COMMON_COPYRIGHT_HEADER */ #ifndef POWERPROVIDERS_H #define POWERPROVIDERS_H #include "power.h" #include #include // for PID_T class PowerProvider: public QObject { Q_OBJECT public: enum DbusErrorCheck { CheckDBUS, DontCheckDBUS }; explicit PowerProvider(QObject *parent = nullptr); ~PowerProvider() override; /*! Returns true if the Power can perform action. This is a pure virtual function, and must be reimplemented in subclasses. */ virtual bool canAction(Power::Action action) const = 0 ; public Q_SLOTS: /*! Performs the requested action. This is a pure virtual function, and must be reimplemented in subclasses. */ virtual bool doAction(Power::Action action) = 0; }; class UPowerProvider: public PowerProvider { Q_OBJECT public: UPowerProvider(QObject *parent = nullptr); ~UPowerProvider() override; bool canAction(Power::Action action) const override; public Q_SLOTS: bool doAction(Power::Action action) override; }; class ConsoleKitProvider: public PowerProvider { Q_OBJECT public: ConsoleKitProvider(QObject *parent = nullptr); ~ConsoleKitProvider() override; bool canAction(Power::Action action) const override; public Q_SLOTS: bool doAction(Power::Action action) override; }; class SystemdProvider: public PowerProvider { Q_OBJECT public: SystemdProvider(QObject *parent = nullptr); ~SystemdProvider() override; bool canAction(Power::Action action) const override; public Q_SLOTS: bool doAction(Power::Action action) override; }; class HalProvider: public PowerProvider { Q_OBJECT public: HalProvider(QObject *parent = nullptr); ~HalProvider() override; bool canAction(Power::Action action) const override; public Q_SLOTS: bool doAction(Power::Action action) override; }; #endif core-0.8/session/process.cpp000066400000000000000000000016131417504024300161570ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: revenmartin * * 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 * 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 "process.h" Process::Process(QObject *parent) : QProcess(parent) { QProcess::setProcessChannelMode(QProcess::ForwardedChannels); } Process::~Process() { } core-0.8/session/process.h000066400000000000000000000016221417504024300156240ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: revenmartin * * 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 * 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 PROCESS_H #define PROCESS_H #include class Process : public QProcess { Q_OBJECT public: Process(QObject *parent = nullptr); ~Process(); }; #endif core-0.8/session/processmanager.cpp000066400000000000000000000173501417504024300175170ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: revenmartin * * 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 * 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 "processmanager.h" #include "application.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include ProcessManager::ProcessManager(Application *app, QObject *parent) : QObject(parent) , m_app(app) , m_wmStarted(false) , m_waitLoop(nullptr) { qApp->installNativeEventFilter(this); } ProcessManager::~ProcessManager() { qApp->removeNativeEventFilter(this); QMapIterator i(m_systemProcess); while (i.hasNext()) { i.next(); QProcess *p = i.value(); delete p; m_systemProcess[i.key()] = nullptr; } } void ProcessManager::start() { startWindowManager(); startDaemonProcess(); } void ProcessManager::logout() { QDBusInterface kwinIface("org.kde.KWin", "/Session", "org.kde.KWin.Session", QDBusConnection::sessionBus()); if (kwinIface.isValid()) { kwinIface.call("aboutToSaveSession", "cutefish"); kwinIface.call("setState", uint(2)); // Quit } QProcess s; s.start("killall", QStringList() << "kglobalaccel5"); s.waitForFinished(-1); QDBusInterface iface("org.freedesktop.login1", "/org/freedesktop/login1/session/self", "org.freedesktop.login1.Session", QDBusConnection::systemBus()); if (iface.isValid()) iface.call("Terminate"); QCoreApplication::exit(0); } void ProcessManager::startWindowManager() { QProcess *wmProcess = new QProcess; wmProcess->start(m_app->wayland() ? "kwin_wayland" : "kwin_x11", QStringList()); if (!m_app->wayland()) { QEventLoop waitLoop; m_waitLoop = &waitLoop; // add a timeout to avoid infinite blocking if a WM fail to execute. QTimer::singleShot(30 * 1000, &waitLoop, SLOT(quit())); waitLoop.exec(); m_waitLoop = nullptr; } } void ProcessManager::startDesktopProcess() { // When the cutefish-settings-daemon theme module is loaded, start the desktop. // In the way, there will be no problem that desktop and launcher can't get wallpaper. QList> list; // Desktop components list << qMakePair(QString("cutefish-notificationd"), QStringList()); list << qMakePair(QString("cutefish-statusbar"), QStringList()); list << qMakePair(QString("cutefish-dock"), QStringList()); list << qMakePair(QString("cutefish-filemanager"), QStringList("--desktop")); list << qMakePair(QString("cutefish-launcher"), QStringList()); list << qMakePair(QString("cutefish-powerman"), QStringList()); list << qMakePair(QString("cutefish-clipboard"), QStringList()); // For CutefishOS. if (QFile("/usr/bin/cutefish-welcome").exists() && !QFile("/run/live/medium/live/filesystem.squashfs").exists()) { QSettings settings("cutefishos", "login"); if (!settings.value("Finished", false).toBool()) { list << qMakePair(QString("/usr/bin/cutefish-welcome"), QStringList()); } else { list << qMakePair(QString("/usr/bin/cutefish-welcome"), QStringList() << "-d"); } } for (QPair pair : list) { QProcess *process = new QProcess; process->setProcessChannelMode(QProcess::ForwardedChannels); process->setProgram(pair.first); process->setArguments(pair.second); process->start(); process->waitForStarted(); qDebug() << "Load DE components: " << pair.first << pair.second; // Add to map if (process->exitCode() == 0) { m_autoStartProcess.insert(pair.first, process); } else { process->deleteLater(); } } // Auto start QTimer::singleShot(100, this, &ProcessManager::loadAutoStartProcess); } void ProcessManager::startDaemonProcess() { QList> list; list << qMakePair(QString("cutefish-settings-daemon"), QStringList()); list << qMakePair(QString("cutefish-xembedsniproxy"), QStringList()); list << qMakePair(QString("cutefish-gmenuproxy"), QStringList()); list << qMakePair(QString("chotkeys"), QStringList()); for (QPair pair : list) { QProcess *process = new QProcess; process->setProcessChannelMode(QProcess::ForwardedChannels); process->setProgram(pair.first); process->setArguments(pair.second); process->start(); process->waitForStarted(); // Add to map if (process->exitCode() == 0) { m_autoStartProcess.insert(pair.first, process); } else { process->deleteLater(); } } } void ProcessManager::loadAutoStartProcess() { QStringList execList; const QStringList dirs = QStandardPaths::locateAll(QStandardPaths::GenericConfigLocation, QStringLiteral("autostart"), QStandardPaths::LocateDirectory); for (const QString &dir : dirs) { const QDir d(dir); const QStringList fileNames = d.entryList(QStringList() << QStringLiteral("*.desktop")); for (const QString &file : fileNames) { QSettings desktop(d.absoluteFilePath(file), QSettings::IniFormat); desktop.setIniCodec("UTF-8"); desktop.beginGroup("Desktop Entry"); if (desktop.contains("OnlyShowIn")) continue; const QString execValue = desktop.value("Exec").toString(); // 避免冲突 if (execValue.contains("gmenudbusmenuproxy")) continue; if (!execValue.isEmpty()) { execList << execValue; } } } for (const QString &exec : execList) { QProcess *process = new QProcess; process->setProgram(exec); process->start(); process->waitForStarted(); if (process->exitCode() == 0) { m_autoStartProcess.insert(exec, process); } else { process->deleteLater(); } } } bool ProcessManager::nativeEventFilter(const QByteArray &eventType, void *message, long *result) { if (eventType != "xcb_generic_event_t") // We only want to handle XCB events return false; // ref: lxqt session if (!m_wmStarted && m_waitLoop) { // all window managers must set their name according to the spec if (!QString::fromUtf8(NETRootInfo(QX11Info::connection(), NET::SupportingWMCheck).wmName()).isEmpty()) { qDebug() << "Window manager started"; m_wmStarted = true; if (m_waitLoop && m_waitLoop->isRunning()) m_waitLoop->exit(); qApp->removeNativeEventFilter(this); } } return false; } core-0.8/session/processmanager.h000066400000000000000000000030671417504024300171640ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: revenmartin * * 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 * 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 PROCESSMANAGER_H #define PROCESSMANAGER_H #include #include #include #include #include class Application; class ProcessManager : public QObject, public QAbstractNativeEventFilter { Q_OBJECT public: explicit ProcessManager(Application *app, QObject *parent = nullptr); ~ProcessManager(); void start(); void logout(); void startWindowManager(); void startDesktopProcess(); void startDaemonProcess(); void loadAutoStartProcess(); bool nativeEventFilter(const QByteArray & eventType, void * message, long * result) override; private: Application *m_app; QMap m_systemProcess; QMap m_autoStartProcess; bool m_wmStarted; QEventLoop *m_waitLoop; }; #endif // PROCESSMANAGER_H core-0.8/settings-daemon/000077500000000000000000000000001417504024300154125ustar00rootroot00000000000000core-0.8/settings-daemon/CMakeLists.txt000066400000000000000000000050561417504024300201600ustar00rootroot00000000000000project(cutefish-settings-daemon) set(TARGET cutefish-settings-daemon) find_package(X11 REQUIRED) find_package(X11_XCB REQUIRED) find_package(XCB REQUIRED) pkg_check_modules(XORGLIBINPUT xorg-libinput IMPORTED_TARGET) pkg_check_modules(XORGSERVER xorg-server IMPORTED_TARGET) pkg_check_modules(SYNAPTICS xorg-synaptics IMPORTED_TARGET GLOBAL) file (GLOB_RECURSE SRCS "*.cpp" "*.h" "theme/*.h" "theme/*.cpp" "brightness/*.h" "brightness/*.cpp" "brightness/*.c" "battery/*.cpp" "battery/*.h" "language/*.cpp" "language/*.h" "dock/*.cpp" "dock/*.h" "mouse/*.h" "mouse/*.cpp" "touchpad/*.h" "touchpad/*.cpp" "touchpad/x11/*.h" "touchpad/x11/*.cpp" ) set(SOURCES ${SRCS}) set(HEADERS "") set(FORMS "") set(RESOURCES "") qt5_add_dbus_adaptor(DBUS_SOURCES brightness/com.cutefish.Brightness.xml brightness/brightnessmanager.h BrightnessManager) qt5_add_dbus_adaptor(DBUS_SOURCES theme/com.cutefish.Theme.xml theme/thememanager.h ThemeManager) qt5_add_dbus_adaptor(DBUS_SOURCES battery/com.cutefish.PrimaryBattery.xml battery/battery.h Battery) qt5_add_dbus_adaptor(DBUS_SOURCES language/com.cutefish.Language.xml language/language.h Language) qt5_add_dbus_adaptor(DBUS_SOURCES dock/com.cutefish.Dock.xml dock/dock.h Dock) qt5_add_dbus_adaptor(DBUS_SOURCES mouse/com.cutefish.Mouse.xml mouse/mousemanager.h Mouse) qt5_add_dbus_adaptor(DBUS_SOURCES touchpad/com.cutefish.Touchpad.xml touchpad/touchpadmanager.h TouchpadManager) set_source_files_properties(${DBUS_SOURCES} PROPERTIES SKIP_AUTOGEN ON) add_executable(${TARGET} ${SOURCES} ${DBUS_SOURCES} ${HEADERS} ${FORMS} ${RESOURCES}) target_link_libraries(${TARGET} Qt5::Core Qt5::Gui Qt5::Widgets Qt5::DBus Qt5::X11Extras Qt5::Xml ${X11_LIBRARIES} X11::X11 X11::Xi X11::XCB ${XCB_LIBRARIES} PkgConfig::XORGLIBINPUT PkgConfig::XORGSERVER PkgConfig::SYNAPTICS ) file(GLOB TS_FILES translations/*.ts) qt5_create_translation(QM_FILES ${TS_FILES}) add_custom_target(translations DEPENDS ${QM_FILES} SOURCES ${TS_FILES}) add_dependencies(${TARGET} translations) install(TARGETS ${TARGET} DESTINATION ${CMAKE_INSTALL_BINDIR}) install(FILES ${QM_FILES} DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${TARGET}/translations) core-0.8/settings-daemon/application.cpp000066400000000000000000000104671417504024300204310ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: revenmartin * * 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 * 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 "application.h" #include "dbusadaptor.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include Application::Application(int &argc, char **argv) : QApplication(argc, argv) , m_themeManager(ThemeManager::self()) , m_brightnessManager(new BrightnessManager(this)) , m_upowerManager(new UPowerManager(this)) , m_language(Language::self()) , m_mouse(new Mouse) , m_touchpad(new TouchpadManager) // , m_kwinTimer(new QTimer(this)) { initTrash(); new DBusAdaptor(this); // connect to D-Bus and register as an object: QDBusConnection::sessionBus().registerService(QStringLiteral("com.cutefish.Settings")); // m_kwinTimer->setSingleShot(false); // m_kwinTimer->setInterval(50); // connect(m_kwinTimer, &QTimer::timeout, this, &Application::initKWin); // m_kwinTimer->start(); // Translations QLocale locale; QString qmFilePath = QString("%1/%2.qm").arg("/usr/share/cutefish-settings-daemon/translations/").arg(locale.name()); if (QFile::exists(qmFilePath)) { QTranslator *translator = new QTranslator(QApplication::instance()); if (translator->load(qmFilePath)) { QApplication::installTranslator(translator); } else { translator->deleteLater(); } } QTimer::singleShot(10, this, &Application::invokeDesktopProcess); } void Application::invokeDesktopProcess() { // Start desktop UI component. QDBusInterface sessionInterface("com.cutefish.Session", "/Session", "com.cutefish.Session", QDBusConnection::sessionBus()); if (sessionInterface.isValid()) { sessionInterface.call("startDesktopProcess"); } } void Application::initTrash() { const QByteArray trashDir = QString(QDir::homePath() + "/.local/share/Trash").toLatin1(); if (::mkdir(trashDir, 0700) != 0) return; struct stat buff; uid_t uid = getuid(); if (::lstat(trashDir, &buff) != 0) return; if ((buff.st_uid == uid) && // must be owned by user ((buff.st_mode & 0777) == 0700)) { // check subdirs QString infoDir = trashDir + QString::fromLatin1("/info"); QString filesDir = trashDir + QString::fromLatin1("/files"); if (!QDir(infoDir).exists()) QDir().mkdir(infoDir); if (!QDir(filesDir).exists()) QDir().mkdir(filesDir); } else { ::rmdir(trashDir); } } //void Application::initKWin() //{ // QDBusInterface effect("org.kde.KWin", "/Effects", "org.kde.kwin.Effects", // QDBusConnection::sessionBus()); // if (effect.isValid() && !effect.lastError().isValid()) { // // KWin // effect.call("loadEffect", "kwin4_effect_dialogparent"); // effect.call("unloadEffect", "kwin4_effect_fadingpopups"); // effect.call("unloadEffect", "kwin4_effect_fade"); // effect.call("unloadEffect", "kwin4_effect_scale"); // effect.call("unloadEffect", "kwin4_effect_grayscale"); // effect.call("unloadEffect", "kwin4_effect_squash"); // effect.call("unloadEffect", "kwin4_effect_translucency"); // effect.call("unloadEffect", "magiclamp"); // effect.call("loadEffect", "cutefish_popups"); // effect.call("loadEffect", "cutefish_scale"); // effect.call("loadEffect", "cutefish_squash"); // m_kwinTimer->stop(); // } //} core-0.8/settings-daemon/application.h000066400000000000000000000027151417504024300200730ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: revenmartin * * 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 * 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 APPLICATION_H #define APPLICATION_H #include #include "theme/thememanager.h" #include "brightness/brightnessmanager.h" #include "battery/upowermanager.h" #include "language/language.h" #include "mouse/mousemanager.h" #include "touchpad/touchpadmanager.h" #include class Application : public QApplication { Q_OBJECT public: explicit Application(int &argc, char **argv); void invokeDesktopProcess(); void initTrash(); // void initKWin(); private: ThemeManager *m_themeManager; BrightnessManager *m_brightnessManager; UPowerManager *m_upowerManager; Language *m_language; Mouse *m_mouse; TouchpadManager *m_touchpad; // QTimer *m_kwinTimer; }; #endif // APPLICATION_H core-0.8/settings-daemon/battery/000077500000000000000000000000001417504024300170645ustar00rootroot00000000000000core-0.8/settings-daemon/battery/battery.cpp000066400000000000000000000245521417504024300212520ustar00rootroot00000000000000#include "battery.h" #include "power.h" #include "primarybatteryadaptor.h" #include #include enum TimeConstants { SecsInDay = 86400, SecsInHour = 3600, SecsInMinute = 60 }; // ref: https://upower.freedesktop.org/docs/Device.html // kf5solid Battery::Battery(UPowerDevice *device, QObject *parent) : QObject(parent) , m_device(device) , m_settings(nullptr) , m_lastChargedPercent(0) , m_lastChargedSecs(0) { connect(device, SIGNAL(changed()), this, SLOT(slotChanged())); updateCache(); init(); } void Battery::updateCache() { m_chargeState = chargeState(); m_isPresent = isPresent(); m_chargePercent = chargePercent(); m_capacity = capacity(); m_isPowerSupply = isPowerSupply(); m_timeToEmpty = timeToEmpty(); m_timeToFull = timeToFull(); m_energy = energy(); m_energyFull = energyFull(); m_energyFullDesign = energyFullDesign(); m_energyRate = energyRate(); m_voltage = voltage(); m_temperature = temperature(); } void Battery::init() { if (type() == Battery::PrimaryBattery) { new PrimaryBatteryAdaptor(this); QDBusConnection::sessionBus().registerObject(QStringLiteral("/PrimaryBattery"), this); m_settings = new QSettings(QStringLiteral("cutefishos"), QStringLiteral("PrimaryBattery")); m_lastChargedPercent = m_settings->value("LastChargedPercent", 0).toInt(); m_lastChargedSecs = m_settings->value("LastChargedSecs").toLongLong(); } } void Battery::refresh() { QDBusInterface iface(UP_DBUS_SERVICE, m_device->udi(), UP_DBUS_INTERFACE_DEVICE, QDBusConnection::systemBus()); if (iface.isValid()) iface.call("Refresh"); } bool Battery::isPresent() const { return m_device->prop("IsPresent").toBool(); } Battery::BatteryType Battery::type() const { Battery::BatteryType result = Battery::UnknownBattery; const uint t = m_device->prop("Type").toUInt(); switch (t) { case UP_DEVICE_KIND_LINE_POWER: // TODO break; case UP_DEVICE_KIND_BATTERY: result = Battery::PrimaryBattery; break; case UP_DEVICE_KIND_UPS: result = Battery::UpsBattery; break; case UP_DEVICE_KIND_MONITOR: result = Battery::MonitorBattery; break; case UP_DEVICE_KIND_MOUSE: result = Battery::MouseBattery; break; case UP_DEVICE_KIND_KEYBOARD: result = Battery::KeyboardBattery; break; case UP_DEVICE_KIND_PDA: result = Battery::PdaBattery; break; case UP_DEVICE_KIND_PHONE: result = Battery::PhoneBattery; break; case UP_DEVICE_KIND_GAMING_INPUT: result = Battery::GamingInputBattery; break; case UP_DEVICE_KIND_UNKNOWN: { // There is currently no "Bluetooth battery" type, so check if it comes from Bluez if (m_device->prop("NativePath").toString().startsWith(QLatin1String("/org/bluez/"))) { result = Battery::BluetoothBattery; } break; } } return result; } int Battery::chargePercent() const { return qRound(m_device->prop("Percentage").toDouble()); } int Battery::capacity() const { return m_device->prop("Capacity").toDouble(); } bool Battery::isRechargeable() const { return m_device->prop("IsRechargeable").toBool(); } bool Battery::isPowerSupply() const { return m_device->prop("PowerSupply").toBool(); } Battery::ChargeState Battery::chargeState() const { Battery::ChargeState result = Battery::NoCharge; const uint state = m_device->prop("State").toUInt(); switch (state) { case 0: result = Battery::NoCharge; // stable or unknown break; case 1: result = Battery::Charging; break; case 2: result = Battery::Discharging; break; case 3: // TODO "Empty" break; case 4: result = Battery::FullyCharged; break; case 5: // TODO "Pending charge" break; case 6: // TODO "Pending discharge" break; } return result; } qlonglong Battery::timeToEmpty() const { return m_device->prop("TimeToEmpty").toLongLong(); } qlonglong Battery::timeToFull() const { return m_device->prop("TimeToFull").toLongLong(); } Battery::Technology Battery::technology() const { const uint tech = m_device->prop("Technology").toUInt(); switch (tech) { case 1: return Battery::LithiumIon; case 2: return Battery::LithiumPolymer; case 3: return Battery::LithiumIronPhosphate; case 4: return Battery::LeadAcid; case 5: return Battery::NickelCadmium; case 6: return Battery::NickelMetalHydride; default: return Battery::UnknownTechnology; } } double Battery::energy() const { return m_device->prop("Energy").toDouble(); } double Battery::energyFull() const { return m_device->prop("EnergyFull").toDouble(); } double Battery::energyFullDesign() const { return m_device->prop("EnergyFullDesign").toDouble(); } double Battery::energyRate() const { return m_device->prop("EnergyRate").toDouble(); } double Battery::voltage() const { return m_device->prop("Voltage").toDouble(); } double Battery::temperature() const { return m_device->prop("Temperature").toDouble(); } bool Battery::isRecalled() const { return m_device->prop("RecallNotice").toBool(); } QString Battery::recallVendor() const { return m_device->prop("RecallVendor").toString(); } QString Battery::recallUrl() const { return m_device->prop("RecallUrl").toString(); } QString Battery::serial() const { return m_device->prop("Serial").toString(); } qlonglong Battery::remainingTime() const { if (chargeState() == Battery::Charging) { return timeToFull(); } else if (chargeState() == Battery::Discharging) { return timeToEmpty(); } return -1; } QString Battery::formatDuration(qlonglong seconds) const { QString result; quint64 secs = seconds; int days = secs / SecsInDay; secs = secs % SecsInDay; int hours = secs / SecsInHour; secs = secs % SecsInHour; int minutes = secs / SecsInMinute; if (days > 0) result.push_back(tr("%1d").arg(days)); if (hours > 0) { if (days > 0) result.push_back(" "); result.push_back(tr("%1h").arg(hours)); } if (minutes > 0) { if (hours > 0) result.push_back(" "); result.push_back(tr("%1m").arg(minutes)); } return result; } QString Battery::statusString() const { if (chargeState() == Battery::Charging) { return tr("%1 until fully charged").arg(formatDuration(remainingTime())); } else if (chargeState() == Battery::Discharging) { return tr("%1 remaining").arg(formatDuration(remainingTime())); } else if (chargeState() == Battery::FullyCharged) { return tr("Fully charged."); } return QString(); } int Battery::lastChargedPercent() const { return m_lastChargedPercent; } quint64 Battery::lastChargedSecs() const { return m_lastChargedSecs; } QString Battery::lastChargedTime() const { QDateTime now = QDateTime::currentDateTime(); QDateTime time = QDateTime::fromSecsSinceEpoch(m_lastChargedSecs); qint64 minutes = qRound64(time.secsTo(now) / 60.0f); if (minutes == 0) return tr("now"); return tr("%1 ago").arg(formatDuration(time.secsTo(now))); } void Battery::slotChanged() { if (m_device) { const bool old_isPresent = m_isPresent; const int old_chargePercent = m_chargePercent; const int old_capacity = m_capacity; const bool old_isPowerSupply = m_isPowerSupply; const Battery::ChargeState old_chargeState = m_chargeState; const qlonglong old_timeToEmpty = m_timeToEmpty; const qlonglong old_timeToFull = m_timeToFull; const double old_energy = m_energy; const double old_energyFull = m_energyFull; const double old_energyFullDesign = m_energyFullDesign; const double old_energyRate = m_energyRate; const double old_voltage = m_voltage; const double old_temperature = m_temperature; updateCache(); if (old_isPresent != m_isPresent) { emit presentStateChanged(m_isPresent); } if (old_chargePercent != m_chargePercent) { emit chargePercentChanged(m_chargePercent); } if (old_capacity != m_capacity) { emit capacityChanged(m_capacity); } if (old_isPowerSupply != m_isPowerSupply) { emit powerSupplyStateChanged(m_isPowerSupply); } if (old_chargeState != m_chargeState) { emit chargeStateChanged(m_chargeState); } // Save last charge percentage if ((old_chargeState == Battery::Charging || old_chargeState == Battery::FullyCharged) && m_chargeState == Battery::Discharging) { m_lastChargedPercent = m_chargePercent; m_lastChargedSecs = QDateTime::currentSecsSinceEpoch(); if (m_settings) { m_settings->setValue("LastChargedPercent", m_lastChargedPercent); m_settings->setValue("LastChargedSecs", m_lastChargedSecs); } emit lastChargedPercentChanged(); emit lastChargedSecsChanged(); } if (old_timeToEmpty != m_timeToEmpty) { emit timeToEmptyChanged(m_timeToEmpty); } if (old_timeToFull != m_timeToFull) { emit timeToFullChanged(m_timeToFull); } if (old_energy != m_energy) { emit energyChanged(m_energy); } if (old_energyFull != m_energyFull) { emit energyFullChanged(m_energyFull); } if (old_energyFullDesign != m_energyFullDesign) { emit energyFullChanged(m_energyFullDesign); } if (old_energyRate != m_energyRate) { emit energyRateChanged(m_energyRate); } if (old_voltage != m_voltage) { emit voltageChanged(m_voltage); } if (old_temperature != m_temperature) { emit temperatureChanged(m_temperature); } if (old_timeToFull != m_timeToFull || old_timeToEmpty != m_timeToEmpty) { emit remainingTimeChanged(remainingTime()); } } } core-0.8/settings-daemon/battery/battery.h000066400000000000000000000140111417504024300207040ustar00rootroot00000000000000#ifndef BATTERY_H #define BATTERY_H #include #include #include #include "upowerdevice.h" class Battery : public QObject { Q_OBJECT Q_PROPERTY(int isPresent READ isPresent) Q_PROPERTY(int type READ type) Q_PROPERTY(int chargePercent READ chargePercent NOTIFY chargePercentChanged) Q_PROPERTY(int capacity READ capacity NOTIFY capacityChanged) Q_PROPERTY(int voltage READ voltage NOTIFY voltageChanged) Q_PROPERTY(int isRechargeable READ isRechargeable) Q_PROPERTY(int isPowerSupply READ isPowerSupply) Q_PROPERTY(int chargeState READ chargeState NOTIFY chargeStateChanged) Q_PROPERTY(qlonglong remainingTime READ remainingTime NOTIFY remainingTimeChanged) Q_PROPERTY(QString statusString READ statusString NOTIFY remainingTimeChanged) Q_PROPERTY(int lastChargedPercent READ lastChargedPercent NOTIFY lastChargedPercentChanged) Q_PROPERTY(quint64 lastChargedSecs READ lastChargedSecs NOTIFY lastChargedSecsChanged) Q_PROPERTY(QString lastChargedTime READ lastChargedTime NOTIFY lastChargedSecsChanged) Q_PROPERTY(QString udi READ udi) public: /** * This enum type defines the type of the device holding the battery * * - PdaBattery : A battery in a Personal Digital Assistant * - UpsBattery : A battery in an Uninterruptible Power Supply * - PrimaryBattery : A primary battery for the system (for example laptop battery) * - MouseBattery : A battery in a mouse * - KeyboardBattery : A battery in a keyboard * - KeyboardMouseBattery : A battery in a combined keyboard and mouse * - CameraBattery : A battery in a camera * - PhoneBattery : A battery in a phone * - MonitorBattery : A battery in a monitor * - GamingInputBattery : A battery in a gaming input device (for example a wireless game pad) * - BluetoothBattery: A generic Bluetooth device battery (if its type isn't known, a Bluetooth * mouse would normally show up as a MouseBattery), @since 5.54 * - UnknownBattery : A battery in an unknown device */ enum BatteryType { UnknownBattery, PdaBattery, UpsBattery, PrimaryBattery, MouseBattery, KeyboardBattery, KeyboardMouseBattery, CameraBattery, PhoneBattery, MonitorBattery, GamingInputBattery, BluetoothBattery }; Q_ENUM(BatteryType) /** * This enum type defines charge state of a battery * * - NoCharge : Battery charge is stable, not charging or discharging or * the state is Unknown * - Charging : Battery is charging * - Discharging : Battery is discharging * - FullyCharged: The battery is fully charged; a battery not necessarily * charges up to 100% */ enum ChargeState { NoCharge, Charging, Discharging, FullyCharged }; Q_ENUM(ChargeState) /** * Technology used in the battery * * 0: Unknown * 1: Lithium ion * 2: Lithium polymer * 3: Lithium iron phosphate * 4: Lead acid * 5: Nickel cadmium * 6: Nickel metal hydride */ enum Technology { UnknownTechnology = 0, LithiumIon, LithiumPolymer, LithiumIronPhosphate, LeadAcid, NickelCadmium, NickelMetalHydride }; Q_ENUM(Technology) // Begin explicit Battery(UPowerDevice *device, QObject *parent = nullptr); void updateCache(); void init(); void refresh(); bool isPresent() const; Battery::BatteryType type() const; int chargePercent() const; int capacity() const; bool isRechargeable() const; bool isPowerSupply() const; Battery::ChargeState chargeState() const; // Number of seconds until the power source is considered empty. Is set to 0 if unknown. // This property is only valid if the property type has the value "battery". qlonglong timeToEmpty() const; // Number of seconds until the power source is considered full. Is set to 0 if unknown. // This property is only valid if the property type has the value "battery". qlonglong timeToFull() const; Battery::Technology technology() const; double energy() const; double energyFull() const; double energyFullDesign() const; double energyRate() const; double voltage() const; double temperature() const; bool isRecalled() const; QString recallVendor() const; QString recallUrl() const; QString serial() const; qlonglong remainingTime() const; QString formatDuration(qlonglong seconds) const; QString statusString() const; int lastChargedPercent() const; quint64 lastChargedSecs() const; QString lastChargedTime() const; QString udi() const { return m_device->udi(); } signals: void presentStateChanged(bool newState); void chargePercentChanged(int value); void capacityChanged(int value); void powerSupplyStateChanged(bool newState); void chargeStateChanged(int newState); void timeToEmptyChanged(qlonglong time); void timeToFullChanged(qlonglong time); void energyChanged(double energy); void energyFullChanged(double energyFull); void energyFullDesignChanged(double energyFullDesign); void energyRateChanged(double energyRate); void voltageChanged(double voltage); void temperatureChanged(double temperature); void remainingTimeChanged(qlonglong time); void lastChargedPercentChanged(); void lastChargedSecsChanged(); private slots: void slotChanged(); private: UPowerDevice *m_device; bool m_isPresent; int m_chargePercent; int m_capacity; bool m_isPowerSupply; Battery::ChargeState m_chargeState; qlonglong m_timeToEmpty; qlonglong m_timeToFull; double m_energy; double m_energyFull; double m_energyFullDesign; double m_energyRate; double m_voltage; double m_temperature; QSettings *m_settings; int m_lastChargedPercent; quint64 m_lastChargedSecs; // QTimer m_refreshTimer; }; #endif // BATTERY_H core-0.8/settings-daemon/battery/com.cutefish.PrimaryBattery.xml000066400000000000000000000025671417504024300251640ustar00rootroot00000000000000 core-0.8/settings-daemon/battery/power.h000066400000000000000000000014231417504024300203710ustar00rootroot00000000000000#ifndef POWER_H #define POWER_H /* UPower */ #define UP_DBUS_SERVICE "org.freedesktop.UPower" #define UP_DBUS_PATH "/org/freedesktop/UPower" #define UP_DBUS_INTERFACE "org.freedesktop.UPower" #define UP_DBUS_INTERFACE_DEVICE UP_DBUS_INTERFACE ".Device" #define UP_UDI_PREFIX "/org/freedesktop/UPower" typedef enum { UP_DEVICE_KIND_UNKNOWN, UP_DEVICE_KIND_LINE_POWER, UP_DEVICE_KIND_BATTERY, UP_DEVICE_KIND_UPS, UP_DEVICE_KIND_MONITOR, UP_DEVICE_KIND_MOUSE, UP_DEVICE_KIND_KEYBOARD, UP_DEVICE_KIND_PDA, UP_DEVICE_KIND_PHONE, UP_DEVICE_KIND_MEDIA_PLAYER, UP_DEVICE_KIND_TABLET, UP_DEVICE_KIND_COMPUTER, UP_DEVICE_KIND_GAMING_INPUT, UP_DEVICE_KIND_LAST } UpDeviceKind; #endif // POWER_H core-0.8/settings-daemon/battery/upowerdevice.cpp000066400000000000000000000124551417504024300223000ustar00rootroot00000000000000#include "upowerdevice.h" #include "power.h" #include #include #include UPowerDevice::UPowerDevice(const QString &udi, QObject *parent) : QObject(parent) , m_device(UP_DBUS_SERVICE, udi, UP_DBUS_INTERFACE_DEVICE, QDBusConnection::systemBus()) , m_udi(udi) { if (m_device.isValid()) { if (m_device.metaObject()->indexOfSignal("Changed()") != -1) { connect(&m_device, SIGNAL(Changed()), this, SLOT(slotChanged())); } else { // for UPower >= 0.99.0, missing Changed() signal QDBusConnection::systemBus().connect(UP_DBUS_SERVICE, m_udi, "org.freedesktop.DBus.Properties", "PropertiesChanged", this, SLOT(onPropertiesChanged(QString, QVariantMap, QStringList))); } // TODO port this to Solid::Power, we can't link against kdelibs4support for this signal // older upower versions not affected QDBusConnection::systemBus().connect("org.freedesktop.login1", "/org/freedesktop/login1", "org.freedesktop.login1.Manager", "PrepareForSleep", this, SLOT(login1Resuming(bool))); } } bool UPowerDevice::queryDeviceInterface(UPowerDevice::Type type) const { const uint uptype = prop("Type").toUInt(); switch (type) { case GenericInterface: return true; case Battery: switch (uptype) { case UP_DEVICE_KIND_BATTERY: case UP_DEVICE_KIND_UPS: case UP_DEVICE_KIND_MOUSE: case UP_DEVICE_KIND_KEYBOARD: case UP_DEVICE_KIND_PDA: case UP_DEVICE_KIND_PHONE: case UP_DEVICE_KIND_GAMING_INPUT: return true; case UP_DEVICE_KIND_UNKNOWN: // There is currently no "Bluetooth battery" type, so check if it comes from Bluez if (prop("NativePath").toString().startsWith(QLatin1String("/org/bluez/"))) { return true; } return false; case UP_DEVICE_KIND_LINE_POWER: case UP_DEVICE_KIND_MONITOR: case UP_DEVICE_KIND_MEDIA_PLAYER: case UP_DEVICE_KIND_TABLET: case UP_DEVICE_KIND_COMPUTER: case UP_DEVICE_KIND_LAST: return false; } default: return false; } } QString UPowerDevice::description() const { if (queryDeviceInterface(Battery)) { return tr("%1 Battery", "%1 is battery technology").arg(batteryTechnology()); } else { QString result = prop("Model").toString(); if (result.isEmpty()) { return vendor(); } return result; } } QString UPowerDevice::batteryTechnology() const { const uint tech = prop("Technology").toUInt(); switch (tech) { case 1: return tr("Lithium-ion", "battery technology"); case 2: return tr("Lithium Polymer", "battery technology"); case 3: return tr("Lithium Iron Phosphate", "battery technology"); case 4: return tr("Lead Acid", "battery technology"); case 5: return tr("Nickel Cadmium", "battery technology"); case 6: return tr("Nickel Metal Hydride", "battery technology"); default: return tr("Unknown", "battery technology"); } } QString UPowerDevice::product() const { QString result = prop("Model").toString(); if (result.isEmpty()) { result = description(); } return result; } QString UPowerDevice::vendor() const { return prop("Vendor").toString(); } QString UPowerDevice::udi() const { return m_udi; } QVariant UPowerDevice::prop(const QString &key) const { checkCache(key); return m_cache.value(key); } bool UPowerDevice::propertyExists(const QString &key) const { checkCache(key); return m_cache.contains(key); } QMap UPowerDevice::allProperties() const { QDBusMessage call = QDBusMessage::createMethodCall(m_device.service(), m_device.path(), "org.freedesktop.DBus.Properties", "GetAll"); call << m_device.interface(); QDBusPendingReply< QVariantMap > reply = QDBusConnection::systemBus().asyncCall(call); reply.waitForFinished(); if (reply.isValid()) { m_cache = reply.value(); } else { m_cache.clear(); } return m_cache; } void UPowerDevice::onPropertiesChanged(const QString &ifaceName, const QVariantMap &changedProps, const QStringList &invalidatedProps) { Q_UNUSED(changedProps); Q_UNUSED(invalidatedProps); if (ifaceName == UP_DBUS_INTERFACE_DEVICE) { slotChanged(); // TODO maybe process the properties separately? } } void UPowerDevice::login1Resuming(bool active) { if (!active) { QDBusReply refreshCall = m_device.asyncCall("Refresh"); if (refreshCall.isValid()) { slotChanged(); } } } void UPowerDevice::slotChanged() { m_cache.clear(); emit changed(); } void UPowerDevice::checkCache(const QString &key) const { if (m_cache.isEmpty()) { // recreate the cache allProperties(); } if (m_cache.contains(key)) { return; } QVariant reply = m_device.property(key.toUtf8()); if (reply.isValid()) { m_cache[key] = reply; } else { m_cache[key] = QVariant(); } } core-0.8/settings-daemon/battery/upowerdevice.h000066400000000000000000000025071417504024300217420ustar00rootroot00000000000000#ifndef UPOWERDEVICE_H #define UPOWERDEVICE_H #include #include class UPowerDevice : public QObject { Q_OBJECT public: enum Type { Unknown = 0, GenericInterface = 1, Processor = 2, Block = 3, StorageAccess = 4, StorageDrive = 5, OpticalDrive = 6, StorageVolume = 7, OpticalDisc = 8, Camera = 9, PortableMediaPlayer = 10, Battery = 12, NetworkShare = 14, Last = 0xffff }; Q_ENUM(Type) explicit UPowerDevice(const QString &udi, QObject *parent = nullptr); bool queryDeviceInterface(Type type) const; QString description() const; QString batteryTechnology() const; QString product() const; QString vendor() const; QString udi() const; QVariant prop(const QString &key) const; bool propertyExists(const QString &key) const; QMap allProperties() const; signals: void changed(); private slots: void onPropertiesChanged(const QString &ifaceName, const QVariantMap &changedProps, const QStringList &invalidatedProps); void login1Resuming(bool active); void slotChanged(); private: void checkCache(const QString &key) const; private: mutable QDBusInterface m_device; mutable QVariantMap m_cache; QString m_udi; }; #endif // UPOWERDEVICE_H core-0.8/settings-daemon/battery/upowermanager.cpp000066400000000000000000000077301417504024300224530ustar00rootroot00000000000000/* SPDX-FileCopyrightText: 2020 Reven Martin SPDX-FileCopyrightText: 2010 Michael Zanetti SPDX-FileCopyrightText: 2010 Lukas Tinkl SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #include "upowermanager.h" #include "upowerdevice.h" #include "battery.h" #include "power.h" #include #include #include #include UPowerManager::UPowerManager(QObject *parent) : QObject(parent) , m_interface(UP_DBUS_SERVICE, UP_DBUS_PATH, UP_DBUS_INTERFACE, QDBusConnection::systemBus()) , m_onBattery(false) { qDBusRegisterMetaType>(); qDBusRegisterMetaType(); bool serviceFound = m_interface.isValid(); if (!serviceFound) { // find out whether it will be activated automatically QDBusMessage message = QDBusMessage::createMethodCall("org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "ListActivatableNames"); QDBusReply reply = QDBusConnection::systemBus().call(message); if (reply.isValid() && reply.value().contains(UP_DBUS_SERVICE)) { QDBusConnection::systemBus().interface()->startService(UP_DBUS_SERVICE); serviceFound = true; } } if (serviceFound) { if (m_interface.metaObject()->indexOfSignal("DeviceAdded(QDBusObjectPath)") != -1) { // for UPower >= 0.99.0, changed signature :o/ connect(&m_interface, SIGNAL(DeviceAdded(QDBusObjectPath)), this, SLOT(onDeviceAdded(QDBusObjectPath))); connect(&m_interface, SIGNAL(DeviceRemoved(QDBusObjectPath)), this, SLOT(onDeviceRemoved(QDBusObjectPath))); } else { connect(&m_interface, SIGNAL(DeviceAdded(QString)), this, SIGNAL(deviceAdded(QString))); connect(&m_interface, SIGNAL(DeviceRemoved(QString)), this, SIGNAL(deviceRemoved(QString))); } // On battery QDBusConnection::systemBus().connect(UP_DBUS_SERVICE, UP_DBUS_PATH, "org.freedesktop.DBus.Properties", "PropertiesChanged", this, SLOT(onPropertiesChanged(QString, QVariantMap, QStringList))); m_onBattery = m_interface.property("OnBattery").toBool(); // All devices QDBusReply> reply = m_interface.call("EnumerateDevices"); if (!reply.isValid()) { qWarning() << Q_FUNC_INFO << " error: " << reply.error().name(); return; } const auto pathList = reply.value(); for (const QDBusObjectPath &path : pathList) { UPowerDevice *device = new UPowerDevice(path.path()); Battery *battery = new Battery(device); if (battery->type() != Battery::PrimaryBattery) { device->deleteLater(); battery->deleteLater(); } } } } QString UPowerManager::udiPrefix() const { return UP_UDI_PREFIX; } bool UPowerManager::onBattery() const { return m_onBattery; } void UPowerManager::onPropertiesChanged(const QString &ifaceName, const QVariantMap &changedProps, const QStringList &invalidatedProps) { Q_UNUSED(ifaceName); Q_UNUSED(changedProps); Q_UNUSED(invalidatedProps); const bool onBattery = m_interface.property("OnBattery").toBool(); m_onBattery = onBattery; emit onBatteryChanged(); } void UPowerManager::onDeviceAdded(const QDBusObjectPath &path) { qDebug() << "onDeviceAdded()" << path.path(); } void UPowerManager::onDeviceRemoved(const QDBusObjectPath &path) { qDebug() << "onDeviceRemoved()" << path.path(); } core-0.8/settings-daemon/battery/upowermanager.h000066400000000000000000000017411417504024300221140ustar00rootroot00000000000000/* SPDX-FileCopyrightText: 2020 Reven Martin SPDX-FileCopyrightText: 2010 Michael Zanetti SPDX-FileCopyrightText: 2010 Lukas Tinkl SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ #ifndef UPOWERMANAGER_H #define UPOWERMANAGER_H #include #include class UPowerDevice; class Battery; class UPowerManager : public QObject { Q_OBJECT public: explicit UPowerManager(QObject *parent = nullptr); QString udiPrefix() const; bool onBattery() const; signals: void onBatteryChanged(); private slots: void onPropertiesChanged(const QString &ifaceName, const QVariantMap &changedProps, const QStringList &invalidatedProps); void onDeviceAdded(const QDBusObjectPath &path); void onDeviceRemoved(const QDBusObjectPath &path); private: QDBusInterface m_interface; bool m_onBattery; }; #endif // UPOWERMANAGER_H core-0.8/settings-daemon/brightness/000077500000000000000000000000001417504024300175625ustar00rootroot00000000000000core-0.8/settings-daemon/brightness/brightnessmanager.cpp000066400000000000000000000144101417504024300237710ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: rekols * * 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 * 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 "brightnessmanager.h" #include "brightnessadaptor.h" #include #include #include #include #include #define PREFIX "/sys/class/backlight/" BrightnessManager::BrightnessManager(QObject *parent) : QObject(parent), m_fileWatcher(new QFileSystemWatcher(this)) { // init dbus new BrightnessAdaptor(this); QDBusConnection::sessionBus().registerObject(QStringLiteral("/Brightness"), this); init(); } BrightnessManager::~BrightnessManager() { } int BrightnessManager::maxBrightness() { int max_brightness; QFile file(m_dirname + "/max_brightness"); if (!file.open(QIODevice::ReadOnly)) { qWarning() << "reading max brightness failed with error code " << file.error() << file.errorString(); return -1; // some non-zero value } QTextStream stream(&file); stream >> max_brightness; file.close(); return max_brightness ? max_brightness : -1; } int BrightnessManager::brightness() { QFile file(m_dirname + "/brightness"); if (!file.open(QIODevice::ReadOnly)) { return -1; } int brightness; QTextStream stream(&file); stream >> brightness; file.close(); return brightness * 100 / maxBrightness(); } void BrightnessManager::setValue(int value) { QProcess process; process.start("pkexec", QStringList() << "cutefish-screen-brightness" << "--set" << QString::number(value)); process.waitForFinished(-1); } void BrightnessManager::init() { if (useWhitelistInit()) initUsingWhitelist(); else initUsingBacklightType(); if (!m_dirname.isEmpty()) { m_fileWatcher->addPath(m_dirname + "/actual_brightness"); m_fileWatcher->addPath(m_dirname + "/brightness"); m_fileWatcher->addPath(m_dirname + "/bl_power"); m_actualBacklight = brightness(); connect(m_fileWatcher, &QFileSystemWatcher::fileChanged, this, &BrightnessManager::handleFileChanged); } } bool BrightnessManager::useWhitelistInit() { struct utsname uts; uname(&uts); int major, minor, patch, result; result = sscanf(uts.release, "%d.%d", &major, &minor); if (result != 2) { return true; // Malformed version } if (major == 3) { return false; //Kernel 3, we want type based init } result = sscanf(uts.release, "%d.%d.%d", &major, &minor, &patch); if (result != 3) { return true; // Malformed version } if (patch < 37) { return true; //Minor than 2.6.37, use whiteList based } return false;//Use Type based interface } void BrightnessManager::initUsingWhitelist() { QStringList interfaces; interfaces << "nv_backlight" << "radeon_bl" << "mbp_backlight" << "asus_laptop" << "toshiba" << "eeepc" << "thinkpad_screen" << "acpi_video1" << "acpi_video0" << "intel_backlight" << "apple_backlight" << "fujitsu-laptop" << "samsung" << "nvidia_backlight" << "dell_backlight" << "sony" << "pwm-backlight"; QDir dir; foreach (const QString & interface, interfaces) { dir.setPath(PREFIX + interface); //qDebug() << "searching dir:" << dir; if (dir.exists()) { m_dirname = dir.path(); //qDebug() << "kernel backlight support found in" << m_dirname; break; } } //If none of our whitelisted interface is available, get the first one (if any) if (m_dirname.isEmpty()) { dir.setPath(PREFIX); dir.setFilter(QDir::AllDirs | QDir::NoDot | QDir::NoDotDot | QDir::NoDotAndDotDot | QDir::Readable); QStringList dirList = dir.entryList(); if (!dirList.isEmpty()) { m_dirname = PREFIX + dirList.first(); } } } void BrightnessManager::initUsingBacklightType() { QString m_dirname; QDir dir(PREFIX); dir.setFilter(QDir::AllDirs | QDir::NoDot | QDir::NoDotDot | QDir::NoDotAndDotDot | QDir::Readable); dir.setSorting(QDir::Name | QDir::Reversed);// Reverse is needed to priorize acpi_video1 over 0 QStringList interfaces = dir.entryList(); if (interfaces.isEmpty()) { return; } QFile file; QByteArray buffer; QStringList firmware, platform, raw; foreach(const QString & interface, interfaces) { file.setFileName(PREFIX + interface + "/type"); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { continue; } buffer = file.readLine().trimmed(); if (buffer == "firmware") { firmware.append(interface); } else if(buffer == "platform") { platform.append(interface); } else if (buffer == "raw") { raw.append(interface); } else { qWarning() << "Interface type not handled" << buffer; } file.close(); } if (!firmware.isEmpty()) { m_dirname = PREFIX + firmware.first(); return; } if (!platform.isEmpty()) { m_dirname = PREFIX + platform.first(); return; } if (!raw.isEmpty()) { m_dirname = PREFIX + raw.first(); return; } } void BrightnessManager::handleFileChanged(const QString &path) { Q_UNUSED(path); int newValue = brightness(); if (m_actualBacklight != newValue) { m_actualBacklight = newValue; Q_EMIT brightnessChanged(); } } bool BrightnessManager::brightnessEnabled() { QDir dir; dir.setPath(PREFIX); dir.setFilter(QDir::AllDirs | QDir::NoDot | QDir::NoDotDot | QDir::NoDotAndDotDot | QDir::Readable); QStringList dirList = dir.entryList(); return !dirList.isEmpty(); } core-0.8/settings-daemon/brightness/brightnessmanager.h000066400000000000000000000030761417504024300234440ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: rekols * * 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 * 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 BRIGHTNESSMANAGER_H #define BRIGHTNESSMANAGER_H #include #include class BrightnessManager : public QObject { Q_OBJECT Q_PROPERTY(bool brightnessEnabled READ brightnessEnabled) Q_PROPERTY(int maxBrightness READ maxBrightness) Q_PROPERTY(int brightness READ brightness WRITE setValue) public: BrightnessManager(QObject *parent = nullptr); ~BrightnessManager(); int maxBrightness(); int brightness(); bool brightnessEnabled(); void setValue(int value); Q_SIGNALS: void brightnessChanged(); private: void init(); bool useWhitelistInit(); void initUsingWhitelist(); void initUsingBacklightType(); private slots: void handleFileChanged(const QString &path); private: QFileSystemWatcher *m_fileWatcher; int m_actualBacklight; QString m_dirname; }; #endif core-0.8/settings-daemon/brightness/com.cutefish.Brightness.xml000066400000000000000000000010371417504024300250030ustar00rootroot00000000000000 core-0.8/settings-daemon/dbusadaptor.h000066400000000000000000000021121417504024300200670ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: revenmartin * * 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 * 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 DBUSADAPTOR_H #define DBUSADAPTOR_H #include #include "application.h" class DBusAdaptor : public QDBusAbstractAdaptor { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.panda.settings") public: DBusAdaptor(Application *app) : QDBusAbstractAdaptor(app), m_app(app) { }; private: Application *m_app; }; #endif core-0.8/settings-daemon/dock/000077500000000000000000000000001417504024300163325ustar00rootroot00000000000000core-0.8/settings-daemon/dock/com.cutefish.Dock.xml000066400000000000000000000011431417504024300223210ustar00rootroot00000000000000 core-0.8/settings-daemon/dock/dock.cpp000066400000000000000000000061001417504024300177530ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: rekols * * 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 * 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 "dock.h" #include "dockadaptor.h" #include #include #include #include #include Dock::Dock(QObject *parent) : QObject(parent) , m_iconSize(0) , m_edgeMargins(10) , m_roundedWindowEnabled(true) , m_direction(Left) , m_visibility(AlwaysVisible) , m_settings(new QSettings(QSettings::UserScope, "cutefishos", "dock")) { new DockAdaptor(this); QDBusConnection::sessionBus().registerObject(QStringLiteral("/Dock"), this); if (!m_settings->contains("IconSize")) m_settings->setValue("IconSize", 64); if (!m_settings->contains("Direction")) m_settings->setValue("Direction", Bottom); if (!m_settings->contains("Visibility")) m_settings->setValue("Visibility", AlwaysVisible); if (!m_settings->contains("RoundedWindow")) m_settings->setValue("RoundedWindow", true); m_settings->sync(); m_iconSize = m_settings->value("IconSize").toInt(); m_direction = static_cast(m_settings->value("Direction").toInt()); m_roundedWindowEnabled = m_settings->value("RoundedWindow").toBool(); } int Dock::iconSize() const { return m_iconSize; } void Dock::setIconSize(int iconSize) { if (m_iconSize != iconSize) { m_iconSize = iconSize; m_settings->setValue("IconSize", iconSize); emit iconSizeChanged(); } } Dock::Direction Dock::direction() const { return m_direction; } void Dock::setDirection(int value) { if (m_direction != value) { m_direction = static_cast(value); m_settings->setValue("Direction", value); emit directionChanged(); } } Dock::Visibility Dock::visibility() const { return m_visibility; } void Dock::setVisibility(int value) { if (m_visibility != value) { m_visibility = static_cast(value); m_settings->setValue("Visibility", value); emit visibilityChanged(); } } int Dock::edgeMargins() const { return m_edgeMargins; } void Dock::setEdgeMargins(int edgeMargins) { m_edgeMargins = edgeMargins; } bool Dock::roundedWindowEnabled() const { return m_roundedWindowEnabled; } void Dock::setRoundedWindowEnabled(bool enabled) { if (m_roundedWindowEnabled != enabled) { m_roundedWindowEnabled = enabled; emit roundedWindowEnabledChanged(); } } core-0.8/settings-daemon/dock/dock.h000066400000000000000000000042121417504024300174220ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: rekols * * 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 * 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 DOCK_H #define DOCK_H #include #include class Dock : public QObject { Q_OBJECT Q_PROPERTY(Direction direction READ direction WRITE setDirection NOTIFY directionChanged) Q_PROPERTY(int iconSize READ iconSize WRITE setIconSize NOTIFY iconSizeChanged) Q_PROPERTY(int edgeMargins READ edgeMargins WRITE setEdgeMargins) Q_PROPERTY(bool roundedWindowEnabled READ roundedWindowEnabled WRITE setRoundedWindowEnabled NOTIFY roundedWindowEnabledChanged) public: enum Direction { Left = 0, Bottom, Right }; Q_ENUMS(Direction) enum Visibility { AlwaysVisible = 0, AutoHide, AlwaysHide }; Q_ENUMS(Visibility) explicit Dock(QObject *parent = nullptr); int iconSize() const; void setIconSize(int iconSize); Direction direction() const; void setDirection(int value); Visibility visibility() const; void setVisibility(int value); int edgeMargins() const; void setEdgeMargins(int edgeMargins); bool roundedWindowEnabled() const; void setRoundedWindowEnabled(bool enabled); signals: void iconSizeChanged(); void directionChanged(); void visibilityChanged(); void roundedWindowEnabledChanged(); private: int m_iconSize; int m_edgeMargins; bool m_roundedWindowEnabled; Direction m_direction; Visibility m_visibility; QSettings *m_settings; }; #endif // DOCK_H core-0.8/settings-daemon/language/000077500000000000000000000000001417504024300171755ustar00rootroot00000000000000core-0.8/settings-daemon/language/com.cutefish.Language.xml000066400000000000000000000006441417504024300240340ustar00rootroot00000000000000 core-0.8/settings-daemon/language/language.cpp000066400000000000000000000054241417504024300214710ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: revenmartin * * 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 * 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 "language.h" #include "languageadaptor.h" #include "theme/thememanager.h" #include #include Language *Language::self() { static Language s; return &s; } Language::Language(QObject *parent) : QObject(parent) , m_settings(new QSettings(QStringLiteral("cutefishos"), QStringLiteral("language"))) { new LanguageAdaptor(this); QDBusConnection::sessionBus().registerObject(QStringLiteral("/Language"), this); if (!m_settings->contains("language")) m_settings->setValue("language", "en_US"); emit languageChanged(); } QString Language::languageCode() const { return m_settings->value("language").toString(); } void Language::setLanguage(const QString &code) { if (m_settings->value("language").toString() == code) { return; } QSettings settings(QStringLiteral("cutefishos"), QStringLiteral("theme")); // Change fonts if (code == "zh_CN") { settings.setValue("Font", "Noto Sans CJK SC"); } else if (code.contains("en_")) { settings.setValue("Font", "Noto Sans"); } else if (code == "zh_TW") { settings.setValue("Font", "Noto Sans CJK TC"); } else if (code == "zh_HK") { settings.setValue("Font", "Noto Serif CJK HK"); } else if (code == "ja_JP") { settings.setValue("Font", "Noto Serif CJK JP"); } m_settings->setValue("language", code); emit languageChanged(); QDBusInterface iface("org.freedesktop.Notifications", "/org/freedesktop/Notifications", "org.freedesktop.Notifications", QDBusConnection::sessionBus()); if (iface.isValid()) { QList args; args << "cutefish-settings"; args << ((unsigned int) 0); args << "preferences-system"; args << ""; args << tr("The system language has been changed, please log out and log in"); args << QStringList(); args << QVariantMap(); args << (int) 10; iface.asyncCallWithArgumentList("Notify", args); } } core-0.8/settings-daemon/language/language.h000066400000000000000000000022571417504024300211370ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: revenmartin * * 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 * 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 LANGUAGE_H #define LANGUAGE_H #include #include class Language : public QObject { Q_OBJECT Q_PROPERTY(QString languageCode READ languageCode WRITE setLanguage NOTIFY languageChanged) public: static Language *self(); Language(QObject *parent = nullptr); QString languageCode() const; void setLanguage(const QString &code); signals: void languageChanged(); private: QSettings *m_settings; }; #endif core-0.8/settings-daemon/main.cpp000066400000000000000000000015701417504024300170450ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: revenmartin * * 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 * 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 "application.h" int main(int argc, char *argv[]) { Application a(argc, argv); a.setQuitOnLastWindowClosed(false); return a.exec(); } core-0.8/settings-daemon/mouse/000077500000000000000000000000001417504024300165425ustar00rootroot00000000000000core-0.8/settings-daemon/mouse/com.cutefish.Mouse.xml000066400000000000000000000014651417504024300227500ustar00rootroot00000000000000 core-0.8/settings-daemon/mouse/libinputsettings.cpp000066400000000000000000000015321417504024300226560ustar00rootroot00000000000000/* SPDX-FileCopyrightText: 2018 Roman Gilg SPDX-License-Identifier: GPL-2.0-or-later */ #include "libinputsettings.h" #include #include template<> bool LibinputSettings::load(QString key, bool defVal) { QSettings settings("cutefishos", "mouse"); return settings.value(key, defVal).toBool(); } template<> qreal LibinputSettings::load(QString key, qreal defVal) { QSettings settings("cutefishos", "mouse"); return settings.value(key, defVal).toReal(); } template<> void LibinputSettings::save(QString key, bool val) { QSettings settings("cutefishos", "mouse"); settings.setValue(key, val); settings.sync(); } template<> void LibinputSettings::save(QString key, qreal val) { QSettings settings("cutefishos", "mouse"); settings.setValue(key, val); settings.sync(); } core-0.8/settings-daemon/mouse/libinputsettings.h000066400000000000000000000005571417504024300223310ustar00rootroot00000000000000/* SPDX-FileCopyrightText: 2018 Roman Gilg SPDX-License-Identifier: GPL-2.0-or-later */ #ifndef LIBINPUTSETTINGS_H #define LIBINPUTSETTINGS_H #include struct LibinputSettings { template T load(QString key, T defVal); template void save(QString key, T val); }; #endif // LIBINPUTSETTINGS_H core-0.8/settings-daemon/mouse/mousemanager.cpp000066400000000000000000000047371417504024300217440ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: Reion Wong * * 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 * 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 "mousemanager.h" #include "mouseadaptor.h" Mouse::Mouse(QObject *parent) : QObject(parent) , m_inputDummydevice(new X11LibinputDummyDevice(this, QX11Info::display())) { // init dbus new MouseAdaptor(this); QDBusConnection::sessionBus().registerObject(QStringLiteral("/Mouse"), this); connect(m_inputDummydevice, &X11LibinputDummyDevice::leftHandedChanged, this, &Mouse::leftHandedChanged); connect(m_inputDummydevice, &X11LibinputDummyDevice::pointerAccelerationProfileChanged, this, &Mouse::accelerationChanged); connect(m_inputDummydevice, &X11LibinputDummyDevice::naturalScrollChanged, this, &Mouse::naturalScrollChanged); connect(m_inputDummydevice, &X11LibinputDummyDevice::pointerAccelerationChanged, this, &Mouse::pointerAccelerationChanged); } Mouse::~Mouse() { delete m_inputDummydevice; } bool Mouse::leftHanded() const { return m_inputDummydevice->isLeftHanded(); } void Mouse::setLeftHanded(bool enabled) { m_inputDummydevice->setLeftHanded(enabled); m_inputDummydevice->applyConfig(); } bool Mouse::acceleration() const { return m_inputDummydevice->pointerAccelerationProfileFlat(); } void Mouse::setAcceleration(bool enabled) { m_inputDummydevice->setPointerAccelerationProfileFlat(enabled); m_inputDummydevice->applyConfig(); } bool Mouse::naturalScroll() const { return m_inputDummydevice->isNaturalScroll(); } void Mouse::setNaturalScroll(bool enabled) { m_inputDummydevice->setNaturalScroll(enabled); m_inputDummydevice->applyConfig(); } qreal Mouse::pointerAcceleration() const { return m_inputDummydevice->pointerAcceleration(); } void Mouse::setPointerAcceleration(qreal value) { m_inputDummydevice->setPointerAcceleration(value); m_inputDummydevice->applyConfig(); } core-0.8/settings-daemon/mouse/mousemanager.h000066400000000000000000000035361417504024300214050ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: Reion Wong * * 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 * 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 MOUSE_H #define MOUSE_H #include #include "x11libinputdummydevice.h" class Mouse : public QObject { Q_OBJECT Q_PROPERTY(bool leftHanded READ leftHanded WRITE setLeftHanded NOTIFY leftHandedChanged) Q_PROPERTY(bool acceleration READ acceleration WRITE setAcceleration NOTIFY accelerationChanged) Q_PROPERTY(bool naturalScroll READ naturalScroll WRITE setNaturalScroll NOTIFY naturalScrollChanged) Q_PROPERTY(qreal pointerAcceleration READ pointerAcceleration WRITE setPointerAcceleration NOTIFY pointerAccelerationChanged) public: explicit Mouse(QObject *parent = nullptr); ~Mouse(); bool leftHanded() const; void setLeftHanded(bool enabled); bool acceleration() const; void setAcceleration(bool enabled); bool naturalScroll() const; void setNaturalScroll(bool enabled); qreal pointerAcceleration() const; void setPointerAcceleration(qreal value); signals: void leftHandedChanged(); void accelerationChanged(); void naturalScrollChanged(); void pointerAccelerationChanged(); private: X11LibinputDummyDevice *m_inputDummydevice; }; #endif // MOUSE_H core-0.8/settings-daemon/mouse/x11libinputdummydevice.cpp000066400000000000000000000160641417504024300236710ustar00rootroot00000000000000/* SPDX-FileCopyrightText: 2018 Roman Gilg SPDX-License-Identifier: GPL-2.0-or-later */ #include "x11libinputdummydevice.h" #include "libinputsettings.h" #include #include #include #include #include static Atom s_touchpadAtom; template static void XIForallPointerDevices(Display *dpy, const Callback &callback) { int ndevices_return; XDeviceInfo *info = XListInputDevices(dpy, &ndevices_return); if (!info) { return; } for (int i = 0; i < ndevices_return; ++i) { XDeviceInfo *dev = info + i; if ((dev->use == IsXPointer || dev->use == IsXExtensionPointer) && dev->type != s_touchpadAtom) { callback(dev); } } XFreeDeviceList(info); } struct ScopedXDeleter { static inline void cleanup(void *pointer) { if (pointer) { XFree(pointer); } } }; namespace { template void valueWriterPart(T val, Atom valAtom, Display *dpy) { Q_UNUSED(val); Q_UNUSED(valAtom); Q_UNUSED(dpy); } template<> void valueWriterPart(bool val, Atom valAtom, Display *dpy) { XIForallPointerDevices(dpy, [&](XDeviceInfo *info) { int deviceid = info->id; Status status; Atom type_return; int format_return; unsigned long num_items_return; unsigned long bytes_after_return; unsigned char *_data = nullptr; // data returned is an 1 byte boolean status = XIGetProperty(dpy, deviceid, valAtom, 0, 1, False, XA_INTEGER, &type_return, &format_return, &num_items_return, &bytes_after_return, &_data); if (status != Success) { return; } QScopedArrayPointer data(_data); _data = nullptr; if (type_return != XA_INTEGER || !data || format_return != 8) { return; } unsigned char sendVal[2] = {0}; if (num_items_return == 1) { sendVal[0] = val; } else { // Special case for acceleration profile. const Atom accel = XInternAtom(dpy, LIBINPUT_PROP_ACCEL_PROFILE_ENABLED, True); if (num_items_return != 2 || valAtom != accel) { return; } sendVal[val] = 1; } XIChangeProperty(dpy, deviceid, valAtom, XA_INTEGER, 8, XIPropModeReplace, sendVal, num_items_return); }); } template<> void valueWriterPart(qreal val, Atom valAtom, Display *dpy) { XIForallPointerDevices(dpy, [&](XDeviceInfo *info) { int deviceid = info->id; Status status; Atom float_type = XInternAtom(dpy, "FLOAT", False); Atom type_return; int format_return; unsigned long num_items_return; unsigned long bytes_after_return; unsigned char *_data = nullptr; // data returned is an 1 byte boolean status = XIGetProperty(dpy, deviceid, valAtom, 0, 1, False, float_type, &type_return, &format_return, &num_items_return, &bytes_after_return, &_data); if (status != Success) { return; } QScopedArrayPointer data(_data); _data = nullptr; if (type_return != float_type || !data || format_return != 32 || num_items_return != 1) { return; } unsigned char buffer[4096]; float *sendPtr = (float *)buffer; *sendPtr = val; XIChangeProperty(dpy, deviceid, valAtom, float_type, format_return, XIPropModeReplace, buffer, 1); }); } } X11LibinputDummyDevice::X11LibinputDummyDevice(QObject *parent, Display *dpy) : QObject(parent) , m_settings(new LibinputSettings()) , m_dpy(dpy) { m_leftHanded.atom = XInternAtom(dpy, LIBINPUT_PROP_LEFT_HANDED, True); m_middleEmulation.atom = XInternAtom(dpy, LIBINPUT_PROP_MIDDLE_EMULATION_ENABLED, True); m_naturalScroll.atom = XInternAtom(dpy, LIBINPUT_PROP_NATURAL_SCROLL, True); m_pointerAcceleration.atom = XInternAtom(dpy, LIBINPUT_PROP_ACCEL, True); m_pointerAccelerationProfileFlat.atom = XInternAtom(dpy, LIBINPUT_PROP_ACCEL_PROFILE_ENABLED, True); m_supportsDisableEvents.val = false; m_enabled.val = true; m_supportedButtons.val = Qt::LeftButton | Qt::MiddleButton | Qt::RightButton; m_supportsLeftHanded.val = true; m_supportsMiddleEmulation.val = true; m_middleEmulationEnabledByDefault.val = false; m_supportsPointerAcceleration.val = true; m_defaultPointerAcceleration.val = 0; m_supportsPointerAccelerationProfileAdaptive.val = true; m_supportsPointerAccelerationProfileFlat.val = true; m_defaultPointerAccelerationProfileAdaptive.val = true; m_defaultPointerAccelerationProfileFlat.val = false; m_supportsNaturalScroll.val = true; m_naturalScrollEnabledByDefault.val = false; s_touchpadAtom = XInternAtom(m_dpy, XI_TOUCHPAD, True); // Init getConfig(); applyConfig(); } X11LibinputDummyDevice::~X11LibinputDummyDevice() { delete m_settings; } bool X11LibinputDummyDevice::getConfig() { auto reset = [this](Prop &prop, bool defVal) { prop.reset(m_settings->load(prop.cfgName, defVal)); }; reset(m_leftHanded, false); reset(m_middleEmulation, false); reset(m_naturalScroll, false); reset(m_pointerAccelerationProfileFlat, false); m_pointerAccelerationProfileAdaptive.reset(!m_settings->load(m_pointerAccelerationProfileFlat.cfgName, false)); m_pointerAcceleration.reset(m_settings->load(m_pointerAcceleration.cfgName, 0.)); emit leftHandedChanged(); emit naturalScrollChanged(); emit pointerAccelerationProfileChanged(); emit pointerAccelerationChanged(); return true; } bool X11LibinputDummyDevice::getDefaultConfig() { m_leftHanded.set(false); m_pointerAcceleration.set(m_defaultPointerAcceleration); m_pointerAccelerationProfileFlat.set(m_defaultPointerAccelerationProfileFlat); m_pointerAccelerationProfileAdaptive.set(m_defaultPointerAccelerationProfileAdaptive); m_middleEmulation.set(m_middleEmulationEnabledByDefault); m_naturalScroll.set(m_naturalScrollEnabledByDefault); return true; } bool X11LibinputDummyDevice::applyConfig() { valueWriter(m_leftHanded); valueWriter(m_middleEmulation); valueWriter(m_naturalScroll); valueWriter(m_pointerAcceleration); valueWriter(m_pointerAccelerationProfileFlat); return true; } template bool X11LibinputDummyDevice::valueWriter(Prop &prop) { // Check atom availability first. if (prop.atom == None) { return false; } if (prop.val != prop.old) { m_settings->save(prop.cfgName, prop.val); } valueWriterPart(prop.val, prop.atom, m_dpy); prop.old = prop.val; return true; } bool X11LibinputDummyDevice::isChangedConfig() const { return m_leftHanded.changed() || m_pointerAcceleration.changed() || m_pointerAccelerationProfileFlat.changed() || m_pointerAccelerationProfileAdaptive.changed() || m_middleEmulation.changed() || m_naturalScroll.changed(); } core-0.8/settings-daemon/mouse/x11libinputdummydevice.h000066400000000000000000000221021417504024300233240ustar00rootroot00000000000000/* SPDX-FileCopyrightText: 2018 Roman Gilg SPDX-License-Identifier: GPL-2.0-or-later */ #ifndef X11LIBINPUTDUMMYDEVICE_H #define X11LIBINPUTDUMMYDEVICE_H #include #include #include #include struct LibinputSettings; class X11LibinputDummyDevice : public QObject { Q_OBJECT // // general Q_PROPERTY(QString name READ name CONSTANT) Q_PROPERTY(bool supportsDisableEvents READ supportsDisableEvents CONSTANT) Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged) // // advanced Q_PROPERTY(Qt::MouseButtons supportedButtons READ supportedButtons CONSTANT) Q_PROPERTY(bool supportsLeftHanded READ supportsLeftHanded CONSTANT) Q_PROPERTY(bool leftHandedEnabledByDefault READ leftHandedEnabledByDefault CONSTANT) Q_PROPERTY(bool leftHanded READ isLeftHanded WRITE setLeftHanded NOTIFY leftHandedChanged) Q_PROPERTY(bool supportsMiddleEmulation READ supportsMiddleEmulation CONSTANT) Q_PROPERTY(bool middleEmulationEnabledByDefault READ middleEmulationEnabledByDefault CONSTANT) Q_PROPERTY(bool middleEmulation READ isMiddleEmulation WRITE setMiddleEmulation NOTIFY middleEmulationChanged) // // acceleration speed and profile Q_PROPERTY(bool supportsPointerAcceleration READ supportsPointerAcceleration CONSTANT) Q_PROPERTY(qreal pointerAcceleration READ pointerAcceleration WRITE setPointerAcceleration NOTIFY pointerAccelerationChanged) Q_PROPERTY(bool supportsPointerAccelerationProfileFlat READ supportsPointerAccelerationProfileFlat CONSTANT) Q_PROPERTY(bool defaultPointerAccelerationProfileFlat READ defaultPointerAccelerationProfileFlat CONSTANT) Q_PROPERTY(bool pointerAccelerationProfileFlat READ pointerAccelerationProfileFlat WRITE setPointerAccelerationProfileFlat NOTIFY pointerAccelerationProfileChanged) Q_PROPERTY(bool supportsPointerAccelerationProfileAdaptive READ supportsPointerAccelerationProfileAdaptive CONSTANT) Q_PROPERTY(bool defaultPointerAccelerationProfileAdaptive READ defaultPointerAccelerationProfileAdaptive CONSTANT) Q_PROPERTY(bool pointerAccelerationProfileAdaptive READ pointerAccelerationProfileAdaptive WRITE setPointerAccelerationProfileAdaptive NOTIFY pointerAccelerationProfileChanged) // // scrolling Q_PROPERTY(bool supportsNaturalScroll READ supportsNaturalScroll CONSTANT) Q_PROPERTY(bool naturalScrollEnabledByDefault READ naturalScrollEnabledByDefault CONSTANT) Q_PROPERTY(bool naturalScroll READ isNaturalScroll WRITE setNaturalScroll NOTIFY naturalScrollChanged) public: X11LibinputDummyDevice(QObject *parent, Display *dpy); ~X11LibinputDummyDevice() override; bool getConfig(); bool getDefaultConfig(); bool applyConfig(); bool isChangedConfig() const; // // general QString name() const { return m_name.val; } QString sysName() const { return m_sysName.val; } bool supportsDisableEvents() const { return m_supportsDisableEvents.val; } void setEnabled(bool enabled) { m_enabled.set(enabled); } bool isEnabled() const { return m_enabled.val; } Qt::MouseButtons supportedButtons() const { return m_supportedButtons.val; } // // advanced bool supportsLeftHanded() const { return m_supportsLeftHanded.val; } bool leftHandedEnabledByDefault() const { return m_leftHandedEnabledByDefault.val; } bool isLeftHanded() const { return m_leftHanded.val; } void setLeftHanded(bool set) { m_leftHanded.set(set); } bool supportsMiddleEmulation() const { return m_supportsMiddleEmulation.val; } bool middleEmulationEnabledByDefault() const { return m_middleEmulationEnabledByDefault.val; } bool isMiddleEmulation() const { return m_middleEmulation.val; } void setMiddleEmulation(bool set) { m_middleEmulation.set(set); } // // acceleration speed and profile bool supportsPointerAcceleration() const { return m_supportsPointerAcceleration.val; } qreal pointerAcceleration() const { return m_pointerAcceleration.val; } void setPointerAcceleration(qreal acceleration) { m_pointerAcceleration.set(acceleration); } bool supportsPointerAccelerationProfileFlat() const { return m_supportsPointerAccelerationProfileFlat.val; } bool defaultPointerAccelerationProfileFlat() const { return m_defaultPointerAccelerationProfileFlat.val; } bool pointerAccelerationProfileFlat() const { return m_pointerAccelerationProfileFlat.val; } void setPointerAccelerationProfileFlat(bool set) { m_pointerAccelerationProfileFlat.set(set); } bool supportsPointerAccelerationProfileAdaptive() const { return m_supportsPointerAccelerationProfileAdaptive.val; } bool defaultPointerAccelerationProfileAdaptive() const { return m_defaultPointerAccelerationProfileAdaptive.val; } bool pointerAccelerationProfileAdaptive() const { return m_pointerAccelerationProfileAdaptive.val; } void setPointerAccelerationProfileAdaptive(bool set) { m_pointerAccelerationProfileAdaptive.set(set); } // // scrolling bool supportsNaturalScroll() const { return m_supportsNaturalScroll.val; } bool naturalScrollEnabledByDefault() const { return m_naturalScrollEnabledByDefault.val; } bool isNaturalScroll() const { return m_naturalScroll.val; } void setNaturalScroll(bool set) { m_naturalScroll.set(set); } Q_SIGNALS: void leftHandedChanged(); void pointerAccelerationChanged(); void pointerAccelerationProfileChanged(); void enabledChanged(); void middleEmulationChanged(); void naturalScrollChanged(); private: template struct Prop { explicit Prop(const QString &_name, const QString &_cfgName = "") : name(_name) , cfgName(_cfgName) { } void set(T newVal) { if (avail && val != newVal) { val = newVal; } } void set(const Prop &p) { if (avail && val != p.val) { val = p.val; } } bool changed() const { return avail && (old != val); } void reset(T newVal) { val = newVal; old = newVal; } QString name; QString cfgName; bool avail = true; T old; T val; Atom atom; }; template bool valueWriter(Prop &prop); // // general Prop m_name = Prop("name"); Prop m_sysName = Prop("sysName"); Prop m_supportsDisableEvents = Prop("supportsDisableEvents"); Prop m_enabled = Prop("enabled"); // // advanced Prop m_supportedButtons = Prop("supportedButtons"); Prop m_supportsLeftHanded = Prop("supportsLeftHanded"); Prop m_leftHandedEnabledByDefault = Prop("leftHandedEnabledByDefault"); Prop m_leftHanded = Prop("leftHanded", "XLbInptLeftHanded"); Prop m_supportsMiddleEmulation = Prop("supportsMiddleEmulation"); Prop m_middleEmulationEnabledByDefault = Prop("middleEmulationEnabledByDefault"); Prop m_middleEmulation = Prop("middleEmulation", "XLbInptMiddleEmulation"); // // acceleration speed and profile Prop m_supportsPointerAcceleration = Prop("supportsPointerAcceleration"); Prop m_defaultPointerAcceleration = Prop("defaultPointerAcceleration"); Prop m_pointerAcceleration = Prop("pointerAcceleration", "XLbInptPointerAcceleration"); Prop m_supportsPointerAccelerationProfileFlat = Prop("supportsPointerAccelerationProfileFlat"); Prop m_defaultPointerAccelerationProfileFlat = Prop("defaultPointerAccelerationProfileFlat"); Prop m_pointerAccelerationProfileFlat = Prop("pointerAccelerationProfileFlat", "XLbInptAccelProfileFlat"); Prop m_supportsPointerAccelerationProfileAdaptive = Prop("supportsPointerAccelerationProfileAdaptive"); Prop m_defaultPointerAccelerationProfileAdaptive = Prop("defaultPointerAccelerationProfileAdaptive"); Prop m_pointerAccelerationProfileAdaptive = Prop("pointerAccelerationProfileAdaptive"); // // scrolling Prop m_supportsNaturalScroll = Prop("supportsNaturalScroll"); Prop m_naturalScrollEnabledByDefault = Prop("naturalScrollEnabledByDefault"); Prop m_naturalScroll = Prop("naturalScroll", "XLbInptNaturalScroll"); LibinputSettings *m_settings; Display *m_dpy = nullptr; }; #endif // X11LIBINPUTDUMMYDEVICE_H core-0.8/settings-daemon/theme/000077500000000000000000000000001417504024300165145ustar00rootroot00000000000000core-0.8/settings-daemon/theme/com.cutefish.Theme.xml000066400000000000000000000060241417504024300226700ustar00rootroot00000000000000 core-0.8/settings-daemon/theme/thememanager.cpp000066400000000000000000000351421417504024300216620ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: revenmartin * * 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 * 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 "thememanager.h" #include "themeadaptor.h" #include #include #include #include #include #include static const QByteArray s_systemFontName = QByteArrayLiteral("Font"); static const QByteArray s_systemFixedFontName = QByteArrayLiteral("FixedFont"); static const QByteArray s_systemPointFontSize = QByteArrayLiteral("FontSize"); static const QByteArray s_devicePixelRatio = QByteArrayLiteral("PixelRatio"); static QString gtkRc2Path() { return QDir::homePath() + QLatin1String("/.gtkrc-2.0"); } static QString gtk3SettingsIniPath() { return QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + QLatin1String("/gtk-3.0/settings.ini"); } ThemeManager *ThemeManager::self() { static ThemeManager t; return &t; } ThemeManager::ThemeManager(QObject *parent) : QObject(parent) , m_settings(new QSettings(QStringLiteral("cutefishos"), QStringLiteral("theme"))) { if (!QFile::exists(m_settings->fileName())) { QFile file(m_settings->fileName()); if (file.open(QIODevice::WriteOnly | QIODevice::Text)) { QTextStream in(&file); in << ""; file.close(); } } // init dbus new ThemeAdaptor(this); QDBusConnection::sessionBus().registerObject(QStringLiteral("/Theme"), this); // init value m_isDarkMode = m_settings->value("DarkMode", false).toBool(); m_darkModeDimsWallpaer = m_settings->value("DarkModeDimsWallpaer", false).toBool(); m_wallpaperPath = m_settings->value("Wallpaper", "/usr/share/backgrounds/cutefishos/default.jpg").toString(); m_accentColor = m_settings->value("AccentColor", 0).toInt(); m_backgroundType = m_settings->value("BackgroundType", 0).toInt(); m_backgroundColor = m_settings->value("BackgroundColor", "#2B8ADA").toString(); m_cursorTheme = m_settings->value("CursorTheme", "default").toString(); m_cursorSize = m_settings->value("CursorSize", 24).toInt(); m_iconTheme = m_settings->value("IconTheme", "Crule").toString(); // Start the DE and need to update the settings again. updateGtk3Config(); // Init fonts. if (!m_settings->contains(s_systemFixedFontName)) { m_settings->setValue(s_systemFixedFontName, "Monospace"); } if (!m_settings->contains(s_systemFontName)) { QSettings lanSettings(QStringLiteral("cutefishos"), QStringLiteral("language")); QString languageCode = lanSettings.value("language").toString(); QString fontName; if (languageCode == "zh_CN") { fontName = "Noto Sans CJK SC"; } else if (languageCode.contains("en_")) { fontName = "Noto Sans"; } else if (languageCode == "zh_TW") { fontName = "Noto Sans CJK TC"; } else if (languageCode == "zh_HK") { fontName = "Noto Serif CJK HK"; } else if (languageCode == "ja_JP") { fontName = "Noto Serif CJK JP"; } else { fontName = "Noto Sans"; } m_settings->setValue(s_systemFontName, fontName); } // 登陆后更新 fontconfig updateFontConfig(); } bool ThemeManager::isDarkMode() { return m_isDarkMode; } void ThemeManager::setDarkMode(bool darkMode) { if (darkMode == m_isDarkMode) return; m_isDarkMode = darkMode; m_settings->setValue("DarkMode", darkMode); updateGtk3Config(); emit darkModeChanged(m_isDarkMode); } bool ThemeManager::darkModeDimsWallpaer() const { return m_darkModeDimsWallpaer; } void ThemeManager::setDarkModeDimsWallpaer(bool value) { if (m_darkModeDimsWallpaer == value) return; m_darkModeDimsWallpaer = value; m_settings->setValue("DarkModeDimsWallpaer", m_darkModeDimsWallpaer); emit darkModeDimsWallpaerChanged(); } int ThemeManager::accentColor() { return m_settings->value("AccentColor", 0).toInt(); } void ThemeManager::setAccentColor(int accentColor) { if (m_accentColor == accentColor) return; m_accentColor = accentColor; m_settings->setValue("AccentColor", m_accentColor); emit accentColorChanged(m_accentColor); } QString ThemeManager::cursorTheme() const { return m_cursorTheme; } void ThemeManager::setCursorTheme(const QString &theme) { if (m_cursorTheme != theme) { m_cursorTheme = theme; m_settings->setValue("CursorTheme", m_cursorTheme); applyXResources(); applyCursor(); emit cursorThemeChanged(); } } int ThemeManager::cursorSize() const { return m_cursorSize; } void ThemeManager::setCursorSize(int size) { if (m_cursorSize != size) { m_cursorSize = size; m_settings->setValue("CursorSize", m_cursorSize); applyXResources(); applyCursor(); emit cursorSizeChanged(); } } void ThemeManager::updateGtk2Config() { } QString ThemeManager::systemFont() { return m_settings->value(s_systemFontName, "Noto Sans").toString(); } void ThemeManager::setSystemFont(const QString &fontFamily) { m_settings->setValue(s_systemFontName, fontFamily); updateGtk3Config(); updateFontConfig(); emit systemFontChanged(); } QString ThemeManager::systemFixedFont() { return m_settings->value(s_systemFixedFontName, "Monospace").toString(); } void ThemeManager::setSystemFixedFont(const QString &fontFamily) { m_settings->setValue(s_systemFixedFontName, fontFamily); updateFontConfig(); } qreal ThemeManager::systemFontPointSize() { return m_settings->value(s_systemPointFontSize, 9).toReal(); } void ThemeManager::setSystemFontPointSize(qreal fontSize) { m_settings->setValue(s_systemPointFontSize, fontSize); updateGtk3Config(); emit systemFontPointSizeChanged(); } qreal ThemeManager::devicePixelRatio() { return m_settings->value(s_devicePixelRatio, 1.0).toReal(); } void ThemeManager::setDevicePixelRatio(qreal ratio) { int fontDpi = qRound(ratio * 96.0); m_settings->setValue(s_devicePixelRatio, ratio); m_settings->setValue("forceFontDPI", fontDpi); m_settings->sync(); applyXResources(); // SDDM QProcess p; p.setProgram("pkexec"); p.setArguments(QStringList() << "cutefish-sddm-helper" << "--dpi" << QString::number(fontDpi)); p.start(); p.waitForFinished(-1); QDBusInterface iface("org.freedesktop.Notifications", "/org/freedesktop/Notifications", "org.freedesktop.Notifications", QDBusConnection::sessionBus()); if (iface.isValid()) { QList args; args << "cutefish-settings"; args << ((unsigned int) 0); args << "preferences-system"; args << ""; args << tr("Screen scaling needs to be re-login to take effect"); args << QStringList(); args << QVariantMap(); args << (int) 10; iface.asyncCallWithArgumentList("Notify", args); } } QString ThemeManager::wallpaper() { return m_wallpaperPath; } void ThemeManager::setWallpaper(const QString &path) { if (m_wallpaperPath != path) { m_wallpaperPath = path; m_settings->setValue("Wallpaper", path); emit wallpaperChanged(path); } } int ThemeManager::backgroundType() { return m_backgroundType; } void ThemeManager::setBackgroundType(int type) { if (m_backgroundType != type) { m_backgroundType = type; m_settings->setValue("BackgroundType", m_backgroundType); emit backgroundTypeChanged(); } } QString ThemeManager::backgroundColor() { return m_backgroundColor; } void ThemeManager::setBackgroundColor(QString color) { if (m_backgroundColor != color) { m_backgroundColor = color; m_settings->setValue("BackgroundColor", m_backgroundColor); emit backgroundColorChanged(); } } void ThemeManager::updateGtk3Config() { QSettings settings(gtk3SettingsIniPath(), QSettings::IniFormat); settings.clear(); settings.setIniCodec("UTF-8"); settings.beginGroup("Settings"); // font settings.setValue("gtk-font-name", QString("%1 %2").arg(systemFont()).arg(systemFontPointSize())); // dark mode settings.setValue("gtk-application-prefer-dark-theme", isDarkMode()); // icon theme settings.setValue("gtk-icon-theme-name", m_iconTheme); // other settings.setValue("gtk-enable-animations", true); // theme settings.setValue("gtk-theme-name", isDarkMode() ? "Cutefish-dark" : "Cutefish-light"); settings.sync(); } void ThemeManager::applyXResources() { m_settings->sync(); qreal scaleFactor = this->devicePixelRatio(); int fontDpi = 96 * scaleFactor; int xftAntialias = m_settings->value("XftAntialias", 1).toBool(); QString xftHintStyle = m_settings->value("XftHintStyle", "hintfull").toString(); const QString datas = QString("Xft.dpi: %1\n" "Xcursor.theme: %2\n" "Xcursor.size: %3\n" "Xft.antialias: %4\n" "Xft.hintstyle: %5") .arg(fontDpi) .arg(m_cursorTheme) .arg(m_cursorSize * scaleFactor) .arg(xftAntialias) .arg(xftHintStyle); QProcess p; p.start(QStringLiteral("xrdb"), {QStringLiteral("-quiet"), QStringLiteral("-merge"), QStringLiteral("-nocpp")}); p.setProcessChannelMode(QProcess::ForwardedChannels); p.write(datas.toLatin1()); p.closeWriteChannel(); p.waitForFinished(-1); } void ThemeManager::applyCursor() { QProcess p; p.start("cupdatecursor", QStringList() << cursorTheme() << QString::number(cursorSize() * devicePixelRatio())); p.waitForFinished(-1); QDBusMessage message = QDBusMessage::createSignal("/KGlobalSettings", "org.kde.KGlobalSettings", "notifyChange"); // ChangeCursor message << 5; message << 0; QDBusConnection::sessionBus().send(message); } void ThemeManager::updateFontConfig() { const QString &familyFont = systemFont(); const QString &fixedFont = systemFixedFont(); const QString &familyFallback = "Noto Sans"; QSettings settings(QSettings::UserScope, "cutefishos", "theme"); bool hinting = settings.value("XftAntialias", 1).toBool(); QString hintStyle = settings.value("XftHintStyle", "hintslight").toString(); QString content = QString("" "" "" "" "" "serif" "" "" "%1" "%2" "" "" "" "" "sans-serif" "" "" "%3" "%4" "" "" "" "" "monospace" "" "" "%5" "%6" "%7" "" "" "" "rgb" "" "" "" "%8" "" "" "" "" "%9" "" "" "" ).arg(familyFont).arg(familyFallback) .arg(familyFont).arg(familyFallback) .arg(fixedFont).arg(fixedFont) .arg(familyFont).arg(hinting ? "true" : "false") .arg(hintStyle); QString targetPath(QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + QLatin1Char('/') + QLatin1String("fontconfig")); if (!QDir(targetPath).exists()) { QDir(targetPath).mkpath(targetPath); } targetPath += "/conf.d"; if (!QDir(targetPath).exists()) { QDir(targetPath).mkpath(targetPath); } QString xmlOut; QXmlStreamReader reader(content); QXmlStreamWriter writer(&xmlOut); writer.setAutoFormatting(true); while (!reader.atEnd()) { reader.readNext(); if (!reader.isWhitespace()) { writer.writeCurrentToken(reader); } } QFile file(targetPath + "/99-cutefish.conf"); if (file.open(QIODevice::WriteOnly)) { QTextStream s(&file); s << xmlOut.toLatin1(); file.close(); } } QString ThemeManager::iconTheme() const { return m_iconTheme; } void ThemeManager::setIconTheme(const QString &iconTheme) { if (m_iconTheme == iconTheme) return; m_iconTheme = iconTheme; m_settings->setValue("IconTheme", m_iconTheme); updateGtk3Config(); emit iconThemeChanged(); } core-0.8/settings-daemon/theme/thememanager.h000066400000000000000000000077661417504024300213420ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: revenmartin * * 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 * 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 THEMEMANAGER_H #define THEMEMANAGER_H #include #include class ThemeManager : public QObject { Q_OBJECT Q_PROPERTY(bool isDarkMode READ isDarkMode WRITE setDarkMode NOTIFY darkModeChanged) Q_PROPERTY(bool darkModeDimsWallpaer READ darkModeDimsWallpaer WRITE setDarkModeDimsWallpaer NOTIFY darkModeDimsWallpaerChanged) Q_PROPERTY(QString systemFont READ systemFont WRITE setSystemFont NOTIFY systemFontChanged) Q_PROPERTY(QString systemFixedFont READ systemFixedFont WRITE setSystemFixedFont) Q_PROPERTY(qreal systemFontPointSize READ systemFontPointSize WRITE setSystemFontPointSize NOTIFY systemFontPointSizeChanged) Q_PROPERTY(qreal devicePixelRatio READ devicePixelRatio WRITE setDevicePixelRatio) Q_PROPERTY(QString wallpaper READ wallpaper WRITE setWallpaper NOTIFY wallpaperChanged) Q_PROPERTY(int accentColor READ accentColor WRITE setAccentColor NOTIFY accentColorChanged) Q_PROPERTY(int backgroundType READ backgroundType WRITE setBackgroundType NOTIFY backgroundTypeChanged) Q_PROPERTY(QString backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged) Q_PROPERTY(QString cursorTheme READ cursorTheme WRITE setCursorTheme NOTIFY cursorThemeChanged) Q_PROPERTY(int cursorSize READ cursorSize WRITE setCursorSize NOTIFY cursorSizeChanged) Q_PROPERTY(QString iconTheme READ iconTheme WRITE setIconTheme NOTIFY iconThemeChanged) public: static ThemeManager *self(); ThemeManager(QObject *parent = nullptr); bool isDarkMode(); void setDarkMode(bool darkMode); bool darkModeDimsWallpaer() const; void setDarkModeDimsWallpaer(bool value); QString systemFont(); void setSystemFont(const QString &fontFamily); QString systemFixedFont(); void setSystemFixedFont(const QString &fontFamily); qreal systemFontPointSize(); void setSystemFontPointSize(qreal fontSize); qreal devicePixelRatio(); void setDevicePixelRatio(qreal ratio); QString wallpaper(); void setWallpaper(const QString &path); int backgroundType(); void setBackgroundType(int type); QString backgroundColor(); void setBackgroundColor(QString color); int accentColor(); void setAccentColor(int accentColor); QString cursorTheme() const; void setCursorTheme(const QString &theme); int cursorSize() const; void setCursorSize(int size); void updateGtk2Config(); void updateGtk3Config(); void applyXResources(); void applyCursor(); QString iconTheme() const; void setIconTheme(const QString &iconTheme); void updateFontConfig(); signals: void darkModeChanged(bool darkMode); void wallpaperChanged(QString path); void darkModeDimsWallpaerChanged(); void accentColorChanged(int accentColor); void backgroundTypeChanged(); void backgroundColorChanged(); void cursorThemeChanged(); void cursorSizeChanged(); void iconThemeChanged(); void systemFontPointSizeChanged(); void systemFontChanged(); private: QSettings *m_settings; bool m_isDarkMode; bool m_darkModeDimsWallpaer; QString m_wallpaperPath; int m_backgroundType; QString m_backgroundColor; int m_accentColor; QString m_cursorTheme; int m_cursorSize; QString m_iconTheme; }; #endif core-0.8/settings-daemon/touchpad/000077500000000000000000000000001417504024300172215ustar00rootroot00000000000000core-0.8/settings-daemon/touchpad/com.cutefish.Touchpad.xml000066400000000000000000000016301417504024300241000ustar00rootroot00000000000000 core-0.8/settings-daemon/touchpad/libinputcommon.cpp000066400000000000000000000002711417504024300227640ustar00rootroot00000000000000/* SPDX-FileCopyrightText: 2019 Atul Bisht SPDX-License-Identifier: GPL-2.0-or-later */ #include "libinputcommon.h" #include "moc_libinputcommon.cpp" core-0.8/settings-daemon/touchpad/libinputcommon.h000066400000000000000000000446411417504024300224420ustar00rootroot00000000000000/* SPDX-FileCopyrightText: 2017 Roman Gilg SPDX-FileCopyrightText: 2019 Atul Bisht SPDX-License-Identifier: GPL-2.0-or-later */ #ifndef LIBINPUTCOMMON_H #define LIBINPUTCOMMON_H #include #include namespace { template inline T valueLoaderPart(QVariant const &reply) { Q_UNUSED(reply); return T(); } template<> inline bool valueLoaderPart(QVariant const &reply) { return reply.toBool(); } template<> inline int valueLoaderPart(QVariant const &reply) { return reply.toInt(); } template<> inline quint32 valueLoaderPart(QVariant const &reply) { return reply.toInt(); } template<> inline qreal valueLoaderPart(QVariant const &reply) { return reply.toReal(); } template<> inline QString valueLoaderPart(QVariant const &reply) { return reply.toString(); } template<> inline Qt::MouseButtons valueLoaderPart(QVariant const &reply) { return static_cast(reply.toInt()); } } class LibinputCommon : public QObject { Q_OBJECT // // general Q_PROPERTY(QString name READ name CONSTANT) Q_PROPERTY(bool supportsDisableEvents READ supportsDisableEvents CONSTANT) Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged) // // advanced Q_PROPERTY(Qt::MouseButtons supportedButtons READ supportedButtons CONSTANT) Q_PROPERTY(bool supportsLeftHanded READ supportsLeftHanded CONSTANT) Q_PROPERTY(bool leftHandedEnabledByDefault READ leftHandedEnabledByDefault CONSTANT) Q_PROPERTY(bool leftHanded READ isLeftHanded WRITE setLeftHanded NOTIFY leftHandedChanged) Q_PROPERTY(bool supportsDisableEventsOnExternalMouse READ supportsDisableEventsOnExternalMouse CONSTANT) Q_PROPERTY(bool supportsDisableWhileTyping READ supportsDisableWhileTyping CONSTANT) Q_PROPERTY(bool disableWhileTypingEnabledByDefault READ disableWhileTypingEnabledByDefault CONSTANT) Q_PROPERTY(bool disableWhileTyping READ isDisableWhileTyping WRITE setDisableWhileTyping NOTIFY disableWhileTypingChanged) Q_PROPERTY(bool supportsMiddleEmulation READ supportsMiddleEmulation CONSTANT) Q_PROPERTY(bool middleEmulationEnabledByDefault READ middleEmulationEnabledByDefault CONSTANT) Q_PROPERTY(bool middleEmulation READ isMiddleEmulation WRITE setMiddleEmulation NOTIFY middleEmulationChanged) // // acceleration speed and profile Q_PROPERTY(bool supportsPointerAcceleration READ supportsPointerAcceleration CONSTANT) Q_PROPERTY(qreal pointerAcceleration READ pointerAcceleration WRITE setPointerAcceleration NOTIFY pointerAccelerationChanged) Q_PROPERTY(bool supportsPointerAccelerationProfileFlat READ supportsPointerAccelerationProfileFlat CONSTANT) Q_PROPERTY(bool defaultPointerAccelerationProfileFlat READ defaultPointerAccelerationProfileFlat CONSTANT) Q_PROPERTY(bool pointerAccelerationProfileFlat READ pointerAccelerationProfileFlat WRITE setPointerAccelerationProfileFlat NOTIFY pointerAccelerationProfileChanged) Q_PROPERTY(bool supportsPointerAccelerationProfileAdaptive READ supportsPointerAccelerationProfileAdaptive CONSTANT) Q_PROPERTY(bool defaultPointerAccelerationProfileAdaptive READ defaultPointerAccelerationProfileAdaptive CONSTANT) Q_PROPERTY(bool pointerAccelerationProfileAdaptive READ pointerAccelerationProfileAdaptive WRITE setPointerAccelerationProfileAdaptive NOTIFY pointerAccelerationProfileChanged) // // tapping Q_PROPERTY(int tapFingerCount READ tapFingerCount CONSTANT) Q_PROPERTY(bool tapToClickEnabledByDefault READ tapToClickEnabledByDefault CONSTANT) Q_PROPERTY(bool tapToClick READ isTapToClick WRITE setTapToClick NOTIFY tapToClickChanged) Q_PROPERTY(bool supportsLmrTapButtonMap READ supportsLmrTapButtonMap CONSTANT) Q_PROPERTY(bool lmrTapButtonMapEnabledByDefault READ lmrTapButtonMapEnabledByDefault CONSTANT) Q_PROPERTY(bool lmrTapButtonMap READ lmrTapButtonMap WRITE setLmrTapButtonMap NOTIFY lmrTapButtonMapChanged) Q_PROPERTY(bool tapAndDragEnabledByDefault READ tapAndDragEnabledByDefault CONSTANT) Q_PROPERTY(bool tapAndDrag READ isTapAndDrag WRITE setTapAndDrag NOTIFY tapAndDragChanged) Q_PROPERTY(bool tapDragLockEnabledByDefault READ tapDragLockEnabledByDefault CONSTANT) Q_PROPERTY(bool tapDragLock READ isTapDragLock WRITE setTapDragLock NOTIFY tapDragLockChanged) // // scrolling Q_PROPERTY(bool supportsNaturalScroll READ supportsNaturalScroll CONSTANT) Q_PROPERTY(bool naturalScrollEnabledByDefault READ naturalScrollEnabledByDefault CONSTANT) Q_PROPERTY(bool naturalScroll READ isNaturalScroll WRITE setNaturalScroll NOTIFY naturalScrollChanged) Q_PROPERTY(bool supportsHorizontalScrolling READ supportsHorizontalScrolling CONSTANT) Q_PROPERTY(bool horizontalScrollingByDefault READ horizontalScrollingByDefault CONSTANT) Q_PROPERTY(bool horizontalScrolling READ horizontalScrolling WRITE setHorizontalScrolling NOTIFY horizontalScrollingChanged) Q_PROPERTY(bool supportsScrollTwoFinger READ supportsScrollTwoFinger CONSTANT) Q_PROPERTY(bool scrollTwoFingerEnabledByDefault READ scrollTwoFingerEnabledByDefault CONSTANT) Q_PROPERTY(bool scrollTwoFinger READ isScrollTwoFinger WRITE setScrollTwoFinger NOTIFY scrollMethodChanged) Q_PROPERTY(bool supportsScrollEdge READ supportsScrollEdge CONSTANT) Q_PROPERTY(bool scrollEdgeEnabledByDefault READ scrollEdgeEnabledByDefault CONSTANT) Q_PROPERTY(bool scrollEdge READ isScrollEdge WRITE setScrollEdge NOTIFY scrollMethodChanged) Q_PROPERTY(bool supportsScrollOnButtonDown READ supportsScrollOnButtonDown CONSTANT) Q_PROPERTY(bool scrollOnButtonDownEnabledByDefault READ scrollOnButtonDownEnabledByDefault CONSTANT) Q_PROPERTY(bool scrollOnButtonDown READ isScrollOnButtonDown WRITE setScrollOnButtonDown NOTIFY scrollMethodChanged) Q_PROPERTY(quint32 defaultScrollButton READ defaultScrollButton CONSTANT) Q_PROPERTY(quint32 scrollButton READ scrollButton WRITE setScrollButton NOTIFY scrollButtonChanged) // Click Methods Q_PROPERTY(bool supportsClickMethodAreas READ supportsClickMethodAreas CONSTANT) Q_PROPERTY(bool defaultClickMethodAreas READ defaultClickMethodAreas CONSTANT) Q_PROPERTY(bool clickMethodAreas READ isClickMethodAreas WRITE setClickMethodAreas NOTIFY clickMethodChanged) Q_PROPERTY(bool supportsClickMethodClickfinger READ supportsClickMethodClickfinger CONSTANT) Q_PROPERTY(bool defaultClickMethodClickfinger READ defaultClickMethodClickfinger CONSTANT) Q_PROPERTY(bool clickMethodClickfinger READ isClickMethodClickfinger WRITE setClickMethodClickfinger NOTIFY clickMethodChanged) Q_PROPERTY(bool supportsScrollFactor READ supportsScrollFactor CONSTANT) public: LibinputCommon() { } virtual ~LibinputCommon() { } virtual QString name() const = 0; virtual bool supportsDisableEvents() const = 0; virtual bool isEnabled() const = 0; virtual void setEnabled(bool set) = 0; // // advanced Qt::MouseButtons supportedButtons() const { return m_supportedButtons.val; } virtual bool supportsLeftHanded() const = 0; bool leftHandedEnabledByDefault() const { return m_leftHandedEnabledByDefault.val; } bool isLeftHanded() const { return m_leftHanded.val; } void setLeftHanded(bool set) { m_leftHanded.set(set); } virtual bool supportsDisableEventsOnExternalMouse() const = 0; virtual bool supportsDisableWhileTyping() const = 0; bool disableWhileTypingEnabledByDefault() const { return m_disableWhileTypingEnabledByDefault.val; } bool isDisableWhileTyping() const { return m_disableWhileTyping.val; } void setDisableWhileTyping(bool set) { m_disableWhileTyping.set(set); } virtual bool supportsMiddleEmulation() const = 0; bool middleEmulationEnabledByDefault() const { return m_middleEmulationEnabledByDefault.val; } bool isMiddleEmulation() const { return m_middleEmulation.val; } void setMiddleEmulation(bool set) { m_middleEmulation.set(set); } virtual bool supportsPointerAcceleration() const = 0; qreal pointerAcceleration() const { return m_pointerAcceleration.val; } void setPointerAcceleration(qreal acceleration) { m_pointerAcceleration.set(acceleration); } virtual bool supportsPointerAccelerationProfileFlat() const = 0; bool defaultPointerAccelerationProfileFlat() const { return m_defaultPointerAccelerationProfileFlat.val; } bool pointerAccelerationProfileFlat() const { return m_pointerAccelerationProfileFlat.val; } void setPointerAccelerationProfileFlat(bool set) { m_pointerAccelerationProfileFlat.set(set); } virtual bool supportsPointerAccelerationProfileAdaptive() const = 0; bool defaultPointerAccelerationProfileAdaptive() const { return m_defaultPointerAccelerationProfileAdaptive.val; } bool pointerAccelerationProfileAdaptive() const { return m_pointerAccelerationProfileAdaptive.val; } void setPointerAccelerationProfileAdaptive(bool set) { m_pointerAccelerationProfileAdaptive.set(set); } // // scrolling virtual bool supportsNaturalScroll() const = 0; bool naturalScrollEnabledByDefault() const { return m_naturalScrollEnabledByDefault.val; } bool isNaturalScroll() const { return m_naturalScroll.val; } void setNaturalScroll(bool set) { m_naturalScroll.set(set); } virtual bool supportsHorizontalScrolling() const = 0; bool horizontalScrollingByDefault() const { return true; } bool horizontalScrolling() const { return m_horizontalScrolling.val; } void setHorizontalScrolling(bool set) { m_horizontalScrolling.set(set); } virtual bool supportsScrollTwoFinger() const = 0; bool scrollTwoFingerEnabledByDefault() const { return m_scrollTwoFingerEnabledByDefault.val; } bool isScrollTwoFinger() const { return m_isScrollTwoFinger.val; } void setScrollTwoFinger(bool set) { m_isScrollTwoFinger.set(set); } virtual bool supportsScrollEdge() const = 0; bool scrollEdgeEnabledByDefault() const { return m_scrollEdgeEnabledByDefault.val; } bool isScrollEdge() const { return m_isScrollEdge.val; } void setScrollEdge(bool set) { m_isScrollEdge.set(set); } virtual bool supportsScrollOnButtonDown() const = 0; bool scrollOnButtonDownEnabledByDefault() const { return m_scrollOnButtonDownEnabledByDefault.val; } bool isScrollOnButtonDown() const { return m_isScrollOnButtonDown.val; } void setScrollOnButtonDown(bool set) { m_isScrollOnButtonDown.set(set); } quint32 defaultScrollButton() const { return m_defaultScrollButton.val; } quint32 scrollButton() const { return m_scrollButton.val; } void setScrollButton(quint32 button) { m_scrollButton.set(button); } // // tapping int tapFingerCount() const { return m_tapFingerCount.val; } bool tapToClickEnabledByDefault() const { return m_tapToClickEnabledByDefault.val; } bool isTapToClick() const { return m_tapToClick.val; } void setTapToClick(bool set) { m_tapToClick.set(set); } bool supportsLmrTapButtonMap() const { return m_tapFingerCount.val > 1; } bool lmrTapButtonMapEnabledByDefault() const { return m_lmrTapButtonMapEnabledByDefault.val; } bool lmrTapButtonMap() const { return m_lmrTapButtonMap.val; } virtual void setLmrTapButtonMap(bool set) = 0; bool tapAndDragEnabledByDefault() const { return m_tapAndDragEnabledByDefault.val; } bool isTapAndDrag() const { return m_tapAndDrag.val; } void setTapAndDrag(bool set) { m_tapAndDrag.set(set); } bool tapDragLockEnabledByDefault() const { return m_tapDragLockEnabledByDefault.val; } bool isTapDragLock() const { return m_tapDragLock.val; } void setTapDragLock(bool set) { m_tapDragLock.set(set); } // // click method virtual bool supportsClickMethodAreas() const = 0; bool defaultClickMethodAreas() const { return m_defaultClickMethodAreas.val; } bool isClickMethodAreas() const { return m_clickMethodAreas.val; } void setClickMethodAreas(bool set) { m_clickMethodAreas.set(set); } virtual bool supportsClickMethodClickfinger() const = 0; bool defaultClickMethodClickfinger() const { return m_defaultClickMethodClickfinger.val; } bool isClickMethodClickfinger() const { return m_clickMethodClickfinger.val; } void setClickMethodClickfinger(bool set) { m_clickMethodClickfinger.set(set); } virtual bool supportsScrollFactor() const = 0; Q_SIGNALS: void enabledChanged(); // Tapping void tapToClickChanged(); void lmrTapButtonMapChanged(); void tapAndDragChanged(); void tapDragLockChanged(); // Advanced void leftHandedChanged(); void disableWhileTypingChanged(); void middleEmulationChanged(); // acceleration speed and profile void pointerAccelerationChanged(); void pointerAccelerationProfileChanged(); // scrolling void naturalScrollChanged(); void horizontalScrollingChanged(); void scrollMethodChanged(); void scrollButtonChanged(); // click methods void clickMethodChanged(); protected: template struct Prop { explicit Prop(const QByteArray &name) : name(name) { } void set(T newVal) { if (avail && val != newVal) { val = newVal; } } void set(const Prop &p) { if (avail && val != p.val) { val = p.val; } } bool changed() const { return avail && (old != val); } // In wayland, name will be dbus name QByteArray name; bool avail; T old; T val; }; // // general Prop m_supportsDisableEvents = Prop("supportsDisableEvents"); Prop m_enabledDefault = Prop("enabledDefault"); Prop m_enabled = Prop("enabled"); // // advanced Prop m_supportedButtons = Prop("supportedButtons"); Prop m_leftHandedEnabledByDefault = Prop("leftHandedEnabledByDefault"); Prop m_leftHanded = Prop("leftHanded"); Prop m_supportsDisableEventsOnExternalMouse = Prop("supportsDisableEventsOnExternalMouse"); Prop m_disableWhileTypingEnabledByDefault = Prop("disableWhileTypingEnabledByDefault"); Prop m_disableWhileTyping = Prop("disableWhileTyping"); Prop m_middleEmulationEnabledByDefault = Prop("middleEmulationEnabledByDefault"); Prop m_middleEmulation = Prop("middleEmulation"); // // acceleration speed and profile Prop m_defaultPointerAcceleration = Prop("defaultPointerAcceleration"); Prop m_pointerAcceleration = Prop("pointerAcceleration"); Prop m_supportsPointerAccelerationProfileFlat = Prop("supportsPointerAccelerationProfileFlat"); Prop m_defaultPointerAccelerationProfileFlat = Prop("defaultPointerAccelerationProfileFlat"); Prop m_pointerAccelerationProfileFlat = Prop("pointerAccelerationProfileFlat"); Prop m_supportsPointerAccelerationProfileAdaptive = Prop("supportsPointerAccelerationProfileAdaptive"); Prop m_defaultPointerAccelerationProfileAdaptive = Prop("defaultPointerAccelerationProfileAdaptive"); Prop m_pointerAccelerationProfileAdaptive = Prop("pointerAccelerationProfileAdaptive"); // // tapping Prop m_tapFingerCount = Prop("tapFingerCount"); Prop m_tapToClickEnabledByDefault = Prop("tapToClickEnabledByDefault"); Prop m_tapToClick = Prop("tapToClick"); Prop m_lmrTapButtonMapEnabledByDefault = Prop("lmrTapButtonMapEnabledByDefault"); Prop m_lmrTapButtonMap = Prop("lmrTapButtonMap"); Prop m_tapAndDragEnabledByDefault = Prop("tapAndDragEnabledByDefault"); Prop m_tapAndDrag = Prop("tapAndDrag"); Prop m_tapDragLockEnabledByDefault = Prop("tapDragLockEnabledByDefault"); Prop m_tapDragLock = Prop("tapDragLock"); // // scrolling Prop m_naturalScrollEnabledByDefault = Prop("naturalScrollEnabledByDefault"); Prop m_naturalScroll = Prop("naturalScroll"); Prop m_horizontalScrolling = Prop("horizontalScrolling"); Prop m_supportsScrollTwoFinger = Prop("supportsScrollTwoFinger"); Prop m_scrollTwoFingerEnabledByDefault = Prop("scrollTwoFingerEnabledByDefault"); Prop m_isScrollTwoFinger = Prop("scrollTwoFinger"); Prop m_supportsScrollEdge = Prop("supportsScrollEdge"); Prop m_scrollEdgeEnabledByDefault = Prop("scrollEdgeEnabledByDefault"); Prop m_isScrollEdge = Prop("scrollEdge"); Prop m_supportsScrollOnButtonDown = Prop("supportsScrollOnButtonDown"); Prop m_scrollOnButtonDownEnabledByDefault = Prop("scrollOnButtonDownEnabledByDefault"); Prop m_isScrollOnButtonDown = Prop("scrollOnButtonDown"); Prop m_defaultScrollButton = Prop("defaultScrollButton"); Prop m_scrollButton = Prop("scrollButton"); // Click Method Prop m_supportsClickMethodAreas = Prop("supportsClickMethodAreas"); Prop m_defaultClickMethodAreas = Prop("defaultClickMethodAreas"); Prop m_clickMethodAreas = Prop("clickMethodAreas"); Prop m_supportsClickMethodClickfinger = Prop("supportsClickMethodClickfinger"); Prop m_defaultClickMethodClickfinger = Prop("defaultClickMethodClickfinger"); Prop m_clickMethodClickfinger = Prop("clickMethodClickfinger"); }; #endif // LIBINPUTCOMMON_H core-0.8/settings-daemon/touchpad/touchpadmanager.cpp000066400000000000000000000025521417504024300230730ustar00rootroot00000000000000#include "touchpadmanager.h" #include "touchpadadaptor.h" #include TouchpadManager::TouchpadManager(QObject *parent) : QObject(parent) , m_backend(XlibBackend::initialize()) { // init dbus new TouchpadAdaptor(this); QDBusConnection::sessionBus().registerObject(QStringLiteral("/Touchpad"), this); m_backend->getConfig(); m_backend->applyConfig(); } bool TouchpadManager::available() const { return m_backend->isTouchpadAvailable(); } bool TouchpadManager::enabled() const { return m_backend->isTouchpadEnabled(); } void TouchpadManager::setEnabled(bool enabled) { m_backend->setTouchpadEnabled(enabled); m_backend->applyConfig(); } bool TouchpadManager::tapToClick() const { return m_backend->tapToClick(); } void TouchpadManager::setTapToClick(bool value) { m_backend->setTapToClick(value); m_backend->applyConfig(); } bool TouchpadManager::naturalScroll() const { return m_backend->naturalScroll(); } void TouchpadManager::setNaturalScroll(bool naturalScroll) { m_backend->setNaturalScroll(naturalScroll); m_backend->applyConfig(); } qreal TouchpadManager::pointerAcceleration() const { return m_backend->pointerAcceleration(); } void TouchpadManager::setPointerAcceleration(qreal value) { qDebug() << value; m_backend->setPointerAcceleration(value); m_backend->applyConfig(); } core-0.8/settings-daemon/touchpad/touchpadmanager.h000066400000000000000000000017561417504024300225450ustar00rootroot00000000000000#ifndef TOUCHPADMANAGER_H #define TOUCHPADMANAGER_H #include #include "x11/xlibbackend.h" class TouchpadManager : public QObject { Q_OBJECT Q_PROPERTY(bool available READ available CONSTANT) Q_PROPERTY(bool enabled READ enabled WRITE setEnabled CONSTANT) Q_PROPERTY(bool tapToClick READ tapToClick WRITE setTapToClick CONSTANT) Q_PROPERTY(bool naturalScroll READ naturalScroll WRITE setNaturalScroll CONSTANT) Q_PROPERTY(qreal pointerAcceleration READ pointerAcceleration WRITE setPointerAcceleration CONSTANT) public: explicit TouchpadManager(QObject *parent = nullptr); bool available() const; bool enabled() const; void setEnabled(bool enabled); bool tapToClick() const; void setTapToClick(bool value); bool naturalScroll() const; void setNaturalScroll(bool naturalScroll); qreal pointerAcceleration() const; void setPointerAcceleration(qreal value); private: XlibBackend *m_backend; }; #endif // TOUCHPADMANAGER_H core-0.8/settings-daemon/touchpad/x11/000077500000000000000000000000001417504024300176325ustar00rootroot00000000000000core-0.8/settings-daemon/touchpad/x11/libinputtouchpad.cpp000066400000000000000000000371201417504024300237170ustar00rootroot00000000000000/* SPDX-FileCopyrightText: 2019 Atul Bisht SPDX-License-Identifier: GPL-2.0-or-later */ #include "libinputtouchpad.h" #include #include #include #include #include #include #include const Parameter libinputProperties[] = { /* libinput disable supports property */ {"supportsDisableEvents", PT_INT, 0, 1, LIBINPUT_PROP_SENDEVENTS_AVAILABLE, 8, 0}, {"enabled", PT_INT, 0, 1, LIBINPUT_PROP_SENDEVENTS_ENABLED, 8, 0}, {"enabledDefault", PT_INT, 0, 1, LIBINPUT_PROP_SENDEVENTS_ENABLED_DEFAULT, 8, 0}, /* LeftHandSupport */ {"leftHandedEnabledByDefault", PT_INT, 0, 1, LIBINPUT_PROP_LEFT_HANDED_DEFAULT, 8, 0}, {"leftHanded", PT_INT, 0, 1, LIBINPUT_PROP_LEFT_HANDED, 8, 0}, /* Disable on external mouse */ {"supportsDisableEventsOnExternalMouse", PT_INT, 0, 1, LIBINPUT_PROP_SENDEVENTS_AVAILABLE, 8, 1}, {"disableEventsOnExternalMouse", PT_INT, 0, 1, LIBINPUT_PROP_SENDEVENTS_ENABLED, 8, 1}, {"disableEventsOnExternalMouseDefault", PT_INT, 0, 1, LIBINPUT_PROP_SENDEVENTS_ENABLED_DEFAULT, 8, 1}, /* Disable while typing */ {"disableWhileTypingEnabledByDefault", PT_INT, 0, 1, LIBINPUT_PROP_DISABLE_WHILE_TYPING_DEFAULT, 8, 0}, {"disableWhileTyping", PT_INT, 0, 1, LIBINPUT_PROP_DISABLE_WHILE_TYPING, 8, 0}, /* Middle Emulation */ {"middleEmulationEnabledByDefault", PT_INT, 0, 1, LIBINPUT_PROP_MIDDLE_EMULATION_ENABLED_DEFAULT, 8, 0}, {"middleEmulation", PT_INT, 0, 1, LIBINPUT_PROP_MIDDLE_EMULATION_ENABLED, 8, 0}, /* This is a boolean for all three fingers, no per-finger config */ {"tapToClick", PT_INT, 0, 1, LIBINPUT_PROP_TAP, 8, 0}, {"tapToClickEnabledByDefault", PT_INT, 0, 1, LIBINPUT_PROP_TAP_DEFAULT, 8, 0}, /* LMR */ {"lrmTapButtonMapEnabledByDefault", PT_INT, 0, 1, LIBINPUT_PROP_TAP_BUTTONMAP_DEFAULT, 8, 0}, {"lrmTapButtonMap", PT_INT, 0, 1, LIBINPUT_PROP_TAP_BUTTONMAP, 8, 0}, {"lmrTapButtonMapEnabledByDefault", PT_INT, 0, 1, LIBINPUT_PROP_TAP_BUTTONMAP_DEFAULT, 8, 1}, {"lmrTapButtonMap", PT_INT, 0, 1, LIBINPUT_PROP_TAP_BUTTONMAP, 8, 1}, /* Tap and Drag Enabled */ {"tapAndDragEnabledByDefault", PT_INT, 0, 1, LIBINPUT_PROP_TAP_DRAG_DEFAULT, 8, 0}, {"tapAndDrag", PT_INT, 0, 1, LIBINPUT_PROP_TAP_DRAG, 8, 0}, /* Tap and Drag Lock Enabled */ {"tapDragLockEnabledByDefault", PT_INT, 0, 1, LIBINPUT_PROP_TAP_DRAG_LOCK_DEFAULT, 8, 0}, {"tapDragLock", PT_INT, 0, 1, LIBINPUT_PROP_TAP_DRAG_LOCK, 8, 0}, /* libinput normalizes the accel to -1/1 */ {"defaultPointerAcceleration", PT_DOUBLE, -1.0, 1.0, LIBINPUT_PROP_ACCEL_DEFAULT, 0 /*float */, 0}, {"pointerAcceleration", PT_DOUBLE, -1.0, 1.0, LIBINPUT_PROP_ACCEL, 0 /*float */, 0}, /* Libinput Accel Profile */ {"supportsPointerAccelerationProfileAdaptive", PT_BOOL, 0, 1, LIBINPUT_PROP_ACCEL_PROFILES_AVAILABLE, 8, 0}, {"defaultPointerAccelerationProfileAdaptive", PT_BOOL, 0, 1, LIBINPUT_PROP_ACCEL_PROFILE_ENABLED_DEFAULT, 8, 0}, {"pointerAccelerationProfileAdaptive", PT_BOOL, 0, 1, LIBINPUT_PROP_ACCEL_PROFILE_ENABLED, 8, 0}, {"supportsPointerAccelerationProfileFlat", PT_BOOL, 0, 1, LIBINPUT_PROP_ACCEL_PROFILES_AVAILABLE, 8, 1}, {"defaultPointerAccelerationProfileFlat", PT_BOOL, 0, 1, LIBINPUT_PROP_ACCEL_PROFILE_ENABLED_DEFAULT, 8, 1}, {"pointerAccelerationProfileFlat", PT_BOOL, 0, 1, LIBINPUT_PROP_ACCEL_PROFILE_ENABLED, 8, 1}, /* Natural Scrolling */ {"naturalScrollEnabledByDefault", PT_INT, 0, 1, LIBINPUT_PROP_NATURAL_SCROLL_DEFAULT, 8, 0}, {"naturalScroll", PT_INT, 0, 1, LIBINPUT_PROP_NATURAL_SCROLL, 8, 0}, /* Horizontal scrolling */ {"horizontalScrolling", PT_INT, 0, 1, LIBINPUT_PROP_HORIZ_SCROLL_ENABLED, 8, 0}, /* Two-Finger Scrolling */ {"supportsScrollTwoFinger", PT_INT, 0, 1, LIBINPUT_PROP_SCROLL_METHODS_AVAILABLE, 8, 0}, {"scrollTwoFingerEnabledByDefault", PT_INT, 0, 1, LIBINPUT_PROP_SCROLL_METHOD_ENABLED_DEFAULT, 8, 0}, {"scrollTwoFinger", PT_INT, 0, 1, LIBINPUT_PROP_SCROLL_METHOD_ENABLED, 8, 0}, /* Edge Scrolling */ {"supportsScrollEdge", PT_INT, 0, 1, LIBINPUT_PROP_SCROLL_METHODS_AVAILABLE, 8, 1}, {"scrollEdgeEnabledByDefault", PT_INT, 0, 1, LIBINPUT_PROP_SCROLL_METHOD_ENABLED_DEFAULT, 8, 1}, {"scrollEdge", PT_INT, 0, 1, LIBINPUT_PROP_SCROLL_METHOD_ENABLED, 8, 1}, /* scroll on button */ {"supportsScrollOnButtonDown", PT_INT, 0, 1, LIBINPUT_PROP_SCROLL_METHODS_AVAILABLE, 8, 2}, {"scrollOnButtonDownEnabledByDefault", PT_INT, 0, 1, LIBINPUT_PROP_SCROLL_METHOD_ENABLED_DEFAULT, 8, 2}, {"scrollOnButtonDown", PT_INT, 0, 1, LIBINPUT_PROP_SCROLL_METHOD_ENABLED, 8, 2}, /* Scroll Button for scroll on button Down */ {"defaultScrollButton", PT_INT, 0, INT_MAX, LIBINPUT_PROP_SCROLL_BUTTON_DEFAULT, 32, 0}, {"scrollButton", PT_INT, 0, INT_MAX, LIBINPUT_PROP_SCROLL_BUTTON, 32, 0}, /* Click Methods */ {"supportsClickMethodAreas", PT_INT, 0, 1, LIBINPUT_PROP_CLICK_METHODS_AVAILABLE, 8, 0}, {"defaultClickMethodAreas", PT_INT, 0, 1, LIBINPUT_PROP_CLICK_METHOD_ENABLED_DEFAULT, 8, 0}, {"clickMethodAreas", PT_INT, 0, 1, LIBINPUT_PROP_CLICK_METHOD_ENABLED, 8, 0}, {"supportsClickMethodClickfinger", PT_INT, 0, 1, LIBINPUT_PROP_CLICK_METHODS_AVAILABLE, 8, 1}, {"defaultClickMethodClickfinger", PT_INT, 0, 1, LIBINPUT_PROP_CLICK_METHOD_ENABLED_DEFAULT, 8, 1}, {"clickMethodClickfinger", PT_INT, 0, 1, LIBINPUT_PROP_CLICK_METHOD_ENABLED, 8, 1}, /* libinput doesn't have a separate toggle for horiz scrolling */ {nullptr, PT_INT, 0, 0, nullptr, 0, 0}}; Qt::MouseButtons maskBtns(Display *display, XIButtonClassInfo *buttonInfo) { Qt::MouseButtons buttons = Qt::NoButton; for (int i = 0; i < buttonInfo->num_buttons; ++i) { QByteArray reply = XGetAtomName(display, buttonInfo->labels[i]); if (reply == BTN_LABEL_PROP_BTN_LEFT) { buttons |= Qt::LeftButton; } if (reply == BTN_LABEL_PROP_BTN_RIGHT) { buttons |= Qt::RightButton; } if (reply == BTN_LABEL_PROP_BTN_MIDDLE) { buttons |= Qt::MiddleButton; } if (reply == BTN_LABEL_PROP_BTN_SIDE) { buttons |= Qt::ExtraButton1; } if (reply == BTN_LABEL_PROP_BTN_EXTRA) { buttons |= Qt::ExtraButton2; } if (reply == BTN_LABEL_PROP_BTN_FORWARD) { buttons |= Qt::ForwardButton; } if (reply == BTN_LABEL_PROP_BTN_BACK) { buttons |= Qt::BackButton; } if (reply == BTN_LABEL_PROP_BTN_TASK) { buttons |= Qt::TaskButton; } } return buttons; } LibinputTouchpad::LibinputTouchpad(Display *display, int deviceId) : LibinputCommon() , XlibTouchpad(display, deviceId) , m_config("cutefishos", "touchpadxlibinputrc") { loadSupportedProperties(libinputProperties); int nDevices = 0; XIDeviceInfo *deviceInfo = XIQueryDevice(m_display, m_deviceId, &nDevices); m_name = deviceInfo->name; for (int i = 0; i < deviceInfo->num_classes; ++i) { XIAnyClassInfo *classInfo = deviceInfo->classes[i]; if (classInfo->type == XIButtonClass) { XIButtonClassInfo *btnInfo = (XIButtonClassInfo *)classInfo; m_supportedButtons.avail = true; m_supportedButtons.set(maskBtns(m_display, btnInfo)); } if (classInfo->type == XITouchClass) { XITouchClassInfo *touchInfo = (XITouchClassInfo *)classInfo; m_tapFingerCount.avail = true; m_tapFingerCount.set(touchInfo->num_touches); } } XIFreeDeviceInfo(deviceInfo); /* FingerCount cannot be zero */ if (!m_tapFingerCount.val) { m_tapFingerCount.avail = true; m_tapFingerCount.set(1); } } bool LibinputTouchpad::getConfig() { bool success = true; success &= valueLoader(m_supportsDisableEvents); success &= valueLoader(m_enabled); success &= valueLoader(m_enabledDefault); success &= valueLoader(m_tapToClickEnabledByDefault); success &= valueLoader(m_tapToClick); success &= valueLoader(m_lrmTapButtonMapEnabledByDefault); success &= valueLoader(m_lrmTapButtonMap); success &= valueLoader(m_lmrTapButtonMapEnabledByDefault); success &= valueLoader(m_lmrTapButtonMap); success &= valueLoader(m_tapAndDragEnabledByDefault); success &= valueLoader(m_tapAndDrag); success &= valueLoader(m_tapDragLockEnabledByDefault); success &= valueLoader(m_tapDragLock); success &= valueLoader(m_leftHandedEnabledByDefault); success &= valueLoader(m_leftHanded); success &= valueLoader(m_supportsDisableEventsOnExternalMouse); success &= valueLoader(m_disableEventsOnExternalMouse); success &= valueLoader(m_disableEventsOnExternalMouseDefault); success &= valueLoader(m_disableWhileTypingEnabledByDefault); success &= valueLoader(m_disableWhileTyping); success &= valueLoader(m_middleEmulationEnabledByDefault); success &= valueLoader(m_middleEmulation); success &= valueLoader(m_defaultPointerAcceleration); success &= valueLoader(m_pointerAcceleration); success &= valueLoader(m_supportsPointerAccelerationProfileFlat); success &= valueLoader(m_defaultPointerAccelerationProfileFlat); success &= valueLoader(m_pointerAccelerationProfileFlat); success &= valueLoader(m_supportsPointerAccelerationProfileAdaptive); success &= valueLoader(m_defaultPointerAccelerationProfileAdaptive); success &= valueLoader(m_pointerAccelerationProfileAdaptive); success &= valueLoader(m_naturalScrollEnabledByDefault); success &= valueLoader(m_naturalScroll); success &= valueLoader(m_horizontalScrolling); success &= valueLoader(m_supportsScrollTwoFinger); success &= valueLoader(m_scrollTwoFingerEnabledByDefault); success &= valueLoader(m_isScrollTwoFinger); success &= valueLoader(m_supportsScrollEdge); success &= valueLoader(m_scrollEdgeEnabledByDefault); success &= valueLoader(m_isScrollEdge); success &= valueLoader(m_supportsScrollOnButtonDown); success &= valueLoader(m_scrollOnButtonDownEnabledByDefault); success &= valueLoader(m_isScrollOnButtonDown); success &= valueLoader(m_defaultScrollButton); success &= valueLoader(m_scrollButton); // click methods success &= valueLoader(m_supportsClickMethodAreas); success &= valueLoader(m_supportsClickMethodClickfinger); success &= valueLoader(m_defaultClickMethodAreas); success &= valueLoader(m_defaultClickMethodClickfinger); success &= valueLoader(m_clickMethodAreas); success &= valueLoader(m_clickMethodClickfinger); return success; } bool LibinputTouchpad::applyConfig() { QVector msgs; msgs << valueWriter(m_enabled) << valueWriter(m_tapToClick) << valueWriter(m_lrmTapButtonMap) << valueWriter(m_lmrTapButtonMap) << valueWriter(m_tapAndDrag) << valueWriter(m_tapDragLock) << valueWriter(m_leftHanded) << valueWriter(m_disableWhileTyping) << valueWriter(m_middleEmulation) << valueWriter(m_pointerAcceleration) << valueWriter(m_pointerAccelerationProfileFlat) << valueWriter(m_pointerAccelerationProfileAdaptive) << valueWriter(m_naturalScroll) << valueWriter(m_horizontalScrolling) << valueWriter(m_isScrollTwoFinger) << valueWriter(m_isScrollEdge) << valueWriter(m_isScrollOnButtonDown) << valueWriter(m_scrollButton) << valueWriter(m_clickMethodAreas) << valueWriter(m_clickMethodClickfinger); bool success = true; QString error_msg; for (QString m : msgs) { if (!m.isNull()) { // qCCritical(KCM_TOUCHPAD) << "in error:" << m; if (!success) { error_msg.append("\n"); } error_msg.append(m); success = false; } } if (!success) { // qCCritical(KCM_TOUCHPAD) << error_msg; } flush(); return success; } bool LibinputTouchpad::getDefaultConfig() { m_enabled.set(m_enabledDefault); m_tapToClick.set(m_tapToClickEnabledByDefault); m_lrmTapButtonMap.set(m_lrmTapButtonMap); m_lmrTapButtonMap.set(m_lmrTapButtonMapEnabledByDefault); m_tapAndDrag.set(m_tapAndDragEnabledByDefault); m_tapDragLock.set(m_tapDragLockEnabledByDefault); m_leftHanded.set(m_leftHandedEnabledByDefault); m_disableEventsOnExternalMouse.set(m_disableEventsOnExternalMouseDefault); m_disableWhileTyping.set(m_disableWhileTypingEnabledByDefault); m_middleEmulation.set(m_middleEmulationEnabledByDefault); m_pointerAcceleration.set(m_defaultPointerAcceleration); m_pointerAccelerationProfileFlat.set(m_defaultPointerAccelerationProfileFlat); m_pointerAccelerationProfileAdaptive.set(m_defaultPointerAccelerationProfileAdaptive); m_naturalScroll.set(m_naturalScrollEnabledByDefault); m_horizontalScrolling.set(true); m_isScrollTwoFinger.set(m_scrollTwoFingerEnabledByDefault); m_isScrollEdge.set(m_scrollEdgeEnabledByDefault); m_isScrollOnButtonDown.set(m_scrollOnButtonDownEnabledByDefault); m_scrollButton.set(m_defaultScrollButton); m_clickMethodAreas.set(m_defaultClickMethodAreas); m_clickMethodClickfinger.set(m_defaultClickMethodClickfinger); return true; } bool LibinputTouchpad::isChangedConfig() { // clang-format off bool changed = m_enabled.changed() || m_tapToClick.changed() || m_lrmTapButtonMap.changed() || m_lmrTapButtonMap.changed() || m_tapAndDrag.changed() || m_tapDragLock.changed() || m_leftHanded.changed() || m_disableEventsOnExternalMouse.changed() || m_disableWhileTyping.changed() || m_middleEmulation.changed() || m_pointerAcceleration.changed() || m_pointerAccelerationProfileFlat.changed() || m_pointerAccelerationProfileAdaptive.changed() || m_naturalScroll.changed() || m_horizontalScrolling.changed() || m_isScrollTwoFinger.changed() || m_isScrollEdge.changed() || m_isScrollOnButtonDown.changed() || m_scrollButton.changed() || m_clickMethodAreas.changed() || m_clickMethodClickfinger.changed(); // clang-format on return changed; } int LibinputTouchpad::touchpadOff() { return m_enabled.val; } XcbAtom &LibinputTouchpad::touchpadOffAtom() { return *m_atoms[QLatin1String(LIBINPUT_PROP_SENDEVENTS_ENABLED)].data(); } template bool LibinputTouchpad::valueLoader(Prop &prop) { const Parameter *p = findParameter(QString::fromLatin1(prop.name)); if (!p) { // qCCritical(KCM_TOUCHPAD) << "Error on read of " << QString::fromLatin1(prop.name); } QVariant reply = getParameter(p); if (!reply.isValid()) { prop.avail = false; return true; } prop.avail = true; m_config.beginGroup(m_name); const T replyValue = valueLoaderPart(reply); const T loadedValue = m_config.value(prop.name, replyValue).toBool(); prop.old = replyValue; prop.val = loadedValue; m_config.endGroup(); return true; } template QString LibinputTouchpad::valueWriter(const Prop &prop) { const Parameter *p = findParameter(QString::fromLatin1(prop.name)); // Reion if (!p /*|| !prop.changed()*/) { return QString(); } bool error = !setParameter(p, prop.val); if (error) { // qCCritical(KCM_TOUCHPAD) << "Cannot set property " + QString::fromLatin1(prop.name); return QStringLiteral("Cannot set property ") + QString::fromLatin1(prop.name); } m_config.beginGroup(m_name); m_config.setValue(prop.name, prop.val); m_config.endGroup(); m_config.sync(); return QString(); } core-0.8/settings-daemon/touchpad/x11/libinputtouchpad.h000066400000000000000000000075311417504024300233670ustar00rootroot00000000000000/* SPDX-FileCopyrightText: 2019 Atul Bisht SPDX-License-Identifier: GPL-2.0-or-later */ #ifndef LIBINPUTTOUCHPAD_H #define LIBINPUTTOUCHPAD_H #include "../libinputcommon.h" #include "xlibtouchpad.h" #include class LibinputTouchpad : public LibinputCommon, public XlibTouchpad { Q_OBJECT public: LibinputTouchpad(Display *display, int deviceId); ~LibinputTouchpad() override { } bool getConfig() override; bool applyConfig() override; bool getDefaultConfig() override; bool isChangedConfig() override; int touchpadOff() override; XcbAtom &touchpadOffAtom() override; private: template bool valueLoader(Prop &prop); template QString valueWriter(const Prop &prop); QSettings m_config; // // general QString name() const override { return m_name; } bool supportsDisableEvents() const override { return m_supportsDisableEvents.avail && m_supportsDisableEvents.val; } bool isEnabled() const override { return !m_enabled.val; } void setEnabled(bool set) override { m_enabled.set(!set); } // // Tapping void setLmrTapButtonMap(bool set) override { m_lrmTapButtonMap.set(!set); m_lmrTapButtonMap.set(set); } // // advanced bool supportsLeftHanded() const override { return m_leftHanded.avail; } bool supportsDisableEventsOnExternalMouse() const override { return m_supportsDisableEventsOnExternalMouse.avail && m_supportsDisableEventsOnExternalMouse.val; } bool supportsDisableWhileTyping() const override { return m_disableWhileTyping.avail; } bool supportsMiddleEmulation() const override { return m_middleEmulation.avail; } // // acceleration speed and profile bool supportsPointerAcceleration() const override { return m_pointerAcceleration.avail; } bool supportsPointerAccelerationProfileFlat() const override { return m_supportsPointerAccelerationProfileFlat.avail && m_supportsPointerAccelerationProfileFlat.val; } bool supportsPointerAccelerationProfileAdaptive() const override { return m_supportsPointerAccelerationProfileAdaptive.avail && m_supportsPointerAccelerationProfileAdaptive.val; } // // scrolling bool supportsNaturalScroll() const override { return m_naturalScroll.avail; } bool supportsHorizontalScrolling() const override { return true; } bool supportsScrollTwoFinger() const override { return m_supportsScrollTwoFinger.avail && m_supportsScrollTwoFinger.val; } bool supportsScrollEdge() const override { return m_supportsScrollEdge.avail && m_supportsScrollEdge.val; } bool supportsScrollOnButtonDown() const override { return m_supportsScrollOnButtonDown.avail && m_supportsScrollOnButtonDown.val; } // // click method bool supportsClickMethodAreas() const override { return m_supportsClickMethodAreas.avail && m_supportsClickMethodAreas.val; } bool supportsClickMethodClickfinger() const override { return m_supportsClickMethodClickfinger.avail && m_supportsClickMethodClickfinger.val; } bool supportsScrollFactor() const override { return false; } // Tapping Prop m_lrmTapButtonMapEnabledByDefault = Prop("lrmTapButtonMapEnabledByDefault"); Prop m_lrmTapButtonMap = Prop("lrmTapButtonMap"); // // advanced Prop m_disableEventsOnExternalMouse = Prop("disableEventsOnExternalMouse"); Prop m_disableEventsOnExternalMouseDefault = Prop("disableEventsOnExternalMouseDefault"); QString m_name; }; #endif // LIBINPUTTOUCHPAD_H core-0.8/settings-daemon/touchpad/x11/propertyinfo.cpp000066400000000000000000000034771417504024300231110ustar00rootroot00000000000000/* SPDX-FileCopyrightText: 2013 Alexander Mezin SPDX-License-Identifier: GPL-2.0-or-later */ #include "propertyinfo.h" #include #include #include #include #include void XDeleter(void *p) { if (p) { XFree(p); } } PropertyInfo::PropertyInfo() : type(0) , format(0) , nitems(0) , f(nullptr) , i(nullptr) , b(nullptr) , display(nullptr) , device(0) , prop(0) { } PropertyInfo::PropertyInfo(Display *display, int device, Atom prop, Atom floatType) : type(0) , format(0) , nitems(0) , f(nullptr) , i(nullptr) , b(nullptr) , display(display) , device(device) , prop(prop) { unsigned char *dataPtr = nullptr; unsigned long bytes_after; XIGetProperty(display, device, prop, 0, 1000, False, AnyPropertyType, &type, &format, &nitems, &bytes_after, &dataPtr); data = QSharedPointer(dataPtr, XDeleter); if (format == CHAR_BIT && type == XA_INTEGER) { b = reinterpret_cast(dataPtr); } if (format == sizeof(int) * CHAR_BIT && (type == XA_INTEGER || type == XA_CARDINAL)) { i = reinterpret_cast(dataPtr); } if (format == sizeof(float) * CHAR_BIT && floatType && type == floatType) { f = reinterpret_cast(dataPtr); } } QVariant PropertyInfo::value(unsigned offset) const { QVariant v; if (offset >= nitems) { return v; } if (b) { v = QVariant(static_cast(b[offset])); } if (i) { v = QVariant(i[offset]); } if (f) { v = QVariant(f[offset]); } return v; } void PropertyInfo::set() { XIChangeProperty(display, device, prop, type, format, XIPropModeReplace, data.data(), nitems); } core-0.8/settings-daemon/touchpad/x11/propertyinfo.h000066400000000000000000000012371417504024300225460ustar00rootroot00000000000000/* SPDX-FileCopyrightText: 2013 Alexander Mezin SPDX-License-Identifier: GPL-2.0-or-later */ #ifndef PROPERTYINFO_H #define PROPERTYINFO_H #include #include #include void XDeleter(void *p); struct PropertyInfo { Atom type; int format; QSharedPointer data; unsigned long nitems; float *f; int *i; char *b; Display *display; int device; Atom prop; PropertyInfo(); PropertyInfo(Display *display, int device, Atom prop, Atom floatType); QVariant value(unsigned offset) const; void set(); }; #endif // PROPERTYINFO_H core-0.8/settings-daemon/touchpad/x11/synapticstouchpad.cpp000066400000000000000000000244671417504024300241200ustar00rootroot00000000000000/* SPDX-FileCopyrightText: 2013 Alexander Mezin SPDX-FileContributor: 2002-2005, 2007 Peter Osterlund SPDX-License-Identifier: GPL-2.0-or-later AND LicenseRef-synaptics */ #include #include #include "synapticstouchpad.h" #include #include #include #define SYN_MAX_BUTTONS 12 const struct Parameter synapticsProperties[] = { {"LeftEdge", PT_INT, 0, 10000, SYNAPTICS_PROP_EDGES, 32, 0}, {"RightEdge", PT_INT, 0, 10000, SYNAPTICS_PROP_EDGES, 32, 1}, {"TopEdge", PT_INT, 0, 10000, SYNAPTICS_PROP_EDGES, 32, 2}, {"BottomEdge", PT_INT, 0, 10000, SYNAPTICS_PROP_EDGES, 32, 3}, {"FingerLow", PT_INT, 0, 255, SYNAPTICS_PROP_FINGER, 32, 0}, {"FingerHigh", PT_INT, 0, 255, SYNAPTICS_PROP_FINGER, 32, 1}, {"MaxTapTime", PT_INT, 0, 1000, SYNAPTICS_PROP_TAP_TIME, 32, 0}, {"MaxTapMove", PT_INT, 0, 2000, SYNAPTICS_PROP_TAP_MOVE, 32, 0}, {"MaxDoubleTapTime", PT_INT, 0, 1000, SYNAPTICS_PROP_TAP_DURATIONS, 32, 1}, {"SingleTapTimeout", PT_INT, 0, 1000, SYNAPTICS_PROP_TAP_DURATIONS, 32, 0}, {"ClickTime", PT_INT, 0, 1000, SYNAPTICS_PROP_TAP_DURATIONS, 32, 2}, {"FastTaps", PT_BOOL, 0, 1, SYNAPTICS_PROP_TAP_FAST, 8, 0}, {"EmulateMidButtonTime", PT_INT, 0, 1000, SYNAPTICS_PROP_MIDDLE_TIMEOUT, 32, 0}, {"EmulateTwoFingerMinZ", PT_INT, 0, 1000, SYNAPTICS_PROP_TWOFINGER_PRESSURE, 32, 0}, {"EmulateTwoFingerMinW", PT_INT, 0, 15, SYNAPTICS_PROP_TWOFINGER_WIDTH, 32, 0}, {"VertScrollDelta", PT_INT, -1000, 1000, SYNAPTICS_PROP_SCROLL_DISTANCE, 32, 0}, {"HorizScrollDelta", PT_INT, -1000, 1000, SYNAPTICS_PROP_SCROLL_DISTANCE, 32, 1}, {"VertEdgeScroll", PT_BOOL, 0, 1, SYNAPTICS_PROP_SCROLL_EDGE, 8, 0}, {"HorizEdgeScroll", PT_BOOL, 0, 1, SYNAPTICS_PROP_SCROLL_EDGE, 8, 1}, {"CornerCoasting", PT_BOOL, 0, 1, SYNAPTICS_PROP_SCROLL_EDGE, 8, 2}, {"VertTwoFingerScroll", PT_BOOL, 0, 1, SYNAPTICS_PROP_SCROLL_TWOFINGER, 8, 0}, {"HorizTwoFingerScroll", PT_BOOL, 0, 1, SYNAPTICS_PROP_SCROLL_TWOFINGER, 8, 1}, {"MinSpeed", PT_DOUBLE, 0, 255.0, SYNAPTICS_PROP_SPEED, 0, /*float */ 0}, {"MaxSpeed", PT_DOUBLE, 0, 255.0, SYNAPTICS_PROP_SPEED, 0, /*float */ 1}, {"AccelFactor", PT_DOUBLE, 0, 1.0, SYNAPTICS_PROP_SPEED, 0, /*float */ 2}, /*{"TouchpadOff", PT_INT, 0, 2, SYNAPTICS_PROP_OFF, 8, 0},*/ {"LockedDrags", PT_BOOL, 0, 1, SYNAPTICS_PROP_LOCKED_DRAGS, 8, 0}, {"LockedDragTimeout", PT_INT, 0, 30000, SYNAPTICS_PROP_LOCKED_DRAGS_TIMEOUT, 32, 0}, {"RTCornerButton", PT_INT, 0, SYN_MAX_BUTTONS, SYNAPTICS_PROP_TAP_ACTION, 8, 0}, {"RBCornerButton", PT_INT, 0, SYN_MAX_BUTTONS, SYNAPTICS_PROP_TAP_ACTION, 8, 1}, {"LTCornerButton", PT_INT, 0, SYN_MAX_BUTTONS, SYNAPTICS_PROP_TAP_ACTION, 8, 2}, {"LBCornerButton", PT_INT, 0, SYN_MAX_BUTTONS, SYNAPTICS_PROP_TAP_ACTION, 8, 3}, {"OneFingerTapButton", PT_INT, 0, SYN_MAX_BUTTONS, SYNAPTICS_PROP_TAP_ACTION, 8, 4}, {"TwoFingerTapButton", PT_INT, 0, SYN_MAX_BUTTONS, SYNAPTICS_PROP_TAP_ACTION, 8, 5}, {"ThreeFingerTapButton", PT_INT, 0, SYN_MAX_BUTTONS, SYNAPTICS_PROP_TAP_ACTION, 8, 6}, {"ClickFinger1", PT_INT, 0, SYN_MAX_BUTTONS, SYNAPTICS_PROP_CLICK_ACTION, 8, 0}, {"ClickFinger2", PT_INT, 0, SYN_MAX_BUTTONS, SYNAPTICS_PROP_CLICK_ACTION, 8, 1}, {"ClickFinger3", PT_INT, 0, SYN_MAX_BUTTONS, SYNAPTICS_PROP_CLICK_ACTION, 8, 2}, {"CircularScrolling", PT_BOOL, 0, 1, SYNAPTICS_PROP_CIRCULAR_SCROLLING, 8, 0}, {"CircScrollDelta", PT_DOUBLE, .01, 3, SYNAPTICS_PROP_CIRCULAR_SCROLLING_DIST, 0 /* float */, 0}, {"CircScrollTrigger", PT_INT, 0, 8, SYNAPTICS_PROP_CIRCULAR_SCROLLING_TRIGGER, 8, 0}, {"PalmDetect", PT_BOOL, 0, 1, SYNAPTICS_PROP_PALM_DETECT, 8, 0}, {"PalmMinWidth", PT_INT, 0, 15, SYNAPTICS_PROP_PALM_DIMENSIONS, 32, 0}, {"PalmMinZ", PT_INT, 0, 255, SYNAPTICS_PROP_PALM_DIMENSIONS, 32, 1}, {"CoastingSpeed", PT_DOUBLE, 0, 255, SYNAPTICS_PROP_COASTING_SPEED, 0 /* float*/, 0}, {"CoastingFriction", PT_DOUBLE, 0, 255, SYNAPTICS_PROP_COASTING_SPEED, 0 /* float*/, 1}, {"PressureMotionMinZ", PT_INT, 1, 255, SYNAPTICS_PROP_PRESSURE_MOTION, 32, 0}, {"PressureMotionMaxZ", PT_INT, 1, 255, SYNAPTICS_PROP_PRESSURE_MOTION, 32, 1}, {"PressureMotionMinFactor", PT_DOUBLE, 0, 10.0, SYNAPTICS_PROP_PRESSURE_MOTION_FACTOR, 0 /*float*/, 0}, {"PressureMotionMaxFactor", PT_DOUBLE, 0, 10.0, SYNAPTICS_PROP_PRESSURE_MOTION_FACTOR, 0 /*float*/, 1}, {"GrabEventDevice", PT_BOOL, 0, 1, SYNAPTICS_PROP_GRAB, 8, 0}, {"TapAndDragGesture", PT_BOOL, 0, 1, SYNAPTICS_PROP_GESTURES, 8, 0}, {"AreaLeftEdge", PT_INT, 0, 10000, SYNAPTICS_PROP_AREA, 32, 0}, {"AreaRightEdge", PT_INT, 0, 10000, SYNAPTICS_PROP_AREA, 32, 1}, {"AreaTopEdge", PT_INT, 0, 10000, SYNAPTICS_PROP_AREA, 32, 2}, {"AreaBottomEdge", PT_INT, 0, 10000, SYNAPTICS_PROP_AREA, 32, 3}, {"HorizHysteresis", PT_INT, 0, 10000, SYNAPTICS_PROP_NOISE_CANCELLATION, 32, 0}, {"VertHysteresis", PT_INT, 0, 10000, SYNAPTICS_PROP_NOISE_CANCELLATION, 32, 1}, {"ClickPad", PT_BOOL, 0, 1, SYNAPTICS_PROP_CLICKPAD, 8, 0}, {"RightButtonAreaLeft", PT_INT, INT_MIN, INT_MAX, SYNAPTICS_PROP_SOFTBUTTON_AREAS, 32, 0}, {"RightButtonAreaRight", PT_INT, INT_MIN, INT_MAX, SYNAPTICS_PROP_SOFTBUTTON_AREAS, 32, 1}, {"RightButtonAreaTop", PT_INT, INT_MIN, INT_MAX, SYNAPTICS_PROP_SOFTBUTTON_AREAS, 32, 2}, {"RightButtonAreaBottom", PT_INT, INT_MIN, INT_MAX, SYNAPTICS_PROP_SOFTBUTTON_AREAS, 32, 3}, {"MiddleButtonAreaLeft", PT_INT, INT_MIN, INT_MAX, SYNAPTICS_PROP_SOFTBUTTON_AREAS, 32, 4}, {"MiddleButtonAreaRight", PT_INT, INT_MIN, INT_MAX, SYNAPTICS_PROP_SOFTBUTTON_AREAS, 32, 5}, {"MiddleButtonAreaTop", PT_INT, INT_MIN, INT_MAX, SYNAPTICS_PROP_SOFTBUTTON_AREAS, 32, 6}, {"MiddleButtonAreaBottom", PT_INT, INT_MIN, INT_MAX, SYNAPTICS_PROP_SOFTBUTTON_AREAS, 32, 7}, {NULL, PT_INT, 0, 0, nullptr, 0, 0}, }; SynapticsTouchpad::SynapticsTouchpad(Display *display, int deviceId) : XlibTouchpad(display, deviceId) , m_resX(1) , m_resY(1) { m_capsAtom.intern(m_connection, SYNAPTICS_PROP_CAPABILITIES); m_touchpadOffAtom.intern(m_connection, SYNAPTICS_PROP_OFF); XcbAtom resolutionAtom(m_connection, SYNAPTICS_PROP_RESOLUTION); XcbAtom edgesAtom(m_connection, SYNAPTICS_PROP_EDGES); loadSupportedProperties(synapticsProperties); m_toRadians.append("CircScrollDelta"); PropertyInfo edges(m_display, m_deviceId, edgesAtom, 0); if (edges.i && edges.nitems == 4) { int w = qAbs(edges.i[1] - edges.i[0]); int h = qAbs(edges.i[3] - edges.i[2]); m_resX = w / 90; m_resY = h / 50; qDebug() << "Width: " << w << " height: " << h; qDebug() << "Approx. resX: " << m_resX << " resY: " << m_resY; } PropertyInfo resolution(m_display, m_deviceId, resolutionAtom, 0); if (resolution.i && resolution.nitems == 2 && resolution.i[0] > 1 && resolution.i[1] > 1) { m_resY = qMin(static_cast(resolution.i[0]), static_cast(INT_MAX)); m_resX = qMin(static_cast(resolution.i[1]), static_cast(INT_MAX)); qDebug() << "Touchpad resolution: x: " << m_resX << " y: " << m_resY; } m_scaleByResX.append("HorizScrollDelta"); m_scaleByResY.append("VertScrollDelta"); m_scaleByResX.append("MaxTapMove"); m_scaleByResY.append("MaxTapMove"); m_resX = qMax(10, m_resX); m_resY = qMax(10, m_resY); qDebug() << "Final resolution x:" << m_resX << " y:" << m_resY; m_negate["HorizScrollDelta"] = "InvertHorizScroll"; m_negate["VertScrollDelta"] = "InvertVertScroll"; m_supported.append(m_negate.values()); m_supported.append("Coasting"); PropertyInfo caps(m_display, m_deviceId, m_capsAtom.atom(), 0); if (!caps.b) { return; } enum TouchpadCapabilitiy { TouchpadHasLeftButton, TouchpadHasMiddleButton, TouchpadHasRightButton, TouchpadTwoFingerDetect, TouchpadThreeFingerDetect, TouchpadPressureDetect, TouchpadPalmDetect, TouchpadCapsCount, }; QVector cap(TouchpadCapsCount, false); std::copy(caps.b, caps.b + qMin(cap.size(), static_cast(caps.nitems)), cap.begin()); if (!cap[TouchpadTwoFingerDetect]) { m_supported.removeAll("HorizTwoFingerScroll"); m_supported.removeAll("VertTwoFingerScroll"); m_supported.removeAll("TwoFingerTapButton"); } if (!cap[TouchpadThreeFingerDetect]) { m_supported.removeAll("ThreeFingerTapButton"); } if (!cap[TouchpadPressureDetect]) { m_supported.removeAll("FingerHigh"); m_supported.removeAll("FingerLow"); m_supported.removeAll("PalmMinZ"); m_supported.removeAll("PressureMotionMinZ"); m_supported.removeAll("PressureMotionMinFactor"); m_supported.removeAll("PressureMotionMaxZ"); m_supported.removeAll("PressureMotionMaxFactor"); m_supported.removeAll("EmulateTwoFingerMinZ"); } if (!cap[TouchpadPalmDetect]) { m_supported.removeAll("PalmDetect"); m_supported.removeAll("PalmMinWidth"); m_supported.removeAll("PalmMinZ"); m_supported.removeAll("EmulateTwoFingerMinW"); } for (QMap::Iterator i = m_negate.begin(); i != m_negate.end(); ++i) { if (!m_supported.contains(i.key())) { m_supported.removeAll(i.value()); } } m_paramList = synapticsProperties; } void SynapticsTouchpad::setTouchpadOff(int touchpadOff) { PropertyInfo off(m_display, m_deviceId, m_touchpadOffAtom.atom(), 0); if (off.b && *(off.b) != touchpadOff) { *(off.b) = touchpadOff; off.set(); } flush(); } int SynapticsTouchpad::touchpadOff() { PropertyInfo off(m_display, m_deviceId, m_touchpadOffAtom.atom(), 0); return off.value(0).toInt(); } XcbAtom &SynapticsTouchpad::touchpadOffAtom() { return m_touchpadOffAtom; } double SynapticsTouchpad::getPropertyScale(const QString &name) const { if (m_scaleByResX.contains(name) && m_scaleByResY.contains(name)) { return std::sqrt(static_cast(m_resX) * m_resX + static_cast(m_resY) * m_resY); } else if (m_scaleByResX.contains(name)) { return m_resX; } else if (m_scaleByResY.contains(name)) { return m_resY; } else if (m_toRadians.contains(name)) { return M_PI_4 / 45.0; } return 1.0; } core-0.8/settings-daemon/touchpad/x11/synapticstouchpad.h000066400000000000000000000013421417504024300235500ustar00rootroot00000000000000/* SPDX-FileCopyrightText: 2015 Weng Xuetian SPDX-License-Identifier: GPL-2.0-or-later */ #ifndef SYNAPTICSTOUCHPAD_H #define SYNAPTICSTOUCHPAD_H #include "xcbatom.h" #include "xlibtouchpad.h" class SynapticsTouchpad : public QObject, public XlibTouchpad { Q_OBJECT public: SynapticsTouchpad(Display *display, int deviceId); void setTouchpadOff(int touchpadOff) override; int touchpadOff() override; XcbAtom &touchpadOffAtom() override; protected: double getPropertyScale(const QString &name) const override; private: XcbAtom m_capsAtom, m_touchpadOffAtom; int m_resX, m_resY; QStringList m_scaleByResX, m_scaleByResY, m_toRadians; }; #endif // SYNAPTICSTOUCHPAD_H core-0.8/settings-daemon/touchpad/x11/xcbatom.cpp000066400000000000000000000016351417504024300220000ustar00rootroot00000000000000/* SPDX-FileCopyrightText: 2013 Alexander Mezin SPDX-License-Identifier: GPL-2.0-or-later */ #include "xcbatom.h" #include #include XcbAtom::XcbAtom() : m_connection(nullptr) , m_reply(nullptr) , m_fetched(false) { } XcbAtom::XcbAtom(xcb_connection_t *c, const char *name, bool onlyIfExists) : m_reply(nullptr) , m_fetched(false) { intern(c, name, onlyIfExists); } void XcbAtom::intern(xcb_connection_t *c, const char *name, bool onlyIfExists) { m_connection = c; m_cookie = xcb_intern_atom(c, onlyIfExists, std::strlen(name), name); } XcbAtom::~XcbAtom() { std::free(m_reply); } xcb_atom_t XcbAtom::atom() { if (!m_fetched) { m_fetched = true; m_reply = xcb_intern_atom_reply(m_connection, m_cookie, nullptr); } if (m_reply) { return m_reply->atom; } else { return 0; } } core-0.8/settings-daemon/touchpad/x11/xcbatom.h000066400000000000000000000013271417504024300214430ustar00rootroot00000000000000/* SPDX-FileCopyrightText: 2013 Alexander Mezin SPDX-License-Identifier: GPL-2.0-or-later */ #ifndef XCBATOM_H #define XCBATOM_H #include class XcbAtom { public: XcbAtom(); XcbAtom(xcb_connection_t *, const char *name, bool onlyIfExists = true); ~XcbAtom(); void intern(xcb_connection_t *, const char *name, bool onlyIfExists = true); xcb_atom_t atom(); operator xcb_atom_t() { return atom(); } private: XcbAtom(const XcbAtom &); XcbAtom &operator=(const XcbAtom &); xcb_connection_t *m_connection; xcb_intern_atom_cookie_t m_cookie; xcb_intern_atom_reply_t *m_reply; bool m_fetched; }; #endif // XCBATOM_H core-0.8/settings-daemon/touchpad/x11/xlibbackend.cpp000066400000000000000000000244531417504024300226140ustar00rootroot00000000000000/* SPDX-FileCopyrightText: 2013 Alexander Mezin SPDX-License-Identifier: GPL-2.0-or-later */ #include #include #include #include // Includes are ordered this way because of #defines in Xorg's headers #include "xlibbackend.h" // krazy:exclude=includes #include "xlibnotifications.h" // krazy:exclude=includes #include "xrecordkeyboardmonitor.h" // krazy:exclude=includes #include #include #include #include #include #include struct DeviceListDeleter { static void cleanup(XDeviceInfo *p) { if (p) { XFreeDeviceList(p); } } }; void XlibBackend::XDisplayCleanup::cleanup(Display *p) { if (p) { XCloseDisplay(p); } } XlibBackend *XlibBackend::initialize(QObject *parent) { XlibBackend *backend = new XlibBackend(parent); if (!backend->m_display) { delete backend; return nullptr; } return backend; } XlibBackend::~XlibBackend() { } XlibBackend::XlibBackend(QObject *parent) : QObject(parent) , m_display(XOpenDisplay(nullptr)) , m_connection(nullptr) { if (m_display) { m_connection = XGetXCBConnection(m_display.data()); } if (!m_connection) { m_errorString = "Cannot connect to X server"; return; } m_mouseAtom.intern(m_connection, XI_MOUSE); m_keyboardAtom.intern(m_connection, XI_KEYBOARD); m_touchpadAtom.intern(m_connection, XI_TOUCHPAD); m_enabledAtom.intern(m_connection, XI_PROP_ENABLED); m_synapticsIdentifierAtom.intern(m_connection, SYNAPTICS_PROP_CAPABILITIES); m_libinputIdentifierAtom.intern(m_connection, "libinput Send Events Modes Available"); m_device.reset(findTouchpad()); if (!m_device) { m_errorString = "No touchpad found"; } } XlibTouchpad *XlibBackend::findTouchpad() { int nDevices = 0; QScopedPointer deviceInfo(XListInputDevices(m_display.data(), &nDevices)); for (XDeviceInfo *info = deviceInfo.data(); info < deviceInfo.data() + nDevices; info++) { // Make sure device is touchpad if (info->type != m_touchpadAtom.atom()) { continue; } int nProperties = 0; QSharedPointer properties(XIListProperties(m_display.data(), info->id, &nProperties), XDeleter); Atom *atom = properties.data(), *atomEnd = properties.data() + nProperties; for (; atom != atomEnd; atom++) { if (*atom == m_libinputIdentifierAtom.atom()) { // setMode(TouchpadInputBackendMode::XLibinput); return new LibinputTouchpad(m_display.data(), info->id); } if (*atom == m_synapticsIdentifierAtom.atom()) { // setMode(TouchpadInputBackendMode::XSynaptics); return new SynapticsTouchpad(m_display.data(), info->id); } } } return nullptr; } bool XlibBackend::applyConfig(const QVariantHash &p) { if (!m_device) { return false; } bool success = m_device->applyConfig(p); if (!success) { m_errorString = "Cannot apply touchpad configuration"; } return success; } bool XlibBackend::applyConfig() { if (!m_device) { return false; } bool success = m_device->applyConfig(); if (!success) { m_errorString = "Cannot apply touchpad configuration"; } return success; } bool XlibBackend::getConfig(QVariantHash &p) { if (!m_device) { return false; } bool success = m_device->getConfig(p); if (!success) { m_errorString = "Cannot read touchpad configuration"; } return success; } bool XlibBackend::getConfig() { if (!m_device) { return false; } bool success = m_device->getConfig(); if (!success) { m_errorString = "Cannot read touchpad configuration"; } return success; } bool XlibBackend::getDefaultConfig() { if (!m_device) { return false; } bool success = m_device->getDefaultConfig(); if (!success) { m_errorString = "Cannot read default touchpad configuration"; } return success; } bool XlibBackend::isChangedConfig() const { if (!m_device) { return false; } return m_device->isChangedConfig(); } void XlibBackend::setTouchpadEnabled(bool enable) { if (!m_device) { return; } m_device->setEnabled(enable); // FIXME? This should not be needed, m_notifications should trigger // a propertyChanged signal when we enable/disable the touchpad, // that will Q_EMIT touchpadStateChanged, but for some reason // XlibNotifications is not getting the property change events // so we just Q_EMIT touchpadStateChanged from here as a workaround Q_EMIT touchpadStateChanged(); } bool XlibBackend::tapToClick() { LibinputTouchpad *object = dynamic_cast(m_device.data()); if (!object) return false; return object->isTapToClick(); } void XlibBackend::setTapToClick(bool enabled) { LibinputTouchpad *object = dynamic_cast(m_device.data()); if (!object) return; object->setTapToClick(enabled); } bool XlibBackend::naturalScroll() { LibinputTouchpad *object = dynamic_cast(m_device.data()); if (!object) return false; return object->isNaturalScroll(); } void XlibBackend::setNaturalScroll(bool value) { LibinputTouchpad *object = dynamic_cast(m_device.data()); if (!object) return; object->setNaturalScroll(value); } qreal XlibBackend::pointerAcceleration() { LibinputTouchpad *object = dynamic_cast(m_device.data()); if (!object) return 1; return object->pointerAcceleration(); } void XlibBackend::setPointerAcceleration(qreal value) { LibinputTouchpad *object = dynamic_cast(m_device.data()); if (!object) return; object->setPointerAcceleration(value); } void XlibBackend::setTouchpadOff(XlibBackend::TouchpadOffState state) { if (!m_device) { return; } int touchpadOff = 0; switch (state) { case TouchpadEnabled: touchpadOff = 0; break; case TouchpadFullyDisabled: touchpadOff = 1; break; case TouchpadTapAndScrollDisabled: touchpadOff = 2; break; default: qCritical() << "Unknown TouchpadOffState" << state; return; } m_device->setTouchpadOff(touchpadOff); } bool XlibBackend::isTouchpadAvailable() { return m_device; } bool XlibBackend::isTouchpadEnabled() { if (!m_device) { return false; } return m_device->enabled(); } XlibBackend::TouchpadOffState XlibBackend::getTouchpadOff() { if (!m_device) { return TouchpadFullyDisabled; } int value = m_device->touchpadOff(); switch (value) { case 0: return TouchpadEnabled; case 1: return TouchpadFullyDisabled; case 2: return TouchpadTapAndScrollDisabled; default: qCritical() << "Unknown TouchpadOff value" << value; return TouchpadFullyDisabled; } } void XlibBackend::touchpadDetached() { qWarning() << "Touchpad detached"; m_device.reset(); Q_EMIT touchpadReset(); } void XlibBackend::devicePlugged(int device) { if (!m_device) { m_device.reset(findTouchpad()); if (m_device) { qWarning() << "Touchpad reset"; m_notifications.reset(); watchForEvents(m_keyboard); Q_EMIT touchpadReset(); } } if (!m_device || device != m_device->deviceId()) { Q_EMIT mousesChanged(); } } void XlibBackend::propertyChanged(xcb_atom_t prop) { if ((m_device && prop == m_device->touchpadOffAtom().atom()) || prop == m_enabledAtom.atom()) { Q_EMIT touchpadStateChanged(); } } QStringList XlibBackend::listMouses(const QStringList &blacklist) { int nDevices = 0; QScopedPointer info(XListInputDevices(m_display.data(), &nDevices)); QStringList list; for (XDeviceInfo *i = info.data(); i != info.data() + nDevices; i++) { if (m_device && i->id == static_cast(m_device->deviceId())) { continue; } if (i->use != IsXExtensionPointer && i->use != IsXPointer) { continue; } // type = KEYBOARD && use = Pointer means usb receiver for both keyboard // and mouse if (i->type != m_mouseAtom.atom() && i->type != m_keyboardAtom.atom()) { continue; } QString name(i->name); if (blacklist.contains(name, Qt::CaseInsensitive)) { continue; } PropertyInfo enabled(m_display.data(), i->id, m_enabledAtom.atom(), 0); if (enabled.value(0) == false) { continue; } list.append(name); } return list; } QVector XlibBackend::getDevices() const { QVector touchpads; LibinputTouchpad *libinputtouchpad = dynamic_cast(m_device.data()); if (libinputtouchpad) { touchpads.push_back(libinputtouchpad); } SynapticsTouchpad *synaptics = dynamic_cast(m_device.data()); if (synaptics) { touchpads.push_back(synaptics); } return touchpads; } void XlibBackend::watchForEvents(bool keyboard) { if (!m_notifications) { m_notifications.reset(new XlibNotifications(m_display.data(), m_device ? m_device->deviceId() : XIAllDevices)); connect(m_notifications.data(), SIGNAL(devicePlugged(int)), SLOT(devicePlugged(int))); connect(m_notifications.data(), SIGNAL(touchpadDetached()), SLOT(touchpadDetached())); connect(m_notifications.data(), SIGNAL(propertyChanged(xcb_atom_t)), SLOT(propertyChanged(xcb_atom_t))); } if (keyboard == !m_keyboard.isNull()) { return; } if (!keyboard) { m_keyboard.reset(); return; } m_keyboard.reset(new XRecordKeyboardMonitor(m_display.data())); connect(m_keyboard.data(), SIGNAL(keyboardActivityStarted()), SIGNAL(keyboardActivityStarted())); connect(m_keyboard.data(), SIGNAL(keyboardActivityFinished()), SIGNAL(keyboardActivityFinished())); } core-0.8/settings-daemon/touchpad/x11/xlibbackend.h000066400000000000000000000054751417504024300222640ustar00rootroot00000000000000/* SPDX-FileCopyrightText: 2013 Alexander Mezin SPDX-License-Identifier: GPL-2.0-or-later */ #ifndef XLIBBACKEND_H #define XLIBBACKEND_H #include #include #include #include #include #include #include #include "libinputtouchpad.h" #include "synapticstouchpad.h" #include "xlibtouchpad.h" #include #include "propertyinfo.h" #include "xcbatom.h" class XlibTouchpad; class XlibNotifications; class XRecordKeyboardMonitor; class XlibBackend : public QObject { Q_OBJECT Q_PROPERTY(int touchpadCount READ touchpadCount CONSTANT) public: enum TouchpadOffState { TouchpadEnabled, TouchpadTapAndScrollDisabled, TouchpadFullyDisabled, }; static XlibBackend *initialize(QObject *parent = nullptr); ~XlibBackend(); bool applyConfig(const QVariantHash &); bool applyConfig(); bool getConfig(QVariantHash &); bool getConfig(); bool getDefaultConfig(); bool isChangedConfig() const; QStringList supportedParameters() const { return m_device ? m_device->supportedParameters() : QStringList(); } QString errorString() const { return m_errorString; } int touchpadCount() const { return m_device ? 1 : 0; } void setTouchpadOff(TouchpadOffState); TouchpadOffState getTouchpadOff(); bool isTouchpadAvailable(); bool isTouchpadEnabled(); void setTouchpadEnabled(bool); bool tapToClick(); void setTapToClick(bool enabled); bool naturalScroll(); void setNaturalScroll(bool value); qreal pointerAcceleration(); void setPointerAcceleration(qreal value); void watchForEvents(bool keyboard); QStringList listMouses(const QStringList &blacklist); QVector getDevices() const; signals: void touchpadStateChanged(); void mousesChanged(); void touchpadReset(); void keyboardActivityStarted(); void keyboardActivityFinished(); void touchpadAdded(bool success); void touchpadRemoved(int index); private Q_SLOTS: void propertyChanged(xcb_atom_t); void touchpadDetached(); void devicePlugged(int); protected: explicit XlibBackend(QObject *parent); struct XDisplayCleanup { static void cleanup(Display *); }; QScopedPointer m_display; xcb_connection_t *m_connection; XcbAtom m_enabledAtom, m_mouseAtom, m_keyboardAtom, m_touchpadAtom; XcbAtom m_synapticsIdentifierAtom; XcbAtom m_libinputIdentifierAtom; XlibTouchpad *findTouchpad(); QScopedPointer m_device; QString m_errorString; QScopedPointer m_notifications; QScopedPointer m_keyboard; }; #endif // XLIBBACKEND_H core-0.8/settings-daemon/touchpad/x11/xlibnotifications.cpp000066400000000000000000000100601417504024300240630ustar00rootroot00000000000000/* SPDX-FileCopyrightText: 2013 Alexander Mezin SPDX-License-Identifier: GPL-2.0-or-later */ #include "xlibnotifications.h" #include #include #include #include #include XlibNotifications::XlibNotifications(Display *display, int device) : m_display(display) , m_device(device) { m_connection = XGetXCBConnection(display); m_notifier = new QSocketNotifier(xcb_get_file_descriptor(m_connection), QSocketNotifier::Read, this); xcb_query_extension_cookie_t inputExtCookie = xcb_query_extension(m_connection, std::strlen(INAME), INAME); QScopedPointer inputExt(xcb_query_extension_reply(m_connection, inputExtCookie, nullptr)); if (!inputExt) { return; } m_inputOpcode = inputExt->major_opcode; const xcb_setup_t *setup = xcb_get_setup(m_connection); xcb_screen_iterator_t iter = xcb_setup_roots_iterator(setup); xcb_screen_t *screen = iter.data; m_inputWindow = xcb_generate_id(m_connection); xcb_create_window(m_connection, 0, m_inputWindow, screen->root, 0, 0, 1, 1, 0, XCB_WINDOW_CLASS_INPUT_ONLY, 0, 0, nullptr); xcb_flush(m_connection); XIEventMask masks[2]; unsigned char touchpadMask[] = {0, 0, 0, 0}; masks[0].deviceid = device; masks[0].mask = touchpadMask; masks[0].mask_len = sizeof(touchpadMask); XISetMask(touchpadMask, XI_PropertyEvent); unsigned char allMask[] = {0, 0, 0, 0}; masks[1].deviceid = XIAllDevices; masks[1].mask = allMask; masks[1].mask_len = sizeof(allMask); XISetMask(allMask, XI_HierarchyChanged); XISelectEvents(display, XDefaultRootWindow(display), masks, sizeof(masks) / sizeof(XIEventMask)); XFlush(display); connect(m_notifier, SIGNAL(activated(int)), SLOT(processEvents())); m_notifier->setEnabled(true); } void XlibNotifications::processEvents() { while (XPending(m_display)) { XEvent event; XNextEvent(m_display, &event); processEvent(&event); } } struct XEventDataDeleter { XEventDataDeleter(Display *display, XGenericEventCookie *cookie) : m_display(display) , m_cookie(cookie) { XGetEventData(m_display, m_cookie); } ~XEventDataDeleter() { if (m_cookie->data) { XFreeEventData(m_display, m_cookie); } } Display *m_display; XGenericEventCookie *m_cookie; }; void XlibNotifications::processEvent(XEvent *event) { if (event->xcookie.type != GenericEvent) { return; } if (event->xcookie.extension != m_inputOpcode) { return; } if (event->xcookie.evtype == XI_PropertyEvent) { XEventDataDeleter helper(m_display, &event->xcookie); if (!event->xcookie.data) { return; } XIPropertyEvent *propEvent = reinterpret_cast(event->xcookie.data); Q_EMIT propertyChanged(propEvent->property); } else if (event->xcookie.evtype == XI_HierarchyChanged) { XEventDataDeleter helper(m_display, &event->xcookie); if (!event->xcookie.data) { return; } XIHierarchyEvent *hierarchyEvent = reinterpret_cast(event->xcookie.data); for (uint16_t i = 0; i < hierarchyEvent->num_info; i++) { if (hierarchyEvent->info[i].deviceid == m_device) { if (hierarchyEvent->info[i].flags & XISlaveRemoved) { Q_EMIT touchpadDetached(); return; } } if (hierarchyEvent->info[i].use != XISlavePointer) { continue; } if (hierarchyEvent->info[i].flags & (XIDeviceEnabled | XIDeviceDisabled)) { Q_EMIT devicePlugged(hierarchyEvent->info[i].deviceid); } } } } XlibNotifications::~XlibNotifications() { xcb_destroy_window(m_connection, m_inputWindow); xcb_flush(m_connection); } #include "moc_xlibnotifications.cpp" core-0.8/settings-daemon/touchpad/x11/xlibnotifications.h000066400000000000000000000014671417504024300235430ustar00rootroot00000000000000/* SPDX-FileCopyrightText: 2013 Alexander Mezin SPDX-License-Identifier: GPL-2.0-or-later */ #ifndef XLIBNOTIFICATIONS_H #define XLIBNOTIFICATIONS_H #include #include #include #include class XlibNotifications : public QObject { Q_OBJECT public: XlibNotifications(Display *display, int device); ~XlibNotifications(); Q_SIGNALS: void propertyChanged(xcb_atom_t); void devicePlugged(int); void touchpadDetached(); private Q_SLOTS: void processEvents(); private: void processEvent(XEvent *); Display *m_display; xcb_connection_t *m_connection; QSocketNotifier *m_notifier; xcb_window_t m_inputWindow; uint8_t m_inputOpcode; int m_device; }; #endif // XLIBNOTIFICATIONS_H core-0.8/settings-daemon/touchpad/x11/xlibtouchpad.cpp000066400000000000000000000144421417504024300230310ustar00rootroot00000000000000#include #include "xlibtouchpad.h" #include #include #include #include static QVariant negateVariant(const QVariant &value) { if (value.type() == QVariant::Double) { return QVariant(-value.toDouble()); } else if (value.type() == QVariant::Int) { return QVariant(-value.toInt()); } return value; } XlibTouchpad::XlibTouchpad(Display *display, int deviceId) : m_display(display) , m_connection(XGetXCBConnection(display)) , m_deviceId(deviceId) { m_floatType.intern(m_connection, "FLOAT"); m_enabledAtom.intern(m_connection, XI_PROP_ENABLED); } bool XlibTouchpad::applyConfig(const QVariantHash &p) { m_props.clear(); bool error = false; for (const QString &name : qAsConst(m_supported)) { QVariantHash::ConstIterator i = p.find(name); if (i == p.end()) { continue; } const Parameter *par = findParameter(name); if (par) { QVariant value(i.value()); double k = getPropertyScale(name); if (k != 1.0) { bool ok = false; value = QVariant(value.toDouble(&ok) * k); if (!ok) { error = true; continue; } } if (m_negate.contains(name)) { QVariantHash::ConstIterator i = p.find(m_negate[name]); if (i != p.end() && i.value().toBool()) { value = negateVariant(value); } } if (name == "CoastingSpeed") { QVariantHash::ConstIterator coastingEnabled = p.find("Coasting"); if (coastingEnabled != p.end() && !coastingEnabled.value().toBool()) { value = QVariant(0); } } if (!setParameter(par, value)) { error = true; } } } flush(); return !error; } bool XlibTouchpad::getConfig(QVariantHash &p) { if (m_supported.isEmpty()) { return false; } m_props.clear(); bool error = false; for (const QString &name : qAsConst(m_supported)) { const Parameter *par = findParameter(name); if (!par) { continue; } QVariant value(getParameter(par)); if (!value.isValid()) { error = true; continue; } double k = getPropertyScale(name); if (k != 1.0) { bool ok = false; value = QVariant(value.toDouble(&ok) / k); if (!ok) { error = true; continue; } } if (m_negate.contains(name)) { bool negative = value.toDouble() < 0.0; p[m_negate[name]] = QVariant(negative); if (negative) { value = negateVariant(value); } } if (name == "CoastingSpeed") { bool coasting = value.toDouble() != 0.0; p["Coasting"] = QVariant(coasting); if (!coasting) { continue; } } p[name] = value; } return !error; } void XlibTouchpad::loadSupportedProperties(const Parameter *props) { m_paramList = props; for (const Parameter *param = props; param->name; param++) { QLatin1String name(param->prop_name); if (!m_atoms.contains(name)) { m_atoms.insert(name, QSharedPointer(new XcbAtom(m_connection, param->prop_name))); } } for (const Parameter *p = props; p->name; p++) { if (getParameter(p).isValid()) { m_supported.append(p->name); } } } QVariant XlibTouchpad::getParameter(const Parameter *par) { PropertyInfo *p = getDevProperty(QLatin1String(par->prop_name)); if (!p || par->prop_offset >= p->nitems) { return QVariant(); } return p->value(par->prop_offset); } void XlibTouchpad::flush() { for (const QLatin1String &name : qAsConst(m_changed)) { m_props[name].set(); } m_changed.clear(); XFlush(m_display); } double XlibTouchpad::getPropertyScale(const QString &name) const { Q_UNUSED(name); return 1.0; } PropertyInfo *XlibTouchpad::getDevProperty(const QLatin1String &propName) { if (m_props.contains(propName)) { return &m_props[propName]; } if (!m_atoms.contains(propName) || !m_atoms[propName]) { return nullptr; } xcb_atom_t prop = m_atoms[propName]->atom(); if (!prop) { return nullptr; } PropertyInfo p(m_display, m_deviceId, prop, m_floatType.atom()); if (!p.b && !p.f && !p.i) { return nullptr; } return &m_props.insert(propName, p).value(); } bool XlibTouchpad::setParameter(const Parameter *par, const QVariant &value) { QLatin1String propName(par->prop_name); PropertyInfo *p = getDevProperty(propName); if (!p || par->prop_offset >= p->nitems) { return false; } QVariant converted(value); QVariant::Type convType = QVariant::Int; if (p->f) { convType = QVariant::Double; } else if (value.type() == QVariant::Double) { converted = QVariant(qRound(static_cast(value.toDouble()))); } if (!converted.convert(convType)) { return false; } if (converted == p->value(par->prop_offset)) { return true; } if (p->b) { p->b[par->prop_offset] = static_cast(converted.toInt()); } else if (p->i) { p->i[par->prop_offset] = converted.toInt(); } else if (p->f) { p->f[par->prop_offset] = converted.toDouble(); } m_changed.insert(propName); return true; } void XlibTouchpad::setEnabled(bool enable) { PropertyInfo enabled(m_display, m_deviceId, m_enabledAtom.atom(), 0); if (enabled.b && *(enabled.b) != enable) { *(enabled.b) = enable; enabled.set(); } flush(); } bool XlibTouchpad::enabled() { PropertyInfo enabled(m_display, m_deviceId, m_enabledAtom.atom(), 0); return enabled.value(0).toBool(); } const Parameter *XlibTouchpad::findParameter(const QString &name) { for (const Parameter *par = m_paramList; par->name; par++) { if (name == par->name) { return par; } } return nullptr; } core-0.8/settings-daemon/touchpad/x11/xlibtouchpad.h000066400000000000000000000044371417504024300225010ustar00rootroot00000000000000/* SPDX-FileCopyrightText: 2015 Weng Xuetian SPDX-License-Identifier: GPL-2.0-or-later */ #ifndef XLIBTOUCHPAD_H #define XLIBTOUCHPAD_H #include #include #include #include "propertyinfo.h" #include "xcbatom.h" #include enum ParaType { PT_INT, PT_BOOL, PT_DOUBLE, }; struct Parameter { const char *name; /* Name of parameter */ enum ParaType type; /* Type of parameter */ double min_val; /* Minimum allowed value */ double max_val; /* Maximum allowed value */ const char *prop_name; /* Property name */ int prop_format; /* Property format (0 for floats) */ unsigned prop_offset; /* Offset inside property */ }; class XlibTouchpad { public: XlibTouchpad(Display *display, int deviceId); virtual ~XlibTouchpad() { } int deviceId() { return m_deviceId; } const QStringList &supportedParameters() const { return m_supported; } bool applyConfig(const QVariantHash &p); bool getConfig(QVariantHash &p); virtual bool getConfig() { return false; } virtual bool applyConfig() { return false; } virtual bool getDefaultConfig() { return false; } virtual bool isChangedConfig() { return false; } void setEnabled(bool enable); bool enabled(); virtual void setTouchpadOff(int /*touchpadOff*/) { } virtual int touchpadOff() = 0; virtual XcbAtom &touchpadOffAtom() = 0; protected: void loadSupportedProperties(const Parameter *props); bool setParameter(const struct Parameter *, const QVariant &); QVariant getParameter(const struct Parameter *); struct PropertyInfo *getDevProperty(const QLatin1String &propName); void flush(); virtual double getPropertyScale(const QString &name) const; const Parameter *findParameter(const QString &name); Display *m_display; xcb_connection_t *m_connection; int m_deviceId; XcbAtom m_floatType, m_enabledAtom; QMap> m_atoms; QMap m_negate; QMap m_props; QSet m_changed; QStringList m_supported; const struct Parameter *m_paramList; }; #endif core-0.8/settings-daemon/touchpad/x11/xrecordkeyboardmonitor.cpp000066400000000000000000000106751417504024300251460ustar00rootroot00000000000000/* SPDX-FileCopyrightText: 2013 Alexander Mezin SPDX-License-Identifier: GPL-2.0-or-later */ #include "xrecordkeyboardmonitor.h" #include #include #include #include #include XRecordKeyboardMonitor::XRecordKeyboardMonitor(Display *display) : m_connection(xcb_connect(XDisplayString(display), nullptr)) , m_modifiersPressed(0) , m_keysPressed(0) { if (!m_connection) { return; } xcb_get_modifier_mapping_cookie_t modmapCookie = xcb_get_modifier_mapping(m_connection); m_context = xcb_generate_id(m_connection); xcb_record_range_t range; memset(&range, 0, sizeof(range)); range.device_events.first = XCB_KEY_PRESS; range.device_events.last = XCB_KEY_RELEASE; xcb_record_client_spec_t cs = XCB_RECORD_CS_ALL_CLIENTS; xcb_record_create_context(m_connection, m_context, 0, 1, 1, &cs, &range); xcb_flush(m_connection); QScopedPointer modmap(xcb_get_modifier_mapping_reply(m_connection, modmapCookie, nullptr)); if (!modmap) { return; } int nModifiers = xcb_get_modifier_mapping_keycodes_length(modmap.data()); xcb_keycode_t *modifiers = xcb_get_modifier_mapping_keycodes(modmap.data()); m_modifier.fill(false, std::numeric_limits::max() + 1); for (xcb_keycode_t *i = modifiers; i < modifiers + nModifiers; i++) { m_modifier[*i] = true; } m_ignore.fill(false, std::numeric_limits::max() + 1); for (xcb_keycode_t *i = modifiers; i < modifiers + modmap->keycodes_per_modifier; i++) { m_ignore[*i] = true; } m_pressed.fill(false, std::numeric_limits::max() + 1); m_cookie = xcb_record_enable_context(m_connection, m_context); xcb_flush(m_connection); m_notifier = new QSocketNotifier(xcb_get_file_descriptor(m_connection), QSocketNotifier::Read, this); connect(m_notifier, &QSocketNotifier::activated, this, &XRecordKeyboardMonitor::processNextReply); m_notifier->setEnabled(true); } XRecordKeyboardMonitor::~XRecordKeyboardMonitor() { if (!m_connection) { return; } xcb_record_disable_context(m_connection, m_context); xcb_record_free_context(m_connection, m_context); xcb_disconnect(m_connection); } void XRecordKeyboardMonitor::processNextReply() { xcb_generic_event_t *event; while ((event = xcb_poll_for_event(m_connection))) { std::free(event); } void *reply = nullptr; xcb_generic_error_t *error = nullptr; while (m_cookie.sequence && xcb_poll_for_reply(m_connection, m_cookie.sequence, &reply, &error)) { // xcb_poll_for_reply may set both reply and error to null if connection has error. // break if xcb_connection has error, no point to continue anyway. if (xcb_connection_has_error(m_connection)) { break; } if (error) { std::free(error); break; } if (!reply) { continue; } QScopedPointer data(reinterpret_cast(reply)); process(data.data()); } } void XRecordKeyboardMonitor::process(xcb_record_enable_context_reply_t *reply) { bool prevActivity = activity(); xcb_key_press_event_t *events = reinterpret_cast(xcb_record_enable_context_data(reply)); int nEvents = xcb_record_enable_context_data_length(reply) / sizeof(xcb_key_press_event_t); bool wasActivity = prevActivity; for (xcb_key_press_event_t *e = events; e < events + nEvents; e++) { if (e->response_type != XCB_KEY_PRESS && e->response_type != XCB_KEY_RELEASE) { continue; } if (m_ignore[e->detail]) { continue; } bool pressed = (e->response_type == XCB_KEY_PRESS); if (m_pressed[e->detail] == pressed) { continue; } m_pressed[e->detail] = pressed; int &counter = m_modifier[e->detail] ? m_modifiersPressed : m_keysPressed; if (pressed) { counter++; } else { counter--; } wasActivity = wasActivity || activity(); } if (!prevActivity && activity()) { Q_EMIT keyboardActivityStarted(); } else if (!activity() && wasActivity) { Q_EMIT keyboardActivityFinished(); } } core-0.8/settings-daemon/touchpad/x11/xrecordkeyboardmonitor.h000066400000000000000000000020201417504024300245740ustar00rootroot00000000000000/* SPDX-FileCopyrightText: 2013 Alexander Mezin SPDX-License-Identifier: GPL-2.0-or-later */ #ifndef XRECORDKEYBOARDMONITOR_H #define XRECORDKEYBOARDMONITOR_H #include #include #include #include #include class XRecordKeyboardMonitor : public QObject { Q_OBJECT public: XRecordKeyboardMonitor(Display *display); ~XRecordKeyboardMonitor(); Q_SIGNALS: void keyboardActivityStarted(); void keyboardActivityFinished(); private Q_SLOTS: void processNextReply(); private: void process(xcb_record_enable_context_reply_t *reply); bool activity() const { return m_keysPressed && !m_modifiersPressed; } QSocketNotifier *m_notifier; xcb_connection_t *m_connection; xcb_record_context_t m_context; xcb_record_enable_context_cookie_t m_cookie; QVector m_modifier, m_ignore, m_pressed; int m_modifiersPressed, m_keysPressed; }; #endif // XRECORDKEYBOARDMONITOR_H core-0.8/settings-daemon/translations/000077500000000000000000000000001417504024300201335ustar00rootroot00000000000000core-0.8/settings-daemon/translations/ar_AA.ts000066400000000000000000000103671417504024300214550ustar00rootroot00000000000000 Battery d Tage h Stunden m Minuten until fully charged. bis Akku voll. remaining. übrig. %1d %1ي %1h %1س %1m %1د %1 until fully charged %1 حتى اكتمال الشحن %1 remaining %1 متبقي Fully charged. مشحون بالكامل. now حالياً %1 ago %1 مضى ago vergangen UPowerDevice %1 Battery %1 is battery technology %1 بطارية Lithium-ion battery technology أيونات الليثيوم Lithium Polymer battery technology بوليمر الليثيوم Lithium Iron Phosphate battery technology خليط فوسفات حديد الليثيوم Lead Acid battery technology حامض الرصاص Nickel Cadmium battery technology سبيكة نيكل وكادميوم Nickel Metal Hydride battery technology هجين معدن النيكل Unknown battery technology غير معروف core-0.8/settings-daemon/translations/be_BY.ts000066400000000000000000000104411417504024300214630ustar00rootroot00000000000000 Battery d Tage h Stunden m Minuten until fully charged. bis Akku voll. remaining. übrig. %1d %1d %1h %1h %1m %1m %1 until fully charged %1 да поўнай зарадкі %1 remaining %1 засталося Fully charged. Цалкам зараджаны. now зараз %1 ago %1 таму ago vergangen UPowerDevice %1 Battery %1 is battery technology %1 Батарэя Lithium-ion battery technology Тып батарэi: Li-Ion Lithium Polymer battery technology Тып батарэі: Li-Poly Lithium Iron Phosphate battery technology Тып батарэі: LFP Lead Acid battery technology Тып батарэі: Свінцова-кіслотная Nickel Cadmium battery technology Тып батарэі: Ni-Cd Nickel Metal Hydride battery technology Тып батарэі: Ni-MH Unknown battery technology Невядомы тып батарэі core-0.8/settings-daemon/translations/be_Latn.ts000066400000000000000000000103231417504024300220460ustar00rootroot00000000000000 Battery d Tage h Stunden m Minuten until fully charged. bis Akku voll. remaining. übrig. %1d %1h %1m %1 until fully charged %1 remaining Fully charged. now %1 ago ago vergangen UPowerDevice %1 Battery %1 is battery technology Lithium-ion battery technology Lithium Polymer battery technology Lithium Iron Phosphate battery technology Lead Acid battery technology Nickel Cadmium battery technology Nickel Metal Hydride battery technology Unknown battery technology core-0.8/settings-daemon/translations/bg_BG.ts000066400000000000000000000103771417504024300214530ustar00rootroot00000000000000 Battery d Tage h Stunden m Minuten until fully charged. bis Akku voll. remaining. übrig. %1d %1d %1h %1h %1m %1m %1 until fully charged %1 до пълно зареждане %1 remaining Остават %1 Fully charged. Напълно заредена. now сега %1 ago Преди %1 ago vergangen UPowerDevice %1 Battery %1 is battery technology %1 Батерия Lithium-ion battery technology Литиево-йонна Lithium Polymer battery technology Литиево-полимерна Lithium Iron Phosphate battery technology Литиев железен фосфат Lead Acid battery technology Оловна киселина Nickel Cadmium battery technology Никел кадмий Nickel Metal Hydride battery technology Никел метал хидрид Unknown battery technology Неизвестна core-0.8/settings-daemon/translations/bs_BA.ts000066400000000000000000000101401417504024300214450ustar00rootroot00000000000000 Battery d Tage h Stunden m Minuten until fully charged. bis Akku voll. remaining. übrig. %1d %1d %1h %1h %1m %1m %1 until fully charged Još %1 dok se ne napuni %1 remaining %1 ostalo Fully charged. Napunjeno. now sada %1 ago Prije %1 ago vergangen UPowerDevice %1 Battery %1 is battery technology %1 baterija Lithium-ion battery technology Litijum-jonska Lithium Polymer battery technology Litij polimer Lithium Iron Phosphate battery technology Litijum-željezni fosfat Lead Acid battery technology Olovna kiselina Nickel Cadmium battery technology Nikl-kadmij Nickel Metal Hydride battery technology Nikl-metal hibrid Unknown battery technology Nepoznata core-0.8/settings-daemon/translations/cs_CZ.ts000066400000000000000000000101641417504024300215060ustar00rootroot00000000000000 Battery d Tage h Stunden m Minuten until fully charged. bis Akku voll. remaining. übrig. %1d %1d %1h %1h %1m %1m %1 until fully charged %1 zbývá do plného nabití %1 remaining %1 zbývá Fully charged. Plně nabito. now teď %1 ago před %1 ago vergangen UPowerDevice %1 Battery %1 is battery technology %1 Baterie Lithium-ion battery technology Lithium-iontová Lithium Polymer battery technology Lithium-polymerová Lithium Iron Phosphate battery technology Lithium-železo-fosfátová Lead Acid battery technology Olověná Nickel Cadmium battery technology Nikl-kadmiová Nickel Metal Hydride battery technology Nikl-metal-hydridová Unknown battery technology Neznámá core-0.8/settings-daemon/translations/da_DK.ts000066400000000000000000000101241417504024300214430ustar00rootroot00000000000000 Battery d Tage h Stunden m Minuten until fully charged. bis Akku voll. remaining. übrig. %1d %1d %1h %1h %1m %1m %1 until fully charged %1 indtil fuldt opladet %1 remaining %1 tilbage Fully charged. Fuldt opladet. now nu %1 ago %1 siden ago vergangen UPowerDevice %1 Battery %1 is battery technology %1 Batteri Lithium-ion battery technology Lithium-ion Lithium Polymer battery technology Lithium Polymer Lithium Iron Phosphate battery technology Lithium-jern-fosfat Lead Acid battery technology Blysyre Nickel Cadmium battery technology Nikkel-cadmium Nickel Metal Hydride battery technology Nikkel-metalhydrid Unknown battery technology Ukendt core-0.8/settings-daemon/translations/de_DE.ts000066400000000000000000000102001417504024300214340ustar00rootroot00000000000000 Battery d Tage h Stunden m Minuten until fully charged. bis Akku voll. remaining. übrig. %1d %1 T. %1h %1 St. %1m %1 Min. %1 until fully charged %1 bis zur vollständigen Aufladung %1 remaining %1 übrig Fully charged. Voll Aufgeladen. now jetzt %1 ago vor %1 ago vergangen UPowerDevice %1 Battery %1 is battery technology %1-Akku Lithium-ion battery technology Lithium-Ionen Lithium Polymer battery technology Lithium-Polymer Lithium Iron Phosphate battery technology Lithium-Eisen-Phosphat Lead Acid battery technology Blei Nickel Cadmium battery technology Nickel-Cadmium Nickel Metal Hydride battery technology Nickel-Metallhydrid Unknown battery technology Unbekannt core-0.8/settings-daemon/translations/en_US.ts000066400000000000000000000076711417504024300215270ustar00rootroot00000000000000 Battery %1d %1 d %1h %1 h %1m %1 min %1 until fully charged %1 until fully charged %1 remaining %1 remaining Fully charged. Fully charged. now now %1 ago %1 ago Language The system language has been changed, please log out and log in ThemeManager Screen scaling needs to be re-login to take effect UPowerDevice %1 Battery %1 is battery technology %1 Battery Lithium-ion battery technology Lithium-ion Lithium Polymer battery technology Lithium Polymer Lithium Iron Phosphate battery technology Lithium Iron Phosphate Lead Acid battery technology Lead Acid Nickel Cadmium battery technology Nickel Cadmium Nickel Metal Hydride battery technology Nickel Metal Hydride Unknown battery technology Unknown core-0.8/settings-daemon/translations/eo_XX.ts000066400000000000000000000103161417504024300215260ustar00rootroot00000000000000 Battery d Tage h Stunden m Minuten until fully charged. bis Akku voll. remaining. übrig. %1d %1h %1m %1 until fully charged %1 remaining Fully charged. now %1 ago ago vergangen UPowerDevice %1 Battery %1 is battery technology Lithium-ion battery technology Lithium Polymer battery technology Lithium Iron Phosphate battery technology Lead Acid battery technology Nickel Cadmium battery technology Nickel Metal Hydride battery technology Unknown battery technology core-0.8/settings-daemon/translations/es_ES.ts000066400000000000000000000101601417504024300214770ustar00rootroot00000000000000 Battery d d h h m m until fully charged. hasta completar la carga. remaining. restantes. %1d %1d %1h %1h %1m %1m %1 until fully charged %1 hasta completar la carga %1 remaining %1 restante Fully charged. Carga completa. now ahora %1 ago hace %1 ago atrás UPowerDevice %1 Battery %1 is battery technology Batería de %1 Lithium-ion battery technology iones de litio Lithium Polymer battery technology polímero de litio Lithium Iron Phosphate battery technology ferrofosfato de litio Lead Acid battery technology plomo-ácido Nickel Cadmium battery technology níquel-cadmio Nickel Metal Hydride battery technology níquel-metalhidruro Unknown battery technology Desconocido core-0.8/settings-daemon/translations/es_MX.ts000066400000000000000000000067011417504024300215220ustar00rootroot00000000000000 Battery %1d %1d %1h %1h %1m %1m %1 until fully charged %1 hasta completar la carga %1 remaining %1 restante Fully charged. Completamente cargado(a). now ahora %1 ago %1 atras UPowerDevice %1 Battery %1 is battery technology %1 de Batería Lithium-ion battery technology Batería de ion de litio Lithium Polymer battery technology Polímero de Litio Lithium Iron Phosphate battery technology Fosfato de hierro y litio Lead Acid battery technology Plomo ácido Nickel Cadmium battery technology Nickel cadmio Nickel Metal Hydride battery technology Hidruro metálico de níquel Unknown battery technology Desconocido core-0.8/settings-daemon/translations/fa_IR.ts000066400000000000000000000103031417504024300214600ustar00rootroot00000000000000 Battery d Tage h Stunden m Minuten until fully charged. bis Akku voll. remaining. übrig. %1d %1ر %1h %1س %1m %1د %1 until fully charged %1 تا شارژ کامل %1 remaining %1 باقی‌ مانده Fully charged. کاملاً شارژ شده. now اکنون %1 ago %1 قبل ago vergangen UPowerDevice %1 Battery %1 is battery technology %1 باتری Lithium-ion battery technology لیتیوم-یون Lithium Polymer battery technology لیتیوم پلیمر Lithium Iron Phosphate battery technology فسفات آهن لیتیوم Lead Acid battery technology اسید سرب Nickel Cadmium battery technology نیکل کادمیوم Nickel Metal Hydride battery technology هیدرید فلز نیکل Unknown battery technology ناشناخته core-0.8/settings-daemon/translations/fi_FI.ts000066400000000000000000000101711417504024300214570ustar00rootroot00000000000000 Battery d Tage h Stunden m Minuten until fully charged. bis Akku voll. remaining. übrig. %1d %1 p. %1h %1 t. %1m %1 min %1 until fully charged %1 kunnes täyteen ladattu %1 remaining %1 jäljellä Fully charged. Ladattu täyteen. now nyt %1 ago %1 sitten ago vergangen UPowerDevice %1 Battery %1 is battery technology %1-akku Lithium-ion battery technology Litiumioni Lithium Polymer battery technology Litiumpolymeeri Lithium Iron Phosphate battery technology Litium-rautafosfaatti Lead Acid battery technology Lyijy Nickel Cadmium battery technology Nikkeli-kadmium Nickel Metal Hydride battery technology Nikkelimetallihydridi Unknown battery technology Tuntematon core-0.8/settings-daemon/translations/fr_FR.ts000066400000000000000000000102371417504024300215040ustar00rootroot00000000000000 Battery d Tage h Stunden m Minuten until fully charged. bis Akku voll. remaining. übrig. %1d %1 j %1h %1 h %1m %1 min %1 until fully charged %1 jusqu'à la recharge complète %1 remaining %1 restants Fully charged. Complètement chargé. now maintenant %1 ago il y a %1 ago vergangen UPowerDevice %1 Battery %1 is battery technology Batterie %1 Lithium-ion battery technology lithium-ion Lithium Polymer battery technology lithium-polymère Lithium Iron Phosphate battery technology lithium-fer-phosphate Lead Acid battery technology acide de plomb Nickel Cadmium battery technology nickel-cadmium Nickel Metal Hydride battery technology nickel-hydrure métallique Unknown battery technology inconnue core-0.8/settings-daemon/translations/he_IL.ts000066400000000000000000000102401417504024300214600ustar00rootroot00000000000000 Battery d Tage h Stunden m Minuten until fully charged. bis Akku voll. remaining. übrig. %1d 1 ימים %1h 1 שעות %1m 1 דקות %1 until fully charged עד לסוללה מלאה %1 remaining נשאר Fully charged. סוללה מלאה. now עכשיו %1 ago לפני ago vergangen UPowerDevice %1 Battery %1 is battery technology סוללה Lithium-ion battery technology ליתיום יון Lithium Polymer battery technology ליתיום פולימר Lithium Iron Phosphate battery technology Lithium Iron Phosphate Lead Acid battery technology חומצת לֵד Nickel Cadmium battery technology Nickel Cadmium Nickel Metal Hydride battery technology Nickel Metal Hydride Unknown battery technology לא ידוע core-0.8/settings-daemon/translations/hi_IN.ts000066400000000000000000000103161417504024300214720ustar00rootroot00000000000000 Battery d Tage h Stunden m Minuten until fully charged. bis Akku voll. remaining. übrig. %1d %1h %1m %1 until fully charged %1 remaining Fully charged. now %1 ago ago vergangen UPowerDevice %1 Battery %1 is battery technology Lithium-ion battery technology Lithium Polymer battery technology Lithium Iron Phosphate battery technology Lead Acid battery technology Nickel Cadmium battery technology Nickel Metal Hydride battery technology Unknown battery technology core-0.8/settings-daemon/translations/hu_HU.ts000066400000000000000000000101621417504024300215130ustar00rootroot00000000000000 Battery d Tage h Stunden m Minuten until fully charged. bis Akku voll. remaining. übrig. %1d %1 nap %1h %1 óra %1m %1 perc %1 until fully charged %1 a teljes feltöltésig %1 remaining %1 maradt Fully charged. Teljesen feltöltve. now most %1 ago %1 óta ago vergangen UPowerDevice %1 Battery %1 is battery technology %1 Akkumulátor Lithium-ion battery technology Lítium-ion Lithium Polymer battery technology Lítium polimer Lithium Iron Phosphate battery technology Lítium-vas-foszfát Lead Acid battery technology Ólom-sav Nickel Cadmium battery technology Nikkel kadmium Nickel Metal Hydride battery technology Nikkelfém-hidrid Unknown battery technology Ismeretlen core-0.8/settings-daemon/translations/id_ID.ts000066400000000000000000000101541417504024300214540ustar00rootroot00000000000000 Battery d Tage h Stunden m Minuten until fully charged. bis Akku voll. remaining. übrig. %1d %1h %1h %1j %1m %1m %1 until fully charged %1 hingga terisi penuh %1 remaining %1 tersisa Fully charged. Terisi penuh. now sekarang %1 ago %1 yang lalu ago vergangen UPowerDevice %1 Battery %1 is battery technology %1 Baterai Lithium-ion battery technology Lithium-ion Lithium Polymer battery technology Lithium Polymer Lithium Iron Phosphate battery technology Lithium Iron Phosphate Lead Acid battery technology Asam Timbal Nickel Cadmium battery technology Nikel Kadmium Nickel Metal Hydride battery technology Hidrida Logam Nikel Unknown battery technology Tidak Diketahui core-0.8/settings-daemon/translations/ie.ts000066400000000000000000000101551417504024300211020ustar00rootroot00000000000000 Battery d Tage h Stunden m Minuten until fully charged. bis Akku voll. remaining. übrig. %1d %1d %1h %1h %1m %1m %1 until fully charged %1 ante li complet charge %1 remaining %1 remane Fully charged. Complet charge. now nu %1 ago ante %1 ago vergangen UPowerDevice %1 Battery %1 is battery technology Batterie de %1 Lithium-ion battery technology Litium-ion Lithium Polymer battery technology Litium-polimeric Lithium Iron Phosphate battery technology Litium-fosfate de ferro Lead Acid battery technology Plumbe-acidic Nickel Cadmium battery technology Nickel-cadmium Nickel Metal Hydride battery technology Nickel-hidride metallic Unknown battery technology Ínconosset core-0.8/settings-daemon/translations/it_IT.ts000066400000000000000000000066641417504024300215270ustar00rootroot00000000000000 Battery %1d %1 g. %1h %1 o. %1m %1 min %1 until fully charged %1 fino alla carica completa %1 remaining %1 rimanenti Fully charged. Carica completa. now adesso %1 ago %1 fa UPowerDevice %1 Battery %1 is battery technology Batteria %1 Lithium-ion battery technology ioni di litio Lithium Polymer battery technology litio-polimero Lithium Iron Phosphate battery technology fosfato di litio ferro Lead Acid battery technology piombo-acido Nickel Cadmium battery technology nichel-cadmio Nickel Metal Hydride battery technology idruro di nichel metallico Unknown battery technology sconosciuta core-0.8/settings-daemon/translations/ja_JP.ts000066400000000000000000000102311417504024300214630ustar00rootroot00000000000000 Battery d Tage h Stunden m Minuten until fully charged. bis Akku voll. remaining. übrig. %1d %1日 %1h %1時間 %1m %1分 %1 until fully charged 充電完了まであと%1 %1 remaining 残り%1 Fully charged. 充電完了。 now %1 ago %1前 ago vergangen UPowerDevice %1 Battery %1 is battery technology %1 バッテリー Lithium-ion battery technology リチウムイオン Lithium Polymer battery technology リチウムポリマー Lithium Iron Phosphate battery technology リン酸鉄リチウム Lead Acid battery technology 酸性鉛 Nickel Cadmium battery technology ニッケル カドミウム Nickel Metal Hydride battery technology ニッケル金属水素化物 Unknown battery technology 不明 core-0.8/settings-daemon/translations/lt_LT.ts000066400000000000000000000102211417504024300215150ustar00rootroot00000000000000 Battery d Tage h Stunden m Minuten until fully charged. bis Akku voll. remaining. übrig. %1d %1h %1m %1 until fully charged %1 iki pilnai įkrauto %1 remaining Liko %1 Fully charged. Pilnai įkrautas. now dabar %1 ago Prieš %1 ago vergangen UPowerDevice %1 Battery %1 is battery technology %1 akumuliatorius Lithium-ion battery technology Ličio jonų Lithium Polymer battery technology Ličio polimero Lithium Iron Phosphate battery technology Ličio geležies fosfato Lead Acid battery technology Rūgštinis Nickel Cadmium battery technology Nikelio-kadmio Nickel Metal Hydride battery technology Nikelio metališkojo hidrido Unknown battery technology Nežinomas core-0.8/settings-daemon/translations/lv_LV.ts000066400000000000000000000101721417504024300215260ustar00rootroot00000000000000 Battery d Tage h Stunden m Minuten until fully charged. bis Akku voll. remaining. übrig. %1d %1d %1h %1st %1m %1m %1 until fully charged %1 līdz pilnīgai uzlādei %1 remaining %1 atliek Fully charged. Pilnīgi uzlādēts. now tagad %1 ago pirms %1 ago vergangen UPowerDevice %1 Battery %1 is battery technology %1 Akumulators Lithium-ion battery technology Litija-Jona Lithium Polymer battery technology Litija Polimēra Lithium Iron Phosphate battery technology Litija dzelzs fosfāts Lead Acid battery technology Svina Skābe Nickel Cadmium battery technology Niķeļa Kadmijs Nickel Metal Hydride battery technology Niķeļa Metāla Hidrīds Unknown battery technology Nezināms core-0.8/settings-daemon/translations/mg.ts000066400000000000000000000101661417504024300211120ustar00rootroot00000000000000 Battery d Tage h Stunden m Minuten until fully charged. bis Akku voll. remaining. übrig. %1d %1 andro %1h Ora %1 %1m %1m %1 until fully charged afaka %1 no hofeno tanteraka %1 remaining %1 sisa Fully charged. Feno tanteraka. now izao %1 ago %1 izay ago vergangen UPowerDevice %1 Battery %1 is battery technology %1 Vatoaratra Lithium-ion battery technology Lithium-ion Lithium Polymer battery technology Lithium Polymer Lithium Iron Phosphate battery technology Lithium Phosphate de fer Lead Acid battery technology Gel acide Nickel Cadmium battery technology Cadmium sy Nickel Nickel Metal Hydride battery technology Safiotra Vy sy Nikela Unknown battery technology Tsy fantatra core-0.8/settings-daemon/translations/ml_IN.ts000066400000000000000000000103161417504024300215020ustar00rootroot00000000000000 Battery d Tage h Stunden m Minuten until fully charged. bis Akku voll. remaining. übrig. %1d %1h %1m %1 until fully charged %1 remaining Fully charged. now %1 ago ago vergangen UPowerDevice %1 Battery %1 is battery technology Lithium-ion battery technology Lithium Polymer battery technology Lithium Iron Phosphate battery technology Lead Acid battery technology Nickel Cadmium battery technology Nickel Metal Hydride battery technology Unknown battery technology core-0.8/settings-daemon/translations/nb_NO.ts000066400000000000000000000102271417504024300215000ustar00rootroot00000000000000 Battery d d h t m m until fully charged. til full opplading. remaining. gjenstående. %1d %1 d %1h %1 t %1m %1 m %1 until fully charged %1 til helt oppladet %1 remaining %1 gjenstår Fully charged. Fullt oppladet. now %1 ago %1 siden ago siden UPowerDevice %1 Battery %1 is battery technology %1 batteri Lithium-ion battery technology Litium-ion Lithium Polymer battery technology Litium-polymer Lithium Iron Phosphate battery technology Litium-jernfosfat Lead Acid battery technology Blysyre Nickel Cadmium battery technology Nikkel-kadmium Nickel Metal Hydride battery technology Mikke-metallhydrid Unknown battery technology Ukjent core-0.8/settings-daemon/translations/ne_NP.ts000066400000000000000000000106131417504024300215030ustar00rootroot00000000000000 Battery d Tage h Stunden m Minuten until fully charged. bis Akku voll. remaining. übrig. %1d %1 दिन %1h $1 घन्टा %1m %1 मिनेट %1 until fully charged पुर्ण चार्ज हुन %1 %1 remaining %1 बाँकी Fully charged. चार्ज पुर्ण। now अहिले %1 ago %1 पहिले ago vergangen UPowerDevice %1 Battery %1 is battery technology %1 ब्याट्री Lithium-ion battery technology लिथियम आयोन Lithium Polymer battery technology लिथियम पोलिमर Lithium Iron Phosphate battery technology लिथियम फोस्फेट आयोन Lead Acid battery technology एसिड र शिशा युक्त Nickel Cadmium battery technology निकेल क्याड्मियम Nickel Metal Hydride battery technology निकेल हाइड्राइड Unknown battery technology अज्ञात core-0.8/settings-daemon/translations/pl_PL.ts000066400000000000000000000103301417504024300215060ustar00rootroot00000000000000 Battery d d. h godz. m min. until fully charged. do pełnego naładowania. remaining. I don't know of a better way to translate this. czasu na baterii. %1d %1d %1h %1h %1m %1min %1 until fully charged %1 do pełnego naładowania %1 remaining Pozostało %1 Fully charged. W pełni naładowana. now teraz %1 ago %1 temu ago temu UPowerDevice %1 Battery %1 is battery technology Bateria %1 Lithium-ion battery technology litowo-jonowa Lithium Polymer battery technology litowo-polimerowa Lithium Iron Phosphate battery technology litowo-żelazowo-fosforanowa Lead Acid battery technology kwasowo-ołowiowa Nickel Cadmium battery technology niklowo-kadmowa Nickel Metal Hydride battery technology niklowo-wodorkowa Unknown battery technology nieznana core-0.8/settings-daemon/translations/pt_BR.ts000066400000000000000000000066511417504024300215210ustar00rootroot00000000000000 Battery %1d %1d %1h %1h %1m %1m %1 until fully charged %1 até a carga completa %1 remaining %1 restante(s) Fully charged. Carga completa. now agora %1 ago %1 atrás UPowerDevice %1 Battery %1 is battery technology %1 Bateria Lithium-ion battery technology Íon de Lítio Lithium Polymer battery technology Polímero de Lítio Lithium Iron Phosphate battery technology Fosfato de Ferrolítio Lead Acid battery technology Chumbo Ácido Nickel Cadmium battery technology Níquel Cádmio Nickel Metal Hydride battery technology Níquel-Hidreto Metálico Unknown battery technology Desconhecido core-0.8/settings-daemon/translations/pt_PT.ts000066400000000000000000000102131417504024300215260ustar00rootroot00000000000000 Battery d Tage h Stunden m Minuten until fully charged. bis Akku voll. remaining. übrig. %1d %1d %1h %1h %1m %1m %1 until fully charged %1 até estar completamente carregado %1 remaining %1 restante Fully charged. Completamente carregado. now agora %1 ago Há %1 ago vergangen UPowerDevice %1 Battery %1 is battery technology Bateria a %1 Lithium-ion battery technology Ião lítio Lithium Polymer battery technology Polímero de Lítio Lithium Iron Phosphate battery technology Fosfato Ferro-Lítio Lead Acid battery technology Chumbo-Ácido Nickel Cadmium battery technology Níquel Cádmio Nickel Metal Hydride battery technology Hidreto de Metal Níquel Unknown battery technology Desconhecido core-0.8/settings-daemon/translations/ro_RO.ts000066400000000000000000000103161417504024300215240ustar00rootroot00000000000000 Battery d Tage h Stunden m Minuten until fully charged. bis Akku voll. remaining. übrig. %1d %1h %1m %1 until fully charged %1 remaining Fully charged. now %1 ago ago vergangen UPowerDevice %1 Battery %1 is battery technology Lithium-ion battery technology Lithium Polymer battery technology Lithium Iron Phosphate battery technology Lead Acid battery technology Nickel Cadmium battery technology Nickel Metal Hydride battery technology Unknown battery technology core-0.8/settings-daemon/translations/ru_RU.ts000066400000000000000000000104701417504024300215410ustar00rootroot00000000000000 Battery d д h ч m м until fully charged. до полной зарядки. remaining. осталось. %1d %1d %1h %1h %1m %1m %1 until fully charged %1 до полной зарядки %1 remaining %1 осталось Fully charged. Полностью заряжен. now сейчас %1 ago %1 назад ago назад UPowerDevice %1 Battery %1 is battery technology %1 аккумулятор Lithium-ion battery technology Литий-ионный Lithium Polymer battery technology Литий-полимерный Lithium Iron Phosphate battery technology Литий-железо-фосфатный Lead Acid battery technology Свинцово-кислотный Nickel Cadmium battery technology Никель-кадмиевый Nickel Metal Hydride battery technology Никель-металлогидридный Unknown battery technology Неизвестный core-0.8/settings-daemon/translations/si_LK.ts000066400000000000000000000104151417504024300215050ustar00rootroot00000000000000 Battery d Tage h Stunden m Minuten until fully charged. bis Akku voll. remaining. übrig. %1d %1h %1m %1 until fully charged %1 remaining Fully charged. now %1 ago ago vergangen UPowerDevice %1 Battery %1 is battery technology Lithium-ion battery technology Lithium Polymer battery technology ලිතියම් පොලිමර් Lithium Iron Phosphate battery technology ලිතියම් යකඩ පොස්පේට් Lead Acid battery technology Nickel Cadmium battery technology Nickel Metal Hydride battery technology Unknown battery technology core-0.8/settings-daemon/translations/sk_SK.ts000066400000000000000000000102511417504024300215140ustar00rootroot00000000000000 Battery d Tage h Stunden m Minuten until fully charged. bis Akku voll. remaining. übrig. %1d %1d %1h %1h %1m %1m %1 until fully charged %1 do úplného nabitia %1 remaining Zostáva %1 Fully charged. Úplne nabité (100 %) now teraz %1 ago Pred %1 ago vergangen UPowerDevice %1 Battery %1 is battery technology %1 Batérie Lithium-ion battery technology Lítium-iónová (Li-Ion) Lithium Polymer battery technology Lítium-polymérová (Li-Pol) Lithium Iron Phosphate battery technology Lítium-železo-fosfátová (LiFePO4) Lead Acid battery technology Olovená (Pb) Nickel Cadmium battery technology Nikel-kadmiová (NiCd) Nickel Metal Hydride battery technology Nikel-metal hydridová (NiMH) Unknown battery technology Neznáma core-0.8/settings-daemon/translations/so.ts000066400000000000000000000101471417504024300211270ustar00rootroot00000000000000 Battery d Tage h Stunden m Minuten until fully charged. bis Akku voll. remaining. übrig. %1d %1m %1h %1s %1m %1d %1 until fully charged %1 inta uu ka buuxsanayo %1 remaining %1 dhiman Fully charged. Dabku wuu buuxaa. now hadda %1 ago %1 kahor ago vergangen UPowerDevice %1 Battery %1 is battery technology %1 Beetari Lithium-ion battery technology Lithium-ion Lithium Polymer battery technology Lithium Polymer Lithium Iron Phosphate battery technology Lithium Birta Phosphate Lead Acid battery technology Lead-Acid Nickel Cadmium battery technology Nickel-Cadmium Nickel Metal Hydride battery technology Nickel-Metal-Hydride Unknown battery technology Lama yaqaan core-0.8/settings-daemon/translations/sr_RS.ts000066400000000000000000000101371417504024300215350ustar00rootroot00000000000000 Battery d Tage h Stunden m Minuten until fully charged. bis Akku voll. remaining. übrig. %1d %1d %1h %1s %1m %1m %1 until fully charged još 1% dok se ne napuni %1 remaining %1 ostalo Fully charged. Napunjeno. now sad %1 ago Prije %1 ago vergangen UPowerDevice %1 Battery %1 is battery technology %1 baterija Lithium-ion battery technology Litijum-jonska Lithium Polymer battery technology Litij polimer Lithium Iron Phosphate battery technology Litijum-željezni fosfat Lead Acid battery technology Olovna kiselina Nickel Cadmium battery technology Nikl-kadmij Nickel Metal Hydride battery technology Nikl-metal hibrid Unknown battery technology Nepoznata core-0.8/settings-daemon/translations/sv_SE.ts000066400000000000000000000101151417504024300215200ustar00rootroot00000000000000 Battery d Tage h Stunden m Minuten until fully charged. bis Akku voll. remaining. übrig. %1d %1d %1h %1h %1m %1m %1 until fully charged %1 tills fulladdad %1 remaining %1 återstår Fully charged. Fulladdad. now nu %1 ago %1 sedan ago vergangen UPowerDevice %1 Battery %1 is battery technology %1 Batteri Lithium-ion battery technology Lithium-ion Lithium Polymer battery technology Lithium Polymer Lithium Iron Phosphate battery technology Litiumjärnfosfat Lead Acid battery technology Bly-syra Nickel Cadmium battery technology Nickel Kadmium Nickel Metal Hydride battery technology Nickelmetallhydrid Unknown battery technology Okänd core-0.8/settings-daemon/translations/sw.ts000066400000000000000000000101241417504024300211320ustar00rootroot00000000000000 Battery d Tage h Stunden m Minuten until fully charged. bis Akku voll. remaining. übrig. %1d %1d %1h %1h %1m %1m %1 until fully charged %1 mbaaka imejaa %1 remaining %1 imebaki Fully charged. Imejaa. now Sasa %1 ago %1 imepita ago vergangen UPowerDevice %1 Battery %1 is battery technology %1 Betri Lithium-ion battery technology Lithium-ion Lithium Polymer battery technology Lithium Polymer Lithium Iron Phosphate battery technology Lithium Iron Phosphate Lead Acid battery technology Lead Acid Nickel Cadmium battery technology Nickel Cadmium Nickel Metal Hydride battery technology Nickel Metal Hydride Unknown battery technology Haijulikani core-0.8/settings-daemon/translations/ta_IN.ts000066400000000000000000000103161417504024300214760ustar00rootroot00000000000000 Battery d Tage h Stunden m Minuten until fully charged. bis Akku voll. remaining. übrig. %1d %1h %1m %1 until fully charged %1 remaining Fully charged. now %1 ago ago vergangen UPowerDevice %1 Battery %1 is battery technology Lithium-ion battery technology Lithium Polymer battery technology Lithium Iron Phosphate battery technology Lead Acid battery technology Nickel Cadmium battery technology Nickel Metal Hydride battery technology Unknown battery technology core-0.8/settings-daemon/translations/tr_TR.ts000066400000000000000000000101511417504024300215330ustar00rootroot00000000000000 Battery d Tage h Stunden m Minuten until fully charged. bis Akku voll. remaining. übrig. %1d %1g %1h %1s %1m %1d %1 until fully charged %1 tamamen şarj olana kadar %1 remaining %1 kalan Fully charged. Tamamen şarj oldu. now şimdi %1 ago %1 önce ago vergangen UPowerDevice %1 Battery %1 is battery technology %1 Batarya Lithium-ion battery technology Lityum İyon Lithium Polymer battery technology Lityum Polimer Lithium Iron Phosphate battery technology Lityum Demir Fosfat Lead Acid battery technology Kurşun Asit Nickel Cadmium battery technology Nikel Kadmiyum Nickel Metal Hydride battery technology Nikel Metal Hidrit Unknown battery technology Bilinmiyor core-0.8/settings-daemon/translations/uk_UA.ts000066400000000000000000000104341417504024300215110ustar00rootroot00000000000000 Battery d Tage h Stunden m Minuten until fully charged. bis Akku voll. remaining. übrig. %1d %1d %1h %1h %1m %1m %1 until fully charged %1 до повного зарядження %1 remaining %1 залишилось Fully charged. Повністю заряджено. now Щойно %1 ago %1 тому ago vergangen UPowerDevice %1 Battery %1 is battery technology %1 Батарея Lithium-ion battery technology Літій-іонний Lithium Polymer battery technology Літій-полімерний Lithium Iron Phosphate battery technology LiFePO Lead Acid battery technology Свинцевий тип Nickel Cadmium battery technology Нікеле-кадмієвий акумулятор Nickel Metal Hydride battery technology Нікель-металогідридний акумулятор Unknown battery technology Невідомо core-0.8/settings-daemon/translations/uz_UZ.ts000066400000000000000000000102041417504024300215540ustar00rootroot00000000000000 Battery d Tage h Stunden m Minuten until fully charged. bis Akku voll. remaining. übrig. %1d %1 d %1h %1h %1m %1 m %1 until fully charged %1 zaryadlangunga qadar %1 remaining %1 qolgan Fully charged. To'liq quvvatlandi. now hozir %1 ago %1 oldin ago vergangen UPowerDevice %1 Battery %1 is battery technology %1 Batareyasi Lithium-ion battery technology Litiyli-ion Lithium Polymer battery technology Litiyli-Polimer Lithium Iron Phosphate battery technology Litiyli-Temir-Fosfat Lead Acid battery technology Qo'rg'oshin-Kistolasi Nickel Cadmium battery technology Nikel-Kadmiy Nickel Metal Hydride battery technology Nikel Metal Gidridi Unknown battery technology Noma'lum core-0.8/settings-daemon/translations/vi_VN.ts000066400000000000000000000102571417504024300215310ustar00rootroot00000000000000 Battery d Tage h Stunden m Minuten until fully charged. bis Akku voll. remaining. übrig. %1d %1 ngày %1h %1 giờ %1m %1 phút %1 until fully charged %1 trước khi được sạc đầy %1 remaining %1 còn lại Fully charged. Đã sạc đầy now bây giờ %1 ago %1 trước ago vergangen UPowerDevice %1 Battery %1 is battery technology %1 Pin Lithium-ion battery technology Pin Lithium-ion Lithium Polymer battery technology Pin Lithium Polymer Lithium Iron Phosphate battery technology Pin Lithium Iron Phosphate Lead Acid battery technology Pin chì-axit Nickel Cadmium battery technology Pin Nickel Cadmium Nickel Metal Hydride battery technology Pin Nickel Hydride kim loại Unknown battery technology Không xác định core-0.8/settings-daemon/translations/zh_CN.ts000066400000000000000000000076751417504024300215230ustar00rootroot00000000000000 Battery %1d %1天 %1h %1小时 %1m %1分钟 %1 until fully charged 预计%1充满 %1 remaining 剩余%1 Fully charged. 已充满电。 now 现在 %1 ago %1之前 Language The system language has been changed, please log out and log in 系统语言已更改,请注销并登录 ThemeManager Screen scaling needs to be re-login to take effect 屏幕缩放需要重新登录才能生效 UPowerDevice %1 Battery %1 is battery technology %1 电池 Lithium-ion battery technology 锂离子 Lithium Polymer battery technology 锂聚合物 Lithium Iron Phosphate battery technology 磷酸铁锂 Lead Acid battery technology 铅酸 Nickel Cadmium battery technology 镍镉 Nickel Metal Hydride battery technology 金属氢化物镍 Unknown battery technology 未知 core-0.8/settings-daemon/translations/zh_TW.ts000066400000000000000000000101551417504024300215400ustar00rootroot00000000000000 Battery d Tage h Stunden m Minuten until fully charged. bis Akku voll. remaining. übrig. %1d %1天 %1h %1小時 %1m %1分鐘 %1 until fully charged 距充電完成還需 %1 %1 remaining 剩餘 %1 Fully charged. 充電完成。 now 當前 %1 ago %1 之前 ago vergangen UPowerDevice %1 Battery %1 is battery technology %1 電量 Lithium-ion battery technology 鋰離子電池 Lithium Polymer battery technology 鋰聚合物電池 Lithium Iron Phosphate battery technology 磷酸鐵鋰電池 Lead Acid battery technology 鉛酸電池 Nickel Cadmium battery technology 鎳鎘電池 Nickel Metal Hydride battery technology 鎳氫電池 Unknown battery technology 未知 core-0.8/shutdown-ui/000077500000000000000000000000001417504024300145775ustar00rootroot00000000000000core-0.8/shutdown-ui/CMakeLists.txt000066400000000000000000000012151417504024300173360ustar00rootroot00000000000000project(cutefish-shutdown) add_executable(cutefish-shutdown main.cpp actions.cpp qml.qrc ) target_link_libraries(cutefish-shutdown Qt5::Core Qt5::Widgets Qt5::Quick Qt5::QuickControls2 Qt5::DBus ) file(GLOB TS_FILES translations/*.ts) qt5_create_translation(QM_FILES ${TS_FILES}) add_custom_target(shutdown-translations DEPENDS ${QM_FILES} SOURCES ${TS_FILES}) add_dependencies(cutefish-shutdown shutdown-translations) install(FILES ${QM_FILES} DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/cutefish-shutdown/translations) install(TARGETS cutefish-shutdown RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) core-0.8/shutdown-ui/IconButton.qml000066400000000000000000000045361417504024300174060ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: Reion Wong * * 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 * 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 . */ import QtQuick 2.0 import QtQuick.Controls 2.5 import QtQuick.Layouts 1.3 import QtGraphicalEffects 1.0 import FishUI 1.0 as FishUI Item { id: control width: 128 height: width property string text property string icon property int iconSize: 52 property bool checked: false signal clicked MouseArea { id: mouseArea anchors.fill: parent hoverEnabled: true acceptedButtons: Qt.LeftButton onClicked: control.clicked() } ColumnLayout { id: layout anchors.fill: parent spacing: FishUI.Units.largeSpacing * 1.5 Item { Layout.fillHeight: true } Item { height: control.iconSize Layout.fillWidth: true Rectangle { anchors.centerIn: parent width: parent.height + FishUI.Units.largeSpacing * 2 height: parent.height + FishUI.Units.largeSpacing * 2 z: -1 color: "white" opacity: mouseArea.pressed ? 0.1 : mouseArea.containsMouse || control.checked ? 0.2 : 0 radius: height / 2 } Image { id: image anchors.centerIn: parent source: control.icon sourceSize: Qt.size(width, height) width: control.iconSize height: width } } Label { id: _label Layout.alignment: Qt.AlignCenter text: control.text color: "white" } Item { Layout.fillHeight: true } } } core-0.8/shutdown-ui/actions.cpp000066400000000000000000000037151417504024300167510ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: revenmartin * * 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 * 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 "actions.h" #include #include #include #include const static QString s_dbusName = "com.cutefish.Session"; const static QString s_pathName = "/Session"; const static QString s_interfaceName = "com.cutefish.Session"; Actions::Actions(QObject *parent) : QObject(parent) { } void Actions::shutdown() { QDBusInterface iface(s_dbusName, s_pathName, s_interfaceName, QDBusConnection::sessionBus()); if (iface.isValid()) { iface.call("powerOff"); } } void Actions::logout() { QDBusInterface iface(s_dbusName, s_pathName, s_interfaceName, QDBusConnection::sessionBus()); if (iface.isValid()) { iface.call("logout"); } } void Actions::reboot() { QDBusInterface iface(s_dbusName, s_pathName, s_interfaceName, QDBusConnection::sessionBus()); if (iface.isValid()) { iface.call("reboot"); } } void Actions::lockScreen() { QProcess::startDetached("cutefish-screenlocker", QStringList()); qApp->exit(0); } void Actions::suspend() { QDBusInterface iface(s_dbusName, s_pathName, s_interfaceName, QDBusConnection::sessionBus()); if (iface.isValid()) { iface.call("suspend"); } QCoreApplication::exit(0); } core-0.8/shutdown-ui/actions.h000066400000000000000000000020711417504024300164100ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: revenmartin * * 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 * 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 ACTIONS_H #define ACTIONS_H #include class Actions : public QObject { Q_OBJECT public: explicit Actions(QObject *parent = nullptr); Q_INVOKABLE void shutdown(); Q_INVOKABLE void logout(); Q_INVOKABLE void reboot(); Q_INVOKABLE void lockScreen(); Q_INVOKABLE void suspend(); }; #endif // ACTIONS_H core-0.8/shutdown-ui/icons/000077500000000000000000000000001417504024300157125ustar00rootroot00000000000000core-0.8/shutdown-ui/icons/system-lock-screen.svg000077500000000000000000000022401417504024300221630ustar00rootroot00000000000000 core-0.8/shutdown-ui/icons/system-log-out.svg000066400000000000000000000011451417504024300213440ustar00rootroot00000000000000 core-0.8/shutdown-ui/icons/system-reboot.svg000066400000000000000000000014211417504024300212450ustar00rootroot00000000000000 core-0.8/shutdown-ui/icons/system-shutdown.svg000066400000000000000000000011251417504024300216270ustar00rootroot00000000000000 core-0.8/shutdown-ui/icons/system-suspend.svg000066400000000000000000000016211417504024300214360ustar00rootroot00000000000000 core-0.8/shutdown-ui/main.cpp000066400000000000000000000042011417504024300162240ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: revenmartin * * 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 * 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 #include #include #include #include #include #include #include "actions.h" int main(int argc, char *argv[]) { QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QGuiApplication app(argc, argv); if (!QDBusConnection::sessionBus().registerService("com.cutefish.ShutdownUI")) { return -1; } if (!QDBusConnection::sessionBus().registerObject("/ShutdownUI", &app)) { return -1; } // Translations QLocale locale; QString qmFilePath = QString("%1/%2.qm").arg("/usr/share/cutefish-shutdown/translations/").arg(locale.name()); if (QFile::exists(qmFilePath)) { QTranslator *translator = new QTranslator(QGuiApplication::instance()); if (translator->load(qmFilePath)) { QGuiApplication::installTranslator(translator); } else { translator->deleteLater(); } } QQmlApplicationEngine engine; const QUrl url(QStringLiteral("qrc:/main.qml")); QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, &app, [url](QObject *obj, const QUrl &objUrl) { if (!obj && url == objUrl) QCoreApplication::exit(-1); }, Qt::QueuedConnection); engine.rootContext()->setContextProperty("actions", new Actions); engine.load(url); return app.exec(); } core-0.8/shutdown-ui/main.qml000066400000000000000000000174711417504024300162500ustar00rootroot00000000000000/* * Copyright (C) 2021 CutefishOS Team. * * Author: Reion Wong * * 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 * 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 . */ import QtQuick 2.12 import QtQuick.Window 2.3 import QtQuick.Controls 2.5 import QtQuick.Layouts 1.3 import QtGraphicalEffects 1.0 import Cutefish.Accounts 1.0 as Accounts import Cutefish.System 1.0 as System import FishUI 1.0 as FishUI ApplicationWindow { width: Screen.width height: Screen.height visible: true visibility: Window.FullScreen flags: Qt.FramelessWindowHint | Qt.X11BypassWindowManagerHint id: root function exit() { Qt.quit() } System.Wallpaper { id: wallpaper } Rectangle { anchors.fill: parent color: wallpaper.color visible: wallpaper.type === 1 } Image { id: wallpaperImage anchors.fill: parent source: "file://" + wallpaper.path sourceSize: Qt.size(width * Screen.devicePixelRatio, height * Screen.devicePixelRatio) fillMode: Image.PreserveAspectCrop asynchronous: false clip: true cache: false smooth: false visible: wallpaper.type === 0 } FastBlur { id: wallpaperBlur anchors.fill: parent radius: 64 source: wallpaperImage cached: true visible: wallpaperImage.visible } ColorOverlay { anchors.fill: parent source: parent color: "#000000" opacity: 0.2 } Accounts.UserAccount { id: currentUser } onActiveChanged: { if (!active) exit() } MouseArea { anchors.fill: parent onClicked: exit() } Item { id: rootItem anchors.fill: parent focus: true Keys.enabled: true Keys.onEscapePressed: { Qt.quit() } Keys.onEnterPressed: { buttonsItem.action() } Keys.onReturnPressed: { buttonsItem.action() } Keys.onLeftPressed: { if (buttonsItem.currentIndex === -1 || buttonsItem.currentIndex === 0) { buttonsItem.currentIndex = 0 } else { buttonsItem.currentIndex = buttonsItem.currentIndex - 1 } buttonsItem.updateChecked() } Keys.onRightPressed: { if (buttonsItem.currentIndex >= 4) { } else { buttonsItem.currentIndex = buttonsItem.currentIndex + 1 } buttonsItem.updateChecked() } Item { id: userItem anchors.top: parent.top anchors.bottom: buttonsItem.top anchors.bottomMargin: root.height * 0.05 anchors.left: parent.left anchors.right: parent.right ColumnLayout { anchors.fill: parent spacing: FishUI.Units.largeSpacing Item { Layout.fillHeight: true } Image { id: userIcon property int iconSize: 60 Layout.preferredHeight: iconSize Layout.preferredWidth: iconSize sourceSize: String(source) === "image://icontheme/default-user" ? Qt.size(iconSize, iconSize) : undefined source: currentUser.iconFileName ? "file:///" + currentUser.iconFileName : "image://icontheme/default-user" Layout.alignment: Qt.AlignHCenter layer.enabled: true layer.effect: OpacityMask { maskSource: Item { width: userIcon.width height: userIcon.height Rectangle { anchors.fill: parent radius: parent.height / 2 } } } // No Action MouseArea { anchors.fill: parent } } Label { Layout.alignment: Qt.AlignHCenter text: currentUser.userName color: "white" // No Action MouseArea { anchors.fill: parent } } } } Item { id: buttonsItem anchors.centerIn: parent width: buttonsLayout.implicitWidth height: buttonsLayout.implicitHeight property int currentIndex: -1 function updateChecked() { shutdownButton.checked = currentIndex === 0 rebootButton.checked = currentIndex === 1 logoutButton.checked = currentIndex === 2 lockscreenButton.checked = currentIndex === 3 suspendButton.checked = currentIndex === 4 } function action() { if (buttonsItem.currentIndex === -1 || buttonsItem.currentIndex > 4) return switch (currentIndex) { case 0: actions.shutdown() break case 1: actions.reboot() break case 2: actions.logout() break case 3: actions.lockScreen() break case 4: actions.suspend() break } } RowLayout { id: buttonsLayout anchors.fill: parent spacing: root.width * 0.015 IconButton { id: shutdownButton Layout.alignment: Qt.AlignVCenter text: qsTr("Shutdown") icon: "qrc:///icons/system-shutdown.svg" onClicked: actions.shutdown() } IconButton { id: rebootButton Layout.alignment: Qt.AlignVCenter text: qsTr("Reboot") icon: "qrc:///icons/system-reboot.svg" onClicked: actions.reboot() } IconButton { id: logoutButton Layout.alignment: Qt.AlignVCenter text: qsTr("Logout") icon: "qrc:///icons/system-log-out.svg" onClicked: actions.logout() } IconButton { id: lockscreenButton Layout.alignment: Qt.AlignVCenter text: qsTr("Lock screen") icon: "qrc:/icons/system-lock-screen.svg" onClicked: actions.lockScreen() } IconButton { id: suspendButton Layout.alignment: Qt.AlignVCenter text: qsTr("Suspend") icon: "qrc:///icons/system-suspend.svg" onClicked: actions.suspend() } } } } } core-0.8/shutdown-ui/qml.qrc000066400000000000000000000005451417504024300161030ustar00rootroot00000000000000 main.qml icons/system-log-out.svg icons/system-reboot.svg icons/system-shutdown.svg icons/system-suspend.svg IconButton.qml icons/system-lock-screen.svg core-0.8/shutdown-ui/translations/000077500000000000000000000000001417504024300173205ustar00rootroot00000000000000core-0.8/shutdown-ui/translations/ar_AA.ts000066400000000000000000000017421417504024300206370ustar00rootroot00000000000000 main Shutdown إيقاف التشغيل Reboot إعادة التشغيل Logout تسجيل الخروج Lock screen قفل الشاشة Suspend سكون core-0.8/shutdown-ui/translations/be_BY.ts000066400000000000000000000015461417504024300206560ustar00rootroot00000000000000 main Shutdown Выключэнне Reboot Перазагрузка Logout Выйсці з сеансу Suspend Спячы рэжым core-0.8/shutdown-ui/translations/be_Latn.ts000066400000000000000000000014371417504024300212410ustar00rootroot00000000000000 main Shutdown Vykliučennie Reboot Pierazahruzka Logout Vyjsci z sieansu Suspend Spiačy režym core-0.8/shutdown-ui/translations/bg_BG.ts000066400000000000000000000017471417504024300206410ustar00rootroot00000000000000 main Shutdown Изкючване Reboot Рестартиране Logout Излизане Lock screen Заключен екран Suspend Приспиване core-0.8/shutdown-ui/translations/bs_BA.ts000066400000000000000000000014141417504024300206360ustar00rootroot00000000000000 main Shutdown Ugasiti Reboot Ponovno pokreni Logout Odjavi se Suspend Suspendiraj core-0.8/shutdown-ui/translations/cs_CZ.ts000066400000000000000000000015031417504024300206700ustar00rootroot00000000000000 main Shutdown Vypnout Reboot Restartovat Logout Odhlásit se Suspend Uspat core-0.8/shutdown-ui/translations/da_DK.ts000066400000000000000000000014471417504024300206400ustar00rootroot00000000000000 main Shutdown Luk ned Reboot Genstart Logout Log ud Suspend Suspender core-0.8/shutdown-ui/translations/de_DE.ts000066400000000000000000000015151417504024300206320ustar00rootroot00000000000000 main Shutdown Herunterfahren Reboot Neustart Logout Abmelden Suspend Bereitschaft core-0.8/shutdown-ui/translations/en_US.ts000066400000000000000000000016501417504024300207030ustar00rootroot00000000000000 main Shutdown Shutdown Reboot Reboot Logout Log out Lock screen Lock screen Suspend Suspend core-0.8/shutdown-ui/translations/eo_XX.ts000066400000000000000000000014521417504024300207140ustar00rootroot00000000000000 main Shutdown Reboot Logout Suspend core-0.8/shutdown-ui/translations/es_ES.ts000066400000000000000000000015061417504024300206700ustar00rootroot00000000000000 main Shutdown Apagar Reboot Reiniciar Logout Cerrar sesión Suspend Suspender core-0.8/shutdown-ui/translations/es_MX.ts000066400000000000000000000014421417504024300207040ustar00rootroot00000000000000 main Shutdown Apagar Reboot Reiniciar Logout Cerrar Sesión Suspend Suspender core-0.8/shutdown-ui/translations/fa_IR.ts000066400000000000000000000015031417504024300206470ustar00rootroot00000000000000 main Shutdown خاموش Reboot راه‌اندازی مجدد Logout خروج Suspend تعلیق core-0.8/shutdown-ui/translations/fi_FI.ts000066400000000000000000000014241417504024300206450ustar00rootroot00000000000000 main Shutdown Sammuta Reboot Käynnistä uudelleen Logout Kirjaudu ulos Suspend Keskeytä core-0.8/shutdown-ui/translations/fr_FR.ts000066400000000000000000000014651417504024300206740ustar00rootroot00000000000000 main Shutdown Éteindre Reboot Redémarrer Logout Se déconnecter Suspend Suspendre core-0.8/shutdown-ui/translations/he_IL.ts000066400000000000000000000017061417504024300206540ustar00rootroot00000000000000 main Shutdown כיבוי Reboot הפעל מחדש Logout התנתק Lock screen מסך נעילה Suspend מצב שינה core-0.8/shutdown-ui/translations/hi_IN.ts000066400000000000000000000014531417504024300206610ustar00rootroot00000000000000 main Shutdown शट डाउन Reboot Logout Suspend core-0.8/shutdown-ui/translations/hu_HU.ts000066400000000000000000000014771417504024300207110ustar00rootroot00000000000000 main Shutdown Leállítás Reboot Újraindítás Logout Kijelentkezés Suspend Alvó állapot core-0.8/shutdown-ui/translations/id_ID.ts000066400000000000000000000014521417504024300206420ustar00rootroot00000000000000 main Shutdown Matikan Reboot Boot Ulang Logout Keluar Suspend Tangguhkan core-0.8/shutdown-ui/translations/ie.ts000066400000000000000000000014151417504024300202660ustar00rootroot00000000000000 main Shutdown Extinter Reboot Reiniciar Logout Cluder li session Suspend Suspender core-0.8/shutdown-ui/translations/it_IT.ts000066400000000000000000000015021417504024300206760ustar00rootroot00000000000000 main Shutdown Spegni Reboot Riavvia Logout Disconnettiti Suspend Sospendi core-0.8/shutdown-ui/translations/ja_JP.ts000066400000000000000000000017141417504024300206560ustar00rootroot00000000000000 main Shutdown シャットダウン Reboot 再起動 Logout ログアウト Lock screen 画面をロック Suspend サスペンド core-0.8/shutdown-ui/translations/lt_LT.ts000066400000000000000000000017001417504024300207040ustar00rootroot00000000000000 main Shutdown Išjungti Reboot Paleisti iš naujo Logout Atsijungti Lock screen Užrakinti ekraną Suspend Pristabdyti core-0.8/shutdown-ui/translations/lv_LV.ts000066400000000000000000000016711417504024300207170ustar00rootroot00000000000000 main Shutdown Izslēgt Reboot Restartēt Logout Izrakstīties Lock screen Bloķēt ekrānu Suspend Aizmidzināt core-0.8/shutdown-ui/translations/mg.ts000066400000000000000000000016601417504024300202760ustar00rootroot00000000000000 main Shutdown Vonoina Reboot Averina alefa Logout Mivoaka Lock screen Hidiana ny ecran Suspend Ajanona core-0.8/shutdown-ui/translations/ml_IN.ts000066400000000000000000000017301417504024300206670ustar00rootroot00000000000000 main Shutdown Reboot Logout Lock screen Suspend core-0.8/shutdown-ui/translations/nb_NO.ts000066400000000000000000000014331417504024300206640ustar00rootroot00000000000000 main Shutdown Slå av Reboot Omstart Logout Logg ut Suspend Hvilemodus core-0.8/shutdown-ui/translations/ne_NP.ts000066400000000000000000000014721417504024300206730ustar00rootroot00000000000000 main Shutdown पावर अफ Reboot पुन: सुचारु Logout लग आउट Suspend सस्पेन्ड core-0.8/shutdown-ui/translations/pl_PL.ts000066400000000000000000000014661417504024300207050ustar00rootroot00000000000000 main Shutdown Wyłącz Reboot Uruchom ponownie Logout Wyloguj się Suspend Uśpij core-0.8/shutdown-ui/translations/pt_BR.ts000066400000000000000000000015151417504024300207000ustar00rootroot00000000000000 main Shutdown Desligar Reboot Reiniciar Logout Encerrar sessão Suspend Suspender core-0.8/shutdown-ui/translations/pt_PT.ts000066400000000000000000000014661417504024300207250ustar00rootroot00000000000000 main Shutdown Desligar Reboot Reiniciar Logout Terminar sessão Suspend Suspender core-0.8/shutdown-ui/translations/ro_RO.ts000066400000000000000000000017301417504024300207110ustar00rootroot00000000000000 main Shutdown Reboot Logout Lock screen Suspend core-0.8/shutdown-ui/translations/ru_RU.ts000066400000000000000000000015551417504024300207320ustar00rootroot00000000000000 main Shutdown Выключение Reboot Перезагрузка Logout Выйти Suspend Спящий режим core-0.8/shutdown-ui/translations/si_LK.ts000066400000000000000000000015021417504024300206670ustar00rootroot00000000000000 main Shutdown Reboot Logout නික්මෙන්න Suspend අත්හිටුවන්න core-0.8/shutdown-ui/translations/sk_SK.ts000066400000000000000000000014611417504024300207040ustar00rootroot00000000000000 main Shutdown Vypnúť Reboot Reštartovať Logout Odhlásiť sa Suspend Uspať core-0.8/shutdown-ui/translations/so.ts000066400000000000000000000013701417504024300203120ustar00rootroot00000000000000 main Shutdown Dami Reboot Soo daar Logout Ka bax Suspend Haki core-0.8/shutdown-ui/translations/sr_RS.ts000066400000000000000000000016671417504024300207320ustar00rootroot00000000000000 main Shutdown Isključi Reboot Pokreni ponovo Logout Odjavi se Lock screen Zaključaj ekran Suspend Suspenduj core-0.8/shutdown-ui/translations/sv_SE.ts000066400000000000000000000015031417504024300207060ustar00rootroot00000000000000 main Shutdown Stäng av Reboot Starta om Logout Logga ut Suspend Viloläge core-0.8/shutdown-ui/translations/sw.ts000066400000000000000000000016531417504024300203260ustar00rootroot00000000000000 main Shutdown Zima Reboot Wakisha tena Logout Toka Nje Lock screen Funga skrini Suspend Simamisha core-0.8/shutdown-ui/translations/ta_IN.ts000066400000000000000000000015631417504024300206670ustar00rootroot00000000000000 main Shutdown நிறுத்தவும் Reboot மீண்டும் துவக்கவும் Logout வெளியேறு Suspend இடைநிறுத்து core-0.8/shutdown-ui/translations/tr_TR.ts000066400000000000000000000014561417504024300207300ustar00rootroot00000000000000 main Shutdown Kapat Reboot Yeniden başlat Logout Çıkış yap Suspend Uyku core-0.8/shutdown-ui/translations/uk_UA.ts000066400000000000000000000015311417504024300206740ustar00rootroot00000000000000 main Shutdown Вимкнути Reboot Перезавантаження Logout Вийти з сеансу Suspend Сон core-0.8/shutdown-ui/translations/uz_UZ.ts000066400000000000000000000014151417504024300207450ustar00rootroot00000000000000 main Shutdown Ishni yakunlash Reboot Qayta yuklash Logout Chiqish Suspend Uhlatish core-0.8/shutdown-ui/translations/vi_VN.ts000066400000000000000000000017101417504024300207100ustar00rootroot00000000000000 main Shutdown Tắt nguồn Reboot Khởi động lại Logout Đăng xuất Lock screen Khóa màn hình Suspend Ngủ đông core-0.8/shutdown-ui/translations/zh_CN.ts000066400000000000000000000016451417504024300206770ustar00rootroot00000000000000 main Shutdown 关机 Reboot 重新启动 Logout 注销 Lock screen 锁屏 Suspend 休眠 core-0.8/shutdown-ui/translations/zh_TW.ts000066400000000000000000000014621417504024300207260ustar00rootroot00000000000000 main Shutdown 關閉電腦 Reboot 重新啓動 Logout 登出 Suspend 掛起 core-0.8/xembed-sni-proxy/000077500000000000000000000000001417504024300155235ustar00rootroot00000000000000core-0.8/xembed-sni-proxy/CMakeLists.txt000066400000000000000000000037551417504024300202750ustar00rootroot00000000000000project(cutefish-xembedsniproxy) add_definitions(-DQT_NO_CAST_TO_ASCII -DQT_NO_CAST_FROM_ASCII -DQT_NO_URL_CAST_FROM_STRING -DQT_NO_CAST_FROM_BYTEARRAY) find_package(X11) set_package_properties(X11 PROPERTIES DESCRIPTION "X11 libraries" URL "http://www.x.org" TYPE OPTIONAL PURPOSE "Required for building the X11 based workspace") if(X11_FOUND) find_package(XCB MODULE REQUIRED COMPONENTS XCB RANDR) set_package_properties(XCB PROPERTIES TYPE REQUIRED) if(NOT X11_SM_FOUND) message(FATAL_ERROR "\nThe X11 Session Management (SM) development package could not be found.\nPlease install libSM.\n") endif(NOT X11_SM_FOUND) find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS X11Extras) endif() if(X11_FOUND AND XCB_XCB_FOUND) set(HAVE_X11 1) endif() find_package(XCB REQUIRED COMPONENTS XCB XFIXES DAMAGE COMPOSITE RANDR SHM UTIL IMAGE ) find_package(KF5WindowSystem) set(XCB_LIBS XCB::XCB XCB::XFIXES XCB::DAMAGE XCB::COMPOSITE XCB::RANDR XCB::SHM XCB::UTIL XCB::IMAGE ) set(XEMBED_SNI_PROXY_SOURCES main.cpp fdoselectionmanager.cpp snidbus.cpp sniproxy.cpp debug.cpp xtestsender.cpp ) qt5_add_dbus_adaptor(DBUS_SOURCES org.kde.StatusNotifierItem.xml sniproxy.h SNIProxy) set(statusnotifierwatcher_xml org.kde.StatusNotifierWatcher.xml) qt5_add_dbus_interface(DBUS_SOURCES ${statusnotifierwatcher_xml} statusnotifierwatcher_interface) set_source_files_properties(${DBUS_SOURCES} PROPERTIES SKIP_AUTOGEN ON) add_executable(cutefish-xembedsniproxy ${XEMBED_SNI_PROXY_SOURCES} ${DBUS_SOURCES}) set_package_properties(XCB PROPERTIES TYPE REQUIRED) target_link_libraries(cutefish-xembedsniproxy Qt5::Core Qt5::X11Extras Qt5::DBus KF5::WindowSystem ${XCB_LIBS} ${X11_XTest_LIB} ) install(TARGETS cutefish-xembedsniproxy DESTINATION ${CMAKE_INSTALL_BINDIR}) core-0.8/xembed-sni-proxy/debug.cpp000066400000000000000000000003611417504024300173150ustar00rootroot00000000000000/* This file is part of the KDE project SPDX-FileCopyrightText: 2015 Bhushan Shah SPDX-License-Identifier: LGPL-2.0-or-later */ #include "debug.h" Q_LOGGING_CATEGORY(SNIPROXY, "com.cutefish.sniproxy", QtWarningMsg)core-0.8/xembed-sni-proxy/debug.h000066400000000000000000000004031417504024300167570ustar00rootroot00000000000000/* This file is part of the KDE project SPDX-FileCopyrightText: 2015 Bhushan Shah SPDX-License-Identifier: LGPL-2.0-or-later */ #ifndef DEBUG_H #define DEBUG_H #include Q_DECLARE_LOGGING_CATEGORY(SNIPROXY) #endifcore-0.8/xembed-sni-proxy/fdoselectionmanager.cpp000066400000000000000000000204371417504024300222460ustar00rootroot00000000000000/* Registers as a embed container SPDX-FileCopyrightText: 2015 David Edmundson SPDX-FileCopyrightText: 2019 Konrad Materka SPDX-License-Identifier: LGPL-2.1-or-later */ #include "fdoselectionmanager.h" #include "debug.h" #include #include #include #include #include #include #include #include #include "sniproxy.h" #include "xcbutils.h" #define SYSTEM_TRAY_REQUEST_DOCK 0 #define SYSTEM_TRAY_BEGIN_MESSAGE 1 #define SYSTEM_TRAY_CANCEL_MESSAGE 2 FdoSelectionManager::FdoSelectionManager() : QObject() , m_selectionOwner(new KSelectionOwner(Xcb::atoms->selectionAtom, -1, this)) { qCDebug(SNIPROXY) << "starting"; // we may end up calling QCoreApplication::quit() in this method, at which point we need the event loop running QTimer::singleShot(0, this, &FdoSelectionManager::init); } FdoSelectionManager::~FdoSelectionManager() { qCDebug(SNIPROXY) << "closing"; m_selectionOwner->release(); } void FdoSelectionManager::init() { // load damage extension xcb_connection_t *c = QX11Info::connection(); xcb_prefetch_extension_data(c, &xcb_damage_id); const auto *reply = xcb_get_extension_data(c, &xcb_damage_id); if (reply && reply->present) { m_damageEventBase = reply->first_event; xcb_damage_query_version_unchecked(c, XCB_DAMAGE_MAJOR_VERSION, XCB_DAMAGE_MINOR_VERSION); } else { // no XDamage means qCCritical(SNIPROXY) << "could not load damage extension. Quitting"; qApp->exit(-1); } qApp->installNativeEventFilter(this); connect(m_selectionOwner, &KSelectionOwner::claimedOwnership, this, &FdoSelectionManager::onClaimedOwnership); connect(m_selectionOwner, &KSelectionOwner::failedToClaimOwnership, this, &FdoSelectionManager::onFailedToClaimOwnership); connect(m_selectionOwner, &KSelectionOwner::lostOwnership, this, &FdoSelectionManager::onLostOwnership); m_selectionOwner->claim(false); } bool FdoSelectionManager::addDamageWatch(xcb_window_t client) { qCDebug(SNIPROXY) << "adding damage watch for " << client; xcb_connection_t *c = QX11Info::connection(); const auto attribsCookie = xcb_get_window_attributes_unchecked(c, client); const auto damageId = xcb_generate_id(c); m_damageWatches[client] = damageId; xcb_damage_create(c, damageId, client, XCB_DAMAGE_REPORT_LEVEL_NON_EMPTY); xcb_generic_error_t *error = nullptr; QScopedPointer attr(xcb_get_window_attributes_reply(c, attribsCookie, &error)); QScopedPointer getAttrError(error); uint32_t events = XCB_EVENT_MASK_STRUCTURE_NOTIFY; if (!attr.isNull()) { events = events | attr->your_event_mask; } // if window is already gone, there is no need to handle it. if (getAttrError && getAttrError->error_code == XCB_WINDOW) { return false; } // the event mask will not be removed again. We cannot track whether another component also needs STRUCTURE_NOTIFY (e.g. KWindowSystem). // if we would remove the event mask again, other areas will break. const auto changeAttrCookie = xcb_change_window_attributes_checked(c, client, XCB_CW_EVENT_MASK, &events); QScopedPointer changeAttrError(xcb_request_check(c, changeAttrCookie)); // if window is gone by this point, it will be caught by eventFilter, so no need to check later errors. if (changeAttrError && changeAttrError->error_code == XCB_WINDOW) { return false; } return true; } bool FdoSelectionManager::nativeEventFilter(const QByteArray &eventType, void *message, long int *result) { Q_UNUSED(result) if (eventType != "xcb_generic_event_t") { return false; } xcb_generic_event_t *ev = static_cast(message); const auto responseType = XCB_EVENT_RESPONSE_TYPE(ev); if (responseType == XCB_CLIENT_MESSAGE) { const auto ce = reinterpret_cast(ev); if (ce->type == Xcb::atoms->opcodeAtom) { switch (ce->data.data32[1]) { case SYSTEM_TRAY_REQUEST_DOCK: dock(ce->data.data32[2]); return true; } } } else if (responseType == XCB_UNMAP_NOTIFY) { const auto unmappedWId = reinterpret_cast(ev)->window; if (m_proxies.contains(unmappedWId)) { undock(unmappedWId); } } else if (responseType == XCB_DESTROY_NOTIFY) { const auto destroyedWId = reinterpret_cast(ev)->window; if (m_proxies.contains(destroyedWId)) { undock(destroyedWId); } } else if (responseType == m_damageEventBase + XCB_DAMAGE_NOTIFY) { const auto damagedWId = reinterpret_cast(ev)->drawable; const auto sniProxy = m_proxies.value(damagedWId); if (sniProxy) { sniProxy->update(); xcb_damage_subtract(QX11Info::connection(), m_damageWatches[damagedWId], XCB_NONE, XCB_NONE); } } else if (responseType == XCB_CONFIGURE_REQUEST) { const auto event = reinterpret_cast(ev); const auto sniProxy = m_proxies.value(event->window); if (sniProxy) { // The embedded window tries to move or resize. Ignore move, handle resize only. if ((event->value_mask & XCB_CONFIG_WINDOW_WIDTH) || (event->value_mask & XCB_CONFIG_WINDOW_HEIGHT)) { sniProxy->resizeWindow(event->width, event->height); } } } else if (responseType == XCB_VISIBILITY_NOTIFY) { const auto event = reinterpret_cast(ev); // it's possible that something showed our container window, we have to hide it // workaround for BUG 357443: when KWin is restarted, container window is shown on top if (event->state == XCB_VISIBILITY_UNOBSCURED) { for (auto sniProxy : m_proxies.values()) { sniProxy->hideContainerWindow(event->window); } } } return false; } void FdoSelectionManager::dock(xcb_window_t winId) { qCDebug(SNIPROXY) << "trying to dock window " << winId; if (m_proxies.contains(winId)) { return; } if (addDamageWatch(winId)) { m_proxies[winId] = new SNIProxy(winId, this); } } void FdoSelectionManager::undock(xcb_window_t winId) { qCDebug(SNIPROXY) << "trying to undock window " << winId; if (!m_proxies.contains(winId)) { return; } m_proxies[winId]->deleteLater(); m_proxies.remove(winId); } void FdoSelectionManager::onClaimedOwnership() { qCDebug(SNIPROXY) << "Manager selection claimed"; setSystemTrayVisual(); } void FdoSelectionManager::onFailedToClaimOwnership() { qCWarning(SNIPROXY) << "failed to claim ownership of Systray Manager"; qApp->exit(-1); } void FdoSelectionManager::onLostOwnership() { qCWarning(SNIPROXY) << "lost ownership of Systray Manager"; qApp->exit(-1); } void FdoSelectionManager::setSystemTrayVisual() { xcb_connection_t *c = QX11Info::connection(); auto screen = xcb_setup_roots_iterator(xcb_get_setup(c)).data; auto trayVisual = screen->root_visual; xcb_depth_iterator_t depth_iterator = xcb_screen_allowed_depths_iterator(screen); xcb_depth_t *depth = nullptr; while (depth_iterator.rem) { if (depth_iterator.data->depth == 32) { depth = depth_iterator.data; break; } xcb_depth_next(&depth_iterator); } if (depth) { xcb_visualtype_iterator_t visualtype_iterator = xcb_depth_visuals_iterator(depth); while (visualtype_iterator.rem) { xcb_visualtype_t *visualtype = visualtype_iterator.data; if (visualtype->_class == XCB_VISUAL_CLASS_TRUE_COLOR) { trayVisual = visualtype->visual_id; break; } xcb_visualtype_next(&visualtype_iterator); } } xcb_change_property(c, XCB_PROP_MODE_REPLACE, m_selectionOwner->ownerWindow(), Xcb::atoms->visualAtom, XCB_ATOM_VISUALID, 32, 1, &trayVisual); } core-0.8/xembed-sni-proxy/fdoselectionmanager.h000066400000000000000000000020421417504024300217030ustar00rootroot00000000000000/* Registers as a embed container SPDX-FileCopyrightText: 2015 David Edmundson SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once #include #include #include #include class KSelectionOwner; class SNIProxy; class FdoSelectionManager : public QObject, public QAbstractNativeEventFilter { Q_OBJECT public: FdoSelectionManager(); ~FdoSelectionManager() override; protected: bool nativeEventFilter(const QByteArray &eventType, void *message, long *result) override; private Q_SLOTS: void onClaimedOwnership(); void onFailedToClaimOwnership(); void onLostOwnership(); private: void init(); bool addDamageWatch(xcb_window_t client); void dock(xcb_window_t embed_win); void undock(xcb_window_t client); void setSystemTrayVisual(); uint8_t m_damageEventBase; QHash m_damageWatches; QHash m_proxies; KSelectionOwner *m_selectionOwner; }; core-0.8/xembed-sni-proxy/main.cpp000066400000000000000000000026771417504024300171670ustar00rootroot00000000000000/* Main SPDX-FileCopyrightText: 2015 David Edmundson SPDX-License-Identifier: LGPL-2.1-or-later */ #include #include #include "fdoselectionmanager.h" #include "debug.h" #include "snidbus.h" #include "xcbutils.h" #include #include namespace Xcb { Xcb::Atoms *atoms; } int main(int argc, char **argv) { // the whole point of this is to interact with X, if we are in any other session, force trying to connect to X // if the QPA can't load xcb, this app is useless anyway. qputenv("QT_QPA_PLATFORM", "xcb"); QGuiApplication::setDesktopSettingsAware(false); QGuiApplication app(argc, argv); if (!KWindowSystem::isPlatformX11()) { qFatal("xembed-sni-proxy is only useful XCB. Aborting"); } auto disableSessionManagement = [](QSessionManager &sm) { sm.setRestartHint(QSessionManager::RestartNever); }; QObject::connect(&app, &QGuiApplication::commitDataRequest, disableSessionManagement); QObject::connect(&app, &QGuiApplication::saveStateRequest, disableSessionManagement); app.setQuitOnLastWindowClosed(false); qDBusRegisterMetaType(); qDBusRegisterMetaType(); qDBusRegisterMetaType(); Xcb::atoms = new Xcb::Atoms(); FdoSelectionManager manager; auto rc = app.exec(); delete Xcb::atoms; return rc; } core-0.8/xembed-sni-proxy/org.kde.StatusNotifierItem.xml000066400000000000000000000037171417504024300234070ustar00rootroot00000000000000 core-0.8/xembed-sni-proxy/org.kde.StatusNotifierWatcher.xml000066400000000000000000000021771417504024300241050ustar00rootroot00000000000000 core-0.8/xembed-sni-proxy/snidbus.cpp000066400000000000000000000067361417504024300177120ustar00rootroot00000000000000/* SNI DBus Serialisers SPDX-FileCopyrightText: 2015 David Edmundson SPDX-FileCopyrightText: 2009 Marco Martin SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL */ #include "snidbus.h" #include #include // mostly copied from KStatusNotiferItemDbus.cpps from knotification KDbusImageStruct::KDbusImageStruct() { } KDbusImageStruct::KDbusImageStruct(const QImage &image) { width = image.size().width(); height = image.size().height(); if (image.format() == QImage::Format_ARGB32) { data = QByteArray((char *)image.bits(), image.sizeInBytes()); } else { QImage image32 = image.convertToFormat(QImage::Format_ARGB32); data = QByteArray((char *)image32.bits(), image32.sizeInBytes()); } // swap to network byte order if we are little endian if (QSysInfo::ByteOrder == QSysInfo::LittleEndian) { quint32 *uintBuf = (quint32 *)data.data(); for (uint i = 0; i < data.size() / sizeof(quint32); ++i) { *uintBuf = qToBigEndian(*uintBuf); ++uintBuf; } } } // Marshall the ImageStruct data into a D-BUS argument const QDBusArgument &operator<<(QDBusArgument &argument, const KDbusImageStruct &icon) { argument.beginStructure(); argument << icon.width; argument << icon.height; argument << icon.data; argument.endStructure(); return argument; } // Retrieve the ImageStruct data from the D-BUS argument const QDBusArgument &operator>>(const QDBusArgument &argument, KDbusImageStruct &icon) { qint32 width; qint32 height; QByteArray data; argument.beginStructure(); argument >> width; argument >> height; argument >> data; argument.endStructure(); icon.width = width; icon.height = height; icon.data = data; return argument; } // Marshall the ImageVector data into a D-BUS argument const QDBusArgument &operator<<(QDBusArgument &argument, const KDbusImageVector &iconVector) { argument.beginArray(qMetaTypeId()); for (int i = 0; i < iconVector.size(); ++i) { argument << iconVector[i]; } argument.endArray(); return argument; } // Retrieve the ImageVector data from the D-BUS argument const QDBusArgument &operator>>(const QDBusArgument &argument, KDbusImageVector &iconVector) { argument.beginArray(); iconVector.clear(); while (!argument.atEnd()) { KDbusImageStruct element; argument >> element; iconVector.append(element); } argument.endArray(); return argument; } // Marshall the ToolTipStruct data into a D-BUS argument const QDBusArgument &operator<<(QDBusArgument &argument, const KDbusToolTipStruct &toolTip) { argument.beginStructure(); argument << toolTip.icon; argument << toolTip.image; argument << toolTip.title; argument << toolTip.subTitle; argument.endStructure(); return argument; } // Retrieve the ToolTipStruct data from the D-BUS argument const QDBusArgument &operator>>(const QDBusArgument &argument, KDbusToolTipStruct &toolTip) { QString icon; KDbusImageVector image; QString title; QString subTitle; argument.beginStructure(); argument >> icon; argument >> image; argument >> title; argument >> subTitle; argument.endStructure(); toolTip.icon = icon; toolTip.image = image; toolTip.title = title; toolTip.subTitle = subTitle; return argument; } core-0.8/xembed-sni-proxy/snidbus.h000066400000000000000000000024521417504024300173460ustar00rootroot00000000000000/* SNI Dbus serialisers Copyright 2015 David Edmundson SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL */ #pragma once #include #include #include #include #include // Custom message type for DBus struct KDbusImageStruct { KDbusImageStruct(); KDbusImageStruct(const QImage &image); int width; int height; QByteArray data; }; typedef QVector KDbusImageVector; struct KDbusToolTipStruct { QString icon; KDbusImageVector image; QString title; QString subTitle; }; const QDBusArgument &operator<<(QDBusArgument &argument, const KDbusImageStruct &icon); const QDBusArgument &operator>>(const QDBusArgument &argument, KDbusImageStruct &icon); Q_DECLARE_METATYPE(KDbusImageStruct) const QDBusArgument &operator<<(QDBusArgument &argument, const KDbusImageVector &iconVector); const QDBusArgument &operator>>(const QDBusArgument &argument, KDbusImageVector &iconVector); Q_DECLARE_METATYPE(KDbusImageVector) const QDBusArgument &operator<<(QDBusArgument &argument, const KDbusToolTipStruct &toolTip); const QDBusArgument &operator>>(const QDBusArgument &argument, KDbusToolTipStruct &toolTip); Q_DECLARE_METATYPE(KDbusToolTipStruct) core-0.8/xembed-sni-proxy/sniproxy.cpp000066400000000000000000000514011417504024300201230ustar00rootroot00000000000000/* Holds one embedded window, registers as DBus entry SPDX-FileCopyrightText: 2015 David Edmundson SPDX-FileCopyrightText: 2019 Konrad Materka SPDX-License-Identifier: LGPL-2.1-or-later */ #include "sniproxy.h" #include #include #include #include "debug.h" #include "xcbutils.h" #include #include #include #include #include #include #include #include "statusnotifieritemadaptor.h" #include "statusnotifierwatcher_interface.h" #include "xtestsender.h" //#define VISUAL_DEBUG #define SNI_WATCHER_SERVICE_NAME "org.kde.StatusNotifierWatcher" #define SNI_WATCHER_PATH "/StatusNotifierWatcher" static uint16_t s_embedSize = 32; // max size of window to embed. We no longer resize the embedded window as Chromium acts stupidly. static unsigned int XEMBED_VERSION = 0; int SNIProxy::s_serviceCount = 0; void xembed_message_send(xcb_window_t towin, long message, long d1, long d2, long d3) { xcb_client_message_event_t ev; ev.response_type = XCB_CLIENT_MESSAGE; ev.window = towin; ev.format = 32; ev.data.data32[0] = XCB_CURRENT_TIME; ev.data.data32[1] = message; ev.data.data32[2] = d1; ev.data.data32[3] = d2; ev.data.data32[4] = d3; ev.type = Xcb::atoms->xembedAtom; xcb_send_event(QX11Info::connection(), false, towin, XCB_EVENT_MASK_NO_EVENT, (char *)&ev); } SNIProxy::SNIProxy(xcb_window_t wid, QObject *parent) : QObject(parent) , // Work round a bug in our SNIWatcher with multiple SNIs per connection. // there is an undocumented feature that you can register an SNI by path, however it doesn't detect an object on a service being removed, only the entire // service closing instead lets use one DBus connection per SNI m_dbus(QDBusConnection::connectToBus(QDBusConnection::SessionBus, QStringLiteral("XembedSniProxy%1").arg(s_serviceCount++))) , m_windowId(wid) , sendingClickEvent(false) , m_injectMode(Direct) { // create new SNI new StatusNotifierItemAdaptor(this); m_dbus.registerObject(QStringLiteral("/StatusNotifierItem"), this); auto statusNotifierWatcher = new org::kde::StatusNotifierWatcher(QStringLiteral(SNI_WATCHER_SERVICE_NAME), QStringLiteral(SNI_WATCHER_PATH), QDBusConnection::sessionBus(), this); auto reply = statusNotifierWatcher->RegisterStatusNotifierItem(m_dbus.baseService()); reply.waitForFinished(); if (reply.isError()) { qCWarning(SNIPROXY) << "could not register SNI:" << reply.error().message(); } auto c = QX11Info::connection(); // create a container window auto screen = xcb_setup_roots_iterator(xcb_get_setup(c)).data; m_containerWid = xcb_generate_id(c); uint32_t values[3]; uint32_t mask = XCB_CW_BACK_PIXEL | XCB_CW_OVERRIDE_REDIRECT | XCB_CW_EVENT_MASK; values[0] = screen->black_pixel; // draw a solid background so the embedded icon doesn't get garbage in it values[1] = true; // bypass wM values[2] = XCB_EVENT_MASK_VISIBILITY_CHANGE | // receive visibility change, to handle KWin restart #357443 // Redirect and handle structure (size, position) requests from the embedded window. XCB_EVENT_MASK_STRUCTURE_NOTIFY | XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY | XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT; xcb_create_window(c, /* connection */ XCB_COPY_FROM_PARENT, /* depth */ m_containerWid, /* window Id */ screen->root, /* parent window */ 0, 0, /* x, y */ s_embedSize, s_embedSize, /* width, height */ 0, /* border_width */ XCB_WINDOW_CLASS_INPUT_OUTPUT, /* class */ screen->root_visual, /* visual */ mask, values); /* masks */ /* We need the window to exist and be mapped otherwise the child won't render it's contents We also need it to exist in the right place to get the clicks working as GTK will check sendEvent locations to see if our window is in the right place. So even though our contents are drawn via compositing we still put this window in the right place We can't composite it away anything parented owned by the root window (apparently) Stack Under works in the non composited case, but it doesn't seem to work in kwin's composited case (probably need set relevant NETWM hint) As a last resort set opacity to 0 just to make sure this container never appears */ #ifndef VISUAL_DEBUG stackContainerWindow(XCB_STACK_MODE_BELOW); NETWinInfo wm(c, m_containerWid, screen->root, NET::Properties(), NET::Properties2()); wm.setOpacity(0); #endif xcb_flush(c); xcb_map_window(c, m_containerWid); xcb_reparent_window(c, wid, m_containerWid, 0, 0); /* * Render the embedded window offscreen */ xcb_composite_redirect_window(c, wid, XCB_COMPOSITE_REDIRECT_MANUAL); /* we grab the window, but also make sure it's automatically reparented back * to the root window if we should die. */ xcb_change_save_set(c, XCB_SET_MODE_INSERT, wid); // tell client we're embedding it xembed_message_send(wid, XEMBED_EMBEDDED_NOTIFY, 0, m_containerWid, XEMBED_VERSION); // move window we're embedding const uint32_t windowMoveConfigVals[2] = {0, 0}; xcb_configure_window(c, wid, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, windowMoveConfigVals); QSize clientWindowSize = calculateClientWindowSize(); // show the embedded window otherwise nothing happens xcb_map_window(c, wid); xcb_clear_area(c, 0, wid, 0, 0, clientWindowSize.width(), clientWindowSize.height()); xcb_flush(c); // guess which input injection method to use // we can either send an X event to the client or XTest // some don't support direct X events (GTK3/4), and some don't support XTest because reasons // note also some clients might not have the XTest extension. We may as well assume it does and just fail to send later. // we query if the client selected button presses in the event mask // if the client does supports that we send directly, otherwise we'll use xtest auto waCookie = xcb_get_window_attributes(c, wid); QScopedPointer windowAttributes(xcb_get_window_attributes_reply(c, waCookie, nullptr)); if (windowAttributes && !(windowAttributes->all_event_masks & XCB_EVENT_MASK_BUTTON_PRESS)) { m_injectMode = XTest; } // there's no damage event for the first paint, and sometimes it's not drawn immediately // not ideal, but it works better than nothing // test with xchat before changing QTimer::singleShot(500, this, &SNIProxy::update); } SNIProxy::~SNIProxy() { auto c = QX11Info::connection(); xcb_destroy_window(c, m_containerWid); QDBusConnection::disconnectFromBus(m_dbus.name()); } void SNIProxy::update() { const QImage image = getImageNonComposite(); if (image.isNull()) { qCDebug(SNIPROXY) << "No xembed icon for" << m_windowId << Title(); return; } int w = image.width(); int h = image.height(); m_pixmap = QPixmap::fromImage(image); if (w > s_embedSize || h > s_embedSize) { qCDebug(SNIPROXY) << "Scaling pixmap of window" << m_windowId << Title() << "from w*h" << w << h; m_pixmap = m_pixmap.scaled(s_embedSize, s_embedSize, Qt::KeepAspectRatio, Qt::SmoothTransformation); } emit NewIcon(); emit NewToolTip(); } void SNIProxy::resizeWindow(const uint16_t width, const uint16_t height) const { auto connection = QX11Info::connection(); uint16_t widthNormalized = std::min(width, s_embedSize); uint16_t heighNormalized = std::min(height, s_embedSize); const uint32_t windowSizeConfigVals[2] = {widthNormalized, heighNormalized}; xcb_configure_window(connection, m_windowId, XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT, windowSizeConfigVals); xcb_flush(connection); } void SNIProxy::hideContainerWindow(xcb_window_t windowId) const { if (m_containerWid == windowId && !sendingClickEvent) { qDebug() << "Container window visible, stack below"; stackContainerWindow(XCB_STACK_MODE_BELOW); } } QSize SNIProxy::calculateClientWindowSize() const { auto c = QX11Info::connection(); auto cookie = xcb_get_geometry(c, m_windowId); QScopedPointer clientGeom(xcb_get_geometry_reply(c, cookie, nullptr)); QSize clientWindowSize; if (clientGeom) { clientWindowSize = QSize(clientGeom->width, clientGeom->height); } // if the window is a clearly stupid size resize to be something sensible // this is needed as chromium and such when resized just fill the icon with transparent space and only draw in the middle // however KeePass2 does need this as by default the window size is 273px wide and is not transparent // use an arbitrary heuristic to make sure icons are always sensible if (clientWindowSize.isEmpty() || clientWindowSize.width() > s_embedSize || clientWindowSize.height() > s_embedSize) { qCDebug(SNIPROXY) << "Resizing window" << m_windowId << Title() << "from w*h" << clientWindowSize; resizeWindow(s_embedSize, s_embedSize); clientWindowSize = QSize(s_embedSize, s_embedSize); } return clientWindowSize; } void sni_cleanup_xcb_image(void *data) { xcb_image_destroy(static_cast(data)); } bool SNIProxy::isTransparentImage(const QImage &image) const { int w = image.width(); int h = image.height(); // check for the center and sub-center pixels first and avoid full image scan if (!(qAlpha(image.pixel(w >> 1, h >> 1)) + qAlpha(image.pixel(w >> 2, h >> 2)) == 0)) return false; // skip scan altogether if sub-center pixel found to be opaque // and break out from the outer loop too on full scan for (int x = 0; x < w; ++x) { for (int y = 0; y < h; ++y) { if (qAlpha(image.pixel(x, y))) { // Found an opaque pixel. return false; } } } return true; } QImage SNIProxy::getImageNonComposite() const { auto c = QX11Info::connection(); QSize clientWindowSize = calculateClientWindowSize(); xcb_image_t *image = xcb_image_get(c, m_windowId, 0, 0, clientWindowSize.width(), clientWindowSize.height(), 0xFFFFFFFF, XCB_IMAGE_FORMAT_Z_PIXMAP); // Don't hook up cleanup yet, we may use a different QImage after all QImage naiveConversion; if (image) { naiveConversion = QImage(image->data, image->width, image->height, QImage::Format_ARGB32); } else { qCDebug(SNIPROXY) << "Skip NULL image returned from xcb_image_get() for" << m_windowId << Title(); return QImage(); } if (isTransparentImage(naiveConversion)) { QImage elaborateConversion = QImage(convertFromNative(image)); // Update icon only if it is at least partially opaque. // This is just a workaround for X11 bug: xembed icon may suddenly // become transparent for a one or few frames. Reproducible at least // with WINE applications. if (isTransparentImage(elaborateConversion)) { qCDebug(SNIPROXY) << "Skip transparent xembed icon for" << m_windowId << Title(); return QImage(); } else return elaborateConversion; } else { // Now we are sure we can eventually delete the xcb_image_t with this version return QImage(image->data, image->width, image->height, image->stride, QImage::Format_ARGB32, sni_cleanup_xcb_image, image); } } QImage SNIProxy::convertFromNative(xcb_image_t *xcbImage) const { QImage::Format format = QImage::Format_Invalid; switch (xcbImage->depth) { case 1: format = QImage::Format_MonoLSB; break; case 16: format = QImage::Format_RGB16; break; case 24: format = QImage::Format_RGB32; break; case 30: { // Qt doesn't have a matching image format. We need to convert manually quint32 *pixels = reinterpret_cast(xcbImage->data); for (uint i = 0; i < (xcbImage->size / 4); i++) { int r = (pixels[i] >> 22) & 0xff; int g = (pixels[i] >> 12) & 0xff; int b = (pixels[i] >> 2) & 0xff; pixels[i] = qRgba(r, g, b, 0xff); } // fall through, Qt format is still Format_ARGB32_Premultiplied Q_FALLTHROUGH(); } case 32: format = QImage::Format_ARGB32_Premultiplied; break; default: return QImage(); // we don't know } QImage image(xcbImage->data, xcbImage->width, xcbImage->height, xcbImage->stride, format, sni_cleanup_xcb_image, xcbImage); if (image.isNull()) { return QImage(); } if (format == QImage::Format_RGB32 && xcbImage->bpp == 32) { QImage m = image.createHeuristicMask(); QBitmap mask(QPixmap::fromImage(m)); QPixmap p = QPixmap::fromImage(image); p.setMask(mask); image = p.toImage(); } // work around an abort in QImage::color if (image.format() == QImage::Format_MonoLSB) { image.setColorCount(2); image.setColor(0, QColor(Qt::white).rgb()); image.setColor(1, QColor(Qt::black).rgb()); } return image; } /* Wine is using XWindow Shape Extension for transparent tray icons. We need to find first clickable point starting from top-left. */ QPoint SNIProxy::calculateClickPoint() const { QPoint clickPoint = QPoint(0, 0); auto c = QX11Info::connection(); // request extent to check if shape has been set xcb_shape_query_extents_cookie_t extentsCookie = xcb_shape_query_extents(c, m_windowId); // at the same time make the request for rectangles (even if this request isn't needed) xcb_shape_get_rectangles_cookie_t rectaglesCookie = xcb_shape_get_rectangles(c, m_windowId, XCB_SHAPE_SK_BOUNDING); QScopedPointer extentsReply(xcb_shape_query_extents_reply(c, extentsCookie, nullptr)); QScopedPointer rectanglesReply(xcb_shape_get_rectangles_reply(c, rectaglesCookie, nullptr)); if (!extentsReply || !rectanglesReply || !extentsReply->bounding_shaped) { return clickPoint; } xcb_rectangle_t *rectangles = xcb_shape_get_rectangles_rectangles(rectanglesReply.get()); if (!rectangles) { return clickPoint; } const QImage image = getImageNonComposite(); double minLength = sqrt(pow(image.height(), 2) + pow(image.width(), 2)); const int nRectangles = xcb_shape_get_rectangles_rectangles_length(rectanglesReply.get()); for (int i = 0; i < nRectangles; ++i) { double length = sqrt(pow(rectangles[i].x, 2) + pow(rectangles[i].y, 2)); if (length < minLength) { minLength = length; clickPoint = QPoint(rectangles[i].x, rectangles[i].y); } } qCDebug(SNIPROXY) << "Click point:" << clickPoint; return clickPoint; } void SNIProxy::stackContainerWindow(const uint32_t stackMode) const { auto c = QX11Info::connection(); const uint32_t stackData[] = {stackMode}; xcb_configure_window(c, m_containerWid, XCB_CONFIG_WINDOW_STACK_MODE, stackData); } //____________properties__________ QString SNIProxy::Category() const { return QStringLiteral("ApplicationStatus"); } QString SNIProxy::Id() const { const auto title = Title(); // we always need /some/ ID so if no window title exists, just use the winId. if (title.isEmpty()) { return QString::number(m_windowId); } return title; } KDbusImageVector SNIProxy::IconPixmap() const { KDbusImageStruct dbusImage(m_pixmap.toImage()); return KDbusImageVector() << dbusImage; } bool SNIProxy::ItemIsMenu() const { return false; } QString SNIProxy::Status() const { return QStringLiteral("Active"); } QString SNIProxy::Title() const { KWindowInfo window(m_windowId, NET::WMName); return window.name(); } int SNIProxy::WindowId() const { return m_windowId; } //____________actions_____________ void SNIProxy::Activate(int x, int y) { sendClick(XCB_BUTTON_INDEX_1, x, y); } void SNIProxy::SecondaryActivate(int x, int y) { sendClick(XCB_BUTTON_INDEX_2, x, y); } void SNIProxy::ContextMenu(int x, int y) { sendClick(XCB_BUTTON_INDEX_3, x, y); } void SNIProxy::Scroll(int delta, const QString &orientation) { if (orientation == QLatin1String("vertical")) { sendClick(delta > 0 ? XCB_BUTTON_INDEX_4 : XCB_BUTTON_INDEX_5, 0, 0); } else { sendClick(delta > 0 ? 6 : 7, 0, 0); } } void SNIProxy::sendClick(uint8_t mouseButton, int x, int y) { // it's best not to look at this code // GTK doesn't like send_events and double checks the mouse position matches where the window is and is top level // in order to solve this we move the embed container over to where the mouse is then replay the event using send_event // if patching, test with xchat + xchat context menus // note x,y are not actually where the mouse is, but the plasmoid // ideally we should make this match the plasmoid hit area qCDebug(SNIPROXY) << "Received click" << mouseButton << "with passed x*y" << x << y; sendingClickEvent = true; auto c = QX11Info::connection(); auto cookieSize = xcb_get_geometry(c, m_windowId); QScopedPointer clientGeom(xcb_get_geometry_reply(c, cookieSize, nullptr)); if (!clientGeom) { return; } auto cookie = xcb_query_pointer(c, m_windowId); QScopedPointer pointer(xcb_query_pointer_reply(c, cookie, nullptr)); /*qCDebug(SNIPROXY) << "samescreen" << pointer->same_screen << endl << "root x*y" << pointer->root_x << pointer->root_y << endl << "win x*y" << pointer->win_x << pointer->win_y;*/ // move our window so the mouse is within its geometry uint32_t configVals[2] = {0, 0}; const QPoint clickPoint = calculateClickPoint(); if (mouseButton >= XCB_BUTTON_INDEX_4) { // scroll event, take pointer position configVals[0] = pointer->root_x; configVals[1] = pointer->root_y; } else { if (pointer->root_x > x + clientGeom->width) configVals[0] = pointer->root_x - clientGeom->width + 1; else configVals[0] = static_cast(x - clickPoint.x()); if (pointer->root_y > y + clientGeom->height) configVals[1] = pointer->root_y - clientGeom->height + 1; else configVals[1] = static_cast(y - clickPoint.y()); } xcb_configure_window(c, m_containerWid, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, configVals); // pull window up stackContainerWindow(XCB_STACK_MODE_ABOVE); // mouse down if (m_injectMode == Direct) { xcb_button_press_event_t *event = new xcb_button_press_event_t; memset(event, 0x00, sizeof(xcb_button_press_event_t)); event->response_type = XCB_BUTTON_PRESS; event->event = m_windowId; event->time = QX11Info::getTimestamp(); event->same_screen = 1; event->root = QX11Info::appRootWindow(); event->root_x = x; event->root_y = y; event->event_x = static_cast(clickPoint.x()); event->event_y = static_cast(clickPoint.y()); event->child = 0; event->state = 0; event->detail = mouseButton; xcb_send_event(c, false, m_windowId, XCB_EVENT_MASK_BUTTON_PRESS, (char *)event); delete event; } else { sendXTestPressed(QX11Info::display(), mouseButton); } // mouse up if (m_injectMode == Direct) { xcb_button_release_event_t *event = new xcb_button_release_event_t; memset(event, 0x00, sizeof(xcb_button_release_event_t)); event->response_type = XCB_BUTTON_RELEASE; event->event = m_windowId; event->time = QX11Info::getTimestamp(); event->same_screen = 1; event->root = QX11Info::appRootWindow(); event->root_x = x; event->root_y = y; event->event_x = static_cast(clickPoint.x()); event->event_y = static_cast(clickPoint.y()); event->child = 0; event->state = 0; event->detail = mouseButton; xcb_send_event(c, false, m_windowId, XCB_EVENT_MASK_BUTTON_RELEASE, (char *)event); delete event; } else { sendXTestReleased(QX11Info::display(), mouseButton); } #ifndef VISUAL_DEBUG stackContainerWindow(XCB_STACK_MODE_BELOW); #endif sendingClickEvent = false; } core-0.8/xembed-sni-proxy/sniproxy.h000066400000000000000000000075171417504024300176010ustar00rootroot00000000000000/* Holds one embedded window, registers as DBus entry SPDX-FileCopyrightText: 2015 David Edmundson SPDX-FileCopyrightText: 2019 Konrad Materka SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once #include #include #include #include #include #include #include #include #include "snidbus.h" class SNIProxy : public QObject { Q_OBJECT Q_PROPERTY(QString Category READ Category) Q_PROPERTY(QString Id READ Id) Q_PROPERTY(QString Title READ Title) Q_PROPERTY(QString Status READ Status) Q_PROPERTY(int WindowId READ WindowId) Q_PROPERTY(bool ItemIsMenu READ ItemIsMenu) Q_PROPERTY(KDbusImageVector IconPixmap READ IconPixmap) public: explicit SNIProxy(xcb_window_t wid, QObject *parent = nullptr); ~SNIProxy() override; void update(); void resizeWindow(const uint16_t width, const uint16_t height) const; void hideContainerWindow(xcb_window_t windowId) const; /** * @return the category of the application associated to this item * @see Category */ QString Category() const; /** * @return the id of this item */ QString Id() const; /** * @return the title of this item */ QString Title() const; /** * @return The status of this item * @see Status */ QString Status() const; /** * @return The id of the main window of the application that controls the item */ int WindowId() const; /** * @return The item only support the context menu, the visualization should prefer sending ContextMenu() instead of Activate() */ bool ItemIsMenu() const; /** * @return a serialization of the icon data */ KDbusImageVector IconPixmap() const; public Q_SLOTS: // interaction /** * Shows the context menu associated to this item * at the desired screen position */ void ContextMenu(int x, int y); /** * Shows the main widget and try to position it on top * of the other windows, if the widget is already visible, hide it. */ void Activate(int x, int y); /** * The user activated the item in an alternate way (for instance with middle mouse button, this depends from the systray implementation) */ void SecondaryActivate(int x, int y); /** * Inform this item that the mouse wheel was used on its representation */ void Scroll(int delta, const QString &orientation); Q_SIGNALS: /** * Inform the systemtray that the own main icon has been changed, * so should be reloaded */ void NewIcon(); /** * Inform the systemtray that there is a new icon to be used as overlay */ void NewOverlayIcon(); /** * Inform the systemtray that the requesting attention icon * has been changed, so should be reloaded */ void NewAttentionIcon(); /** * Inform the systemtray that something in the tooltip has been changed */ void NewToolTip(); /** * Signal the new status when it has been changed * @see Status */ void NewStatus(const QString &status); private: enum InjectMode { Direct, XTest, }; QSize calculateClientWindowSize() const; void sendClick(uint8_t mouseButton, int x, int y); QImage getImageNonComposite() const; bool isTransparentImage(const QImage &image) const; QImage convertFromNative(xcb_image_t *xcbImage) const; QPoint calculateClickPoint() const; void stackContainerWindow(const uint32_t stackMode) const; QDBusConnection m_dbus; xcb_window_t m_windowId; xcb_window_t m_containerWid; static int s_serviceCount; QPixmap m_pixmap; bool sendingClickEvent; InjectMode m_injectMode; }; core-0.8/xembed-sni-proxy/xcbutils.h000066400000000000000000000053501417504024300175340ustar00rootroot00000000000000/* SPDX-FileCopyrightText: 2012, 2013 Martin Graesslin SPDX-FileCopyrightText: 2015 David Edmudson SPDX-License-Identifier: GPL-2.0-or-later */ #pragma once #include #include #include #include #include #include #include #include #include #include /** XEMBED messages */ #define XEMBED_EMBEDDED_NOTIFY 0 #define XEMBED_WINDOW_ACTIVATE 1 #define XEMBED_WINDOW_DEACTIVATE 2 #define XEMBED_REQUEST_FOCUS 3 #define XEMBED_FOCUS_IN 4 #define XEMBED_FOCUS_OUT 5 #define XEMBED_FOCUS_NEXT 6 #define XEMBED_FOCUS_PREV 7 namespace Xcb { typedef xcb_window_t WindowId; template using ScopedCPointer = QScopedPointer; class Atom { public: explicit Atom(const QByteArray &name, bool onlyIfExists = false, xcb_connection_t *c = QX11Info::connection()) : m_connection(c) , m_retrieved(false) , m_cookie(xcb_intern_atom_unchecked(m_connection, onlyIfExists, name.length(), name.constData())) , m_atom(XCB_ATOM_NONE) , m_name(name) { } Atom() = delete; Atom(const Atom &) = delete; ~Atom() { if (!m_retrieved && m_cookie.sequence) { xcb_discard_reply(m_connection, m_cookie.sequence); } } operator xcb_atom_t() const { (const_cast(this))->getReply(); return m_atom; } bool isValid() { getReply(); return m_atom != XCB_ATOM_NONE; } bool isValid() const { (const_cast(this))->getReply(); return m_atom != XCB_ATOM_NONE; } inline const QByteArray &name() const { return m_name; } private: void getReply() { if (m_retrieved || !m_cookie.sequence) { return; } ScopedCPointer reply(xcb_intern_atom_reply(m_connection, m_cookie, nullptr)); if (!reply.isNull()) { m_atom = reply->atom; } m_retrieved = true; } xcb_connection_t *m_connection; bool m_retrieved; xcb_intern_atom_cookie_t m_cookie; xcb_atom_t m_atom; QByteArray m_name; }; class Atoms { public: Atoms() : xembedAtom("_XEMBED") , selectionAtom(xcb_atom_name_by_screen("_NET_SYSTEM_TRAY", QX11Info::appScreen())) , opcodeAtom("_NET_SYSTEM_TRAY_OPCODE") , messageData("_NET_SYSTEM_TRAY_MESSAGE_DATA") , visualAtom("_NET_SYSTEM_TRAY_VISUAL") { } Atom xembedAtom; Atom selectionAtom; Atom opcodeAtom; Atom messageData; Atom visualAtom; }; extern Atoms *atoms; } // namespace Xcb core-0.8/xembed-sni-proxy/xtestsender.cpp000066400000000000000000000007431417504024300206030ustar00rootroot00000000000000/* Wrap XLIB code in a new file as it defines keywords that conflict with Qt SPDX-FileCopyrightText: 2017 David Edmundson SPDX-License-Identifier: LGPL-2.1-or-later */ #include "xtestsender.h" #include void sendXTestPressed(Display *display, int button) { XTestFakeButtonEvent(display, button, true, 0); } void sendXTestReleased(Display *display, int button) { XTestFakeButtonEvent(display, button, false, 0); } core-0.8/xembed-sni-proxy/xtestsender.h000066400000000000000000000005471417504024300202520ustar00rootroot00000000000000/* Wrap XLIB code in a new file as it defines keywords that conflict with Qt SPDX-FileCopyrightText: 2017 David Edmundson SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once typedef struct _XDisplay Display; void sendXTestPressed(Display *display, int button); void sendXTestReleased(Display *display, int button);