Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
GNOME:Factory
feedbackd
feedbackd-0.2.1.obscpio
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File feedbackd-0.2.1.obscpio of Package feedbackd
07070100000000000081A400000000000000000000000164F062AA000001B8000000000000000000000000000000000000001F00000000feedbackd-0.2.1/.dir-locals.el( (c-mode . ( (c-file-style . "linux") (indent-tabs-mode . nil) (c-basic-offset . 2) )) (setq auto-mode-alist (cons '("\\.ui$" . nxml-mode) auto-mode-alist)) (nxml-mode . ( (indent-tabs-mode . nil) )) (css-mode . ( (css-indent-offset . 2) )) (js-mode . ( (indent-tabs-mode . nil) (js-indent-level . 2) )) ) 07070100000001000081A400000000000000000000000164F062AA000001B5000000000000000000000000000000000000001E00000000feedbackd-0.2.1/.editorconfigroot = true [*] charset = utf-8 end_of_line = lf insert_final_newline = true [meson.build] indent_size = 2 tab_size = 2 indent_style = space [*.{c,h,h.in}] indent_size = 2 tab_size = 2 indent_style = space max_line_length = 80 [*.css] indent_size = 2 tab_size = 2 indent_style = space [*.xml] indent_size = 2 tab_size = 2 indent_style = space [*.json] indent_size = 2 tab_size = 2 indent_style = space [NEWS] max_line_length = 72 07070100000002000081A400000000000000000000000164F062AA0000016F000000000000000000000000000000000000001B00000000feedbackd-0.2.1/.gitignore_build debian/.debhelper/ debian/debhelper-build-stamp debian/files debian/gir1.2-feedback-0.0.substvars debian/gir1.2-feedback-0.0/ debian/*.debhelper debian/*.debhelper.log debian/*.substvars debian/feedbackd/ debian/feedbackd-common/ debian/libfeedback-0.0-0.substvars debian/libfeedback-0.0-0/ debian/libfeedback-dev.substvars debian/libfeedback-dev/ debian/tmp/ 07070100000003000081A400000000000000000000000164F062AA0000066C000000000000000000000000000000000000001F00000000feedbackd-0.2.1/.gitlab-ci.ymlinclude: - remote: 'https://source.puri.sm/Librem5/librem5-ci/raw/master/librem5-pipeline-definitions.yml' - remote: 'https://gitlab.freedesktop.org/freedesktop/ci-templates/-/raw/34039cd573a2df832d465bc9e4c5f543571f5241/templates/ci-fairy.yml' variables: GIT_SUBMODULE_STRATEGY: normal GIT_SUBMODULE_DEPTH: 1 stages: - build - test - package .before_script: &before_script before_script: - export DEBIAN_FRONTEND=noninteractive - apt-get -y update - apt-get -y build-dep . - apt-get -y install gcovr git .image: &image image: name: debian:bookworm .tags: &tags tags: - librem5:arm64 # Regular, full build build:native-debian-bookworm:full: <<: *tags <<: *image <<: *before_script stage: build artifacts: paths: - _build script: - meson -Db_coverage=true --werror . _build - ninja -C _build except: variables: - $PKG_ONLY == "1" # Minimal build for e.g. submodule usage build:native-debian-bookworm:lib: <<: *tags <<: *image <<: *before_script stage: build script: - meson --werror -Ddaemon=false -Dgtk_doc=false . _build - ninja -C _build except: variables: - $PKG_ONLY == "1" test:native-debian-bookworm: <<: *tags <<: *image <<: *before_script stage: test needs: - build:native-debian-bookworm:full coverage: '/^\s+lines\.+:\s+([\d.]+\%)\s+/' script: - dbus-run-session ninja -C _build test coverage except: variables: - $PKG_ONLY == "1" package:deb-debian-bookwarm:arm64: variables: L5_DOCKER_IMAGE: debian:bookworm extends: .l5-build-debian-package tags: - librem5:arm64 07070100000004000081A400000000000000000000000164F062AA00000071000000000000000000000000000000000000001C00000000feedbackd-0.2.1/.gitmodules[submodule "subprojects/gmobile"] path = subprojects/gmobile url = https://gitlab.gnome.org/guidog/gmobile.git 07070100000005000081A400000000000000000000000164F062AA0000894B000000000000000000000000000000000000001800000000feedbackd-0.2.1/COPYING GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> 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. <one line to give the program's name and a brief idea of what it does.> Copyright (C) <year> <name of author> 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 <http://www.gnu.org/licenses/>. 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: <program> Copyright (C) <year> <name of author> 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 <http://www.gnu.org/licenses/>. 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 <http://www.gnu.org/philosophy/why-not-lgpl.html>. 07070100000006000081A400000000000000000000000164F062AA000067A2000000000000000000000000000000000000001C00000000feedbackd-0.2.1/COPYING.LIB GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999 Copyright (C) 1991, 1999 Free Software Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. [This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. When we speak of free software, we are referring to freedom of use, 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 this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. GNU LESSER GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) "Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. 1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) The modified work must itself be a software library. b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. This option is useful when you wish to copy part of the code of the Library into a program that is not a library. 4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. 6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. 7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. 10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. 11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), 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 distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 13. The Free Software Foundation may publish revised and/or new versions of the Lesser 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 Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. 14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "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 LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY 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 LIBRARY (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 LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Libraries If you develop a new library, and you want it to be of the greatest possible use to the public, we recommend making it free software that everyone can redistribute and change. You can do so by permitting redistribution under these terms (or, alternatively, under the terms of the ordinary General Public License). To apply these terms, attach the following notices to the library. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. <one line to give the library's name and a brief idea of what it does.> Copyright (C) <year> <name of author> This 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 Also add information on how to contact you by electronic and paper mail. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the library, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the library `Frob' (a library for tweaking knobs) written by James Random Hacker. <signature of Ty Coon>, 1 April 1990 Ty Coon, President of Vice That's all there is to it! 07070100000007000081A400000000000000000000000164F062AA00000524000000000000000000000000000000000000001500000000feedbackd-0.2.1/NEWSfeedback 0.2.1 -------------- Released August 2023 * Minor documentation updates feedback 0.2.0 -------------- Released April 2023 * lfbevent: Add api to set app-id * lfbevent: Change signature of get_feedback_profile(). (API change but no known users) * Contributors: * Guido Günther feedbackd 0.1.1 --------------- Released March 2023 * Fix test failure exposed by glib 2.76 * Leak fixes * Contributors: * Guido Günther feedbackd 0.1.0 --------------- Released February 2023 * Make LED class more flexible. This will allow e.g. hw based implementations * Trigger module load via udev. This avoids shipping another conf file * Contributors: * Dylan Van Assche * Guido Günther feedbackd 0.0.3 --------------- Released February 2023 * spec: Separate system and application events * theme: add screen-shot event * Build and doc fixes * Update gmobile to 0.0.1 * Contributors: * Guido Günther feedbackd 0.0.2 --------------- Released December 2022 * Support theme merging * Support user themes (`theme` gsetting) * Add theme validator * Doc updates * Switch documentation to gi-docgen * Switch manpages to reStructuredText * Contributors: Chris Vogel Guido Günther feedbackd 0.0.1 --------------- Released November 2022 * Initial release (all version before were git snapshots) 07070100000008000081A400000000000000000000000164F062AA0000217D000000000000000000000000000000000000001A00000000feedbackd-0.2.1/README.mdHaptic/visual/audio feedback for GNOME ====================================== [![Code coverage](https://source.puri.sm/Librem5/feedbackd/badges/master/coverage.svg)](https://source.puri.sm/guido.gunther/feedbackd/commits/master) feedbackd provides a DBus daemon (feedbackd) to act on events to provide haptic, visual and audio feedback. It offers a library (libfeedback) and GObject introspection bindings to ease using it from applications. ## License feedbackd is licensed under the GPLv3+ while the libfeedback library is licensed under LGPL 2.1+. ## Getting the source ```sh git clone https://source.puri.sm/Librem5/feedbackd cd feedbackd ``` The master branch has the current development version. ## Dependencies On a Debian based system run ```sh sudo apt-get -y install build-essential sudo apt-get -y build-dep . ``` For an explicit list of dependencies check the `Build-Depends` entry in the [debian/control][] file. ## Building We use the meson (and thereby Ninja) build system for feedbackd. The quickest way to get going is to do the following: meson . _build ninja -C _build ninja -C _build test ninja -C _build install ## Running ### Running from the source tree To run the daemon use ```sh _build/run _build/src/feedbackd ``` To run under gdb use ``` sh FBD_GDB=1 _build/run _build/src/feedbackd ``` You can introspect and get the current theme with ```sh gdbus introspect --session --dest org.sigxcpu.Feedback --object-path /org/sigxcpu/Feedback ``` To run feedback for an event, use [fbcli](#fbcli) See `examples/` for a simple python example using GObject introspection. # How it works We're using a [event naming spec](./doc/Event-naming-spec-0.0.0.md) similar to http://0pointer.de/public/sound-naming-spec.html to name events. This will allow us to act as a system sound library so applications only need to call into this library and things like the quiet and silent profile work out of the box. Any feedback triggered by a client via an event will be stopped latest when the client disconnects from DBus. This makes sure all feedbacks get canceled if the app that triggered it crashes. ## Feedback theme Events are then mapped to a specific type of feedback (sound, led, vibra) via a device specific theme - since devices have different capabilities and different users different needs. Feedbackd is shipped with a default theme `default.json`. You can add your own themes in multiple ways: 1. By exporting an environment variable `FEEDBACK_THEME` with a path to a valid theme file (not recommended, use for testing only), or 2. By creating a theme file under `$XDG_CONFIG_HOME/feedbackd/themes/default.json`. If `XDG_CONFIG_HOME` environment variable is not set or empty, it will default to `$HOME/.config`, or 3. By creating a theme file under `$XDG_CONFIG_HOME/feedbackd/themes/custom.json`. You only specify the values you want to change in that theme and add an entry ```json { "name: "custom" "parent-theme": "default" "profiles" : [ ...(entries you want to change go here)... ] } ``` next to the `name` entry in. This has the upside that your theme gets way smaller and that new entries added to the default theme will automatically be used by your theme too. See [here](./tests/data/user-config/feedbackd/themes/custom.json) for an example. Once you have the file in place, tell feedbackd the them you want to use: gsettings set org.sigxcpu.feedbackd theme custom When you want to go back to the default theme just do: gsettings reset org.sigxcpu.feedbackd theme Note that you can name your theme as you wish but avoid theme names starting with `__` or `$` as this namespace is reserved. 4. By adding your theme file to one of the folders in the `XDG_DATA_DIRS` environment variable, appended with `feedbackd/themes/`. This folder isn't created automatically, so you have to create it yourself. Here's an example: ```bash # Check which folders are "valid" $ echo $XDG_DATA_DIRS [ ... ]:/usr/local/share:/usr/share # Pick a folder that suits you. Note that you shouldn't place themes in # /usr/share, because they would be overwritten by updates! # Create missing directories $ sudo mkdir -p /usr/local/share/feedbackd/themes # Add your theme file! $ sudo cp my_awesome_theme.json /usr/local/share/feedbackd/themes/ ``` Upon reception of `SIGHUP` signal, the daemon process will proceed to retrigger the above logic to find the themes, and reload the corresponding one. This can be used to avoid having to restart the daemon in case of configuration changes. Check out the companion [feedbackd-device-themes][1] repository for a selection of device-specific themes. In order for your theme to be recognized it must be named properly. Currently, theme names are based on the `compatible` device-tree attribute. You can run the following command to get a list of valid filenames for your custom theme (**Note**: You must run this command on the device you want to create the theme for!): ```bash $ cat /sys/firmware/devicetree/base/compatible | tr '\0' "\n" ``` Example output (for a Pine64 PinePhone): ```bash $ cat /sys/firmware/devicetree/base/compatible | tr '\0' "\n" pine64,pinephone-1.2 pine64,pinephone allwinner,sun50i-a64 ``` Thus you could create a custom feedbackd theme for the Pinephone by placing a modified theme file in `/usr/local/share/feedbackd/themes/pine64,pinephone.json` If multiple theme files exist, the selection logic follows these steps: 1. It picks an identifier from the devicetree, until none are left 2. It searches through the folders in `XDG_DATA_DIRS` in order of appearence, until none are left 3. If a theme file is found in the current location with the current name, **it will be chosen** and other themes are ignored. If no theme file can be found this way (i.e. there are no identifiers and folders left to check), `default.json` is chosen instead. Given the above examples: - `/usr/local/share/feedbackd/themes/pine64,pinephone-1.2.json` takes precedence over `/usr/local/share/feedbackd/themes/pine64-pinephone.json` - `/usr/local/share/feedbackd/themes/pine64-pinephone.json` takes precedence over `/usr/share/feedbackd/themes/pine64-pinephone-1.2.json` - etc... The currently available feedback types are: - Sound (an audible sound from the sound naming spec) - VibraRumble: haptic motor rumbling - VibraPeriodic: periodic feedback from the haptic motor - Led: Feedback via blinking LEDs You can check the feedback theme and the classes (prefixed with Fbd) for available properties. Note that the feedback theme API (including the theme file format) is not stable but considered internal to the daemon. ## Profiles The profile determines which parts of the theme are in use: - `full`: Use configured events from the `full`, `quiet` and `silent` parts of the feedback them. - `quiet`: Use `quiet` and `silent` part from of the feedback theme. This usually means no audio feedback. - `silent`: Only use the `silent` part from the feedback theme. This usually means to not use audio or vibra. It can be set via a GSetting ```sh gsettings set org.sigxcpu.feedbackd profile full ``` ## fbcli `fbcli` can be used to trigger feedback for different events. Here are some examples: ### Phone call Run feedbacks for event `phone-incoming-call` until explicitly stopped: ``` _build/cli/fbcli -t 0 -E phone-incoming-call ``` ### New instant message Run feedbacks for event `message-new-instant` just once: ``` _build/cli/fbcli -t -1 -E message-new-instant ``` ### Alarm clock Run feedbacks for event `message-new-instant` for 10 seconds: ``` _build/cli/fbcli -t 10 -E alarm-clock-elapsed ``` ## Python example There's an `example.py` script in the example/ folder of the repository demonstrating how to trigger feedback via an event. ## Per app profiles One can set the feedback profile of an individual application via `GSettings`. E.g. for an app with app id `sm.puri.Phosh` to set the profile to `quiet` do: ``` GSETTINGS_SCHEMA_DIR=_build/data/ gsettings set org.sigxcpu.feedbackd.application:/org/sigxcpu/feedbackd/application/sm-puri-phosh/ profile quiet ``` # Documentation - [Libfeedback API](https://honk.sigxcpu.org/projects/feedbackd/doc/) - [Event naming spec draft](./doc/Event-naming-spec-0.0.0.md) - [Feedback-theme-spec draft](./doc/Feedback-theme-spec-0.0.0.md) [debian/control]: ./debian/control#L5 [1]: https://source.puri.sm/Librem5/feedbackd-device-themes 07070100000009000041ED00000000000000000000000264F062AA00000000000000000000000000000000000000000000001A00000000feedbackd-0.2.1/build-aux0707010000000A000081A400000000000000000000000164F062AA0000012F000000000000000000000000000000000000002A00000000feedbackd-0.2.1/build-aux/post_install.py#!/usr/bin/python3 import os import subprocess import sys destdir = os.environ.get('DESTDIR', '') if not destdir and len(sys.argv) > 1: datadir = sys.argv[1] print('Compiling gsettings schemas...') subprocess.call(['glib-compile-schemas', os.path.join(datadir, 'glib-2.0', 'schemas')]) 0707010000000B000041ED00000000000000000000000264F062AA00000000000000000000000000000000000000000000001400000000feedbackd-0.2.1/cli0707010000000C000081A400000000000000000000000164F062AA0000121B000000000000000000000000000000000000001C00000000feedbackd-0.2.1/cli/fbcli.c/* * Copyright (C) 2020 Purism SPC * SPDX-License-Identifier: GPL-3.0+ * Author: Guido Günther <agx@sigxcpu.org> */ #define LIBFEEDBACK_USE_UNSTABLE_API #include "libfeedback.h" #include <glib.h> #include <gio/gio.h> #include <glib-unix.h> #include <locale.h> #define DEFAULT_EVENT "phone-incoming-call" static GMainLoop *loop; static gboolean on_shutdown_signal (gpointer unused) { /* End right away, lfb_uninit will end running feedback */ g_main_loop_quit (loop); return FALSE; } static gboolean on_watch_expired (gpointer unused) { g_warning ("Watch expired waiting for all feedbacks to finish"); g_main_loop_quit (loop); return G_SOURCE_REMOVE; } static void on_feedback_ended (LfbEvent *event, int* data) { g_return_if_fail (LFB_IS_EVENT (event)); g_debug ("Feedback ended for event"); *data = TRUE; g_main_loop_quit (loop); } static gboolean on_user_input (GIOChannel *channel, GIOCondition cond, LfbEvent *event) { g_autoptr(GError) err = NULL; if (cond == G_IO_IN) { g_print ("Ending feedback\n"); if (!lfb_event_end_feedback (event, &err)) g_warning ("Failed to end feedback: %s", err->message); } return FALSE; } static gboolean trigger_event (const char *name, const gchar *profile, gint timeout) { g_autoptr(GError) err = NULL; g_autoptr(LfbEvent) event = NULL; g_autoptr(GIOChannel) input = NULL; int success = FALSE; g_unix_signal_add (SIGTERM, on_shutdown_signal, NULL); g_unix_signal_add (SIGINT, on_shutdown_signal, NULL); g_print ("Triggering feedback for event '%s'\n", name); event = lfb_event_new (name); lfb_event_set_timeout (event, timeout); if (profile) lfb_event_set_feedback_profile (event, profile); g_signal_connect (event, "feedback-ended", (GCallback)on_feedback_ended, &success); if (!lfb_event_trigger_feedback (event, &err)) { g_print ("Failed to report event: %s\n", err->message); return FALSE; } input = g_io_channel_unix_new (STDIN_FILENO); g_io_add_watch (input, G_IO_IN, (GIOFunc)on_user_input, event); g_print ("Press <RETURN> to end feedback right away.\n"); loop = g_main_loop_new (NULL, FALSE); g_main_loop_run (loop); g_main_loop_unref (loop); return success; } static void on_profile_changed (LfbGdbusFeedback *proxy, GParamSpec *psepc, gpointer unused) { g_print ("Set feedback profile to: '%s'\n", lfb_get_feedback_profile ()); g_main_loop_quit (loop); } static gboolean set_profile (const gchar *profile) { LfbGdbusFeedback *proxy; const gchar *current; current = lfb_get_feedback_profile (); g_debug ("Current profile is %s", current); if (!g_strcmp0 (current, profile)) { g_print ("Profile is already set to %s\n", profile); return TRUE; } g_debug ("Setting profile to %s", profile); proxy = lfb_get_proxy (); /* Set profile and wait until we got notified about the profile change */ loop = g_main_loop_new (NULL, FALSE); lfb_set_feedback_profile (profile); g_signal_connect (proxy, "notify::profile", (GCallback)on_profile_changed, NULL); g_main_loop_run (loop); g_print ("Current feedback profile is: '%s'\n", lfb_get_feedback_profile ()); return TRUE; } int main (int argc, char *argv[0]) { g_autoptr(GOptionContext) opt_context = NULL; g_autoptr(GError) err = NULL; g_autofree gchar *profile = NULL; const char *name = NULL; gboolean success; int watch = 30; int timeout = -1; const GOptionEntry options [] = { {"event", 'E', 0, G_OPTION_ARG_STRING, &name, "Event name. (default: " DEFAULT_EVENT ").", NULL}, {"timeout", 't', 0, G_OPTION_ARG_INT, &timeout, "Run feedback for timeout seconds", NULL}, {"profile", 'P', 0, G_OPTION_ARG_STRING, &profile, "Profile name to set", NULL}, {"watch", 'w', 0, G_OPTION_ARG_INT, &watch, "How long to watch for feedback longest", NULL}, { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL } }; setlocale (LC_ALL, ""); opt_context = g_option_context_new ("- A cli for feedbackd"); g_option_context_add_main_entries (opt_context, options, NULL); if (!g_option_context_parse (opt_context, &argc, &argv, &err)) { g_warning ("%s", err->message); return 1; } if (!lfb_init ("org.sigxcpu.fbcli", &err)) { g_print ("Failed to init libfeedback: %s\n", err->message); return 1; } if (profile && !name) success = set_profile (profile); else { if (!name) name = g_strdup (DEFAULT_EVENT); g_timeout_add_seconds (watch, (GSourceFunc)on_watch_expired, NULL); success = trigger_event (name, profile, timeout); } lfb_uninit (); return !success; } 0707010000000D000081A400000000000000000000000164F062AA000000B1000000000000000000000000000000000000002000000000feedbackd-0.2.1/cli/meson.buildfbcli_sources = [ 'fbcli.c', ] fbcli_deps = [ libfeedback_dep, gio, gio_unix, ] executable( 'fbcli', fbcli_sources, dependencies: fbcli_deps, install: true, ) 0707010000000E000041ED00000000000000000000000264F062AA00000000000000000000000000000000000000000000001500000000feedbackd-0.2.1/data0707010000000F000081A400000000000000000000000164F062AA00001503000000000000000000000000000000000000002200000000feedbackd-0.2.1/data/default.json{ "name" : "default", "profiles" : [ { "name" : "full", "feedbacks" : [ { "event-name" : "alarm-clock-elapsed", "type" : "Sound", "effect" : "alarm-clock-elapsed" }, { "event-name" : "button-pressed", "type" : "Sound", "effect" : "button-pressed" }, { "event-name" : "button-released", "type" : "Sound", "effect" : "button-released" }, { "event-name" : "camera-focus", "type" : "Sound", "effect" : "camera-focus" }, { "event-name" : "camera-shutter", "type" : "Sound", "effect" : "camera-shutter" }, { "event-name" : "message-new-email", "type" : "Sound", "effect" : "message-new-email" }, { "event-name" : "message-new-instant", "type" : "Sound", "effect" : "message-new-instant" }, { "event-name" : "message-new-sms", "type" : "Sound", "effect" : "message-new-instant" }, { "event-name" : "phone-incoming-call", "type" : "Sound", "effect" : "phone-incoming-call" }, { "event-name" : "phone-hangup", "type" : "Sound", "effect" : "phone-hangup" }, { "event-name" : "phone-failure", "type" : "Sound", "effect" : "phone-failure" }, { "event-name" : "phone-outgoing-busy", "type" : "Sound", "effect" : "phone-outgoing-busy" }, { "event-name" : "screen-capture", "type" : "Sound", "effect" : "screen-capture" }, { "event-name" : "timeout-completed", "type" : "Sound", "effect" : "complete" }, { "event-name" : "theme-demo", "type" : "Sound", "effect" : "theme-demo" }, { "event-name" : "window-close", "type" : "Sound", "effect" : "theme-demo" } ] }, { "name" : "quiet", "feedbacks" : [ { "event-name" : "alarm-clock-elapsed", "type" : "VibraPeriodic", "magnitude" : 32767, "duration" : 10000, "fade-in-time" : 10000, "fade-in-level": 4096 }, { "event-name" : "bell-terminal", "type" : "VibraRumble", "duration" : 100 }, { "event-name" : "button-pressed", "type" : "VibraRumble", "duration" : 15 }, { "event-name" : "button-released", "type" : "VibraRumble", "duration" : 12 }, { "event-name" : "message-new-email", "type" : "VibraRumble", "duration" : 750, "count" : 3, "pause" : 100 }, { "event-name" : "message-new-instant", "type" : "VibraRumble", "duration" : 150 }, { "event-name" : "message-new-sms", "type" : "VibraRumble", "duration" : 500, "count" : 2, "pause" : 100 }, { "event-name" : "message-sent-instant", "type" : "VibraRumble", "duration" : 150 }, { "event-name" : "phone-incoming-call", "type" : "VibraPeriodic", "duration" : 10000 }, { "event-name" : "timeout-completed", "type" : "VibraRumble", "duration" : 100 }, { "event-name" : "theme-demo", "type" : "VibraPeriodic", "magnitude" : 32767, "duration" : 5000 }, { "event-name" : "window-close", "type" : "VibraRumble", "duration" : 25 } ] }, { "name" : "silent", "feedbacks" : [ { "event-name" : "battery-caution", "type" : "Led", "color" : "red", "frequency" : 5000 }, { "event-name" : "phone-missed-call", "type" : "Led", "color" : "blue", "frequency" : 3000 }, { "event-name" : "message-missed-email", "type" : "Led", "color" : "blue", "frequency" : 2000 }, { "event-name" : "message-missed-instant", "type" : "Led", "color" : "blue", "frequency" : 1000 }, { "event-name" : "message-missed-notification", "type" : "Led", "color" : "blue", "frequency" : 500 }, { "event-name" : "message-missed-sms", "type" : "Led", "color" : "blue", "frequency" : 2000 } ] } ] } 07070100000010000081A400000000000000000000000164F062AA00000609000000000000000000000000000000000000002100000000feedbackd-0.2.1/data/meson.build# DBus server interface prefix = 'org.sigxcpu.' namespace = 'LfbGdbus' generated_dbus_sources = [] dbus_interfaces = [ 'org.sigxcpu.Feedback.xml' ] generated_dbus_sources += gnome.gdbus_codegen('lfb-gdbus', sources : dbus_interfaces, object_manager : false, docbook : 'libfeedback', interface_prefix : prefix, install_header : true, install_dir : join_paths(get_option('includedir'), libname), namespace : namespace) dbus_header_dir = meson.current_build_dir() dbus_inc = include_directories('.') install_data(dbus_interfaces, install_dir: ifacedir) schemas = ['org.sigxcpu.feedbackd.gschema.xml'] compiled = gnome.compile_schemas( build_by_default: true ) install_data( schemas, install_dir: 'share/glib-2.0/schemas' ) if get_option('daemon') service_data = configuration_data() service_data.set('libexecdir', libexecdir) service_file = 'org.sigxcpu.Feedback.service' configure_file( input : service_file + '.in', output : service_file, configuration : service_data, install : true, install_dir: servicedir, ) theme_json = ['default.json'] install_data( theme_json, install_dir: feedbackd_theme_dir, ) if json_glib_validate.found() jsons = [] foreach theme : theme_json jsons += (join_paths(meson.current_source_dir(), theme)) endforeach custom_target('validate-json', build_by_default: true, input: theme_json, output: 'json_validate_stamp', command: [json_glib_validate.full_path()] + jsons) endif endif # daemon 07070100000011000081A400000000000000000000000164F062AA00000047000000000000000000000000000000000000003500000000feedbackd-0.2.1/data/org.sigxcpu.Feedback.service.in[D-BUS Service] Name=org.sigxcpu.Feedback Exec=@libexecdir@/feedbackd 07070100000012000081A400000000000000000000000164F062AA000008FC000000000000000000000000000000000000002E00000000feedbackd-0.2.1/data/org.sigxcpu.Feedback.xml<?xml version="1.0" encoding="UTF-8" ?> <node> <!-- org.sigxcpu.Feedback @short_description: haptic/audio/visual feedback interface This D-Bus interface is used to get the current feedback theme and to give feedback on events. --> <interface name="org.sigxcpu.Feedback"> <!-- Profile: The currently used profile. The currently used feedback profile name. Applications should usually not change this value. --> <property name="Profile" type="s" access="readwrite" /> <!-- TriggerFeedback: @app_id: The application id usually in "reverse DNS" format @event: The event name from the Event naming spec @hints: Additional hints (e.g. to prefer haptic feedback over audio feedback on button press events) @timeout: When the feedbacks for this event should end latest in seconds. The special values '-1' (just run each feedback once) and '0' (endless loop) are also supported. @id: Event id for future reference Give user feedback for an event by triggering feedbacks defined in the daemon. The method call returns an event id that can be used later on to e.g. cancel the triggered feedbacks early. Depending on the event, theme and profile several forms of feedback will be triggered such as an audio ring tone and a haptic motor. --> <method name="TriggerFeedback"> <arg direction="in" name="app_id" type="s"/> <arg direction="in" name="event" type="s"/> <arg direction="in" name="hints" type="a{sv}"/> <arg direction="in" name="timeout" type="i"/> <arg direction="out" name="id" type="u"/> </method> <!-- EndFeedback: @id: The id of the event End all feedbacks triggered by the event with the given id. --> <method name="EndFeedback"> <arg direction="in" name="id" type="u"/> </method> <!-- FeedbackEnded: @id: The id of the event @reason: The reason why feedback was ended (currently unused). Emitted when all feedbacks for an event have ended. --> <signal name="FeedbackEnded"> <arg name="id" type="u"/> <arg name="reason" type="u"/> </signal> </interface> </node> 07070100000013000081A400000000000000000000000164F062AA000004EA000000000000000000000000000000000000003700000000feedbackd-0.2.1/data/org.sigxcpu.feedbackd.gschema.xml<schemalist> <schema id="org.sigxcpu.feedbackd" path="/org/sigxcpu/feedbackd/"> <key name="profile" type="s"> <choices> <choice value='full'/> <choice value='quiet'/> <choice value='silent'/> </choices> <default>'full'</default> <summary>Feedack profile to use</summary> <description> The feedback profile determines the audio and haptical feedback level given on events to the user. </description> </key> <key name="theme" type="s"> <default>'default'</default> <summary>The feedback theme to use</summary> <description> The feedback theme determines which feedbacks are triggered when feedbackd receives an event. </description> </key> </schema> <schema id="org.sigxcpu.feedbackd.application"> <key name="profile" type="s"> <choices> <choice value='full'/> <choice value='quiet'/> <choice value='silent'/> </choices> <default>'full'</default> <summary>Feedack profile to use</summary> <description> The feedback profile determines the audio and haptical feedback level given on events to the user. </description> </key> </schema> </schemalist> 07070100000014000041ED00000000000000000000000264F062AA00000000000000000000000000000000000000000000001700000000feedbackd-0.2.1/debian07070100000015000081A400000000000000000000000164F062AA0000043E000000000000000000000000000000000000002500000000feedbackd-0.2.1/debian/README.sourceThis package is maintained with git-buildpackage(1). It follows DEP-14 for branch naming (e.g. using debian/sid for the current version in Debian unstable). It uses pristine-tar(1) to store enough information in git to generate bit identical tarballs when building the package without having downloaded an upstream tarball first. When working with patches it is recommended to use "gbp pq import" to import the patches, modify the source and then use "gbp pq export --commit" to commit the modifications. The changelog is generated using "gbp dch" so if you submit any changes don't bother to add changelog entries but rather provide a nice git commit message that can then end up in the changelog. It is recommended to build the package with pbuilder using: gbp buildpackage --git-pbuilder For information on how to set up a pbuilder environment see the git-pbuilder(1) manpage. In short: DIST=sid git-pbuilder create gbp clone <project-url> cd <project> gbp buildpackage --git-pbuilder -- Guido Günther <agx@sigxcpu.org>, Wed, 2 Dec 2015 18:51:15 +0100 07070100000016000081A400000000000000000000000164F062AA00006D2A000000000000000000000000000000000000002100000000feedbackd-0.2.1/debian/changelogfeedbackd (0.2.1) experimental; urgency=medium * Update NEWS * event: Fix doc link * treewide: Drop superfluous '()' after functions in doc strings. Otherwise we have that doubled in the docs * doc: Better cross reference manpages * doc: Add manpage for feedback themes. This should direct users to the documentation. -- Guido Günther <agx@sigxcpu.org> Tue, 29 Aug 2023 18:32:09 +0200 feedbackd (0.2.0) experimental; urgency=medium * build: Bump version to 0.2.0. We have a slight api change. * lfb-event: Avoid allocation when getting profile. We can return the const *. This makes it consistent with other getters. This is an API change we didn't find any users and the API is declared unstable. * tests: Get properties all at once * lfb-event: Add getter and setter for app-id. For applications this is figured out automatically but notification daemons and portal implementations might want to override it to have the per-app feedback profile picked up automatically. -- Guido Günther <agx@sigxcpu.org> Mon, 17 Apr 2023 12:14:14 +0200 feedbackd (0.1.1) experimental; urgency=medium * build: Avoid meson deprecation warning * fbd-event: Make sure we iterate the list safely. When all feedbacks are done the event signals "feedbacks-ended" which lets the manager dispose the feedback. When all feedbacks end instantly and synchronously (as is the case with the dummy feedback) this triggers the disposal of the event within the loop leading to a crash. Make sure the object doesn't go away be referencing it during the loop iteration. We didn't see this before as glib's slice allocator for lists papered over this for us. Closes: https://source.puri.sm/Librem5/feedbackd/-/issues/69 * tests: Don't leak json string * tests: Don't leak profiles and test that. We finalize the theme first so the last reference is dropped when finalizing the profiles. * feedback-profile: Don't leak json array when serializing profile json_array_add_element doesn't transfer ownership * feedback-theme: Don't leak json array when serializing profile json_array_add_element doesn't transfer ownership. * feedback-theme: Don't leak parent name * tests/profile: Don't leak json node -- Guido Günther <agx@sigxcpu.org> Thu, 23 Mar 2023 10:35:01 +0100 feedbackd (0.1.0) experimental; urgency=medium [ Dylan Van Assche ] * udev: load the required kernel modules. Loading the required kernel modules such as ledtrig-pattern via /etc/modules-load.d may introduce a race condition on some systems such as non-systemd based distros. Load the kernel modules using the builtin 'kmod load' udev command instead. [ Guido Günther ] * debian: Drop obsolete conf file. As this is now handled via udev's kmod builtin we can drop this. * theme: Fix some indentation * fbd-dev-leds: Use gi-docgen compatible format. We don't document the server classes via gi-docgen atm but as we use it for the lib update classes we touch. * Move LED device to separate file. We separate out the led as different LED types have different ways to set patterns, etc * fbd-dev-leds: Move led creation into fbd-dev-led. This will allow us to separate the different led types * fbd-dev-leds: Move pattern trigger into fbd-dev-led * fbd-dev-led: Allow to lookup color. This allows us to make the led structure into an opaque in the next commit * fbd-dev-led: Make structure opaque. This will allow us to turn it into a GObject * fbd-dev-led: Turn into a GObject. This is just the minimal changes to switch to a derivable GObject * fbd-dev-led: Use GInitable. Use default GObject patterns instead of stuffing things into the fbd_dev_led_new () so derived classes can override it. * fbd-dev-led: Add class methods so derived classes can override functionality * fbd-dev-led: Move multicolor handling to separate class. Everything related to multicolor moves into the new class and we add the necessary getters and setters so derived classes can access the parent classes attributes where needed. * d/gbp.conf: Be less strict when matching the meson version field -- Guido Günther <agx@sigxcpu.org> Sat, 25 Feb 2023 14:04:43 +0100 feedbackd (0.0.3) experimental; urgency=medium * build: Add dbus sources to the lib dependency. Otherwise we might fail to generate it for the executables * event-naming-spec: Separate application and system events. Make it obvious which events are meant to be used by "normal" GUI applications in contrast to system components like desktop shells or components monitoring the battery, etc. This was prompted by https://github.com/flatpak/xdg-desktop-portal/issues/929 * feedback-theme: Add screen-shot event. Used to indicate that a screen shot is being taken. * lfb-event: Fix docstring. This allows gi-docgen to pick it up * doc: Fix link to spec in manpage * libfeedback: Fix link to specs. Since we now have them as part of the API docs we can avoid any remote URLs * Update gmobile to 0.0.1 -- Guido Günther <agx@sigxcpu.org> Thu, 02 Feb 2023 12:10:51 +0100 feedbackd (0.0.2) experimental; urgency=medium [ Chris Vogel ] * docs: Update references to documentation from branch master to branch main. * README: Mention python example * doc: feedback stops when client disconnects * run: Export GI_TYPELIB_PATH as well. This is needed for programs needing GObject introspection data * run: Don't hardcode feedbackd. This allows arbitrary executables from the source tree with a well defined environment. * example: Document usage [ Guido Günther ] * run: Fix daemon name. Fixes: 99fc8c2 ("run: Make it easy to run under gdb and document usage") * example: Wait a bit before ending feedbackd terminates feedback when clients disconnect from DBus so we need to wait a bit before quitting as otherwise no feedback will be played. (Closes: #65) * d/gbp.conf: Update branch. Missed that one when switching to 'main' * ci: Switch build to bookworm / byzantium. Use Debian bookworm for the tests and PureOS byzantium for the package build We use the arm64 builder as the amd64 one fails to find a shell in the bookworm image. * d/control: Add settings schema for the tests * d/control: Drop Breaks/Replaces on packages long gone * d/rules: Support nodoc build profile * build: Bump required meson version * Switch library documentation to gi-docgen. Switch from gtk-doc to gi-docgen for the library documentation and adjust the source files accordingly. We don't bother about the daemon doc headers as they're not built into any docs atm. (Closes: #56) * Include specifications in the documentation. Now that we can use markdown easily add them as they provide help to the developer what events exist, etc. * dir-locals: Simlify consistent JS indenting * feedback-vibra: Fix indentation * tests: Test feedback theme name * feedback-theme: No need for constructed. We can do all that in init * feedback-theme: Fix indentation * feedback-theme: Use getter. Ensures we stay consistent with future changes * feedback-theme: Allow to set name * feedback-profile: Document hash types * feedback-dummy: Add getter for duration. Useful in tests * feedback-profile: Allow to update profiles. Allow to add feedbacks from a profile to another one * feedback-theme: Allow to update theme. New profiles are added, existing profiles updated. This will allow to merge themes. * feedback-theme: Allow to get and set parent theme name. If set the parent theme's feedbackd and profiles should be merged into this theme. * ci: Install git. Needed for the submodule * Add gmobile library * build: Don't include main in lib. For that move the error quark to a separate file. * Recursively load themes. Themes (other than the default theme) can specify a `parent-name` in the json file. This theme will be used as a base for the theme. Events and profiles of the children override those in the parents. For this we move the lookup code into it's separate class and also add tests. (Closes: #38) * theme-expander: Allow to set the theme to expand * data: Allow to set feedback theme * manager: Don't load theme in constructor. Loading the theme can trigger calls to fbd_feedback_manager_get_default() which then results in an endless look as the object isn't fully initialized in constructed. Instead do the setup in main() which has the advantage that the manager's life cycle becomes more obvious too. * feedback-manager: Handle theme gsetting. Update the theme when the gsetting changes * README: Document custom themes * tests: Help old glib on PureOS along * theme-expander: Also log initial theme file * Add theme validator. Recursively loads a given theme file. * ci: Use bookworm image for package build too. No need to fight against old glib and friends in PureOS * doc: Convert manpages to rst. This will make it more fun to add details and more manpages. * doc: Add manual page for fbd-theme-validate * d/rules: Don't build tests with nocheck -- Guido Günther <agx@sigxcpu.org> Tue, 13 Dec 2022 13:53:57 +0100 feedbackd (0.0.1) byzantium; urgency=medium [ Evangelos Ribeiro Tzaras ] * spec: Clarify feedback noisiness. The old wording could be interpreted as the feedback being discarded if it's noisier than the currently selected profile which is not the case. Also take the new per application settings into account. * lfb-event: Fix SPDX identifier. The library is LGPL-2.1+, not GPL-3.0+ * test-lfb-integration: Test event state in async callback * lfb-event: Notify state change before completing async task lfb_event_trigger_feedback_async() internally uses a GTask to handle invocation of the user provided callback when g_task_return_*() is called. Currently GTask is completed first and only afterwards is the state of the event being updated which can lead to surprising behaviour. * feedback-manager: Use guint for event id. The ID is inserted into a hashtable below with GUINT_TO_POINTER and is set using self->next_id++ with next_id also being a guint, so change the type accordingly. * run: Make it easy to run under gdb and document usage. Having a fast and easy way to run the daemon under gdb can be beneficial for debugging. For that start the run script with FBD_GDB=1. * tests/integration: Indicate that callback quits main loop on_event_triggered() is renamed to on_event_triggered_quit() as we will shortly introduce a variant that does not quit. * tests/integration: Fix whitespace. Remove all tabs in favour of spaces and align function arguments. * tests/integration: Test that "feedback-ended" is propagated through LfbEvent. When no feedbacks are available (either because the requested event does not exist in the theme or because the system does not have required capabilities, e.g. no vibration motor or LED) feedbackd will emit a "feedback-ended" signal (with reason LFB_EVENT_STATE_REASON_NOT_FOUND) on DBus _before_ completing the event triggering DBus call. Since the DBus call was not completed yet, LfbEvent will not have learned it's ID yet and therefore not emit it's own "feedback-ended" GObject signal. In this case the test will timeout since the main loop is never quit. * feedback-manager: Complete DBus call before emitting "feedback-ended" See previous commit adding the test (that now passes) for the reasoning. Fixes: #62 [ Guido Günther ] * data: Drop outdated comment. We use the hints since some time, see lfb_event_set_feedback_profile(). * lfb-event: Fix typo. It's LfbEvent * lfb-event: Use consistent prefix. Make async data use the same prefix. * Use g_error() when library is not initialized. This makes sure it still works when asserts are disabled. * lfb-event: Untabify * tests: Drop unused variable * tests/integration: Check the state of the ended event * manager: Use FEEDBACKD_UDEV_ATTR. It was introduced in a5b4f99 ("feedbackd: Support visual feedback via LEDs") * fbd: Fix indentation -- Guido Günther <agx@sigxcpu.org> Thu, 10 Nov 2022 13:53:19 +0100 feedbackd (0.0.0+git20220520) byzantium; urgency=medium [ Guido Günther ] * udev: Drop pre L5 pre 5.9 workaround. Not neeed in 2022. * udev: Use more generic comment. Make it more obvious that this isn't device specific [ Dylan Van Assche ] * fbd-dev-leds: use define for max_brightness. All other attributes use a define, let's do the same for max_brightness. * fbd-dev-leds: rename var to max_brightness_percentage. Improve readability of the code. [ Luca Weiss ] * fbd-dev-leds: support for multicolor LEDs. Add support for multicolor LEDs as supported by the kernel. Used by Qualcomm devices such as SHIFT 6mq, OnePlus 6, etc. Co-Developed-by: Dylan Van Assche <me@dylanvanassche.be> -- Guido Günther <agx@sigxcpu.org> Fri, 20 May 2022 10:55:13 +0200 feedbackd (0.0.0+git20220208) byzantium; urgency=medium [ Pablo Correa Gómez ] * Reload theme on SIGHUP signal. Allows for users/applications to request a theme reload by sending SIGHUP signal to the daemon. [ Evangelos Ribeiro Tzaras ] * lfb-event: Clarify docstring on lfb_event_set_feedback_profile * fbd-event: Fix return value for fbd_event_get_sender * doc: Clarify that the timeout is in seconds [ Guido Günther ] * libfeedback: Remove unused variables * tests: Remove unused variables * manager: Set initial profile to unknown. This makes sure we sync the profile with the DBus property after fetching it from GSettings. * manager: Sync profile with setting on startup. On startup the GSetting is the relevant input for selecting the profle. (Closes: #52) * manager: Don't sync DBus profile property. This will happen in on_feedbackd_setting_changed() once the profile was adjusted. -- Guido Günther <agx@sigxcpu.org> Tue, 08 Feb 2022 11:29:41 +0100 feedbackd (0.0.0+git20211018) byzantium; urgency=medium [ Evangelos Ribeiro Tzaras ] * fbd-dev-sound: Honour sound theme name for all GNOME based desktops. * d/control: Add json-glib-tools as build dependency. This will make sure that the json theme file gets validated in CI. * feedback-theme: Add phone-{hangup,failure,outgoing-busy} events. * naming-spec: Fix upper cases, whitespaces and punctuation. [ Andreas Hartmann ] * fbd-feedback-manager: Make sure theme path components are '/' separated. * README: Add explanation on custom theme paths. [ Pablo Correa Gómez ] * feedback-manager: Search for default theme under XDG_CONFIG_HOME first. This would allow users to create their own feedback profiles * Fix typos in documentation * README: dbus calls not usable to trigger feedback. Fixes #45 [ Guido Günther ] * examples: Unbreak python example. * docs: Fix --profile short option. It's '-P', not '-p'. * cli: Fix changing global profile. * feedback-theme: Add camera related events * gitlab-ci: Switch to bullseye. * fbd-dev-sound: Delay sending `ended` signal. This makes sure we properly end the feedback even when looping. -- Guido Günther <agx@sigxcpu.org> Tue, 19 Oct 2021 13:13:43 +0200 feedbackd (0.0.0+git20210426) byzantium; urgency=medium [ Martin Bürgmann ] * implement fbd_dev_sound_stop tracks the FdbFeedbackSounds in a GHashTable in the FdbDevSound (Closes: #10) [ Guido Günther ] * fbd-dev-sound: Don't leak GError * fbd-dev-sound: Don't warn when sound was cancelled. This is not an error per se. * lfb-event: Don't leak error. Don't leak the error values in the success case * tests: Run lfb_event_{get,set}_timeout * test-lfb-integration: Test invocation error * event: Make log-domain match source file name * tests: Run event tests too * event: Remove 'g' prefix from common C types. This matchs phosh's style. * fbd-event: Add sender property. This allows us to store the DBus sender * fbd-manager: Keep DBus sender around * feedback-manager: Track DBus clients and end feedbacks if they go away. When the client goes away we build up a list of events to end feedback for to make sure the hash table isn't modified in place. tThe alternative approach would be to disconnect the on_event_feedbacks_ended handler, duplicate the DBus signal emission and use g_hash_table_foreach_remove but that looks less robust than using the same code path. (Closes: #25) * Help emacs to indent properly * fbd-feedback-theme: Don't leak JSON node * fbd-dev-leds: Free actual FbdDevLed as well. So far we only unref'ed the device. * fbd-dev-leds: Don't leak enum_name g_enum_to_string() is transfer full. * fbd-dev-leds: Don't leak color g_ascii_strdown() creates a copy already. * fbd-dev-leds: Use automatic deep cleanup for device list. The current logic was fragile and failed e.g. when the FEEDBACKD_UDEV_VAL_LED would not match leaking the dev since the g_object_unref() at the end of the loop was never hit. Prevent that with automatic cleanup and explicitly ref'ing the devs we want to use. * fbd-dev-sound: Use correct cleanup for hash table. This went unnoticed since the manager forgot to cleanup this at all (see follow up commit). * fbd-feedback-manager: Make sure to dispose sound device as well. Fixes another leak. * fbd-feedback-manager: Don't leak config_path. It's assigned multiple times. * fbd-feedback-manager: Don't leak device list [ Clayton Craft ] * fbd-ledctrl: fix matching of trigger in list of triggers. If the trigger is the last thing in sysfs_path/LED_TRIGGER_ATTR, then the new-line at the end of the output causes g_strv_contains to fail to find the trigger in the list. This strips the new-line before splitting the output into a list for searching. [ Sebastian Spaeth ] * README: Fix gdbus test command. It is TriggerFeedback and not Feedback (anymore). Also add a note how to end the feedback in order to prevent loss of hearing :-). -- Guido Günther <agx@sigxcpu.org> Mon, 26 Apr 2021 12:34:38 +0200 feedbackd (0.0.0+git20210125) amber-phone; urgency=medium [ Dylan Van Assche ] * meson.build: compile GLib schemas on install. Run a script as a post install to make sure that all GLib schemas are compiled * fbd-feedback-manager: Allow device-specific feedbackd themes. [ Guido Günther ] * feedback-manager: Fix formatting. -- Guido Günther <agx@sigxcpu.org> Mon, 25 Jan 2021 10:50:15 +0100 feedbackd (0.0.0+git20201114) amber-phone; urgency=high [ Guido Günther ] * sound: Set 'event' media role. This allows pa to cork, duck, etc. * gitlab-ci: Honor PKG_ONLY. This allow us to get debs quicker * udev: Update led maching for the librem5. The names changed in device tree which tickles up into userspace. * debian: Don't abuse the video group. Use a separate group for users that should be able to access the LED devices. [ Luca Weiss ] * fbd-dev-leds: fix brightness parameter. The fbd_dev_led_set_brightness function is only getting called with parameter 0 at the moment so this was never noticed. * Fix typos -- Guido Günther <agx@sigxcpu.org> Sat, 14 Nov 2020 15:54:23 +0100 feedbackd (0.0.0+git20200726) amber-phone; urgency=medium [ Arnaud Ferraris ] * debian: udev: add support for PinePhone front LEDs * fbd-dev-leds: store LED color when parsing devices. Failing to do so will always select the first recognized LED (the blue one for the PinePhone). [ Guido Günther ] * Release new git snapshot * fbd-dev-sound: Be less verbose on missing sound files. This is quite common so don't fill the logs at normal debug levels but be more specific about what is missing. * fbd-feedback-base: Add fbd_feedback_is_available () This allows to check if a feedback type is available at all. * feedback-manager: Fix indentation * fbd-feedback-manager: Check if feedback is usable. If we don't find any usable feedbacks for an event return FBD_EVENT_END_REASON_NOT_FOUND. * fbd-feedback-led: Implement is_available () This avoids criticals when there's no Leds available. * feedback-vibra-rumble: Implement is_available. This avoids criticals when there's no rumble vibra available. * feedback-vibra-periodic: Implement is_available. This avoids criticals when there's no periodic vibra available. * feedback-sound: Implement is_available. This avoids criticals when there's sound device available. We can also be more precise about the reason why feedback ended. * feedback-theme: Avoid warning when feedback is not found. We tell the caller so debug level is enough * tests: Don't check end reason in feedback handler. This allows to reuse the feedback handler and we check the reason in the actual test function anyway. * tests: Test event not found case too * feedback-manager: Deeply free the feedback list. Instead of freeing each element after each iteration and then the list itself at the very end just fully free the list. g_autoslist does not work well on oder glib so do that manually. This is just cosmetics. * feedback-manager: Don't forget to remove not found events from the hash table. This plugs a leak. * feedback-manager: Dispose leds too * feedback-led: Stop the correct led color * feedback-led: Don't try to stop led when there's no led device. This is not a critical since we prevented submitting initially but daemon cleanup processes all entries in the theme. * fbd: Dispose manager at the very end -- Guido Günther <agx@sigxcpu.org> Sun, 26 Jul 2020 13:05:59 +0200 feedbackd (0.0.0+git20200714) amber-phone; urgency=medium [ Arnaud Ferraris ] * doc: fix typos * doc: feedbackd: add short description. Lintian issues a warning if short description is empty. * fbd-ledctrl: fix typo [ Guido Günther ] * lfb-event: Clarify return values of `finished` functions. They just inidicate that we talked to feedbackd successfully. * lfb-event: Connect done handler in async case too. Otherwise the event state is not updated properly * tests: Don't quit mainloop on event end. This is needed to properly test aync where we have the finished async event handler and the signal. * tests: Use async feedback as the test name implies -- Guido Günther <agx@sigxcpu.org> Tue, 14 Jul 2020 10:30:45 +0200 feedbackd (0.0.0+git20200707) amber-phone; urgency=medium [ Sebastian Krzyszkowiak ] * data: Lower rumble time for window-close and button-pressed even more. Haptic feedback for touchscreen input should be as subtle as possible to not make it distracting. * data: Add button-released event [ Guido Günther ] * feedback-sound: Plug a leak. We did not free the effect name * Doc cleanups * feedback-manager: Only act on add. We would otherwise ignore the action when no vibra device was yet found. Make sure we release the old device when updating. * libfeedback: Unset _initted early. This make sure a client does not end up in our shutdown phase and sees a half initted library. * libfeedback: Cancel all running feedbacks on uninit. We keep track of the active ids and end them on uninit. This make sure feedbacks don't continue to run if the application quits and forgets to end a feedback. * fbcli: Quit main loop on CTRL-C / SIGTERM. This makes sure we invoke the cleanup function correctly and allows to test running event handling. * docs: Add manpages (Closes: #12) * data: Drop phone-missed-call in 'quiet' profile. Only want LEDs there. * feedbackd: Add helper to set up permissions for LEDs. This helper knows about the triggers and necessary permission. It's intended to be run via udev. * debian: Setup leds via udev. This allows feedbackd to set periodic feedback and makes usable LED devices identifiable by feedbackd. * feedbackd: Support visual feedback via LEDs. later on by using the 'repeat' attribute of the LED pattern trigger. * data: Use LED feedback for missed calls, IMs and SMS * Add generic missed notification. This can be used e.g. by the shell for general purpose notifictions but also for in app notifications of the foreground app. * feedback-manager: Add hint to select feedback profile per event. This e.g. allows events that are meant for haptic only to avoid emitting a sound by omitting the 'full' level and using "quiet" instead. (Closes: #7) * LfbEvent: Add feedback-profile property. This allows to specify the feedback profile to use for this particular event. * cli: Allow to set profile per event. We allowed set the global profile via `-P` use it as per event profile when used with `-E`. [ Dorota Czaplejewicz ] * build: Remove feedback dependencies from libfeedback builds -- Guido Günther <agx@sigxcpu.org> Fri, 10 Jul 2020 11:52:07 +0200 feedbackd (0.0.0+git20200527) amber; urgency=medium [ Rasmus Thomsen ] * build: add proper dependencies on gdbus-codgen-generated headers. Without this it was possible that ninja built a target that needs the generated header before the header was generated [ Guido Günther ] * Release another git snapshot * Honor sound theme on GNOME. We don't set this for other DEs since they might want to pick a good default from elsewhere. -- Guido Günther <agx@sigxcpu.org> Wed, 27 May 2020 10:00:08 +0200 feedbackd (0.0.0+git20200420) amber; urgency=medium [ Guido Günther ] * Release another git snapshot * Add symbols file * theme: order feedbacks alphabetically. * theme: Add feedbacks for window-close and button-press * Allow to lower the feedback level per application. [ Arnaud Ferraris ] * d/control: customize short descriptions per binary package * d/control: change feedbackd-common architecture to 'all' * debian: rename gir package to match typelib name -- Guido Günther <agx@sigxcpu.org> Mon, 20 Apr 2020 09:55:33 +0200 feedbackd (0.0.0+git20200305) amber-phone; urgency=medium * feedbackd-common: Add proper Breaks/Replaces. This handles partial upgrades with newer schema but old feebackd. -- Guido Günther <agx@sigxcpu.org> Mon, 23 Mar 2020 10:21:14 +0100 feedbackd (0.0.0+git20200304) amber-phone; urgency=medium [ Guido Günther ] * libfeedback: Drop trailing semicolon. Trips up some compilers. Thanks to Andrea Schaefer * build: Don't add lfb-enums.c to list of generated sources. Otherwise when used as a subproject the master project will try to rebuild with it's own set of flags. These lack LIBFEEDBACK_COMPILATION which does not end well. * Fix typos * theme: Add timeout-completed event for alarms and stop watches * Update docs (Closes: #4, #8) * debian: Split out shared files. This allows other programs (like gnome-control-center) to consume the settings schema without having to depend on the daemon itself. [ Rasmus Thomsen ] * fbd-feedback-profile: use G_GSIZE_FORMAT instead of hardcoding lu. On 32-bit platforms lu doesn't apply since GType is defined as a gsize fixes #15 -- Guido Günther <agx@sigxcpu.org> Wed, 04 Mar 2020 16:46:36 +0100 feedbackd (0.0.0+git20200214) amber-phone; urgency=medium * Initial git snapshot -- Guido Günther <agx@sigxcpu.org> Wed, 16 Oct 2019 21:22:33 +0200 07070100000017000081A400000000000000000000000164F062AA0000098A000000000000000000000000000000000000001F00000000feedbackd-0.2.1/debian/controlSource: feedbackd Section: x11 Priority: optional Maintainer: Guido Günther <agx@sigxcpu.org> Build-Depends: dbus, debhelper-compat (= 12), dh-sequence-gir, gsettings-desktop-schemas <!nocheck>, gi-docgen <!nodoc>, json-glib-tools, libgirepository1.0-dev, libglib2.0-dev, libgudev-1.0-dev (>= 232), libgsound-dev, libjson-glib-dev, meson, pkg-config, python3-docutils <!nodoc>, valac, Standards-Version: 4.4.0 Homepage: https://source.puri.sm/Librem5/feedbackd Package: feedbackd Architecture: any Depends: ${misc:Depends}, ${shlibs:Depends}, feedbackd-common (>= ${source:Version}), sound-theme-freedesktop, Description: DBus service for haptic/visual/audio feedback Feedbackd is a DBus activated daemon that provides haptic/ visual/audio feedback based on events. . This package contains the daemon. Package: feedbackd-common Architecture: all Depends: ${misc:Depends}, ${shlibs:Depends}, Breaks: feedbackd (<< 0.0.0+git20200304), Replaces: feedbackd (<< 0.0.0+git20200304), Description: Shared files for feedbackd Feedbackd is a DBus activated daemon that provides haptic/ visual/audio feedback based on events. . This package contains the architecture-independent shared files. Package: libfeedback-0.0-0 Architecture: any Section: libs Depends: ${misc:Depends}, ${shlibs:Depends}, Description: Library for managing haptic/visual/audio feedback Feedbackd is a DBus activated daemon that provides haptic/ visual/audio feedback based on events. . This package contains the shared libraries for applications interfacing with Feedbackd and the API documentation. Package: libfeedback-dev Architecture: any Section: libdevel Depends: gir1.2-lfb-0.0 (= ${binary:Version}), libfeedback-0.0-0 (= ${binary:Version}), libglib2.0-dev, ${misc:Depends}, ${shlibs:Depends}, Description: Development files for libfeedback Feedbackd is a DBus activated daemon that provides haptic/ visual/audio feedback based on events. . This package contains development files and Vala bindings to use when writing applications that interface with GThd. Package: gir1.2-lfb-0.0 Architecture: any Section: introspection Depends: ${gir:Depends}, ${misc:Depends}, ${shlibs:Depends}, Description: GObject introspection data for libfeedback Feedbackd is a DBus activated daemon that provides haptic/ visual/audio feedback based on events. . This package contains introspection data for the libfeedback library. 07070100000018000081A400000000000000000000000164F062AA00000723000000000000000000000000000000000000002100000000feedbackd-0.2.1/debian/copyrightFormat: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Upstream-Name: feedbackd Source: https://source.puri.sm/Librem5/feedbackd Files: * Copyright: 2020 Purism SPC License: GPL-3+ This package 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 package 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 <https://www.gnu.org/licenses/> . On Debian systems, the complete text of the GNU General Public License version 3 can be found in "/usr/share/common-licenses/GPL-3". Files: libfeedback/* Copyright: 2020 Purism SPC License: LGPL-2.1+ This package 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 3 of the License, or (at your option) any later version. . This package 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 program. If not, see <https://www.gnu.org/licenses/> . On Debian systems, the complete text of the GNU Lesser General Public License version 3 can be found in "/usr/share/common-licenses/LGPL-2.1". 07070100000019000081A400000000000000000000000164F062AA0000001B000000000000000000000000000000000000003000000000feedbackd-0.2.1/debian/feedbackd-common.installusr/share/glib-2.0/schemas 0707010000001A000081A400000000000000000000000164F062AA00000051000000000000000000000000000000000000002900000000feedbackd-0.2.1/debian/feedbackd.install/usr/bin/ /usr/libexec/ /usr/share/dbus-1/ /usr/share/feedbackd/ /usr/share/man/ 0707010000001B000081A400000000000000000000000164F062AA00000035000000000000000000000000000000000000002D00000000feedbackd-0.2.1/debian/feedbackd.maintscriptrm_conffile /etc/modules-load.d/feedbackd.conf 0.0.4 0707010000001C000081A400000000000000000000000164F062AA00000430000000000000000000000000000000000000002A00000000feedbackd-0.2.1/debian/feedbackd.postinst#!/bin/sh # postinst script for feedbackd # # see: dh_installdeb(1) set -e # summary of how this script can be called: # * <postinst> `configure' <most-recently-configured-version> # * <old-postinst> `abort-upgrade' <new version> # * <conflictor's-postinst> `abort-remove' `in-favour' <package> # <new-version> # * <postinst> `abort-remove' # * <deconfigured's-postinst> `abort-deconfigure' `in-favour' # <failed-install-package> <version> `removing' # <conflicting-package> <version> # for details, see https://www.debian.org/doc/debian-policy/ or # the debian-policy package case "$1" in configure) if ! getent group feedbackd >/dev/null; then addgroup --quiet --system feedbackd fi ;; 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 0707010000001D000081A400000000000000000000000164F062AA000002B4000000000000000000000000000000000000002600000000feedbackd-0.2.1/debian/feedbackd.udev# SPDX-License-Identifier: LGPL-2.1+ # # This file is part of feedbackd. ACTION=="remove", GOTO="feedbackd_end" SUBSYSTEM=="input", KERNEL=="event*", ENV{ID_INPUT}=="1", ENV{ID_PATH}=="platform-vibrator", TAG+="uaccess", ENV{FEEDBACKD_TYPE}="vibra" # See include/dt-bindings/leds/common.h in the linux kernel SUBSYSTEM=="leds", DEVPATH=="*/*:status", ENV{FEEDBACKD_TYPE}="led", RUN{builtin}+="kmod load ledtrig-pattern", RUN+="/usr/libexec/fbd-ledctrl -p %S%p -t pattern -G feedbackd" SUBSYSTEM=="leds", DEVPATH=="*/*:indicator", ENV{FEEDBACKD_TYPE}="led", RUN{builtin}+="kmod load ledtrig-pattern", RUN+="/usr/libexec/fbd-ledctrl -p %S%p -t pattern -G feedbackd" LABEL="feedbackd_end" 0707010000001E000081A400000000000000000000000164F062AA000000C5000000000000000000000000000000000000002000000000feedbackd-0.2.1/debian/gbp.conf[DEFAULT] debian-branch = main debian-tag = v%(version)s debian-tag-msg = %(pkg)s v%(version)s [dch] postedit = sed -i s"@^\( \+version *: '\)[0-9.]\+\(',\)@\1$GBP_DEBIAN_VERSION\2@" meson.build 0707010000001F000081A400000000000000000000000164F062AA0000001C000000000000000000000000000000000000002E00000000feedbackd-0.2.1/debian/gir1.2-lfb-0.0.install/usr/lib/*/girepository-1.0 07070100000020000081A400000000000000000000000164F062AA0000001E000000000000000000000000000000000000003100000000feedbackd-0.2.1/debian/libfeedback-0.0-0.install/usr/lib/*/libfeedback-*.so.0 07070100000021000081A400000000000000000000000164F062AA00000B3A000000000000000000000000000000000000003100000000feedbackd-0.2.1/debian/libfeedback-0.0-0.symbolslibfeedback-0.0.so.0 libfeedback-0.0-0 #MINVER# LIBFEEDBACK_0_0_0@LIBFEEDBACK_0_0_0 0.1.1 lfb_event_end_feedback@LIBFEEDBACK_0_0_0 0.1.1 lfb_event_end_feedback_async@LIBFEEDBACK_0_0_0 0.1.1 lfb_event_end_feedback_finish@LIBFEEDBACK_0_0_0 0.1.1 lfb_event_end_reason_get_type@LIBFEEDBACK_0_0_0 0.1.1 lfb_event_get_app_id@LIBFEEDBACK_0_0_0 0.2.0 lfb_event_get_end_reason@LIBFEEDBACK_0_0_0 0.1.1 lfb_event_get_event@LIBFEEDBACK_0_0_0 0.1.1 lfb_event_get_feedback_profile@LIBFEEDBACK_0_0_0 0.1.1 lfb_event_get_state@LIBFEEDBACK_0_0_0 0.1.1 lfb_event_get_timeout@LIBFEEDBACK_0_0_0 0.1.1 lfb_event_get_type@LIBFEEDBACK_0_0_0 0.1.1 lfb_event_new@LIBFEEDBACK_0_0_0 0.1.1 lfb_event_set_app_id@LIBFEEDBACK_0_0_0 0.2.0 lfb_event_set_feedback_profile@LIBFEEDBACK_0_0_0 0.1.1 lfb_event_set_timeout@LIBFEEDBACK_0_0_0 0.1.1 lfb_event_state_get_type@LIBFEEDBACK_0_0_0 0.1.1 lfb_event_trigger_feedback@LIBFEEDBACK_0_0_0 0.1.1 lfb_event_trigger_feedback_async@LIBFEEDBACK_0_0_0 0.1.1 lfb_event_trigger_feedback_finish@LIBFEEDBACK_0_0_0 0.1.1 lfb_gdbus_feedback_call_end_feedback@LIBFEEDBACK_0_0_0 0.1.1 lfb_gdbus_feedback_call_end_feedback_finish@LIBFEEDBACK_0_0_0 0.1.1 lfb_gdbus_feedback_call_end_feedback_sync@LIBFEEDBACK_0_0_0 0.1.1 lfb_gdbus_feedback_call_trigger_feedback@LIBFEEDBACK_0_0_0 0.1.1 lfb_gdbus_feedback_call_trigger_feedback_finish@LIBFEEDBACK_0_0_0 0.1.1 lfb_gdbus_feedback_call_trigger_feedback_sync@LIBFEEDBACK_0_0_0 0.1.1 lfb_gdbus_feedback_complete_end_feedback@LIBFEEDBACK_0_0_0 0.1.1 lfb_gdbus_feedback_complete_trigger_feedback@LIBFEEDBACK_0_0_0 0.1.1 lfb_gdbus_feedback_dup_profile@LIBFEEDBACK_0_0_0 0.1.1 lfb_gdbus_feedback_emit_feedback_ended@LIBFEEDBACK_0_0_0 0.1.1 lfb_gdbus_feedback_get_profile@LIBFEEDBACK_0_0_0 0.1.1 lfb_gdbus_feedback_get_type@LIBFEEDBACK_0_0_0 0.1.1 lfb_gdbus_feedback_interface_info@LIBFEEDBACK_0_0_0 0.1.1 lfb_gdbus_feedback_override_properties@LIBFEEDBACK_0_0_0 0.1.1 lfb_gdbus_feedback_proxy_get_type@LIBFEEDBACK_0_0_0 0.1.1 lfb_gdbus_feedback_proxy_new@LIBFEEDBACK_0_0_0 0.1.1 lfb_gdbus_feedback_proxy_new_finish@LIBFEEDBACK_0_0_0 0.1.1 lfb_gdbus_feedback_proxy_new_for_bus@LIBFEEDBACK_0_0_0 0.1.1 lfb_gdbus_feedback_proxy_new_for_bus_finish@LIBFEEDBACK_0_0_0 0.1.1 lfb_gdbus_feedback_proxy_new_for_bus_sync@LIBFEEDBACK_0_0_0 0.1.1 lfb_gdbus_feedback_proxy_new_sync@LIBFEEDBACK_0_0_0 0.1.1 lfb_gdbus_feedback_set_profile@LIBFEEDBACK_0_0_0 0.1.1 lfb_gdbus_feedback_skeleton_get_type@LIBFEEDBACK_0_0_0 0.1.1 lfb_gdbus_feedback_skeleton_new@LIBFEEDBACK_0_0_0 0.1.1 lfb_get_app_id@LIBFEEDBACK_0_0_0 0.1.1 lfb_get_feedback_profile@LIBFEEDBACK_0_0_0 0.1.1 lfb_get_proxy@LIBFEEDBACK_0_0_0 0.1.1 lfb_init@LIBFEEDBACK_0_0_0 0.1.1 lfb_is_initted@LIBFEEDBACK_0_0_0 0.1.1 lfb_set_app_id@LIBFEEDBACK_0_0_0 0.1.1 lfb_set_feedback_profile@LIBFEEDBACK_0_0_0 0.1.1 lfb_uninit@LIBFEEDBACK_0_0_0 0.1.1 07070100000022000081A400000000000000000000000164F062AA000000B1000000000000000000000000000000000000002F00000000feedbackd-0.2.1/debian/libfeedback-dev.install/usr/include /usr/share/gir-1.0/ /usr/share/doc/libfeedback-0 /usr/share/doc/libfeedback-dev/ /usr/share/vala/ /usr/lib/*/libfeedback-*.so /usr/lib/*/pkgconfig/libfeedback-*.pc 07070100000023000081A400000000000000000000000164F062AA00000052000000000000000000000000000000000000002D00000000feedbackd-0.2.1/debian/libfeedback-dev.linksusr/share/doc/libfeedback-dev/libfeedback-0 usr/share/devhelp/books/libfeedback-0 07070100000024000081ED00000000000000000000000164F062AA00000242000000000000000000000000000000000000001D00000000feedbackd-0.2.1/debian/rules#!/usr/bin/make -f export DEB_BUILD_MAINT_OPTIONS = hardening=+all ifneq (,$(filter nocheck,$(DEB_BUILD_OPTIONS))) CONFIGURE_OPTS += -Dtests=false endif ifeq (,$(filter nodoc,$(DEB_BUILD_PROFILES))) CONFIGURE_OPTS += -Dgtk_doc=true -Dman=true endif %: dh $@ --builddirectory=_build override_dh_auto_configure: dh_auto_configure -- $(CONFIGURE_OPTS) override_dh_installudev: # Make sure all the symlink rules in 60 ran: dh_installudev --priority=90 override_dh_auto_test: ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS))) dbus-run-session ninja -C _build test endif 07070100000025000041ED00000000000000000000000264F062AA00000000000000000000000000000000000000000000001E00000000feedbackd-0.2.1/debian/source07070100000026000081A400000000000000000000000164F062AA0000000D000000000000000000000000000000000000002500000000feedbackd-0.2.1/debian/source/format3.0 (native) 07070100000027000041ED00000000000000000000000264F062AA00000000000000000000000000000000000000000000001D00000000feedbackd-0.2.1/debian/tests07070100000028000081ED00000000000000000000000164F062AA000000E6000000000000000000000000000000000000002800000000feedbackd-0.2.1/debian/tests/build-test#!/usr/bin/make -f CFLAGS=$(shell pkg-config --cflags libfeedback-0.0) LIBS=$(shell pkg-config --libs libfeedback-0.0) t1: debian/tests/build-test.c gcc -o $@ $(CFLAGS) $< $(LIBS) @echo "Build test of $< succeeded" @rm -f $@ 07070100000029000081A400000000000000000000000164F062AA0000009B000000000000000000000000000000000000002A00000000feedbackd-0.2.1/debian/tests/build-test.c#define LIBFEEDBACK_USE_UNSTABLE_API #include <libfeedback.h> int main (int argc, char **argv) { lfb_init("org.sigxcpu.autopkgtest1", NULL); } 0707010000002A000081A400000000000000000000000164F062AA00000112000000000000000000000000000000000000002500000000feedbackd-0.2.1/debian/tests/controlTests: build-test Depends: build-essential, libfeedback-dev, pkg-config, Restrictions: allow-stderr, superficial Test-Command: python3 -c 'import gi; from gi.repository import Lfb' Depends: gir1.2-lfb-0.0, python3, python3-gi, Restrictions: allow-stderr, superficial 0707010000002B000041ED00000000000000000000000264F062AA00000000000000000000000000000000000000000000001400000000feedbackd-0.2.1/doc0707010000002C000081A400000000000000000000000164F062AA0000145F000000000000000000000000000000000000002F00000000feedbackd-0.2.1/doc/Event-naming-spec-0.0.0.mdTitle: Event Naming Specification Slug: Event Naming Specification # Overview This specification gives direction on how to name the Event types (triggering feedbacks such as running the haptic motor or blinking an LED) that are available for use by applications, when creating a feedback theme. It does so by laying out a standard naming scheme for Event creation, as well as providing a minimal list of must have Events, and a larger list with many more examples to help with the creation of extended Events for third party applications, with different event types and usage. This is similar in spirit (and heavily based on) to the [Sound naming spec][]. # Context The list of default contexts for the feedback theme are: - Alerts: Events to alert the user of an action or event which may have a major impact on the system or their current use - Notifications: Events to trigger feedback to notify the user that the system, or their current use case has changed state in some way, e.g. new email arriving - Actions: Event that notify the user on their actions. - Input Event: This triggers feedbacks that give direct response to input events from the user, such as key presses on an on screen keyboard # Event naming guides Here we define some guidelines for when creating new Event names that extend the standardized list of Event names defined here, in order to provide Events for more specific events and usages. Event names are in the en_US.US_ASCII locale. This means that the characters allowed in the Event names must fall within the US-ASCII character set. As a further restriction, all Event names may only contain lowercase letters, numbers, underscore, dash, or period characters. Spaces, colons, slashes, and backslashes are not allowed. Also, sound names must be spelled as they are in the en_US dictionary. Events for branded applications should be named the same as the binary executable for the application, prefixed by the string “x-”, to avoid name space clashes with future standardized names. Example: “x-openoffice-foobar”. ## Standard Event names This section describes the standard Event names that should be used by artists when creating themes, and by developers when writing applications which will use the Feedback Theme Specification. Application developers should only use event names from the *Applications* section as the other sections are reserved for system components. ### Applications These events are meant to be used by applications. #### Notifications - camera-focus: The event used when the camera got focus. - camera-shutter: The event used when a photo was taken. - message-new-instant: The event used when a new IM is received. - message-new-sms: The event used when a new sms is received. - message-new-email: The event used when a new email is received. - message-missed-email: The event used when an email was received but not seen by the user. - message-missed-instant: The event used when a instant message was received but not seen by the user. - message-missed-notification: The event used when a notification was shown but not seen by the user. - message-missed-sms: The event used when a sms message was received but not seen by the user. - phone-incoming-call: The event used when a phone/voip call is coming in. - phone-missed-call: The event used when a phone/voip call is was incoming but not answered. - phone-outgoing-busy: The event used when for outgoing phone/voip call when the responder is busy/not available. - phone-hangup: The event used when a phone/voip call is hung up. - phone-failure: The event used when a phone/voip call is terminated because of a failure. - alarm-clock-elapsed: A user configured alarm elapsed. - timeout-completed: A user configured timeout completed (e.g. a stop watch). #### Actions - message-sent-instant: The sound used when a new IM is sent. #### Input Events - button-pressed: The event used when a button is pressed. - button-released: The event used when a button is released. ### System Components These events are meant to be used by applications. ### Actions - bell-terminal: The sound to use as a terminal bell. - screen-capture: A screenshot was made - theme-demo: A event that should be played for demoing this theme. Usually this should just be an alias for a very representative sound (such as a incoming phone call) of a theme that would work nicely as a demo event for a theme in the theme selector dialog. ### Alerts - battery-low: The Event used when the battery is low (below 20%, for example). - power-unplug-battery-low: The power cable has been unplugged and the battery level is low. ### Notifications - battery-caution: The event used when the battery is nearing exhaustion (below 40%, for example). - battery-full: The event used when the battery is fully loaded up. - device-added: The event used when a device has become available to the desktop, i.e. due to USB plugging. - power-plug: The power cable has been plugged in. - power-unplug: The power cable has been unplugged. #### Input Events - window-close: The sound used when an existing window is closed. [Sound naming spec]: http://0pointer.de/public/sound-naming-spec.html 0707010000002D000081A400000000000000000000000164F062AA000009AF000000000000000000000000000000000000003100000000feedbackd-0.2.1/doc/Feedback-theme-spec-0.0.0.mdTitle: Feedback Theme Specification Slug: Feedback Theme Specification # Overview A feedback theme defines the kind of feedback that events (as described in the [Event naming spec][]) will trigger. The feedback daemon is responsible to select an appropriate feedback theme for a given device. # Definitions - Feedback: A feedback is something that notifies the user that s.th. happened (e.g. a played sound, the vibration of a haptic motor or led blinking). - Feedback theme: A feedback theme is a set of feedbacks grouped by profiles. Each feedback is mapped to a single event. - Feedback Profile: A feedback profile groups feedbacks by "noisiness". The currently defined profiles names are *full*, *quiet* and *silent*. With *full* being the noisiest profile. - Event: What the user should be notified about. The event names are built according to the [Event naming spec][]. # Implementation When an application requests feedback for an event via the feedback daemon the daemon selects the provided feedback like this, capping the noisiness for each limit: 1. The currently selected profile provides the (global) upper limit for noisiness 2. Per application settings impose another upper limit 3. Per event noisiness is the last noisiness constraint 4. All feedback consistent with the resulting limit are selected and run to provide the feedback to the user With the above a feedback theme in YAML format could look like: ```yaml full: - event-name: phone-incoming-call type: Sound effect: phone-incoming-call - event-name: message-new-sms ... quiet: - event-name: phone-incoming-call type: Vibra duration: 0.5s - event-name: message-new-sms ... silent: - event-name: phone-incoming-call type: Led location: Front Color: Green Interval: 0.2s - event-name: message-new-sms ... ``` At the time of writing the theme format is daemon dependent. E.g. feedbackd uses a format [similar to the above in JSON](https://source.puri.sm/Librem5/feedbackd/-/blob/main/data/default.json) # Recommendations - The silent theme should not produce any audible feedback. This includes the buzzing of haptic motors. - The quiet theme should not play any sounds. Haptic motors and LEDs can be used. - The full feedback theme can use any available feedback mechanisms [Event naming spec]: https://source.puri.sm/Librem5/feedbackd/-/blob/main/doc/Event-naming-spec-0.0.0.md 0707010000002E000081A400000000000000000000000164F062AA000004FB000000000000000000000000000000000000002300000000feedbackd-0.2.1/doc/build-howto.mdTitle: Compiling with libfeedback Slug: building # Compiling with libfeedback If you need to build libfeedback, get the source from [here](https://source.puri.sm/Librem5/feedbackd) and see the `README.md` file. ## Using `pkg-config` Like other GObject based libraries, libfeedback uses `pkg-config` to provide compiler options. The package name is `libfeedback-0.0`. When using the Meson build system you can declare a dependency like: ```meson dependency('libfeedback-0.0') ``` ## Bundling the Library ### Using a Subproject Libfeedback can be used as a Meson subproject. Create a `subprojects/libfeedback.wrap` file with the following contents: ```ini [wrap-git] directory=libfeedback url=https://source.puri.sm/Librem5/feedbackd.git revision=main depth=1 ``` Add this to your `meson.build`: ```meson libfeedback = dependency( 'libfeedback-0.0', version: '>= 0.0.1', fallback: ['libfeedback', 'libfeedback_dep'], default_options: [ 'daemon=false', 'man=false', 'gtk_doc=false', 'vapi=false', 'tests=false', ] ) ``` Then the `libfeedback` variable can be used as a dependency. # Next Steps Once libfeedback has been compiled and included into your project, it needs to be initialized. See [Initialization](initialization.html). 0707010000002F000081A400000000000000000000000164F062AA0000044D000000000000000000000000000000000000001E00000000feedbackd-0.2.1/doc/fbcli.rst.. _fbcli(1): ===== fbcli ===== ------------------------ Emit events to feedbackd ------------------------ SYNOPSIS -------- | **fbcli** [OPTIONS...] DESCRIPTION ----------- ``fbcli`` can be used to submit events to ``feedbackd`` to trigger audio, visual or haptic feedback. OPTIONS ======= ``-h``, ``--help`` print help and exit ``-E=EVENT``; ``--event=EVENT`` Submit the given event to ``feedbackd``. Valid events are listes in the event naming spec at https://source.puri.sm/Librem5/feedbackd/-/blob/main/doc/Event-naming-spec-0.0.0.md ``-t=TIMEOUT``; ``--timeout=TIMEOUT`` The timeout in seconds after which feedback for the given event should be stopped. ``-P=PROFILE``; ``--profile=PROFILE`` The feedback profile (``full``, ``quiet``, ``silent``) to use for the given event. If no event is specified then the global feedback profile is changed. ``-w=TIMEOUT``; ``--watch=TIMEOUT`` Maximum timeout to wait for the feedback for the given event to end and ``fbcli`` to exit. See also ======== ``feedbackd(8)`` ``fbd-theme-validate(1)`` ``feedback-themes(5)`` 07070100000030000081A400000000000000000000000164F062AA00000461000000000000000000000000000000000000002B00000000feedbackd-0.2.1/doc/fbd-theme-validate.rst.. _fbd-theme-validate(1): ================== fbd-theme-validate ================== ------------------------- Validate feedbackd themes ------------------------- SYNOPSIS -------- | **fbd-theme-validate** [OPTIONS...] <FILE> DESCRIPTION ----------- ``fbd-theme-validate`` parses and validates the given feedbackd theme file. If the theme specifies parent themes then these are parsed and validates as well. OPTIONS ======= ``-h``, ``--help`` print help and exit ``--version`` print version information and exit ``--compatible=COMPATIBLE`` Specify the device compatible to use. Specify this if you validate a user theme and want to simulate how it would look like on a device with compatible ```COMPATIBLE```. EXAMPLES ======== Validate a custom theme in the users home directory the same way as it would be loaded on a Librem 5: :: fbd-theme-validate --compatible=purism,librem5 ~/.config/feedbackd/themes/custom.json Validate the device theme for a OnePlus 6T: :: fbd-theme-validate /usr/share/feedbackd/themes/oneplus,fajita.json See also ======== ``feedbackd(8)`` ``fbcli(1)`` 07070100000031000081A400000000000000000000000164F062AA00000399000000000000000000000000000000000000002800000000feedbackd-0.2.1/doc/feedback-themes.rst.. _feedback-themes(5): =============== feedback themes =============== --------------------------------- Theme configuration for feedbackd --------------------------------- DESCRIPTION =========== In order to reflect device specifics and user overrides the feedback (such as sound, haptic or led) that are being triggered by events can be configured. This allows for device as well as user specific configuration. Themes use a json format and can be validated by ``fbd-theme-validate``. For details on how to create or modify feedback themes see [feedbackd's documentation]( https://source.puri.sm/Librem5/feedbackd#feedback-theme) Sound events ============ Sound feedbacks specify an event name from a XDG sound theme. Sound themes are described in the [Sound theme spec](https://freedesktop.org/wiki/Specifications/sound-theme-spec/). See also ======== ``feedbackd(8)`` ``fbcli(1)`` ``fbd-theme-validate(1)`` 07070100000032000081A400000000000000000000000164F062AA000003D2000000000000000000000000000000000000002200000000feedbackd-0.2.1/doc/feedbackd.rst.. _feedbackd(8): ========= feedbackd ========= -------------------------------------- A daemon to provide feedback on events -------------------------------------- SYNOPSIS -------- | **feedbackd** [OPTIONS...] DESCRIPTION =========== ``Feedbackd`` is a daemon that runs in the users session to trigger event feedback such as playing a sound, trigger a haptic motor or blink a LED. The feedback triggered by a given event is determined by the feedback theme in use. Events are submitted via a DBus API. Any feedback triggered by a client via an event will be stopped latest when the client disconnects from DBus. This makes sure all feedbacks get canceled if the app that triggered it crashes. For details refer to the event and feedback theme specs at `<https://source.puri.sm/Librem5/feedbackd/>`__ Options ======= ``-h``, ``--help`` print help and exit See also ======== ``fbcli(1)`` ``fbd-theme-validate(1)`` ``feedback-themes(5)`` ``feedback-themes(5)`` 07070100000033000081A400000000000000000000000164F062AA000003E1000000000000000000000000000000000000002600000000feedbackd-0.2.1/doc/initialization.mdTitle: Initialization Slug: initialization # Initialization Before using libfeedback, it must be initialized. To use the library call [func@Lfb.init]() with the id of your application (usually the desktop file name without the .desktop extension). For that you include the `libfeedback.h` header. Since the API is considered unstable at this point in time you need to acknowledge this by definining `LIBFEEDBACK_USE_UNSTABLE_API`: ```c #define LIBFEEDBACK_USE_UNSTABLE_API #include <libfeedback.h> int main(void) { g_autoptr (GError) *err = NULL; if (lfb_init ("com.example.appid", &err)) { g_error ("%s", err->message); } ... lfb_uninit (); return 0; } ``` You can also acknowledge this with the definition option of your C compiler, like `-DFEEDBACK_USE_UNSTABLE_API`. After initializing the library you can trigger feedback using [class@Lfb.Event] objects. When your application finishes call [func@Lfb.uninit]() to free any resources: 07070100000034000081A400000000000000000000000164F062AA0000049F000000000000000000000000000000000000002800000000feedbackd-0.2.1/doc/libfeedback.toml.in[library] version = "@VERSION@" description = "A library to trigger feedback (such as haptic feedback) via events sent by your application." authors = "Purism SPC" license = "LGPL-2.1-or-later" browse_url = "https://source.puri.sm/Librem5/feedbackd/" repository_url = "https://source.puri.sm/Librem5/feedbackd.git" website_url = "https://source.puri.sm/Librem5/feedbackd/" dependencies = [ "Gio-2.0", "GLib-2.0", ] devhelp = true search_index = true [dependencies."Gio-2.0"] name = "GIO" description = "GObject Interfaces and Objects, Networking, IPC, and I/O" docs_url = "https://docs.gtk.org/gio/" [dependencies."GLib-2.0"] name = "GLib " description = "The base type system library" docs_url = "https://docs.gtk.org/glib/" [theme] name = "basic" show_index_summary = true show_class_hierarchy = true [source-location] # The base URL for the web UI base_url = "https://source.puri.sm/Librem5/feedbackd/-/blob/main/" # The format for links, using "filename" and "line" for the format file_format = "{filename}#L{line}" [extra] content_files = [ "overview.md", "build-howto.md", "initialization.md", "Event-naming-spec-0.0.0.md", "Feedback-theme-spec-0.0.0.md", ] 07070100000035000081A400000000000000000000000164F062AA0000074A000000000000000000000000000000000000002000000000feedbackd-0.2.1/doc/meson.buildif get_option('gtk_doc') expand_content_md_files = [ 'overview.md', 'build-howto.md', 'initialization.md', 'Event-naming-spec-0.0.0.md', 'Feedback-theme-spec-0.0.0.md', ] toml_data = configuration_data() toml_data.set('VERSION', meson.project_version()) libfeedback_toml = configure_file( input: 'libfeedback.toml.in', output: 'libfeedback.toml', configuration: toml_data ) dependency('gi-docgen', version: '>= 2021.1', fallback: ['gi-docgen', 'dummy_dep'], native: true, required: get_option('gtk_doc')) gidocgen = find_program('gi-docgen') docs_dir = datadir / 'doc' custom_target('libfeedback-doc', input: [ libfeedback_toml, libfeedback_gir[0] ], output: 'libfeedback-0', command: [ gidocgen, 'generate', '--quiet', '--add-include-path=@0@'.format(meson.current_build_dir() / '../src'), '--config=@INPUT0@', '--output-dir=@OUTPUT@', '--no-namespace-dir', '--content-dir=@0@'.format(meson.current_source_dir()), '@INPUT1@', ], depend_files: [ expand_content_md_files ], build_by_default: true, install: true, install_dir: docs_dir, ) endif if get_option('man') manpages = [ ['fbcli', 1], ['fbd-theme-validate', 1], ['feedbackd', 8], ['feedback-themes', 5], ] rst2man = find_program('rst2man', 'rst2man.py', required: false) rst2man_flags = [ '--syntax-highlight=none', ] foreach manpage: manpages man_name = manpage[0] man_section = manpage[1] custom_target('man-@0@'.format(man_name), input: '@0@.rst'.format(man_name), output: '@0@.@1@'.format(man_name, man_section), command: [ rst2man, rst2man_flags, '@INPUT@', ], capture: true, install: true, install_dir: get_option('mandir') / 'man@0@'.format(man_section), ) endforeach endif 07070100000036000081A400000000000000000000000164F062AA0000038C000000000000000000000000000000000000002000000000feedbackd-0.2.1/doc/overview.mdTitle: Overview Slug: Overview # Libfeedback Introduction The purpose of libfeedback is to make it simple to supply audible, haptic and visual feedback to the user. This is done by notifying a feedback_daemon over DBus that a certain event happened. The daemon then selects the appropriate feedbacks (such as a buzzing haptic motor or playing an audio file) based on the user session's current feedback profile, feedback theme and available hardware. Events are identified by strings like `message-new-sms` or `message-new-sms`. The available event names are described in the [Event naming specification](Event-naming-spec-0.0.0.html). Libfeedback provides synchronous and asynchronous APIs to trigger and stop feedback for these events and is usable from other languages than C by GObject introspection. See [Compiling with libfeedback](build-howto.html) on how to include libfeedback in your project. 07070100000037000041ED00000000000000000000000264F062AA00000000000000000000000000000000000000000000001900000000feedbackd-0.2.1/examples07070100000038000081ED00000000000000000000000164F062AA00000264000000000000000000000000000000000000002400000000feedbackd-0.2.1/examples/example.py#!/usr/bin/python3 # # depends on GObject introspection data for libfeedback # # After building from source you can start this example like this: # _build/run examples/example.py # Otherwise like this: # GI_TYPELIB_PATH=</somepath/girepository-x.y/> example.py import gi import time gi.require_version('Lfb', '0.0') from gi.repository import Lfb Lfb.init('org.sigxcpu.lfbexample') event = Lfb.Event.new('phone-incoming-call') event.trigger_feedback() # feedbackd terminates feedback from clients that disconnect from DBus to avoid # feedback not being stopped. So wait a bit before quitting: time.sleep(3) 07070100000039000081A400000000000000000000000164F062AA0000001C000000000000000000000000000000000000002C00000000feedbackd-0.2.1/gir1.2-feedback-0.0.install/usr/lib/*/girepository-1.0 0707010000003A000041ED00000000000000000000000264F062AA00000000000000000000000000000000000000000000001C00000000feedbackd-0.2.1/libfeedback0707010000003B000081A400000000000000000000000164F062AA00005C56000000000000000000000000000000000000002800000000feedbackd-0.2.1/libfeedback/lfb-event.c/* * Copyright (C) 2020 Purism SPC * SPDX-License-Identifier: LGPL-2.1+ * Author: Guido Günther <agx@sigxcpu.org> */ #include "libfeedback.h" #include "lfb-priv.h" #include <gio/gio.h> /** * LfbEvent: * * An event triggering feedback to the user * * #LfbEvent represents an event that should trigger * audio, haptic and/or visual feedback to the user by triggering * feedback on a feedback daemon. Valid event names are specified * in the * [Event naming specification](Event-naming-spec-0.0.0.html). * * One event can trigger multiple feedbacks at once (e.g. audio and * haptic feedback). This is determined by the feedback theme in * use (which is not under the appliction's control) and the active * feedback profile (see [func@Lfb.set_feedback_profile]. * * After initializing the library via [func@Lfb.init] feedback can be * triggered like: * * ```c * g_autoptr (GError) err = NULL; * LfbEvent *event = lfb_event_new ("message-new-instant"); * lfb_event_set_timeout (event, 0); * if (!lfb_event_trigger_feedback (event, &err)) * g_warning ("Failed to trigger feedback: %s", err->message); * ``` * * When all feedback for this event has ended the [signal@LfbEvent::feedback-ended] * signal is emitted. If you want to end the feedback ahead of time use * [method@LfbEvent.end_feedback]: * * ```c * if (!lfb_event_end_feedback (event, &err)) * g_warning ("Failed to end feedback: %s", err->message); * ``` * * Since these methods involve DBus calls there are asynchronous variants * available, e.g. [method@LfbEvent.trigger_feedback_async]: * * ```c * static void * on_feedback_triggered (LfbEvent *event, * GAsyncResult *res, * gpointer unused) * { * g_autoptr (GError) err = NULL; * if (!lfb_event_trigger_feedback_finish (event, res, &err)) { * g_warning ("Failed to trigger feedback for %s: %s", * lfb_event_get_event (event), err->message); * } * } * * static void * my_function () * { * LfbEvent *event = lfb_event_new ("message-new-instant"); * lfb_event_trigger_feedback_async (event, NULL, * (GAsyncReadyCallback)on_feedback_triggered, * NULL); * } * ``` */ enum { PROP_0, PROP_EVENT, PROP_TIMEOUT, PROP_STATE, PROP_END_REASON, PROP_FEEDBACK_PROFILE, PROP_APP_ID, PROP_LAST_PROP, }; static GParamSpec *props[PROP_LAST_PROP]; enum { SIGNAL_FEEDBACK_ENDED, N_SIGNALS, }; static guint signals[N_SIGNALS]; typedef struct _LfbEvent { GObject parent; char *event; gint timeout; gchar *profile; char *app_id; guint id; LfbEventState state; gint end_reason; gulong handler_id; } LfbEvent; G_DEFINE_TYPE (LfbEvent, lfb_event, G_TYPE_OBJECT); typedef struct _LfbAsyncData { LfbEvent *event; GTask *task; } LfbAsyncData; static void lfb_event_set_state (LfbEvent *self, LfbEventState state) { if (self->state == state) return; self->state = state; g_object_notify_by_pspec (G_OBJECT (self), props[PROP_STATE]); } static void lfb_event_set_end_reason (LfbEvent *self, LfbEventEndReason reason) { if (self->end_reason == reason) return; self->end_reason = reason; g_object_notify_by_pspec (G_OBJECT (self), props[PROP_END_REASON]); } static GVariant * build_hints (LfbEvent *self) { GVariantBuilder hints_builder; g_variant_builder_init (&hints_builder, G_VARIANT_TYPE ("a{sv}")); if (self->profile) g_variant_builder_add (&hints_builder, "{sv}", "profile", g_variant_new_string (self->profile)); return g_variant_builder_end (&hints_builder); } static void on_trigger_feedback_finished (LfbGdbusFeedback *proxy, GAsyncResult *res, LfbAsyncData *data) { GTask *task = data->task; LfbEvent *self = data->event; g_autoptr (GError) err = NULL; gboolean success; g_return_if_fail (G_IS_TASK (task)); g_return_if_fail (LFB_GDBUS_IS_FEEDBACK (proxy)); g_return_if_fail (LFB_IS_EVENT (self)); success = lfb_gdbus_feedback_call_trigger_feedback_finish (proxy, &self->id, res, &err); lfb_event_set_state (self, success ? LFB_EVENT_STATE_RUNNING : LFB_EVENT_STATE_ERRORED); if (!success) { g_task_return_error (task, g_steal_pointer (&err)); } else { g_task_return_boolean (task, TRUE); _lfb_active_add_id (self->id); } g_free (data); g_object_unref (task); g_object_unref (self); } static void on_end_feedback_finished (LfbGdbusFeedback *proxy, GAsyncResult *res, LfbAsyncData *data) { GTask *task = data->task; LfbEvent *self = data->event; g_autoptr (GError) err = NULL; gboolean success; g_return_if_fail (G_IS_TASK (task)); g_return_if_fail (LFB_GDBUS_IS_FEEDBACK (proxy)); g_return_if_fail (LFB_IS_EVENT (self)); success = lfb_gdbus_feedback_call_end_feedback_finish (proxy, res, &err); if (!success) { g_task_return_error (task, g_steal_pointer (&err)); } else g_task_return_boolean (task, TRUE); g_free (data); g_object_unref (task); g_object_unref (self); } static void lfb_event_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) { LfbEvent *self = LFB_EVENT (object); switch (property_id) { case PROP_EVENT: g_free (self->event); self->event = g_value_dup_string (value); g_object_notify_by_pspec (G_OBJECT (self), props[PROP_EVENT]); break; case PROP_TIMEOUT: lfb_event_set_timeout (self, g_value_get_int (value)); break; case PROP_FEEDBACK_PROFILE: lfb_event_set_feedback_profile (self, g_value_get_string (value)); break; case PROP_APP_ID: lfb_event_set_app_id (self, g_value_get_string (value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; } } static void lfb_event_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec) { LfbEvent *self = LFB_EVENT (object); switch (property_id) { case PROP_EVENT: g_value_set_string (value, self->event); break; case PROP_TIMEOUT: g_value_set_int (value, self->timeout); break; case PROP_FEEDBACK_PROFILE: g_value_set_string (value, lfb_event_get_feedback_profile (self)); break; case PROP_APP_ID: g_value_set_string (value, lfb_event_get_app_id (self)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; } } static void lfb_event_finalize (GObject *object) { LfbEvent *self = LFB_EVENT (object); /* Signal handler is disconnected automatically due to g_signal_connect_object */ self->handler_id = 0; g_clear_pointer (&self->event, g_free); g_clear_pointer (&self->profile, g_free); g_clear_pointer (&self->app_id, g_free); G_OBJECT_CLASS (lfb_event_parent_class)->finalize (object); } static void lfb_event_class_init (LfbEventClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->set_property = lfb_event_set_property; object_class->get_property = lfb_event_get_property; object_class->finalize = lfb_event_finalize; /** * LfbEvent:event: * * The type of event from the Event naming spec, e.g. 'message-new-instant'. */ props[PROP_EVENT] = g_param_spec_string ( "event", "Event", "The name of the event triggering the feedback", NULL, G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); /** * LfbEvent:timeout: * * How long feedback should be provided in seconds. The special value * %-1 uses the natural length of each feedback while %0 plays each feedback * in a loop until ended explicitly via e.g. [method@LfbEvent.end_feedback]. */ props[PROP_TIMEOUT] = g_param_spec_int ( "timeout", "Timeout", "When the event should timeout", -1, G_MAXINT, -1, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); props[PROP_STATE] = g_param_spec_enum ( "state", "State", "The event's state", LFB_TYPE_EVENT_STATE, LFB_EVENT_END_REASON_NATURAL, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY); props[PROP_END_REASON] = g_param_spec_enum ( "end-reason", "End reason", "The reason why the feedbacks ended", LFB_TYPE_EVENT_END_REASON, LFB_EVENT_END_REASON_NATURAL, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY); /** * LfbEvent:feedback-profile: * * The name of the feedback profile to use for this event. See * [method@LfbEvent.set_feedback_profile] for details. */ props[PROP_FEEDBACK_PROFILE] = g_param_spec_string ( "feedback-profile", "Feedback profile", "Feedback profile to use for this event", NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY); /** * LfbEvent:app-id: * * The application id to use for the event. * [method@LfbEvent.set_feedback_profile] for details. */ props[PROP_APP_ID] = g_param_spec_string ( "app-id", "Application Id", "The Application id to use for this event", NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY); g_object_class_install_properties (object_class, PROP_LAST_PROP, props); /** * LfbEvent::feedback-ended: * * Emitted when all feedbacks triggered by the event have ended. */ signals[SIGNAL_FEEDBACK_ENDED] = g_signal_new ("feedback-ended", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 0); } static void lfb_event_init (LfbEvent *self) { self->timeout = -1; self->state = LFB_EVENT_STATE_NONE; self->end_reason = LFB_EVENT_END_REASON_NATURAL; } /** * lfb_event_new: * @event: The event's name. * * Creates a new [class@Lfb.Event] based on the given event * name. See [property@Lfb.Event:event] for details. * * Returns: The [class@Lfb.Event]. */ LfbEvent * lfb_event_new (const char *event) { return g_object_new (LFB_TYPE_EVENT, "event", event, NULL); } static void on_feedback_ended (LfbEvent *self, guint event_id, guint reason, LfbGdbusFeedback *proxy) { g_return_if_fail (LFB_IS_EVENT (self)); g_return_if_fail (LFB_GDBUS_IS_FEEDBACK (proxy)); if (event_id != self->id) return; lfb_event_set_end_reason (self, reason); lfb_event_set_state (self, LFB_EVENT_STATE_ENDED); g_signal_emit (self, signals[SIGNAL_FEEDBACK_ENDED], 0); _lfb_active_remove_id (self->id); self->id = 0; g_signal_handler_disconnect (proxy, self->handler_id); self->handler_id = 0; } /** * lfb_event_trigger_feedback: * @self: The event to trigger feedback for. * @error: The returned error information. * * Tells the feedback server to provide proper feedback for the give * event to the user. * * Returns: %TRUE if successful. On error, this will return %FALSE and set * @error. */ gboolean lfb_event_trigger_feedback (LfbEvent *self, GError **error) { LfbGdbusFeedback *proxy; gboolean success; const char *app_id; g_return_val_if_fail (LFB_IS_EVENT (self), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); if (!lfb_is_initted ()) g_error ("You must call lfb_init() before triggering events."); proxy = _lfb_get_proxy (); g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), FALSE); if (self->handler_id == 0) { self->handler_id = g_signal_connect_object (proxy, "feedback-ended", G_CALLBACK (on_feedback_ended), self, G_CONNECT_SWAPPED); } app_id = self->app_id ?: lfb_get_app_id (); success = lfb_gdbus_feedback_call_trigger_feedback_sync (proxy, app_id, self->event, build_hints (self), self->timeout, &self->id, NULL, error); if (success) _lfb_active_add_id (self->id); lfb_event_set_state (self, success ? LFB_EVENT_STATE_RUNNING : LFB_EVENT_STATE_ERRORED); return success; } /** * lfb_event_trigger_feedback_async: * @self: The event to trigger feedback for. * @cancellable: (nullable): A #GCancellable to cancel the operation or %NULL. * @callback: A #GAsyncReadyCallback to call when the request is satisfied or %NULL. * @user_data: User data to pass to @callback. * * Tells the feedback server to provide proper feedback for the give * event to the user. This is the sync version of * [method@LfbEvent.trigger_feedback]. */ void lfb_event_trigger_feedback_async (LfbEvent *self, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { LfbAsyncData *data; LfbGdbusFeedback *proxy; const char *app_id; g_return_if_fail (LFB_IS_EVENT (self)); if (!lfb_is_initted ()) g_error ("You must call lfb_init() before triggering events."); proxy = _lfb_get_proxy (); g_return_if_fail (LFB_GDBUS_IS_FEEDBACK (proxy)); if (self->handler_id == 0) { self->handler_id = g_signal_connect_object (proxy, "feedback-ended", G_CALLBACK (on_feedback_ended), self, G_CONNECT_SWAPPED); } data = g_new0 (LfbAsyncData, 1); data->task = g_task_new (self, cancellable, callback, user_data); data->event = g_object_ref (self); app_id = self->app_id ?: lfb_get_app_id (); lfb_gdbus_feedback_call_trigger_feedback (proxy, app_id, self->event, build_hints (self), self->timeout, cancellable, (GAsyncReadyCallback)on_trigger_feedback_finished, data); } /** * lfb_event_trigger_feedback_finish: * @self: the event * @res: Result object passed to the callback of [method@LfbEvent.trigger_feedback_async] * @error: Return location for error * * Finish an async operation started by [method@LfbEvent.trigger_feedback_async]. You * must call this function in the callback to free memory and receive any * errors which occurred. * * Returns: %TRUE if triggering the feedbacks was successful */ gboolean lfb_event_trigger_feedback_finish (LfbEvent *self, GAsyncResult *res, GError **error) { g_return_val_if_fail (g_task_is_valid (res, self), FALSE); return g_task_propagate_boolean (G_TASK (res), error); } /** * lfb_event_end_feedback: * @self: The event to end feedback for. * @error: The returned error information. * * Tells the feedback server to end all feedback for the given event as * soon as possible. * * Returns: %TRUE if successful. On error, this will return %FALSE and set * @error. */ gboolean lfb_event_end_feedback (LfbEvent *self, GError **error) { LfbGdbusFeedback *proxy; g_return_val_if_fail (LFB_IS_EVENT (self), FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); if (!lfb_is_initted ()) g_error ("You must call lfb_init() before ending events."); proxy = _lfb_get_proxy (); g_return_val_if_fail (LFB_GDBUS_IS_FEEDBACK (proxy), FALSE); return lfb_gdbus_feedback_call_end_feedback_sync (proxy, self->id, NULL, error); } /** * lfb_event_end_feedback_finish: * @self: the event * @res: Result object passed to the callback of [method@LfbEvent.end_feedback_async] * @error: Return location for error * * Finish an async operation started by lfb_event_end_feedback_async. You * must call this function in the callback to free memory and receive any * errors which occurred. * * This does not mean that the feedbacks finished right away. Connect to the * [@signal@LfbEvent::feedback-ended] signal for this. * * Returns: %TRUE if ending the feedbacks was successful */ gboolean lfb_event_end_feedback_finish (LfbEvent *self, GAsyncResult *res, GError **error) { g_return_val_if_fail (g_task_is_valid (res, self), FALSE); return g_task_propagate_boolean (G_TASK (res), error); } /** * lfb_event_end_feedback_async: * @self: The event to end feedback for. * @cancellable: (nullable): A #GCancellable to cancel the operation or %NULL. * @callback: A #GAsyncReadyCallback to call when the request is satisfied or %NULL. * @user_data: User data to pass to @callback. * * Tells the feedback server to end all feedback for the given event as * soon as possible. */ void lfb_event_end_feedback_async (LfbEvent *self, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { LfbAsyncData *data; LfbGdbusFeedback *proxy; g_return_if_fail (LFB_IS_EVENT (self)); if (!lfb_is_initted ()) g_error ("You must call lfb_init() before ending events."); proxy = _lfb_get_proxy (); g_return_if_fail (LFB_GDBUS_IS_FEEDBACK (proxy)); data = g_new0 (LfbAsyncData, 1); data->task = g_task_new (self, cancellable, callback, user_data); data->event = g_object_ref (self); lfb_gdbus_feedback_call_end_feedback (proxy, self->id, cancellable, (GAsyncReadyCallback)on_end_feedback_finished, data); } /** * lfb_event_set_timeout: * @self: The event * @timeout: The timeout * * Tells the feedback server to end feedack after #timeout seconds. * The value -1 indicates to not set a timeout and let feedbacks stop * on their own while 0 indicates to loop all feedbacks endlessly. * They must be stopped via [method@LfbEvent.end_feedback] in this case. * * It is an error to change the timeout after the feedback has been triggered * via [method@LfbEvent.trigger_feedback]. */ void lfb_event_set_timeout (LfbEvent *self, gint timeout) { g_return_if_fail (LFB_IS_EVENT (self)); if (self->timeout == timeout) return; self->timeout = timeout; g_object_notify_by_pspec (G_OBJECT (self), props[PROP_TIMEOUT]); } /** * lfb_event_get_event: * @self: The event * * Get the event's name according to the event naming spec. * * Returns: The event name */ const char * lfb_event_get_event (LfbEvent *self) { g_return_val_if_fail (LFB_IS_EVENT (self), NULL); return self->event; } /** * lfb_event_get_timeout: * @self: The event * * Get the currently set timeout. * * Returns: The event timeout in milliseconds */ gint lfb_event_get_timeout (LfbEvent *self) { g_return_val_if_fail (LFB_IS_EVENT (self), -1); return self->timeout; } /** * lfb_event_get_state: * @self: The event * * Get the current event state (e.g. if triggered feeedback is * currently running. * * Returns: The state of the feedback triggered by event. */ LfbEventState lfb_event_get_state (LfbEvent *self) { g_return_val_if_fail (LFB_IS_EVENT (self), LFB_EVENT_STATE_NONE); return self->state; } /** * lfb_event_get_end_reason: * @self: The event * * Get the reason why the feadback ended. * * Returns: The reason why feedback ended. */ LfbEventEndReason lfb_event_get_end_reason (LfbEvent *self) { g_return_val_if_fail (LFB_IS_EVENT (self), LFB_EVENT_END_REASON_NATURAL); return self->end_reason; } /** * lfb_event_set_feedback_profile: * @self: The event * @profile: The feedback profile to use * * Tells the feedback server to use the given feedback profile for * this event when it is submitted. The server might ignore this * request. Valid profile names and their 'noisiness' are specified * in the [Feedback theme specification](Feedback-theme-spec-0.0.0.html). * * A value of %NULL (the default) lets the server pick the profile. */ void lfb_event_set_feedback_profile (LfbEvent *self, const gchar *profile) { g_return_if_fail (LFB_IS_EVENT (self)); if (!g_strcmp0 (self->profile, profile)) return; g_free (self->profile); self->profile = g_strdup (profile); g_object_notify_by_pspec (G_OBJECT (self), props[PROP_FEEDBACK_PROFILE]); } /** * lfb_event_get_feedback_profile: * @self: The event * * Gets the set feedback profile. If no profile was set it returns * %NULL. The event uses the system wide profile in this case. * * Returns: The set feedback profile to use for this event or %NULL. */ const char * lfb_event_get_feedback_profile (LfbEvent *self) { g_return_val_if_fail (LFB_IS_EVENT (self), NULL); return self->profile; } /** * lfb_event_set_app_id: * @self: The event * @app_id: The application id to use * * Tells the feedback server to use the given application id for * this event when it is submitted. The server might ignore this * request. This can be used by notification daemons to honor per * application settings automatically. * * The functions is usually not used by applications. * * A value of %NULL (the default) lets the server pick the profile. */ void lfb_event_set_app_id (LfbEvent *self, const gchar *app_id) { g_return_if_fail (LFB_IS_EVENT (self)); if (!g_strcmp0 (self->app_id, app_id)) return; g_free (self->app_id); self->app_id = g_strdup (app_id); g_object_notify_by_pspec (G_OBJECT (self), props[PROP_APP_ID]); } /** * lfb_event_get_app_id: * @self: The event * * Returns the app-id for this event. If no app-id has been explicitly * set, %NULL is returned. The event uses the app-id returned by * [func@Lfb.get_app_id] in this case. * * Returns:(transfer none): The set app-id for this event or %NULL. */ const char * lfb_event_get_app_id (LfbEvent *self) { g_return_val_if_fail (LFB_IS_EVENT (self), NULL); return self->app_id; } 0707010000003C000081A400000000000000000000000164F062AA00000D8F000000000000000000000000000000000000002800000000feedbackd-0.2.1/libfeedback/lfb-event.h/* * Copyright (C) 2020 Purism SPC * * SPDX-License-Identifier: LGPL-2.1+ */ #pragma once #include <gio/gio.h> #include <glib-object.h> #if !defined (__LIBFEEDBACK_H_INSIDE__) && !defined (LIBFEEDBACK_COMPILATION) #error "Only <libfeedback.h> can be included directly." #endif G_BEGIN_DECLS /** * LfbEventState: * @LFB_EVENT_STATE_ERRORED: An error occurred triggering feedbacks * @LFB_EVENT_STATE_NONE: No state information yet * @LFB_EVENT_STATE_RUNNING: The feedbacks for this event are currently running * @LFB_EVENT_STATE_ENDED: All feedbacks for this event ended * * Enum values to indicate the current state of the feedbacks * triggered by an event. */ typedef enum _LfbEventState { LFB_EVENT_STATE_ERRORED = -1, LFB_EVENT_STATE_NONE = 0, LFB_EVENT_STATE_RUNNING = 1, LFB_EVENT_STATE_ENDED = 2, } LfbEventState; /** * LfbEventEndReason: * @LFB_EVENT_END_REASON_NOT_FOUND: There was no feedback in the current theme for this event * so no feedback was provided to the user. * @LFB_EVENT_END_REASON_NATURAL: All feedbacks finished playing their natural length * @LFB_EVENT_END_REASON_EXPIRED: Feedbacks ran until the set timeout expired * @LFB_EVENT_END_REASON_EXPLICIT: The feedbacks were ended explicitly * * Enum values used to indicate why the feedbacks for an event ended. **/ typedef enum _LfbEventEndReason { LFB_EVENT_END_REASON_NOT_FOUND = -1, LFB_EVENT_END_REASON_NATURAL = 0, LFB_EVENT_END_REASON_EXPIRED = 1, LFB_EVENT_END_REASON_EXPLICIT = 2, } LfbEventEndReason; #define LFB_TYPE_EVENT (lfb_event_get_type()) G_DECLARE_FINAL_TYPE (LfbEvent, lfb_event, LFB, EVENT, GObject) LfbEvent* lfb_event_new (const char *event); gboolean lfb_event_trigger_feedback (LfbEvent *self, GError **error); void lfb_event_trigger_feedback_async (LfbEvent *self, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); gboolean lfb_event_trigger_feedback_finish (LfbEvent *self, GAsyncResult *res, GError **error); gboolean lfb_event_end_feedback (LfbEvent *self, GError **error); void lfb_event_end_feedback_async (LfbEvent *self, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); gboolean lfb_event_end_feedback_finish (LfbEvent *self, GAsyncResult *res, GError **error); void lfb_event_set_timeout (LfbEvent *self, gint timeout); gint lfb_event_get_timeout (LfbEvent *self); void lfb_event_set_feedback_profile (LfbEvent *self, const char *profile); const char *lfb_event_get_feedback_profile (LfbEvent *self); void lfb_event_set_app_id (LfbEvent *self, const char *app_id); const char *lfb_event_get_app_id (LfbEvent *self); const char *lfb_event_get_event (LfbEvent *self); LfbEventState lfb_event_get_state (LfbEvent *self); LfbEventEndReason lfb_event_get_end_reason (LfbEvent *self); G_END_DECLS 0707010000003D000081A400000000000000000000000164F062AA000000E2000000000000000000000000000000000000002800000000feedbackd-0.2.1/libfeedback/lfb-names.h/* * Copyright (C) 2020 Purism SPC * * SPDX-License-Identifier: LGPL-2.1+ */ #pragma once #define FB_DBUS_NAME "org.sigxcpu.Feedback" #define FB_DBUS_PATH "/org/sigxcpu/Feedback" #define FB_DBUS_TYPE G_BUS_TYPE_SESSION 0707010000003E000081A400000000000000000000000164F062AA00000137000000000000000000000000000000000000002700000000feedbackd-0.2.1/libfeedback/lfb-priv.h/* * Copyright (C) 2020 Purism SPC * * SPDX-License-Identifier: LGPL-2.1+ */ #pragma once #include <gio/gio.h> #include "lfb-gdbus.h" G_BEGIN_DECLS LfbGdbusFeedback *_lfb_get_proxy (void); void _lfb_active_add_id (guint id); void _lfb_active_remove_id (guint id); G_END_DECLS 0707010000003F000081A400000000000000000000000164F062AA0000125C000000000000000000000000000000000000002A00000000feedbackd-0.2.1/libfeedback/libfeedback.c/* * Copyright (C) 2020 Purism SPC * SPDX-License-Identifier: LGPL-2.1+ * Author: Guido Günther <agx@sigxcpu.org> */ #include "libfeedback.h" #include "lfb-gdbus.h" #include "lfb-priv.h" #include "lfb-names.h" static LfbGdbusFeedback *_proxy; static char *_app_id; static gboolean _initted; static GHashTable *_active_ids; static void lfb_cancel_feedbacks (void) { gpointer key, value; GHashTableIter iter; g_hash_table_iter_init (&iter, _active_ids); while (g_hash_table_iter_next (&iter, &key, &value)) { guint id = GPOINTER_TO_UINT(key); g_hash_table_iter_remove (&iter); g_debug ("Cancellling feedback on shutdown %d", id); /* Need to use a sync call here since there might not be a main loop anymore */ lfb_gdbus_feedback_call_end_feedback_sync (_proxy, id, NULL, NULL); } } void _lfb_active_add_id (guint id) { g_return_if_fail (id > 0); if (!_initted) return; g_hash_table_add (_active_ids, GUINT_TO_POINTER (id)); } void _lfb_active_remove_id (guint id) { gboolean success; g_return_if_fail (id > 0); if (!_initted) return; success = g_hash_table_remove (_active_ids, GUINT_TO_POINTER(id)); if (!success) g_warning ("Event id %d not known", id); } LfbGdbusFeedback * _lfb_get_proxy (void) { /* Caller needs to check since the proxy might be gone when the last event gets finalized */ return _proxy; } /** * lfb_init: * @app_id: The application id * @error: Error information * * Initialize libfeedback. This must be called before any other of libfeedback's functions. * * Returns: %TRUE if successful, or %FALSE on error. */ gboolean lfb_init (const gchar *app_id, GError **error) { g_return_val_if_fail (app_id != NULL, FALSE); g_return_val_if_fail (*app_id != '\0', FALSE); if (_initted) return TRUE; lfb_set_app_id (app_id); _proxy = lfb_gdbus_feedback_proxy_new_for_bus_sync( FB_DBUS_TYPE, 0, FB_DBUS_NAME, FB_DBUS_PATH, NULL, error); if (!_proxy) return FALSE; _active_ids = g_hash_table_new (g_direct_hash, g_direct_equal); g_object_add_weak_pointer (G_OBJECT (_proxy), (gpointer *) &_proxy); _initted = TRUE; return TRUE; } /** * lfb_uninit: * * Uninitialize the library when no longer used. Usually called * on program shutdown. */ void lfb_uninit (void) { _initted = FALSE; /* Cancel all feedbacks that the client forgot to clean up */ lfb_cancel_feedbacks (); g_clear_pointer (&_active_ids, g_hash_table_destroy); g_clear_pointer (&_app_id, g_free); g_clear_object (&_proxy); } /** * lfb_set_app_id: * @app_id: The application id * * Sets the application id. */ void lfb_set_app_id (const char *app_id) { g_free (_app_id); _app_id = g_strdup (app_id); } /** * lfb_get_app_id: * * Get the application id set via [func@Lfb.set_app_id]. * * Returns: the application id. */ const gchar * lfb_get_app_id (void) { return _app_id; } /** * lfb_is_initted: * * Gets whether or not libfeedback is initialized. * * Returns: %TRUE if libfeedback is initialized, or %FALSE otherwise. */ gboolean lfb_is_initted (void) { return _initted; } /** * lfb_get_feedback_profile: * * Gets the currently set feedback profile. * * Returns: The current profile or %NULL on error. */ const char * lfb_get_feedback_profile (void) { LfbGdbusFeedback *proxy; if (!lfb_is_initted ()) g_error ("You must call lfb_init() before ending events."); proxy = _lfb_get_proxy (); g_return_val_if_fail (LFB_GDBUS_IS_FEEDBACK (proxy), NULL); return lfb_gdbus_feedback_get_profile (LFB_GDBUS_FEEDBACK (proxy)); } /** * lfb_set_feedback_profile: * @profile: The profile to set * * Sets the active feedback profile to #profile. It is up to the feedback * daemon to ignore this request. The new profile might not become active * immediately. You can listen to changes #LfbGdbusFeedback's ::profile * property to get notified when it takes effect. */ void lfb_set_feedback_profile (const gchar *profile) { LfbGdbusFeedback *proxy; if (!lfb_is_initted ()) g_error ("You must call lfb_init() before ending events."); proxy = _lfb_get_proxy (); g_return_if_fail (LFB_GDBUS_IS_FEEDBACK (proxy)); lfb_gdbus_feedback_set_profile (LFB_GDBUS_FEEDBACK (proxy), profile); } /** * lfb_get_proxy: * * This can be used to access the lower level API e.g. to listen to * property changes. The object is not owned by the caller. Don't * unref it after use. * * Returns: (transfer none): The DBus proxy. */ LfbGdbusFeedback * lfb_get_proxy (void) { LfbGdbusFeedback *proxy = _lfb_get_proxy (); g_return_val_if_fail (LFB_GDBUS_IS_FEEDBACK (proxy), NULL); return proxy; } 07070100000040000081A400000000000000000000000164F062AA000002F9000000000000000000000000000000000000002A00000000feedbackd-0.2.1/libfeedback/libfeedback.h/* * Copyright (C) 2020 Purism SPC * * SPDX-License-Identifier: LGPL-2.1+ */ #pragma once #include <glib.h> G_BEGIN_DECLS #define __LIBFEEDBACK_H_INSIDE__ #ifndef LIBFEEDBACK_USE_UNSTABLE_API #error LIBFEEDBACK is unstable API. You must define LIBFEEDBACK_USE_UNSTABLE_API before including libfeedback.h #endif #include "lfb-enums.h" #include "lfb-event.h" #include "lfb-gdbus.h" gboolean lfb_init (const gchar *app_id, GError **error); void lfb_uninit (void); void lfb_set_app_id (const char *app_id); const char *lfb_get_app_id (void); gboolean lfb_is_initted (void); void lfb_set_feedback_profile (const char *profile); const char *lfb_get_feedback_profile (void); LfbGdbusFeedback *lfb_get_proxy (void); G_END_DECLS 07070100000041000081A400000000000000000000000164F062AA00000036000000000000000000000000000000000000002D00000000feedbackd-0.2.1/libfeedback/libfeedback.symsLIBFEEDBACK_0_0_0 { global: lfb_*; local: *; }; 07070100000042000081A400000000000000000000000164F062AA00000CB5000000000000000000000000000000000000002800000000feedbackd-0.2.1/libfeedback/meson.build# Shared library and language bindings libfeedback_libdir = get_option('libdir') libfeedback_header_dir = get_option('includedir') / libname libfeedback_link_args = [] libfeedback_symbols_file = 'libfeedback.syms' # Check linker flags ld_version_script_arg = '-Wl,--version-script,@0@'.format(meson.current_source_dir() / libfeedback_symbols_file) if cc.links('int main() { return 0; }', args : ld_version_script_arg, name : 'ld_supports_version_script') libfeedback_link_args += [ld_version_script_arg] endif lfb_enum_headers = files([ 'lfb-event.h', ]) lfb_enum_sources = gnome.mkenums_simple('lfb-enums', sources : lfb_enum_headers, install_header : true, install_dir: libfeedback_header_dir, ) libfeedback_headers = [ 'libfeedback.h', 'lfb-event.h', ] libfeedback_sources = [ generated_dbus_sources, lfb_enum_sources, libfeedback_headers, 'libfeedback.c', 'lfb-event.c', ] libfeedback_deps = [ gio, gio_unix, glib, ] libfeedback_c_args = [ '-DG_LOG_DOMAIN="libfeedback"', '-DLIBFEEDBACK_COMPILATION', '-DLIBFEEDBACK_USE_UNSTABLE_API', ] libtype = 'shared_library' libfeedback = build_target( 'feedback-' + apiversion, libfeedback_sources, soversion : 0, c_args : libfeedback_c_args, dependencies : libfeedback_deps, link_args : libfeedback_link_args, install : true, install_dir : libfeedback_libdir, target_type : libtype, ) libfeedback_inc = include_directories('.') libfeedback_dep = declare_dependency( sources : [generated_dbus_sources, lfb_enum_sources[1]], link_with : libfeedback, dependencies: libfeedback_deps, include_directories : libfeedback_inc, ) install_headers(libfeedback_headers, subdir : libname) pkgconfig = import('pkgconfig') pkgconfig.generate( libraries : [libfeedback], subdirs : libname, version : meson.project_version(), name : 'Feedback', filebase : 'libfeedback-@0@'.format(apiversion), description : 'GNOME feedback library', requires : 'gio-2.0', install_dir : join_paths(libfeedback_libdir, 'pkgconfig'), ) if introspection libfeedback_gir_extra_args = [ '-I' + dbus_header_dir, '--c-include=libfeedback.h', '--quiet', '-DLIBFEEDBACK_COMPILATION', '-DLIBFEEDBACK_USE_UNSTABLE_API', '--warn-all', ] libfeedback_gir = gnome.generate_gir(libfeedback, sources : libfeedback_sources, nsversion : apiversion, namespace : 'Lfb', export_packages : 'libfeedback-@0@'.format(apiversion), symbol_prefix : 'lfb', identifier_prefix : 'Lfb', link_with : libfeedback, includes : ['Gio-2.0'], install : true, install_dir_gir : girdir, install_dir_typelib : typelibdir, extra_args : libfeedback_gir_extra_args, fatal_warnings : true, ) if get_option('vapi') libfeedback_vapi = gnome.generate_vapi('libfeedback-' + apiversion, sources : libfeedback_gir[0], packages : ['gio-2.0'], install : true, install_dir : vapidir, metadata_dirs : [meson.current_source_dir()], ) endif endif 07070100000043000081A400000000000000000000000164F062AA00000FE4000000000000000000000000000000000000001C00000000feedbackd-0.2.1/meson.buildproject('feedbackd', 'c', version : '0.2.1', license : 'LGPLv3+', meson_version : '>= 0.56.0', default_options : [ 'warning_level=1', 'buildtype=debugoptimized', 'c_std=gnu11', ], ) gio = dependency('gio-2.0', version: '>=2.50.0') gio_unix = dependency('gio-unix-2.0', version: '>=2.50.0') glib = dependency('glib-2.0', version: '>=2.50.0') if get_option('daemon') gobject = dependency('gobject-2.0', version: '>=2.50.0') gmobile_subp = subproject('gmobile', default_options: [ 'examples=false', 'gtk_doc=false', 'tests=false', ]) gmobile = gmobile_subp.get_variable('gmobile_dep') gsound = dependency('gsound') gudev = dependency('gudev-1.0', version: '>=232') json_glib = dependency('json-glib-1.0') endif prefix = get_option('prefix') bindir = join_paths(prefix, get_option('bindir')) datadir = join_paths(prefix, get_option('datadir')) libdir = join_paths(prefix, get_option('libdir')) girdir = join_paths(prefix, join_paths(datadir, 'gir-1.0')) ifacedir = join_paths(prefix, join_paths(datadir, 'dbus-1', 'interfaces')) servicedir = join_paths(prefix, join_paths(datadir, 'dbus-1', 'services')) libexecdir = join_paths(prefix, get_option('libexecdir')) typelibdir = join_paths(prefix, join_paths(libdir, 'girepository-1.0')) vapidir = join_paths(prefix, join_paths(datadir, 'vala', 'vapi')) feedbackd_theme_dir = join_paths(datadir, 'feedbackd', 'themes') run_data = configuration_data() run_data.set('ABS_BUILDDIR', meson.current_build_dir()) run_data.set('ABS_SRCDIR', meson.current_source_dir()) configure_file( input: 'run.in', output: 'run', configuration: run_data) gnome = import('gnome') cc = meson.get_compiler('c') test_c_args = [ '-Wcast-align', '-Wdate-time', ['-Werror=format-security', '-Werror=format=2'], '-Wendif-labels', '-Werror=incompatible-pointer-types', '-Werror=missing-declarations', '-Werror=overflow', '-Werror=return-type', '-Werror=shift-count-overflow', '-Werror=shift-overflow=2', '-Werror=implicit-fallthrough=3', '-Wformat-nonliteral', '-Wformat-security', '-Winit-self', '-Wmaybe-uninitialized', '-Wmissing-field-initializers', '-Wmissing-include-dirs', '-Wmissing-noreturn', '-Wnested-externs', '-Wno-missing-field-initializers', '-Wno-sign-compare', '-Wno-strict-aliasing', '-Wno-unused-parameter', '-Wold-style-definition', '-Wpointer-arith', '-Wredundant-decls', '-Wstrict-prototypes', '-Wtype-limits', '-Wundef', '-Wunused-function', ] if get_option('buildtype') != 'plain' test_c_args += '-fstack-protector-strong' endif global_c_args = [ '-DFEEDBACKD_THEME_DIR="@0@"'.format(feedbackd_theme_dir), '-DLIBFEEDBACK_COMPILATION', '-DFBD_VERSION="@0@"'.format(meson.project_version()), ] add_project_arguments( global_c_args + cc.get_supported_arguments(test_c_args), language: 'c' ) introspection_feature = get_option('introspection') introspection = introspection_feature.enabled() or introspection_feature.auto() apiversion = '0.0' libname = 'libfeedback-' + apiversion json_glib_validate = find_program('json-glib-validate', required: false) meson.add_install_script( join_paths('build-aux', 'post_install.py'), datadir ) subdir('data') subdir('libfeedback') subdir('src') subdir('cli') subdir('tests') subdir('doc') summary = [ '', '---------------', 'feedbackd @0@'.format(meson.project_version()), '', ' Daemon: @0@'.format(get_option('daemon')), ' Documentation: @0@'.format(get_option('gtk_doc')), ' Manual pages: @0@'.format(get_option('man')), ' Introspection: @0@'.format(introspection), ' Vapi: @0@'.format(get_option('vapi')), ' Tests: @0@'.format(get_option('tests')), '---------------', '' ] message('\n'.join(summary)) 07070100000044000081A400000000000000000000000164F062AA00000231000000000000000000000000000000000000002200000000feedbackd-0.2.1/meson_options.txtoption('introspection', type: 'feature', value: 'auto') option('vapi', type: 'boolean', value: true) option('daemon', type: 'boolean', value: true, description: 'Whether to build the daemon') option('gtk_doc', type: 'boolean', value: false, description: 'Whether to generate the API reference for Libfeedback') option('man', type: 'boolean', value : false, description : 'generate man pages (requires rst2man)') option('tests', type: 'boolean', value: true, description: 'Whether to compile unit tests') 07070100000045000081ED00000000000000000000000164F062AA0000019D000000000000000000000000000000000000001700000000feedbackd-0.2.1/run.in#!/bin/sh set -e ABS_BUILDDIR='@ABS_BUILDDIR@' ABS_SRCDIR='@ABS_SRCDIR@' FEEDBACK_THEME=${FEEDBACK_THEME:-"${ABS_SRCDIR}/data/default.json"} export FEEDBACK_THEME export GSETTINGS_SCHEMA_DIR="${ABS_BUILDDIR}/data" export GI_TYPELIB_PATH="${ABS_BUILDDIR}/libfeedback:$GI_TYPELIB_PATH" if [ "${FBD_GDB}" = 1 ]; then echo "Running feedbackd under gdb" WRAPPER="gdb --args" fi set -x exec ${WRAPPER} "$@" 07070100000046000041ED00000000000000000000000264F062AA00000000000000000000000000000000000000000000001400000000feedbackd-0.2.1/src07070100000047000081A400000000000000000000000164F062AA000014D9000000000000000000000000000000000000002D00000000feedbackd-0.2.1/src/fbd-dev-led-multicolor.c/* * Copyright (C) 2023 Purism SPC * SPDX-License-Identifier: GPL-3.0+ * Author: Guido Günther <agx@sigxcpu.org> * * See Documentation/ABI/testing/sysfs-class-led-trigger-pattern */ #define G_LOG_DOMAIN "fbd-dev-led" #include "fbd-dev-led-priv.h" #include "fbd-dev-led-multicolor.h" #include "fbd-enums.h" #include "fbd-udev.h" #include <gio/gio.h> #define LED_MULTI_INDEX_ATTR "multi_index" #define LED_MULTI_INDEX_RED "red" #define LED_MULTI_INDEX_GREEN "green" #define LED_MULTI_INDEX_BLUE "blue" #define LED_MULTI_INTENSITY_ATTR "multi_intensity" typedef struct _FbdDevLedMulticolor { FbdDevLed parent; guint red_index; guint green_index; guint blue_index; } FbdDevLedMulticolor; G_DEFINE_TYPE (FbdDevLedMulticolor, fbd_dev_led_multicolor, FBD_TYPE_DEV_LED) static gboolean fbd_dev_led_probe_multicolor (FbdDevLed *led, GError **error) { g_autoptr (GError) err = NULL; FbdDevLedMulticolor *self = FBD_DEV_LED_MULTICOLOR (led); GUdevDevice *dev = fbd_dev_led_get_device (led); const gchar *name, *path; const gchar * const *index; guint counter = 0; guint max_brightness; name = g_udev_device_get_name (dev); index = g_udev_device_get_sysfs_attr_as_strv (dev, LED_MULTI_INDEX_ATTR); if (index == NULL) { g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, "%s is no multicololor LED", name); return FALSE; } max_brightness = g_udev_device_get_sysfs_attr_as_int (dev, LED_MAX_BRIGHTNESS_ATTR); if (!max_brightness) { g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, "%s has no max_brightness", name); return FALSE; } fbd_dev_led_set_max_brightness (led, max_brightness); fbd_dev_led_set_color (led, FBD_FEEDBACK_LED_COLOR_RGB); for (int i = 0; index[i] != NULL; i++) { g_debug ("Index: %s", index[i]); if (g_strcmp0 (index[i], LED_MULTI_INDEX_RED) == 0) { self->red_index = counter; counter++; } else if (g_strcmp0 (index[i], LED_MULTI_INDEX_GREEN) == 0) { self->green_index = counter; counter++; } else if (g_strcmp0 (index[i], LED_MULTI_INDEX_BLUE) == 0) { self->blue_index = counter; counter++; } else { g_warning ("Unsupport LED color index: %d %s", counter, index[i]); } } path = g_udev_device_get_sysfs_path (dev); g_debug ("LED at '%s' usable as multicolor", path); return TRUE; } static gboolean fbd_dev_led_start_periodic_multicolor (FbdDevLed *led, FbdFeedbackLedColor color, guint max_brightness_percentage, guint freq) { FbdDevLedMulticolor *self = FBD_DEV_LED_MULTICOLOR (led); GUdevDevice *dev = fbd_dev_led_get_device (led); g_autofree char *intensity = NULL; g_autoptr (GError) err = NULL; g_autofree gchar *str = NULL; gboolean success = FALSE; guint max_brightness; guint colors[] = { 0, 0, 0 }; max_brightness = fbd_dev_led_get_max_brightness (led); switch (color) { case FBD_FEEDBACK_LED_COLOR_WHITE: colors[self->red_index] = max_brightness; colors[self->green_index] = max_brightness; colors[self->blue_index] = max_brightness; break; case FBD_FEEDBACK_LED_COLOR_RED: colors[self->red_index] = max_brightness; colors[self->green_index] = 0; colors[self->blue_index] = 0; break; case FBD_FEEDBACK_LED_COLOR_GREEN: colors[self->red_index] = 0; colors[self->green_index] = max_brightness; colors[self->blue_index] = 0; break; case FBD_FEEDBACK_LED_COLOR_BLUE: colors[self->red_index] = 0; colors[self->green_index] = 0; colors[self->blue_index] = max_brightness; break; default: g_warning("Unhandled color: %d\n", color); return FALSE; } intensity = g_strdup_printf ("%d %d %d\n", colors[0], colors[1], colors[2]); fbd_dev_led_set_brightness (led, max_brightness); success = fbd_udev_set_sysfs_path_attr_as_string (dev, LED_MULTI_INTENSITY_ATTR, intensity, &err); if (!success) { g_warning ("Failed to set multi intensity: %s", err->message); return FALSE; } /* Chain up to parent class to set the pattern */ return FBD_DEV_LED_CLASS (fbd_dev_led_multicolor_parent_class)->start_periodic ( led, color, max_brightness_percentage, freq); } static gboolean fbd_dev_led_has_color_multicolor (FbdDevLed *led, FbdFeedbackLedColor color) { return color == FBD_FEEDBACK_LED_COLOR_RGB; } static void fbd_dev_led_multicolor_class_init (FbdDevLedMulticolorClass *klass) { FbdDevLedClass *fbd_dev_led_class = FBD_DEV_LED_CLASS (klass); fbd_dev_led_class->probe = fbd_dev_led_probe_multicolor; fbd_dev_led_class->start_periodic = fbd_dev_led_start_periodic_multicolor; fbd_dev_led_class->has_color = fbd_dev_led_has_color_multicolor; } static void fbd_dev_led_multicolor_init (FbdDevLedMulticolor *self) { } FbdDevLed * fbd_dev_led_multicolor_new (GUdevDevice *dev, GError **err) { return g_initable_new (FBD_TYPE_DEV_LED_MULTICOLOR, NULL, err, "dev", dev, NULL); } 07070100000048000081A400000000000000000000000164F062AA00000195000000000000000000000000000000000000002D00000000feedbackd-0.2.1/src/fbd-dev-led-multicolor.h/* * Copyright (C) 2023 Purism SPC * * SPDX-License-Identifier: GPL-3.0+ */ #pragma once #include "fbd-dev-led.h" G_BEGIN_DECLS #define FBD_TYPE_DEV_LED_MULTICOLOR fbd_dev_led_multicolor_get_type() G_DECLARE_FINAL_TYPE (FbdDevLedMulticolor, fbd_dev_led_multicolor, FBD, DEV_LED_MULTICOLOR, FbdDevLed) FbdDevLed *fbd_dev_led_multicolor_new (GUdevDevice *dev, GError **err); G_END_DECLS 07070100000049000081A400000000000000000000000164F062AA00000202000000000000000000000000000000000000002700000000feedbackd-0.2.1/src/fbd-dev-led-priv.h/* * Copyright (C) 2023 Purism SPC * * SPDX-License-Identifier: GPL-3.0+ */ #pragma once #include "fbd-dev-led.h" #include "fbd-feedback-led.h" #include <gudev/gudev.h> #include <glib-object.h> G_BEGIN_DECLS #define LED_MAX_BRIGHTNESS_ATTR "max_brightness" GUdevDevice *fbd_dev_led_get_device (FbdDevLed *led); void fbd_dev_led_set_max_brightness (FbdDevLed *led, guint max_brightness); void fbd_dev_led_set_color (FbdDevLed *led, FbdFeedbackLedColor color); G_END_DECLS 0707010000004A000081A400000000000000000000000164F062AA000021BE000000000000000000000000000000000000002200000000feedbackd-0.2.1/src/fbd-dev-led.c/* * Copyright (C) 2020 Purism SPC * SPDX-License-Identifier: GPL-3.0+ * Author: Guido Günther <agx@sigxcpu.org> * * See Documentation/ABI/testing/sysfs-class-led-trigger-pattern */ #define G_LOG_DOMAIN "fbd-dev-led" #include "fbd-dev-led.h" #include "fbd-dev-led-priv.h" #include "fbd-enums.h" #include "fbd-udev.h" #include <gio/gio.h> #define LED_BRIGHTNESS_ATTR "brightness" #define LED_MULTI_INDEX_ATTR "multi_index" #define LED_MULTI_INDEX_RED "red" #define LED_MULTI_INDEX_GREEN "green" #define LED_MULTI_INDEX_BLUE "blue" #define LED_MULTI_INTENSITY_ATTR "multi_intensity" #define LED_PATTERN_ATTR "pattern" enum { PROP_0, PROP_DEV, PROP_LAST_PROP }; static GParamSpec *props[PROP_LAST_PROP]; typedef struct _FbdDevLedPrivate { GUdevDevice *dev; guint max_brightness; /* * We just use the colors from the feedback until we * do rgb mixing, etc */ FbdFeedbackLedColor color; } FbdDevLedPrivate; static void initable_iface_init (GInitableIface *iface); G_DEFINE_TYPE_WITH_CODE (FbdDevLed, fbd_dev_led, G_TYPE_OBJECT, G_ADD_PRIVATE (FbdDevLed) G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, initable_iface_init)) static gboolean fbd_dev_led_probe_default (FbdDevLed *led, GError **error) { FbdDevLedPrivate *priv = fbd_dev_led_get_instance_private (led); const gchar *name, *path; gboolean success; name = g_udev_device_get_name (priv->dev); /* We don't know anything about diffusors that can combine different color LEDSs so go with fixed colors until the kernel gives us enough information */ for (int i = 0; i < FBD_FEEDBACK_LED_COLOR_RGB; i++) { g_autofree char *color = NULL; g_autofree char *enum_name = NULL; gchar *c; enum_name = g_enum_to_string (FBD_TYPE_FEEDBACK_LED_COLOR, i); c = strrchr (enum_name, '_'); color = g_ascii_strdown (c+1, -1); if (g_strstr_len (name, -1, color)) { g_autoptr (GError) err = NULL; guint brightness = g_udev_device_get_sysfs_attr_as_int (priv->dev, LED_MAX_BRIGHTNESS_ATTR); if (!brightness) continue; priv->color = i; fbd_dev_led_set_max_brightness (led, brightness); path = g_udev_device_get_sysfs_path (priv->dev); g_debug ("LED at '%s' usable for %s", path, color); success = TRUE; break; } } if (!success) { g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, "%s not usable as RBG LED", name); } return success; } static gboolean fbd_dev_led_start_periodic_default (FbdDevLed *led, FbdFeedbackLedColor color, guint max_brightness_percentage, guint freq) { FbdDevLedPrivate *priv; g_autoptr (GError) err = NULL; g_autofree gchar *str = NULL; gboolean success = FALSE; gdouble max; gdouble t; g_return_val_if_fail (FBD_IS_DEV_LED (led), FALSE); priv = fbd_dev_led_get_instance_private (led); max = priv->max_brightness * (max_brightness_percentage / 100.0); /* ms mHz T/2 */ t = 1000.0 * 1000.0 / freq / 2.0; str = g_strdup_printf ("0 %d %d %d\n", (gint)t, (gint)max, (gint)t); g_debug ("Freq %d mHz, Brightness: %d%%, Blink pattern: %s", freq, max_brightness_percentage, str); success = fbd_udev_set_sysfs_path_attr_as_string (priv->dev, LED_PATTERN_ATTR, str, &err); if (!success) g_warning ("Failed to set led pattern: %s", err->message); return success; } static gboolean fbd_dev_led_has_color_default (FbdDevLed *led, FbdFeedbackLedColor color) { FbdDevLedPrivate *priv; g_return_val_if_fail (FBD_IS_DEV_LED (led), FALSE); priv = fbd_dev_led_get_instance_private (led); return priv->color == color; } static void fbd_dev_led_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) { FbdDevLed *led = FBD_DEV_LED (object); FbdDevLedPrivate *priv = fbd_dev_led_get_instance_private (led); switch (property_id) { case PROP_DEV: priv->dev = g_value_dup_object (value); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; } } static void fbd_dev_led_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec) { FbdDevLed *led = FBD_DEV_LED (object); FbdDevLedPrivate *priv = fbd_dev_led_get_instance_private (led); switch (property_id) { case PROP_DEV: g_value_set_object (value, priv->dev); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; } } static void fbd_dev_led_finalize (GObject *object) { FbdDevLed *self = FBD_DEV_LED (object); FbdDevLedPrivate *priv = fbd_dev_led_get_instance_private (self); g_clear_object (&priv->dev); G_OBJECT_CLASS (fbd_dev_led_parent_class)->finalize (object); } static gboolean initable_init (GInitable *initable, GCancellable *cancellable, GError **error) { FbdDevLedClass *fbd_dev_led_class = FBD_DEV_LED_GET_CLASS (initable); return fbd_dev_led_class->probe (FBD_DEV_LED (initable), error); } static void initable_iface_init (GInitableIface *iface) { iface->init = initable_init; } static void fbd_dev_led_class_init (FbdDevLedClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); FbdDevLedClass *fbd_dev_led_class = FBD_DEV_LED_CLASS (klass); object_class->get_property = fbd_dev_led_get_property; object_class->set_property = fbd_dev_led_set_property; object_class->finalize = fbd_dev_led_finalize; fbd_dev_led_class->probe = fbd_dev_led_probe_default; fbd_dev_led_class->start_periodic = fbd_dev_led_start_periodic_default; fbd_dev_led_class->has_color = fbd_dev_led_has_color_default; props[PROP_DEV] = g_param_spec_object ("dev", "", "", G_UDEV_TYPE_DEVICE, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); g_object_class_install_properties (object_class, PROP_LAST_PROP, props); } static void fbd_dev_led_init (FbdDevLed *self) { } FbdDevLed * fbd_dev_led_new (GUdevDevice *dev, GError **err) { return g_initable_new (FBD_TYPE_DEV_LED, NULL, err, "dev", dev, NULL); } gboolean fbd_dev_led_set_brightness (FbdDevLed *led, guint brightness) { FbdDevLedPrivate *priv; g_autoptr (GError) err = NULL; g_return_val_if_fail (FBD_IS_DEV_LED (led), FALSE); priv = fbd_dev_led_get_instance_private (led); if (!fbd_udev_set_sysfs_path_attr_as_int (priv->dev, LED_BRIGHTNESS_ATTR, brightness, &err)) { g_warning ("Failed to setup brightness: %s", err->message); return FALSE; } return TRUE; } gboolean fbd_dev_led_start_periodic (FbdDevLed *led, FbdFeedbackLedColor color, guint max_brightness_percentage, guint freq) { FbdDevLedClass *fbd_dev_led_class = FBD_DEV_LED_GET_CLASS (led); g_return_val_if_fail (FBD_IS_DEV_LED (led), FALSE); return fbd_dev_led_class->start_periodic (led, color, max_brightness_percentage, freq); } gboolean fbd_dev_led_has_color (FbdDevLed *led, FbdFeedbackLedColor color) { FbdDevLedClass *fbd_dev_led_class = FBD_DEV_LED_GET_CLASS (led); g_return_val_if_fail (FBD_IS_DEV_LED (led), FALSE); return fbd_dev_led_class->has_color (led, color); } guint fbd_dev_led_get_max_brightness (FbdDevLed *led) { FbdDevLedPrivate *priv; g_return_val_if_fail (FBD_IS_DEV_LED (led), 0); priv = fbd_dev_led_get_instance_private (led); return priv->max_brightness; } /* Functions for derived classes */ GUdevDevice * fbd_dev_led_get_device (FbdDevLed *led) { FbdDevLedPrivate *priv; g_return_val_if_fail (FBD_IS_DEV_LED (led), NULL); priv = fbd_dev_led_get_instance_private (led); return priv->dev; } void fbd_dev_led_set_color (FbdDevLed *led, FbdFeedbackLedColor color) { FbdDevLedPrivate *priv; g_return_if_fail (FBD_IS_DEV_LED (led)); priv = fbd_dev_led_get_instance_private (led); priv->color = color; } void fbd_dev_led_set_max_brightness (FbdDevLed *led, guint max_brightness) { FbdDevLedPrivate *priv; g_return_if_fail (FBD_IS_DEV_LED (led)); priv = fbd_dev_led_get_instance_private (led); priv->max_brightness = max_brightness; } 0707010000004B000081A400000000000000000000000164F062AA000005B1000000000000000000000000000000000000002200000000feedbackd-0.2.1/src/fbd-dev-led.h/* * Copyright (C) 2023 Purism SPC * * SPDX-License-Identifier: GPL-3.0+ */ #pragma once #include "fbd-feedback-led.h" #include <gudev/gudev.h> #include <glib-object.h> G_BEGIN_DECLS #define FBD_TYPE_DEV_LED fbd_dev_led_get_type() G_DECLARE_DERIVABLE_TYPE (FbdDevLed, fbd_dev_led, FBD, DEV_LED, GObject) FbdDevLed *fbd_dev_led_new (GUdevDevice *dev, GError **err); gboolean fbd_dev_led_set_brightness (FbdDevLed *led, guint brightness); guint fbd_dev_led_get_max_brightness (FbdDevLed *led); gboolean fbd_dev_led_start_periodic (FbdDevLed *led, FbdFeedbackLedColor color, guint max_brightness_percentage, guint freq); gboolean fbd_dev_led_has_color (FbdDevLed *led, FbdFeedbackLedColor color); struct _FbdDevLedClass { GObjectClass parent_class; gboolean (*probe) (FbdDevLed *led, GError **error); gboolean (*start_periodic) (FbdDevLed *led, FbdFeedbackLedColor color, guint max_brightness_percentage, guint freq); gboolean (*has_color) (FbdDevLed *led, FbdFeedbackLedColor color); }; G_END_DECLS 0707010000004C000081A400000000000000000000000164F062AA000011E2000000000000000000000000000000000000002300000000feedbackd-0.2.1/src/fbd-dev-leds.c/* * Copyright (C) 2020 Purism SPC * SPDX-License-Identifier: GPL-3.0+ * Author: Guido Günther <agx@sigxcpu.org> * * See Documentation/ABI/testing/sysfs-class-led-trigger-pattern */ #define G_LOG_DOMAIN "fbd-dev-leds" #include "fbd.h" #include "fbd-enums.h" #include "fbd-dev-led.h" #include "fbd-dev-led-multicolor.h" #include "fbd-dev-leds.h" #include "fbd-feedback-led.h" #include "fbd-udev.h" #include <gio/gio.h> #define LED_SUBSYSTEM "leds" /** * FbdDevLeds: * * LED device interface * * #FbdDevLeds is used to interface with LEDS via sysfs * It currently only supports one pattern per led at a time. */ typedef struct _FbdDevLeds { GObject parent; GUdevClient *client; GSList *leds; } FbdDevLeds; static void initable_iface_init (GInitableIface *iface); G_DEFINE_TYPE_WITH_CODE (FbdDevLeds, fbd_dev_leds, G_TYPE_OBJECT, G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, initable_iface_init)); static FbdDevLed * find_led_by_color (FbdDevLeds *self, FbdFeedbackLedColor color) { g_return_val_if_fail (self->leds, NULL); for (GSList *l = self->leds; l != NULL; l = l->next) { FbdDevLed *led = l->data; if (fbd_dev_led_has_color (led, color)) return led; } /* If we did not match a color pick the first */ return self->leds->data; } static gboolean initable_init (GInitable *initable, GCancellable *cancellable, GError **error) { const gchar * const subsystems[] = { LED_SUBSYSTEM, NULL }; FbdDevLeds *self = FBD_DEV_LEDS (initable); g_autolist (GUdevDevice) leds = NULL; gboolean found = FALSE; self->client = g_udev_client_new (subsystems); leds = g_udev_client_query_by_subsystem (self->client, LED_SUBSYSTEM); for (GList *l = leds; l != NULL; l = l->next) { g_autoptr (GError) err = NULL; GUdevDevice *dev = G_UDEV_DEVICE (l->data); FbdDevLed *led; if (g_strcmp0 (g_udev_device_get_property (dev, FEEDBACKD_UDEV_ATTR), FEEDBACKD_UDEV_VAL_LED)) { continue; } /* Try multicolor first, fall back to single color */ led = fbd_dev_led_multicolor_new (dev, &err); if (led == NULL) { g_debug ("Led not usable as multicolor: '%s'", err->message); led = fbd_dev_led_new (dev, &err); if (led == NULL) g_debug ("Led not usable as single color: '%s'", err->message); } if (led) { self->leds = g_slist_append (self->leds, led); found = TRUE; } } /* TODO: listen for new leds via udev events */ if (!found) { g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, "No usable LEDs found"); } return found; } static void initable_iface_init (GInitableIface *iface) { iface->init = initable_init; } static void fbd_dev_leds_dispose (GObject *object) { FbdDevLeds *self = FBD_DEV_LEDS (object); g_clear_object (&self->client); g_slist_free_full (self->leds, (GDestroyNotify)g_object_unref); self->leds = NULL; G_OBJECT_CLASS (fbd_dev_leds_parent_class)->dispose (object); } static void fbd_dev_leds_class_init (FbdDevLedsClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->dispose = fbd_dev_leds_dispose; } static void fbd_dev_leds_init (FbdDevLeds *self) { } FbdDevLeds * fbd_dev_leds_new (GError **error) { return FBD_DEV_LEDS (g_initable_new (FBD_TYPE_DEV_LEDS, NULL, error, NULL)); } /** * fbd_dev_leds_start_periodic: * @self: The #FbdDevLeds * @color: The color to use for the LED pattern * @max_brightness_percentage: The max brightness (in percent) to use for the pattern * @freq: The pattern's frequency in mHz * * Start periodic feedback. */ gboolean fbd_dev_leds_start_periodic (FbdDevLeds *self, FbdFeedbackLedColor color, guint max_brightness_percentage, guint freq) { FbdDevLed *led; g_return_val_if_fail (FBD_IS_DEV_LEDS (self), FALSE); g_return_val_if_fail (max_brightness_percentage <= 100.0, FALSE); led = find_led_by_color (self, color); g_return_val_if_fail (led, FALSE); return fbd_dev_led_start_periodic (led, color, max_brightness_percentage, freq); } gboolean fbd_dev_leds_stop (FbdDevLeds *self, FbdFeedbackLedColor color) { FbdDevLed *led; g_return_val_if_fail (FBD_IS_DEV_LEDS (self), FALSE); led = find_led_by_color (self, color); g_return_val_if_fail (led, FALSE); return fbd_dev_led_set_brightness (led, 0); } 0707010000004D000081A400000000000000000000000164F062AA000002B6000000000000000000000000000000000000002300000000feedbackd-0.2.1/src/fbd-dev-leds.h/* * Copyright (C) 2020 Purism SPC * * SPDX-License-Identifier: GPL-3.0+ */ #pragma once #include "fbd-feedback-led.h" #include "fbd-udev.h" #include <glib-object.h> G_BEGIN_DECLS #define FBD_TYPE_DEV_LEDS (fbd_dev_leds_get_type ()) G_DECLARE_FINAL_TYPE (FbdDevLeds, fbd_dev_leds, FBD, DEV_LEDS, GObject); FbdDevLeds *fbd_dev_leds_new (GError **error); gboolean fbd_dev_leds_start_periodic (FbdDevLeds *self, FbdFeedbackLedColor color, guint max_brighness, guint freq); gboolean fbd_dev_leds_stop (FbdDevLeds *self, FbdFeedbackLedColor color); G_END_DECLS 0707010000004E000081A400000000000000000000000164F062AA0000199E000000000000000000000000000000000000002400000000feedbackd-0.2.1/src/fbd-dev-sound.c/* * Copyright (C) 2020 Purism SPC * SPDX-License-Identifier: GPL-3.0+ * Author: Guido Günther <agx@sigxcpu.org> * * See https://www.kernel.org/doc/html/latest/input/ff.html * and fftest.c from the joystick package. */ #define G_LOG_DOMAIN "fbd-dev-sound" #include "fbd-dev-sound.h" #include "fbd-feedback-sound.h" #include <gsound.h> #define GNOME_SOUND_SCHEMA_ID "org.gnome.desktop.sound" #define GNOME_SOUND_KEY_THEME_NAME "theme-name" /** * SECTION:fbd-dev-sound * @short_description: Sound interface * @Title: FbdDevSound * * The #FbdDevSound is used to play sounds via the systems audio * system. */ typedef struct _FbdAsyncData { FbdDevSoundPlayedCallback callback; FbdFeedbackSound *feedback; FbdDevSound *dev; GCancellable *cancel; } FbdAsyncData; typedef struct _FbdDevSound { GObject parent; GSoundContext *ctx; GSettings *sound_settings; GHashTable *playbacks; } FbdDevSound; static void initable_iface_init (GInitableIface *iface); G_DEFINE_TYPE_WITH_CODE (FbdDevSound, fbd_dev_sound, G_TYPE_OBJECT, G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, initable_iface_init)); static void on_sound_theme_name_changed (FbdDevSound *self, const gchar *key, GSettings *settings) { gboolean ok; g_autoptr(GError) error = NULL; g_autofree gchar *name = NULL; g_return_if_fail (FBD_IS_DEV_SOUND (self)); g_return_if_fail (G_IS_SETTINGS (settings)); g_return_if_fail (!g_strcmp0 (key, GNOME_SOUND_KEY_THEME_NAME)); g_return_if_fail (self->ctx); name = g_settings_get_string (settings, key); g_debug ("Setting sound theme to %s", name); ok = gsound_context_set_attributes (self->ctx, &error, GSOUND_ATTR_CANBERRA_XDG_THEME_NAME, name, NULL); if (!ok) g_warning ("Failed to set sound theme name to %s: %s", key, error->message); } static FbdAsyncData* fbd_async_data_new (FbdDevSound *dev, FbdFeedbackSound *feedback, FbdDevSoundPlayedCallback callback) { FbdAsyncData* data; data = g_new0 (FbdAsyncData, 1); data->callback = callback; data->feedback = g_object_ref (feedback); data->dev = g_object_ref (dev); data->cancel = g_cancellable_new (); return data; } static void fbd_async_data_dispose (FbdAsyncData *data) { g_object_unref (data->feedback); g_object_unref (data->dev); g_object_unref (data->cancel); g_free (data); } static void fbd_dev_sound_dispose (GObject *object) { FbdDevSound *self = FBD_DEV_SOUND (object); g_clear_object (&self->ctx); g_clear_object (&self->sound_settings); g_clear_pointer (&self->playbacks, g_hash_table_unref); G_OBJECT_CLASS (fbd_dev_sound_parent_class)->dispose (object); } static gboolean initable_init (GInitable *initable, GCancellable *cancellable, GError **error) { FbdDevSound *self = FBD_DEV_SOUND (initable); const char *desktop; gboolean gnome_session = FALSE; self->playbacks = g_hash_table_new (g_direct_hash, g_direct_equal); self->ctx = gsound_context_new (NULL, error); if (!self->ctx) return FALSE; desktop = g_getenv ("XDG_CURRENT_DESKTOP"); if (desktop) { g_auto (GStrv) components = g_strsplit (desktop, ":", -1); gnome_session = g_strv_contains ((const char * const *)components, "GNOME"); } if (gnome_session) { self->sound_settings = g_settings_new (GNOME_SOUND_SCHEMA_ID); g_signal_connect_object (self->sound_settings, "changed::" GNOME_SOUND_KEY_THEME_NAME, G_CALLBACK (on_sound_theme_name_changed), self, G_CONNECT_SWAPPED); on_sound_theme_name_changed (self, GNOME_SOUND_KEY_THEME_NAME, self->sound_settings); } return TRUE; } static void initable_iface_init (GInitableIface *iface) { iface->init = initable_init; } static void fbd_dev_sound_class_init (FbdDevSoundClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->dispose = fbd_dev_sound_dispose; } static void fbd_dev_sound_init (FbdDevSound *self) { } FbdDevSound * fbd_dev_sound_new (GError **error) { return FBD_DEV_SOUND (g_initable_new (FBD_TYPE_DEV_SOUND, NULL, error, NULL)); } static void on_sound_play_finished_callback (GSoundContext *ctx, GAsyncResult *res, FbdAsyncData *data) { g_autoptr (GError) err = NULL; if (!gsound_context_play_full_finish (ctx, res, &err)) { if (err->domain == GSOUND_ERROR && err->code == GSOUND_ERROR_NOTFOUND) { g_debug ("Failed to find sound '%s'", fbd_feedback_sound_get_effect (data->feedback)); } else if (g_error_matches (err, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { g_debug ("Sound '%s' cancelled", fbd_feedback_sound_get_effect (data->feedback)); } else { g_warning ("Failed to play sound '%s': %s", fbd_feedback_sound_get_effect (data->feedback), err->message); } } /* Order matters here. We need to remove the feedback from the hash table before invoking the callback. */ g_hash_table_remove (data->dev->playbacks, data->feedback); (*data->callback)(data->feedback); fbd_async_data_dispose (data); } gboolean fbd_dev_sound_play (FbdDevSound *self, FbdFeedbackSound *feedback, FbdDevSoundPlayedCallback callback) { FbdAsyncData *data; g_return_val_if_fail (FBD_IS_DEV_SOUND (self), FALSE); g_return_val_if_fail (GSOUND_IS_CONTEXT (self->ctx), FALSE); data = fbd_async_data_new (self, feedback, callback); if (!g_hash_table_insert (self->playbacks, feedback, data)) g_warning ("Feedback %p already present", feedback); gsound_context_play_full (self->ctx, data->cancel, (GAsyncReadyCallback) on_sound_play_finished_callback, data, GSOUND_ATTR_EVENT_ID, fbd_feedback_sound_get_effect (feedback), GSOUND_ATTR_EVENT_DESCRIPTION, "Feedbackd sound feedback", GSOUND_ATTR_MEDIA_ROLE, "event", NULL); return TRUE; } gboolean fbd_dev_sound_stop (FbdDevSound *self, FbdFeedbackSound *feedback) { FbdAsyncData *data; g_return_val_if_fail (FBD_IS_DEV_SOUND (self), FALSE); data = g_hash_table_lookup (self->playbacks, feedback); if (data == NULL) return FALSE; g_cancellable_cancel (data->cancel); return TRUE; } 0707010000004F000081A400000000000000000000000164F062AA000002BA000000000000000000000000000000000000002400000000feedbackd-0.2.1/src/fbd-dev-sound.h/* * Copyright (C) 2020 Purism SPC * * SPDX-License-Identifier: GPL-3.0+ */ #pragma once #include <glib-object.h> #include "fbd-feedback-sound.h" G_BEGIN_DECLS #define FBD_TYPE_DEV_SOUND (fbd_dev_sound_get_type()) G_DECLARE_FINAL_TYPE (FbdDevSound, fbd_dev_sound, FBD, DEV_SOUND, GObject); typedef void (*FbdDevSoundPlayedCallback)(FbdFeedbackSound *feedback); FbdDevSound *fbd_dev_sound_new (GError **error); gboolean fbd_dev_sound_play (FbdDevSound *self, FbdFeedbackSound *feedback, FbdDevSoundPlayedCallback callback); gboolean fbd_dev_sound_stop (FbdDevSound *self, FbdFeedbackSound *feedback); G_END_DECLS 07070100000050000081A400000000000000000000000164F062AA00002543000000000000000000000000000000000000002400000000feedbackd-0.2.1/src/fbd-dev-vibra.c/* * Copyright (C) 2020 Purism SPC * SPDX-License-Identifier: GPL-3.0+ * Author: Guido Günther <agx@sigxcpu.org> * * See https://www.kernel.org/doc/html/latest/input/ff.html * and fftest.c from the joystick package. */ #define G_LOG_DOMAIN "fbd-dev-vibra" #include "fbd-dev-vibra.h" #include <gio/gio.h> #include <errno.h> #include <fcntl.h> #include <linux/input.h> #include <sys/ioctl.h> #include <sys/stat.h> #include <sys/types.h> /** * SECTION:fbd-dev-vibra * @short_description: Haptic motor device interface * @Title: FbdDevVibra * * The #FbdDevVibra is used to interface with haptic motor via the force * feedback interface. It currently only supports one id at a time. */ enum { PROP_0, PROP_DEVICE, PROP_LAST_PROP, }; static GParamSpec *props[PROP_LAST_PROP]; typedef enum { FBD_DEV_VIBRA_FEATURE_RUMBLE, FBD_DEV_VIBRA_FEATURE_PERIODIC, FBD_DEV_VIBRA_FEATURE_GAIN, } FbdDevVibraFeatureFlags; typedef struct _FbdDevVibra { GObject parent; GUdevDevice *device; gint fd; gint id; /* currently used id */ FbdDevVibraFeatureFlags features; } FbdDevVibra; static void initable_iface_init (GInitableIface *iface); G_DEFINE_TYPE_WITH_CODE (FbdDevVibra, fbd_dev_vibra, G_TYPE_OBJECT, G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, initable_iface_init)); static void fbd_dev_vibra_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) { FbdDevVibra *self = FBD_DEV_VIBRA (object); switch (property_id) { case PROP_DEVICE: g_clear_object (&self->device); self->device = g_value_dup_object (value); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; } } static void fbd_dev_vibra_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec) { switch (property_id) { default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; } } #define BITS_PER_LONG (8 * sizeof (long)) #define HAS_FEATURE(fbit, a) \ (a[(fbit/BITS_PER_LONG)] >> ((fbit % BITS_PER_LONG)) & 1) static gboolean initable_init (GInitable *initable, GCancellable *cancellable, GError **error) { FbdDevVibra *self = FBD_DEV_VIBRA (initable); const char *filename = g_udev_device_get_device_file (self->device); gulong features[1 + FF_MAX/BITS_PER_LONG]; struct input_event gain = { 0 }; self->fd = open (filename, O_RDWR | O_NONBLOCK, O_RDWR); if (self->fd < 0) { g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, "Unable to open '%s': %s", filename, g_strerror (errno)); return FALSE; } if (ioctl (self->fd, EVIOCGBIT(EV_FF, sizeof (features)), features) == -1) { g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, "Unable to probe features of '%s': %s", filename, g_strerror (errno)); return FALSE; } if (HAS_FEATURE(FF_RUMBLE, features)) self->features |= FBD_DEV_VIBRA_FEATURE_RUMBLE; else { g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, "No rumble capable vibra device “%s”: %s", filename, g_strerror (errno)); return FALSE; } if (HAS_FEATURE(FF_PERIODIC, features)) self->features |= FBD_DEV_VIBRA_FEATURE_PERIODIC; else { g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, "No rumble capable vibra device “%s”: %s", filename, g_strerror (errno)); return FALSE; } /* Set gain to 75% if supported */ if (HAS_FEATURE(FF_GAIN, features)) { self->features |= FBD_DEV_VIBRA_FEATURE_GAIN; memset(&gain, 0, sizeof(gain)); gain.type = EV_FF; gain.code = FF_GAIN; gain.value = 0xC000; /* [0, 0xFFFF]) */ g_debug("Setting master gain to 75%%"); if (write(self->fd, &gain, sizeof(gain)) != sizeof(gain)) { g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, "Unable to set gain of '%s': %s", filename, g_strerror (errno)); } } else { g_debug ("Gain unsupported"); } g_debug ("Vibra device at '%s' usable", filename); return TRUE; } static void initable_iface_init (GInitableIface *iface) { iface->init = initable_init; } static void fbd_dev_vibra_dispose (GObject *object) { FbdDevVibra *self = FBD_DEV_VIBRA (object); g_clear_object (&self->device); G_OBJECT_CLASS (fbd_dev_vibra_parent_class)->dispose (object); } static void fbd_dev_vibra_finalize (GObject *object) { FbdDevVibra *self = FBD_DEV_VIBRA (object); if (self->fd >= 0) { close (self->fd); self->fd = -1; } G_OBJECT_CLASS (fbd_dev_vibra_parent_class)->finalize (object); } static void fbd_dev_vibra_class_init (FbdDevVibraClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->set_property = fbd_dev_vibra_set_property; object_class->get_property = fbd_dev_vibra_get_property; object_class->dispose = fbd_dev_vibra_dispose; object_class->finalize = fbd_dev_vibra_finalize; props[PROP_DEVICE] = g_param_spec_object ( "device", "Device", "The udev device", G_UDEV_TYPE_DEVICE, G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); g_object_class_install_properties (object_class, PROP_LAST_PROP, props); } static void fbd_dev_vibra_init (FbdDevVibra *self) { } FbdDevVibra * fbd_dev_vibra_new (GUdevDevice *device, GError **error) { return FBD_DEV_VIBRA (g_initable_new (FBD_TYPE_DEV_VIBRA, NULL, error, "device", device, NULL)); } gboolean fbd_dev_vibra_rumble (FbdDevVibra *self, guint duration, gboolean upload) { struct input_event event = { 0 }; struct ff_effect effect = { 0 }; g_return_val_if_fail (FBD_IS_DEV_VIBRA (self), FALSE); memset(&effect, 0, sizeof(effect)); effect.type = FF_RUMBLE; effect.id = -1; effect.u.rumble.strong_magnitude = 0x8000; effect.u.rumble.weak_magnitude = 0; effect.replay.length = duration; effect.replay.delay = 0; if (upload) { g_debug("Uploading rumbling vibra effect (%d)", self->fd); if (ioctl(self->fd, EVIOCSFF, &effect) == -1) { g_warning ("Failed to upload rumbling vibra effect: %s", g_strerror (errno)); return FALSE; } self->id = effect.id; } g_debug("Playing rumbling vibra effect id %d", effect.id); event.type = EV_FF; event.value = 1; event.code = self->id; if (write (self->fd, (const void*) &event, sizeof (event)) < 0) { g_warning ("Failed to play rumbling vibra effect."); return FALSE; } return TRUE; } /* TODO: fall back to multiple rumbles when sine not supported */ gboolean fbd_dev_vibra_periodic (FbdDevVibra *self, guint duration, guint magnitude, guint fade_in_level, guint fade_in_time) { struct input_event event; struct ff_effect effect = { 0 }; g_return_val_if_fail (FBD_IS_DEV_VIBRA (self), FALSE); if (!magnitude) magnitude = 0x7FFF; if (!fade_in_level) fade_in_level = magnitude; if (!fade_in_time) fade_in_time = duration; effect.type = FF_PERIODIC; effect.id = -1; effect.u.periodic.waveform = FF_SINE; effect.u.periodic.period = 10; effect.u.periodic.magnitude = magnitude; effect.u.periodic.offset = 0; effect.u.periodic.phase = 0; effect.direction = 0x4000; effect.u.periodic.envelope.attack_length = fade_in_time; effect.u.periodic.envelope.attack_level = fade_in_level;; effect.u.periodic.envelope.fade_length = 0; effect.u.periodic.envelope.fade_level = 0; effect.trigger.button = 0; effect.trigger.interval = 0; effect.replay.length = duration; effect.replay.delay = 200; g_debug("Uploading periodic effect (%d)", self->fd); if (ioctl(self->fd, EVIOCSFF, &effect) == -1) { g_warning ("Failed to upload periodic vibra effect: %s", g_strerror (errno)); return FALSE; } g_debug("Playing periodic vibra effect id %d", effect.id); event.type = EV_FF; self->id = event.code = effect.id; event.value = 1; if (write (self->fd, (const void*) &event, sizeof (event)) < 0) { g_warning ("Failed to play rumbling effect."); return FALSE; } return TRUE; } gboolean fbd_dev_vibra_remove_effect (FbdDevVibra *self) { g_return_val_if_fail (FBD_IS_DEV_VIBRA (self), FALSE); g_debug("Erasing vibra effect (%d)", self->fd); if (ioctl(self->fd, EVIOCRMFF, self->id) == -1) { g_warning ("Failed to erase vibra effect with id %d: %s", self->id, strerror(errno)); return FALSE; } return TRUE; } gboolean fbd_dev_vibra_stop(FbdDevVibra *self) { struct input_event stop = { 0 }; g_return_val_if_fail (FBD_IS_DEV_VIBRA (self), FALSE); stop.type = EV_FF; stop.code = self->id; stop.value = 0; if (write(self->fd, (const void*) &stop, sizeof(stop)) < 0) { g_warning ("Failed to stop vibra effect with id %d: %s", self->id, strerror(errno)); return FALSE; } return fbd_dev_vibra_remove_effect (self); } GUdevDevice * fbd_dev_vibra_get_device(FbdDevVibra *self) { g_return_val_if_fail (FBD_IS_DEV_VIBRA (self), FALSE); return self->device; } 07070100000051000081A400000000000000000000000164F062AA0000030B000000000000000000000000000000000000002400000000feedbackd-0.2.1/src/fbd-dev-vibra.h/* * Copyright (C) 2020 Purism SPC * * SPDX-License-Identifier: GPL-3.0+ */ #pragma once #include <glib-object.h> #include <gudev/gudev.h> G_BEGIN_DECLS #define FBD_TYPE_DEV_VIBRA (fbd_dev_vibra_get_type()) G_DECLARE_FINAL_TYPE (FbdDevVibra, fbd_dev_vibra, FBD, DEV_VIBRA, GObject); FbdDevVibra *fbd_dev_vibra_new (GUdevDevice *device, GError **error); gboolean fbd_dev_vibra_rumble (FbdDevVibra *device, guint duration, gboolean upload); gboolean fbd_dev_vibra_periodic (FbdDevVibra *self, guint duration, guint magnitude, guint fade_in_level, guint fade_in_time); gboolean fbd_dev_vibra_stop (FbdDevVibra *self); gboolean fbd_dev_vibra_remove_effect (FbdDevVibra *self); GUdevDevice *fbd_dev_vibra_get_device(FbdDevVibra *self); G_END_DECLS 07070100000052000081A400000000000000000000000164F062AA00000122000000000000000000000000000000000000002000000000feedbackd-0.2.1/src/fbd-error.c/* * Copyright (C) 2022 Guido Günther * * SPDX-License-Identifier: GPL-3.0+ * * Author: Guido Günther <agx@sigxcpu.org> */ #include "fbd.h" GQuark fbd_error_quark (void) { static GQuark quark = 0; if (!quark) quark = g_quark_from_static_string("fbd"); return quark; } 07070100000053000081A400000000000000000000000164F062AA00002D0D000000000000000000000000000000000000002000000000feedbackd-0.2.1/src/fbd-event.c/* * Copyright (C) 2020 Purism SPC * SPDX-License-Identifier: GPL-3.0+ * Author: Guido Günther <agx@sigxcpu.org> */ #define G_LOG_DOMAIN "fbd-event" #include "lfb-names.h" #include "fbd.h" #include "fbd-enums.h" #include "fbd-event.h" enum { SIGNAL_FEEDBACKS_ENDED, N_SIGNALS }; static guint signals[N_SIGNALS]; enum { PROP_0, PROP_ID, PROP_APP_ID, PROP_EVENT, PROP_END_REASON, PROP_FEEDBACKS_ENDED, PROP_TIMEOUT, PROP_SENDER, PROP_LAST_PROP, }; static GParamSpec *props[PROP_LAST_PROP]; typedef struct _FbdEvent { GObject parent; guint id; char *app_id; char *event; char *sender; int timeout; gboolean expired; guint timeout_id; gboolean ended; FbdEventEndReason end_reason; GSList *feedbacks; } FbdEvent; G_DEFINE_TYPE (FbdEvent, fbd_event, G_TYPE_OBJECT); static gboolean on_timeout_expired (FbdEvent *self) { g_return_val_if_fail (FBD_IS_EVENT (self), G_SOURCE_REMOVE); self->expired = TRUE; self->timeout_id = 0; return G_SOURCE_REMOVE; } static gboolean check_ended (FbdEvent *self) { if (!fbd_event_get_feedbacks_ended (self)) return FALSE; self->ended = TRUE; g_object_notify_by_pspec (G_OBJECT (self), props[PROP_FEEDBACKS_ENDED]); g_signal_emit (self, signals[SIGNAL_FEEDBACKS_ENDED], 0); return TRUE; } static void on_fb_ended (FbdEvent *self, FbdFeedbackBase *fb) { switch (self->timeout) { case FBD_EVENT_TIMEOUT_ONESHOT: check_ended (self); break; case FBD_EVENT_TIMEOUT_LOOP: if (self->end_reason != FBD_EVENT_END_REASON_NATURAL) check_ended (self); else fbd_feedback_run (fb); break; default: if (!self->expired && self->end_reason == FBD_EVENT_END_REASON_NATURAL) fbd_feedback_run (fb); else check_ended (self); break; } } static void fbd_event_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) { FbdEvent *self = FBD_EVENT (object); switch (property_id) { case PROP_ID: self->id = g_value_get_int (value); break; case PROP_APP_ID: g_free (self->app_id); self->app_id = g_value_dup_string (value); break; case PROP_EVENT: g_free (self->event); self->event = g_value_dup_string (value); break; case PROP_TIMEOUT: self->timeout = g_value_get_int (value); break; case PROP_END_REASON: fbd_event_set_end_reason (self, g_value_get_enum (value)); break; case PROP_SENDER: g_free (self->sender); self->sender = g_value_dup_string (value); break; case PROP_FEEDBACKS_ENDED: default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; } } static void fbd_event_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec) { FbdEvent *self = FBD_EVENT (object); switch (property_id) { case PROP_ID: g_value_set_int (value, self->id); break; case PROP_APP_ID: g_value_set_string (value, self->app_id); break; case PROP_EVENT: g_value_set_string (value, self->event); break; case PROP_TIMEOUT: g_value_set_int (value, self->timeout); break; case PROP_END_REASON: g_value_set_enum (value, fbd_event_get_end_reason (self)); break; case PROP_FEEDBACKS_ENDED: g_value_set_boolean (value, self->ended); break; case PROP_SENDER: g_value_set_string (value, self->sender); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; } } static void fbd_event_dispose (GObject *object) { FbdEvent *self = FBD_EVENT (object); g_clear_handle_id (&self->timeout_id, g_source_remove); if (self->feedbacks) { /* Feedbacks end themselves when unrefed */ g_slist_free_full (self->feedbacks, g_object_unref); self->feedbacks = NULL; } G_OBJECT_CLASS (fbd_event_parent_class)->dispose (object); } static void fbd_event_finalize (GObject *object) { FbdEvent *self = FBD_EVENT (object); g_clear_pointer (&self->app_id, g_free); g_clear_pointer (&self->event, g_free); g_clear_pointer (&self->sender, g_free); G_OBJECT_CLASS (fbd_event_parent_class)->finalize (object); } static void fbd_event_class_init (FbdEventClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->set_property = fbd_event_set_property; object_class->get_property = fbd_event_get_property; object_class->dispose = fbd_event_dispose; object_class->finalize = fbd_event_finalize; props[PROP_ID] = g_param_spec_int ( "id", "Id", "The event id", 0, G_MAXINT, 0, G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); props[PROP_APP_ID] = g_param_spec_string ( "app-id", "App id", "The application id", NULL, G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); props[PROP_EVENT] = g_param_spec_string ( "event", "Event", "The event name", NULL, G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); props[PROP_TIMEOUT] = g_param_spec_int ( "timeout", "Timeout", "Timeout after which feedback for event should end", -1, G_MAXINT, -1, G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); props[PROP_FEEDBACKS_ENDED] = g_param_spec_boolean ( "feedbacks-ended", "Feedbacks ended", "Whether all feedbacks have ended playing", FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY); props[PROP_END_REASON] = g_param_spec_enum ( "end-reason", "End reason", "The reason why the feedbacks ends/ended", FBD_TYPE_EVENT_END_REASON, FBD_EVENT_END_REASON_NATURAL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY); /** * FbdEvent:Sender: * * The DBus name of the sender */ props[PROP_SENDER] = g_param_spec_string ( "sender", "", "", NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY); g_object_class_install_properties (object_class, PROP_LAST_PROP, props); /** * FbdEvent::feedbacks-ended: * * Emitted when all feedbacks associated with this event ended. */ signals[SIGNAL_FEEDBACKS_ENDED] = g_signal_new ("feedbacks-ended", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 0); } static void fbd_event_init (FbdEvent *self) { self->timeout = -1; } FbdEvent * fbd_event_new (int id, const char *app_id, const char *event, int timeout, const char *sender) { return FBD_EVENT (g_object_new (FBD_TYPE_EVENT, "id", id, "app_id", app_id, "event", event, "timeout", timeout, "sender", sender, NULL)); } const char * fbd_event_get_event (FbdEvent *self) { g_return_val_if_fail (FBD_IS_EVENT (self), NULL); return self->event; } const char * fbd_event_get_app_id (FbdEvent *self) { g_return_val_if_fail (FBD_IS_EVENT (self), NULL); return self->app_id; } guint fbd_event_get_id (FbdEvent *self) { g_return_val_if_fail (FBD_IS_EVENT (self), 0); return self->id; } int fbd_event_get_timeout (FbdEvent *self) { g_return_val_if_fail (FBD_IS_EVENT (self), -1); return self->timeout; } /** * fbd_event_add_feedback: * @self: The event that gets a feedback added * @feedback: (transfer-none): The feedback to add * * Add a feedback to the list of feedbacks triggered by event */ void fbd_event_add_feedback (FbdEvent *self, FbdFeedbackBase *feedback) { self->feedbacks = g_slist_prepend (self->feedbacks, g_object_ref(feedback)); g_object_set_data (G_OBJECT (feedback), "event-id", GUINT_TO_POINTER(self->id)); g_signal_connect_object (feedback, "ended", (GCallback) on_fb_ended, self, G_CONNECT_SWAPPED); } GSList * fbd_event_get_feedbacks (FbdEvent *self) { return self->feedbacks; } int fbd_event_remove_feedback (FbdEvent *self, FbdFeedbackBase *feedback) { g_return_val_if_fail (FBD_IS_EVENT (self), 0); self->feedbacks = g_slist_remove (self->feedbacks, feedback); return g_slist_length (self->feedbacks); } /** * fbd_event_run_feedbacks: * @self: The Event * * Run all feedbacks associated for an event. */ void fbd_event_run_feedbacks (FbdEvent *self) { g_return_if_fail (FBD_IS_EVENT (self)); g_debug ("Running %d feedbacks for event %d", g_slist_length (self->feedbacks), self->id); if (!self->feedbacks) return; if (self->timeout > 0) { self->timeout_id = g_timeout_add_seconds (self->timeout, (GSourceFunc)on_timeout_expired, self); g_source_set_name_by_id (self->timeout_id, "event timeout source"); } g_object_ref (self); for (GSList *l = self->feedbacks; l; l = l->next) { FbdFeedbackBase *fb = FBD_FEEDBACK_BASE (l->data); fbd_feedback_run (fb); } g_object_unref (self); } /** * fbd_event_end_feedbacks: * @self: The Event * * End all running feedbacks as early as possible. */ void fbd_event_end_feedbacks (FbdEvent *self) { g_return_if_fail (FBD_IS_EVENT (self)); fbd_event_set_end_reason (self, FBD_EVENT_END_REASON_EXPLICIT); g_debug ("Ending %d feedbacks for event %d", g_slist_length (self->feedbacks), self->id); g_slist_foreach (self->feedbacks, (GFunc)fbd_feedback_end, NULL); } /** * fbd_event_get_feedbacks_ended: * @self: The Event * * Whether all feedbacks have finished running. * * Returns: %TRUE if all feedbacks have finished, otherwise %FALSE. */ gboolean fbd_event_get_feedbacks_ended (FbdEvent *self) { GSList *l; g_return_val_if_fail (FBD_IS_EVENT (self), FALSE); if (!self->feedbacks) return TRUE; for (l = self->feedbacks; l ; l = l->next) { if (!fbd_feedback_get_ended (FBD_FEEDBACK_BASE (l->data))) return FALSE; } return TRUE; } /** * fbd_event_set_end_reason: * @self: The Event * @reason: The reason why feedback for the event ended * * Sets the reason why feedback for the event ends/has ended. */ void fbd_event_set_end_reason (FbdEvent *self, FbdEventEndReason reason) { g_return_if_fail (FBD_IS_EVENT (self)); if (self->end_reason == reason) return; self->end_reason = reason; g_object_notify_by_pspec (G_OBJECT (self), props[PROP_END_REASON]); } /** * fbd_event_get_end_reason: * @self: The Event * * Returns: The reason why feedback for the event ended. */ FbdEventEndReason fbd_event_get_end_reason (FbdEvent *self) { g_return_val_if_fail (FBD_IS_EVENT (self), FBD_EVENT_END_REASON_NATURAL); return self->end_reason; } /** * fbd_event_get_sender: * @self: The Event * * Returns: The DBus sender that triggered the event. */ const char * fbd_event_get_sender (FbdEvent *self) { g_return_val_if_fail (FBD_IS_EVENT (self), NULL); return self->sender; } 07070100000054000081A400000000000000000000000164F062AA0000074D000000000000000000000000000000000000002000000000feedbackd-0.2.1/src/fbd-event.h/* * Copyright (C) 2020 Purism SPC * * SPDX-License-Identifier: GPL-3.0+ */ #pragma once #include "fbd-feedback-base.h" #include "fbd-feedback-manager.h" #include <glib-object.h> G_BEGIN_DECLS typedef enum _FbdEventEndReason { /* No usable feedback in current theme for this event */ FBD_EVENT_END_REASON_NOT_FOUND = -1, /* all feedbacks finished playing their natural length */ FBD_EVENT_END_REASON_NATURAL = 0, /* The timer expired */ FBD_EVENT_END_REASON_EXPIRED = 1, /* Application wanted to end feedbacks explicitly */ FBD_EVENT_END_REASON_EXPLICIT = 2, } FbdEventEndReason; typedef enum _FbdEventTimeout { /* Run each feedback once */ FBD_EVENT_TIMEOUT_ONESHOT = -1, FBD_EVENT_TIMEOUT_LOOP = 0, } FbdEventTimeout; #define FBD_TYPE_EVENT (fbd_event_get_type()) G_DECLARE_FINAL_TYPE (FbdEvent, fbd_event, FBD, EVENT, GObject); FbdEvent *fbd_event_new (gint id, const char *app_id, const char *event, int timeout, const char *sender); const char *fbd_event_get_event (FbdEvent *event); const char *fbd_event_get_app_id (FbdEvent *event); guint fbd_event_get_id (FbdEvent *event); int fbd_event_get_timeout (FbdEvent *self); void fbd_event_set_end_reason (FbdEvent *self, FbdEventEndReason reason); FbdEventEndReason fbd_event_get_end_reason (FbdEvent *self); GSList * fbd_event_get_feedbacks (FbdEvent *self); void fbd_event_add_feedback (FbdEvent *self, FbdFeedbackBase *feedback); int fbd_event_remove_feedback (FbdEvent *self, FbdFeedbackBase *feedback); void fbd_event_run_feedbacks (FbdEvent *self); void fbd_event_end_feedbacks (FbdEvent *self); gboolean fbd_event_get_feedbacks_ended (FbdEvent *self); const char *fbd_event_get_sender (FbdEvent *self); G_END_DECLS 07070100000055000081A400000000000000000000000164F062AA00001788000000000000000000000000000000000000002800000000feedbackd-0.2.1/src/fbd-feedback-base.c/* * Copyright (C) 2020 Purism SPC * SPDX-License-Identifier: GPL-3.0+ * Author: Guido Günther <agx@sigxcpu.org> */ #define G_LOG_DOMAIN "fbd-feedback-base" #include "fbd-feedback-base.h" /** * SECTION:fbd-feedback-base * @short_description: Base class for different feedback types * @Title: FbdFeedbackManager * * You usually don't want to create objects of this type. It just * serves as a base class for other feedback types. */ enum { PROP_0, PROP_EVENT_NAME, PROP_LAST_PROP, }; static GParamSpec *props[PROP_LAST_PROP]; enum { SIGNAL_ENDED, N_SIGNALS }; static guint signals[N_SIGNALS]; typedef struct _FbdFeedbackBasePrivate { gchar *event_name; gboolean ended; } FbdFeedbackBasePrivate; G_DEFINE_TYPE_WITH_PRIVATE (FbdFeedbackBase, fbd_feedback_base, G_TYPE_OBJECT); static void fbd_feedback_base_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) { FbdFeedbackBase *self = FBD_FEEDBACK_BASE (object); FbdFeedbackBasePrivate *priv = fbd_feedback_base_get_instance_private (self); switch (property_id) { case PROP_EVENT_NAME: g_free (priv->event_name); priv->event_name = g_value_dup_string (value); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; } } static void fbd_feedback_base_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec) { FbdFeedbackBase *self = FBD_FEEDBACK_BASE (object); FbdFeedbackBasePrivate *priv = fbd_feedback_base_get_instance_private (self); switch (property_id) { case PROP_EVENT_NAME: g_value_set_string (value, priv->event_name); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; } } static void fbd_feedback_base_dispose (GObject *object) { FbdFeedbackBase *self = FBD_FEEDBACK_BASE (object); /* end feedback if running */ if (!fbd_feedback_get_ended (self)) fbd_feedback_end (self); G_OBJECT_CLASS (fbd_feedback_base_parent_class)->dispose (object); } static void fbd_feedback_base_finalize (GObject *object) { FbdFeedbackBase *self = FBD_FEEDBACK_BASE (object); FbdFeedbackBasePrivate *priv = fbd_feedback_base_get_instance_private (self); g_clear_pointer (&priv->event_name, g_free); G_OBJECT_CLASS (fbd_feedback_base_parent_class)->finalize (object); } static void fbd_feedback_base_class_init (FbdFeedbackBaseClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->set_property = fbd_feedback_base_set_property; object_class->get_property = fbd_feedback_base_get_property; object_class->dispose = fbd_feedback_base_dispose; object_class->finalize = fbd_feedback_base_finalize; props[PROP_EVENT_NAME] = g_param_spec_string ( "event-name", "Event Name", "The event this feedback is associated with", NULL, G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); g_object_class_install_properties (object_class, PROP_LAST_PROP, props); /** * FbdFeedbackBase::ended: * * Emitted when the feedback has ended */ signals[SIGNAL_ENDED] = g_signal_new ("ended", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 0); } static void fbd_feedback_base_init (FbdFeedbackBase *self) { } /** * fbd_feedback_get_event_name: * @self: The feedback * * Returns: the name from the event naming spec this feedback is associated with. */ const gchar * fbd_feedback_get_event_name (FbdFeedbackBase *self) { FbdFeedbackBasePrivate *priv; g_return_val_if_fail (FBD_IS_FEEDBACK_BASE (self), NULL); priv = fbd_feedback_base_get_instance_private (self); return priv->event_name; } /** * fbd_feedback_run: * @self: The feedback to run * * Emit the feedback. */ void fbd_feedback_run (FbdFeedbackBase *self) { FbdFeedbackBaseClass *klass; FbdFeedbackBasePrivate *priv; g_return_if_fail (FBD_IS_FEEDBACK_BASE (self)); priv = fbd_feedback_base_get_instance_private (self); priv->ended = FALSE; klass = FBD_FEEDBACK_BASE_GET_CLASS (self); g_return_if_fail (klass->run); klass->run (self); } /** * fbd_feedback_end: * @self: The feedback to end * * End the feedback immediately. */ void fbd_feedback_end (FbdFeedbackBase *self) { FbdFeedbackBaseClass *klass; g_return_if_fail (FBD_IS_FEEDBACK_BASE (self)); klass = FBD_FEEDBACK_BASE_GET_CLASS (self); g_return_if_fail (klass->end); klass->end (self); } /** * fbd_feedback_get_ended: * @self: The feedback * * Whether the feedback is ended. * * Returns: %TRUE if feedback has ended, otherwise %FALSE. */ gboolean fbd_feedback_get_ended (FbdFeedbackBase *self) { FbdFeedbackBasePrivate *priv = fbd_feedback_base_get_instance_private (self); return priv->ended; } /** * fbd_feedback_base_done: * @self: The feedback * * Invoked by a derived classes to notify that it's done emitting feedback, * e.g. when the vibra motor stopped or a sound finished playing. */ void fbd_feedback_base_done (FbdFeedbackBase *self) { FbdFeedbackBasePrivate *priv = fbd_feedback_base_get_instance_private (self); priv->ended = TRUE; g_signal_emit (self, signals[SIGNAL_ENDED], 0); } /** * fbd_feedback_available: * @self: The feedback * * Whether this feedback type is available at all. This can be %FALSE e.g. * due to missing hardware. * * Returns: %FALSE if the feedback type is not available at all %TRUE if unsure * or available. */ gboolean fbd_feedback_is_available (FbdFeedbackBase *self) { FbdFeedbackBaseClass *klass; g_return_val_if_fail (FBD_IS_FEEDBACK_BASE (self), FALSE); klass = FBD_FEEDBACK_BASE_GET_CLASS (self); if (klass->is_available) return klass->is_available (self); else return TRUE; } 07070100000056000081A400000000000000000000000164F062AA00000366000000000000000000000000000000000000002800000000feedbackd-0.2.1/src/fbd-feedback-base.h/* * Copyright (C) 2020 Purism SPC * * SPDX-License-Identifier: GPL-3.0+ */ #pragma once #include <glib-object.h> G_BEGIN_DECLS #define FBD_TYPE_FEEDBACK_BASE (fbd_feedback_base_get_type()) G_DECLARE_DERIVABLE_TYPE (FbdFeedbackBase, fbd_feedback_base, FBD, FEEDBACK_BASE, GObject); struct _FbdFeedbackBaseClass { GObjectClass parent_class; void (*run) (FbdFeedbackBase *self); void (*end) (FbdFeedbackBase *self); gboolean (*is_available) (FbdFeedbackBase *self); }; const gchar *fbd_feedback_get_event_name (FbdFeedbackBase *self); void fbd_feedback_run (FbdFeedbackBase *self); void fbd_feedback_end (FbdFeedbackBase *self); gboolean fbd_feedback_get_ended (FbdFeedbackBase *self); void fbd_feedback_base_done (FbdFeedbackBase *self); gboolean fbd_feedback_is_available (FbdFeedbackBase *self); G_END_DECLS 07070100000057000081A400000000000000000000000164F062AA00000CB4000000000000000000000000000000000000002900000000feedbackd-0.2.1/src/fbd-feedback-dummy.c/* * Copyright (C) 2020 Purism SPC * SPDX-License-Identifier: GPL-3.0+ * Author: Guido Günther <agx@sigxcpu.org> */ #define G_LOG_DOMAIN "fbd-feedback-dummy" #include "fbd-enums.h" #include "fbd-feedback-dummy.h" #include "fbd-feedback-manager.h" /** * SECTION:fbd-feedback-dummy * @short_description: Describes a dummy feedback event that does nothing * @Title: FbdFeedbackDummy */ enum { PROP_0, PROP_DURATION, PROP_LAST_PROP, }; static GParamSpec *props[PROP_LAST_PROP]; typedef struct _FbdFeedbackDummy { FbdFeedbackBase parent; guint duration; guint timer_id; } FbdFeedbackDummy; G_DEFINE_TYPE (FbdFeedbackDummy, fbd_feedback_dummy, FBD_TYPE_FEEDBACK_BASE); static void fbd_feedback_dummy_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) { FbdFeedbackDummy *self = FBD_FEEDBACK_DUMMY (object); switch (property_id) { case PROP_DURATION: self->duration = g_value_get_uint (value); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; } } static void fbd_feedback_dummy_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec) { FbdFeedbackDummy *self = FBD_FEEDBACK_DUMMY (object); switch (property_id) { case PROP_DURATION: g_value_set_uint (value, self->duration); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; } } static gboolean on_timeout_expired (FbdFeedbackDummy *self) { fbd_feedback_base_done (FBD_FEEDBACK_BASE(self)); return G_SOURCE_REMOVE; } static void fbd_feedback_dummy_run (FbdFeedbackBase *base) { FbdFeedbackDummy *self = FBD_FEEDBACK_DUMMY (base); if (self->duration) { self->timer_id = g_timeout_add (self->duration, (GSourceFunc)on_timeout_expired, self); g_source_set_name_by_id (self->timer_id, "feedback-dummy-timer"); } else { fbd_feedback_base_done (base); } } static void fbd_feedback_dummy_end (FbdFeedbackBase *base) { FbdFeedbackDummy *self = FBD_FEEDBACK_DUMMY (base); g_clear_handle_id(&self->timer_id, g_source_remove); fbd_feedback_base_done (base); } static void fbd_feedback_dummy_class_init (FbdFeedbackDummyClass *klass) { FbdFeedbackBaseClass *base_class = FBD_FEEDBACK_BASE_CLASS (klass); GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->set_property = fbd_feedback_dummy_set_property; object_class->get_property = fbd_feedback_dummy_get_property; base_class->run = fbd_feedback_dummy_run; base_class->end = fbd_feedback_dummy_end; props[PROP_DURATION] = g_param_spec_uint ( "duration", "Duration", "Dummy event duration in msecs", 0, G_MAXUINT, 0, G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); g_object_class_install_properties (object_class, PROP_LAST_PROP, props); } static void fbd_feedback_dummy_init (FbdFeedbackDummy *self) { } guint fbd_feedback_dummy_get_duration (FbdFeedbackDummy *self) { g_return_val_if_fail (FBD_IS_FEEDBACK_DUMMY (self), 0); return self->duration; } 07070100000058000081A400000000000000000000000164F062AA0000017F000000000000000000000000000000000000002900000000feedbackd-0.2.1/src/fbd-feedback-dummy.h/* * Copyright (C) 2020 Purism SPC * * SPDX-License-Identifier: GPL-3.0+ */ #pragma once #include "fbd-feedback-base.h" G_BEGIN_DECLS #define FBD_TYPE_FEEDBACK_DUMMY (fbd_feedback_dummy_get_type()) G_DECLARE_FINAL_TYPE (FbdFeedbackDummy, fbd_feedback_dummy, FBD, FEEDBACK_DUMMY, FbdFeedbackBase); guint fbd_feedback_dummy_get_duration (FbdFeedbackDummy *self); G_END_DECLS 07070100000059000081A400000000000000000000000164F062AA00001586000000000000000000000000000000000000002700000000feedbackd-0.2.1/src/fbd-feedback-led.c/* * Copyright (C) 2020 Purism SPC * SPDX-License-Identifier: GPL-3.0+ * Author: Guido Günther <agx@sigxcpu.org> */ #define G_LOG_DOMAIN "fbd-feedback-led" #include "fbd-enums.h" #include "fbd-dev-leds.h" #include "fbd-feedback-led.h" #include "fbd-feedback-manager.h" /** * SECTION:fbd-feedback-led * @short_description: Describes a led feedback * @Title: FbdFeedbackLed * * The #FbdFeedbackLed describes a feedback via an LED. It currently * only supports periodic patterns. */ enum { PROP_0, PROP_FREQUENCY, PROP_COLOR, PROP_MAX_BRIGHTNESS, PROP_PRIORITY, PROP_LAST_PROP, }; static GParamSpec *props[PROP_LAST_PROP]; typedef struct _FbdFeedbackLed { FbdFeedbackBase parent; guint frequency; guint priority; guint max_brightness; FbdFeedbackLedColor color; } FbdFeedbackLed; G_DEFINE_TYPE (FbdFeedbackLed, fbd_feedback_led, FBD_TYPE_FEEDBACK_BASE) static void fbd_feedback_led_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) { FbdFeedbackLed *self = FBD_FEEDBACK_LED (object); switch (property_id) { case PROP_FREQUENCY: self->frequency = g_value_get_uint (value); break; case PROP_PRIORITY: self->priority = g_value_get_uint (value); break; case PROP_MAX_BRIGHTNESS: self->max_brightness = g_value_get_uint (value); break; case PROP_COLOR: self->color = g_value_get_enum (value); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; } } static void fbd_feedback_led_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec) { FbdFeedbackLed *self = FBD_FEEDBACK_LED (object); switch (property_id) { case PROP_FREQUENCY: g_value_set_uint (value, self->frequency); break; case PROP_PRIORITY: g_value_set_uint (value, self->priority); break; case PROP_MAX_BRIGHTNESS: g_value_set_uint (value, self->max_brightness); break; case PROP_COLOR: g_value_set_enum (value, self->color); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; } } static void fbd_feedback_led_run (FbdFeedbackBase *base) { FbdFeedbackLed *self = FBD_FEEDBACK_LED (base); FbdFeedbackManager *manager = fbd_feedback_manager_get_default (); FbdDevLeds *dev = fbd_feedback_manager_get_dev_leds (manager); g_return_if_fail (FBD_IS_DEV_LEDS (dev)); g_debug ("Periodic led feedback: self->max_brightness, self->frequency"); /* FIXME: handle priority */ fbd_dev_leds_start_periodic (dev, self->color, self->max_brightness, self->frequency); } static void fbd_feedback_led_end (FbdFeedbackBase *base) { FbdFeedbackLed *self = FBD_FEEDBACK_LED (base); FbdFeedbackManager *manager = fbd_feedback_manager_get_default (); FbdDevLeds *dev = fbd_feedback_manager_get_dev_leds (manager); if (dev) fbd_dev_leds_stop (dev, self->color); fbd_feedback_base_done (FBD_FEEDBACK_BASE (self)); } static gboolean fbd_feedback_led_is_available (FbdFeedbackBase *base) { FbdFeedbackManager *manager = fbd_feedback_manager_get_default (); FbdDevLeds *dev = fbd_feedback_manager_get_dev_leds (manager); return FBD_IS_DEV_LEDS (dev); } static void fbd_feedback_led_class_init (FbdFeedbackLedClass *klass) { FbdFeedbackBaseClass *base_class = FBD_FEEDBACK_BASE_CLASS (klass); GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->set_property = fbd_feedback_led_set_property; object_class->get_property = fbd_feedback_led_get_property; base_class->run = fbd_feedback_led_run; base_class->end = fbd_feedback_led_end; base_class->is_available = fbd_feedback_led_is_available; props[PROP_FREQUENCY] = g_param_spec_uint ( "frequency", "Frequency", "Led event frequency in mHz", 0, G_MAXUINT, 0, G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); props[PROP_COLOR] = g_param_spec_enum ( "color", "Color", "The LED color", FBD_TYPE_FEEDBACK_LED_COLOR, FBD_FEEDBACK_LED_COLOR_WHITE, G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); /** * FbdFeedbackLed:priority: * * Priority of the led pattern. Led devices can only display a limited * amount of patterns at time. In this case the pattern with the highest * priority wins. */ props[PROP_PRIORITY] = g_param_spec_uint ( "priority", "Priority", "The LED pattern priority", 0, 255, 0, G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); /** * FbdFeedbackLed:max-brightness: * * The maximum brightness in the LED pattern in percent of the LEDs * maximum brightness. */ props[PROP_MAX_BRIGHTNESS] = g_param_spec_uint ( "max-brightness", "Maximum brightness percentage", "Maximum brightness in the LED pattern", 1, 100, 100, G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); g_object_class_install_properties (object_class, PROP_LAST_PROP, props); } static void fbd_feedback_led_init (FbdFeedbackLed *self) { self->max_brightness = 100; } 0707010000005A000081A400000000000000000000000164F062AA0000025C000000000000000000000000000000000000002700000000feedbackd-0.2.1/src/fbd-feedback-led.h/* * Copyright (C) 2020 Purism SPC * * SPDX-License-Identifier: GPL-3.0+ */ #pragma once #include "fbd-feedback-base.h" G_BEGIN_DECLS typedef enum _FbdFeedbackLedColor { FBD_FEEDBACK_LED_COLOR_WHITE = 0, FBD_FEEDBACK_LED_COLOR_RED = 1, FBD_FEEDBACK_LED_COLOR_GREEN = 2, FBD_FEEDBACK_LED_COLOR_BLUE = 3, FBD_FEEDBACK_LED_COLOR_RGB = 4, FBD_FEEDBACK_LED_COLOR_LAST = FBD_FEEDBACK_LED_COLOR_RGB, } FbdFeedbackLedColor; #define FBD_TYPE_FEEDBACK_LED (fbd_feedback_led_get_type ()) G_DECLARE_FINAL_TYPE (FbdFeedbackLed, fbd_feedback_led, FBD, FEEDBACK_LED, FbdFeedbackBase); G_END_DECLS 0707010000005B000081A400000000000000000000000164F062AA000048D3000000000000000000000000000000000000002B00000000feedbackd-0.2.1/src/fbd-feedback-manager.c/* * Copyright (C) 2020 Purism SPC * SPDX-License-Identifier: GPL-3.0+ * Author: Guido Günther <agx@sigxcpu.org> */ #define G_LOG_DOMAIN "fbd-feedback-manager" #include "lfb-names.h" #include "fbd.h" #include "fbd-dev-vibra.h" #include "fbd-dev-leds.h" #include "fbd-event.h" #include "fbd-feedback-vibra.h" #include "fbd-feedback-manager.h" #include "fbd-feedback-theme.h" #include "fbd-theme-expander.h" #define GMOBILE_USE_UNSTABLE_API #include <gmobile.h> #include <gio/gio.h> #include <glib-unix.h> #include <gudev/gudev.h> #define FEEDBACKD_SCHEMA_ID "org.sigxcpu.feedbackd" #define FEEDBACKD_KEY_PROFILE "profile" #define FEEDBACKD_KEY_THEME "theme" #define APP_SCHEMA FEEDBACKD_SCHEMA_ID ".application" #define APP_PREFIX "/org/sigxcpu/feedbackd/application/" #define FEEDBACKD_THEME_VAR "FEEDBACK_THEME" /** * SECTION:fbd-feedback-manager * @short_description: The manager processing incoming events * @Title: FbdFeedbackManager * * The #FbdFeedbackManager listens for DBus messages and triggers feedbacks * based on the incoming events. */ typedef struct _FbdFeedbackManager { LfbGdbusFeedbackSkeleton parent; GSettings *settings; FbdFeedbackProfileLevel level; FbdFeedbackTheme *theme; guint next_id; /* Key: event id, value: event */ GHashTable *events; /* Key: DBus name, value: watch_id */ GHashTable *clients; /* Hardware interaction */ GUdevClient *client; FbdDevVibra *vibra; FbdDevSound *sound; FbdDevLeds *leds; } FbdFeedbackManager; static void fbd_feedback_manager_feedback_iface_init (LfbGdbusFeedbackIface *iface); G_DEFINE_TYPE_WITH_CODE (FbdFeedbackManager, fbd_feedback_manager, LFB_GDBUS_TYPE_FEEDBACK_SKELETON, G_IMPLEMENT_INTERFACE ( LFB_GDBUS_TYPE_FEEDBACK, fbd_feedback_manager_feedback_iface_init)); static void device_changes (FbdFeedbackManager *self, gchar *action, GUdevDevice *device, GUdevClient *client) { g_debug ("Device changes: action = %s, device = %s", action, g_udev_device_get_sysfs_path (device)); if (g_strcmp0 (action, "remove") == 0 && self->vibra) { GUdevDevice *dev = fbd_dev_vibra_get_device (self->vibra); if (g_strcmp0 (g_udev_device_get_sysfs_path (dev), g_udev_device_get_sysfs_path (device)) == 0) { g_debug ("Vibra device %s got removed", g_udev_device_get_sysfs_path (dev)); g_clear_object (&self->vibra); } } else if (g_strcmp0 (action, "add") == 0) { if (!g_strcmp0 (g_udev_device_get_property (device, FEEDBACKD_UDEV_ATTR), "vibra")) { g_autoptr (GError) err = NULL; g_debug ("Found hotplugged vibra device at %s", g_udev_device_get_sysfs_path (device)); g_clear_object (&self->vibra); self->vibra = fbd_dev_vibra_new (device, &err); if (!self->vibra) g_warning ("Failed to init vibra device: %s", err->message); } } } static gchar * munge_app_id (const gchar *app_id) { gchar *id = g_strdup (app_id); gint i; g_strcanon (id, "0123456789" "abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "-", '-'); for (i = 0; id[i] != '\0'; i++) id[i] = g_ascii_tolower (id[i]); return id; } static FbdFeedbackProfileLevel app_get_feedback_level (const gchar *app_id) { g_autofree gchar *profile = NULL; g_autofree gchar *munged_app_id = munge_app_id (app_id); g_autofree gchar *path = g_strconcat (APP_PREFIX, munged_app_id, "/", NULL); g_autoptr (GSettings) setting = g_settings_new_with_path (APP_SCHEMA, path); profile = g_settings_get_string (setting, FEEDBACKD_KEY_PROFILE); g_debug ("%s uses app profile %s", app_id, profile); return fbd_feedback_profile_level (profile); } static void init_devices (FbdFeedbackManager *self) { GList *l; g_autolist (GUdevClient) devices = NULL; g_autoptr(GError) err = NULL; devices = g_udev_client_query_by_subsystem (self->client, "input"); for (l = devices; l != NULL; l = l->next) { GUdevDevice *dev = l->data; if (!g_strcmp0 (g_udev_device_get_property (dev, FEEDBACKD_UDEV_ATTR), "vibra")) { g_debug ("Found vibra device"); self->vibra = fbd_dev_vibra_new (dev, &err); if (!self->vibra) { g_warning ("Failed to init vibra device: %s", err->message); g_clear_error (&err); } } } if (!self->vibra) g_debug ("No vibra capable device found"); self->leds = fbd_dev_leds_new (&err); if (!self->leds) { g_debug ("Failed to init leds device: %s", err->message); g_clear_error (&err); } self->sound = fbd_dev_sound_new (&err); if (!self->sound) { g_warning ("Failed to init sound device: %s", err->message); g_clear_error (&err); } } static void on_event_feedbacks_ended (FbdFeedbackManager *self, FbdEvent *event) { guint event_id; g_return_if_fail (FBD_IS_FEEDBACK_MANAGER (self)); g_return_if_fail (FBD_IS_EVENT (event)); event_id = fbd_event_get_id (event); event = g_hash_table_lookup (self->events, GUINT_TO_POINTER (event_id)); if (!event) { g_warning ("Feedback ended for unknown event %d", event_id); return; } g_return_if_fail (fbd_event_get_feedbacks_ended (event)); lfb_gdbus_feedback_emit_feedback_ended (LFB_GDBUS_FEEDBACK (self), event_id, fbd_event_get_end_reason (event)); g_debug ("All feedbacks for event %d finished", event_id); g_hash_table_remove (self->events, GUINT_TO_POINTER (event_id)); } static void on_profile_changed (FbdFeedbackManager *self, GParamSpec *psepc, gpointer unused) { const gchar *pname; g_return_if_fail (FBD_IS_FEEDBACK_MANAGER (self)); pname = lfb_gdbus_feedback_get_profile (LFB_GDBUS_FEEDBACK (self)); if (!fbd_feedback_manager_set_profile (self, pname)) g_warning ("Invalid profile '%s'", pname); /* TODO: end running feedbacks that aren't allowed in new profile immediately */ } static void on_feedbackd_setting_changed (FbdFeedbackManager *self, const gchar *key, GSettings *settings) { g_autofree gchar *profile = NULL; g_return_if_fail (FBD_IS_FEEDBACK_MANAGER (self)); g_return_if_fail (G_IS_SETTINGS (settings)); if (g_str_equal (key, FEEDBACKD_KEY_PROFILE)) { profile = g_settings_get_string (settings, key); fbd_feedback_manager_set_profile (self, profile); } else if (g_str_equal (key, FEEDBACKD_KEY_THEME)) { fbd_feedback_manager_load_theme (self); } else { g_critical ("Unknown settings key '%s'", key); } } static void on_client_vanished (GDBusConnection *connection, const gchar *name, gpointer user_data) { FbdFeedbackManager *self = FBD_FEEDBACK_MANAGER (user_data); GHashTableIter iter; gpointer key, value; FbdEvent *event; GSList *l; g_autoptr (GSList) events = NULL; g_return_if_fail (name); g_debug ("Client %s vanished", name); /* * Prepare a list of events to end feedback for so we don't modify * the hash table in place when 'feedbacks-ended' fires. */ g_hash_table_iter_init (&iter, self->events); while (g_hash_table_iter_next (&iter, &key, &value)) { event = FBD_EVENT (value); if (!g_strcmp0 (fbd_event_get_sender (event), name)) events = g_slist_append (events, event); } for (l = events; l; l = l->next) { event = l->data; g_debug ("Ending event %s (%d) since %s vanished", fbd_event_get_event (event), fbd_event_get_id (event), name); fbd_event_end_feedbacks (event); } g_hash_table_remove (self->clients, name); } static void watch_client (FbdFeedbackManager *self, GDBusMethodInvocation *invocation) { guint watch_id; GDBusConnection *conn = g_dbus_method_invocation_get_connection (invocation); const char *sender = g_dbus_method_invocation_get_sender (invocation); watch_id = g_bus_watch_name_on_connection (conn, sender, G_BUS_NAME_WATCHER_FLAGS_NONE, NULL, on_client_vanished, self, NULL); g_hash_table_insert (self->clients, g_strdup (sender), GUINT_TO_POINTER (watch_id)); } static void free_client_watch (gpointer data) { guint watch_id = GPOINTER_TO_UINT (data); if (watch_id == 0) return; g_bus_unwatch_name (watch_id); } static FbdFeedbackProfileLevel get_max_level (FbdFeedbackProfileLevel global_level, FbdFeedbackProfileLevel app_level, FbdFeedbackProfileLevel event_level) { FbdFeedbackProfileLevel level; /* Individual events and apps can select lower levels than the global level but not higher ones */ level = global_level > app_level ? app_level : global_level; level = level > event_level ? event_level : level; return level; } static gboolean parse_hints (GVariant *hints, FbdFeedbackProfileLevel *level) { const gchar *profile; gboolean found; g_auto (GVariantDict) dict = G_VARIANT_DICT_INIT (NULL); g_variant_dict_init (&dict, hints); found = g_variant_dict_lookup (&dict, "profile", "&s", &profile); if (level && found) *level = fbd_feedback_profile_level (profile); return TRUE; } static gboolean fbd_feedback_manager_handle_trigger_feedback (LfbGdbusFeedback *object, GDBusMethodInvocation *invocation, const gchar *arg_app_id, const gchar *arg_event, GVariant *arg_hints, gint arg_timeout) { FbdFeedbackManager *self; FbdEvent *event; GSList *feedbacks, *l; guint event_id; const gchar *sender; FbdFeedbackProfileLevel app_level, level, hint_level = FBD_FEEDBACK_PROFILE_LEVEL_FULL; gboolean found_fb = FALSE; sender = g_dbus_method_invocation_get_sender (invocation); g_debug ("Event '%s' for '%s' from %s", arg_event, arg_app_id, sender); g_return_val_if_fail (FBD_IS_FEEDBACK_MANAGER (object), FALSE); g_return_val_if_fail (arg_app_id, FALSE); g_return_val_if_fail (arg_event, FALSE); self = FBD_FEEDBACK_MANAGER (object); if (!strlen (arg_app_id)) { g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "Invalid app id %s", arg_app_id); return TRUE; } if (!strlen (arg_event)) { g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "Invalid event %s", arg_event); return TRUE; } if (!parse_hints (arg_hints, &hint_level)) { g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "Invalid hints"); return TRUE; } if (arg_timeout < -1) arg_timeout = -1; event_id = self->next_id++; event = fbd_event_new (event_id, arg_app_id, arg_event, arg_timeout, sender); g_hash_table_insert (self->events, GUINT_TO_POINTER (event_id), event); app_level = app_get_feedback_level (arg_app_id); level = get_max_level (self->level, app_level, hint_level); feedbacks = fbd_feedback_theme_lookup_feedback (self->theme, level, event); if (feedbacks) { for (l = feedbacks; l; l = l->next) { FbdFeedbackBase *fb = l->data; if (fbd_feedback_is_available (FBD_FEEDBACK_BASE (fb))) { fbd_event_add_feedback (event, fb); found_fb = TRUE; } } g_slist_free_full (feedbacks, g_object_unref); } else { /* No feedbacks found at all */ found_fb = FALSE; } lfb_gdbus_feedback_complete_trigger_feedback (object, invocation, event_id); if (found_fb) { g_signal_connect_object (event, "feedbacks-ended", (GCallback) on_event_feedbacks_ended, self, G_CONNECT_SWAPPED); fbd_event_run_feedbacks (event); watch_client (self, invocation); } else { g_hash_table_remove (self->events, GUINT_TO_POINTER (event_id)); lfb_gdbus_feedback_emit_feedback_ended (LFB_GDBUS_FEEDBACK (self), event_id, FBD_EVENT_END_REASON_NOT_FOUND); } return TRUE; } static gboolean fbd_feedback_manager_handle_end_feedback (LfbGdbusFeedback *object, GDBusMethodInvocation *invocation, guint event_id) { FbdFeedbackManager *self; FbdEvent *event; g_debug ("Ending feedback for event '%d'", event_id); g_return_val_if_fail (FBD_IS_FEEDBACK_MANAGER (object), FALSE); g_return_val_if_fail (event_id, FALSE); self = FBD_FEEDBACK_MANAGER (object); event = g_hash_table_lookup (self->events, GUINT_TO_POINTER (event_id)); if (event) { /* The last feedback ending will trigger event disposal via `on_fb_ended` */ fbd_event_end_feedbacks (event); } else { g_warning ("Tried to end non-existing event %d", event_id); } lfb_gdbus_feedback_complete_end_feedback (object, invocation); return TRUE; } static void fbd_feedback_manager_constructed (GObject *object) { FbdFeedbackManager *self = FBD_FEEDBACK_MANAGER (object); G_OBJECT_CLASS (fbd_feedback_manager_parent_class)->constructed (object); g_signal_connect (self, "notify::profile", (GCallback)on_profile_changed, NULL); self->settings = g_settings_new (FEEDBACKD_SCHEMA_ID); g_signal_connect_swapped (self->settings, "changed::" FEEDBACKD_KEY_THEME, G_CALLBACK (on_feedbackd_setting_changed), self); g_signal_connect_swapped (self->settings, "changed::" FEEDBACKD_KEY_PROFILE, G_CALLBACK (on_feedbackd_setting_changed), self); on_feedbackd_setting_changed (self, FEEDBACKD_KEY_PROFILE, self->settings); } static void fbd_feedback_manager_dispose (GObject *object) { FbdFeedbackManager *self = FBD_FEEDBACK_MANAGER (object); g_clear_object (&self->settings); g_clear_object (&self->theme); g_clear_object (&self->sound); g_clear_object (&self->vibra); g_clear_object (&self->leds); g_clear_object (&self->client); g_clear_pointer (&self->events, g_hash_table_destroy); g_clear_pointer (&self->clients, g_hash_table_destroy); G_OBJECT_CLASS (fbd_feedback_manager_parent_class)->dispose (object); } static void fbd_feedback_manager_feedback_iface_init (LfbGdbusFeedbackIface *iface) { iface->handle_trigger_feedback = fbd_feedback_manager_handle_trigger_feedback; iface->handle_end_feedback = fbd_feedback_manager_handle_end_feedback; } static void fbd_feedback_manager_class_init (FbdFeedbackManagerClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->constructed = fbd_feedback_manager_constructed; object_class->dispose = fbd_feedback_manager_dispose; } static void fbd_feedback_manager_init (FbdFeedbackManager *self) { const gchar * const subsystems[] = { "input", NULL }; self->next_id = 1; self->level = FBD_FEEDBACK_PROFILE_LEVEL_UNKNOWN; self->client = g_udev_client_new (subsystems); g_signal_connect_swapped (G_OBJECT (self->client), "uevent", G_CALLBACK (device_changes), self); init_devices (self); self->events = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, (GDestroyNotify)g_object_unref); self->clients = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, free_client_watch); } FbdFeedbackManager * fbd_feedback_manager_get_default (void) { static FbdFeedbackManager *instance; if (instance == NULL) { instance = g_object_new (FBD_TYPE_FEEDBACK_MANAGER, NULL); g_object_add_weak_pointer (G_OBJECT (instance), (gpointer *)&instance); } return instance; } FbdDevVibra * fbd_feedback_manager_get_dev_vibra (FbdFeedbackManager *self) { g_return_val_if_fail (FBD_IS_FEEDBACK_MANAGER (self), NULL); return self->vibra; } FbdDevSound * fbd_feedback_manager_get_dev_sound (FbdFeedbackManager *self) { g_return_val_if_fail (FBD_IS_FEEDBACK_MANAGER (self), NULL); return self->sound; } FbdDevLeds * fbd_feedback_manager_get_dev_leds (FbdFeedbackManager *self) { g_return_val_if_fail (FBD_IS_FEEDBACK_MANAGER (self), NULL); return self->leds; } void fbd_feedback_manager_load_theme (FbdFeedbackManager *self) { g_autoptr (FbdThemeExpander) expander = NULL; g_autoptr (FbdFeedbackTheme) theme = NULL; g_autoptr (GError) err = NULL; g_auto (GStrv) compatibles = NULL; g_autofree char *theme_name = NULL; const char *theme_file = g_getenv (FEEDBACKD_THEME_VAR); compatibles = gm_device_tree_get_compatibles (NULL, &err); if (compatibles == NULL && err) { g_debug ("Failed to get compatibles: %s", err->message); g_clear_error (&err); } if (theme_file == NULL) theme_name = g_settings_get_string (self->settings, FEEDBACKD_KEY_THEME); expander = fbd_theme_expander_new ((const char *const *)compatibles, theme_name, theme_file); theme = fbd_theme_expander_load_theme_files (expander, &err); if (theme) { g_set_object(&self->theme, theme); } else { if (self->theme) g_warning ("Failed to reload theme: %s", err->message); else g_error ("Failed to load any theme: %s", err->message); // No point to carry on } } gboolean fbd_feedback_manager_set_profile (FbdFeedbackManager *self, const gchar *profile) { FbdFeedbackProfileLevel level; g_return_val_if_fail (FBD_IS_FEEDBACK_MANAGER (self), FALSE); level = fbd_feedback_profile_level (profile); if (level == FBD_FEEDBACK_PROFILE_LEVEL_UNKNOWN) return FALSE; if (level == self->level) return TRUE; g_debug ("Switching profile to '%s'", profile); self->level = level; lfb_gdbus_feedback_set_profile (LFB_GDBUS_FEEDBACK (self), profile); g_settings_set_string (self->settings, FEEDBACKD_KEY_PROFILE, profile); return TRUE; } 0707010000005C000081A400000000000000000000000164F062AA00000381000000000000000000000000000000000000002B00000000feedbackd-0.2.1/src/fbd-feedback-manager.h/* * Copyright (C) 2020 Purism SPC * * SPDX-License-Identifier: GPL-3.0+ */ #pragma once #include "fbd-dev-vibra.h" #include "fbd-dev-leds.h" #include "fbd-dev-sound.h" #include "lfb-gdbus.h" #include <glib-object.h> G_BEGIN_DECLS #define FBD_TYPE_FEEDBACK_MANAGER (fbd_feedback_manager_get_type()) G_DECLARE_FINAL_TYPE (FbdFeedbackManager, fbd_feedback_manager, FBD, FEEDBACK_MANAGER, LfbGdbusFeedbackSkeleton); FbdFeedbackManager *fbd_feedback_manager_get_default (void); FbdDevVibra *fbd_feedback_manager_get_dev_vibra (FbdFeedbackManager *self); FbdDevSound *fbd_feedback_manager_get_dev_sound (FbdFeedbackManager *self); FbdDevLeds *fbd_feedback_manager_get_dev_leds (FbdFeedbackManager *self); void fbd_feedback_manager_load_theme (FbdFeedbackManager *self); gboolean fbd_feedback_manager_set_profile (FbdFeedbackManager *self, const gchar *profile); G_END_DECLS 0707010000005D000081A400000000000000000000000164F062AA00002E31000000000000000000000000000000000000002B00000000feedbackd-0.2.1/src/fbd-feedback-profile.c/* * Copyright (C) 2020 Purism SPC * SPDX-License-Identifier: GPL-3.0+ * Author: Guido Günther <agx@sigxcpu.org> */ #define G_LOG_DOMAIN "fbd-feedback-profile" #include "fbd-feedback-dummy.h" #include "fbd-feedback-profile.h" #include "fbd-feedback-sound.h" #include "fbd-feedback-led.h" #include "fbd-feedback-vibra-periodic.h" #include "fbd-feedback-vibra-rumble.h" #include <json-glib/json-glib.h> #define FBD_FEEDBACK_CLS_PREFIX "FbdFeedback" enum { PROP_0, PROP_NAME, PROP_FEEDBACKS, PROP_LAST_PROP, }; static GParamSpec *props[PROP_LAST_PROP]; /** * SECTION:fbd-feedback-profile * @short_description: A profile in a #FbdFeedbackTheme * @Title: FbdFeedbackProfile */ typedef struct _FbdFeedbackProfile { GObject parent; gchar *name; GHashTable *feedbacks; /* key: event name, value: feedback */ } FbdFeedbackProfile; static void json_serializable_iface_init (JsonSerializableIface *iface); G_DEFINE_TYPE_WITH_CODE (FbdFeedbackProfile, fbd_feedback_profile, G_TYPE_OBJECT, G_IMPLEMENT_INTERFACE (JSON_TYPE_SERIALIZABLE, json_serializable_iface_init)); static JsonNode * fbd_feedback_profile_serializable_serialize_property (JsonSerializable *serializable, const gchar *property_name, const GValue *value, GParamSpec *pspec) { FbdFeedbackProfile *self = FBD_FEEDBACK_PROFILE (serializable); JsonNode *node = NULL; if (g_strcmp0 (property_name, "feedbacks") == 0) { GHashTableIter iter; gpointer key; FbdFeedbackProfile *profile; g_autoptr (JsonArray) array = json_array_sized_new (FBD_FEEDBACK_PROFILE_N_PROFILES); g_hash_table_iter_init (&iter, self->feedbacks); while (g_hash_table_iter_next (&iter, (gpointer *)&key, (gpointer *) &profile)) { json_array_add_element (array, json_gobject_serialize (G_OBJECT(profile))); } node = json_node_init_array (json_node_alloc (), array); } else { node = json_serializable_default_serialize_property (serializable, property_name, value, pspec); } return node; } static GType feedback_get_type (JsonNode *feedback_node) { g_autofree gchar *type_name = NULL; JsonObject *obj = json_node_get_object (feedback_node); JsonNode *type_node = json_object_get_member (obj, "type"); GType gtype = 0; /* Ensure all feedback types so the json parsing can use them */ g_type_ensure (FBD_TYPE_FEEDBACK_DUMMY); g_type_ensure (FBD_TYPE_FEEDBACK_LED); g_type_ensure (FBD_TYPE_FEEDBACK_VIBRA_PERIODIC); g_type_ensure (FBD_TYPE_FEEDBACK_VIBRA_RUMBLE); g_type_ensure (FBD_TYPE_FEEDBACK_SOUND); g_return_val_if_fail (type_node, FBD_TYPE_FEEDBACK_DUMMY); type_name = g_strdup_printf ("FbdFeedback%s", json_node_get_string (type_node)); type_name[strlen(FBD_FEEDBACK_CLS_PREFIX)] = g_ascii_toupper (type_name[strlen(FBD_FEEDBACK_CLS_PREFIX)]); gtype = g_type_from_name (type_name); g_debug ("Feedback %s, type %" G_GSIZE_FORMAT, type_name, gtype); g_return_val_if_fail (gtype, FBD_TYPE_FEEDBACK_DUMMY); return gtype; } static gboolean fbd_feedback_profile_serializable_deserialize_property (JsonSerializable *serializable, const gchar *property_name, GValue *value, GParamSpec *pspec, JsonNode *property_node) { if (g_strcmp0 (property_name, "feedbacks") == 0) { if (JSON_NODE_TYPE (property_node) == JSON_NODE_NULL) { g_value_set_pointer (value, NULL); return TRUE; } else if (JSON_NODE_TYPE (property_node) == JSON_NODE_ARRAY) { JsonArray *array = json_node_get_array (property_node); guint i, array_len = json_array_get_length (array); GHashTable *feedbacks = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify)g_object_unref); for (i = 0; i < array_len; i++) { JsonNode *element_node = json_array_get_element (array, i); if (JSON_NODE_HOLDS_OBJECT (element_node)) { gchar *event_name; FbdFeedbackBase *feedback; GType gtype = feedback_get_type (element_node); feedback = FBD_FEEDBACK_BASE (json_gobject_deserialize (gtype, element_node)); event_name = g_strdup (fbd_feedback_get_event_name (FBD_FEEDBACK_BASE(feedback))); g_hash_table_insert (feedbacks, event_name, feedback); } else { return FALSE; } } g_value_set_boxed (value, feedbacks); return TRUE; } return FALSE; } else { return json_serializable_default_deserialize_property (serializable, property_name, value, pspec, property_node); } return FALSE; } static void fbd_feedback_profile_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) { FbdFeedbackProfile *self = FBD_FEEDBACK_PROFILE (object); switch (property_id) { case PROP_NAME: g_free (self->name); self->name = g_value_dup_string (value); break; case PROP_FEEDBACKS: if (self->feedbacks) g_hash_table_unref (self->feedbacks); self->feedbacks = g_value_get_boxed (value); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; } } static void fbd_feedback_profile_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec) { FbdFeedbackProfile *self = FBD_FEEDBACK_PROFILE (object); switch (property_id) { case PROP_NAME: g_value_set_string (value, self->name); break; case PROP_FEEDBACKS: g_value_set_boxed (value, self->feedbacks); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; } } static void fbd_feedback_profile_dispose (GObject *object) { FbdFeedbackProfile *self = FBD_FEEDBACK_PROFILE (object); g_clear_pointer (&self->feedbacks, g_hash_table_unref); G_OBJECT_CLASS (fbd_feedback_profile_parent_class)->dispose (object); } static void fbd_feedback_profile_finalize (GObject *object) { FbdFeedbackProfile *self = FBD_FEEDBACK_PROFILE (object); g_clear_pointer (&self->name, g_free); G_OBJECT_CLASS (fbd_feedback_profile_parent_class)->finalize (object); } static void json_serializable_iface_init (JsonSerializableIface *iface) { iface->serialize_property = fbd_feedback_profile_serializable_serialize_property; iface->deserialize_property = fbd_feedback_profile_serializable_deserialize_property; } static void fbd_feedback_profile_constructed (GObject *object) { FbdFeedbackProfile *self = FBD_FEEDBACK_PROFILE (object); G_OBJECT_CLASS (fbd_feedback_profile_parent_class)->constructed (object); if (!self->feedbacks) { self->feedbacks = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify)g_object_unref); } } static void fbd_feedback_profile_class_init (FbdFeedbackProfileClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->set_property = fbd_feedback_profile_set_property; object_class->get_property = fbd_feedback_profile_get_property; object_class->constructed = fbd_feedback_profile_constructed; object_class->dispose = fbd_feedback_profile_dispose; object_class->finalize = fbd_feedback_profile_finalize; props[PROP_NAME] = g_param_spec_string ( "name", "Name", "The feedback name", NULL, G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); props[PROP_FEEDBACKS] = g_param_spec_boxed ( "feedbacks", "Feedbacks", "The feedbacks for this profile", G_TYPE_HASH_TABLE, /* Can't be CONSTRUCT_ONLY since json-glib can't handle it */ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); g_object_class_install_properties (object_class, PROP_LAST_PROP, props); } static void fbd_feedback_profile_init (FbdFeedbackProfile *self) { } FbdFeedbackProfile * fbd_feedback_profile_new (const gchar *name) { return g_object_new(FBD_TYPE_FEEDBACK_PROFILE, "name", name, NULL); } const char * fbd_feedback_profile_get_name (FbdFeedbackProfile *self) { g_return_val_if_fail (FBD_IS_FEEDBACK_PROFILE (self), ""); return self->name; } void fbd_feedback_profile_add_feedback (FbdFeedbackProfile *self, FbdFeedbackBase *feedback) { g_return_if_fail (FBD_IS_FEEDBACK_PROFILE (self)); gchar *name = g_strdup (fbd_feedback_get_event_name (feedback)); /* TODO: allow for more than one feedback per event and profile */ g_hash_table_insert (self->feedbacks, name, g_object_ref (feedback)); } FbdFeedbackBase * fbd_feedback_profile_get_feedback (FbdFeedbackProfile *self, const char *event_name) { g_return_val_if_fail (FBD_IS_FEEDBACK_PROFILE (self), NULL); return g_hash_table_lookup (self->feedbacks, event_name); } FbdFeedbackProfileLevel fbd_feedback_profile_level (const char *name) { FbdFeedbackProfileLevel profile = FBD_FEEDBACK_PROFILE_LEVEL_UNKNOWN; if (!g_strcmp0("silent", name)) { profile = FBD_FEEDBACK_PROFILE_LEVEL_SILENT; } else if (!g_strcmp0("quiet", name)) { profile = FBD_FEEDBACK_PROFILE_LEVEL_QUIET; } else if (!g_strcmp0("full", name)) { profile = FBD_FEEDBACK_PROFILE_LEVEL_FULL; } return profile; } const char* fbd_feedback_profile_level_to_string (FbdFeedbackProfileLevel level) { switch (level) { case FBD_FEEDBACK_PROFILE_LEVEL_SILENT: return "silent"; case FBD_FEEDBACK_PROFILE_LEVEL_QUIET: return "quiet"; case FBD_FEEDBACK_PROFILE_LEVEL_FULL: return "full"; case FBD_FEEDBACK_PROFILE_LEVEL_UNKNOWN: default: return "full"; } } /** * fbd_profile_update: * @self: The profile that should be updated * @new: The profile theme we want to take new feedbacks from * * Updates a profile. Feedbacks are read from the `new` profile. If * feedback already exists in `self` it is overwritten with the feedback * from `new`. * * It is not allowed to update a profile with a profile of a different name. */ void fbd_feedback_profile_update (FbdFeedbackProfile *self, FbdFeedbackProfile *new) { GHashTableIter iter; const char *event_name; FbdFeedbackBase *fb; g_return_if_fail (FBD_IS_FEEDBACK_PROFILE (self)); g_return_if_fail (FBD_IS_FEEDBACK_PROFILE (new)); g_return_if_fail (g_str_equal (fbd_feedback_profile_get_name (self), fbd_feedback_profile_get_name (new))); g_hash_table_iter_init (&iter, new->feedbacks); while (g_hash_table_iter_next (&iter, (gpointer)&event_name, (gpointer)&fb)) { g_hash_table_insert (self->feedbacks, g_strdup (event_name), g_object_ref (fb)); } } 0707010000005E000081A400000000000000000000000164F062AA00000568000000000000000000000000000000000000002B00000000feedbackd-0.2.1/src/fbd-feedback-profile.h/* * Copyright (C) 2020 Purism SPC * * SPDX-License-Identifier: GPL-3.0+ */ #pragma once #include <fbd-feedback-base.h> #include <glib-object.h> G_BEGIN_DECLS typedef enum _FbdFeedbackProfileLevel { FBD_FEEDBACK_PROFILE_LEVEL_UNKNOWN = -1, FBD_FEEDBACK_PROFILE_LEVEL_SILENT = 0, FBD_FEEDBACK_PROFILE_LEVEL_QUIET, FBD_FEEDBACK_PROFILE_LEVEL_FULL, FBD_FEEDBACK_PROFILE_N_PROFILES, } FbdFeedbackProfileLevel; #define FBD_TYPE_FEEDBACK_PROFILE (fbd_feedback_profile_get_type()) G_DECLARE_FINAL_TYPE (FbdFeedbackProfile, fbd_feedback_profile, FBD, FEEDBACK_PROFILE, GObject); FbdFeedbackProfile *fbd_feedback_profile_new (const gchar *name); void fbd_feedback_profile_update (FbdFeedbackProfile *self, FbdFeedbackProfile *new); const gchar *fbd_feedback_profile_get_name (FbdFeedbackProfile *self); void fbd_feedback_profile_add_feedback (FbdFeedbackProfile *self, FbdFeedbackBase *feedback); FbdFeedbackBase *fbd_feedback_profile_get_feedback (FbdFeedbackProfile *self, const char *event_name); FbdFeedbackProfileLevel fbd_feedback_profile_level (const char *name); const char* fbd_feedback_profile_level_to_string (FbdFeedbackProfileLevel level); G_END_DECLS 0707010000005F000081A400000000000000000000000164F062AA00001004000000000000000000000000000000000000002900000000feedbackd-0.2.1/src/fbd-feedback-sound.c/* * Copyright (C) 2020 Purism SPC * SPDX-License-Identifier: GPL-3.0+ * Author: Guido Günther <agx@sigxcpu.org> */ #define G_LOG_DOMAIN "fbd-feedback-sound" #include "fbd-enums.h" #include "fbd-feedback-sound.h" #include "fbd-feedback-manager.h" /** * SECTION:fbd-feedback-sound * @short_description: Describes a feedback via a haptic motor * @Title: FbdFeedbackSound * * The #FbdSoundSound describes the properties of a sound feedback * event. It knows nothing about how to play sound itself but calls * #FbdDevSound for that. */ enum { PROP_0, PROP_EFFECT, PROP_LAST_PROP, }; static GParamSpec *props[PROP_LAST_PROP]; typedef struct _FbdFeedbackSound { FbdFeedbackBase parent; gchar *effect; } FbdFeedbackSound; G_DEFINE_TYPE (FbdFeedbackSound, fbd_feedback_sound, FBD_TYPE_FEEDBACK_BASE); static void on_effect_finished (FbdFeedbackSound *self) { fbd_feedback_base_done (FBD_FEEDBACK_BASE(self)); } static void fbd_feedback_sound_run (FbdFeedbackBase *base) { FbdFeedbackSound *self = FBD_FEEDBACK_SOUND (base); FbdFeedbackManager *manager = fbd_feedback_manager_get_default (); FbdDevSound *sound = fbd_feedback_manager_get_dev_sound (manager); g_return_if_fail (FBD_IS_DEV_SOUND (sound)); g_debug ("Sound event %s", self->effect); fbd_dev_sound_play (sound, self, on_effect_finished); } static void fbd_feedback_sound_end (FbdFeedbackBase *base) { FbdFeedbackSound *self = FBD_FEEDBACK_SOUND (base); FbdFeedbackManager *manager = fbd_feedback_manager_get_default (); FbdDevSound *sound = fbd_feedback_manager_get_dev_sound (manager); fbd_dev_sound_stop (sound, self); } static gboolean fbd_feedback_sound_is_available (FbdFeedbackBase *base) { FbdFeedbackManager *manager = fbd_feedback_manager_get_default (); FbdDevSound *sound = fbd_feedback_manager_get_dev_sound (manager); return FBD_IS_DEV_SOUND (sound); } static void fbd_feedback_sound_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) { FbdFeedbackSound *self = FBD_FEEDBACK_SOUND (object); switch (property_id) { case PROP_EFFECT: self->effect = g_value_dup_string (value); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; } } static void fbd_feedback_sound_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec) { FbdFeedbackSound *self = FBD_FEEDBACK_SOUND (object); switch (property_id) { case PROP_EFFECT: g_value_set_string (value, fbd_feedback_sound_get_effect (self)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; } } static void fbd_feedback_sound_finalize (GObject *object) { FbdFeedbackSound *self = FBD_FEEDBACK_SOUND (object); g_clear_pointer (&self->effect, g_free); G_OBJECT_CLASS (fbd_feedback_sound_parent_class)->finalize (object); } static void fbd_feedback_sound_class_init (FbdFeedbackSoundClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); FbdFeedbackBaseClass *base_class = FBD_FEEDBACK_BASE_CLASS (klass); object_class->finalize = fbd_feedback_sound_finalize; object_class->set_property = fbd_feedback_sound_set_property; object_class->get_property = fbd_feedback_sound_get_property; base_class->run = fbd_feedback_sound_run; base_class->end = fbd_feedback_sound_end; base_class->is_available = fbd_feedback_sound_is_available; props[PROP_EFFECT] = g_param_spec_string ( "effect", "Effect", "The sound effects name", "", G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); g_object_class_install_properties (object_class, PROP_LAST_PROP, props); } static void fbd_feedback_sound_init (FbdFeedbackSound *self) { } const char *fbd_feedback_sound_get_effect (FbdFeedbackSound *self) { return self->effect; } 07070100000060000081A400000000000000000000000164F062AA00000183000000000000000000000000000000000000002900000000feedbackd-0.2.1/src/fbd-feedback-sound.h/* * Copyright (C) 2020 Purism SPC * * SPDX-License-Identifier: GPL-3.0+ */ #pragma once #include "fbd-feedback-base.h" G_BEGIN_DECLS #define FBD_TYPE_FEEDBACK_SOUND (fbd_feedback_sound_get_type()) G_DECLARE_FINAL_TYPE (FbdFeedbackSound, fbd_feedback_sound, FBD, FEEDBACK_SOUND, FbdFeedbackBase); const char *fbd_feedback_sound_get_effect (FbdFeedbackSound *self); G_END_DECLS 07070100000061000081A400000000000000000000000164F062AA00002C7F000000000000000000000000000000000000002900000000feedbackd-0.2.1/src/fbd-feedback-theme.c/* * Copyright (C) 2020 Purism SPC * SPDX-License-Identifier: GPL-3.0+ * Author: Guido Günther <agx@sigxcpu.org> */ #define G_LOG_DOMAIN "fbd-feedback-theme" #include "fbd-feedback-base.h" #include "fbd-feedback-dummy.h" #include "fbd-feedback-sound.h" #include "fbd-feedback-theme.h" #include "fbd-feedback-vibra.h" #include "fbd-feedback-profile.h" #include <json-glib/json-glib.h> enum { PROP_0, PROP_NAME, PROP_PARENT_NAME, PROP_PROFILES, PROP_LAST_PROP, }; static GParamSpec *props[PROP_LAST_PROP]; typedef struct _FbdFeedbackTheme { GObject parent; char *name; char *parent_name; GHashTable *profiles; } FbdFeedbackTheme; static void json_serializable_iface_init (JsonSerializableIface *iface); G_DEFINE_TYPE_WITH_CODE (FbdFeedbackTheme, fbd_feedback_theme, G_TYPE_OBJECT, G_IMPLEMENT_INTERFACE (JSON_TYPE_SERIALIZABLE, json_serializable_iface_init)); static JsonNode * fbd_theme_serializable_serialize_property (JsonSerializable *serializable, const gchar *property_name, const GValue *value, GParamSpec *pspec) { FbdFeedbackTheme *self = FBD_FEEDBACK_THEME (serializable); JsonNode *node = NULL; if (g_strcmp0 (property_name, "profiles") == 0) { GHashTableIter iter; gpointer key; FbdFeedbackProfile *profile; g_autoptr (JsonArray) array = json_array_sized_new (FBD_FEEDBACK_PROFILE_N_PROFILES); g_hash_table_iter_init (&iter, self->profiles); while (g_hash_table_iter_next (&iter, (gpointer *)&key, (gpointer *) &profile)) { json_array_add_element (array, json_gobject_serialize (G_OBJECT(profile))); } node = json_node_init_array (json_node_alloc (), array); } else { node = json_serializable_default_serialize_property (serializable, property_name, value, pspec); } return node; } static gboolean fbd_theme_serializable_deserialize_property (JsonSerializable *serializable, const gchar *property_name, GValue *value, GParamSpec *pspec, JsonNode *property_node) { if (g_strcmp0 (property_name, "profiles") == 0) { if (JSON_NODE_TYPE (property_node) == JSON_NODE_NULL) { g_value_set_pointer (value, NULL); return TRUE; } else if (JSON_NODE_TYPE (property_node) == JSON_NODE_ARRAY) { JsonArray *array = json_node_get_array (property_node); guint i, array_len = json_array_get_length (array); GHashTable *profiles = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify)g_object_unref); for (i = 0; i < array_len; i++) { JsonNode *element_node = json_array_get_element (array, i); FbdFeedbackProfile *profile; gchar *name; if (JSON_NODE_HOLDS_OBJECT (element_node)) { profile = FBD_FEEDBACK_PROFILE (json_gobject_deserialize (FBD_TYPE_FEEDBACK_PROFILE, element_node)); name = g_strdup (fbd_feedback_profile_get_name (profile)); g_hash_table_insert (profiles, name, profile); } else { return FALSE; } } g_value_set_boxed (value, profiles); return TRUE; } return FALSE; } else { return json_serializable_default_deserialize_property (serializable, property_name, value, pspec, property_node); } return FALSE; } static void fbd_feedback_theme_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) { FbdFeedbackTheme *self = FBD_FEEDBACK_THEME (object); switch (property_id) { case PROP_NAME: fbd_feedback_theme_set_name (self, g_value_get_string (value)); break; case PROP_PARENT_NAME: fbd_feedback_theme_set_parent_name (self, g_value_get_string (value)); break; case PROP_PROFILES: if (self->profiles) g_hash_table_unref (self->profiles); self->profiles = g_value_get_boxed (value); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; } } static void fbd_feedback_theme_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec) { FbdFeedbackTheme *self = FBD_FEEDBACK_THEME (object); switch (property_id) { case PROP_NAME: g_value_set_string (value, fbd_feedback_theme_get_name (self)); break; case PROP_PARENT_NAME: g_value_set_string (value, fbd_feedback_theme_get_parent_name (self)); break; case PROP_PROFILES: g_value_set_boxed (value, self->profiles); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; } } static void fbd_feedback_theme_dispose (GObject *object) { FbdFeedbackTheme *self = FBD_FEEDBACK_THEME (object); g_clear_pointer (&self->profiles, g_hash_table_unref); G_OBJECT_CLASS (fbd_feedback_theme_parent_class)->dispose (object); } static void fbd_feedback_theme_finalize (GObject *object) { FbdFeedbackTheme *self = FBD_FEEDBACK_THEME (object); g_clear_pointer (&self->parent_name, g_free); g_clear_pointer (&self->name, g_free); G_OBJECT_CLASS (fbd_feedback_theme_parent_class)->finalize (object); } static void json_serializable_iface_init (JsonSerializableIface *iface) { iface->serialize_property = fbd_theme_serializable_serialize_property; iface->deserialize_property = fbd_theme_serializable_deserialize_property; } static void fbd_feedback_theme_class_init (FbdFeedbackThemeClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->set_property = fbd_feedback_theme_set_property; object_class->get_property = fbd_feedback_theme_get_property; object_class->dispose = fbd_feedback_theme_dispose; object_class->finalize = fbd_feedback_theme_finalize; props[PROP_NAME] = g_param_spec_string ( "name", "Name", "The theme name", NULL, G_PARAM_EXPLICIT_NOTIFY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); props[PROP_PARENT_NAME] = g_param_spec_string ( "parent-name", "Parent theme Name", "The parent theme name", NULL, G_PARAM_EXPLICIT_NOTIFY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); props[PROP_PROFILES] = g_param_spec_boxed ( "profiles", "Profiles", "The feedback profiles", G_TYPE_HASH_TABLE, /* Can't be CONSTRUCT_ONLY since json-glib can't handle it */ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); g_object_class_install_properties (object_class, PROP_LAST_PROP, props); } static void fbd_feedback_theme_init (FbdFeedbackTheme *self) { self->profiles = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify)g_object_unref); } FbdFeedbackTheme * fbd_feedback_theme_new (const gchar *name) { return FBD_FEEDBACK_THEME (g_object_new (FBD_TYPE_FEEDBACK_THEME, "name", name, NULL)); } FbdFeedbackTheme * fbd_feedback_theme_new_from_data (const gchar *data, GError **error) { g_autoptr (JsonNode) node = json_from_string(data, error); if (!node) return NULL; return FBD_FEEDBACK_THEME (json_gobject_deserialize (FBD_TYPE_FEEDBACK_THEME, node)); } FbdFeedbackTheme * fbd_feedback_theme_new_from_file (const gchar *filename, GError **error) { g_autofree char *data = NULL; if (!g_file_get_contents (filename, &data, NULL, error)) return NULL; return fbd_feedback_theme_new_from_data (data, error); } void fbd_feedback_theme_set_name (FbdFeedbackTheme *self, const char *name) { g_return_if_fail (FBD_IS_FEEDBACK_THEME (self)); if (g_strcmp0 (self->name, name) == 0) return; g_free (self->name); self->name = g_strdup (name); g_object_notify_by_pspec (G_OBJECT (self), props[PROP_NAME]); } const char * fbd_feedback_theme_get_name (FbdFeedbackTheme *self) { g_return_val_if_fail (FBD_IS_FEEDBACK_THEME (self), ""); return self->name; } void fbd_feedback_theme_set_parent_name (FbdFeedbackTheme *self, const char *parent_name) { g_return_if_fail (FBD_IS_FEEDBACK_THEME (self)); if (g_strcmp0 (self->parent_name, parent_name) == 0) return; g_free (self->parent_name); self->parent_name = g_strdup (parent_name); g_object_notify_by_pspec (G_OBJECT (self), props[PROP_PARENT_NAME]); } const char * fbd_feedback_theme_get_parent_name (FbdFeedbackTheme *self) { g_return_val_if_fail (FBD_IS_FEEDBACK_THEME (self), ""); return self->parent_name; } void fbd_feedback_theme_add_profile (FbdFeedbackTheme *self, FbdFeedbackProfile *profile) { gchar *name; g_return_if_fail (FBD_IS_FEEDBACK_THEME (self)); g_return_if_fail (FBD_IS_FEEDBACK_PROFILE (profile)); name = g_strdup (fbd_feedback_profile_get_name (profile)); g_hash_table_insert (self->profiles, name, g_object_ref (profile)); } FbdFeedbackProfile * fbd_feedback_theme_get_profile (FbdFeedbackTheme *self, const char *name) { g_return_val_if_fail (FBD_IS_FEEDBACK_THEME (self), NULL); return g_hash_table_lookup (self->profiles, name); } GSList * fbd_feedback_theme_lookup_feedback (FbdFeedbackTheme *self, FbdFeedbackProfileLevel level, FbdEvent *event) { GSList *feedbacks = NULL; for (int i = level; i >= FBD_FEEDBACK_PROFILE_LEVEL_SILENT; i--) { const char *profile_name = fbd_feedback_profile_level_to_string (i); FbdFeedbackProfile *profile = fbd_feedback_theme_get_profile (self, profile_name); FbdFeedbackBase *feedback = fbd_feedback_profile_get_feedback (profile, fbd_event_get_event (event)); if (feedback) { feedbacks = g_slist_prepend (feedbacks, g_object_ref(feedback)); } } if (!g_slist_length (feedbacks)) g_debug ("No feedback for event %s", fbd_event_get_event (event)); return feedbacks; } /** * fbd_feedback_theme_update: * @self: The feedback theme that should be updated * @new: The feedback theme we want to take profiles and feedbacks new * * Merges two feedback themes. Feedbacks and profiles are read new * the `new` theme. If feedback already exists in the same profile * of `self` it is overwritten with the feedback in `new`. */ void fbd_feedback_theme_update (FbdFeedbackTheme *self, FbdFeedbackTheme *new) { GHashTableIter iter; const char *profile_name; FbdFeedbackProfile *profile; g_return_if_fail (FBD_IS_FEEDBACK_THEME (self)); g_return_if_fail (FBD_IS_FEEDBACK_THEME (new)); fbd_feedback_theme_set_name (self, fbd_feedback_theme_get_name (new)); g_hash_table_iter_init (&iter, new->profiles); while (g_hash_table_iter_next (&iter, (gpointer)&profile_name, (gpointer)&profile)) { FbdFeedbackProfile *current; current = g_hash_table_lookup (self->profiles, profile_name); if (current == NULL) { current = fbd_feedback_profile_new (profile_name); g_hash_table_insert (self->profiles, g_strdup (profile_name), current); } fbd_feedback_profile_update (current, profile); } } 07070100000062000081A400000000000000000000000164F062AA0000065C000000000000000000000000000000000000002900000000feedbackd-0.2.1/src/fbd-feedback-theme.h/* * Copyright (C) 2020 Purism SPC * * SPDX-License-Identifier: GPL-3.0+ */ #pragma once #include "fbd-event.h" #include "fbd-feedback-base.h" #include "fbd-feedback-manager.h" #include "fbd-feedback-profile.h" #include <glib-object.h> G_BEGIN_DECLS #define FBD_TYPE_FEEDBACK_THEME (fbd_feedback_theme_get_type()) G_DECLARE_FINAL_TYPE (FbdFeedbackTheme, fbd_feedback_theme, FBD, FEEDBACK_THEME, GObject); FbdFeedbackTheme *fbd_feedback_theme_new (const char *name); FbdFeedbackTheme *fbd_feedback_theme_new_from_data (const gchar *data, GError **error); FbdFeedbackTheme *fbd_feedback_theme_new_from_file (const gchar *filename, GError **error); void fbd_feedback_theme_update (FbdFeedbackTheme *self, FbdFeedbackTheme *from); const char *fbd_feedback_theme_get_name (FbdFeedbackTheme *self); void fbd_feedback_theme_set_name (FbdFeedbackTheme *self, const char *name); void fbd_feedback_theme_set_parent_name (FbdFeedbackTheme *self, const char *parent_name); const char *fbd_feedback_theme_get_parent_name (FbdFeedbackTheme *self); void fbd_feedback_theme_add_profile (FbdFeedbackTheme *self, FbdFeedbackProfile *profile); FbdFeedbackProfile *fbd_feedback_theme_get_profile (FbdFeedbackTheme *self, const char *name); GSList *fbd_feedback_theme_lookup_feedback (FbdFeedbackTheme *self, FbdFeedbackProfileLevel profile, FbdEvent *event); G_END_DECLS 07070100000063000081A400000000000000000000000164F062AA000012A3000000000000000000000000000000000000003200000000feedbackd-0.2.1/src/fbd-feedback-vibra-periodic.c/* * Copyright (C) 2020 Purism SPC * SPDX-License-Identifier: GPL-3.0+ * Author: Guido Günther <agx@sigxcpu.org> */ #define G_LOG_DOMAIN "fbd-feedback-vibra-periodic" #include "fbd-enums.h" #include "fbd-feedback-vibra-periodic.h" #include "fbd-feedback-manager.h" /** * SECTION:fbd-feedback-vibra-periodic * @short_description: Describes a periodic feedback via a haptic motor * @Title: FbdFeedbackVibraPeriodic * * The #FbdVibraVibraPeriodic describes the properties of a haptic feedback * event. It knows nothing about the hardware itself but calls * #FbdDevVibra for that. */ enum { PROP_0, PROP_MAGNITUDE, PROP_FADE_IN_LEVEL, PROP_FADE_IN_TIME, PROP_LAST_PROP, }; static GParamSpec *props[PROP_LAST_PROP]; typedef struct _FbdFeedbackVibraPeriodic { FbdFeedbackVibra parent; guint magnitude; guint fade_in_level; guint fade_in_time; } FbdFeedbackVibraPeriodic; G_DEFINE_TYPE (FbdFeedbackVibraPeriodic, fbd_feedback_vibra_periodic, FBD_TYPE_FEEDBACK_VIBRA); static void fbd_feedback_vibra_periodic_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) { FbdFeedbackVibraPeriodic *self = FBD_FEEDBACK_VIBRA_PERIODIC (object); switch (property_id) { case PROP_MAGNITUDE: self->magnitude = g_value_get_uint (value); break; case PROP_FADE_IN_LEVEL: self->fade_in_level = g_value_get_uint (value); break; case PROP_FADE_IN_TIME: self->fade_in_time = g_value_get_uint (value); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; } } static void fbd_feedback_vibra_periodic_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec) { FbdFeedbackVibraPeriodic *self = FBD_FEEDBACK_VIBRA_PERIODIC (object); switch (property_id) { case PROP_MAGNITUDE: g_value_set_uint (value, self->magnitude); break; case PROP_FADE_IN_LEVEL: g_value_set_uint (value, self->fade_in_level); break; case PROP_FADE_IN_TIME: g_value_set_uint (value, self->fade_in_time); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; } } static void fbd_feedback_vibra_periodic_end_vibra (FbdFeedbackVibra *vibra) { FbdFeedbackManager *manager = fbd_feedback_manager_get_default (); FbdDevVibra *dev = fbd_feedback_manager_get_dev_vibra (manager); fbd_dev_vibra_stop (dev); } static void fbd_feedback_vibra_periodic_start_vibra (FbdFeedbackVibra *vibra) { FbdFeedbackVibraPeriodic *self = FBD_FEEDBACK_VIBRA_PERIODIC (vibra); FbdFeedbackManager *manager = fbd_feedback_manager_get_default (); FbdDevVibra *dev = fbd_feedback_manager_get_dev_vibra (manager); guint duration = fbd_feedback_vibra_get_duration (vibra); g_return_if_fail (FBD_IS_DEV_VIBRA (dev)); g_debug ("Periodic Vibra: %d %d %d %d", duration, self->magnitude, self->fade_in_level, self->fade_in_time); fbd_dev_vibra_periodic (dev, duration, self->magnitude, self->fade_in_level, self->fade_in_time); } static gboolean fbd_feedback_vibra_periodic_is_available (FbdFeedbackBase *base) { FbdFeedbackManager *manager = fbd_feedback_manager_get_default (); FbdDevVibra *dev = fbd_feedback_manager_get_dev_vibra (manager); return FBD_IS_DEV_VIBRA (dev); } static void fbd_feedback_vibra_periodic_class_init (FbdFeedbackVibraPeriodicClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); FbdFeedbackBaseClass *base_class = FBD_FEEDBACK_BASE_CLASS (klass); FbdFeedbackVibraClass *vibra_class = FBD_FEEDBACK_VIBRA_CLASS (klass); object_class->set_property = fbd_feedback_vibra_periodic_set_property; object_class->get_property = fbd_feedback_vibra_periodic_get_property; base_class->is_available = fbd_feedback_vibra_periodic_is_available; vibra_class->start_vibra = fbd_feedback_vibra_periodic_start_vibra; vibra_class->end_vibra = fbd_feedback_vibra_periodic_end_vibra; props[PROP_MAGNITUDE] = g_param_spec_uint ( "magnitude", "Magnitude", "total magnitude", 0, 0xFFFF, 0x7FFF, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); props[PROP_FADE_IN_TIME] = g_param_spec_uint ( "fade-in-time", "Fade in time", "Fade in time until full strength", 0, G_MAXINT, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); props[PROP_FADE_IN_LEVEL] = g_param_spec_uint ( "fade-in-level", "Fade in level", "Fade in start level", 0, 0xFFFF, 0x7FFF, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); g_object_class_install_properties (object_class, PROP_LAST_PROP, props); } static void fbd_feedback_vibra_periodic_init (FbdFeedbackVibraPeriodic *self) { } 07070100000064000081A400000000000000000000000164F062AA0000017C000000000000000000000000000000000000003200000000feedbackd-0.2.1/src/fbd-feedback-vibra-periodic.h/* * Copyright (C) 2020 Purism SPC * * SPDX-License-Identifier: GPL-3.0+ */ #pragma once #include "fbd-feedback-vibra.h" G_BEGIN_DECLS #define FBD_TYPE_FEEDBACK_VIBRA_PERIODIC (fbd_feedback_vibra_periodic_get_type()) G_DECLARE_FINAL_TYPE (FbdFeedbackVibraPeriodic, fbd_feedback_vibra_periodic, FBD, FEEDBACK_VIBRA_PERIODIC, FbdFeedbackVibra); G_END_DECLS 07070100000065000081A400000000000000000000000164F062AA000014A0000000000000000000000000000000000000003000000000feedbackd-0.2.1/src/fbd-feedback-vibra-rumble.c/* * Copyright (C) 2020 Purism SPC * SPDX-License-Identifier: GPL-3.0+ * Author: Guido Günther <agx@sigxcpu.org> */ #define G_LOG_DOMAIN "fbd-feedback-vibra-rumble" #include "fbd-enums.h" #include "fbd-feedback-vibra-rumble.h" #include "fbd-feedback-manager.h" /** * SECTION:fbd-feedback-vibra * @short_description: Describes a rumble feedback via a haptic motor * @Title: FbdFeedbackVibraRumble * * The #FbdVibraVibraRumble describes the properties of a haptic feedback * event. It knows nothing about the hardware itself but calls * #FbdDevVibra for that. */ enum { PROP_0, PROP_COUNT, PROP_PAUSE, PROP_LAST_PROP, }; static GParamSpec *props[PROP_LAST_PROP]; typedef struct _FbdFeedbackVibraRumble { FbdFeedbackVibra parent; guint count; /* number of rumbles */ guint pause; /* pause in msecs */ guint rumble; /* rumble in msecs */ guint periods; /* number of periods to play */ guint timer_id; } FbdFeedbackVibraRumble; G_DEFINE_TYPE (FbdFeedbackVibraRumble, fbd_feedback_vibra_rumble, FBD_TYPE_FEEDBACK_VIBRA); static void fbd_feedback_vibra_rumble_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) { FbdFeedbackVibraRumble *self = FBD_FEEDBACK_VIBRA_RUMBLE (object); switch (property_id) { case PROP_COUNT: self->count = g_value_get_uint (value); break; case PROP_PAUSE: self->pause = g_value_get_uint (value); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; } } static void fbd_feedback_vibra_rumble_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec) { FbdFeedbackVibraRumble *self = FBD_FEEDBACK_VIBRA_RUMBLE (object); switch (property_id) { case PROP_COUNT: g_value_set_uint (value, self->count); break; case PROP_PAUSE: g_value_set_uint (value, self->pause); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; } } static gboolean on_period_ended (FbdFeedbackVibraRumble *self) { FbdFeedbackManager *manager = fbd_feedback_manager_get_default (); FbdDevVibra *dev = fbd_feedback_manager_get_dev_vibra (manager); g_return_val_if_fail (FBD_IS_FEEDBACK_VIBRA_RUMBLE (self), G_SOURCE_REMOVE); if (self->periods) { fbd_dev_vibra_rumble (dev, self->rumble, FALSE); self->periods--; return G_SOURCE_CONTINUE; } return G_SOURCE_REMOVE; } static void fbd_feedback_vibra_rumble_end_vibra (FbdFeedbackVibra *vibra) { FbdFeedbackVibraRumble *self = FBD_FEEDBACK_VIBRA_RUMBLE (vibra); FbdFeedbackManager *manager = fbd_feedback_manager_get_default (); FbdDevVibra *dev = fbd_feedback_manager_get_dev_vibra (manager); fbd_dev_vibra_stop (dev); g_clear_handle_id(&self->timer_id, g_source_remove); } static void fbd_feedback_vibra_rumble_start_vibra (FbdFeedbackVibra *vibra) { FbdFeedbackVibraRumble *self = FBD_FEEDBACK_VIBRA_RUMBLE (vibra); FbdFeedbackManager *manager = fbd_feedback_manager_get_default (); FbdDevVibra *dev = fbd_feedback_manager_get_dev_vibra (manager); guint duration = fbd_feedback_vibra_get_duration (vibra); guint period; self->rumble = (duration / self->count) - self->pause; if (self->rumble <= 0) { self->rumble = FBD_FEEDBACK_VIBRA_DEFAULT_DURATION; self->pause = 0; self->count = 1; } period = self->rumble + self->pause; self->periods = self->count; g_debug ("Rumble Vibra event: duration %d, rumble: %d, pause: %d, period: %d", duration, self->rumble, self->pause, period); fbd_dev_vibra_rumble (dev, self->rumble, TRUE); self->periods--; if (self->periods) { self->timer_id = g_timeout_add (period, (GSourceFunc) on_period_ended, self); } } static gboolean fbd_feedback_vibra_rumble_is_available (FbdFeedbackBase *base) { FbdFeedbackManager *manager = fbd_feedback_manager_get_default (); FbdDevVibra *dev = fbd_feedback_manager_get_dev_vibra (manager); return FBD_IS_DEV_VIBRA (dev); } static void fbd_feedback_vibra_rumble_class_init (FbdFeedbackVibraRumbleClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); FbdFeedbackBaseClass *base_class = FBD_FEEDBACK_BASE_CLASS (klass); FbdFeedbackVibraClass *vibra_class = FBD_FEEDBACK_VIBRA_CLASS (klass); object_class->set_property = fbd_feedback_vibra_rumble_set_property; object_class->get_property = fbd_feedback_vibra_rumble_get_property; base_class->is_available = fbd_feedback_vibra_rumble_is_available; vibra_class->start_vibra = fbd_feedback_vibra_rumble_start_vibra; vibra_class->end_vibra = fbd_feedback_vibra_rumble_end_vibra; props[PROP_COUNT] = g_param_spec_uint ( "count", "Count", "The number of rumbles", 0, G_MAXINT, 1, G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); props[PROP_PAUSE] = g_param_spec_uint ( "pause", "Pause", "The pause in msecs between rumbles", 0, G_MAXINT, 0, G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); g_object_class_install_properties (object_class, PROP_LAST_PROP, props); } static void fbd_feedback_vibra_rumble_init (FbdFeedbackVibraRumble *self) { self->count = 1; } 07070100000066000081A400000000000000000000000164F062AA00000172000000000000000000000000000000000000003000000000feedbackd-0.2.1/src/fbd-feedback-vibra-rumble.h/* * Copyright (C) 2020 Purism SPC * * SPDX-License-Identifier: GPL-3.0+ */ #pragma once #include "fbd-feedback-vibra.h" G_BEGIN_DECLS #define FBD_TYPE_FEEDBACK_VIBRA_RUMBLE (fbd_feedback_vibra_rumble_get_type()) G_DECLARE_FINAL_TYPE (FbdFeedbackVibraRumble, fbd_feedback_vibra_rumble, FBD, FEEDBACK_VIBRA_RUMBLE, FbdFeedbackVibra); G_END_DECLS 07070100000067000081A400000000000000000000000164F062AA000010BB000000000000000000000000000000000000002900000000feedbackd-0.2.1/src/fbd-feedback-vibra.c/* * Copyright (C) 2020 Purism SPC * SPDX-License-Identifier: GPL-3.0+ * Author: Guido Günther <agx@sigxcpu.org> */ #define G_LOG_DOMAIN "fbd-feedback-vibra" #include "fbd-enums.h" #include "fbd-feedback-vibra.h" #include "fbd-feedback-manager.h" /** * SECTION:fbd-feedback-vibra * @short_description: Describes a feedback via a haptic motor * @Title: FbdFeedbackVibra * * The #FbdVibraVibra describes the properties of a haptic feedback * event. It knows nothing about the hardware itself but calls * #FbdDevVibra for that. */ enum { PROP_0, PROP_DURATION, PROP_LAST_PROP, }; static GParamSpec *props[PROP_LAST_PROP]; typedef struct _FbdFeedbackVibraPrivate { guint duration; guint timer_id; } FbdFeedbackVibraPrivate; G_DEFINE_TYPE_WITH_PRIVATE (FbdFeedbackVibra, fbd_feedback_vibra, FBD_TYPE_FEEDBACK_BASE); static gboolean on_timeout_expired (FbdFeedbackVibra *self) { FbdFeedbackManager *manager = fbd_feedback_manager_get_default (); FbdDevVibra *dev = fbd_feedback_manager_get_dev_vibra (manager); fbd_dev_vibra_remove_effect (dev); fbd_feedback_base_done (FBD_FEEDBACK_BASE(self)); return G_SOURCE_REMOVE; } static void fbd_feedback_vibra_run (FbdFeedbackBase *base) { FbdFeedbackVibra *self = FBD_FEEDBACK_VIBRA (base); FbdFeedbackVibraPrivate *priv = fbd_feedback_vibra_get_instance_private (self); FbdFeedbackVibraClass *klass; klass = FBD_FEEDBACK_VIBRA_GET_CLASS (self); g_return_if_fail (klass->start_vibra); klass->start_vibra (self); priv->timer_id = g_timeout_add (priv->duration, (GSourceFunc)on_timeout_expired, self); g_source_set_name_by_id (priv->timer_id, "feedback-vibra-timer"); } static void fbd_feedback_vibra_end (FbdFeedbackBase *base) { FbdFeedbackVibra *self = FBD_FEEDBACK_VIBRA (base); FbdFeedbackVibraPrivate *priv = fbd_feedback_vibra_get_instance_private (self); FbdFeedbackVibraClass *klass = FBD_FEEDBACK_VIBRA_GET_CLASS (self); if (!priv->timer_id) return; g_return_if_fail (klass->end_vibra); klass->end_vibra(self); g_clear_handle_id(&priv->timer_id, g_source_remove); fbd_feedback_base_done (FBD_FEEDBACK_BASE(self)); } static void fbd_feedback_vibra_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) { FbdFeedbackVibra *self = FBD_FEEDBACK_VIBRA (object); FbdFeedbackVibraPrivate *priv = fbd_feedback_vibra_get_instance_private (self); switch (property_id) { case PROP_DURATION: priv->duration = g_value_get_uint (value); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; } } static void fbd_feedback_vibra_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec) { FbdFeedbackVibra *self = FBD_FEEDBACK_VIBRA (object); FbdFeedbackVibraPrivate *priv = fbd_feedback_vibra_get_instance_private (self); switch (property_id) { case PROP_DURATION: g_value_set_uint (value, priv->duration); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; } } static void fbd_feedback_vibra_class_init (FbdFeedbackVibraClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); FbdFeedbackBaseClass *base_class = FBD_FEEDBACK_BASE_CLASS (klass); object_class->set_property = fbd_feedback_vibra_set_property; object_class->get_property = fbd_feedback_vibra_get_property; base_class->run = fbd_feedback_vibra_run; base_class->end = fbd_feedback_vibra_end; props[PROP_DURATION] = g_param_spec_uint ( "duration", "Duration", "Vibra event duration in msecs", 0, G_MAXUINT, FBD_FEEDBACK_VIBRA_DEFAULT_DURATION, G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); g_object_class_install_properties (object_class, PROP_LAST_PROP, props); } static void fbd_feedback_vibra_init (FbdFeedbackVibra *self) { } guint fbd_feedback_vibra_get_duration (FbdFeedbackVibra *self) { FbdFeedbackVibraPrivate *priv; g_return_val_if_fail (FBD_IS_FEEDBACK_VIBRA (self), 0); priv = fbd_feedback_vibra_get_instance_private (self); return priv->duration; } 07070100000068000081A400000000000000000000000164F062AA0000025D000000000000000000000000000000000000002900000000feedbackd-0.2.1/src/fbd-feedback-vibra.h/* * Copyright (C) 2020 Purism SPC * * SPDX-License-Identifier: GPL-3.0+ */ #pragma once #include "fbd-feedback-base.h" G_BEGIN_DECLS #define FBD_TYPE_FEEDBACK_VIBRA (fbd_feedback_vibra_get_type()) #define FBD_FEEDBACK_VIBRA_DEFAULT_DURATION 1000 G_DECLARE_DERIVABLE_TYPE (FbdFeedbackVibra, fbd_feedback_vibra, FBD, FEEDBACK_VIBRA, FbdFeedbackBase); struct _FbdFeedbackVibraClass { FbdFeedbackBaseClass parent_class; void (*start_vibra) (FbdFeedbackVibra *self); void (*end_vibra) (FbdFeedbackVibra *self); }; guint fbd_feedback_vibra_get_duration (FbdFeedbackVibra *self); G_END_DECLS 07070100000069000081A400000000000000000000000164F062AA000013D2000000000000000000000000000000000000002200000000feedbackd-0.2.1/src/fbd-ledctrl.c/* * Copyright (C) 2020 Purism SPC * SPDX-License-Identifier: GPL-3.0+ * Author: Guido Günther <agx@sigxcpu.org> */ #define G_LOG_DOMAIN "fbd-ledctrl" #include <glib.h> #include <errno.h> #include <fcntl.h> #include <grp.h> #include <stdio.h> #include <sys/stat.h> #include <sys/types.h> #include <unistd.h> #define LED_BRIGHTNESS_ATTR "brightness" #define LED_MULTI_INTENSITY_ATTR "multi_intensity" #define LED_PATTERN_ATTR "pattern" #define LED_REPEAT_ATTR "repeat" #define LED_TRIGGER_ATTR "trigger" #define LED_TRIGGER_PATTERN "pattern" enum { FBD_LEDCTRL_ERR_CMDLINE = 1, FBD_LEDCTRL_ERR_TRIGGER = 2, FBD_LEDCTRL_ERR_PERMS = 3, }; static gboolean write_sysfs_attr (const char *sysfs_path, const char *attr, const char *val) { gint fd; int len; g_autofree gchar *path = g_strjoin ("/", sysfs_path, attr, NULL); fd = open (path, O_WRONLY|O_TRUNC, 0666); if (fd < 0) { fprintf (stderr, "Failed to open %s: %s\n", path, strerror (errno)); return FALSE; } len = strlen (val); if (write (fd, val, len) < 0) { fprintf (stderr, "Failed to write %s to %s: %s\n", val, path, strerror (errno)); close (fd); return FALSE; } if (close (fd) < 0) { fprintf (stderr, "Failed to close %s: %s\n", path, strerror (errno)); return FALSE; } return TRUE; } static gchar * read_sysfs_attr (const char *sysfs_path, const char *attr) { gchar *content = NULL; g_autoptr (GError) err = NULL; g_autofree gchar *path = g_strjoin ("/", sysfs_path, attr, NULL); if (!g_file_get_contents (path, &content, NULL, &err)) { fprintf (stderr, "Failed to read %s: %s\n", path, err->message); return NULL; } return content; } static gboolean set_sysfs_attr_perm (const char *sysfs_path, const char *attr, gid_t gid) { g_autofree gchar *path = g_strjoin ("/", sysfs_path, attr, NULL); if (chown(path, -1, gid) < 0) { fprintf (stderr, "Failed to set perms of %s to %d: %s\n", path, gid, strerror (errno)); return FALSE; } if (chmod(path, 0664) < 0) { fprintf (stderr, "Failed to set mode of %s: %s\n", path, strerror (errno)); return FALSE; } return TRUE; } static gboolean set_trigger (const char *sysfs_path, const char *trigger) { g_autofree gchar *val = NULL; g_auto(GStrv) triggers = NULL; /* * Check the current trigger, don't do anything if it's already * set. This prevents a change event storm when setting the * same trigger over and over again in a udev rule. */ val = read_sysfs_attr (sysfs_path, LED_TRIGGER_ATTR); g_strstrip(val); triggers = g_strsplit (val, " ", 0); /* * The active trigger is marked with [...] so if we don't find the * trigger verbatim it's already the active one: */ if (!g_strv_contains ((const gchar * const *)triggers, trigger)) return TRUE; return write_sysfs_attr (sysfs_path, LED_TRIGGER_ATTR, trigger); } static gboolean set_perms (const char *sysfs_path, const char *trigger, const char *gname) { struct group *group; gboolean success = TRUE; group = getgrnam (gname); if (!set_sysfs_attr_perm (sysfs_path, LED_BRIGHTNESS_ATTR, group->gr_gid)) return FALSE; // Attribute is optional set_sysfs_attr_perm (sysfs_path, LED_MULTI_INTENSITY_ATTR, group->gr_gid); if (!g_strcmp0 (trigger, LED_TRIGGER_PATTERN)) { if (!set_sysfs_attr_perm (sysfs_path, LED_PATTERN_ATTR, group->gr_gid)) success = FALSE; if (!set_sysfs_attr_perm (sysfs_path, LED_REPEAT_ATTR, group->gr_gid)) success = FALSE; } /* specific setup for other triggers goes here */ return success; } int main(int argc, char *argv[]) { g_autoptr(GError) err = NULL; g_autoptr(GOptionContext) opt_context = NULL; g_autofree gchar *sysfs_path = NULL; g_autofree gchar *group = NULL; g_autofree gchar *trigger = NULL; const GOptionEntry options [] = { {"path", 'p', 0, G_OPTION_ARG_STRING, &sysfs_path, "Path to LEDs sysfs dir", NULL}, {"group", 'G', 0, G_OPTION_ARG_STRING, &group, "Group to set permissions to", NULL}, {"trigger", 't', 0, G_OPTION_ARG_STRING, &trigger, "LED trigger to configure", NULL}, { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL } }; opt_context = g_option_context_new ("- helper to prepare sysfs for feedbackd"); g_option_context_add_main_entries (opt_context, options, NULL); if (!g_option_context_parse (opt_context, &argc, &argv, &err)) { fprintf (stderr, "%s", err->message); g_clear_error (&err); return 1; } if (!sysfs_path) { fprintf (stderr, "No sysfs path given\n"); return FBD_LEDCTRL_ERR_CMDLINE; } if (!trigger) { fprintf (stderr, "No trigger specified\n"); return FBD_LEDCTRL_ERR_CMDLINE;; } g_debug ("Configuring LED at %s for trigger %s", sysfs_path, trigger); if (!set_trigger (sysfs_path, trigger)) return FBD_LEDCTRL_ERR_TRIGGER; if (group) { g_debug ("Setting permission of %s to %s", sysfs_path, group); if (!set_perms (sysfs_path, trigger, group)) return FBD_LEDCTRL_ERR_PERMS; } return 0; } 0707010000006A000081A400000000000000000000000164F062AA0000321C000000000000000000000000000000000000002900000000feedbackd-0.2.1/src/fbd-theme-expander.c/* * Copyright (C) 2022 Guido Günther * * SPDX-License-Identifier: GPL-3.0+ * * Author: Guido Günther <agx@sigxcpu.org> */ #define G_LOG_DOMAIN "fbd-theme-expander" #include "fbd.h" #include "fbd-feedback-theme.h" #include "fbd-theme-expander.h" #define DEFAULT_THEME_NAME "default" #define DEVICE_THEME_NAME "$device" #define MAX_THEME_DEPTH 10 /** * SECTION:theme-expander * @short_description: Feedback theme expander * @Title: FbdThemeExpander * * The theme expander reads themes from disks and expands references * to other themes */ enum { PROP_0, PROP_THEME_NAME, PROP_THEME_FILE, PROP_COMPATIBLES, PROP_LAST_PROP }; static GParamSpec *props[PROP_LAST_PROP]; struct _FbdThemeExpander { GObject parent; char *theme_name; char *theme_file; gboolean device_theme_loaded; GStrv compatibles; }; G_DEFINE_TYPE (FbdThemeExpander, fbd_theme_expander, G_TYPE_OBJECT) static void fbd_theme_expander_set_compatibles (FbdThemeExpander *self, const char * const * compatibles) { g_return_if_fail (FBD_IS_THEME_EXPANDER (self)); g_strfreev (self->compatibles); self->compatibles = g_strdupv ((GStrv)compatibles); /* Make sure we reload the device theme */ self->device_theme_loaded = FALSE; } static void fbd_theme_expander_set_theme_name (FbdThemeExpander *self, const char *theme_name) { g_return_if_fail (FBD_IS_THEME_EXPANDER (self)); g_free (self->theme_name); if (theme_name) self->theme_name = g_strdup (theme_name); else self->theme_name = g_strdup (DEFAULT_THEME_NAME); /* Make sure we reload the device theme */ self->device_theme_loaded = FALSE; } static void fbd_theme_expander_set_theme_file (FbdThemeExpander *self, const char *theme_file) { g_return_if_fail (FBD_IS_THEME_EXPANDER (self)); g_free (self->theme_file); self->theme_file = g_strdup (theme_file); /* Make sure we reload the device theme */ self->device_theme_loaded = FALSE; } static char * fbd_theme_expander_find_theme_in_xdg_data (const char *theme_name) { const char * const *xdg_data_dirs = g_get_system_data_dirs (); g_autofree char *theme_file_name = g_strconcat (theme_name, ".json", NULL); for (int i = 0; xdg_data_dirs[i] != NULL; i++) { g_autofree char *theme_path = NULL; theme_path = g_build_filename (xdg_data_dirs[i], "feedbackd", "themes", theme_file_name, NULL); g_debug ("Looking for theme file at %s", theme_path); /* Check if file exist */ if (g_file_test (theme_path, (G_FILE_TEST_EXISTS))) { g_info ("Loading theme file at '%s'", theme_path); return g_steal_pointer (&theme_path); } } return NULL; } static char * fbd_theme_expander_find_device_theme_path (FbdThemeExpander *self, const char *theme_name) { /* Device specific lookup only for default theme */ if (g_str_equal (theme_name, DEVICE_THEME_NAME) == FALSE && g_str_equal (theme_name, DEFAULT_THEME_NAME) == FALSE) { return NULL; } if (self->device_theme_loaded) return NULL; self->device_theme_loaded = TRUE; /* no compatibles found */ if (self->compatibles == NULL) return NULL; for (int i = 0; i < g_strv_length (self->compatibles); i++) { const char *compatible = self->compatibles[i]; g_autofree char *theme_path = NULL; theme_path = fbd_theme_expander_find_theme_in_xdg_data (compatible); if (theme_path) { g_debug ("Loading themefile for compatible '%s' at: %s", compatible, theme_path); return g_steal_pointer (&theme_path); } } g_debug ("No device theme found"); return NULL; } static char * fbd_theme_expander_find_user_theme_path (const char *theme_name) { g_autofree char *filename = g_strdup_printf ("%s.json", theme_name); g_autofree char *user_config_path = NULL; user_config_path = g_build_filename (g_get_user_config_dir (), "feedbackd", "themes", filename, NULL); if (g_file_test (user_config_path, (G_FILE_TEST_EXISTS))) { g_info ("Found theme file at: %s", user_config_path); return g_steal_pointer (&user_config_path); } g_debug ("No user theme found for '%s'", theme_name); return NULL; } static char * fbd_theme_expander_find_theme_path (FbdThemeExpander *self, const char *theme_name) { g_autofree char *file_name = NULL; char *theme_path; g_assert (theme_name); theme_path = fbd_theme_expander_find_user_theme_path (theme_name); if (theme_path) return theme_path; theme_path = fbd_theme_expander_find_device_theme_path (self, theme_name); if (theme_path) return theme_path; if (g_str_equal (theme_name, DEFAULT_THEME_NAME) == FALSE) g_critical ("Theme '%s' not found, falling back to default theme", theme_name); theme_path = fbd_theme_expander_find_theme_in_xdg_data (DEFAULT_THEME_NAME); if (theme_path) return theme_path; /* Last resort is shipped default config */ file_name = g_strdup_printf ("%s.json", theme_name); g_info ("Using theme_file: %s", file_name); return g_build_filename (FEEDBACKD_THEME_DIR, file_name, NULL); } static void fbd_theme_expander_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) { FbdThemeExpander *self = FBD_THEME_EXPANDER (object); switch (property_id) { case PROP_THEME_NAME: fbd_theme_expander_set_theme_name (self, g_value_get_string (value)); break; case PROP_THEME_FILE: fbd_theme_expander_set_theme_file (self, g_value_get_string (value)); break; case PROP_COMPATIBLES: fbd_theme_expander_set_compatibles (self, g_value_get_boxed (value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; } } static void fbd_theme_expander_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec) { FbdThemeExpander *self = FBD_THEME_EXPANDER (object); switch (property_id) { case PROP_THEME_NAME: g_value_set_string (value, fbd_theme_expander_get_theme_name (self)); break; case PROP_THEME_FILE: g_value_set_string (value, fbd_theme_expander_get_theme_file (self)); break; case PROP_COMPATIBLES: g_value_set_boxed (value, fbd_theme_expander_get_compatibles (self)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; } } static void fbd_theme_expander_finalize (GObject *object) { FbdThemeExpander *self = FBD_THEME_EXPANDER(object); g_clear_pointer (&self->theme_name, g_free); g_clear_pointer (&self->theme_file, g_free); g_clear_pointer (&self->compatibles, g_strfreev); G_OBJECT_CLASS (fbd_theme_expander_parent_class)->finalize (object); } static void fbd_theme_expander_class_init (FbdThemeExpanderClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->get_property = fbd_theme_expander_get_property; object_class->set_property = fbd_theme_expander_set_property; object_class->finalize = fbd_theme_expander_finalize; /** * FbdThemeExpander:theme-name: * * Specifies the theme to expand. Assumes `default` if unset. * * The `compatibles` defines which device specific theme bits are loaded. */ props[PROP_THEME_NAME] = g_param_spec_string ("theme-name", "", "", DEFAULT_THEME_NAME, G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS); /** * FbdThemeExpander:theme-file: * * Specifies the theme-file to load an expand. Takes preference over `theme`. */ props[PROP_THEME_FILE] = g_param_spec_string ("theme-file", "", "", NULL, G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS); /** * FbdThemeExpander:compatibles: * * Specifies the device types this device is compatible with. The * device compatbiles to look for. When unset the value is retrieved * from /sysfs. * * The `compatibles` defines which device specific theme bits are loaded. */ props[PROP_COMPATIBLES] = g_param_spec_boxed ("compatibles", "", "", G_TYPE_STRV, G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); g_object_class_install_properties (object_class, PROP_LAST_PROP, props); } static void fbd_theme_expander_init (FbdThemeExpander *self) { } FbdThemeExpander * fbd_theme_expander_new (const char * const *compatibles, const char *theme_name, const char *theme_file) { return FBD_THEME_EXPANDER (g_object_new (FBD_TYPE_THEME_EXPANDER, "theme-name", theme_name, "theme-file", theme_file, "compatibles", compatibles, NULL)); } static void update_theme (gpointer data, gpointer user_data) { FbdFeedbackTheme *theme = FBD_FEEDBACK_THEME (data); FbdFeedbackTheme *merged = FBD_FEEDBACK_THEME (user_data); g_assert (FBD_IS_FEEDBACK_THEME (theme)); g_assert (FBD_IS_FEEDBACK_THEME (merged)); fbd_feedback_theme_update (merged, theme); } /** * fbd_theme_expander_load_theme_files: * @self: The theme expander * @err: return location for error or %NULL * * Parses a theme recursively taking the theme's `parent-name` relations into * account as well as the expander's list of `compatibles`. * * Returns: (transfer full)(allow-none): The parsed theme or %NULL on error */ FbdFeedbackTheme * fbd_theme_expander_load_theme_files (FbdThemeExpander *self, GError **err) { g_autoqueue (FbdFeedbackTheme) queue = g_queue_new (); g_autoptr (FbdFeedbackTheme) merged = fbd_feedback_theme_new ("merged-theme"); g_autoptr (FbdFeedbackTheme) theme = NULL; g_autofree char *theme_file = NULL; guint len = 0; g_return_val_if_fail (FBD_IS_THEME_EXPANDER (self), NULL); g_return_val_if_fail (err == NULL || *err == NULL, NULL); if (self->theme_file) { theme_file = g_strdup (self->theme_file); } else { theme_file = fbd_theme_expander_find_theme_path (self, self->theme_name); if (g_strcmp0 (self->theme_file, theme_file)) { self->theme_file = g_steal_pointer (&theme_file); g_object_notify_by_pspec (G_OBJECT (self), props[PROP_THEME_FILE]); } } g_info ("Loading theme file at '%s'", self->theme_file); theme = fbd_feedback_theme_new_from_file (self->theme_file, err); if (theme == NULL) return NULL; /* Build a list of themes */ while (TRUE) { g_autofree char *parent_path = NULL; const char *parent_name, *theme_name; if (len > MAX_THEME_DEPTH) { g_set_error (err, fbd_error_quark(), FBD_ERROR_THEME_EXPAND, "Theme depth exceeded"); return NULL; } theme_name = fbd_feedback_theme_get_name (theme); if (theme_name == NULL || theme_name[0] == '\0') { g_set_error (err, fbd_error_quark(), FBD_ERROR_THEME_EXPAND, "Theme name of %s can't be empty", self->theme_file); return NULL; } parent_name = fbd_feedback_theme_get_parent_name (theme); if (parent_name && g_str_equal (fbd_feedback_theme_get_name (theme), DEFAULT_THEME_NAME)) { g_set_error (err, fbd_error_quark(), FBD_ERROR_THEME_EXPAND, "Default theme can't specify a parent"); return NULL; } parent_name = fbd_feedback_theme_get_parent_name (theme); g_queue_push_head (queue, g_steal_pointer (&theme)); if (parent_name == NULL) break; parent_path = fbd_theme_expander_find_theme_path (self, parent_name); theme = fbd_feedback_theme_new_from_file (parent_path, err); if (theme == NULL) return NULL; len++; } /* Merge themes bottom to top */ g_queue_foreach (queue, update_theme, merged); fbd_feedback_theme_set_name (merged, self->theme_name); return g_steal_pointer (&merged); } const char * fbd_theme_expander_get_theme_name (FbdThemeExpander *self) { g_return_val_if_fail (FBD_IS_THEME_EXPANDER (self), NULL); return self->theme_name; } const char * fbd_theme_expander_get_theme_file (FbdThemeExpander *self) { g_return_val_if_fail (FBD_IS_THEME_EXPANDER (self), NULL); return self->theme_file; } const char * const * fbd_theme_expander_get_compatibles (FbdThemeExpander *self) { g_return_val_if_fail (FBD_IS_THEME_EXPANDER (self), NULL); return (const char * const*)self->compatibles; } 0707010000006B000081A400000000000000000000000164F062AA000003FA000000000000000000000000000000000000002900000000feedbackd-0.2.1/src/fbd-theme-expander.h/* * Copyright (C) 2022 Guido Günther * * SPDX-License-Identifier: GPL-3.0-or-later * * Author: Guido Günther <agx@sigxcpu.org> */ #pragma once #include "fbd-feedback-theme.h" #include <glib-object.h> G_BEGIN_DECLS #define FBD_TYPE_THEME_EXPANDER (fbd_theme_expander_get_type ()) G_DECLARE_FINAL_TYPE (FbdThemeExpander, fbd_theme_expander, FBD, THEME_EXPANDER, GObject) FbdThemeExpander *fbd_theme_expander_new (const char * const *compatibles, const char *theme_name, const char *theme_file); FbdFeedbackTheme *fbd_theme_expander_load_theme_files (FbdThemeExpander *self, GError **err); const char *fbd_theme_expander_get_theme_name (FbdThemeExpander *self); const char *fbd_theme_expander_get_theme_file (FbdThemeExpander *self); const char * const *fbd_theme_expander_get_compatibles (FbdThemeExpander *self); G_END_DECLS 0707010000006C000081A400000000000000000000000164F062AA0000091E000000000000000000000000000000000000002900000000feedbackd-0.2.1/src/fbd-theme-validate.c/* * Copyright (C) 2022 Guido Günther * * SPDX-License-Identifier: GPL-3.0+ */ #define G_LOG_DOMAIN "fbd" #include "fbd-theme-expander.h" #include <gio/gio.h> #define BLURP "- A validator for feedback themes" static void print_version (void) { g_print ("%s %s " BLURP "\n", g_get_prgname(), FBD_VERSION); exit (0); } static void log_handler (const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, gpointer user_data) { g_print ("%s\n", message); } int main(int argc, char *argv[]) { g_autoptr (GError) err = NULL; g_autoptr (GOptionContext) opt_context = NULL; g_autoptr (FbdThemeExpander) expander = NULL; g_autoptr (FbdFeedbackTheme) theme = NULL; g_autofree char *theme_file = NULL; const char *compatible = NULL; gboolean version = FALSE; GStrv args = NULL; const char *compatibles[] = { NULL, NULL }; int ret = EXIT_FAILURE; const GOptionEntry options [] = { {"version", 0, 0, G_OPTION_ARG_NONE, &version, "Show version information", NULL}, {"compatible", 0, 0, G_OPTION_ARG_STRING, &compatible, "The device compatible", NULL}, { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &args, NULL, NULL }, G_OPTION_ENTRY_NULL, }; opt_context = g_option_context_new ("THEME-FILE " BLURP); g_option_context_add_main_entries (opt_context, options, NULL); if (!g_option_context_parse (opt_context, &argc, &argv, &err)) { g_warning ("%s", err->message); g_clear_error (&err); return 1; } if (version) { print_version (); } g_log_set_handler ("fbd-theme-expander", G_LOG_LEVEL_INFO | G_LOG_FLAG_RECURSION, log_handler, NULL); if (!args) { g_printerr ("%s: No theme file given\n", g_get_prgname ()); g_printerr ("Try \"%s --help\" for more information.", g_get_prgname ()); g_printerr ("\n"); return 1; } compatibles[0] = compatible; theme_file = *args; expander = fbd_theme_expander_new (compatibles, NULL, theme_file); theme = fbd_theme_expander_load_theme_files (expander, &err); if (theme == NULL) { g_printerr ("Validation of '%s' failed \n\n", theme_file); g_printerr ("error: %s\n\n", err->message); } else { g_print ("Validation successful.\n"); ret = EXIT_SUCCESS; } return ret; } 0707010000006D000081A400000000000000000000000164F062AA0000087F000000000000000000000000000000000000001F00000000feedbackd-0.2.1/src/fbd-udev.c/* * Copyright (C) 2020 Purism SPC * SPDX-License-Identifier: GPL-3.0+ * Author: Guido Günther <agx@sigxcpu.org> * */ #define G_LOG_DOMAIN "fbd-udev" #include "fbd-udev.h" #include <gio/gio.h> #include <sys/types.h> #include <sys/stat.h> #include <errno.h> #include <fcntl.h> gboolean fbd_udev_set_sysfs_path_attr_as_string (GUdevDevice *dev, const gchar *attr, const gchar *s, GError **err) { gint fd; int len; g_autofree gchar *path = g_strjoin ("/", g_udev_device_get_sysfs_path (dev), attr, NULL); fd = open (path, O_WRONLY|O_TRUNC, 0666); if (fd < 0) { g_set_error (err, G_IO_ERROR, G_IO_ERROR_FAILED, "Failed to open %s: %s", path, strerror (errno)); return FALSE; } len = strlen (s); if (write (fd, s, len) < 0) { g_set_error (err, G_IO_ERROR, G_IO_ERROR_FAILED, "Failed to write %s to %s: %s", s, path, strerror (errno)); close (fd); return FALSE; } if (close (fd) < 0) { g_set_error (err, G_IO_ERROR, G_IO_ERROR_FAILED, "Failed to close %s: %s", path, strerror (errno)); return FALSE; } return TRUE; } gboolean fbd_udev_set_sysfs_path_attr_as_int (GUdevDevice *dev, const gchar *attr, gint val, GError **err) { gint fd; int len; g_autofree gchar *s = NULL; g_autofree gchar *path = g_strjoin ("/", g_udev_device_get_sysfs_path (dev), attr, NULL); fd = open (path, O_WRONLY|O_TRUNC, 0666); if (fd < 0) { g_set_error (err, G_IO_ERROR, G_IO_ERROR_FAILED, "Failed to open %s: %s", path, strerror (errno)); return FALSE; } s = g_strdup_printf ("%d", val); len = strlen (s); if (write (fd, s, len) < len) { g_set_error (err, G_IO_ERROR, G_IO_ERROR_FAILED, "Failed to write %s: %s", path, strerror (errno)); close (fd); return FALSE; } if (close (fd) < 0) { g_set_error (err, G_IO_ERROR, G_IO_ERROR_FAILED, "Failed to close %s: %s", path, strerror (errno)); return FALSE; } return TRUE; } 0707010000006E000081A400000000000000000000000164F062AA0000019A000000000000000000000000000000000000001F00000000feedbackd-0.2.1/src/fbd-udev.h/* * Copyright (C) 2020 Purism SPC * * SPDX-License-Identifier: GPL-3.0+ */ #pragma once #include <glib.h> #include <gudev/gudev.h> G_BEGIN_DECLS gboolean fbd_udev_set_sysfs_path_attr_as_string (GUdevDevice *dev, const gchar *attr, const gchar *s, GError **err); gboolean fbd_udev_set_sysfs_path_attr_as_int (GUdevDevice *dev, const gchar *attr, gint val, GError **err); G_END_DECLS 0707010000006F000081A400000000000000000000000164F062AA00000BCF000000000000000000000000000000000000001A00000000feedbackd-0.2.1/src/fbd.c/* * Copyright (C) 2020 Purism SPC * SPDX-License-Identifier: GPL-3.0+ * Author: Guido Günther <agx@sigxcpu.org> */ #define G_LOG_DOMAIN "fbd" #include "fbd.h" #include "fbd-feedback-manager.h" #include "lfb-names.h" #include "lfb-gdbus.h" #include <gio/gio.h> #include <glib-unix.h> static GMainLoop *loop; static gboolean quit_cb (gpointer user_data) { g_info ("Caught signal, shutting down..."); if (loop) g_idle_add ((GSourceFunc) g_main_loop_quit, loop); else exit (0); return FALSE; } static gboolean reload_cb (gpointer user_data) { FbdFeedbackManager *manager = fbd_feedback_manager_get_default(); g_return_val_if_fail (FBD_IS_FEEDBACK_MANAGER (manager), FALSE); g_debug ("Caught signal, reloading feedback theme..."); fbd_feedback_manager_load_theme (manager); return TRUE; } static void bus_acquired_cb (GDBusConnection *connection, const gchar *name, gpointer user_data) { FbdFeedbackManager *manager = fbd_feedback_manager_get_default (); g_debug ("Bus acquired, creating manager..."); g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (manager), connection, FB_DBUS_PATH, NULL); } static void name_acquired_cb (GDBusConnection *connection, const gchar *name, gpointer user_data) { g_debug ("Service name '%s' was acquired", name); } static void name_lost_cb (GDBusConnection *connection, const gchar *name, gpointer user_data) { /* Note that we're not allowing replacement, so once the name acquired, the * process won't lose it. */ if (!name) { g_warning ("Could not get the session bus. Make sure " "the message bus daemon is running!"); } else { if (connection) g_warning ("Could not acquire the '%s' service name", name); else g_debug ("DBus connection close"); } g_main_loop_quit (loop); } int main(int argc, char *argv[]) { g_autoptr(GError) err = NULL; g_autoptr(GOptionContext) opt_context = NULL; g_autoptr (FbdFeedbackManager) manager = NULL; opt_context = g_option_context_new ("- A daemon to trigger event feedback"); if (!g_option_context_parse (opt_context, &argc, &argv, &err)) { g_warning ("%s", err->message); g_clear_error (&err); return 1; } manager = fbd_feedback_manager_get_default (); fbd_feedback_manager_load_theme (manager); g_unix_signal_add (SIGTERM, quit_cb, NULL); g_unix_signal_add (SIGINT, quit_cb, NULL); g_unix_signal_add (SIGHUP, reload_cb, NULL); loop = g_main_loop_new (NULL, FALSE); g_bus_own_name (FB_DBUS_TYPE, FB_DBUS_NAME, G_BUS_NAME_OWNER_FLAGS_NONE, bus_acquired_cb, name_acquired_cb, name_lost_cb, NULL, NULL); g_main_loop_run (loop); g_main_loop_unref (loop); } 07070100000070000081A400000000000000000000000164F062AA0000016C000000000000000000000000000000000000001A00000000feedbackd-0.2.1/src/fbd.h#pragma once #include <glib-object.h> G_BEGIN_DECLS /* * The udev attribute and values devices must have to be handled by * fbd feedbackd */ #define FEEDBACKD_UDEV_ATTR "FEEDBACKD_TYPE" #define FEEDBACKD_UDEV_VAL_LED "led" typedef enum { FBD_ERROR_FAILED = 0, FBD_ERROR_THEME_EXPAND = 1, } FbdError; GQuark fbd_error_quark (void); G_END_DECLS 07070100000071000081A400000000000000000000000164F062AA000006C4000000000000000000000000000000000000002000000000feedbackd-0.2.1/src/meson.build# Feedback daemon if get_option('daemon') fbd_enum_headers = files([ 'fbd-event.h', 'fbd-feedback-led.h', 'fbd-feedback-vibra.h', ]) fbd_enum_sources = gnome.mkenums_simple('fbd-enums', sources : fbd_enum_headers) sources = [ generated_dbus_sources, fbd_enum_sources, 'fbd-error.c', 'fbd-dev-vibra.c', 'fbd-dev-sound.c', 'fbd-dev-led.c', 'fbd-dev-led-multicolor.c', 'fbd-dev-leds.c', 'fbd-event.c', 'fbd-feedback-base.c', 'fbd-feedback-dummy.c', 'fbd-feedback-led.c', 'fbd-feedback-manager.c', 'fbd-feedback-profile.c', 'fbd-feedback-sound.c', 'fbd-feedback-theme.c', 'fbd-feedback-vibra.c', 'fbd-feedback-vibra-periodic.c', 'fbd-feedback-vibra-rumble.c', 'fbd-theme-expander.c', 'fbd-udev.c', ] fbd_deps = [ gio, gio_unix, glib, gmobile, gobject, gsound, gudev, json_glib, ] fbd_inc = [ include_directories('.'), libfeedback_inc, dbus_inc, ] fbd_lib = static_library( 'fbd', sources, include_directories : fbd_inc, dependencies : fbd_deps, install : false, ) fbd_dep = declare_dependency( sources: generated_dbus_sources, include_directories : fbd_inc, link_with : fbd_lib, dependencies : fbd_deps, ) executable( 'feedbackd', sources : ['fbd.c', generated_dbus_sources[1]], include_directories : fbd_inc, dependencies : fbd_dep, install : true, install_dir: libexecdir, ) executable( 'fbd-ledctrl', sources : ['fbd-ledctrl.c'], include_directories : fbd_inc, dependencies : [glib], install : true, install_dir: libexecdir, ) executable( 'fbd-theme-validate', sources : ['fbd-theme-validate.c'], include_directories : fbd_inc, dependencies : fbd_dep, install : true, install_dir: bindir, ) endif 07070100000072000041ED00000000000000000000000264F062AA00000000000000000000000000000000000000000000001C00000000feedbackd-0.2.1/subprojects07070100000073000041ED00000000000000000000000264F062AA00000000000000000000000000000000000000000000002400000000feedbackd-0.2.1/subprojects/gmobile07070100000074000081A400000000000000000000000164F062AA000001B7000000000000000000000000000000000000003300000000feedbackd-0.2.1/subprojects/gmobile/.dir-locals.el( (c-mode . ( (c-file-style . "linux") (indent-tabs-mode . nil) (c-basic-offset . 2) )) (setq auto-mode-alist (cons '("\\.ui$" . nxml-mode) auto-mode-alist)) (nxml-mode . ( (indent-tabs-mode . nil) )) (css-mode . ( (css-indent-offset . 2) )) (js-mode . ( (indent-tabs-mode . nil) (js-indent-level . 2) )) ) 07070100000075000081A400000000000000000000000164F062AA00000188000000000000000000000000000000000000003200000000feedbackd-0.2.1/subprojects/gmobile/.editorconfigroot = true [*] charset = utf-8 end_of_line = lf insert_final_newline = true trim_trailing_whitespace = true [meson.build] indent_size = 2 tab_size = 2 indent_style = space [*.{c,h,c.in,h.in}] indent_size = 2 tab_size = 2 indent_style = space max_line_length = 100 [*.css] indent_size = 2 tab_size = 2 indent_style = space [*.{xml,ui}] indent_size = 2 tab_size = 2 indent_style = space 07070100000076000081A400000000000000000000000164F062AA00000673000000000000000000000000000000000000003300000000feedbackd-0.2.1/subprojects/gmobile/.gitlab-ci.ymlstages: - build - tests - deploy variables: DIST: bookworm DEPS: >- ccache build-essential libglib2.0-dev libjson-glib-dev meson python3-toml python3-jinja2 python3-typogrify libgirepository1.0-dev git gi-docgen gcovr before_script: - echo "man-db man-db/auto-update boolean false" | debconf-set-selections - export DEBIAN_FRONTEND=noninteractive - apt-get -y update - apt-get -y install eatmydata - eatmydata apt-get -y install $DEPS # Make sure that gcovr is used by removing lcov - eatmydata dpkg --remove lcov .build: &build_steps echo "BUILD_OPTS=${BUILD_OPTS}" && export LC_ALL=C.UTF-8 && meson ${BUILD_OPTS} . _build && ninja -C _build build-debian-gcc: image: debian:bookworm stage: build variables: BUILD_OPTS: -Db_coverage=true --werror script: - *build_steps artifacts: when: always paths: - _build # TODO: move to prebuilt container doc: image: debian:bookworm stage: build variables: BUILD_OPTS: >- -Dtests=false -Dgtk_doc=true script: - meson ${BUILD_OPTS} _build - ninja -C _build - mv _build/doc/gmobile-0 _doc/ artifacts: paths: - _doc/ tests: image: debian:bookworm stage: tests variables: needs: ['build-debian-gcc'] script: - meson ${BUILD_OPTS} _build - meson test -C _build - ninja -C _build coverage coverage: '/^lines:\s+([\d.]+\%)\s+/' artifacts: reports: junit: _build/meson-logs/testlog.junit.xml pages: stage: deploy before_script: [] needs: ['doc'] script: - mv _doc/ public/ artifacts: paths: - public only: - main 07070100000077000081A400000000000000000000000164F062AA00000229000000000000000000000000000000000000002900000000feedbackd-0.2.1/subprojects/gmobile/NEWSgmobile 0.0.1 ------------- Released: January 2023 * Initial release (no API guarantees!) * New API: - GmSvgPath: Store SVG path and get it's bounds - GmRect: Simple rectangle - GmCutout: A display cutout or notch - GmDisplayPanel: Describes a display panel - GmDeviceInfo: Retrieve device information * New tools: - gm-display-panel-preview: Generate SVGs and HTML to visualize a device's panel * Added devices: - Librem 5 - OnePlus 6 - OnePlust 6T * API changes: gm_device_tree_get_compatibles -> gm_devicetree_get_compatibles 07070100000078000081A400000000000000000000000164F062AA000003D1000000000000000000000000000000000000002E00000000feedbackd-0.2.1/subprojects/gmobile/README.md# gmobile gmobile carries some helpers for GNOME on mobile devices. Some of those parts might move to glib or libgnome-desktop eventually. It is currently meant to be used as a git submodule by projects. There aren't any API stability guarantees at this point in time. ## License gmobile is licensed under the LGPLv2.1-or-later. ## Getting the source ```sh git clone https://gitlab.gnome.org/guidog/gmobile.git cd gmobile.git ``` The `main` branch has the current development version. ## Dependencies See `meson.build` for required dependencies. ## Building We use the meson (and thereby Ninja) build system for gmobile. The quickest way to get going is to do the following: meson . _build meson compile -C _build # API docs API documentation is available at https://guidog.pages.gitlab.gnome.org/gmobile/ # Getting in Touch * Issue tracker: https://gitlab.gnome.org/guidog/gmobile/-/issues * Matrix: https://im.puri.sm/#/room/#phosh:talk.puri.sm 07070100000079000041ED00000000000000000000000264F062AA00000000000000000000000000000000000000000000002900000000feedbackd-0.2.1/subprojects/gmobile/data0707010000007A000041ED00000000000000000000000264F062AA00000000000000000000000000000000000000000000003100000000feedbackd-0.2.1/subprojects/gmobile/data/devices0707010000007B000041ED00000000000000000000000264F062AA00000000000000000000000000000000000000000000004000000000feedbackd-0.2.1/subprojects/gmobile/data/devices/display-panels0707010000007C000081A400000000000000000000000164F062AA000001B2000000000000000000000000000000000000005700000000feedbackd-0.2.1/subprojects/gmobile/data/devices/display-panels/oneplus,enchilada.json{ "name": "Oneplus 6", "x-res": 1080, "y-res": 2280, "comment": "Device owner, please provide a value:", "border-radius": 30, "width": 68, "height": 145, "cutouts" : [ { "name": "notch", "path": "M 357 0 A 24 24 0 0 1 381 22 A 64 64 0 0 0 445 80 L 635 80 A 64 64 0 0 0 699 22 A 24 24 0 0 1 723 0 Z" } ] } 0707010000007D000081A400000000000000000000000164F062AA00000282000000000000000000000000000000000000005400000000feedbackd-0.2.1/subprojects/gmobile/data/devices/display-panels/oneplus,fajita.json{ "name": "Oneplus 6T", "x-res": 1080, "y-res": 2340, "border-radius": 120, "width": 68, "height": 145, "cutouts" : [ { "name": "notch", "path": "M 355,0 h 368.34 c -9.77,0.44 -19.57,0.08 -29.28,1.24 c -20.33,1.14 -41.18,5.17 -58.62,16.24 c -16.9,10.79 -29.44,26.78 -43.44,40.81 a 72.73,72.73 0 0 1 -38.29 19.58 c -16.53,2.51 -34,1 -49.09,-6.62 c -9.85,-4.62 -17.88,-12.24 -25.21,-20.18 c -10.46,-11.27 -20.9,-22.75 -33.53,-31.66 c -11.49,-8 -24.9,-12.78 -38.53,-15.42 c -17.27,-3.18 -34.86,-3.6 -52.35,-3.99 Z" } ] } 0707010000007E000081A400000000000000000000000164F062AA00000061000000000000000000000000000000000000005400000000feedbackd-0.2.1/subprojects/gmobile/data/devices/display-panels/purism,librem5.json{ "name": "Purism Librem 5", "x-res": 720, "y-res": 1440, "width": 68, "height": 145 } 0707010000007F000081A400000000000000000000000164F062AA000001D0000000000000000000000000000000000000004000000000feedbackd-0.2.1/subprojects/gmobile/data/gmobile.gresources.xml<?xml version="1.0" encoding="UTF-8"?> <gresources> <gresource prefix="/org/gnome/gmobile/"> <!-- Devices with one panel matched by their DT compatible --> <file preprocess="json-stripblanks">devices/display-panels/oneplus,enchilada.json</file> <file preprocess="json-stripblanks">devices/display-panels/oneplus,fajita.json</file> <file preprocess="json-stripblanks">devices/display-panels/purism,librem5.json</file> </gresource> </gresources> 07070100000080000081A400000000000000000000000164F062AA0000008B000000000000000000000000000000000000003500000000feedbackd-0.2.1/subprojects/gmobile/data/meson.buildgm_resources = gnome.compile_resources( 'gm-resources', 'gmobile.gresources.xml', extra_args: '--manual-register', c_name: 'gm', ) 07070100000081000041ED00000000000000000000000264F062AA00000000000000000000000000000000000000000000002800000000feedbackd-0.2.1/subprojects/gmobile/doc07070100000082000081A400000000000000000000000164F062AA00000501000000000000000000000000000000000000003700000000feedbackd-0.2.1/subprojects/gmobile/doc/build-howto.mdTitle: Compiling with gmobile Slug: building # Compiling with gmobile If you need to build gmobile, get the source from [here](https://gitlab.gnome.org/guidog/gmobile/) and see the `README.md` file. ## Bundling the library gmobile is currently not meant to be used as a shared library. It can be bundled in one of two ways: ### As a git submodule To use it as a submodule add the submodule to git ``` git submodule add https://gitlab.gnome.org/guidog/gmobile.git subprojects/gmobile ``` And then add this to your `meson.build`: ```meson gmobile = subproject('gmobile', default_options: [ 'package_name=' + meson.project_name(), 'package_version=' + meson.project_version(), 'pkgdatadir=' + pkgdatadir, 'pkglibdir=' + pkglibdir, 'examples=false', 'gtk_doc=false', 'tests=false', ]) gmobile_dep = gmobile.get_variable('gmobile_dep') ``` ### As a meson subproject To use it as a meson subproject add this to `subprojects/gmobile.wrap`: ```ini [wrap-git] directory=gmobile url=https://gitlab.gnome.org/guidog/gmobile.git revision=main depth=1 ``` You can then use `gmobile_dep` in your mesn build files like: ```meson gmobile = dependency('gmobile', fallback: ['gmobile', 'gmobile_dep'], native: true) ``` 07070100000083000081A400000000000000000000000164F062AA00000353000000000000000000000000000000000000003800000000feedbackd-0.2.1/subprojects/gmobile/doc/gmobile.toml.in[library] version = "@VERSION@" description = "Mobile friendly helpers" authors = "Purism SPC" license = "LGPL-2.1-or-later" browse_url = "https://gitlab.gnome.org/guidog/gmobile/" repository_url = "https://gitlab.gnome.org/guidog/gmobile.git" website_url = "https://gitlab.gnome.org/guidog/gmobile" dependencies = [ "GLib-2.0", ] devhelp = true search_index = true [dependencies."GLib-2.0"] name = "GLib " description = "The base type system library" docs_url = "https://developer.gnome.org/gib/stable" [theme] name = "basic" show_index_summary = true show_class_hierarchy = true [source-location] # The base URL for the web UI base_url = "https://gitlab.gnome.org/guidog/gmobile/-/blob/main/" # The format for links, using "filename" and "line" for the format file_format = "{filename}#L{line}" [extra] content_files = [ "build-howto.md", ] 07070100000084000081A400000000000000000000000164F062AA000003FD000000000000000000000000000000000000003400000000feedbackd-0.2.1/subprojects/gmobile/doc/meson.buildif get_option('gtk_doc') expand_content_md_files = [ 'build-howto.md', ] toml_data = configuration_data() toml_data.set('VERSION', meson.project_version()) gmobile_toml = configure_file( input: 'gmobile.toml.in', output: 'gmobile.toml', configuration: toml_data ) dependency('gi-docgen', version: '>= 2021.1', fallback: ['gi-docgen', 'dummy_dep'], native: true, required: get_option('gtk_doc')) gidocgen = find_program('gi-docgen') docs_dir = datadir / 'doc' custom_target('gmobile-doc', input: [ gmobile_toml, gmobile_gir[0] ], output: 'gmobile-0', command: [ gidocgen, 'generate', '--quiet', '--add-include-path=@0@'.format(meson.current_build_dir() / '../../src'), '--config=@INPUT0@', '--output-dir=@OUTPUT@', '--no-namespace-dir', '--content-dir=@0@'.format(meson.current_source_dir()), '@INPUT1@', ], depend_files: [ expand_content_md_files ], build_by_default: true, install: true, install_dir: docs_dir, ) endif 07070100000085000041ED00000000000000000000000264F062AA00000000000000000000000000000000000000000000002D00000000feedbackd-0.2.1/subprojects/gmobile/examples07070100000086000081A400000000000000000000000164F062AA000015F8000000000000000000000000000000000000004800000000feedbackd-0.2.1/subprojects/gmobile/examples/gm-display-panel-preview.c/* * Copyright (C) 2022 Guido Günther * * SPDX-License-Identifier: GPL-3-or-later */ #define GMOBILE_USE_UNSTABLE_API #include "gmobile.h" #include <gio/gio.h> #include <glib/gprintf.h> static void print_version (void) { g_printf ("gm-display-panel-preview %s\n", GM_VERSION); exit (0); } #define X_OFF 5 #define Y_OFF 5 static char * build_svg (GmDisplayPanel *panel) { GString *svg = g_string_new (""); int xres = gm_display_panel_get_x_res (panel); int yres = gm_display_panel_get_y_res (panel); int radius = gm_display_panel_get_border_radius (panel); GListModel *cutouts; g_string_append_printf (svg, " <svg width=\"%d\" height=\"%d\">\n" " <g transform=\"translate(%d,%d)\">\n" " <!-- The panel -->\n" " <path d=\"M0 %d" " a %d %d 0 0 1 %d %d" " h%d" " a %d %d 0 0 1 %d %d" " v%d" " a %d %d 0 0 1 %d %d" " h%d" " a %d %d 0 0 1 %d %d" " Z \"" " stroke=\"black\" stroke-width=\"2\" fill=\"lightgrey\" />\n", xres + 2 * X_OFF, yres + 2 * Y_OFF, X_OFF, Y_OFF, radius, radius, radius, radius, -radius, xres - 2 * radius, radius, radius, radius, radius, yres - 2 * radius, radius, radius, -radius, radius, -xres + 2 * radius, radius, radius, -radius, -radius); cutouts = gm_display_panel_get_cutouts (panel); for (int i = 0; i < g_list_model_get_n_items (cutouts); i++) { g_autoptr (GmCutout) cutout = g_list_model_get_item (cutouts, i); if (cutout) { const GmRect *bounds = gm_cutout_get_bounds (cutout); const char *name = gm_cutout_get_name (cutout) ?: ""; g_string_append_printf (svg, " <!-- cutout %s -->\n" " <path d=\"%s\" stroke=\"black\" stroke-width=\"2\" fill=\"none\" />\n", name, gm_cutout_get_path (cutout)); g_string_append_printf (svg, " <!-- bbox of cutout %s -->\n" " <rect x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\"" " fill=\"red\" fill-opacity=\"0.1\" />\n", name, bounds->x, bounds->y, bounds->width, bounds->height); } } g_string_append_printf (svg, " </g>\n" " </svg>\n"); return g_string_free (svg, FALSE); } static char * build_html (GmDisplayPanel *panel) { GString *html = g_string_new (""); g_autofree char *svg = NULL; svg = build_svg (panel); g_string_append_printf (html, "<!DOCTYPE html>\n" "<html>\n" " <head>\n" " <title>%s</title>\n" " <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n" " </head>\n" " <body>\n" "%s" " </body>\n" "</html>", gm_display_panel_get_name (panel), svg); return g_string_free (html, FALSE); } int main (int argc, char **argv) { g_autoptr (GOptionContext) opt_context = NULL; gboolean version = FALSE; gboolean svg = FALSE; const char *output_file = NULL; g_autofree char *content = NULL; g_autoptr (GError) err = NULL; g_autoptr (GmDeviceInfo) info = NULL; g_auto (GStrv) compatibles = NULL; GmDisplayPanel *panel = NULL; GStrv compatibles_opt = NULL; const GOptionEntry options [] = { {"compatible", 'c', 0, G_OPTION_ARG_STRING_ARRAY, &compatibles_opt, "Device tree compatibles to use for panel lookup ", NULL}, {"output", 'o', 0, G_OPTION_ARG_STRING, &output_file, "Sleep for that many seconds", NULL}, {"svg", 's', 0, G_OPTION_ARG_NONE, &svg, "Output svg instead of html", NULL}, {"version", 0, 0, G_OPTION_ARG_NONE, &version, "Show version information", NULL}, { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL } }; opt_context = g_option_context_new ("- panel preview"); g_option_context_add_main_entries (opt_context, options, NULL); if (!g_option_context_parse (opt_context, &argc, &argv, &err)) { g_warning ("%s", err->message); g_clear_error (&err); return EXIT_FAILURE; } if (version) print_version (); if (compatibles_opt && compatibles_opt) { compatibles = g_strdupv (compatibles_opt); } else { compatibles = gm_device_tree_get_compatibles (NULL, &err); if (compatibles == NULL) { g_critical ("Failed to get compatibles: %s", err->message); return EXIT_FAILURE; } } info = gm_device_info_new ((const char *const *)compatibles); panel = gm_device_info_get_display_panel (info); if (panel == NULL) { g_critical ("Failed to find any panel"); return EXIT_FAILURE; } if (svg) content = build_svg (panel); else content = build_html (panel); if (output_file) { g_autoptr (GFile) dest = g_file_new_for_path (output_file); if (!g_file_replace_contents (dest, content, strlen (content), NULL, FALSE, G_FILE_CREATE_REPLACE_DESTINATION, NULL, NULL, &err)) { g_critical ("Failed to write html: %s", err->message); return EXIT_FAILURE; } } else { g_printf ("%s", content); } return EXIT_SUCCESS; } 07070100000087000081A400000000000000000000000164F062AA000006FA000000000000000000000000000000000000003A00000000feedbackd-0.2.1/subprojects/gmobile/examples/gm-timeout.c/* * Copyright (C) 2022 Purism SPC * * SPDX-License-Identifier: GPL-3-or-later * * Author: Guido Günther <agx@sigxcpu.org> */ /* Wait for n seconds taking suspend/resume into account */ #define GMOBILE_USE_UNSTABLE_API #include "gmobile.h" #include <glib/gprintf.h> static void print_version (void) { g_printf ("gm-timeout %s - Wait a bit\n", GM_VERSION); exit (0); } static void print_now (void) { g_autoptr (GDateTime) now = g_date_time_new_now_local (); g_message ("Now %.2d:%.2d:%.2d", g_date_time_get_hour (now), g_date_time_get_minute (now), g_date_time_get_second (now)); } static gboolean on_timeout (gpointer data) { g_main_loop_quit (data); g_message ("Exiting main loop"); return G_SOURCE_REMOVE; } int main (int argc, char **argv) { g_autoptr(GOptionContext) opt_context = NULL; g_autoptr (GMainLoop) loop = NULL; g_autoptr (GError) err = NULL; int seconds = 60; gboolean version = FALSE; const GOptionEntry options [] = { {"seconds", 's', 0, G_OPTION_ARG_INT, &seconds, "Sleep for that many seconds", NULL}, {"version", 0, 0, G_OPTION_ARG_NONE, &version, "Show version information", NULL}, { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL } }; opt_context = g_option_context_new ("- Wait a bit"); g_option_context_add_main_entries (opt_context, options, NULL); if (!g_option_context_parse (opt_context, &argc, &argv, &err)) { g_warning ("%s", err->message); g_clear_error (&err); return 1; } if (version) print_version (); loop = g_main_loop_new (NULL, FALSE); g_message ("Arming timer with %d seconds", seconds); gm_timeout_add_seconds_once (seconds, (GSourceFunc)on_timeout, loop); print_now (); g_main_loop_run (loop); print_now (); } 07070100000088000081A400000000000000000000000164F062AA0000012D000000000000000000000000000000000000003900000000feedbackd-0.2.1/subprojects/gmobile/examples/meson.buildif get_option('examples') test_timeout = executable( 'gm-timeout', ['gm-timeout.c'], dependencies: [gmobile_dep], install: true ) test_display_panel_preview = executable( 'gm-display-panel-preview', ['gm-display-panel-preview.c'], dependencies: [gmobile_dep], install: true ) endif 07070100000089000081A400000000000000000000000164F062AA000003E9000000000000000000000000000000000000003100000000feedbackd-0.2.1/subprojects/gmobile/gmobile.doap<?xml version="1.0" encoding="UTF-8"?> <Project xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:foaf="http://xmlns.com/foaf/0.1/" xmlns:gnome="http://api.gnome.org/doap-extensions#" xmlns="http://usefulinc.com/ns/doap#"> <name>gmobile</name> <shortname>gmobile</shortname> <shortdesc>Classes and utilities for mobile devices</shortdesc> <description> gmobile aims to make developing GLib/GObject based software for mobile devices running Linux easier. </description> <homepage rdf:resource="https://gitlab.gnome.org/guidog/gmobile" /> <license rdf:resource="http://usefulinc.com/doap/licenses/lgpl" /> <programming-language>C</programming-language> <maintainer> <foaf:Person> <foaf:name>Guido Günther</foaf:name> <foaf:mbox rdf:resource="mailto:agx@sigxcpu.org" /> <gnome:userid>guidog</gnome:userid> </foaf:Person> </maintainer> </Project> 0707010000008A000081A400000000000000000000000164F062AA000009C9000000000000000000000000000000000000003000000000feedbackd-0.2.1/subprojects/gmobile/meson.buildproject('gmobile', 'c', version: '0.0.1', license: 'LGPLv2.1+', meson_version: '>= 0.56.1', default_options: [ 'warning_level=1', 'buildtype=debugoptimized', 'c_std=gnu11' ], ) cc = meson.get_compiler('c') prefix = get_option('prefix') bindir = join_paths(prefix, get_option('bindir')) datadir = join_paths(prefix, get_option('datadir')) localedir = join_paths(prefix, get_option('localedir')) libdir = join_paths(prefix, get_option('libdir')) pkgdatadir = join_paths(datadir, meson.project_name()) pkglibdir = join_paths(libdir, meson.project_name()) global_c_args = ['-DGMOBILE_COMPILATION'] test_c_args = [ '-Wcast-align', '-Wdate-time', '-Wdeclaration-after-statement', ['-Werror=format-security', '-Werror=format=2'], '-Wendif-labels', '-Werror=incompatible-pointer-types', '-Werror=missing-declarations', '-Werror=overflow', '-Werror=return-type', '-Werror=shift-count-overflow', '-Werror=shift-overflow=2', '-Werror=implicit-fallthrough=3', '-Wfloat-equal', '-Wformat-nonliteral', '-Wformat-security', '-Winit-self', '-Wmaybe-uninitialized', '-Wmissing-field-initializers', '-Wmissing-include-dirs', '-Wmissing-noreturn', '-Wnested-externs', '-Wno-missing-field-initializers', '-Wno-sign-compare', '-Wno-strict-aliasing', '-Wno-unused-parameter', '-Wold-style-definition', '-Wpointer-arith', '-Wredundant-decls', '-Wshadow', '-Wstrict-prototypes', '-Wswitch-default', '-Wswitch-enum', '-Wtype-limits', '-Wundef', '-Wunused-function', ] if get_option('buildtype') != 'plain' test_c_args += '-fstack-protector-strong' endif glib_dep = dependency('glib-2.0', version: '>=2.66') gio_dep = dependency('gio-2.0', version: '>=2.66') json_glib_dep = dependency('json-glib-1.0', version: '>= 1.6.2', fallback: ['json-glib', 'json_glib_dep']) foreach arg: test_c_args if cc.has_multi_arguments(arg) global_c_args += arg endif endforeach gnome = import('gnome') add_project_arguments( global_c_args, language: 'c' ) config_h = configuration_data() config_h.set_quoted('GM_VERSION', meson.project_version()) root_inc = include_directories('.') configure_file( output: 'gm-config.h', configuration: config_h, ) subdir('data') subdir('src') subdir('tests') subdir('examples') subdir('doc') summary({ 'Examples': get_option('examples'), 'Tests': get_option('tests'), 'Docmentation': get_option('gtk_doc'), }, bool_yn: true, section: 'Build', ) 0707010000008B000081A400000000000000000000000164F062AA00000151000000000000000000000000000000000000003600000000feedbackd-0.2.1/subprojects/gmobile/meson_options.txtoption('examples', type: 'boolean', value: true, description: 'Whether to compile the examples') option('tests', type: 'boolean', value: true, description: 'Whether to compile unit tests') option('gtk_doc', type: 'boolean', value: false, description: 'Whether to generate the API reference') 0707010000008C000041ED00000000000000000000000264F062AA00000000000000000000000000000000000000000000002800000000feedbackd-0.2.1/subprojects/gmobile/src0707010000008D000081A400000000000000000000000164F062AA0000132D000000000000000000000000000000000000003400000000feedbackd-0.2.1/subprojects/gmobile/src/gm-cutout.c/* * Copyright (C) 2022 Guido Günther * * SPDX-License-Identifier: LGPL-2.1-or-later */ #include "gm-cutout.h" #include "gm-rect.h" #include "gm-svg-path.h" #include <gio/gio.h> /** * GmCutout: * * A display cutout or notch. * * A display cutout is an area of a display that is not usable for * rendering e.g. because a camera or speaker is placed there. This * includes so called "notches". The are needs to be avoided when * rendering. It is described by a SVG path. Each cutouts coordinate * systems is located at the top left display corner in the displays * natural orientation. Applications can query the area to avoid * for rendering via the `bounds` property so they don't need to * deal with the SVG path themselves. */ enum { PROP_0, PROP_NAME, PROP_PATH, PROP_BOUNDS, PROP_LAST_PROP }; static GParamSpec *props[PROP_LAST_PROP]; struct _GmCutout { GObject parent; char *name; char *path; GmRect bounds; }; G_DEFINE_TYPE (GmCutout, gm_cutout, G_TYPE_OBJECT); static gboolean gm_cutout_set_path (GmCutout *self, const char *path, GError **err) { g_autoptr (GError) local_err = NULL; int x1, y1, x2, y2; if (g_strcmp0 (self->path, path) == 0) return TRUE; if (gm_svg_path_get_bounding_box (path, &x1, &x2, &y1, &y2, &local_err) == FALSE) { if (err) *err = g_error_copy (local_err); /* Tracking errors in when setting properties can be hard so make it simple * to get some debugging */ g_debug ("Failed to parse bounding box for %s: %s", path, local_err->message); return FALSE; } g_free (self->path); self->path = g_strdup (path); self->bounds.x = x1; self->bounds.y = y1; self->bounds.width = x2 - x1; self->bounds.height = y2 - y1; return TRUE; } static void gm_cutout_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) { GmCutout *self = GM_CUTOUT (object); switch (property_id) { case PROP_NAME: g_free (self->name); self->name = g_value_dup_string (value); break; case PROP_PATH: gm_cutout_set_path (self, g_value_get_string (value), NULL); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; } } static void gm_cutout_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec) { GmCutout *self = GM_CUTOUT (object); switch (property_id) { case PROP_NAME: g_value_set_string (value, gm_cutout_get_name (self)); break; case PROP_PATH: g_value_set_string (value, gm_cutout_get_path (self)); break; case PROP_BOUNDS: g_value_set_boxed (value, gm_cutout_get_bounds (self)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; } } static void gm_cutout_finalize (GObject *object) { GmCutout *self = GM_CUTOUT (object); g_clear_pointer (&self->name, g_free); g_clear_pointer (&self->path, g_free); G_OBJECT_CLASS (gm_cutout_parent_class)->finalize (object); } static void gm_cutout_class_init (GmCutoutClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->get_property = gm_cutout_get_property; object_class->set_property = gm_cutout_set_property; object_class->finalize = gm_cutout_finalize; /** * GmCutout:name: * * A name identifying the cutout. */ props[PROP_NAME] = g_param_spec_string ("name", "", "", NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY); /** * GmCutout:path: * * The SVG path that describes the display cutout or notch. */ props[PROP_PATH] = g_param_spec_string ("path", "", "", NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY); /** * GmCutout:bounds: * * Rectangular bounds of the cutout */ props[PROP_BOUNDS] = g_param_spec_boxed ("bounds", "", "", GM_TYPE_RECT, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); g_object_class_install_properties (object_class, PROP_LAST_PROP, props); } static void gm_cutout_init (GmCutout *self) { } GmCutout * gm_cutout_new (const char *path) { return GM_CUTOUT (g_object_new (GM_TYPE_CUTOUT, "path", path, NULL)); } const char * gm_cutout_get_name (GmCutout *self) { g_return_val_if_fail (GM_IS_CUTOUT (self), NULL); return self->name; } const char * gm_cutout_get_path (GmCutout *self) { g_return_val_if_fail (GM_IS_CUTOUT (self), NULL); return self->path; } const GmRect * gm_cutout_get_bounds (GmCutout *self) { g_return_val_if_fail (GM_IS_CUTOUT (self), NULL); return &self->bounds; } 0707010000008E000081A400000000000000000000000164F062AA000001F8000000000000000000000000000000000000003400000000feedbackd-0.2.1/subprojects/gmobile/src/gm-cutout.h/* * Copyright (C) 2022 Guido Günther * * SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once #include "gm-rect.h" #include <glib-object.h> G_BEGIN_DECLS #define GM_TYPE_CUTOUT (gm_cutout_get_type ()) G_DECLARE_FINAL_TYPE (GmCutout, gm_cutout, GM, CUTOUT, GObject) GmCutout *gm_cutout_new (const char *path); const char *gm_cutout_get_name (GmCutout *self); const char *gm_cutout_get_path (GmCutout *self); const GmRect *gm_cutout_get_bounds (GmCutout *self); G_END_DECLS 0707010000008F000081A400000000000000000000000164F062AA0000100B000000000000000000000000000000000000003900000000feedbackd-0.2.1/subprojects/gmobile/src/gm-device-info.c/* * Copyright (C) 2022 Guido Günther * * SPDX-License-Identifier: GPL-3.0-or-later * * Author: Guido Günther <agx@sigxcpu.org> */ #include "gm-config.h" #include "gm-device-info.h" #include "gm-display-panel.h" #define GM_RESOURCE_PREFIX "/org/gnome/gmobile/" #define GM_DISPLAY_PANEL_RESOURCE_PREFIX GM_RESOURCE_PREFIX "devices/display-panels/" /** * GmDeviceInfo: * * Get device dependent information. * * Allows to query device dependent information from different * sources (currently we only look a the built-in gresources). * * The lookups are currently based on device tree compatibles. * See [func@device_tree_get_compatibles]. */ enum { PROP_0, PROP_COMPATIBLES, PROP_LAST_PROP }; static GParamSpec *props[PROP_LAST_PROP]; struct _GmDeviceInfo { GObject parent; GStrv compatibles; GmDisplayPanel *panel; }; G_DEFINE_TYPE (GmDeviceInfo, gm_device_info, G_TYPE_OBJECT) static void gm_device_info_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) { GmDeviceInfo *self = GM_DEVICE_INFO (object); switch (property_id) { case PROP_COMPATIBLES: g_strfreev (self->compatibles); self->compatibles = g_value_dup_boxed (value); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; } } static void gm_device_info_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec) { GmDeviceInfo *self = GM_DEVICE_INFO (object); switch (property_id) { case PROP_COMPATIBLES: g_value_set_boxed (value, self->compatibles); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; } } static void gm_device_info_finalize (GObject *object) { GmDeviceInfo *self = GM_DEVICE_INFO(object); g_clear_object (&self->panel); g_clear_pointer (&self->compatibles, g_strfreev); G_OBJECT_CLASS (gm_device_info_parent_class)->finalize (object); } static void gm_device_info_class_init (GmDeviceInfoClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->get_property = gm_device_info_get_property; object_class->set_property = gm_device_info_set_property; object_class->finalize = gm_device_info_finalize; /** * GmDeviceInfo:compatibles: * * The compatibles to look up device information for. */ props[PROP_COMPATIBLES] = g_param_spec_boxed ("compatibles", "", "", G_TYPE_STRV, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); g_object_class_install_properties (object_class, PROP_LAST_PROP, props); } static void gm_device_info_init (GmDeviceInfo *self) { } GmDeviceInfo * gm_device_info_new (const char * const *compatibles) { return GM_DEVICE_INFO (g_object_new (GM_TYPE_DEVICE_INFO, "compatibles", compatibles, NULL)); } /** * gm_device_info_get_display_panel: * @self: The device info * * Get display panel information. Queries the database for the best * matching panel based on the device's compatibles. * * Returns:(transfer none): The display panel information */ GmDisplayPanel * gm_device_info_get_display_panel (GmDeviceInfo *self) { GmDisplayPanel *panel = NULL; g_return_val_if_fail (GM_IS_DEVICE_INFO (self), NULL); g_return_val_if_fail (self->compatibles, NULL); if (self->panel) return self->panel; for (int i = 0; self->compatibles[i] != NULL; i++) { g_autofree char *filename = g_strdup_printf ("%s.json", self->compatibles[i]); g_autofree char *resource = NULL; resource = g_build_path ("/", GM_DISPLAY_PANEL_RESOURCE_PREFIX, filename, NULL); panel = gm_display_panel_new_from_resource (resource, NULL); if (panel) { self->panel = panel; break; } } return self->panel; } 07070100000090000081A400000000000000000000000164F062AA000001D8000000000000000000000000000000000000003900000000feedbackd-0.2.1/subprojects/gmobile/src/gm-device-info.h/* * Copyright (C) 2022 Guido Günther * * SPDX-License-Identifier: GPL-3.0-or-later */ #pragma once #include "gm-display-panel.h" #include <glib-object.h> G_BEGIN_DECLS #define GM_TYPE_DEVICE_INFO (gm_device_info_get_type ()) G_DECLARE_FINAL_TYPE (GmDeviceInfo, gm_device_info, GM, DEVICE_INFO, GObject) GmDeviceInfo *gm_device_info_new (const char * const *compatibles); GmDisplayPanel *gm_device_info_get_display_panel (GmDeviceInfo *self); G_END_DECLS 07070100000091000081A400000000000000000000000164F062AA00000918000000000000000000000000000000000000003900000000feedbackd-0.2.1/subprojects/gmobile/src/gm-device-tree.c/* * Copyright (C) 2022 Guido Günther <agx@sigxcpu.org> * * SPDX-License-Identifier: LGPL-2.1-or-later */ #include "gm-device-tree.h" #include <gio/gio.h> #include <glib.h> #define DT_COMPATIBLE_PATH "firmware/devicetree/base/compatible" static GStrv get_env_compatibles (void) { const char *env = g_getenv ("GMOBILE_DT_COMPATIBLES"); if (env) return g_strsplit(env, ":", -1); return NULL; } /** * gm_device_tree_get_compatibles: * @sysfs_root: Path where /sys is mounted. Defaults to `/sys` if %NULL is passed. * @err: return location for error or %NULL * * Read compatible machine types from * `sysfs_root/firmware/devicetree/base/compatible` on Linux. * If the path doesn't exist or host is not Linux return %NULL. * * For debugging purposes `GMOBILE_DT_COMPATIBLES` can be set to a `:` * separated list of compatibles which will be returned instead. * * Returns:(transfer full): compatible machine types or %NULL */ GStrv gm_device_tree_get_compatibles (const char *sysfs_root, GError **err) { GStrv env_compatibles; #ifdef __linux__ gsize len; g_autoptr (GPtrArray) parts = NULL; g_autofree char *compatible_path = NULL; g_autofree gchar *compatibles = NULL; const char *comp; g_return_val_if_fail (err == NULL || *err == NULL, NULL); env_compatibles = get_env_compatibles(); if (env_compatibles) return env_compatibles; compatible_path = g_build_filename (sysfs_root ?: "/sys", DT_COMPATIBLE_PATH, NULL); if (g_file_test (compatible_path, (G_FILE_TEST_EXISTS)) == FALSE) { g_set_error (err, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, "%s not found", compatible_path); return NULL; } if (!g_file_get_contents (compatible_path, &compatibles, &len, err)) { return NULL; } parts = g_ptr_array_new (); comp = compatibles; while (comp - compatibles < len) { g_ptr_array_add (parts, (gpointer) g_strdup (comp)); comp = strchr (comp, 0); comp++; } g_ptr_array_add (parts, NULL); return (GStrv) g_ptr_array_steal (parts, NULL); #else env_compatibles = get_env_compatibles(); if (env_compatibles) return env_compatibles; g_set_error_literal (err, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "Not supported on this platform"); return NULL; #endif } 07070100000092000081A400000000000000000000000164F062AA0000017B000000000000000000000000000000000000003900000000feedbackd-0.2.1/subprojects/gmobile/src/gm-device-tree.h/* * Copyright (C) 2022 Guido Günther <agx@sigxcpu.org> * * SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once #if !defined(_GMOBILE_INSIDE) && !defined(GMOBILE_COMPILATION) #error "Only <gmobile.h> can be included directly." #endif #include <glib.h> G_BEGIN_DECLS GStrv gm_device_tree_get_compatibles (const char *sysfs_root, GError **err); G_END_DECLS 07070100000093000081A400000000000000000000000164F062AA00002A1A000000000000000000000000000000000000003B00000000feedbackd-0.2.1/subprojects/gmobile/src/gm-display-panel.c/* * Copyright (C) 2022 Guido Günther * * SPDX-License-Identifier: GPL-3.0-or-later * * Author: Guido Günther <agx@sigxcpu.org> */ #include "gm-cutout.h" #include "gm-display-panel.h" #include "gm-main.h" #include <json-glib/json-glib.h> /** * GmDisplayPanel: * * Physical properties of a display panel like size, cutouts and * rounded corners. */ enum { PROP_0, PROP_NAME, PROP_CUTOUTS, PROP_X_RES, PROP_Y_RES, PROP_WIDTH, PROP_HEIGHT, PROP_BORDER_RADIUS, PROP_LAST_PROP }; static GParamSpec *props[PROP_LAST_PROP]; struct _GmDisplayPanel { GObject parent; char *name; GListStore *cutouts; int x_res; int y_res; int border_radius; int width; int height; }; static void gm_display_panel_json_serializable_iface_init (JsonSerializableIface *iface); G_DEFINE_TYPE_WITH_CODE (GmDisplayPanel, gm_display_panel, G_TYPE_OBJECT, G_IMPLEMENT_INTERFACE (JSON_TYPE_SERIALIZABLE, gm_display_panel_json_serializable_iface_init)); static void gm_display_panel_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) { GmDisplayPanel *self = GM_DISPLAY_PANEL (object); switch (property_id) { case PROP_NAME: g_free (self->name); self->name = g_value_dup_string (value); break; case PROP_CUTOUTS: g_set_object (&self->cutouts, g_value_get_object (value)); break; case PROP_X_RES: self->x_res = g_value_get_int (value); break; case PROP_Y_RES: self->y_res = g_value_get_int (value); break; case PROP_BORDER_RADIUS: self->border_radius = g_value_get_int (value); break; case PROP_WIDTH: self->width = g_value_get_int (value); break; case PROP_HEIGHT: self->height = g_value_get_int (value); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; } } static void gm_display_panel_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec) { GmDisplayPanel *self = GM_DISPLAY_PANEL (object); switch (property_id) { case PROP_NAME: g_value_set_string (value, self->name); break; case PROP_CUTOUTS: g_value_set_object (value, self->cutouts); break; case PROP_X_RES: g_value_set_int (value, gm_display_panel_get_x_res (self)); break; case PROP_Y_RES: g_value_set_int (value, gm_display_panel_get_y_res (self)); break; case PROP_BORDER_RADIUS: g_value_set_int (value, gm_display_panel_get_border_radius (self)); break; case PROP_WIDTH: g_value_set_int (value, gm_display_panel_get_width (self)); break; case PROP_HEIGHT: g_value_set_int (value, gm_display_panel_get_height (self)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; } } static JsonNode * gm_display_panel_serializable_serialize_property (JsonSerializable *serializable, const gchar *property_name, const GValue *value, GParamSpec *pspec) { GmDisplayPanel *self = GM_DISPLAY_PANEL (serializable); JsonNode *node = NULL; if (g_strcmp0 (property_name, "cutouts") == 0) { JsonArray *array = json_array_sized_new (1); for (int i = 0; i < g_list_model_get_n_items (G_LIST_MODEL (self->cutouts)); i++) { g_autoptr (GObject) cutout = g_list_model_get_item (G_LIST_MODEL (self->cutouts), i); json_array_add_element (array, json_gobject_serialize (cutout)); } node = json_node_init_array (json_node_alloc (), array); } else { node = json_serializable_default_serialize_property (serializable, property_name, value, pspec); } return node; } static gboolean gm_display_panel_serializable_deserialize_property (JsonSerializable *serializable, const gchar *property_name, GValue *value, GParamSpec *pspec, JsonNode *property_node) { if (g_strcmp0 (property_name, "cutouts") == 0) { if (JSON_NODE_TYPE (property_node) == JSON_NODE_NULL) { g_value_set_pointer (value, NULL); return TRUE; } else if (JSON_NODE_TYPE (property_node) == JSON_NODE_ARRAY) { JsonArray *array = json_node_get_array (property_node); guint array_len = json_array_get_length (array); GListStore *cutouts = g_list_store_new (GM_TYPE_CUTOUT); for (int i = 0; i < array_len; i++) { JsonNode *element_node = json_array_get_element (array, i); GmCutout *cutout; if (JSON_NODE_HOLDS_OBJECT (element_node)) { cutout = GM_CUTOUT (json_gobject_deserialize (GM_TYPE_CUTOUT, element_node)); g_list_store_append (cutouts, cutout); } else { return FALSE; } } g_value_set_object (value, cutouts); return TRUE; } return FALSE; } else { return json_serializable_default_deserialize_property (serializable, property_name, value, pspec, property_node); } return FALSE; } static void gm_display_panel_json_serializable_iface_init (JsonSerializableIface *iface) { iface->serialize_property = gm_display_panel_serializable_serialize_property; iface->deserialize_property = gm_display_panel_serializable_deserialize_property; } static void gm_display_panel_finalize (GObject *object) { GmDisplayPanel *self = GM_DISPLAY_PANEL(object); g_clear_object (&self->cutouts); g_clear_pointer (&self->name, g_free); G_OBJECT_CLASS (gm_display_panel_parent_class)->finalize (object); } static void gm_display_panel_class_init (GmDisplayPanelClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->get_property = gm_display_panel_get_property; object_class->set_property = gm_display_panel_set_property; object_class->finalize = gm_display_panel_finalize; /** * GmDisplayPanel:name: * * The name of the display */ props[PROP_NAME] = g_param_spec_string ("name", "", "", NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); /** * GmDisplayPanel:cutouts: * * The display cutouts as `GListModel` of [class@Cutout]. */ props[PROP_CUTOUTS] = g_param_spec_object ("cutouts", "", "", G_TYPE_LIST_STORE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); /** * GmDisplayPanel:x-res: * * The panel resolution in pixels in the x direction */ props[PROP_X_RES] = g_param_spec_int ("x-res", "", "", 0, G_MAXINT, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); /** * GmDisplayPanel:y-res: * * The panel resolution in pixels in the y direction */ props[PROP_Y_RES] = g_param_spec_int ("y-res", "", "", 0, G_MAXINT, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); /** * GmDisplayPanel:border-radius: * * The border radius of the panel edges in device pixels * If a single border radius isn't enough use multiple [type@Cutout]. */ props[PROP_BORDER_RADIUS] = g_param_spec_int ("border-radius", "", "", 0, G_MAXINT, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); /** * GmDisplayPanel:width: * * The display width in millimeters */ props[PROP_WIDTH] = g_param_spec_int ("width", "", "", 0, G_MAXINT, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); /** * GmDisplayPanel:height: * * The display height in millimeters */ props[PROP_HEIGHT] = g_param_spec_int ("height", "", "", 0, G_MAXINT, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); g_object_class_install_properties (object_class, PROP_LAST_PROP, props); } static void gm_display_panel_init (GmDisplayPanel *self) { self->cutouts = g_list_store_new (GM_TYPE_CUTOUT); } GmDisplayPanel * gm_display_panel_new (void) { return GM_DISPLAY_PANEL (g_object_new (GM_TYPE_DISPLAY_PANEL, NULL)); } GmDisplayPanel * gm_display_panel_new_from_data (const gchar *data, GError **error) { g_autoptr (JsonNode) node = json_from_string(data, error); if (!node) return NULL; return GM_DISPLAY_PANEL (json_gobject_deserialize (GM_TYPE_DISPLAY_PANEL, node)); } GmDisplayPanel * gm_display_panel_new_from_resource (const gchar *resource_name, GError **error) { g_autoptr (GBytes) bytes = NULL; g_return_val_if_fail (resource_name && resource_name[0], NULL); /* Make sure resources are initialized */ gm_init (); bytes = g_resources_lookup_data (resource_name, 0, error); if (bytes == NULL) return NULL; return GM_DISPLAY_PANEL (gm_display_panel_new_from_data ((const char *)g_bytes_get_data (bytes, NULL), error)); } const char * gm_display_panel_get_name (GmDisplayPanel *self) { g_return_val_if_fail (GM_IS_DISPLAY_PANEL (self), NULL); return self->name; } /** * gm_display_panel_get_cutouts: * @self: The display panel * * Get the display cutouts. * * Returns: (transfer none): The display cutouts */ GListModel * gm_display_panel_get_cutouts (GmDisplayPanel *self) { g_return_val_if_fail (GM_IS_DISPLAY_PANEL (self), NULL); return G_LIST_MODEL (self->cutouts); } int gm_display_panel_get_x_res (GmDisplayPanel *self) { g_return_val_if_fail (GM_IS_DISPLAY_PANEL (self), 0); return self->x_res; } int gm_display_panel_get_y_res (GmDisplayPanel *self) { g_return_val_if_fail (GM_IS_DISPLAY_PANEL (self), 0); return self->y_res; } int gm_display_panel_get_border_radius (GmDisplayPanel *self) { g_return_val_if_fail (GM_IS_DISPLAY_PANEL (self), 0); return self->border_radius; } int gm_display_panel_get_width (GmDisplayPanel *self) { g_return_val_if_fail (GM_IS_DISPLAY_PANEL (self), 0); return self->width; } int gm_display_panel_get_height (GmDisplayPanel *self) { g_return_val_if_fail (GM_IS_DISPLAY_PANEL (self), 0); return self->height; } 07070100000094000081A400000000000000000000000164F062AA00000431000000000000000000000000000000000000003B00000000feedbackd-0.2.1/subprojects/gmobile/src/gm-display-panel.h/* * Copyright (C) 2022 Guido Günther * * SPDX-License-Identifier: GPL-3.0-or-later */ #pragma once #include <glib-object.h> #include <gio/gio.h> G_BEGIN_DECLS #define GM_TYPE_DISPLAY_PANEL (gm_display_panel_get_type ()) G_DECLARE_FINAL_TYPE (GmDisplayPanel, gm_display_panel, GM, DISPLAY_PANEL, GObject) GmDisplayPanel *gm_display_panel_new (void); GmDisplayPanel *gm_display_panel_new_from_data (const gchar *data, GError **error); GmDisplayPanel *gm_display_panel_new_from_resource (const char *resource_name, GError **error); const char *gm_display_panel_get_name (GmDisplayPanel *self); GListModel *gm_display_panel_get_cutouts (GmDisplayPanel *self); int gm_display_panel_get_x_res (GmDisplayPanel *self); int gm_display_panel_get_y_res (GmDisplayPanel *self); int gm_display_panel_get_border_radius (GmDisplayPanel *self); int gm_display_panel_get_width (GmDisplayPanel *self); int gm_display_panel_get_height (GmDisplayPanel *self); G_END_DECLS 07070100000095000081A400000000000000000000000164F062AA00000111000000000000000000000000000000000000003300000000feedbackd-0.2.1/subprojects/gmobile/src/gm-error.c/* * Copyright (C) 2022 Guido Günther <agx@sigxcpu.org> * * SPDX-License-Identifier: LGPL-2.1-or-later */ #include "gm-error.h" GQuark gm_error_quark (void) { static GQuark quark = 0; if (!quark) quark = g_quark_from_static_string("gm"); return quark; } 07070100000096000081A400000000000000000000000164F062AA00000127000000000000000000000000000000000000003300000000feedbackd-0.2.1/subprojects/gmobile/src/gm-error.h/* * Copyright (C) 2022 Purism SPC * * SPDX-License-Identifier: LGPL-2.1-or-later * * Author: Guido Günther <agx@sigxcpu.org> */ #pragma once #include <glib.h> typedef enum { GM_ERROR_PARSING_FAILED = 1, } GmError; #define GM_ERROR (gm_error_quark()) GQuark gm_error_quark (void); 07070100000097000081A400000000000000000000000164F062AA00000282000000000000000000000000000000000000003200000000feedbackd-0.2.1/subprojects/gmobile/src/gm-main.c/* * Copyright (C) 2022 Guido Günther <agx@sigxcpu.org> * * SPDX-License-Identifier: GPL-3-or-later */ #include "gm-main.h" #include "gm-resources.h" /** * gm_init: * * Call this function to initialize the library explicitly. This makes * the embedded device information available. */ void gm_init (void) { static gsize initialized = FALSE; if (g_once_init_enter (&initialized)) { /* * gmobile is currently meant as static library so register * resources explicitly. otherwise they get dropped during static * linking */ gm_register_resource (); g_once_init_leave (&initialized, TRUE); } } 07070100000098000081A400000000000000000000000164F062AA00000143000000000000000000000000000000000000003200000000feedbackd-0.2.1/subprojects/gmobile/src/gm-main.h/* * Copyright (C) 2022 Guido Günther <agx@sigxcpu.org> * * SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once #if !defined(_GMOBILE_INSIDE) && !defined(GMOBILE_COMPILATION) #error "Only <gmobile.h> can be included directly." #endif #include <glib.h> G_BEGIN_DECLS void gm_init (void); G_END_DECLS 07070100000099000081A400000000000000000000000164F062AA00000270000000000000000000000000000000000000003200000000feedbackd-0.2.1/subprojects/gmobile/src/gm-rect.c/* * Copyright (C) 2022 Guido Günther * * SPDX-License-Identifier: LGPL-2.1-or-later */ #include "gm-rect.h" /** * GmRect: * @x: x coordindate of the upper, left corner * @y: y coordindate of the upper, left corner * @width: the width of the rectangle * @height: the height of the rectangle * * A rectangle. * * Similar to GdkRectangle but we don't want to pull in gtk/gdk. */ static GmRect * gm_rect_copy (const GmRect *self) { GmRect *copy = g_new (GmRect, 1); *copy = *self; return copy; } /* TODO: transform from/to GdkRectangle */ G_DEFINE_BOXED_TYPE (GmRect, gm_rect, gm_rect_copy, g_free); 0707010000009A000081A400000000000000000000000164F062AA000001CC000000000000000000000000000000000000003200000000feedbackd-0.2.1/subprojects/gmobile/src/gm-rect.h/* * Copyright (C) 2022 Guido Günther <agx@sigxcpu.org> * * SPDX-License-Identifier: LGPL-2.1-or-later */ #include <glib-object.h> #pragma once #if !defined(_GMOBILE_INSIDE) && !defined(GMOBILE_COMPILATION) #error "Only <gmobile.h> can be included directly." #endif G_BEGIN_DECLS typedef struct _GmRect { int x, y; int width, height; } GmRect; GType gm_rect_get_type (void) G_GNUC_CONST; #define GM_TYPE_RECT (gm_rect_get_type ()) G_END_DECLS 0707010000009B000081A400000000000000000000000164F062AA00003857000000000000000000000000000000000000003600000000feedbackd-0.2.1/subprojects/gmobile/src/gm-svg-path.c/* * Copyright (C) 2022 Guido Günther <agx@sigxcpu.org> * * SPDX-License-Identifier: LGPL-2.1-or-later */ #include "gm-error.h" #include "gm-rect.h" #include "gm-svg-path.h" #include <math.h> #if !GLIB_CHECK_VERSION(2, 74, 0) # define G_REGEX_DEFAULT 0 # define G_REGEX_MATCH_DEFAULT 0 #endif struct bbox { int x1, x2, y1, y2; int cx, cy; }; struct fbbox { double x1, x2, y1, y2; }; static void swap (double *a, double *b) { double tmp = *a; *a = *b; *b = tmp; } static double bbox_quad_deriv (double start, double control, double end) { double t; /* control point between start and end, nothing to do */ if ((control > start && control < end) || (control > end && control < start)) return start; t = ((start - control) / (start - (2 * control) + end)); return start * ((1 - t) * (1 - t)) + 2 * control * (1 - t) * t + end * t * t; } /* * See https://pomax.github.io/bezierinfo/ , * http://pomax.nihongoresources.com/pages/bezier/ */ static struct fbbox bbox_quadratic_bezier (double x1, double y1, double x2, double y2, double x3, double y3) { struct fbbox bbox = { 0.0 }; double x, y; bbox.x1 = fmin (x1, x3); bbox.y1 = fmin (y1, y3); bbox.x2 = fmax (x1, x3); bbox.y2 = fmax (y1, y3); x = bbox_quad_deriv (x1, x2, x3); if (x < bbox.x1) bbox.x1 = x; else if (x > bbox.x2) bbox.x2 = x; y = bbox_quad_deriv (y1, y2, y3); if (y < bbox.y1) bbox.y1 = y; else if (y > bbox.y2) bbox.y2 = y; return bbox; } static inline double bbox_arc_get_angle (double bx, double by) { return fmod (2 * M_PI + (by > 0.0 ? 1.0 : -1.0) * acos ( bx / sqrt (bx * bx + by * by) ), 2 * M_PI); } /* See https://fridrich.blogspot.com/2011/06/bounding-box-of-svg-elliptical-arc.html */ static struct fbbox bbox_arc (double x1, double y1, double rx, double ry, double phi, gboolean large_arc, gboolean sweep, double x2, double y2) { struct fbbox bbox; gboolean other_arc; const double x1prime = cos (phi)*(x1 - x2)/2 + sin (phi)*(y1 - y2) / 2; const double y1prime = -sin (phi)*(x1 - x2)/2 + cos (phi)*(y1 - y2) / 2; double txmin, txmax, tymin, tymax, cx, cy, radicant, angle1, angle2; double cxprime = 0.0; double cyprime = 0.0; if (rx < 0.0) rx *= -1.0; if (ry < 0.0) ry *= -1.0; if (G_APPROX_VALUE (rx, 0.0, DBL_EPSILON) || G_APPROX_VALUE (ry, 0.0, DBL_EPSILON)) { bbox.x1 = (x1 < x2 ? x1 : x2); bbox.x2 = (x1 > x2 ? x1 : x2); bbox.y1 = (y1 < y2 ? y1 : y2); bbox.y2 = (y1 > y2 ? y1 : y2); return bbox; } radicant = (rx*rx*ry*ry - rx*rx*y1prime*y1prime - ry*ry*x1prime*x1prime); radicant /= (rx*rx*y1prime*y1prime + ry*ry*x1prime*x1prime); if (radicant < 0.0) { double ratio = rx/ry; double rad = y1prime * y1prime + x1prime * x1prime / (ratio * ratio); if (rad < 0.0) { bbox.x1 = (x1 < x2 ? x1 : x2); bbox.x2 = (x1 > x2 ? x1 : x2); bbox.y1 = (y1 < y2 ? y1 : y2); bbox.y2 = (y1 > y2 ? y1 : y2); return bbox; } ry =sqrt (rad); rx = ratio * ry; } else { double factor = ((large_arc == sweep) ? -1.0 : 1.0) * sqrt (radicant); cxprime = factor * rx* y1prime / ry; cyprime = -factor * ry * x1prime / rx; } cx = cxprime * cos (phi) - cyprime * sin (phi) + (x1 + x2) / 2; cy = cxprime * sin (phi) + cyprime * cos (phi) + (y1 + y2) / 2; if (G_APPROX_VALUE (phi, 0.0, DBL_EPSILON) || G_APPROX_VALUE (phi, M_PI, DBL_EPSILON)) { bbox.x1 = cx - rx; txmin = bbox_arc_get_angle (-rx, 0); bbox.x2 = cx + rx; txmax = bbox_arc_get_angle (rx, 0); bbox.y1 = cy - ry; tymin = bbox_arc_get_angle (0, -ry); bbox.y2 = cy + ry; tymax = bbox_arc_get_angle (0, ry); } else if (G_APPROX_VALUE (phi, M_PI / 2.0, DBL_EPSILON) || G_APPROX_VALUE (phi, 3.0 * M_PI / 2.0, DBL_EPSILON)) { bbox.x1 = cx - ry; txmin = bbox_arc_get_angle (-ry, 0); bbox.x2 = cx + ry; txmax = bbox_arc_get_angle (ry, 0); bbox.y1 = cy - rx; tymin = bbox_arc_get_angle (0, -rx); bbox.y2 = cy + rx; tymax = bbox_arc_get_angle (0, rx); } else { double tmp_x, tmp_y; txmin = -atan (ry*tan (phi)/rx); txmax = M_PI - atan (ry*tan (phi)/rx); bbox.x1 = cx + rx * cos (txmin) * cos (phi) - ry * sin (txmin) * sin (phi); bbox.x2 = cx + rx * cos (txmax) * cos (phi) - ry * sin (txmax) * sin (phi); if (bbox.x1 > bbox.x2) { swap (&bbox.x1, &bbox.x2); swap (&txmin, &txmax); } tmp_y = cy + rx * cos (txmin) * sin (phi) + ry * sin (txmin) * cos (phi); txmin = bbox_arc_get_angle (bbox.x1 - cx, tmp_y - cy); tmp_y = cy + rx * cos (txmax) * sin (phi) + ry * sin (txmax) * cos (phi); txmax = bbox_arc_get_angle (bbox.x2 - cx, tmp_y - cy); tymin = atan (ry / (tan (phi) * rx)); tymax = atan (ry / (tan (phi) * rx)) + M_PI; bbox.y1 = cy + rx * cos (tymin) * sin (phi) + ry * sin (tymin) * cos (phi); bbox.y2 = cy + rx * cos (tymax) * sin (phi) + ry * sin (tymax) * cos (phi); if (bbox.y1 > bbox.y2) { swap (&bbox.y1, &bbox.y2); swap (&tymin, &tymax); } tmp_x = cx + rx * cos (tymin) * cos (phi) - ry * sin (tymin) * sin (phi); tymin = bbox_arc_get_angle (tmp_x - cx, bbox.y1 - cy); tmp_x = cx + rx * cos (tymax) * cos (phi) - ry * sin (tymax) * sin (phi); tymax = bbox_arc_get_angle (tmp_x - cx, bbox.y2 - cy); } angle1 = bbox_arc_get_angle (x1 - cx, y1 - cy); angle2 = bbox_arc_get_angle (x2 - cx, y2 - cy); if (!sweep) swap (&angle1, &angle2); other_arc = FALSE; if (angle1 > angle2) { swap (&angle1, &angle2); other_arc = TRUE; } if ((!other_arc && (angle1 > txmin || angle2 < txmin)) || (other_arc && !(angle1 > txmin || angle2 < txmin))) bbox.x1 = x1 < x2 ? x1 : x2; if ((!other_arc && (angle1 > txmax || angle2 < txmax)) || (other_arc && !(angle1 > txmax || angle2 < txmax))) bbox.x2 = x1 > x2 ? x1 : x2; if ((!other_arc && (angle1 > tymin || angle2 < tymin)) || (other_arc && !(angle1 > tymin || angle2 < tymin))) bbox.y1 = y1 < y2 ? y1 : y2; if ((!other_arc && (angle1 > tymax || angle2 < tymax)) || (other_arc && !(angle1 > tymax || angle2 < tymax))) bbox.y2 = y1 > y2 ? y1 : y2; return bbox; } static gboolean parse_int (const char *str, int *number, GError **err) { gint64 nl; char *endptr; if (str == NULL) { g_set_error_literal (err, GM_ERROR, GM_ERROR_PARSING_FAILED, "empty string is not a number"); return FALSE; } nl = g_ascii_strtoll (str, &endptr, 10); if (nl == 0 && str == endptr) { g_set_error (err, GM_ERROR, GM_ERROR_PARSING_FAILED, "'%s' not a number", str); return FALSE; } if (ABS (nl) > G_MAXINT) { g_set_error (err, GM_ERROR, GM_ERROR_PARSING_FAILED, "'%s' too large", str); return FALSE; } *number = nl; return TRUE; } static void extend_bbox_by_point (struct bbox *bbox, int x, int y) { if (x < bbox->x1) bbox->x1 = x; if (x > bbox->x2) bbox->x2 = x; if (y < bbox->y1) bbox->y1 = y; if (y > bbox->y2) bbox->y2 = y; bbox->cx = x; bbox->cy = y; } static void extend_bbox_by_frect (struct bbox *bbox, struct fbbox *rect) { if (rect->x1 < bbox->x1) bbox->x1 = rect->x1; if (rect->x2 > bbox->x2) bbox->x2 = rect->x2; if (rect->y1 < bbox->y1) bbox->y1 = rect->y1; if (rect->y2 > bbox->y2) bbox->y2 = rect->y2; } static gboolean is_command (char c) { switch (c) { case 'A': /* arc */ case 'a': case 'C': /* cubic bezier */ case 'c': case 'H': /* horizonal line */ case 'h': case 'L': /* line */ case 'l': case 'M': /* move to */ case 'm': case 'Q': /* quadratic bezier (TBD) */ case 'q': case 'S': /* shortcut cubic bezier (TBD) */ case 's': case 'T': /* shortcut quadratic bezier (TBD) */ case 't': case 'V': /* vertical line */ case 'v': case 'Z': /* close path */ return TRUE; default: return FALSE; } } static char * normalize_path (const char *path) { GString *canon = g_string_new (""); char *norm; for (int i = 0; path[i] != '\0'; i++) { if (path[i] == ',' || path[i] == '\n' || path[i] == '\t') { /* Comma works like whitespace */ g_string_append_c (canon, ' '); } else if (is_command (path[i])) { /* Make sure there's whitespace after each command */ g_string_append_c (canon, path[i]); /* Make sure there's whitespace after each command */ g_string_append_c (canon, ' '); } else { g_string_append_c (canon, path[i]); } } norm = g_string_free (canon, FALSE); return g_strstrip (norm); } /** * gm_svg_path_get_bounding_box: * @path: An SVG path * @x1: The lower x coordinate * @x2: The upper x coordinate * @y1: The lower y coordinate * @y2: The upper x coordinate * * Returns the bounding box of an SVG path. As this is meant for * display cutouts we operate on integer (whole pixel) values. * * See https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Paths for path syntax introduction. */ gboolean gm_svg_path_get_bounding_box (const char *path, int *x1, int *x2, int *y1, int *y2, GError **err) { g_auto (GStrv) parts = NULL; g_autoptr (GRegex) whitespace = NULL; g_autofree char *norm = NULL; struct bbox bbox = { G_MAXINT, 0, G_MAXINT, 0 }; g_return_val_if_fail (err == NULL || *err == NULL, FALSE); norm = normalize_path (path); whitespace = g_regex_new (" +", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, err); g_return_val_if_fail (whitespace, FALSE); parts = g_regex_split (whitespace, norm, G_REGEX_MATCH_DEFAULT); for (int i = 0; parts[i] != NULL; i++) { const char *cmd = parts[i]; int x, y, dx, dy; gboolean rel = FALSE; switch (cmd[0]) { case 'M': /* x,y */ case 'L': i++; if (parse_int (parts[i], &x, err) == FALSE) return FALSE; i++; if (parse_int (parts[i], &y, err) == FALSE) return FALSE; extend_bbox_by_point (&bbox, x, y); break; case 'm': /* dx,dy */ case 'l': i++; if (parse_int (parts[i], &dx, err) == FALSE) return FALSE; i++; if (parse_int (parts[i], &dy, err) == FALSE) return FALSE; extend_bbox_by_point (&bbox, bbox.cx + dx, bbox.cy + dy); break; case 'V': /* y */ i++; if (parse_int (parts[i], &y, err) == FALSE) return FALSE; extend_bbox_by_point (&bbox, bbox.cx, y); break; case 'v': /* dy */ i++; if (parse_int (parts[i], &dy, err) == FALSE) return FALSE; extend_bbox_by_point (&bbox, bbox.cx, bbox.cy + dy); break; case 'H': /* x */ i++; if (parse_int (parts[i], &x, err) == FALSE) return FALSE; extend_bbox_by_point (&bbox, x, bbox.cy); break; case 'h': /* dx */ i++; if (parse_int (parts[i], &dx, err) == FALSE) return FALSE; extend_bbox_by_point (&bbox, bbox.cx + dx, bbox.cy); break; case 'a': rel = TRUE; G_GNUC_FALLTHROUGH; case 'A': { /* rx ry x-axis-rotation large-arc-flag sweep-flag x y */ int rx, ry, xrot; gboolean large, sweep; struct fbbox fbox; i++; if (parse_int (parts[i], &rx, err) == FALSE) return FALSE; i++; if (parse_int (parts[i], &ry, err) == FALSE) return FALSE; i++; if (parse_int (parts[i], &xrot, err) == FALSE) return FALSE; i++; if (parse_int (parts[i], &large, err) == FALSE) return FALSE; i++; if (parse_int (parts[i], &sweep, err) == FALSE) return FALSE; i++; if (parse_int (parts[i], &x, err) == FALSE) return FALSE; i++; if (parse_int (parts[i], &y, err) == FALSE) return FALSE; if (rel) { x = bbox.cx + x; y = bbox.cy + y; } fbox = bbox_arc (bbox.cx, bbox.cy, rx, ry, xrot, !!large, !!sweep, x, y); extend_bbox_by_frect (&bbox, &fbox); bbox.cx = x; bbox.cy = y; break; } case 'q': rel = TRUE; G_GNUC_FALLTHROUGH; case 'Q': { int cx, cy; struct fbbox fbox; /* control point */ i++; if (parse_int (parts[i], &cx, err) == FALSE) return FALSE; i++; if (parse_int (parts[i], &cy, err) == FALSE) return FALSE; /* end */ i++; if (parse_int (parts[i], &x, err) == FALSE) return FALSE; i++; if (parse_int (parts[i], &y, err) == FALSE) return FALSE; if (rel) { cx = bbox.cx + cx; cy = bbox.cy + cy; x = bbox.cx + x; y = bbox.cy + y; } fbox = bbox_quadratic_bezier (bbox.cx, bbox.cy, cx, cy, x, y); extend_bbox_by_frect (&bbox, &fbox); bbox.cx = x; bbox.cy = y; break; } case 'c': rel = TRUE; G_GNUC_FALLTHROUGH; case 'C': { int cx1, cy1, cx2, cy2; /* control point 1 */ i++; if (parse_int (parts[i], &cx1, err) == FALSE) return FALSE; i++; if (parse_int (parts[i], &cy1, err) == FALSE) return FALSE; i++; if (parse_int (parts[i], &cx2, err) == FALSE) return FALSE; i++; if (parse_int (parts[i], &cy2, err) == FALSE) return FALSE; /* end */ i++; if (parse_int (parts[i], &x, err) == FALSE) return FALSE; i++; if (parse_int (parts[i], &y, err) == FALSE) return FALSE; if (rel) { cx1 = bbox.cx + cx1; cy1 = bbox.cy + cy1; cx2 = bbox.cx + cx2; cy2 = bbox.cy + cy2; x = bbox.cx + x; y = bbox.cy + y; } #if 0 struct fbbox fbox; /* TODO properly calculate minimal bbox using derivate */ fbox = bbox_cubic_bezier (bbox.cx, bbox.cy, cx, cy, x, y); extend_bbox_by_frect (&bbox, &fbox); #else extend_bbox_by_point (&bbox, x, y); extend_bbox_by_point (&bbox, cx1, cy1); extend_bbox_by_point (&bbox, cx2, cy2); #endif bbox.cx = x; bbox.cy = y; break; } case 'Z': break; default: g_set_error (err, GM_ERROR, GM_ERROR_PARSING_FAILED, "Unknown command '%s'", cmd); return FALSE; } } *x1 = bbox.x1; *x2 = bbox.x2; *y1 = bbox.y1; *y2 = bbox.y2; return TRUE; } 0707010000009C000081A400000000000000000000000164F062AA000002C9000000000000000000000000000000000000003600000000feedbackd-0.2.1/subprojects/gmobile/src/gm-svg-path.h/* * Copyright (C) 2022 Guido Günther <agx@sigxcpu.org> * * SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once #if !defined(_GMOBILE_INSIDE) && !defined(GMOBILE_COMPILATION) #error "Only <gmobile.h> can be included directly." #endif #include <glib.h> G_BEGIN_DECLS gboolean gm_svg_path_get_bounding_box (const char *path, int *x1, int *x2, int *y1, int *y2, GError **err); G_END_DECLS 0707010000009D000081A400000000000000000000000164F062AA000016BE000000000000000000000000000000000000003500000000feedbackd-0.2.1/subprojects/gmobile/src/gm-timeout.c/* * Copyright (C) 2022 Purism SPC * * SPDX-License-Identifier: LGPL-2.1-or-later * * Author: Guido Günther <agx@sigxcpu.org> */ #include "gm-timeout.h" #include <fcntl.h> #include <unistd.h> #include <sys/timerfd.h> typedef struct _GmTimeoutOnce { GSource source; int fd; gpointer tag; gulong timeout_ms; gboolean armed; } GmTimeoutOnce; static gboolean gm_timeout_once_prepare (GSource *source, gint *timeout) { GmTimeoutOnce *timer = (GmTimeoutOnce *)source; struct itimerspec time_spec = { 0 }; int ret; if (timer->fd == -1) return FALSE; if (timer->armed) return FALSE; time_spec.it_value.tv_sec = timer->timeout_ms / 1000; time_spec.it_value.tv_nsec = (timer->timeout_ms % 1000) * 1000; ret = timerfd_settime (timer->fd, 0 /* flags */, &time_spec, NULL); if (ret) g_warning ("Failed to set up timer: %s", strerror (ret)); g_debug ("Prepared %p[%s] for %ld seconds", source, g_source_get_name (source)?: "(null)", timer->timeout_ms / 1000); timer->armed = TRUE; /* Never wake up the source due to a timeout */ *timeout = -1; return FALSE; } static gboolean gm_timeout_once_dispatch (GSource *source, GSourceFunc callback, void *data) { if (!callback) { g_warning ("Timeout source dispatched without callback. " "You must call g_source_set_callback()."); return G_SOURCE_REMOVE; } g_debug ("Dispatching %p[%s]", source, g_source_get_name (source)?: "(null)"); callback (data); return G_SOURCE_REMOVE; } static void gm_timeout_once_finalize (GSource *source) { GmTimeoutOnce *timer = (GmTimeoutOnce *) source; close (timer->fd); timer->fd = -1; timer->armed = FALSE; g_source_remove_unix_fd (source, timer->tag); timer->tag = NULL; g_debug ("Finalize %p[%s]", source, g_source_get_name (source)?: "(null)"); } static GSourceFuncs gm_timeout_once_source_funcs = { gm_timeout_once_prepare, NULL, /* check */ gm_timeout_once_dispatch, gm_timeout_once_finalize, }; static GSource * gm_timeout_source_once_new (gulong timeout_ms) { int fdf, fsf; GmTimeoutOnce *timer = (GmTimeoutOnce *) g_source_new (&gm_timeout_once_source_funcs, sizeof (GmTimeoutOnce)); timer->timeout_ms = timeout_ms; #if GLIB_CHECK_VERSION(2, 70, 0) g_source_set_static_name ((GSource *)timer, "[gm] boottime timeout source"); #endif timer->fd = timerfd_create (CLOCK_BOOTTIME, 0); if (timer->fd == -1) return (GSource*)timer; fdf = fcntl (timer->fd, F_GETFD) | FD_CLOEXEC; fcntl (timer->fd, F_SETFD, fdf); fsf = fcntl (timer->fd, F_GETFL) | O_NONBLOCK; fcntl (timer->fd, F_SETFL, fsf); timer->tag = g_source_add_unix_fd (&timer->source, timer->fd, G_IO_IN | G_IO_ERR); return (GSource*)timer; } /** * gm_timeout_add_seconds_once_full: (rename-to gm_timeout_add_seconds_once) * @priority: the priority of the timeout source. Typically this will be in * the range between %G_PRIORITY_DEFAULT and %G_PRIORITY_HIGH. * @seconds: the timeout in seconds * @function: function to call * @data: data to pass to @function * @notify: (nullable): function to call when the timeout is removed, or %NULL * * Sets a function to be called after a timeout with priority @priority. * Correctly calculates the timeout even when the system is suspended in between. * * This internally creates a main loop source using * g_timeout_source_new_seconds() and attaches it to the main loop context * using g_source_attach(). * * The timeout given is in terms of `CLOCK_BOOTTIME` time, it hence is also * correct across suspend and resume. If that doesn't matter use * `g_timeout_add_seconds_full` instead. * * Note that glib's `g_timeout_add_seconds()` doesn't take system * suspend/resume into account: https://gitlab.gnome.org/GNOME/glib/-/issues/2739 * * Returns: the ID (greater than 0) of the event source. **/ guint gm_timeout_add_seconds_once_full (gint priority, gulong seconds, GSourceFunc function, gpointer data, GDestroyNotify notify) { g_autoptr (GSource) source = NULL; guint id; g_return_val_if_fail (function != NULL, 0); source = gm_timeout_source_once_new (1000L * seconds); if (priority != G_PRIORITY_DEFAULT) g_source_set_priority (source, priority); g_source_set_callback (source, function, data, notify); id = g_source_attach (source, NULL); return id; } /** * gm_timeout_add_seconds_once: * @seconds: the timeout in seconds * @function: function to call * @data: data to pass to @function * * Sets a function to be called after a timeout with the default * priority, %G_PRIORITY_DEFAULT. Correctly calculates the timeout * even when the system is suspended in between. * * This internally creates a main loop source using * g_timeout_source_new_seconds() and attaches it to the main loop context * using g_source_attach(). * * The timeout given is in terms of `CLOCK_BOOTTIME` time, it hence is also * correct across suspend and resume. If that doesn't matter use * `g_timeout_add_seconds` instead. * * Note that glib's `g_timeout_add_seconds()` doesn't take system * suspend/resume into account: https://gitlab.gnome.org/GNOME/glib/-/issues/2739 * * Returns: the ID (greater than 0) of the event source. **/ guint gm_timeout_add_seconds_once (int seconds, GSourceFunc function, gpointer data) { g_return_val_if_fail (function != NULL, 0); return gm_timeout_add_seconds_once_full (G_PRIORITY_DEFAULT, seconds, function, data, NULL); } 0707010000009E000081A400000000000000000000000164F062AA000002A5000000000000000000000000000000000000003500000000feedbackd-0.2.1/subprojects/gmobile/src/gm-timeout.h/* * Copyright (C) 2022 Purism SPC * * SPDX-License-Identifier: LGPL-2.1-or-later * * Author: Guido Günther <agx@sigxcpu.org> */ #pragma once #if !defined(_GMOBILE_INSIDE) && !defined(GMOBILE_COMPILATION) #error "Only <gmobile.h> can be included directly." #endif #include <glib.h> G_BEGIN_DECLS guint gm_timeout_add_seconds_once_full (int priority, gulong seconds, GSourceFunc function, gpointer data, GDestroyNotify notify); guint gm_timeout_add_seconds_once (int seconds, GSourceFunc function, gpointer data); G_END_DECLS 0707010000009F000081A400000000000000000000000164F062AA00000207000000000000000000000000000000000000003200000000feedbackd-0.2.1/subprojects/gmobile/src/gmobile.h/* * Copyright (C) 2022 Purism SPC * * SPDX-License-Identifier: LGPL-2.1-or-later * * Author: Guido Günther <agx@sigxcpu.org> */ #pragma once #ifndef GMOBILE_USE_UNSTABLE_API #error gmobile is unstable API. You must define GMOBILE_USE_UNSTABLE_API before including gmobile.h #endif #define _GMOBILE_INSIDE #include "gm-config.h" #include "gm-cutout.h" #include "gm-device-info.h" #include "gm-device-tree.h" #include "gm-display-panel.h" #include "gm-error.h" #include "gm-main.h" #include "gm-timeout.h" 070701000000A0000081A400000000000000000000000164F062AA000005D6000000000000000000000000000000000000003400000000feedbackd-0.2.1/subprojects/gmobile/src/meson.buildgm_deps = [ gio_dep, glib_dep, json_glib_dep, cc.find_library('m', required: false), cc.find_library('rt', required: false), ] gm_public_sources = files( 'gmobile.h', 'gm-cutout.c', 'gm-cutout.h', 'gm-device-info.c', 'gm-device-info.h', 'gm-device-tree.c', 'gm-device-tree.h', 'gm-display-panel.c', 'gm-display-panel.h', 'gm-error.c', 'gm-error.h', 'gm-main.c', 'gm-main.h', 'gm-rect.c', 'gm-rect.h', 'gm-svg-path.c', 'gm-svg-path.h', 'gm-timeout.c', 'gm-timeout.h', ) gm_sources = [ gm_public_sources, gm_resources, ] gm_c_args = [ '-DG_LOG_DOMAIN="gmobile"', ] gm_lib = static_library( 'gmobile', gm_sources, include_directories: root_inc, c_args: gm_c_args, dependencies: gm_deps) gmobile_dep = declare_dependency( include_directories: [root_inc, include_directories('.')], dependencies: gm_deps, link_with: gm_lib) if get_option('gtk_doc') gmobile_gir_extra_args = [ '--c-include=gmobile.h', '-L@0@'.format(meson.current_build_dir()), '--quiet', '-DGMOBILE_USE_UNSTABLE_API', ] gmobile_gir = gnome.generate_gir(gm_lib, sources: gm_sources, nsversion: '0', namespace: 'Gm', export_packages: 'gmobile-0', symbol_prefix: 'gm', identifier_prefix: 'Gm', link_with: gm_lib, includes: ['Gio-2.0'], install: false, extra_args: gmobile_gir_extra_args, ) endif 070701000000A1000041ED00000000000000000000000264F062AA00000000000000000000000000000000000000000000003000000000feedbackd-0.2.1/subprojects/gmobile/subprojects070701000000A2000081A400000000000000000000000164F062AA0000009E000000000000000000000000000000000000003F00000000feedbackd-0.2.1/subprojects/gmobile/subprojects/gi-docgen.wrap[wrap-git] directory=gi-docgen url=https://gitlab.gnome.org/GNOME/gi-docgen.git push-url=ssh://git@gitlab.gnome.org:GNOME/gi-docgen.git revision=main depth=1 070701000000A3000081A400000000000000000000000164F062AA00000067000000000000000000000000000000000000003F00000000feedbackd-0.2.1/subprojects/gmobile/subprojects/json-glib.wrap[wrap-git] directory=json-glib url=https://gitlab.gnome.org/GNOME/json-glib.git revision=1.6.6 depth=1 070701000000A4000041ED00000000000000000000000264F062AA00000000000000000000000000000000000000000000002A00000000feedbackd-0.2.1/subprojects/gmobile/tests070701000000A5000041ED00000000000000000000000264F062AA00000000000000000000000000000000000000000000002F00000000feedbackd-0.2.1/subprojects/gmobile/tests/data070701000000A6000041ED00000000000000000000000264F062AA00000000000000000000000000000000000000000000003C00000000feedbackd-0.2.1/subprojects/gmobile/tests/data/compatibles1070701000000A7000041ED00000000000000000000000264F062AA00000000000000000000000000000000000000000000004500000000feedbackd-0.2.1/subprojects/gmobile/tests/data/compatibles1/firmware070701000000A8000041ED00000000000000000000000264F062AA00000000000000000000000000000000000000000000005000000000feedbackd-0.2.1/subprojects/gmobile/tests/data/compatibles1/firmware/devicetree070701000000A9000041ED00000000000000000000000264F062AA00000000000000000000000000000000000000000000005500000000feedbackd-0.2.1/subprojects/gmobile/tests/data/compatibles1/firmware/devicetree/base070701000000AA000081A400000000000000000000000164F062AA0000002B000000000000000000000000000000000000006000000000feedbackd-0.2.1/subprojects/gmobile/tests/data/compatibles1/firmware/devicetree/base/compatiblepurism,librem5r4purism,librem5fsl,imx8mq070701000000AB000041ED00000000000000000000000264F062AA00000000000000000000000000000000000000000000003C00000000feedbackd-0.2.1/subprojects/gmobile/tests/data/compatibles2070701000000AC000041ED00000000000000000000000264F062AA00000000000000000000000000000000000000000000004500000000feedbackd-0.2.1/subprojects/gmobile/tests/data/compatibles2/firmware070701000000AD000041ED00000000000000000000000264F062AA00000000000000000000000000000000000000000000005000000000feedbackd-0.2.1/subprojects/gmobile/tests/data/compatibles2/firmware/devicetree070701000000AE000041ED00000000000000000000000264F062AA00000000000000000000000000000000000000000000005500000000feedbackd-0.2.1/subprojects/gmobile/tests/data/compatibles2/firmware/devicetree/base070701000000AF000081A400000000000000000000000164F062AA00000000000000000000000000000000000000000000006000000000feedbackd-0.2.1/subprojects/gmobile/tests/data/compatibles2/firmware/devicetree/base/compatible070701000000B0000081A400000000000000000000000164F062AA00000259000000000000000000000000000000000000003600000000feedbackd-0.2.1/subprojects/gmobile/tests/meson.buildif get_option('tests') test_env = [ 'G_DEBUG=gc-friendly,fatal-warnings', 'MALLOC_CHECK_=2', 'NO_AT_BRIDGE=1', ] test_cflags = [ '-DTEST_DATA_DIR="@0@"'.format(join_paths(meson.current_source_dir(), 'data')), ] tests = [ 'device-tree', 'display-panel', 'cutout', 'svg-path', 'timeout', ] foreach test : tests t = executable('test-@0@'.format(test), ['test-@0@.c'.format(test)], c_args : test_cflags, pie: true, link_with: gm_lib, dependencies: gmobile_dep) test(test, t, env: test_env) endforeach endif 070701000000B1000081A400000000000000000000000164F062AA00000358000000000000000000000000000000000000003800000000feedbackd-0.2.1/subprojects/gmobile/tests/test-cutout.c/* * Copyright (C) 2022 Guido Günther <agx@sigxcpu.org> * * SPDX-License-Identifier: GPL-3-or-later */ #define GMOBILE_USE_UNSTABLE_API #include "gmobile.h" static void test_gm_cutout_bounding_box (void) { char *path = "M455, 0 \ V 79 \ H 625 \ V 0 \ Z"; g_autoptr (GError) err = NULL; GmCutout *cutout; const GmRect *rect; cutout = gm_cutout_new (path); g_assert_no_error (err); rect = gm_cutout_get_bounds (cutout); g_assert_cmpint (rect->x, ==, 455); g_assert_cmpint (rect->y, ==, 0); g_assert_cmpint (rect->width, ==, 170); g_assert_cmpint (rect->height, ==, 79); } gint main (gint argc, gchar *argv[]) { g_test_init (&argc, &argv, NULL); g_test_add_func ("/Gm/cutout/bounding-box", test_gm_cutout_bounding_box); return g_test_run (); } 070701000000B2000081A400000000000000000000000164F062AA000005AA000000000000000000000000000000000000003D00000000feedbackd-0.2.1/subprojects/gmobile/tests/test-device-tree.c/* * Copyright (C) 2022 Guido Günther <agx@sigxcpu.org> * * SPDX-License-Identifier: GPL-3-or-later */ #define GMOBILE_USE_UNSTABLE_API #include "gmobile.h" #include "gio/gio.h" static void test_gm_device_tree_get_compatibles (void) { g_auto (GStrv) compatibles = NULL; GError *err = NULL; /* nonexistent */ compatibles = gm_device_tree_get_compatibles (TEST_DATA_DIR "/doesnotexist", &err); g_assert_null (compatibles); g_assert_error (err, G_IO_ERROR, G_IO_ERROR_NOT_FOUND); g_clear_error (&err); /* nonexistent, don't store error */ compatibles = gm_device_tree_get_compatibles (TEST_DATA_DIR "/doesnotexist", NULL); g_assert_null (compatibles); /* Regular format */ compatibles = gm_device_tree_get_compatibles (TEST_DATA_DIR "/compatibles1", &err); g_assert_no_error (err); g_assert_nonnull (compatibles); g_assert_cmpstr (compatibles[0], ==, "purism,librem5r4"); g_assert_cmpstr (compatibles[1], ==, "purism,librem5"); g_assert_cmpstr (compatibles[2], ==, "fsl,imx8mq"); g_assert_null (compatibles[3]); g_strfreev (compatibles); /* empty file */ compatibles = gm_device_tree_get_compatibles (TEST_DATA_DIR "/compatibles2", &err); g_assert_no_error (err); g_assert_nonnull (compatibles); } gint main (gint argc, gchar *argv[]) { g_test_init (&argc, &argv, NULL); g_test_add_func ("/Gm/device-tree/get-compatibles", test_gm_device_tree_get_compatibles); return g_test_run (); } 070701000000B3000081A400000000000000000000000164F062AA00000954000000000000000000000000000000000000003F00000000feedbackd-0.2.1/subprojects/gmobile/tests/test-display-panel.c/* * Copyright (C) 2022 Guido Günther <agx@sigxcpu.org> * * SPDX-License-Identifier: GPL-3-or-later */ #define GMOBILE_USE_UNSTABLE_API #include "gmobile.h" static void test_gm_display_panel_parse (void) { const char *json = " " "{ " " \"name\": \"Oneplus 6T\", " " \"x-res\": 1080, " " \"y-res\": 2340, " " \"border-radius\": 10, " " \"width\": 68, " " \"height\": 145, " " \"cutouts\" : [ " " { " " \"name\": \"notch\", " " \"path\": \"M 455 0 V 79 H 625 V 0 Z\" " " } " " ] " "} "; g_autoptr (GError) err = NULL; g_autoptr (GmDisplayPanel) panel = NULL; g_autoptr (GmCutout) cutout = NULL; GListModel *cutouts; const GmRect *bounds; panel = gm_display_panel_new_from_data (json, &err); g_assert_no_error (err); g_assert_nonnull (panel); cutouts = gm_display_panel_get_cutouts (panel); g_assert_cmpint (g_list_model_get_n_items (cutouts), ==, 1); cutout = g_list_model_get_item (cutouts, 0); g_assert_nonnull (cutout); g_assert_cmpstr (gm_cutout_get_name (cutout), ==, "notch"); g_assert_cmpstr (gm_cutout_get_path (cutout), ==, "M 455 0 V 79 H 625 V 0 Z"); bounds = gm_cutout_get_bounds (cutout); g_assert_cmpint (bounds->x, ==, 455); g_assert_cmpint (bounds->y, ==, 0); g_assert_cmpint (bounds->width, ==, 170); g_assert_cmpint (bounds->height, ==, 79); g_assert_cmpint (gm_display_panel_get_x_res (panel), ==, 1080); g_assert_cmpint (gm_display_panel_get_y_res (panel), ==, 2340); g_assert_cmpint (gm_display_panel_get_border_radius (panel), ==, 10); g_assert_cmpint (gm_display_panel_get_width (panel), ==, 68); g_assert_cmpint (gm_display_panel_get_height (panel), ==, 145); } gint main (gint argc, gchar *argv[]) { g_test_init (&argc, &argv, NULL); g_test_add_func ("/Gm/display-panel/parse", test_gm_display_panel_parse); return g_test_run (); } 070701000000B4000081A400000000000000000000000164F062AA00000D4A000000000000000000000000000000000000003A00000000feedbackd-0.2.1/subprojects/gmobile/tests/test-svg-path.c/* * Copyright (C) 2022 Guido Günther <agx@sigxcpu.org> * * SPDX-License-Identifier: GPL-3-or-later */ #define GMOBILE_USE_UNSTABLE_API #include "gm-svg-path.h" #include "gio/gio.h" static void test_gm_svg_path_get_bounding_box_abs (void) { const char *path = "M455, 0 \ V 79 \ H 625 \ V 0 \ Z "; gboolean success; int x1, x2, y1, y2; g_autoptr (GError) err = NULL; success = gm_svg_path_get_bounding_box (path, &x1, &x2, &y1, &y2, &err); g_assert_no_error (err); g_assert_true (success); g_assert_cmpint (x1, ==, 455); g_assert_cmpint (x2, ==, 625); g_assert_cmpint (y1, ==, 0); g_assert_cmpint (y2, ==, 79); } static void test_gm_svg_path_get_bounding_box_rel (void) { const char *path = "m 455 0 \ v 79 \ h 170 \ v 0 \ Z"; gboolean success; int x1, x2, y1, y2; g_autoptr (GError) err = NULL; success = gm_svg_path_get_bounding_box (path, &x1, &x2, &y1, &y2, &err); g_assert_no_error (err); g_assert_true (success); g_assert_cmpint (x1, ==, 455); g_assert_cmpint (x2, ==, 625); g_assert_cmpint (y1, ==, 0); g_assert_cmpint (y2, ==, 79); } static void test_gm_svg_path_get_bounding_box_arc (void) { const char *path = "M 10 315\n" "L 110 215\n" "A 30 50 0 0 1 162 160"; gboolean success; int x1, x2, y1, y2; g_autoptr (GError) err = NULL; success = gm_svg_path_get_bounding_box (path, &x1, &x2, &y1, &y2, &err); g_assert_no_error (err); g_assert_true (success); g_assert_cmpint (x1, ==, 10); g_assert_cmpint (x2, ==, 162); g_assert_cmpint (y1, ==, 136); g_assert_cmpint (y2, ==, 315); } static void test_gm_svg_path_get_bounding_box_quad_bezier (void) { /* control point not between start and end */ const char *path1 = "M 70 250 Q 20 110 220 60 Z"; /* same but in relative */ const char *path1_rel = "M 70 250 q -50 -140 150 -190 Z"; /* control point between start and end */ const char *path2 = "M 70 250 Q 110 110 220 60 Z"; gboolean success; int x1, x2, y1, y2; g_autoptr (GError) err = NULL; success = gm_svg_path_get_bounding_box (path1, &x1, &x2, &y1, &y2, &err); g_assert_no_error (err); g_assert_true (success); g_assert_cmpint (x1, ==, 60); g_assert_cmpint (x2, ==, 220); g_assert_cmpint (y1, ==, 60); g_assert_cmpint (y2, ==, 250); success = gm_svg_path_get_bounding_box (path1_rel, &x1, &x2, &y1, &y2, &err); g_assert_no_error (err); g_assert_true (success); g_assert_cmpint (x1, ==, 60); g_assert_cmpint (x2, ==, 220); g_assert_cmpint (y1, ==, 60); g_assert_cmpint (y2, ==, 250); success = gm_svg_path_get_bounding_box (path2, &x1, &x2, &y1, &y2, &err); g_assert_no_error (err); g_assert_true (success); g_assert_cmpint (x1, ==, 70); g_assert_cmpint (x2, ==, 220); g_assert_cmpint (y1, ==, 60); g_assert_cmpint (y2, ==, 250); } gint main (gint argc, gchar *argv[]) { g_test_init (&argc, &argv, NULL); g_test_add_func ("/Gm/svg-path/bounding_box/abs", test_gm_svg_path_get_bounding_box_abs); g_test_add_func ("/Gm/svg-path/bounding_box/rel", test_gm_svg_path_get_bounding_box_rel); g_test_add_func ("/Gm/svg-path/bounding_box/arc", test_gm_svg_path_get_bounding_box_arc); g_test_add_func ("/Gm/svg-path/bounding_box/quad_bezier", test_gm_svg_path_get_bounding_box_quad_bezier); return g_test_run (); } 070701000000B5000081A400000000000000000000000164F062AA0000061E000000000000000000000000000000000000003900000000feedbackd-0.2.1/subprojects/gmobile/tests/test-timeout.c/* * Copyright (C) 2022 Purism SPC * * SPDX-License-Identifier: GPL-3-or-later * * Author: Guido Günther <agx@sigxcpu.org> */ #define GMOBILE_USE_UNSTABLE_API #include "gmobile.h" static gboolean on_timeout (gpointer data) { g_main_loop_quit (data); return G_SOURCE_REMOVE; } static void test_gm_timeout_simple (void) { g_autoptr (GMainLoop) loop = NULL; int seconds = 1; loop = g_main_loop_new (NULL, FALSE); gm_timeout_add_seconds_once (seconds, (GSourceFunc)on_timeout, loop); g_main_loop_run (loop); } static gboolean on_timeout2 (gpointer data) { g_assert_not_reached (); return G_SOURCE_REMOVE; } static gboolean remove_timeout (gpointer data) { g_source_remove (GPOINTER_TO_UINT (data)); return G_SOURCE_REMOVE; } static void test_gm_timeout_remove (void) { g_autoptr (GMainLoop) loop = NULL; guint id; loop = g_main_loop_new (NULL, FALSE); id = gm_timeout_add_seconds_once (1, (GSourceFunc)on_timeout2, NULL); g_assert_nonnull (g_main_context_find_source_by_id (NULL, id)); g_idle_add (remove_timeout, GUINT_TO_POINTER (id)); /* End the main loop, id must not have fired yet */ g_timeout_add_seconds (2, (GSourceFunc)on_timeout, loop); g_main_loop_run (loop); /* source got removed */ g_assert_null (g_main_context_find_source_by_id (NULL, id)); } gint main (gint argc, gchar *argv[]) { g_test_init (&argc, &argv, NULL); g_test_add_func ("/Gm/timeout/simple", test_gm_timeout_simple); g_test_add_func ("/Gm/timeout/remove", test_gm_timeout_remove); return g_test_run (); } 070701000000B6000041ED00000000000000000000000264F062AA00000000000000000000000000000000000000000000001600000000feedbackd-0.2.1/tests070701000000B7000041ED00000000000000000000000264F062AA00000000000000000000000000000000000000000000001B00000000feedbackd-0.2.1/tests/data070701000000B8000041ED00000000000000000000000264F062AA00000000000000000000000000000000000000000000002200000000feedbackd-0.2.1/tests/data/parent070701000000B9000081A400000000000000000000000164F062AA0000022B000000000000000000000000000000000000002C00000000feedbackd-0.2.1/tests/data/parent/base.json{ "name" : "base", "profiles" : [ { "name" : "full", "feedbacks" : [ { "type" : "Dummy", "event-name" : "test-dummy-00", "duration" : 0x01 }, { "type" : "Dummy", "event-name" : "test-dummy-01", "duration" : 0x02 } ] }, { "name" : "quiet", "feedbacks" : [ { "type" : "Dummy", "event-name" : "test-dummy-00", "duration" : 0x03 } ] } ] } 070701000000BA000081A400000000000000000000000164F062AA000002ED000000000000000000000000000000000000002C00000000feedbackd-0.2.1/tests/data/parent/test.json{ "name" : "test", "profiles" : [ { "name" : "full", "feedbacks" : [ { "type" : "Dummy", "event-name" : "test-dummy-00", "duration" : 0x10 }, { "type" : "Dummy", "event-name" : "test-dummy-10", "duration" : 0x20 } ] }, { "name" : "quiet", "feedbacks" : [ { "type" : "Dummy", "event-name" : "test-dummy-10", "duration" : 0x30 } ] }, { "name" : "silent", "feedbacks" : [ { "type" : "Dummy", "event-name" : "test-dummy-10", "duration" : 0x40 } ] } ] } 070701000000BB000081A400000000000000000000000164F062AA00000294000000000000000000000000000000000000002500000000feedbackd-0.2.1/tests/data/test.json{ "name" : "default", "profiles" : [ { "name" : "full", "feedbacks" : [ { "type" : "Dummy", "event-name" : "test-dummy-0" }, { "type" : "Dummy", "event-name" : "test-dummy-10", "duration" : 10000 } ] }, { "name" : "quiet", "feedbacks" : [ { "type" : "Dummy", "event-name" : "test-dummy-0" }, { "type" : "Dummy", "event-name" : "test-dummy-10", "duration" : 10000 } ] }, { "name" : "silent" } ] } 070701000000BC000041ED00000000000000000000000264F062AA00000000000000000000000000000000000000000000002700000000feedbackd-0.2.1/tests/data/user-config070701000000BD000041ED00000000000000000000000264F062AA00000000000000000000000000000000000000000000003100000000feedbackd-0.2.1/tests/data/user-config/feedbackd070701000000BE000041ED00000000000000000000000264F062AA00000000000000000000000000000000000000000000003800000000feedbackd-0.2.1/tests/data/user-config/feedbackd/themes070701000000BF000081A400000000000000000000000164F062AA00000186000000000000000000000000000000000000004400000000feedbackd-0.2.1/tests/data/user-config/feedbackd/themes/custom.json{ "name" : "custom", "parent-name": "default", "profiles" : [ { "name" : "full", "feedbacks" : [ { "event-name" : "test-dummy-0", "type" : "Dummy", "duration" : 0x10 }, { "event-name" : "test-dummy-2", "type" : "Dummy", "duration" : 0x30 } ] } ] } 070701000000C0000041ED00000000000000000000000264F062AA00000000000000000000000000000000000000000000002400000000feedbackd-0.2.1/tests/data/xdg-data070701000000C1000041ED00000000000000000000000264F062AA00000000000000000000000000000000000000000000002E00000000feedbackd-0.2.1/tests/data/xdg-data/feedbackd070701000000C2000041ED00000000000000000000000264F062AA00000000000000000000000000000000000000000000003500000000feedbackd-0.2.1/tests/data/xdg-data/feedbackd/themes070701000000C3000081A400000000000000000000000164F062AA00000035000000000000000000000000000000000000004200000000feedbackd-0.2.1/tests/data/xdg-data/feedbackd/themes/chainup.json{ "name" : "$device", "parent-name": "default" } 070701000000C4000081A400000000000000000000000164F062AA0000022D000000000000000000000000000000000000004200000000feedbackd-0.2.1/tests/data/xdg-data/feedbackd/themes/default.json{ "name" : "default", "profiles" : [ { "name" : "full", "feedbacks" : [ { "event-name" : "test-dummy-0", "type" : "Dummy" }, { "event-name" : "test-dummy-1", "type" : "Dummy" } ] }, { "name" : "quiet", "feedbacks" : [ { "event-name" : "test-dummy-0", "type" : "Dummy" }, { "event-name" : "test-dummy-1", "type" : "Dummy" } ] } ] } 070701000000C5000081A400000000000000000000000164F062AA00000187000000000000000000000000000000000000004200000000feedbackd-0.2.1/tests/data/xdg-data/feedbackd/themes/replace.json{ "name" : "$device", "parent-name": "default", "profiles" : [ { "name" : "full", "feedbacks" : [ { "event-name" : "test-dummy-0", "type" : "Dummy", "duration" : 0x10 }, { "event-name" : "test-dummy-2", "type" : "Dummy", "duration" : 0x20 } ] } ] } 070701000000C6000081A400000000000000000000000164F062AA000008E4000000000000000000000000000000000000002200000000feedbackd-0.2.1/tests/meson.buildif get_option('tests') test_env = environment() test_env.set('G_TEST_SRCDIR', meson.current_source_dir()) test_env.set('G_TEST_BUILDDIR', meson.current_build_dir()) test_env.set('G_DEBUG', 'gc-friendly,fatal-warnings') test_env.set('GSETTINGS_BACKEND', 'memory') test_env.set('GSETTINGS_SCHEMA_DIR', '@0@/data'.format(meson.project_build_root())) test_env.set('PYTHONDONTWRITEBYTECODE', 'yes') test_env.set('MALLOC_CHECK_', '2') test_env.set('XDG_CONFIG_HOME', meson.current_source_dir() / 'data' / 'user-config') test_env.set('XDG_CONFIG_DIRS', meson.current_source_dir()) # Shared library Unit tests test_lfb_cflags = [ '-DTEST_APP_ID="org.sigxcpu.feedbackd_test"', '-DLIBFEEDBACK_USE_UNSTABLE_API', '-DTEST_DATA_DIR="@0@"'.format(join_paths(meson.current_source_dir(), 'data')), ] test_lfb_link_args = [ '-fPIC', ] test_lfb_deps = [ libfeedback_dep, glib, gio_unix, ] lfb_tests = [ 'lfb-event', ] if get_option ('daemon') # The integration test needs the daemon lfb_tests += 'lfb-integration' subdir('services') endif foreach test : lfb_tests t = executable('test-@0@'.format(test), ['test-@0@.c'.format(test)], c_args : test_lfb_cflags, pie : true, link_args : test_lfb_link_args, dependencies : test_lfb_deps) test(test, t, env: test_env) endforeach # Daemon Unit tests if get_option('daemon') test_env_fbd = test_env test_env_fbd.set('XDG_DATA_DIRS', meson.current_source_dir() / 'data' / 'xdg-data') test_fbd_cflags = [ '-DTEST_APP_ID="org.sigxcpu.feedbackd_test"', '-DTEST_DATA_DIR="@0@"'.format(join_paths(meson.current_source_dir(), 'data')), ] test_fbd_link_args = [ '-fPIC', ] test_fbd_deps = [ fbd_dep, ] fbd_tests = [ 'fbd-feedback-profile', 'fbd-feedback-theme', 'fbd-event', 'fbd-theme-expander', ] foreach test : fbd_tests t = executable('test-@0@'.format(test), ['test-@0@.c'.format(test), generated_dbus_sources[1]], c_args : test_fbd_cflags, pie : true, link_args : test_fbd_link_args, include_directories : fbd_inc, dependencies : test_fbd_deps) test(test, t, env : test_env_fbd) endforeach endif # daemon endif 070701000000C7000041ED00000000000000000000000264F062AA00000000000000000000000000000000000000000000001F00000000feedbackd-0.2.1/tests/services070701000000C8000081A400000000000000000000000164F062AA000000FA000000000000000000000000000000000000002B00000000feedbackd-0.2.1/tests/services/meson.buildservice_file = 'org.sigxcpu.Feedback.service' service_data = configuration_data() service_data.set('ABS_BUILDDIR', meson.project_build_root()) configure_file( input : service_file + '.in', output : service_file, configuration : service_data ) 070701000000C9000081A400000000000000000000000164F062AA00000060000000000000000000000000000000000000003F00000000feedbackd-0.2.1/tests/services/org.sigxcpu.Feedback.service.in[D-BUS Service] Name=org.sigxcpu.Feedback Exec=@ABS_BUILDDIR@/run @ABS_BUILDDIR@/src/feedbackd 070701000000CA000081A400000000000000000000000164F062AA000015EC000000000000000000000000000000000000002700000000feedbackd-0.2.1/tests/test-fbd-event.c/* * Copyright (C) 2020 Purism SPC * SPDX-License-Identifier: GPL-3.0+ * Author: Guido Günther <agx@sigxcpu.org> */ #include "fbd-event.h" #include "fbd-feedback-dummy.h" #define TEST_EVENT "window-close" static void test_fbd_event (void) { g_autoptr(FbdEvent) event = NULL; g_autofree gchar *appid = NULL; g_autofree gchar *name = NULL; g_autofree gchar *sender = NULL; FbdEventEndReason reason; gint timeout; event = fbd_event_new (1, TEST_APP_ID, TEST_EVENT, 2, "sender-id"); g_assert_true (FBD_IS_EVENT (event)); g_object_get (event, "end-reason", &reason, "event", &name, "app-id", &appid, "timeout", &timeout, "sender", &sender, NULL); g_assert_cmpstr (fbd_event_get_event (event), ==, TEST_EVENT); g_assert_cmpstr (name, ==, TEST_EVENT); g_assert_cmpstr (fbd_event_get_app_id (event), ==, TEST_APP_ID); g_assert_cmpstr (appid, ==, TEST_APP_ID); g_assert_cmpint (fbd_event_get_timeout (event), ==, timeout); g_assert_cmpint (timeout, ==, 2); g_assert_cmpstr (fbd_event_get_sender (event), ==, sender); g_assert_cmpstr (sender, ==, "sender-id"); g_assert_cmpint (fbd_event_get_end_reason (event), ==, FBD_EVENT_END_REASON_NATURAL); g_assert_cmpint (reason, ==, FBD_EVENT_END_REASON_NATURAL); } static void test_fbd_event_feedback (void) { GSList *feedbacks; g_autoptr(FbdEvent) event = NULL; g_autoptr(FbdFeedbackDummy) feedback1 = NULL; g_autoptr(FbdFeedbackDummy) feedback2 = NULL; event = fbd_event_new (1, TEST_APP_ID, TEST_EVENT, -1, NULL); feedback1 = g_object_new (FBD_TYPE_FEEDBACK_DUMMY, NULL); feedback2 = g_object_new (FBD_TYPE_FEEDBACK_DUMMY, NULL); feedbacks = fbd_event_get_feedbacks (event); g_assert_cmpint (g_slist_length (feedbacks), ==, 0); fbd_event_add_feedback (event, FBD_FEEDBACK_BASE(feedback1)); feedbacks = fbd_event_get_feedbacks (event); g_assert_cmpint (g_slist_length (feedbacks), ==, 1); /* Remove non existing feedback */ fbd_event_remove_feedback (event, FBD_FEEDBACK_BASE(feedback2)); feedbacks = fbd_event_get_feedbacks (event); g_assert_cmpint (g_slist_length (feedbacks), ==, 1); fbd_event_remove_feedback (event, FBD_FEEDBACK_BASE(feedback1)); feedbacks = fbd_event_get_feedbacks (event); g_assert_cmpint (g_slist_length (feedbacks), ==, 0); fbd_event_add_feedback (event, FBD_FEEDBACK_BASE(feedback1)); fbd_event_add_feedback (event, FBD_FEEDBACK_BASE(feedback2)); feedbacks = fbd_event_get_feedbacks (event); g_assert_cmpint (g_slist_length (feedbacks), ==, 2); g_assert_false (fbd_event_get_feedbacks_ended (event)); fbd_event_end_feedbacks (event); /* Dummy feedback ends immediately */ g_assert_true (fbd_event_get_feedbacks_ended (event)); } static void on_feedbacks_ended (FbdEvent *event, gboolean *ended) { FBD_IS_EVENT (event); *ended = TRUE; } static void test_fbd_event_feedback_ended (void) { g_autoptr(FbdEvent) event = NULL; g_autoptr(FbdFeedbackDummy) feedback1 = NULL; g_autoptr(FbdFeedbackDummy) feedback2 = NULL; gboolean ended = FALSE; event = fbd_event_new (1, TEST_APP_ID, TEST_EVENT, FBD_EVENT_TIMEOUT_ONESHOT, NULL); feedback1 = g_object_new (FBD_TYPE_FEEDBACK_DUMMY, NULL); fbd_event_add_feedback (event, FBD_FEEDBACK_BASE(feedback1)); feedback2 = g_object_new (FBD_TYPE_FEEDBACK_DUMMY, NULL); fbd_event_add_feedback (event, FBD_FEEDBACK_BASE(feedback2)); g_signal_connect (event, "feedbacks-ended", (GCallback)on_feedbacks_ended, &ended); fbd_event_end_feedbacks (event); g_assert_true (ended); } static void test_fbd_event_feedback_loop (void) { g_autoptr(FbdEvent) event = NULL; g_autoptr(FbdFeedbackDummy) feedback1 = NULL; g_autoptr(FbdFeedbackDummy) feedback2 = NULL; gboolean ended = FALSE; event = fbd_event_new (1, TEST_APP_ID, TEST_EVENT, FBD_EVENT_TIMEOUT_LOOP, NULL); feedback1 = g_object_new (FBD_TYPE_FEEDBACK_DUMMY, NULL); fbd_event_add_feedback (event, FBD_FEEDBACK_BASE(feedback1)); feedback2 = g_object_new (FBD_TYPE_FEEDBACK_DUMMY, NULL); fbd_event_add_feedback (event, FBD_FEEDBACK_BASE(feedback2)); g_signal_connect (event, "feedbacks-ended", (GCallback)on_feedbacks_ended, &ended); g_assert_false (ended); fbd_event_end_feedbacks (event); g_assert_true (ended); } static void test_fbd_event_feedback_timeout (void) { g_autoptr(FbdEvent) event = NULL; g_autoptr(FbdFeedbackDummy) feedback1 = NULL; g_autoptr(FbdFeedbackDummy) feedback2 = NULL; gboolean ended = FALSE; event = fbd_event_new (1, TEST_APP_ID, TEST_EVENT, 1, NULL); feedback1 = g_object_new (FBD_TYPE_FEEDBACK_DUMMY, NULL); fbd_event_add_feedback (event, FBD_FEEDBACK_BASE(feedback1)); feedback2 = g_object_new (FBD_TYPE_FEEDBACK_DUMMY, NULL); fbd_event_add_feedback (event, FBD_FEEDBACK_BASE(feedback2)); g_signal_connect (event, "feedbacks-ended", (GCallback)on_feedbacks_ended, &ended); g_assert_false (ended); fbd_event_end_feedbacks (event); g_assert_true (ended); } gint main (gint argc, gchar *argv[]) { g_test_init (&argc, &argv, NULL); g_test_add_func("/feedbackd/fbd/event/new", test_fbd_event); g_test_add_func("/feedbackd/fbd/event/feedbacks/props", test_fbd_event_feedback); g_test_add_func("/feedbackd/fbd/event/feedbacks/ended", test_fbd_event_feedback_ended); g_test_add_func("/feedbackd/fbd/event/feedbacks/loop", test_fbd_event_feedback_loop); g_test_add_func("/feedbackd/fbd/event/feedbacks/timeout", test_fbd_event_feedback_timeout); return g_test_run(); } 070701000000CB000081A400000000000000000000000164F062AA00001422000000000000000000000000000000000000003200000000feedbackd-0.2.1/tests/test-fbd-feedback-profile.c/* * Copyright (C) 2020 Purism SPC * SPDX-License-Identifier: GPL-3.0+ * Author: Guido Günther <agx@sigxcpu.org> */ #include "fbd-feedback-profile.h" #include "fbd-feedback-dummy.h" #include "fbd-feedback-vibra.h" #include <json-glib/json-glib.h> #define PROFILE_NAME "test" static void test_fbd_feedback_profile_name (void) { g_autoptr(FbdFeedbackProfile) profile = fbd_feedback_profile_new (PROFILE_NAME); g_assert_true (FBD_IS_FEEDBACK_PROFILE (profile)); g_assert_cmpstr (fbd_feedback_profile_get_name (profile), ==, PROFILE_NAME); } static void test_fbd_feedback_profile_feedbacks (void) { GHashTable *feedbacks; FbdFeedbackBase *fb; g_autoptr (FbdFeedbackDummy) fb1 = g_object_new (FBD_TYPE_FEEDBACK_DUMMY, "event-name", "event1", NULL); g_autoptr (FbdFeedbackDummy) fb2 = g_object_new (FBD_TYPE_FEEDBACK_DUMMY, "event-name", "event2", NULL); g_autoptr(FbdFeedbackProfile) profile = fbd_feedback_profile_new (PROFILE_NAME); g_assert_true (FBD_IS_FEEDBACK_PROFILE (profile)); g_object_get (profile, "feedbacks", &feedbacks, NULL); g_assert_nonnull (feedbacks); g_hash_table_unref (feedbacks); fbd_feedback_profile_add_feedback (profile, FBD_FEEDBACK_BASE(fb1)); fbd_feedback_profile_add_feedback (profile, FBD_FEEDBACK_BASE(fb2)); fb = fbd_feedback_profile_get_feedback (profile, "event1"); g_assert_cmpstr (fbd_feedback_get_event_name (fb), ==, "event1"); fb = fbd_feedback_profile_get_feedback (profile, "does-not-exist"); g_assert_null (fb); } static void test_fbd_feedback_profile_parse (void) { const char *json =" " " { " " \"name\" : \"full\", " " \"feedbacks\" : [ " " { " " \"type\" : \"vibra\", " " \"event-name\" : \"event1\" " " }, " " { " " \"type\" : \"dummy\", " " \"event-name\" : \"event2\" " " } " " ] " " } "; g_autoptr (GError) err = NULL; g_autoptr (FbdFeedbackProfile) profile = NULL; g_autoptr (JsonNode) node = NULL; FbdFeedbackBase *fb; node = json_from_string(json, &err); g_assert_no_error (err); profile = FBD_FEEDBACK_PROFILE (json_gobject_deserialize (FBD_TYPE_FEEDBACK_PROFILE, node)); g_assert_nonnull (profile); fb = fbd_feedback_profile_get_feedback (profile, "event2"); g_assert_true (FBD_IS_FEEDBACK_DUMMY(fb)); fb = fbd_feedback_profile_get_feedback (profile, "event1"); g_assert_true (FBD_IS_FEEDBACK_VIBRA(fb)); } static void test_fbd_feedback_profile_update (void) { FbdFeedbackBase *fb; FbdFeedbackProfile *a = fbd_feedback_profile_new (PROFILE_NAME); FbdFeedbackProfile *b = fbd_feedback_profile_new (PROFILE_NAME); g_autoptr (FbdFeedbackDummy) fb_a_1 = g_object_new (FBD_TYPE_FEEDBACK_DUMMY, "event-name", "a-1", NULL); g_autoptr (FbdFeedbackDummy) fb_a_2 = g_object_new (FBD_TYPE_FEEDBACK_DUMMY, "event-name", "a-2", NULL); /* New event */ g_autoptr (FbdFeedbackDummy) fb_b_1 = g_object_new (FBD_TYPE_FEEDBACK_DUMMY, "event-name", "b-1", NULL); /* overwrite existing event */ g_autoptr (FbdFeedbackDummy) fb_b_2 = g_object_new (FBD_TYPE_FEEDBACK_VIBRA, "event-name", "a-2", NULL); fbd_feedback_profile_add_feedback (a, FBD_FEEDBACK_BASE(fb_a_1)); fbd_feedback_profile_add_feedback (a, FBD_FEEDBACK_BASE(fb_a_2)); fbd_feedback_profile_add_feedback (b, FBD_FEEDBACK_BASE(fb_b_1)); fbd_feedback_profile_add_feedback (b, FBD_FEEDBACK_BASE(fb_b_2)); fbd_feedback_profile_update (a,b); fb = fbd_feedback_profile_get_feedback (a, "a-1"); g_assert_true (FBD_IS_FEEDBACK_DUMMY(fb)); fb = fbd_feedback_profile_get_feedback (a, "a-2"); g_assert_true (FBD_IS_FEEDBACK_VIBRA(fb)); fb = fbd_feedback_profile_get_feedback (a, "b-1"); g_assert_true (FBD_IS_FEEDBACK_DUMMY(fb)); g_assert_finalize_object (b); g_assert_finalize_object (a); } gint main (gint argc, gchar *argv[]) { g_test_init (&argc, &argv, NULL); g_test_add_func("/feedbackd/fbd/feedback-profile/name", test_fbd_feedback_profile_name); g_test_add_func("/feedbackd/fbd/feedback-profile/feedbacks", test_fbd_feedback_profile_feedbacks); g_test_add_func("/feedbackd/fbd/feedback-profile/parse", test_fbd_feedback_profile_parse); g_test_add_func("/feedbackd/fbd/feedback-profile/update", test_fbd_feedback_profile_update); return g_test_run(); } 070701000000CC000081A400000000000000000000000164F062AA00001DE4000000000000000000000000000000000000003000000000feedbackd-0.2.1/tests/test-fbd-feedback-theme.c/* * Copyright (C) 2020 Purism SPC * SPDX-License-Identifier: GPL-3.0+ * Author: Guido Günther <agx@sigxcpu.org> */ #include "fbd-feedback-dummy.h" #include "fbd-feedback-theme.h" #include <json-glib/json-glib.h> #define THEME_NAME "test" static void test_fbd_feedback_theme_name (void) { g_autoptr(FbdFeedbackTheme) theme = fbd_feedback_theme_new (THEME_NAME); g_assert_true (FBD_IS_FEEDBACK_THEME (theme)); g_assert_cmpstr (fbd_feedback_theme_get_name (theme), ==, THEME_NAME); } static void test_fbd_feedback_theme_profiles (void) { g_autoptr (FbdFeedbackDummy) quiet_fb1 = g_object_new (FBD_TYPE_FEEDBACK_DUMMY, "event-name", "event1", NULL); g_autoptr (FbdFeedbackDummy) quiet_fb2 = g_object_new (FBD_TYPE_FEEDBACK_DUMMY, "event-name", "event2", NULL); g_autoptr (FbdFeedbackDummy) full_fb1 = g_object_new (FBD_TYPE_FEEDBACK_DUMMY, "event-name", "event1", NULL); g_autoptr (FbdFeedbackDummy) full_fb2 = g_object_new (FBD_TYPE_FEEDBACK_DUMMY, "event-name", "event2", NULL); FbdFeedbackTheme *theme = fbd_feedback_theme_new (THEME_NAME); FbdFeedbackProfile *profile_full = fbd_feedback_profile_new ("full"); FbdFeedbackProfile *profile_quiet = fbd_feedback_profile_new ("quiet"); FbdFeedbackProfile *profile; g_autofree char *json = NULL; fbd_feedback_profile_add_feedback (profile_quiet, FBD_FEEDBACK_BASE(quiet_fb1)); fbd_feedback_profile_add_feedback (profile_quiet, FBD_FEEDBACK_BASE(quiet_fb2)); fbd_feedback_profile_add_feedback (profile_full, FBD_FEEDBACK_BASE(full_fb1)); fbd_feedback_profile_add_feedback (profile_full, FBD_FEEDBACK_BASE(full_fb2)); g_assert_true (FBD_IS_FEEDBACK_THEME (theme)); fbd_feedback_theme_add_profile (theme, profile_quiet); fbd_feedback_theme_add_profile (theme, profile_full); profile = fbd_feedback_theme_get_profile (theme, "full"); g_assert_true (FBD_IS_FEEDBACK_PROFILE (profile)); json = json_gobject_to_data (G_OBJECT(theme), NULL); g_print ("%s\n", json); g_assert_finalize_object (theme); g_assert_finalize_object (profile_full); g_assert_finalize_object (profile_quiet); } static void test_fbd_feedback_theme_parse (void) { const char *json =" " "{ " " \"name\" : \"test\", " " \"parent-name\" : \"parent-test\", " " \"profiles\" : [ " " { " " \"name\" : \"full\", " " \"feedbacks\" : [ " " { " " \"type\" : \"dummy\", " " \"event-name\" : \"event1\" " " }, " " { " " \"type\" : \"dummy\", " " \"event-name\" : \"event2\" " " } " " ] " " }, " " { " " \"name\" : \"quiet\", " " \"feedbacks\" : [ " " { " " \"type\" : \"dummy\", " " \"event-name\" : \"event1\" " " }, " " { " " \"type\" : \"dummy\", " " \"event-name\" : \"event2\" " " } " " ] " " } " " ] " "} "; g_autoptr (GError) err = NULL; g_autoptr (FbdFeedbackTheme) theme = NULL; FbdFeedbackProfile *profile; const char *name; theme = fbd_feedback_theme_new_from_data (json, &err); g_assert_no_error (err); g_assert_nonnull (theme); name = fbd_feedback_theme_get_name (theme); g_assert_cmpstr ("test", ==, name); name = fbd_feedback_theme_get_parent_name (theme); g_assert_cmpstr ("parent-test", ==, name); profile = fbd_feedback_theme_get_profile (theme, "full"); g_assert_true (FBD_IS_FEEDBACK_PROFILE(profile)); g_assert_cmpstr ("full", ==, fbd_feedback_profile_get_name (profile)); profile = fbd_feedback_theme_get_profile (theme, "quiet"); g_assert_true (FBD_IS_FEEDBACK_PROFILE(profile)); g_assert_cmpstr ("quiet", ==, fbd_feedback_profile_get_name (profile)); } static void test_fbd_feedback_theme_update (void) { g_autoptr (GError) err = NULL; FbdFeedbackTheme *theme, *from; FbdFeedbackProfile *profile; FbdFeedbackBase *fb; const char *name; /* test-dummy-1x feedbacks */ from = fbd_feedback_theme_new_from_file (TEST_DATA_DIR "/parent/test.json", &err); g_assert_no_error (err); g_assert_true (FBD_IS_FEEDBACK_THEME (from)); /* test-dummy-0{0,1} feedbacks */ theme = fbd_feedback_theme_new_from_file (TEST_DATA_DIR "/parent/base.json", &err); g_assert_no_error (err); g_assert_true (FBD_IS_FEEDBACK_THEME (theme)); name = fbd_feedback_theme_get_name (from); g_assert_cmpstr ("test", ==, name); name = fbd_feedback_theme_get_name (theme); g_assert_cmpstr ("base", ==, name); /* `theme` is lacking "silent" while `from` has it */ profile = fbd_feedback_theme_get_profile (theme, "silent"); g_assert_null (profile); profile = fbd_feedback_theme_get_profile (from, "silent"); g_assert_true (FBD_IS_FEEDBACK_PROFILE(profile)); fbd_feedback_theme_update (theme, from); /* After merging `theme` has a silent profile too */ profile = fbd_feedback_theme_get_profile (theme, "silent"); g_assert_true (FBD_IS_FEEDBACK_PROFILE(profile)); g_assert_cmpstr ("silent", ==, fbd_feedback_profile_get_name (profile)); /* Name updated */ name = fbd_feedback_theme_get_name (theme); g_assert_cmpstr ("test", ==, name); /* test-dummy-10 added */ profile = fbd_feedback_theme_get_profile (theme, "full"); fb = fbd_feedback_profile_get_feedback (profile, "test-dummy-10"); g_assert_cmpstr ("test-dummy-10", ==, fbd_feedback_get_event_name (fb)); profile = fbd_feedback_theme_get_profile (theme, "quiet"); fb = fbd_feedback_profile_get_feedback (profile, "test-dummy-10"); g_assert_cmpstr ("test-dummy-10", ==, fbd_feedback_get_event_name (fb)); profile = fbd_feedback_theme_get_profile (theme, "silent"); fb = fbd_feedback_profile_get_feedback (profile, "test-dummy-10"); g_assert_cmpstr ("test-dummy-10", ==, fbd_feedback_get_event_name (fb)); /* test-dummy-00 updated */ profile = fbd_feedback_theme_get_profile (theme, "full"); fb = fbd_feedback_profile_get_feedback (profile, "test-dummy-00"); g_assert_cmpstr ("test-dummy-00", ==, fbd_feedback_get_event_name (fb)); g_assert_cmpint (fbd_feedback_dummy_get_duration (FBD_FEEDBACK_DUMMY (fb)), ==, 0x10); g_assert_finalize_object (from); g_assert_finalize_object (theme); } gint main (gint argc, gchar *argv[]) { g_test_init (&argc, &argv, NULL); g_test_add_func("/feedbackd/fbd/feedback-theme/name", test_fbd_feedback_theme_name); g_test_add_func("/feedbackd/fbd/feedback-theme/profiles", test_fbd_feedback_theme_profiles); g_test_add_func("/feedbackd/fbd/feedback-theme/parse", test_fbd_feedback_theme_parse); g_test_add_func("/feedbackd/fbd/feedback-theme/update", test_fbd_feedback_theme_update); return g_test_run(); } 070701000000CD000081A400000000000000000000000164F062AA00001409000000000000000000000000000000000000003000000000feedbackd-0.2.1/tests/test-fbd-theme-expander.c/* * Copyright (C) 2022 Guido Günther <agx@sigxcpu.org> * * SPDX-License-Identifier: GPL-3.0+ */ #include "fbd-feedback-dummy.h" #include "fbd-theme-expander.h" #include <json-glib/json-glib.h> static void test_fbd_theme_expander_object (void) { g_autoptr (FbdThemeExpander) expander = g_object_new (FBD_TYPE_THEME_EXPANDER, NULL); g_assert_cmpstr ("default", ==, fbd_theme_expander_get_theme_name (expander)); g_assert_null (fbd_theme_expander_get_theme_file (expander)); g_assert_null (fbd_theme_expander_get_compatibles (expander)); } static void test_fbd_theme_expander_device (void) { g_autoptr (GError) err = NULL; const char *compatibles[] = { NULL, NULL }; FbdFeedbackProfile *profile; FbdThemeExpander *expander; FbdFeedbackTheme *theme; FbdFeedbackBase *fb; const char *const *compatibles2; /* just the default profile */ compatibles[0] = "doesnotexist"; expander = fbd_theme_expander_new (compatibles, NULL, NULL); g_assert_cmpstr ("default", ==, fbd_theme_expander_get_theme_name (expander)); theme = fbd_theme_expander_load_theme_files (expander, &err); compatibles2 = fbd_theme_expander_get_compatibles (expander); #if GLIB_CHECK_VERSION(2, 68, 0) g_assert_cmpstrv (compatibles2, compatibles); #endif g_assert_no_error (err); profile = fbd_feedback_theme_get_profile (theme, "silent"); g_assert_null (profile); profile = fbd_feedback_theme_get_profile (theme, "quiet"); g_assert_true (FBD_IS_FEEDBACK_PROFILE(profile)); profile = fbd_feedback_theme_get_profile (theme, "full"); g_assert_true (FBD_IS_FEEDBACK_PROFILE(profile)); g_assert_finalize_object (theme); g_assert_finalize_object (expander); /* Empty device theme that just chains up */ compatibles[0] = "chainup"; expander = fbd_theme_expander_new (compatibles, NULL, NULL); compatibles2 = fbd_theme_expander_get_compatibles (expander); #if GLIB_CHECK_VERSION(2, 68, 0) g_assert_cmpstrv (compatibles2, compatibles); #endif theme = fbd_theme_expander_load_theme_files (expander, &err); g_assert_no_error (err); profile = fbd_feedback_theme_get_profile (theme, "silent"); g_assert_null (profile); profile = fbd_feedback_theme_get_profile (theme, "quiet"); g_assert_true (FBD_IS_FEEDBACK_PROFILE(profile)); profile = fbd_feedback_theme_get_profile (theme, "full"); g_assert_true (FBD_IS_FEEDBACK_PROFILE(profile)); g_assert_finalize_object (theme); g_assert_finalize_object (expander); /* Replace an existing event */ compatibles[0] = "replace"; expander = fbd_theme_expander_new (compatibles, NULL, NULL); compatibles2 = fbd_theme_expander_get_compatibles (expander); #if GLIB_CHECK_VERSION(2, 68, 0) g_assert_cmpstrv (compatibles2, compatibles); #endif theme = fbd_theme_expander_load_theme_files (expander, &err); g_assert_no_error (err); profile = fbd_feedback_theme_get_profile (theme, "full"); g_assert_true (FBD_IS_FEEDBACK_PROFILE(profile)); fb = fbd_feedback_profile_get_feedback (profile, "test-dummy-0"); g_assert_cmpstr ("test-dummy-0", ==, fbd_feedback_get_event_name (fb)); g_assert_cmpint (fbd_feedback_dummy_get_duration (FBD_FEEDBACK_DUMMY (fb)), ==, 0x10); g_assert_true (FBD_IS_FEEDBACK_PROFILE(profile)); fb = fbd_feedback_profile_get_feedback (profile, "test-dummy-2"); g_assert_cmpstr ("test-dummy-2", ==, fbd_feedback_get_event_name (fb)); g_assert_cmpint (fbd_feedback_dummy_get_duration (FBD_FEEDBACK_DUMMY (fb)), ==, 0x20); g_assert_finalize_object (theme); g_assert_finalize_object (expander); } static void test_fbd_theme_expander_custom (void) { g_autoptr (GError) err = NULL; const char *compatibles[] = { NULL, NULL }; FbdFeedbackProfile *profile; FbdThemeExpander *expander; FbdFeedbackTheme *theme; FbdFeedbackBase *fb; /* Load a custom theme that overrides a single event on top of the `replace` from above */ compatibles[0] = "replace"; expander = fbd_theme_expander_new (compatibles, "custom", NULL); theme = fbd_theme_expander_load_theme_files (expander, &err); g_assert_no_error (err); profile = fbd_feedback_theme_get_profile (theme, "full"); g_assert_true (FBD_IS_FEEDBACK_PROFILE(profile)); fb = fbd_feedback_profile_get_feedback (profile, "test-dummy-0"); g_assert_cmpstr ("test-dummy-0", ==, fbd_feedback_get_event_name (fb)); g_assert_cmpint (fbd_feedback_dummy_get_duration (FBD_FEEDBACK_DUMMY (fb)), ==, 0x10); g_assert_true (FBD_IS_FEEDBACK_PROFILE(profile)); fb = fbd_feedback_profile_get_feedback (profile, "test-dummy-2"); g_assert_cmpstr ("test-dummy-2", ==, fbd_feedback_get_event_name (fb)); g_assert_cmpint (fbd_feedback_dummy_get_duration (FBD_FEEDBACK_DUMMY (fb)), ==, 0x30); g_assert_finalize_object (theme); g_assert_finalize_object (expander); } gint main (int argc, char *argv[]) { g_test_init (&argc, &argv, NULL); g_test_add_func("/feedbackd/fbd/theme-expander/object", test_fbd_theme_expander_object); g_test_add_func("/feedbackd/fbd/theme-expander/device", test_fbd_theme_expander_device); g_test_add_func("/feedbackd/fbd/theme-expander/custom", test_fbd_theme_expander_custom); return g_test_run(); } 070701000000CE000081A400000000000000000000000164F062AA0000093B000000000000000000000000000000000000002700000000feedbackd-0.2.1/tests/test-lfb-event.c/* * Copyright (C) 2020 Purism SPC * SPDX-License-Identifier: GPL-3.0+ * Author: Guido Günther <agx@sigxcpu.org> */ #include "libfeedback.h" #include <gio/gio.h> /* Property set/get */ static void test_lfb_event_props (void) { g_autoptr(LfbEvent) event = NULL; g_autofree gchar *evname = NULL; g_autofree gchar *profile = NULL; g_autofree gchar *app_id = NULL; gint timeout; g_assert_true (lfb_init (TEST_APP_ID, NULL)); event = lfb_event_new ("window-close"); g_assert_true (LFB_IS_EVENT (event)); g_object_get (event, "event", &evname, "timeout", &timeout, "feedback-profile", &profile, "app-id", &app_id, NULL); g_assert_cmpstr (evname, ==, "window-close"); g_assert_cmpint (timeout, ==, -1); g_assert_null (profile); g_assert_null (app_id); g_assert_cmpint (lfb_event_get_end_reason (event), ==, LFB_EVENT_END_REASON_NATURAL); g_assert_cmpint (lfb_event_get_state (event), ==, LFB_EVENT_STATE_NONE); g_object_set (event, "feedback-profile", "full", NULL); g_object_get (event, "feedback-profile", &profile, NULL); g_assert_cmpstr (profile, ==, "full"); g_assert_cmpstr (lfb_event_get_feedback_profile (event), ==, "full"); g_object_set (event, "app-id", "com.example.foo", NULL); g_object_get (event, "app-id", &app_id, NULL); g_assert_cmpstr (app_id, ==, "com.example.foo"); g_assert_cmpstr (lfb_event_get_app_id (event), ==, "com.example.foo"); lfb_uninit (); } /* Test failure paths when no feedback daemon is running */ static void test_lfb_event_trigger (void) { g_autoptr(LfbEvent) event = NULL; g_autoptr (GError) err = NULL; g_assert_true (lfb_init (TEST_APP_ID, NULL)); event = lfb_event_new ("window-close"); g_assert_false (lfb_event_trigger_feedback (event, &err)); g_assert_nonnull (err); g_clear_error (&err); g_assert_false (lfb_event_end_feedback (event, &err)); g_assert_nonnull (err); g_clear_error (&err); lfb_uninit (); } gint main (gint argc, gchar *argv[]) { g_test_init (&argc, &argv, NULL); g_autoptr(GTestDBus) bus = g_test_dbus_new (0); g_test_dbus_up (bus); g_test_add_func("/feedbackd/libfeedback/lfb-event/props", test_lfb_event_props); g_test_add_func("/feedbackd/libfeedback/lfb-event/trigger", test_lfb_event_trigger); return g_test_run(); } 070701000000CF000081A400000000000000000000000164F062AA00002C1E000000000000000000000000000000000000002D00000000feedbackd-0.2.1/tests/test-lfb-integration.c/* * Copyright (C) 2020 Purism SPC * SPDX-License-Identifier: GPL-3.0+ * Author: Guido Günther <agx@sigxcpu.org> */ #include "libfeedback.h" #include <gio/gio.h> typedef struct { GTestDBus *dbus; } TestFixture; GMainLoop *mainloop; static void fixture_setup (TestFixture *fixture, gconstpointer unused) { g_autoptr (GError) err = NULL; gchar *relative, *servicesdir; gint success; fixture->dbus = g_test_dbus_new (G_TEST_DBUS_NONE); relative = g_test_build_filename (G_TEST_BUILT, "services", NULL); servicesdir = g_canonicalize_filename (relative, NULL); g_free (relative); g_test_dbus_add_service_dir (fixture->dbus, servicesdir); g_free (servicesdir); g_setenv ("FEEDBACK_THEME", TEST_DATA_DIR "/test.json", TRUE); g_setenv ("GSETTINGS_BACKEND", "memory", TRUE); g_test_dbus_up (fixture->dbus); g_assert_null (mainloop); mainloop = g_main_loop_new (NULL, FALSE); success = lfb_init (TEST_APP_ID, &err); g_assert_no_error (err); g_assert_true (success); } static void fixture_teardown (TestFixture *fixture, gconstpointer unused) { g_clear_pointer (&mainloop, g_main_loop_unref); lfb_uninit (); g_test_dbus_down (fixture->dbus); g_object_unref (fixture->dbus); } static void on_feedback_ended (LfbEvent *event, LfbEvent **cmp) { g_assert_true (LFB_IS_EVENT (event)); g_assert_null (*cmp); g_debug ("Feedback ended for %s: %d", lfb_event_get_event (event), lfb_event_get_end_reason (event)); g_assert_cmpint (lfb_event_get_state (event), ==, LFB_EVENT_STATE_ENDED); /* "Return" event */ *cmp = event; } static void test_lfb_integration_event_sync (void) { g_autoptr(LfbEvent) event0 = NULL; g_autoptr(LfbEvent) event10 = NULL; g_autoptr (GError) err = NULL; LfbEvent *cmp = NULL; gboolean success; event0 = lfb_event_new ("test-dummy-0"); success = lfb_event_trigger_feedback (event0, &err); g_assert_no_error (err); g_assert_true (success); event10 = lfb_event_new ("test-dummy-10"); g_signal_connect (event10, "feedback-ended", (GCallback)on_feedback_ended, &cmp); g_signal_connect_swapped (event10, "feedback-ended", (GCallback)g_main_loop_quit, mainloop); success = lfb_event_trigger_feedback (event10, &err); g_assert_no_error (err); g_assert_true (success); success = lfb_event_end_feedback (event10, &err); g_assert_no_error (err); g_assert_true (success); g_main_loop_run (mainloop); /* If the signal fired cmp will match event */ g_assert_true (event10 == cmp); g_assert_cmpint (lfb_event_get_state (event10), ==, LFB_EVENT_STATE_ENDED); g_assert_cmpint (lfb_event_get_end_reason (event10), ==, LFB_EVENT_END_REASON_EXPLICIT); } static void test_lfb_integration_event_not_found (void) { g_autoptr(LfbEvent) event0 = NULL; g_autoptr (GError) err = NULL; LfbEvent *cmp = NULL; gboolean success; event0 = lfb_event_new ("test-does-not-exist"); g_signal_connect (event0, "feedback-ended", (GCallback)on_feedback_ended, &cmp); g_signal_connect_swapped (event0, "feedback-ended", (GCallback)g_main_loop_quit, mainloop); success = lfb_event_trigger_feedback (event0, &err); g_assert_no_error (err); g_assert_true (success); g_main_loop_run (mainloop); /* If the signal fired cmp will match event */ g_assert_true (event0 == cmp); g_assert_cmpint (lfb_event_get_state (event0), ==, LFB_EVENT_STATE_ENDED); g_assert_cmpint (lfb_event_get_end_reason (event0), ==, LFB_EVENT_END_REASON_NOT_FOUND); } static void on_event_triggered (LfbEvent *event, GAsyncResult *res, LfbEvent **cmp) { g_autoptr (GError) err = NULL; gboolean success; g_assert_true (LFB_IS_EVENT (event)); g_assert_null (*cmp); g_debug ("%s: %p, %s", __func__, event, lfb_event_get_event (event)); success = lfb_event_trigger_feedback_finish (event, res, &err); g_assert_no_error (err); g_assert_true (success); g_assert_cmpint (lfb_event_get_state (event), ==, LFB_EVENT_STATE_RUNNING); /* "Return" event */ *cmp = event; } static void on_event_triggered_quit (LfbEvent *event, GAsyncResult *res, LfbEvent **cmp) { g_autoptr (GError) err = NULL; gboolean success; g_assert_true (LFB_IS_EVENT (event)); g_assert_null (*cmp); g_debug ("%s: %p, %s", __func__, event, lfb_event_get_event (event)); success = lfb_event_trigger_feedback_finish (event, res, &err); g_assert_no_error (err); g_assert_true (success); g_assert_cmpint (lfb_event_get_state (event), ==, LFB_EVENT_STATE_RUNNING); /* "Return" event */ *cmp = event; g_main_loop_quit (mainloop); } static void on_event_end_finished (LfbEvent *event, GAsyncResult *res, LfbEvent **cmp) { g_autoptr (GError) err = NULL; gboolean success; g_debug ("%s: %p, %s", __func__, event, lfb_event_get_event (event)); g_assert_true (LFB_IS_EVENT (event)); g_assert_null (*cmp); success = lfb_event_end_feedback_finish (event, res, &err); g_assert_no_error (err); g_assert_true (success); /* This is not guaranteed for all types of feedback, see `feedback-ended` */ g_assert_cmpint (lfb_event_get_state (event), ==, LFB_EVENT_STATE_ENDED); /* "Return" event */ *cmp = event; g_main_loop_quit (mainloop); } static void test_lfb_integration_event_not_found_async (void) { g_autoptr(LfbEvent) event0 = NULL; LfbEvent *cmp = NULL; LfbEvent *cmp2 = NULL; event0 = lfb_event_new ("test-does-not-exist"); g_signal_connect (event0, "feedback-ended", (GCallback)on_feedback_ended, &cmp2); /* The main loop will only quit if the "feedback-ended" signal actually gets emitted */ g_signal_connect_swapped (event0, "feedback-ended", (GCallback)g_main_loop_quit, mainloop); lfb_event_trigger_feedback_async (event0, NULL, (GAsyncReadyCallback)on_event_triggered, &cmp); g_main_loop_run (mainloop); /* If the signal fired cmp will match event */ g_assert_true (event0 == cmp); g_assert_true (event0 == cmp2); g_assert_cmpint (lfb_event_get_state (event0), ==, LFB_EVENT_STATE_ENDED); g_assert_cmpint (lfb_event_get_end_reason (event0), ==, LFB_EVENT_END_REASON_NOT_FOUND); } static void test_lfb_integration_event_async (void) { g_autoptr(LfbEvent) event0 = NULL; g_autoptr(LfbEvent) event10 = NULL; LfbEvent *cmp1 = NULL, *cmp2 = NULL, *cmp3 = NULL; event0 = lfb_event_new ("test-dummy-0"); lfb_event_trigger_feedback_async (event0, NULL, (GAsyncReadyCallback)on_event_triggered_quit, &cmp1); g_main_loop_run (mainloop); /* The async finish callback saw the right event */ g_assert_true (event0 == cmp1); cmp1 = NULL; event10 = lfb_event_new ("test-dummy-10"); lfb_event_set_timeout (event10, 1); g_assert_cmpint (lfb_event_get_timeout (event10), ==, 1); lfb_event_set_feedback_profile (event10, "quiet"); g_signal_connect (event10, "feedback-ended", (GCallback)on_feedback_ended, &cmp1); /* The async callback ends the main loop */ lfb_event_trigger_feedback_async (event10, NULL, (GAsyncReadyCallback)on_event_triggered_quit, &cmp2); g_main_loop_run (mainloop); /* The async callback ends the main loop */ lfb_event_end_feedback_async (event10, NULL, (GAsyncReadyCallback)on_event_end_finished, &cmp3); g_main_loop_run (mainloop); /* Check if callbacks saw the right event */ g_assert_true (event10 == cmp1); g_assert_true (event10 == cmp2); g_assert_true (event10 == cmp3); g_assert_cmpint (lfb_event_get_state (event10), ==, LFB_EVENT_STATE_ENDED); g_assert_cmpint (lfb_event_get_end_reason (event10), ==, LFB_EVENT_END_REASON_EXPLICIT); } static void on_event_with_error_triggered (LfbEvent *event, GAsyncResult *res, LfbEvent **cmp) { g_autoptr (GError) err = NULL; gboolean success; g_debug ("%s: %p, %s", __func__, event, lfb_event_get_event (event)); g_assert_true (LFB_IS_EVENT (event)); g_assert_null (*cmp); success = lfb_event_end_feedback_finish (event, res, &err); g_assert_false (success); g_assert_error (err, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS); /* "Return" event */ *cmp = event; g_main_loop_quit (mainloop); } static void test_lfb_integration_event_async_error (void) { g_autoptr(LfbEvent) event0 = NULL; LfbEvent *cmp1 = NULL; /* Empty event names are invalid */ event0 = lfb_event_new (""); lfb_event_trigger_feedback_async (event0, NULL, (GAsyncReadyCallback)on_event_with_error_triggered, &cmp1); g_main_loop_run (mainloop); /* The async finish callback saw the right event */ g_assert_true (event0 == cmp1); } static void on_profile_changed (LfbGdbusFeedback *proxy, GParamSpec *psepc, const gchar **profile) { g_assert_null (*profile); *profile = lfb_get_feedback_profile(); g_debug("Set feedback profile to: '%s'", *profile); g_main_loop_quit (mainloop); } static void test_lfb_integration_profile (void) { LfbGdbusFeedback *proxy; gchar *cmp = NULL; g_assert_cmpstr (lfb_get_feedback_profile (), ==, "full"); proxy = lfb_get_proxy (); g_assert_nonnull (proxy); lfb_set_feedback_profile ("quiet"); g_signal_connect (proxy, "notify::profile", (GCallback)on_profile_changed, &cmp); g_main_loop_run (mainloop); g_assert_cmpstr (lfb_get_feedback_profile (), ==, "quiet"); g_assert_cmpstr (cmp, ==, "quiet"); } gint main (gint argc, gchar *argv[]) { g_test_init (&argc, &argv, NULL); g_test_add("/feedbackd/lfb-integration/event_sync", TestFixture, NULL, (gpointer)fixture_setup, (gpointer)test_lfb_integration_event_sync, (gpointer)fixture_teardown); g_test_add("/feedbackd/lfb-integration/event_async/success", TestFixture, NULL, (gpointer)fixture_setup, (gpointer)test_lfb_integration_event_async, (gpointer)fixture_teardown); g_test_add("/feedbackd/lfb-integration/event_async/error", TestFixture, NULL, (gpointer)fixture_setup, (gpointer)test_lfb_integration_event_async_error, (gpointer)fixture_teardown); g_test_add("/feedbackd/lfb-integration/event_not_found", TestFixture, NULL, (gpointer)fixture_setup, (gpointer)test_lfb_integration_event_not_found, (gpointer)fixture_teardown); g_test_add("/feedbackd/lfb-integration/event_not_found_async", TestFixture, NULL, (gpointer)fixture_setup, (gpointer)test_lfb_integration_event_not_found_async, (gpointer)fixture_teardown); g_test_add("/feedbackd/lfb-integration/profile", TestFixture, NULL, (gpointer)fixture_setup, (gpointer)test_lfb_integration_profile, (gpointer)fixture_teardown); return g_test_run(); } 07070100000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000B00000000TRAILER!!!1002 blocks
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor